First commit

This commit is contained in:
Theodotos Andreou 2018-01-14 13:10:16 +00:00
commit c6e2478c40
13918 changed files with 2303184 additions and 0 deletions

View file

@ -0,0 +1,656 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
/**
* This class create activities for a case.
*/
class CRM_Case_Form_Activity extends CRM_Activity_Form_Activity {
/**
* The default variable defined.
*
* @var int
*/
public $_caseId;
/**
* The default case type variable defined.
*
* @var int
*/
public $_caseType;
/**
* The array of releted contact info.
*
* @var array
*/
public $_relatedContacts;
/**
* Build the form object.
*/
public function preProcess() {
$caseIds = CRM_Utils_Request::retrieve('caseid', 'String', $this);
$this->_caseId = explode(',', $caseIds);
$this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
if (!$this->_context) {
$this->_context = 'caseActivity';
}
$this->_crmDir = 'Case';
$this->assign('context', $this->_context);
$result = parent::preProcess();
$scheduleStatusId = CRM_Core_OptionGroup::getValue('activity_status', 'Scheduled', 'name');
$this->assign('scheduleStatusId', $scheduleStatusId);
if (!$this->_caseId && $this->_activityId) {
$this->_caseId = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_CaseActivity', $this->_activityId,
'case_id', 'activity_id'
);
}
if ($this->_caseId) {
$this->assign('caseId', $this->_caseId);
$this->assign('countId', count($this->_caseId));
$this->assign('caseID', CRM_Utils_Array::first($this->_caseId));
}
if (!$this->_caseId ||
(!$this->_activityId && !$this->_activityTypeId)
) {
CRM_Core_Error::fatal('required params missing.');
}
//check for case activity access.
if (!CRM_Case_BAO_Case::accessCiviCase()) {
CRM_Core_Error::fatal(ts('You are not authorized to access this page.'));
}
//validate case id.
if ($this->_caseId &&
!CRM_Core_Permission::check('access all cases and activities')
) {
$session = CRM_Core_Session::singleton();
$allCases = CRM_Case_BAO_Case::getCases(TRUE, $session->get('userID'), 'any');
if (count(array_intersect($this->_caseId, array_keys($allCases))) == 0) {
CRM_Core_Error::fatal(ts('You are not authorized to access this page.'));
}
}
//validate case activity id.
if ($this->_activityId &&
($this->_action & CRM_Core_Action::UPDATE)
) {
$valid = CRM_Case_BAO_Case::checkPermission($this->_activityId, 'edit',
$this->_activityTypeId
);
if (!$valid) {
CRM_Core_Error::fatal(ts('You are not authorized to access this page.'));
}
}
foreach ($this->_caseId as $casePos => $caseId) {
$this->_caseType[$casePos] = CRM_Case_BAO_Case::getCaseType($caseId, 'name');
}
$this->assign('caseType', $this->_caseType);
$xmlProcessorProcess = new CRM_Case_XMLProcessor_Process();
$isMultiClient = $xmlProcessorProcess->getAllowMultipleCaseClients();
$this->assign('multiClient', $isMultiClient);
foreach ($this->_caseId as $casePos => $caseId) {
$clients[] = CRM_Case_BAO_Case::getContactNames($caseId);
}
$this->assign('client_names', $clients);
$caseIds = implode(',', $this->_caseId);
// set context for pushUserContext and for statusBounce
if ($this->_context == 'fulltext') {
if ($this->_action == CRM_Core_Action::UPDATE || $this->_action == CRM_Core_Action::DELETE) {
$url = CRM_Utils_System::url('civicrm/contact/view/case',
"reset=1&action=view&cid={$this->_currentlyViewedContactId}&id={$caseIds}&show=1&context={$this->_context}"
);
}
else {
$url = CRM_Utils_System::url('civicrm/contact/search/custom', 'force=1');
}
}
else {
$url = CRM_Utils_System::url('civicrm/contact/view/case',
"reset=1&action=view&cid={$this->_currentlyViewedContactId}&id={$caseIds}&show=1"
);
}
if (!$this->_activityId) {
$caseTypes = CRM_Case_PseudoConstant::caseType();
if (empty($caseTypes) && ($this->_activityTypeName == 'Change Case Type') && !$this->_caseId) {
$url = CRM_Utils_System::url('civicrm/contact/view/case',
"reset=1&action=view&cid={$this->_currentlyViewedContactId}&id={$caseIds}&show=1"
);
$session = CRM_Core_Session::singleton();
$session->pushUserContext($url);
CRM_Core_Error::statusBounce(ts("You do not have any active Case Types"));
}
// check if activity count is within the limit
$xmlProcessor = new CRM_Case_XMLProcessor_Process();
foreach ($this->_caseId as $casePos => $caseId) {
$caseType = $this->_caseType[$casePos];
$activityInst = $xmlProcessor->getMaxInstance($caseType);
// If not bounce back and also provide activity edit link
if (isset($activityInst[$this->_activityTypeName])) {
$activityCount = CRM_Case_BAO_Case::getCaseActivityCount($caseId, $this->_activityTypeId);
if ($activityCount >= $activityInst[$this->_activityTypeName]) {
if ($activityInst[$this->_activityTypeName] == 1) {
$atArray = array('activity_type_id' => $this->_activityTypeId);
$activities = CRM_Case_BAO_Case::getCaseActivity($caseId,
$atArray,
$this->_currentUserId
);
$activities = array_keys($activities);
$activities = $activities[0];
$editUrl = CRM_Utils_System::url('civicrm/case/activity',
"reset=1&cid={$this->_currentlyViewedContactId}&caseid={$caseId}&action=update&id={$activities}"
);
}
CRM_Core_Error::statusBounce(ts("You can not add another '%1' activity to this case. %2",
array(
1 => $this->_activityTypeName,
2 => ts("Do you want to <a %1>edit the existing activity</a>?", array(1 => "href='$editUrl'")),
)
),
$url
);
}
}
}
}
$session = CRM_Core_Session::singleton();
$session->pushUserContext($url);
}
/**
* Set default values for the form.
*/
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;
}
}
public function buildQuickForm() {
$this->_fields['source_contact_id']['label'] = ts('Reported By');
unset($this->_fields['status_id']['attributes']['required']);
if ($this->_caseType) {
$xmlProcessor = new CRM_Case_XMLProcessor_Process();
$aTypes = array();
foreach ($this->_caseType as $key => $val) {
$activityTypes = $xmlProcessor->get($val, 'ActivityTypes', TRUE);
$aTypes = $aTypes + $activityTypes;
}
// remove Open Case activity type since we're inside an existing case
$openCaseID = CRM_Core_OptionGroup::getValue('activity_type', 'Open Case', 'name');
unset($aTypes[$openCaseID]);
asort($aTypes);
$this->_fields['followup_activity_type_id']['attributes'] = array('' => '- select activity type -') + $aTypes;
}
parent::buildQuickForm();
if ($this->_action & (CRM_Core_Action::DELETE | CRM_Core_Action::DETACH | CRM_Core_Action::RENEW)) {
return;
}
$this->assign('urlPath', 'civicrm/case/activity');
$encounterMediums = CRM_Case_PseudoConstant::encounterMedium();
// Fixme: what's the justification for this? It seems like it is just re-adding an option in case it is the default and disabled.
// Is that really a big problem?
if ($this->_activityTypeFile == 'OpenCase') {
$this->_encounterMedium = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $this->_activityId,
'medium_id'
);
if (!array_key_exists($this->_encounterMedium, $encounterMediums)) {
$encounterMediums[$this->_encounterMedium] = CRM_Core_OptionGroup::getLabel('encounter_medium',
$this->_encounterMedium,
FALSE
);
}
}
$this->add('select', 'medium_id', ts('Medium'), $encounterMediums, TRUE);
$i = 0;
foreach ($this->_caseId as $key => $val) {
$this->_relatedContacts[] = $rgc = CRM_Case_BAO_Case::getRelatedAndGlobalContacts($val);
$contName = CRM_Case_BAO_Case::getContactNames($val);
foreach ($contName as $nkey => $nval) {
array_push($this->_relatedContacts[$i][0], $this->_relatedContacts[$i][0]['managerOf'] = $nval['display_name']);
}
$i++;
}
//add case client in send a copy selector.CRM-4438.
foreach ($this->_caseId as $key => $val) {
$relatedContacts[] = $relCon = CRM_Case_BAO_Case::getContactNames($val);
}
if (!empty($relatedContacts)) {
foreach ($relatedContacts as $relatedContact) {
$this->_relatedContacts[] = $relatedContact;
}
}
if (!empty($this->_relatedContacts)) {
$checkBoxes = array();
foreach ($this->_relatedContacts as $id => $row) {
foreach ($row as $key => $value) {
$checkBoxes[$key] = $this->addElement('checkbox', $key, NULL, NULL, array('class' => 'select-row'));
}
}
$this->addGroup($checkBoxes, 'contact_check');
$this->addElement('checkbox', 'toggleSelect', NULL, NULL,
array('class' => 'select-rows')
);
$this->assign('searchRows', $this->_relatedContacts);
}
$this->_relatedContacts = $rgc + $relCon;
$this->addFormRule(array('CRM_Case_Form_Activity', 'formRule'), $this);
}
/**
* Global form rule.
*
* @param array $fields
* The input form values.
* @param array $files
* The uploaded files if any.
* @param $self
*
* @return bool|array
* true if no errors, else array of errors
*/
public static function formRule($fields, $files, $self) {
// skip form rule if deleting
if (CRM_Utils_Array::value('_qf_Activity_next_', $fields) == 'Delete' || CRM_Utils_Array::value('_qf_Activity_next_', $fields) == 'Restore') {
return TRUE;
}
return parent::formRule($fields, $files, $self);
}
/**
* 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_Activity_BAO_ActivityContact::buildOptions('record_type_id', 'validate');
$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');
}
}
}

View file

@ -0,0 +1,248 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
/**
* This class generates form components for OpenCase Activity.
*/
class CRM_Case_Form_Activity_ChangeCaseStartDate {
/**
* @param CRM_Core_Form $form
*
* @throws Exception
*/
public static function preProcess(&$form) {
if (!isset($form->_caseId)) {
CRM_Core_Error::fatal(ts('Case Id not found.'));
}
if (count($form->_caseId) != 1) {
CRM_Core_Resources::fatal(ts('Expected one case-type'));
}
}
/**
* Set default values for the form.
*
* For edit/view mode the default values are retrieved from the database.
*
* @param CRM_Core_Form $form
*
* @return array
*/
public static function setDefaultValues(&$form) {
$defaults = array();
$openCaseActivityType = CRM_Core_OptionGroup::getValue('activity_type',
'Open Case',
'name'
);
$caseId = CRM_Utils_Array::first($form->_caseId);
$openCaseParams = array('activity_type_id' => $openCaseActivityType);
$openCaseInfo = CRM_Case_BAO_Case::getCaseActivityDates($caseId, $openCaseParams, TRUE);
if (empty($openCaseInfo)) {
list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date::setDateDefaults();
}
else {
// We know there can only be one result
$openCaseInfo = current($openCaseInfo);
// store activity id for updating it later
$form->openCaseActivityId = $openCaseInfo['id'];
list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date::setDateDefaults($openCaseInfo['activity_date'], 'activityDateTime');
}
return $defaults;
}
/**
* @param CRM_Core_Form $form
*/
public static function buildQuickForm(&$form) {
$form->removeElement('status_id');
$form->removeElement('priority_id');
$caseId = CRM_Utils_Array::first($form->_caseId);
$currentStartDate = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_Case', $caseId, 'start_date');
$form->assign('current_start_date', $currentStartDate);
$form->addDate('start_date', ts('New Start Date'), FALSE, array('formatType' => 'activityDateTime'));
}
/**
* Global validation rules for the form.
*
* @param array $values
* Posted values of the form.
*
* @param $files
* @param CRM_Core_Form $form
*
* @return array
* list of errors to be posted back to the form
*/
public static function formRule($values, $files, $form) {
return TRUE;
}
/**
* Process the form submission.
*
*
* @param CRM_Core_Form $form
* @param array $params
*/
public static function beginPostProcess(&$form, &$params) {
if ($form->_context == 'case') {
$params['id'] = $form->_id;
}
}
/**
* Process the form submission.
*
*
* @param CRM_Core_Form $form
* @param array $params
* @param $activity
*/
public static function endPostProcess(&$form, &$params, $activity) {
if (!empty($params['start_date'])) {
$params['start_date'] = CRM_Utils_Date::processDate($params['start_date'], $params['start_date_time']);
}
$caseType = CRM_Utils_Array::first($form->_caseType);
$caseId = CRM_Utils_Array::first($form->_caseId);
if (!$caseType && $caseId) {
$caseType = CRM_Case_BAO_Case::getCaseType($caseId, 'title');
}
if (!$form->_currentlyViewedContactId ||
!$form->_currentUserId ||
!$caseId ||
!$caseType
) {
CRM_Core_Error::fatal('Required parameter missing for ChangeCaseType - end post processing');
}
$config = CRM_Core_Config::singleton();
$params['status_id'] = CRM_Core_OptionGroup::getValue('activity_status', 'Completed', 'name');
$activity->status_id = $params['status_id'];
$params['priority_id'] = CRM_Core_OptionGroup::getValue('priority', 'Normal', 'name');
$activity->priority_id = $params['priority_id'];
// 1. save activity subject with new start date
$currentStartDate = CRM_Utils_Date::customFormat(CRM_Core_DAO::getFieldValue('CRM_Case_DAO_Case',
$caseId, 'start_date'
), $config->dateformatFull);
$newStartDate = CRM_Utils_Date::customFormat(CRM_Utils_Date::mysqlToIso($params['start_date']), $config->dateformatFull);
$subject = 'Change Case Start Date from ' . $currentStartDate . ' to ' . $newStartDate;
$activity->subject = $subject;
$activity->save();
// 2. initiate xml processor
$xmlProcessor = new CRM_Case_XMLProcessor_Process();
$xmlProcessorParams = array(
'clientID' => $form->_currentlyViewedContactId,
'creatorID' => $form->_currentUserId,
'standardTimeline' => 0,
'activity_date_time' => $params['start_date'],
'caseID' => $caseId,
'caseType' => $caseType,
'activityTypeName' => 'Change Case Start Date',
'activitySetName' => 'standard_timeline',
'resetTimeline' => 1,
);
$xmlProcessor->run($caseType, $xmlProcessorParams);
// 2.5 Update open case activity date
// Multiple steps since revisioned
if ($form->openCaseActivityId) {
$abao = new CRM_Activity_BAO_Activity();
$oldParams = array('id' => $form->openCaseActivityId);
$oldActivityDefaults = array();
$oldActivity = $abao->retrieve($oldParams, $oldActivityDefaults);
// save the old values
require_once 'api/v3/utils.php';
$openCaseParams = array();
//@todo calling api functions directly is not supported
_civicrm_api3_object_to_array($oldActivity, $openCaseParams);
// update existing revision
$oldParams = array(
'id' => $form->openCaseActivityId,
'is_current_revision' => 0,
);
$oldActivity = new CRM_Activity_DAO_Activity();
$oldActivity->copyValues($oldParams);
$oldActivity->save();
// change some params for the new one
unset($openCaseParams['id']);
$openCaseParams['activity_date_time'] = $params['start_date'];
$openCaseParams['target_contact_id'] = $oldActivityDefaults['target_contact'];
$openCaseParams['assignee_contact_id'] = $oldActivityDefaults['assignee_contact'];
$session = CRM_Core_Session::singleton();
$openCaseParams['source_contact_id'] = $session->get('userID');
// original_id always refers to the first activity, so only update if null (i.e. this is the second revision)
$openCaseParams['original_id'] = $openCaseParams['original_id'] ? $openCaseParams['original_id'] : $form->openCaseActivityId;
$newActivity = CRM_Activity_BAO_Activity::create($openCaseParams);
if (is_a($newActivity, 'CRM_Core_Error')) {
CRM_Core_Error::fatal('Unable to update Open Case activity');
}
else {
// Create linkage to case
$caseActivityParams = array(
'activity_id' => $newActivity->id,
'case_id' => $caseId,
);
CRM_Case_BAO_Case::processCaseActivity($caseActivityParams);
$caseActivityParams = array(
'activityID' => $form->openCaseActivityId,
'mainActivityId' => $newActivity->id,
);
CRM_Activity_BAO_Activity::copyExtendedActivityData($caseActivityParams);
}
}
// 3.status msg
$params['statusMsg'] = ts('Case Start Date changed successfully.');
}
}

View file

@ -0,0 +1,207 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
/**
* This class generates form components for OpenCase Activity.
*/
class CRM_Case_Form_Activity_ChangeCaseStatus {
/**
* @param CRM_Core_Form $form
*
* @throws Exception
*/
public static function preProcess(&$form) {
if (!isset($form->_caseId)) {
CRM_Core_Error::fatal(ts('Case Id not found.'));
}
}
/**
* Set default values for the form.
*
* For edit/view mode the default values are retrieved from the database.
*
*
* @param CRM_Core_Form $form
*
* @return array
*/
public static function setDefaultValues(&$form) {
$defaults = array();
// Retrieve current case status
$defaults['case_status_id'] = $form->_defaultCaseStatus;
return $defaults;
}
/**
* @param CRM_Core_Form $form
*/
public static function buildQuickForm(&$form) {
$form->removeElement('status_id');
$form->removeElement('priority_id');
$caseTypes = array();
$form->_caseStatus = CRM_Case_PseudoConstant::caseStatus();
$statusNames = CRM_Case_PseudoConstant::caseStatus('name');
// Limit case statuses to allowed types for these case(s)
$allCases = civicrm_api3('Case', 'get', array('return' => 'case_type_id', 'id' => array('IN' => (array) $form->_caseId)));
foreach ($allCases['values'] as $case) {
$caseTypes[$case['case_type_id']] = $case['case_type_id'];
}
$caseTypes = civicrm_api3('CaseType', 'get', array('id' => array('IN' => $caseTypes)));
foreach ($caseTypes['values'] as $ct) {
if (!empty($ct['definition']['statuses'])) {
foreach ($form->_caseStatus as $id => $label) {
if (!in_array($statusNames[$id], $ct['definition']['statuses'])) {
unset($form->_caseStatus[$id]);
}
}
}
}
foreach ($form->_caseId as $key => $val) {
$form->_oldCaseStatus[] = $form->_defaultCaseStatus[] = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_Case', $val, 'status_id');
}
foreach ($form->_defaultCaseStatus as $keydefault => $valdefault) {
if (!array_key_exists($valdefault, $form->_caseStatus)) {
$form->_caseStatus[$valdefault] = CRM_Core_OptionGroup::getLabel('case_status',
$valdefault,
FALSE
);
}
}
$element = $form->add('select', 'case_status_id', ts('Case Status'),
$form->_caseStatus, TRUE
);
// check if the case status id passed in url is a valid one, set as default and freeze
if (CRM_Utils_Request::retrieve('case_status_id', 'Positive', $form)) {
$caseStatusId = CRM_Utils_Request::retrieve('case_status_id', 'Positive', $form);
$caseStatus = CRM_Case_PseudoConstant::caseStatus();
$form->_defaultCaseStatus = array_key_exists($caseStatusId, $caseStatus) ? $caseStatusId : NULL;
$element->freeze();
}
}
/**
* Global validation rules for the form.
*
* @param array $values
* Posted values of the form.
*
* @param $files
* @param CRM_Core_Form $form
*
* @return array
* list of errors to be posted back to the form
*/
public static function formRule($values, $files, $form) {
return TRUE;
}
/**
* Process the form submission.
*
*
* @param CRM_Core_Form $form
* @param array $params
*/
public static function beginPostProcess(&$form, &$params) {
$params['id'] = CRM_Utils_Array::value('case_id', $params);
}
/**
* Process the form submission.
*
*
* @param CRM_Core_Form $form
* @param array $params
* @param CRM_Activity_BAO_Activity $activity
*/
public static function endPostProcess(&$form, &$params, $activity) {
$groupingValues = CRM_Core_OptionGroup::values('case_status', FALSE, TRUE, FALSE, NULL, 'value');
// Set case end_date if we're closing the case. Clear end_date if we're (re)opening it.
if (CRM_Utils_Array::value($params['case_status_id'], $groupingValues) == 'Closed' && !empty($params['activity_date_time'])) {
$params['end_date'] = $params['activity_date_time'];
// End case-specific relationships (roles)
foreach ($params['target_contact_id'] as $cid) {
$rels = CRM_Case_BAO_Case::getCaseRoles($cid, $params['case_id']);
// FIXME: Is there an existing function to close a relationship?
$query = 'UPDATE civicrm_relationship SET end_date=%2 WHERE id=%1';
foreach ($rels as $relId => $relData) {
$relParams = array(
1 => array($relId, 'Integer'),
2 => array($params['end_date'], 'Timestamp'),
);
CRM_Core_DAO::executeQuery($query, $relParams);
}
}
}
elseif (CRM_Utils_Array::value($params['case_status_id'], $groupingValues) == 'Opened') {
$params['end_date'] = "null";
// Reopen case-specific relationships (roles)
foreach ($params['target_contact_id'] as $cid) {
$rels = CRM_Case_BAO_Case::getCaseRoles($cid, $params['case_id']);
// FIXME: Is there an existing function?
$query = 'UPDATE civicrm_relationship SET end_date=NULL WHERE id=%1';
foreach ($rels as $relId => $relData) {
$relParams = array(1 => array($relId, 'Integer'));
CRM_Core_DAO::executeQuery($query, $relParams);
}
}
}
$params['status_id'] = CRM_Core_OptionGroup::getValue('activity_status', 'Completed', 'name');
$activity->status_id = $params['status_id'];
$params['priority_id'] = CRM_Core_OptionGroup::getValue('priority', 'Normal', 'name');
$activity->priority_id = $params['priority_id'];
foreach ($form->_oldCaseStatus as $statuskey => $statusval) {
if ($activity->subject == 'null') {
$activity->subject = ts('Case status changed from %1 to %2', array(
1 => CRM_Utils_Array::value($statusval, $form->_caseStatus),
2 => CRM_Utils_Array::value($params['case_status_id'], $form->_caseStatus),
)
);
$activity->save();
}
}
}
}

View file

@ -0,0 +1,194 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
/**
* This class generates form components for OpenCase Activity.
*/
class CRM_Case_Form_Activity_ChangeCaseType {
/**
* @param CRM_Core_Form $form
*
* @throws Exception
*/
public static function preProcess(&$form) {
if (!isset($form->_caseId)) {
CRM_Core_Error::fatal(ts('Case Id not found.'));
}
}
/**
* Set default values for the form.
*
* For edit/view mode the default values are retrieved from the database.
*
* @param CRM_Core_Form $form
*
* @return array
*/
public static function setDefaultValues(&$form) {
$defaults = array();
$defaults['is_reset_timeline'] = 1;
$defaults['reset_date_time'] = array();
list($defaults['reset_date_time'], $defaults['reset_date_time_time']) = CRM_Utils_Date::setDateDefaults(NULL, 'activityDateTime');
$defaults['case_type_id'] = $form->_caseTypeId;
return $defaults;
}
/**
* @param CRM_Core_Form $form
*/
public static function buildQuickForm(&$form) {
$form->removeElement('status_id');
$form->removeElement('priority_id');
$caseId = CRM_Utils_Array::first($form->_caseId);
$form->_caseType = CRM_Case_BAO_Case::buildOptions('case_type_id', 'create');
$form->_caseTypeId = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_Case',
$caseId,
'case_type_id'
);
if (!in_array($form->_caseTypeId, $form->_caseType)) {
$form->_caseType[$form->_caseTypeId] = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_CaseType', $form->_caseTypeId, 'title');
}
$form->addField('case_type_id', array('context' => 'create', 'entity' => 'Case'));
// timeline
$form->addYesNo('is_reset_timeline', ts('Reset Case Timeline?'), NULL, TRUE, array('onclick' => "return showHideByValue('is_reset_timeline','','resetTimeline','table-row','radio',false);"));
$form->addDateTime('reset_date_time', ts('Reset Start Date'), FALSE, array('formatType' => 'activityDateTime'));
}
/**
* Global validation rules for the form.
*
* @param array $values
* Posted values of the form.
*
* @param $files
* @param CRM_Core_Form $form
*
* @return array
* list of errors to be posted back to the form
*/
public static function formRule($values, $files, $form) {
return TRUE;
}
/**
* Process the form submission.
*
*
* @param CRM_Core_Form $form
* @param array $params
*/
public static function beginPostProcess(&$form, &$params) {
if ($form->_context == 'case') {
$params['id'] = $form->_id;
}
if (CRM_Utils_Array::value('is_reset_timeline', $params) == 0) {
unset($params['reset_date_time']);
}
else {
// store the date with proper format
$params['reset_date_time'] = CRM_Utils_Date::processDate($params['reset_date_time'], $params['reset_date_time_time']);
}
}
/**
* Process the form submission.
*
*
* @param CRM_Core_Form $form
* @param array $params
* @param $activity
*/
public static function endPostProcess(&$form, &$params, $activity) {
if (!$form->_caseId) {
// always expecting a change, so case-id is a must.
return;
}
$caseTypes = CRM_Case_PseudoConstant::caseType('name');
$allCaseTypes = CRM_Case_PseudoConstant::caseType('title', FALSE);
if (!empty($caseTypes[$params['case_type_id']])) {
$caseType = $caseTypes[$params['case_type_id']];
}
if (!$form->_currentlyViewedContactId ||
!$form->_currentUserId ||
!$params['case_type_id'] ||
!$caseType
) {
CRM_Core_Error::fatal('Required parameter missing for ChangeCaseType - end post processing');
}
$params['status_id'] = CRM_Core_OptionGroup::getValue('activity_status', 'Completed', 'name');
$activity->status_id = $params['status_id'];
$params['priority_id'] = CRM_Core_OptionGroup::getValue('priority', 'Normal', 'name');
$activity->priority_id = $params['priority_id'];
if ($activity->subject == 'null') {
$activity->subject = ts('Case type changed from %1 to %2',
array(
1 => CRM_Utils_Array::value($form->_defaults['case_type_id'], $allCaseTypes),
2 => CRM_Utils_Array::value($params['case_type_id'], $allCaseTypes),
)
);
$activity->save();
}
// 1. initiate xml processor
$xmlProcessor = new CRM_Case_XMLProcessor_Process();
$caseId = CRM_Utils_Array::first($form->_caseId);
$xmlProcessorParams = array(
'clientID' => $form->_currentlyViewedContactId,
'creatorID' => $form->_currentUserId,
'standardTimeline' => 1,
'activityTypeName' => 'Change Case Type',
'activity_date_time' => CRM_Utils_Array::value('reset_date_time', $params),
'caseID' => $caseId,
'resetTimeline' => CRM_Utils_Array::value('is_reset_timeline', $params),
);
$xmlProcessor->run($caseType, $xmlProcessorParams);
// status msg
$params['statusMsg'] = ts('Case Type changed successfully.');
}
}

View file

@ -0,0 +1,163 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
/**
* This class generates form components for LinkCase Activity.
*/
class CRM_Case_Form_Activity_LinkCases {
/**
* @param CRM_Core_Form $form
*
* @throws Exception
*/
public static function preProcess(&$form) {
if (empty($form->_caseId)) {
CRM_Core_Error::fatal(ts('Case Id not found.'));
}
if (count($form->_caseId) != 1) {
CRM_Core_Resources::fatal(ts('Expected one case-type'));
}
$caseId = CRM_Utils_Array::first($form->_caseId);
$form->assign('clientID', $form->_currentlyViewedContactId);
$form->assign('sortName', CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $form->_currentlyViewedContactId, 'sort_name'));
$form->assign('caseTypeLabel', CRM_Case_BAO_Case::getCaseType($caseId));
// get the related cases for given case.
$relatedCases = $form->get('relatedCases');
if (!isset($relatedCases)) {
$relatedCases = CRM_Case_BAO_Case::getRelatedCases($caseId);
$form->set('relatedCases', empty($relatedCases) ? FALSE : $relatedCases);
}
}
/**
* Set default values for the form.
*
* @param CRM_Core_Form $form
*
* @return array
*/
public static function setDefaultValues(&$form) {
$defaults = array();
if (!empty($_GET['link_to_case_id']) && CRM_Utils_Rule::positiveInteger($_GET['link_to_case_id'])) {
$defaults['link_to_case_id'] = $_GET['link_to_case_id'];
}
return $defaults;
}
/**
* @param CRM_Core_Form $form
*/
public static function buildQuickForm(&$form) {
$excludeCaseIds = (array) $form->_caseId;
$relatedCases = $form->get('relatedCases');
if (is_array($relatedCases) && !empty($relatedCases)) {
$excludeCaseIds = array_merge($excludeCaseIds, array_keys($relatedCases));
}
$form->addEntityRef('link_to_case_id', ts('Link To Case'), array(
'entity' => 'Case',
'api' => array(
'extra' => array('case_id.case_type_id.title', 'contact_id.sort_name'),
'params' => array(
'case_id' => array('NOT IN' => $excludeCaseIds),
'case_id.is_deleted' => 0,
),
),
), TRUE);
}
/**
* Global validation rules for the form.
*
* @param array $values
* Posted values of the form.
*
* @param $files
* @param CRM_Core_Form $form
*
* @return array
* list of errors to be posted back to the form
*/
public static function formRule($values, $files, $form) {
$errors = array();
$linkCaseId = CRM_Utils_Array::value('link_to_case_id', $values);
assert('is_numeric($linkCaseId)');
if ($linkCaseId == CRM_Utils_Array::first($form->_caseId)) {
$errors['link_to_case'] = ts('Please select some other case to link.');
}
// do check for existing related cases.
$relatedCases = $form->get('relatedCases');
if (is_array($relatedCases) && array_key_exists($linkCaseId, $relatedCases)) {
$errors['link_to_case'] = ts('Selected case is already linked.');
}
return empty($errors) ? TRUE : $errors;
}
/**
* Process the form submission.
*
*
* @param CRM_Core_Form $form
* @param array $params
*/
public static function beginPostProcess(&$form, &$params) {
}
/**
* Process the form submission.
*
*
* @param CRM_Core_Form $form
* @param array $params
* @param CRM_Activity_BAO_Activity $activity
*/
public static function endPostProcess(&$form, &$params, &$activity) {
$activityId = $activity->id;
$linkCaseID = CRM_Utils_Array::value('link_to_case_id', $params);
//create a link between two cases.
if ($activityId && $linkCaseID) {
$caseParams = array(
'case_id' => $linkCaseID,
'activity_id' => $activityId,
);
CRM_Case_BAO_Case::processCaseActivity($caseParams);
}
}
}

View file

@ -0,0 +1,368 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
/**
* This class generates form components for OpenCase Activity.
*/
class CRM_Case_Form_Activity_OpenCase {
/**
* The id of the client associated with this case.
*
* @var int
*/
public $_contactID;
/**
* @param CRM_Core_Form $form
*/
public static function preProcess(&$form) {
//get multi client case configuration
$xmlProcessorProcess = new CRM_Case_XMLProcessor_Process();
$form->_allowMultiClient = (bool) $xmlProcessorProcess->getAllowMultipleCaseClients();
if ($form->_context == 'caseActivity') {
$contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $form);
$atype = CRM_Core_OptionGroup::getValue('activity_type',
'Change Case Start Date',
'name'
);
$caseId = CRM_Utils_Array::first($form->_caseId);
$form->assign('changeStartURL', CRM_Utils_System::url('civicrm/case/activity',
"action=add&reset=1&cid=$contactID&caseid={$caseId}&atype=$atype"
)
);
return;
}
$form->_context = CRM_Utils_Request::retrieve('context', 'String', $form);
$form->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $form);
$form->assign('context', $form->_context);
// check if the case type id passed in url is a valid one
$caseTypeId = CRM_Utils_Request::retrieve('ctype', 'Positive', $form);
$caseTypes = CRM_Case_BAO_Case::buildOptions('case_type_id', 'create');
$form->_caseTypeId = array_key_exists($caseTypeId, $caseTypes) ? $caseTypeId : NULL;
// check if the case status id passed in url is a valid one
$caseStatusId = CRM_Utils_Request::retrieve('case_status_id', 'Positive', $form);
$caseStatus = CRM_Case_PseudoConstant::caseStatus();
$form->_caseStatusId = array_key_exists($caseStatusId, $caseStatus) ? $caseStatusId : NULL;
// Add attachments
CRM_Core_BAO_File::buildAttachment($form, 'civicrm_activity', $form->_activityId);
$session = CRM_Core_Session::singleton();
$session->pushUserContext(CRM_Utils_System::url('civicrm/case', 'reset=1'));
}
/**
* Set default values for the form. For edit/view mode
* the default values are retrieved from the database
*
*
* @param CRM_Core_Form $form
*/
public static function setDefaultValues(&$form) {
$defaults = array();
if ($form->_context == 'caseActivity') {
return $defaults;
}
list($defaults['start_date'], $defaults['start_date_time']) = CRM_Utils_Date::setDateDefaults(NULL, 'activityDateTime');
// set default case status, case type, encounter medium, location type and phone type defaults are set in DB
if ($form->_caseStatusId) {
$caseStatus = $form->_caseStatusId;
}
else {
$caseStatus = CRM_Core_OptionGroup::values('case_status', FALSE, FALSE, FALSE, 'AND is_default = 1');
if (count($caseStatus) == 1) {
$caseStatus = key($caseStatus); //$defaults['status_id'] = key($caseStatus);
}
}
$defaults['status_id'] = $caseStatus;
// set default case type passed in url
if ($form->_caseTypeId) {
$defaults['case_type_id'] = $form->_caseTypeId;
}
else {
// TODO: Not possible yet to set a default case type in the system
// For now just add the convenience of auto-selecting if there is only one option
$caseTypes = CRM_Case_BAO_Case::buildOptions('case_type_id', 'create');
if (count($caseTypes) == 1) {
reset($caseTypes);
$defaults['case_type_id'] = key($caseTypes);
}
}
$medium = CRM_Core_OptionGroup::values('encounter_medium', FALSE, FALSE, FALSE, 'AND is_default = 1');
if (count($medium) == 1) {
$defaults['medium_id'] = key($medium);
}
$defaultLocationType = CRM_Core_BAO_LocationType::getDefault();
if ($defaultLocationType->id) {
$defaults['location[1][location_type_id]'] = $defaultLocationType->id;
}
$phoneType = CRM_Core_OptionGroup::values('phone_type', FALSE, FALSE, FALSE, 'AND is_default = 1');
if (count($phoneType) == 1) {
$defaults['location[1][phone][1][phone_type_id]'] = key($phoneType);
}
return $defaults;
}
/**
* @param CRM_Case_Form_Case $form
*/
public static function buildQuickForm(&$form) {
if ($form->_context == 'caseActivity') {
return;
}
if ($form->_context == 'standalone') {
$form->addEntityRef('client_id', ts('Client'), array(
'create' => TRUE,
'multiple' => $form->_allowMultiClient,
), TRUE);
}
$element = $form->addField('case_type_id', array(
'context' => 'create',
'entity' => 'Case',
'onchange' => "CRM.buildCustomData('Case', this.value);",
), TRUE);
if ($form->_caseTypeId) {
$element->freeze();
}
$csElement = $form->addField('status_id', array(
'context' => 'create',
'entity' => 'Case',
), TRUE);
if ($form->_caseStatusId) {
$csElement->freeze();
}
$form->add('text', 'duration', ts('Activity Duration'), array('size' => 4, 'maxlength' => 8));
$form->addRule('duration', ts('Please enter the duration as number of minutes (integers only).'), 'positiveInteger');
if ($form->_currentlyViewedContactId) {
list($displayName) = CRM_Contact_BAO_Contact::getDisplayAndImage($form->_currentlyViewedContactId);
$form->assign('clientName', $displayName);
}
$form->addDate('start_date', ts('Case Start Date'), TRUE, array('formatType' => 'activityDateTime'));
$form->addField('medium_id', array('entity' => 'activity', 'context' => 'create'), TRUE);
// calling this field activity_location to prevent conflict with contact location fields
$form->add('text', 'activity_location', ts('Location'), CRM_Core_DAO::getAttribute('CRM_Activity_DAO_Activity', 'location'));
$form->add('wysiwyg', 'activity_details', ts('Details'), array('rows' => 4, 'cols' => 60), FALSE);
$form->addButtons(array(
array(
'type' => 'upload',
'name' => ts('Save'),
'isDefault' => TRUE,
),
array(
'type' => 'upload',
'name' => ts('Save and New'),
'subName' => 'new',
),
array(
'type' => 'cancel',
'name' => ts('Cancel'),
),
)
);
}
/**
* Process the form submission.
*
*
* @param CRM_Core_Form $form
* @param array $params
*/
public static function beginPostProcess(&$form, &$params) {
if ($form->_context == 'caseActivity') {
return;
}
if ($form->_context == 'standalone') {
$params['client_id'] = explode(',', $params['client_id']);
$form->_currentlyViewedContactId = $params['client_id'][0];
}
// for open case start date should be set to current date
$params['start_date'] = CRM_Utils_Date::processDate($params['start_date'], $params['start_date_time']);
$caseStatus = CRM_Case_PseudoConstant::caseStatus('name');
// for resolved case the end date should set to now
if ($params['status_id'] == array_search('Closed', $caseStatus)) {
$params['end_date'] = $params['now'];
}
// rename activity_location param to the correct column name for activity DAO
$params['location'] = CRM_Utils_Array::value('activity_location', $params);
// Add attachments
CRM_Core_BAO_File::formatAttachment(
$params,
$params,
'civicrm_activity',
$form->_activityId
);
}
/**
* Global validation rules for the form.
*
* @param $fields
* @param $files
* @param CRM_Core_Form $form
*
* @return array
* list of errors to be posted back to the form
*/
public static function formRule($fields, $files, $form) {
if ($form->_context == 'caseActivity') {
return TRUE;
}
$errors = array();
return $errors;
}
/**
* Process the form submission.
*
* @param CRM_Core_Form $form
* @param array $params
*/
public static function endPostProcess(&$form, &$params) {
if ($form->_context == 'caseActivity') {
return;
}
$xmlProcessorProcess = new CRM_Case_XMLProcessor_Process();
$isMultiClient = $xmlProcessorProcess->getAllowMultipleCaseClients();
if (!$isMultiClient && !$form->_currentlyViewedContactId) {
CRM_Core_Error::fatal('Required parameter missing for OpenCase - end post processing');
}
if (!$form->_currentUserId ||
!$params['case_id'] ||
!$params['case_type']
) {
CRM_Core_Error::fatal('Required parameter missing for OpenCase - end post processing');
}
// 1. create case-contact
if ($isMultiClient && $form->_context == 'standalone') {
foreach ($params['client_id'] as $cliId) {
if (empty($cliId)) {
CRM_Core_Error::fatal('client_id cannot be empty');
}
$contactParams = array(
'case_id' => $params['case_id'],
'contact_id' => $cliId,
);
CRM_Case_BAO_CaseContact::create($contactParams);
}
}
else {
$contactParams = array(
'case_id' => $params['case_id'],
'contact_id' => $form->_currentlyViewedContactId,
);
CRM_Case_BAO_CaseContact::create($contactParams);
}
// 2. initiate xml processor
$xmlProcessor = new CRM_Case_XMLProcessor_Process();
$xmlProcessorParams = array(
'clientID' => $form->_currentlyViewedContactId,
'creatorID' => $form->_currentUserId,
'standardTimeline' => 1,
'activityTypeName' => 'Open Case',
'caseID' => $params['case_id'],
'subject' => $params['activity_subject'],
'location' => $params['location'],
'activity_date_time' => $params['start_date'],
'duration' => CRM_Utils_Array::value('duration', $params),
'medium_id' => $params['medium_id'],
'details' => $params['activity_details'],
);
if (array_key_exists('custom', $params) && is_array($params['custom'])) {
$xmlProcessorParams['custom'] = $params['custom'];
}
// Add parameters for attachments
$numAttachments = Civi::settings()->get('max_attachments');
for ($i = 1; $i <= $numAttachments; $i++) {
$attachName = "attachFile_$i";
if (isset($params[$attachName]) && !empty($params[$attachName])) {
$xmlProcessorParams[$attachName] = $params[$attachName];
}
}
$xmlProcessor->run($params['case_type'], $xmlProcessorParams);
// status msg
$params['statusMsg'] = ts('Case opened successfully.');
$buttonName = $form->controller->getButtonName();
$session = CRM_Core_Session::singleton();
if ($buttonName == $form->getButtonName('upload', 'new')) {
if ($form->_context == 'standalone') {
$session->replaceUserContext(CRM_Utils_System::url('civicrm/case/add',
'reset=1&action=add&context=standalone'
));
}
else {
$session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view/case',
"reset=1&action=add&context=case&cid={$form->_contactID}"
));
}
}
}
}

View file

@ -0,0 +1,114 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
/**
* This class generates form components for building activity to a case.
*/
class CRM_Case_Form_ActivityToCase extends CRM_Core_Form {
/**
* Build all the data structures needed to build the form.
*/
public function preProcess() {
$this->_activityId = CRM_Utils_Request::retrieve('activityId', 'Positive');
if (!$this->_activityId) {
CRM_Core_Error::fatal('required activity id is missing.');
}
$this->_currentCaseId = CRM_Utils_Request::retrieve('caseId', 'Positive');
$this->assign('currentCaseId', $this->_currentCaseId);
$this->assign('buildCaseActivityForm', TRUE);
}
/**
* Set default values for the form. For edit/view mode
* the default values are retrieved from the database
*
*
* @return array
*/
public function setDefaultValues() {
$defaults = array();
$params = array('id' => $this->_activityId);
CRM_Activity_BAO_Activity::retrieve($params, $defaults);
$defaults['file_on_case_activity_subject'] = $defaults['subject'];
$defaults['file_on_case_target_contact_id'] = $defaults['target_contact'];
// If this contact has an open case, supply it as a default
$cid = CRM_Utils_Request::retrieve('cid', 'Integer');
if (!$cid) {
$act = civicrm_api3('Activity', 'getsingle', array('id' => $this->_activityId, 'return' => 'target_contact_id'));
if (!empty($act['target_contact_id'])) {
$cid = $act['target_contact_id'][0];
}
}
if ($cid) {
$cases = civicrm_api3('CaseContact', 'get', array(
'contact_id' => $cid,
'case_id' => array('!=' => $this->_currentCaseId),
'case_id.status_id' => array('!=' => "Closed"),
'case_id.is_deleted' => 0,
'case_id.end_date' => array('IS NULL' => 1),
'options' => array('limit' => 1),
'return' => 'case_id',
));
foreach ($cases['values'] as $record) {
$defaults['file_on_case_unclosed_case_id'] = $record['case_id'];
break;
}
}
return $defaults;
}
/**
* Build the form object.
*/
public function buildQuickForm() {
$this->addEntityRef('file_on_case_unclosed_case_id', ts('Select Case'), array(
'entity' => 'Case',
'api' => array(
'extra' => array('contact_id'),
'params' => array(
'case_id' => array('!=' => $this->_currentCaseId),
'case_id.is_deleted' => 0,
'case_id.status_id' => array('!=' => "Closed"),
'case_id.end_date' => array('IS NULL' => 1),
),
),
), TRUE);
$this->addEntityRef('file_on_case_target_contact_id', ts('With Contact(s)'), array('multiple' => TRUE));
$this->add('text', 'file_on_case_activity_subject', ts('Subject'), array('size' => 50));
}
}

View file

@ -0,0 +1,177 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
/**
* This class does pre processing for viewing an activity or their revisions.
*/
class CRM_Case_Form_ActivityView extends CRM_Core_Form {
/**
* Process the view.
*/
public function preProcess() {
$contactID = CRM_Utils_Request::retrieve('cid', 'Integer', $this, TRUE);
$activityID = CRM_Utils_Request::retrieve('aid', 'Integer', $this, TRUE);
$revs = CRM_Utils_Request::retrieve('revs', 'Boolean');
$caseID = CRM_Utils_Request::retrieve('caseID', 'Boolean');
$activitySubject = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity',
$activityID,
'subject'
);
//check for required permissions, CRM-6264
if ($activityID &&
!CRM_Activity_BAO_Activity::checkPermission($activityID, CRM_Core_Action::VIEW)
) {
CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
}
$this->assign('contactID', $contactID);
$this->assign('caseID', $caseID);
// CRM-9145
$this->assign('activityID', $activityID);
$xmlProcessor = new CRM_Case_XMLProcessor_Report();
$report = $xmlProcessor->getActivityInfo($contactID, $activityID, TRUE);
$attachmentUrl = CRM_Core_BAO_File::attachmentInfo('civicrm_activity', $activityID);
if ($attachmentUrl) {
$report['fields'][] = array(
'label' => 'Attachment(s)',
'value' => $attachmentUrl,
'type' => 'Link',
);
}
$tags = CRM_Core_BAO_EntityTag::getTag($activityID, 'civicrm_activity');
if (!empty($tags)) {
$allTag = CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
foreach ($tags as $tid) {
$tags[$tid] = $allTag[$tid];
}
$report['fields'][] = array(
'label' => 'Tags',
'value' => implode('<br />', $tags),
'type' => 'String',
);
}
$this->assign('report', $report);
$latestRevisionID = CRM_Activity_BAO_Activity::getLatestActivityId($activityID);
$viewPriorActivities = array();
$priorActivities = CRM_Activity_BAO_Activity::getPriorAcitivities($activityID);
foreach ($priorActivities as $activityId => $activityValues) {
if (CRM_Case_BAO_Case::checkPermission($activityId, 'view', NULL, $contactID)) {
$viewPriorActivities[$activityId] = $activityValues;
}
}
if ($revs) {
CRM_Utils_System::setTitle(ts('Activity Revision History'));
$this->assign('revs', $revs);
$this->assign('result', $viewPriorActivities);
$this->assign('subject', $activitySubject);
$this->assign('latestRevisionID', $latestRevisionID);
}
else {
if (count($viewPriorActivities) > 1) {
$this->assign('activityID', $activityID);
}
if ($latestRevisionID != $activityID) {
$this->assign('latestRevisionID', $latestRevisionID);
}
}
$parentID = CRM_Activity_BAO_Activity::getParentActivity($activityID);
if ($parentID) {
$this->assign('parentID', $parentID);
}
//viewing activity should get diplayed in recent list.CRM-4670
$activityTypeID = CRM_Core_DAO::getFieldValue('CRM_Activity_DAO_Activity', $activityID, 'activity_type_id');
$activityContacts = CRM_Activity_BAO_ActivityContact::buildOptions('record_type_id', 'validate');
$targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
$activityTargetContacts = CRM_Activity_BAO_ActivityContact::retrieveContactIdsByActivityId($activityID, $targetID);
if (!empty($activityTargetContacts)) {
$recentContactId = $activityTargetContacts[0];
}
else {
$recentContactId = $contactID;
}
if (!isset($caseID)) {
$caseID = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_CaseActivity', $activityID, 'case_id', 'activity_id');
}
$url = CRM_Utils_System::url('civicrm/case/activity/view',
"reset=1&aid={$activityID}&cid={$recentContactId}&caseID={$caseID}&context=home"
);
$recentContactDisplay = CRM_Contact_BAO_Contact::displayName($recentContactId);
// add the recently created Activity
$activityTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE);
$title = "";
if (isset($activitySubject)) {
$title = $activitySubject . ' - ';
}
$title = $title . $recentContactDisplay . ' (' . $activityTypes[$activityTypeID] . ')';
$recentOther = array();
if (CRM_Case_BAO_Case::checkPermission($activityID, 'edit')) {
$recentOther['editUrl'] = CRM_Utils_System::url('civicrm/case/activity',
"reset=1&action=update&id={$activityID}&cid={$recentContactId}&caseid={$caseID}&context=home"
);
}
if (CRM_Case_BAO_Case::checkPermission($activityID, 'delete')) {
$recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/case/activity',
"reset=1&action=delete&id={$activityID}&cid={$recentContactId}&caseid={$caseID}&context=home"
);
}
CRM_Utils_Recent::add($title,
$url,
$activityID,
'Activity',
$recentContactId,
$recentContactDisplay,
$recentOther
);
}
}

View file

@ -0,0 +1,410 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
/**
* This class generates form components for case activity.
*/
class CRM_Case_Form_Case extends CRM_Core_Form {
/**
* The context
*
* @var string
*/
public $_context = 'case';
/**
* Case Id
*/
public $_caseId = NULL;
/**
* Client Id
*/
public $_currentlyViewedContactId = NULL;
/**
* Activity Type File
*/
public $_activityTypeFile = NULL;
/**
* Logged in contact Id
*/
public $_currentUserId = NULL;
/**
* Activity type Id
*/
public $_activityTypeId = NULL;
/**
* Activity type Id
*/
public $_activityId = NULL;
/**
* Action
*/
public $_action;
/**
* Case type id
*/
public $_caseTypeId = NULL;
/**
* Build the form object.
*/
public function preProcess() {
$this->_caseId = CRM_Utils_Request::retrieve('id', 'Positive', $this);
$this->_currentlyViewedContactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
if ($this->_action & CRM_Core_Action::ADD && !$this->_currentlyViewedContactId) {
// check for add contacts permissions
if (!CRM_Core_Permission::check('add contacts')) {
CRM_Utils_System::permissionDenied();
return;
}
}
//CRM-4418
if (!CRM_Core_Permission::checkActionPermission('CiviCase', $this->_action)) {
CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
}
if ($this->_action & CRM_Core_Action::DELETE || $this->_action & CRM_Core_Action::RENEW) {
return TRUE;
}
if (!$this->_caseId) {
$caseAttributes = array(
'case_type_id' => ts('Case Type'),
'status_id' => ts('Case Status'),
'medium_id' => ts('Activity Medium'),
);
foreach ($caseAttributes as $key => $label) {
if (!CRM_Case_BAO_Case::buildOptions($key, 'create')) {
CRM_Core_Error::fatal(ts('You do not have any active %1', array(1 => $label)));
}
}
}
if ($this->_action & CRM_Core_Action::ADD) {
$this->_activityTypeId = CRM_Core_OptionGroup::getValue('activity_type',
'Open Case',
'name'
);
if (!$this->_activityTypeId) {
CRM_Core_Error::fatal(ts('The Open Case activity type is missing or disabled. Please have your site administrator check Administer > Option Lists > Activity Types for the CiviCase component.'));
}
}
//check for case permissions.
if (!CRM_Case_BAO_Case::accessCiviCase()) {
CRM_Core_Error::fatal(ts('You are not authorized to access this page.'));
}
if (($this->_action & CRM_Core_Action::ADD) &&
(!CRM_Core_Permission::check('access all cases and activities') &&
!CRM_Core_Permission::check('add cases')
)
) {
CRM_Core_Error::fatal(ts('You are not authorized to access this page.'));
}
if ($this->_activityTypeFile = CRM_Activity_BAO_Activity::getFileForActivityTypeId($this->_activityTypeId,
'Case'
)
) {
$this->assign('activityTypeFile', $this->_activityTypeFile);
}
$details = CRM_Case_PseudoConstant::caseActivityType(FALSE);
CRM_Utils_System::setTitle($details[$this->_activityTypeId]['label']);
$this->assign('activityType', $details[$this->_activityTypeId]['label']);
$this->assign('activityTypeDescription', $details[$this->_activityTypeId]['description']);
if (isset($this->_currentlyViewedContactId)) {
$contact = new CRM_Contact_DAO_Contact();
$contact->id = $this->_currentlyViewedContactId;
if (!$contact->find(TRUE)) {
CRM_Core_Error::statusBounce(ts('Client contact does not exist: %1', array(1 => $this->_currentlyViewedContactId)));
}
$this->assign('clientName', $contact->display_name);
}
$session = CRM_Core_Session::singleton();
$this->_currentUserId = $session->get('userID');
//when custom data is included in this page
CRM_Custom_Form_CustomData::preProcess($this, NULL, $this->_activityTypeId, 1, 'Activity');
$className = "CRM_Case_Form_Activity_{$this->_activityTypeFile}";
$className::preProcess($this);
$activityGroupTree = $this->_groupTree;
// for case custom fields to populate with defaults
if (!empty($_POST['hidden_custom'])) {
$params = CRM_Utils_Request::exportValues();
CRM_Custom_Form_CustomData::preProcess($this, NULL, CRM_Utils_Array::value('case_type_id', $params, $this->_caseTypeId), 1, 'Case', $this->_caseId);
CRM_Custom_Form_CustomData::buildQuickForm($this);
}
// so that grouptree is not populated with case fields, since the grouptree is used
// for populating activity custom fields.
$this->_groupTree = $activityGroupTree;
}
/**
* Set default values for the form.
*/
public function setDefaultValues() {
if ($this->_action & CRM_Core_Action::DELETE || $this->_action & CRM_Core_Action::RENEW) {
return TRUE;
}
$className = "CRM_Case_Form_Activity_{$this->_activityTypeFile}";
$defaults = $className::setDefaultValues($this);
$defaults = array_merge($defaults, CRM_Custom_Form_CustomData::setDefaultValues($this));
return $defaults;
}
public function buildQuickForm() {
$xmlProcessorProcess = new CRM_Case_XMLProcessor_Process();
$isMultiClient = $xmlProcessorProcess->getAllowMultipleCaseClients();
$this->assign('multiClient', $isMultiClient);
if ($this->_action & CRM_Core_Action::DELETE || $this->_action & CRM_Core_Action::RENEW) {
$title = 'Delete';
if ($this->_action & CRM_Core_Action::RENEW) {
$title = 'Restore';
}
$this->addButtons(array(
array(
'type' => 'next',
'name' => $title,
'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
'isDefault' => TRUE,
),
array(
'type' => 'cancel',
'name' => ts('Cancel'),
),
)
);
return;
}
//need to assign custom data type and subtype to the template
$this->assign('customDataType', 'Case');
CRM_Custom_Form_CustomData::buildQuickForm($this);
// we don't want to show button on top of custom form
$this->assign('noPreCustomButton', TRUE);
$s = CRM_Core_DAO::getAttribute('CRM_Activity_DAO_Activity', 'subject');
if (!is_array($s)) {
$s = array();
}
$this->add('text', 'activity_subject', ts('Subject'),
array_merge($s, array(
'maxlength' => '128',
)), TRUE
);
$tags = CRM_Core_BAO_Tag::getColorTags('civicrm_case');
if (!empty($tags)) {
$this->add('select2', 'tag', ts('Tags'), $tags, FALSE,
array('class' => 'huge', 'multiple' => 'multiple')
);
}
// build tag widget
$parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_case');
CRM_Core_Form_Tag::buildQuickForm($this, $parentNames, 'civicrm_case', NULL, FALSE, TRUE);
$this->addButtons(array(
array(
'type' => 'next',
'name' => ts('Save'),
'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
'isDefault' => TRUE,
),
array(
'type' => 'cancel',
'name' => ts('Cancel'),
),
)
);
$className = "CRM_Case_Form_Activity_{$this->_activityTypeFile}";
$className::buildQuickForm($this);
}
/**
* Add local and global form rules.
*
* @return bool
*/
public function addRules() {
if ($this->_action & CRM_Core_Action::DELETE || $this->_action & CRM_Core_Action::RENEW) {
return TRUE;
}
$className = "CRM_Case_Form_Activity_{$this->_activityTypeFile}";
$this->addFormRule(array($className, 'formRule'), $this);
$this->addFormRule(array('CRM_Case_Form_Case', 'formRule'), $this);
}
/**
* Global validation rules for the form.
*
* @param array $values
* Posted values of the form.
*
* @param $files
* @param CRM_Core_Form $form
*
* @return array
* list of errors to be posted back to the form
*/
public static function formRule($values, $files, $form) {
return TRUE;
}
/**
* Process the form submission.
*/
public function postProcess() {
$transaction = new CRM_Core_Transaction();
// check if dedupe button, if so return.
$buttonName = $this->controller->getButtonName();
if (isset($this->_dedupeButtonName) && $buttonName == $this->_dedupeButtonName) {
return;
}
if ($this->_action & CRM_Core_Action::DELETE) {
$caseDelete = CRM_Case_BAO_Case::deleteCase($this->_caseId, TRUE);
if ($caseDelete) {
CRM_Core_Session::setStatus(ts('You can view and / or restore deleted cases by checking the "Deleted Cases" option under Find Cases.'), ts('Case Deleted'), 'success');
}
return;
}
if ($this->_action & CRM_Core_Action::RENEW) {
$caseRestore = CRM_Case_BAO_Case::restoreCase($this->_caseId);
if ($caseRestore) {
CRM_Core_Session::setStatus(ts('The selected case has been restored.'), ts('Restored'), 'success');
}
return;
}
// store the submitted values in an array
$params = $this->controller->exportValues($this->_name);
$params['now'] = date("Ymd");
// 1. call begin post process
if ($this->_activityTypeFile) {
$className = "CRM_Case_Form_Activity_{$this->_activityTypeFile}";
$className::beginPostProcess($this, $params);
}
if (!empty($params['hidden_custom']) &&
!isset($params['custom'])
) {
$params['custom'] = CRM_Core_BAO_CustomField::postProcess(
$params,
NULL,
'Case'
);
}
// 2. create/edit case
if (!empty($params['case_type_id'])) {
$params['case_type'] = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_CaseType', $params['case_type_id'], 'name', 'id');
$params['subject'] = $params['activity_subject'];
}
$caseObj = CRM_Case_BAO_Case::create($params);
$params['case_id'] = $caseObj->id;
// unset any ids, custom data
unset($params['id'], $params['custom']);
// add tags if exists
$tagParams = array();
if (!empty($params['tag'])) {
$tagParams = array();
if (!is_array($params['tag'])) {
$params['tag'] = explode(',', $params['tag']);
}
foreach ($params['tag'] as $tag) {
$tagParams[$tag] = 1;
}
}
CRM_Core_BAO_EntityTag::create($tagParams, 'civicrm_case', $caseObj->id);
//save free tags
if (isset($params['case_taglist']) && !empty($params['case_taglist'])) {
CRM_Core_Form_Tag::postProcess($params['case_taglist'], $caseObj->id, 'civicrm_case', $this);
}
// user context
$url = CRM_Utils_System::url('civicrm/contact/view/case',
"reset=1&action=view&cid={$this->_currentlyViewedContactId}&id={$caseObj->id}"
);
CRM_Core_Session::singleton()->pushUserContext($url);
// 3. format activity custom data
if (!empty($params['hidden_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,
$this->_activityId,
'Activity'
);
}
// 4. call end post process
if ($this->_activityTypeFile) {
$className::endPostProcess($this, $params);
}
CRM_Core_Session::setStatus($params['statusMsg'], ts('Saved'), 'success');
}
}

View file

@ -0,0 +1,533 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
/**
* This class generates view mode for CiviCase.
*/
class CRM_Case_Form_CaseView extends CRM_Core_Form {
/**
* Check for merge cases.
* @var bool
*/
private $_mergeCases = FALSE;
/**
* Set variables up before form is built.
*/
public function preProcess() {
$this->_showRelatedCases = CRM_Utils_Array::value('relatedCases', $_GET);
$xmlProcessorProcess = new CRM_Case_XMLProcessor_Process();
$isMultiClient = $xmlProcessorProcess->getAllowMultipleCaseClients();
$this->assign('multiClient', $isMultiClient);
//pull the related cases.
$this->assign('showRelatedCases', FALSE);
if ($this->_showRelatedCases) {
$relatedCases = $this->get('relatedCases');
if (!isset($relatedCases)) {
$cId = CRM_Utils_Request::retrieve('cid', 'Integer');
$caseId = CRM_Utils_Request::retrieve('id', 'Integer');
$relatedCases = CRM_Case_BAO_Case::getRelatedCases($caseId);
}
$this->assign('relatedCases', $relatedCases);
$this->assign('showRelatedCases', TRUE);
CRM_Utils_System::setTitle(ts('Related Cases'));
return;
}
$this->_hasAccessToAllCases = CRM_Core_Permission::check('access all cases and activities');
$this->assign('hasAccessToAllCases', $this->_hasAccessToAllCases);
$this->assign('contactID', $this->_contactID = (int) $this->get('cid'));
$this->assign('caseID', $this->_caseID = (int) $this->get('id'));
// Access check.
if (!CRM_Case_BAO_Case::accessCase($this->_caseID, FALSE)) {
CRM_Core_Error::fatal(ts('You are not authorized to access this page.'));
}
$fulltext = CRM_Utils_Request::retrieve('context', 'String');
if ($fulltext == 'fulltext') {
$this->assign('fulltext', $fulltext);
}
$this->assign('contactType', CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactID, 'contact_type'));
$this->assign('userID', CRM_Core_Session::getLoggedInContactID());
//retrieve details about case
$params = array('id' => $this->_caseID);
$returnProperties = array('case_type_id', 'subject', 'status_id', 'start_date');
CRM_Core_DAO::commonRetrieve('CRM_Case_BAO_Case', $params, $values, $returnProperties);
$statuses = CRM_Case_PseudoConstant::caseStatus('label', FALSE);
$caseTypeName = CRM_Case_BAO_Case::getCaseType($this->_caseID, 'name');
$caseType = CRM_Case_BAO_Case::getCaseType($this->_caseID);
$this->_caseDetails = array(
'case_type' => $caseType,
'case_status' => CRM_Utils_Array::value($values['case_status_id'], $statuses),
'case_subject' => CRM_Utils_Array::value('subject', $values),
'case_start_date' => $values['case_start_date'],
);
$this->_caseType = $caseTypeName;
$this->assign('caseDetails', $this->_caseDetails);
$reportUrl = CRM_Utils_System::url('civicrm/case/report',
"reset=1&cid={$this->_contactID}&caseid={$this->_caseID}&asn=",
FALSE, NULL, FALSE
);
$this->assign('reportUrl', $reportUrl);
// add to recently viewed
$url = CRM_Utils_System::url('civicrm/contact/view/case',
"action=view&reset=1&id={$this->_caseID}&cid={$this->_contactID}&context=home"
);
$displayName = CRM_Contact_BAO_Contact::displayName($this->_contactID);
$this->assign('displayName', $displayName);
CRM_Utils_System::setTitle($displayName . ' - ' . $caseType);
$recentOther = array();
if (CRM_Core_Permission::checkActionPermission('CiviCase', CRM_Core_Action::DELETE)) {
$recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/case',
"action=delete&reset=1&id={$this->_caseID}&cid={$this->_contactID}&context=home"
);
}
// Add the recently viewed case
CRM_Utils_Recent::add($displayName . ' - ' . $caseType,
$url,
$this->_caseID,
'Case',
$this->_contactID,
NULL,
$recentOther
);
//get the related cases for given case.
$relatedCases = $this->get('relatedCases');
if (!isset($relatedCases)) {
$relatedCases = CRM_Case_BAO_Case::getRelatedCases($this->_caseID);
$relatedCases = empty($relatedCases) ? FALSE : $relatedCases;
$this->set('relatedCases', $relatedCases);
}
$this->assign('hasRelatedCases', (bool) $relatedCases);
if ($relatedCases) {
$this->assign('relatedCaseLabel', ts('%1 Related Case', array(
'count' => count($relatedCases),
'plural' => '%1 Related Cases',
)));
$this->assign('relatedCaseUrl', CRM_Utils_System::url('civicrm/contact/view/case', array(
'id' => $this->_caseID,
'cid' => $this->_contactID,
'relatedCases' => 1,
'action' => 'view',
)));
}
$entitySubType = !empty($values['case_type_id']) ? $values['case_type_id'] : NULL;
$this->assign('caseTypeID', $entitySubType);
$groupTree = CRM_Core_BAO_CustomGroup::getTree('Case',
NULL,
$this->_caseID,
NULL,
$entitySubType
);
CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $this->_caseID);
}
/**
* Set default values for the form.
*
* @return array;
*/
public function setDefaultValues() {
$defaults = array();
return $defaults;
}
/**
* Build the form object.
*/
public function buildQuickForm() {
//this call is for show related cases.
if ($this->_showRelatedCases) {
return;
}
$allowedRelationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType($this->_contactID);
CRM_Core_Resources::singleton()
->addScriptFile('civicrm', 'js/crm.livePage.js', 1, 'html-header')
->addScriptFile('civicrm', 'templates/CRM/Case/Form/CaseView.js', 2, 'html-header')
->addVars('relationshipTypes', CRM_Contact_Form_Relationship::getRelationshipTypeMetadata($allowedRelationshipTypes));
$xmlProcessor = new CRM_Case_XMLProcessor_Process();
$caseRoles = $xmlProcessor->get($this->_caseType, 'CaseRoles');
$reports = $xmlProcessor->get($this->_caseType, 'ActivitySets');
//adding case manager.CRM-4510.
$managerRoleId = $xmlProcessor->getCaseManagerRoleId($this->_caseType);
if (!empty($managerRoleId)) {
$caseRoles[$managerRoleId] = $caseRoles[$managerRoleId] . '<br />' . '(' . ts('Case Manager') . ')';
}
$aTypes = $xmlProcessor->get($this->_caseType, 'ActivityTypes', TRUE);
$allActTypes = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'name');
$emailActivityType = array_search('Email', $allActTypes);
$pdfActivityType = array_search('Print PDF Letter', $allActTypes);
if ($pdfActivityType) {
$this->assign('exportDoc', CRM_Utils_System::url('civicrm/activity/pdf/add',
"action=add&context=standalone&reset=1&cid={$this->_contactID}&caseid={$this->_caseID}&atype=$pdfActivityType"));
}
// remove Open Case activity type since we're inside an existing case
if ($openActTypeId = array_search('Open Case', $allActTypes)) {
unset($aTypes[$openActTypeId]);
}
// Only show "link cases" activity if other cases exist.
$linkActTypeId = array_search('Link Cases', $allActTypes);
if ($linkActTypeId) {
$count = civicrm_api3('Case', 'getcount', array(
'check_permissions' => TRUE,
'id' => array('!=' => $this->_caseID),
'is_deleted' => 0,
));
if (!$count) {
unset($aTypes[$linkActTypeId]);
}
}
if (!$xmlProcessor->getNaturalActivityTypeSort()) {
asort($aTypes);
}
$activityLinks = array('' => ts('Add Activity'));
foreach ($aTypes as $type => $label) {
if ($type == $emailActivityType) {
$url = CRM_Utils_System::url('civicrm/activity/email/add',
"action=add&context=standalone&reset=1&caseid={$this->_caseID}&atype=$type",
FALSE, NULL, FALSE
);
}
elseif ($type == $pdfActivityType) {
$url = CRM_Utils_System::url('civicrm/activity/pdf/add',
"action=add&context=standalone&reset=1&cid={$this->_contactID}&caseid={$this->_caseID}&atype=$type",
FALSE, NULL, FALSE);
}
else {
$url = CRM_Utils_System::url('civicrm/case/activity',
"action=add&reset=1&cid={$this->_contactID}&caseid={$this->_caseID}&atype=$type",
FALSE, NULL, FALSE
);
}
$activityLinks[$url] = $label;
}
$this->add('select', 'add_activity_type_id', '', $activityLinks, FALSE, array('class' => 'crm-select2 crm-action-menu fa-calendar-check-o twenty'));
if ($this->_hasAccessToAllCases) {
$this->add('select', 'report_id', '',
array('' => ts('Activity Audit')) + $reports,
FALSE,
array('class' => 'crm-select2 crm-action-menu fa-list-alt')
);
$this->add('select', 'timeline_id', '',
array('' => ts('Add Timeline')) + $reports,
FALSE,
array('class' => 'crm-select2 crm-action-menu fa-list-ol')
);
}
$this->addElement('submit', $this->getButtonName('next'), ' ', array('class' => 'hiddenElement'));
$this->buildMergeCaseForm();
//call activity form
self::activityForm($this, $aTypes);
//get case related relationships (Case Role)
$caseRelationships = CRM_Case_BAO_Case::getCaseRoles($this->_contactID, $this->_caseID);
//save special label because we unset it in the loop
$managerLabel = empty($managerRoleId) ? '' : $caseRoles[$managerRoleId];
foreach ($caseRelationships as $key => & $value) {
if (!empty($managerRoleId)) {
if ($managerRoleId == $value['relation_type']) {
$value['relation'] = $managerLabel;
}
}
//calculate roles that don't have relationships
if (!empty($caseRoles[$value['relation_type']])) {
unset($caseRoles[$value['relation_type']]);
}
}
$this->assign('caseRelationships', $caseRelationships);
//also add client as role. CRM-4438
$caseRoles['client'] = CRM_Case_BAO_Case::getContactNames($this->_caseID);
$this->assign('caseRoles', $caseRoles);
// Retrieve ALL client relationships
$relClient = CRM_Contact_BAO_Relationship::getRelationship($this->_contactID,
CRM_Contact_BAO_Relationship::CURRENT,
0, 0, 0, NULL, NULL, FALSE
);
// Now build 'Other Relationships' array by removing relationships that are already listed under Case Roles
// so they don't show up twice.
$clientRelationships = array();
foreach ($relClient as $r) {
if (!array_key_exists($r['id'], $caseRelationships)) {
$clientRelationships[] = $r;
}
}
$this->assign('clientRelationships', $clientRelationships);
// Now global contact list that appears on all cases.
$globalGroupInfo = array();
CRM_Case_BAO_Case::getGlobalContacts($globalGroupInfo);
$this->assign('globalGroupInfo', $globalGroupInfo);
// List relationship types for adding an arbitrary new role to the case
$this->add('select',
'role_type',
ts('Relationship Type'),
array('' => ts('- select type -')) + $allowedRelationshipTypes,
FALSE,
array('class' => 'crm-select2 twenty', 'data-select-params' => '{"allowClear": false}')
);
$hookCaseSummary = CRM_Utils_Hook::caseSummary($this->_caseID);
if (is_array($hookCaseSummary)) {
$this->assign('hookCaseSummary', $hookCaseSummary);
}
$allTags = CRM_Core_BAO_Tag::getColorTags('civicrm_case');
if (!empty($allTags)) {
$this->add('select2', 'case_tag', ts('Tags'), $allTags, FALSE,
array('id' => 'tags', 'multiple' => 'multiple')
);
$tags = CRM_Core_BAO_EntityTag::getTag($this->_caseID, 'civicrm_case');
foreach ($tags as $tid) {
$tagInfo = CRM_Utils_Array::findInTree($tid, $allTags);
if ($tagInfo) {
$tags[$tid] = $tagInfo;
}
else {
unset($tags[$tid]);
}
}
$this->setDefaults(array('case_tag' => implode(',', array_keys($tags))));
$this->assign('tags', $tags);
$this->assign('showTags', TRUE);
}
else {
$this->assign('showTags', FALSE);
}
// build tagset widget
// see if we have any tagsets which can be assigned to cases
$parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_case');
$tagSetTags = array();
if ($parentNames) {
$this->assign('showTags', TRUE);
$tagSetItems = civicrm_api3('entityTag', 'get', array(
'entity_id' => $this->_caseID,
'entity_table' => 'civicrm_case',
'tag_id.parent_id.is_tagset' => 1,
'options' => array('limit' => 0),
'return' => array("tag_id.parent_id", "tag_id.parent_id.name", "tag_id.name"),
));
foreach ($tagSetItems['values'] as $tag) {
$tagSetTags += array(
$tag['tag_id.parent_id'] => array(
'name' => $tag['tag_id.parent_id.name'],
'items' => array(),
),
);
$tagSetTags[$tag['tag_id.parent_id']]['items'][] = $tag['tag_id.name'];
}
}
$this->assign('tagSetTags', $tagSetTags);
CRM_Core_Form_Tag::buildQuickForm($this, $parentNames, 'civicrm_case', $this->_caseID, FALSE, TRUE);
$this->addButtons(array(
array(
'type' => 'cancel',
'name' => ts('Done'),
'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
'isDefault' => TRUE,
),
)
);
}
/**
* Process the form.
*/
public function postProcess() {
$params = $this->controller->exportValues($this->_name);
$buttonName = $this->controller->getButtonName();
// user context
$url = CRM_Utils_System::url('civicrm/contact/view/case',
"reset=1&action=view&cid={$this->_contactID}&id={$this->_caseID}&show=1"
);
$session = CRM_Core_Session::singleton();
$session->pushUserContext($url);
if (!empty($params['timeline_id']) && !empty($_POST['_qf_CaseView_next'])) {
civicrm_api3('Case', 'addtimeline', array(
'case_id' => $this->_caseID,
'timeline' => $params['timeline_id'],
));
$xmlProcessor = new CRM_Case_XMLProcessor_Process();
$reports = $xmlProcessor->get($this->_caseType, 'ActivitySets');
CRM_Core_Session::setStatus(ts('Activities from the %1 activity set have been added to this case.',
array(1 => $reports[$params['timeline_id']])
), ts('Done'), 'success');
}
elseif ($this->_mergeCases &&
$buttonName == '_qf_CaseView_next_merge_case'
) {
$mainCaseId = $params['merge_case_id'];
$otherCaseId = $this->_caseID;
//merge two cases.
CRM_Case_BAO_Case::mergeCases($this->_contactID, $mainCaseId, NULL, $otherCaseId);
//redirect user to main case view.
$url = CRM_Utils_System::url('civicrm/contact/view/case',
"reset=1&action=view&cid={$this->_contactID}&id={$mainCaseId}&show=1"
);
$session = CRM_Core_Session::singleton();
$session->pushUserContext($url);
}
}
/**
* Build the activity selector/datatable
* @param CRM_Core_Form $form
* @param array $aTypes
* To include acivities related to current case id $form->_caseID.
*/
public static function activityForm($form, $aTypes = array()) {
$caseRelationships = CRM_Case_BAO_Case::getCaseRoles($form->_contactID, $form->_caseID);
//build reporter select
$reporters = array("" => ts(' - any reporter - '));
foreach ($caseRelationships as $key => & $value) {
$reporters[$value['cid']] = $value['name'] . " ( {$value['relation']} )";
}
$form->add('select', 'reporter_id', ts('Reporter/Role'), $reporters, FALSE, array('id' => 'reporter_id_' . $form->_caseID));
// take all case activity types for search filter, CRM-7187
$aTypesFilter = array();
$allCaseActTypes = CRM_Case_PseudoConstant::caseActivityType();
foreach ($allCaseActTypes as $typeDetails) {
if (!in_array($typeDetails['name'], array('Open Case'))) {
$aTypesFilter[$typeDetails['id']] = CRM_Utils_Array::value('label', $typeDetails);
}
}
$aTypesFilter = $aTypesFilter + $aTypes;
asort($aTypesFilter);
$form->add('select', 'activity_type_filter_id', ts('Activity Type'), array('' => ts('- select activity type -')) + $aTypesFilter, FALSE, array('id' => 'activity_type_filter_id_' . $form->_caseID));
$activityStatus = CRM_Core_PseudoConstant::activityStatus();
$form->add('select', 'status_id', ts('Status'), array("" => ts(' - any status - ')) + $activityStatus, FALSE, array('id' => 'status_id_' . $form->_caseID));
// activity dates
$form->addDate('activity_date_low_' . $form->_caseID, ts('Activity Dates - From'), FALSE, array('formatType' => 'searchDate'));
$form->addDate('activity_date_high_' . $form->_caseID, ts('To'), FALSE, array('formatType' => 'searchDate'));
if (CRM_Core_Permission::check('administer CiviCRM')) {
$form->add('checkbox', 'activity_deleted', ts('Deleted Activities'), '', FALSE, array('id' => 'activity_deleted_' . $form->_caseID));
}
}
/**
* Form elements for merging cases
*/
public function buildMergeCaseForm() {
$otherCases = array();
$result = civicrm_api3('Case', 'get', array(
'check_permissions' => TRUE,
'contact_id' => $this->_contactID,
'is_deleted' => 0,
'id' => array('!=' => $this->_caseID),
'return' => array('id', 'start_date', 'case_type_id.title'),
));
foreach ($result['values'] as $id => $case) {
$otherCases[$id] = "#$id: {$case['case_type_id.title']} " . ts('(opened %1)', array(1 => $case['start_date']));
}
$this->assign('mergeCases', $this->_mergeCases = (bool) $otherCases);
if ($otherCases) {
$this->add('select', 'merge_case_id',
ts('Select Case for Merge'),
array(
'' => ts('- select case -'),
) + $otherCases,
FALSE,
array('class' => 'crm-select2 huge')
);
$this->addElement('submit',
$this->getButtonName('next', 'merge_case'),
ts('Merge'),
array(
'class' => 'hiddenElement',
)
);
}
}
}

View file

@ -0,0 +1,158 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
/**
* This class generates form components for custom data
*
* It delegates the work to lower level subclasses and integrates the changes
* back in. It also uses a lot of functionality with the CRM API's, so any change
* made here could potentially affect the API etc. Be careful, be aware, use unit tests.
*/
class CRM_Case_Form_CustomData extends CRM_Core_Form {
/**
* The entity id, used when editing/creating custom data
*
* @var int
*/
protected $_entityID;
/**
* Entity sub type of the table id.
*
* @var string
*/
protected $_subTypeID;
/**
* Pre processing work done here.
*
* gets session variables for table name, id of entity in table, type of entity and stores them.
*/
public function preProcess() {
$this->_groupID = CRM_Utils_Request::retrieve('groupID', 'Positive', $this, TRUE);
$this->_entityID = CRM_Utils_Request::retrieve('entityID', 'Positive', $this, TRUE);
$this->_subTypeID = CRM_Utils_Request::retrieve('subType', 'Positive', $this, TRUE);
$this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
$groupTree = CRM_Core_BAO_CustomGroup::getTree('Case',
NULL,
$this->_entityID,
$this->_groupID,
$this->_subTypeID
);
// simplified formatted groupTree
$groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, $this);
// Array contains only one item
foreach ($groupTree as $groupValues) {
$this->_customTitle = $groupValues['title'];
CRM_Utils_System::setTitle(ts('Edit %1', array(1 => $groupValues['title'])));
}
$this->_defaults = array();
CRM_Core_BAO_CustomGroup::setDefaults($groupTree, $this->_defaults);
$this->setDefaults($this->_defaults);
CRM_Core_BAO_CustomGroup::buildQuickForm($this, $groupTree);
//need to assign custom data type and subtype to the template
$this->assign('entityID', $this->_entityID);
$this->assign('groupID', $this->_groupID);
$this->assign('subType', $this->_subTypeID);
$this->assign('contactID', $this->_contactID);
}
/**
* Build the form object.
*/
public function buildQuickForm() {
// make this form an upload since we dont know if the custom data injected dynamically
// is of type file etc
$this->addButtons(array(
array(
'type' => 'upload',
'name' => ts('Save'),
'isDefault' => TRUE,
),
array(
'type' => 'cancel',
'name' => ts('Cancel'),
),
)
);
}
/**
* Process the user submitted custom data values.
*/
public function postProcess() {
$params = $this->controller->exportValues($this->_name);
$transaction = new CRM_Core_Transaction();
CRM_Core_BAO_CustomValueTable::postProcess($params,
'civicrm_case',
$this->_entityID,
'Case'
);
$session = CRM_Core_Session::singleton();
$session->pushUserContext(CRM_Utils_System::url('civicrm/contact/view/case', "reset=1&id={$this->_entityID}&cid={$this->_contactID}&action=view"));
$session = CRM_Core_Session::singleton();
$activityTypeID = CRM_Core_OptionGroup::getValue('activity_type', 'Change Custom Data', 'name');
$activityParams = array(
'activity_type_id' => $activityTypeID,
'source_contact_id' => $session->get('userID'),
'is_auto' => TRUE,
'subject' => $this->_customTitle . " : change data",
'status_id' => CRM_Core_OptionGroup::getValue('activity_status',
'Completed',
'name'
),
'target_contact_id' => $this->_contactID,
'details' => json_encode($this->_defaults),
'activity_date_time' => date('YmdHis'),
);
$activity = CRM_Activity_BAO_Activity::create($activityParams);
$caseParams = array(
'activity_id' => $activity->id,
'case_id' => $this->_entityID,
);
CRM_Case_BAO_Case::processCaseActivity($caseParams);
$transaction->commit();
}
}

View file

@ -0,0 +1,130 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
/**
* This class assigns the current case to another client.
*/
class CRM_Case_Form_EditClient extends CRM_Core_Form {
/**
* Build all the data structures needed to build the form.
*/
public function preProcess() {
$cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE);
$context = CRM_Utils_Request::retrieve('context', 'String', $this);
//get current client name.
$this->assign('currentClientName', CRM_Contact_BAO_Contact::displayName($cid));
//set the context.
$url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&force=1&cid={$cid}&selectedChild=case");
if ($context == 'search') {
$qfKey = CRM_Utils_Request::retrieve('key', 'String', $this);
//validate the qfKey
$urlParams = 'force=1';
if (CRM_Utils_Rule::qfKey($qfKey)) {
$urlParams .= "&qfKey=$qfKey";
}
$url = CRM_Utils_System::url('civicrm/case/search', $urlParams);
}
elseif ($context == 'dashboard') {
$url = CRM_Utils_System::url('civicrm/case', 'reset=1');
}
elseif (in_array($context, array(
'dashlet',
'dashletFullscreen',
))) {
$url = CRM_Utils_System::url('civicrm/dashboard', 'reset=1');
}
$session = CRM_Core_Session::singleton();
$session->pushUserContext($url);
}
/**
* Build the form object.
*/
public function buildQuickForm() {
$this->addEntityRef('reassign_contact_id', ts('Select Contact'), array('create' => TRUE), TRUE);
$this->addButtons(array(
array(
'type' => 'done',
'name' => ts('Reassign Case'),
),
array(
'type' => 'cancel',
'name' => ts('Cancel'),
),
));
// This form may change the url structure so should not submit via ajax
$this->preventAjaxSubmit();
}
public function addRules() {
$this->addFormRule(array(get_class($this), 'formRule'), $this);
}
/**
* @param $vals
* @param $rule
* @param CRM_Core_Form $form
*
* @return array
*/
public static function formRule($vals, $rule, $form) {
$errors = array();
if (empty($vals['reassign_contact_id']) || $vals['reassign_contact_id'] == $form->get('cid')) {
$errors['reassign_contact_id'] = ts("Please select a different contact.");
}
return $errors;
}
/**
* Process the form.
*/
public function postProcess() {
$params = $this->controller->exportValues($this->_name);
//assign case to another client.
$mainCaseId = CRM_Case_BAO_Case::mergeCases($params['reassign_contact_id'], $this->get('id'), $this->get('cid'), NULL, TRUE);
// user context
$url = CRM_Utils_System::url('civicrm/contact/view/case',
"reset=1&action=view&cid={$params['reassign_contact_id']}&id={$mainCaseId[0]}&show=1"
);
CRM_Core_Session::singleton()->pushUserContext($url);
}
}

View file

@ -0,0 +1,132 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
/**
* This class generates form components for case report.
*/
class CRM_Case_Form_Report extends CRM_Core_Form {
/**
* Case Id
*/
public $_caseID = NULL;
/**
* Client Id
*/
public $_clientID = NULL;
/**
* Activity set name
*/
public $_activitySetName = NULL;
public $_report = NULL;
/**
* Build the form object.
*/
public function preProcess() {
$this->_caseID = CRM_Utils_Request::retrieve('caseid', 'Integer', $this, TRUE);
$this->_clientID = CRM_Utils_Request::retrieve('cid', 'Integer', $this, TRUE);
$this->_activitySetName = CRM_Utils_Request::retrieve('asn', 'String', $this, TRUE);
$this->_report = $this->get('report');
if ($this->_report) {
$this->assign_by_ref('report', $this->_report);
}
// user context
$url = CRM_Utils_System::url('civicrm/contact/view/case',
"reset=1&action=view&cid={$this->_clientID}&id={$this->_caseID}&show=1"
);
$session = CRM_Core_Session::singleton();
$session->pushUserContext($url);
}
public function buildQuickForm() {
if ($this->_report) {
return;
}
$includeActivites = array(
1 => ts('All Activities'),
2 => ts('Exclude Completed Activities'),
);
$includeActivitesGroup = $this->addRadio('include_activities',
NULL,
$includeActivites,
NULL,
'&nbsp;',
TRUE
);
$includeActivitesGroup->setValue(1);
$this->add('checkbox',
'is_redact',
ts('Redact (hide) Client and Service Provider Data')
);
$this->addButtons(array(
array(
'type' => 'refresh',
'name' => ts('Generate Report'),
'isDefault' => TRUE,
),
array(
'type' => 'cancel',
'name' => ts('Cancel'),
),
)
);
// We want this form to redirect to a full page
$this->preventAjaxSubmit();
}
/**
* Process the form submission.
*/
public function postProcess() {
// store the submitted values in an array
$params = $this->controller->exportValues($this->_name);
$xmlProcessor = new CRM_Case_XMLProcessor_Report();
$contents = $xmlProcessor->run($this->_clientID,
$this->_caseID,
$this->_activitySetName,
$params
);
$this->set('report', $contents);
}
}

View file

@ -0,0 +1,434 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
/**
* This file is for Case search.
*/
class CRM_Case_Form_Search extends CRM_Core_Form_Search {
/**
* The params that are sent to the query
*
* @var array
*/
protected $_queryParams;
/**
* Are we restricting ourselves to a single contact
*
* @var boolean
*/
protected $_single = FALSE;
/**
* Are we restricting ourselves to a single contact
*
* @var boolean
*/
protected $_limit = NULL;
/**
* Prefix for the controller
*/
protected $_prefix = 'case_';
/**
* Processing needed for buildForm and later.
*/
public function preProcess() {
$this->set('searchFormName', 'Search');
//check for civicase access.
if (!CRM_Case_BAO_Case::accessCiviCase()) {
CRM_Core_Error::fatal(ts('You are not authorized to access this page.'));
}
//validate case configuration.
$configured = CRM_Case_BAO_Case::isCaseConfigured();
$this->assign('notConfigured', !$configured['configured']);
if (!$configured['configured']) {
return;
}
/**
* set the button names
*/
$this->_searchButtonName = $this->getButtonName('refresh');
$this->_actionButtonName = $this->getButtonName('next', 'action');
$this->_done = FALSE;
$this->defaults = array();
/*
* we allow the controller to set force/reset externally, useful when we are being
* driven by the wizard framework
*/
$this->_reset = CRM_Utils_Request::retrieve('reset', 'Boolean');
$this->_force = CRM_Utils_Request::retrieve('force', 'Boolean', $this, FALSE);
$this->_limit = CRM_Utils_Request::retrieve('limit', 'Positive', $this);
$this->_context = CRM_Utils_Request::retrieve('context', 'String', $this, FALSE, 'search');
$this->assign('context', $this->_context);
// get user submitted values
// get it from controller only if form has been submitted, else preProcess has set this
if (!empty($_POST) && !$this->controller->isModal()) {
$this->_formValues = $this->controller->exportValues($this->_name);
}
else {
$this->_formValues = $this->get('formValues');
}
if (empty($this->_formValues)) {
if (isset($this->_ssID)) {
$this->_formValues = CRM_Contact_BAO_SavedSearch::getFormValues($this->_ssID);
}
}
if ($this->_force) {
$this->postProcess();
$this->set('force', 0);
}
$sortID = NULL;
if ($this->get(CRM_Utils_Sort::SORT_ID)) {
$sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID),
$this->get(CRM_Utils_Sort::SORT_DIRECTION)
);
}
$this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues);
$selector = new CRM_Case_Selector_Search($this->_queryParams,
$this->_action,
NULL,
$this->_single,
$this->_limit,
$this->_context
);
$prefix = NULL;
if ($this->_context == 'user') {
$prefix = $this->_prefix;
}
$this->assign("{$prefix}limit", $this->_limit);
$this->assign("{$prefix}single", $this->_single);
$controller = new CRM_Core_Selector_Controller($selector,
$this->get(CRM_Utils_Pager::PAGE_ID),
$sortID,
CRM_Core_Action::VIEW,
$this,
CRM_Core_Selector_Controller::TRANSFER,
$prefix
);
$controller->setEmbedded(TRUE);
$controller->moveFromSessionToTemplate();
$this->assign('summary', $this->get('summary'));
}
/**
* Build the form object.
*/
public function buildQuickForm() {
parent::buildQuickForm();
$this->addSortNameField();
CRM_Case_BAO_Query::buildSearchForm($this);
$rows = $this->get('rows');
if (is_array($rows)) {
if (!$this->_single) {
$this->addRowSelectors($rows);
}
$permission = CRM_Core_Permission::getPermission();
$tasks = CRM_Case_Task::permissionedTaskTitles($permission);
if (!empty($this->_formValues['case_deleted'])) {
unset($tasks[1]);
}
else {
unset($tasks[4]);
}
$this->addTaskMenu($tasks);
}
}
/**
* Get the label for the sortName field if email searching is on.
*
* (email searching is a setting under search preferences).
*
* @return string
*/
protected function getSortNameLabelWithEmail() {
return ts('Client Name or Email');
}
/**
* Get the label for the sortName field if email searching is off.
*
* (email searching is a setting under search preferences).
*
* @return string
*/
protected function getSortNameLabelWithOutEmail() {
return ts('Client Name');
}
/**
* The post processing of the form gets done here.
*
* Key things done during post processing are
* - check for reset or next request. if present, skip post procesing.
* - now check if user requested running a saved search, if so, then
* the form values associated with the saved search are used for searching.
* - if user has done a submit with new values the regular post submissing is
* done.
* The processing consists of using a Selector / Controller framework for getting the
* search results.
*/
public function postProcess() {
if ($this->_done) {
return;
}
$this->_done = TRUE;
$this->_formValues = $this->controller->exportValues($this->_name);
$this->fixFormValues();
if (isset($this->_ssID) && empty($_POST)) {
// if we are editing / running a saved search and the form has not been posted
$this->_formValues = CRM_Contact_BAO_SavedSearch::getFormValues($this->_ssID);
}
//search for civicase
if (!$this->_force) {
if (array_key_exists('case_owner', $this->_formValues) && !$this->_formValues['case_owner']) {
$this->_formValues['case_owner'] = 0;
}
}
if (empty($this->_formValues['case_deleted'])) {
$this->_formValues['case_deleted'] = 0;
}
CRM_Core_BAO_CustomValue::fixCustomFieldValue($this->_formValues);
$this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues);
$this->set('formValues', $this->_formValues);
$this->set('queryParams', $this->_queryParams);
$buttonName = $this->controller->getButtonName();
if ($buttonName == $this->_actionButtonName) {
// check actionName and if next, then do not repeat a search, since we are going to the next page
// hack, make sure we reset the task values
$stateMachine = $this->controller->getStateMachine();
$formName = $stateMachine->getTaskFormName();
$this->controller->resetPage($formName);
return;
}
$sortID = NULL;
if ($this->get(CRM_Utils_Sort::SORT_ID)) {
$sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID),
$this->get(CRM_Utils_Sort::SORT_DIRECTION)
);
}
$this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues);
$selector = new CRM_Case_Selector_Search($this->_queryParams,
$this->_action,
NULL,
$this->_single,
$this->_limit,
$this->_context
);
$selector->setKey($this->controller->_key);
$prefix = NULL;
if ($this->_context == 'user') {
$prefix = $this->_prefix;
}
$this->assign("{$prefix}limit", $this->_limit);
$this->assign("{$prefix}single", $this->_single);
$controller = new CRM_Core_Selector_Controller($selector,
$this->get(CRM_Utils_Pager::PAGE_ID),
$sortID,
CRM_Core_Action::VIEW,
$this,
CRM_Core_Selector_Controller::SESSION,
$prefix
);
$controller->setEmbedded(TRUE);
$query = &$selector->getQuery();
if ($this->_context == 'user') {
$query->setSkipPermission(TRUE);
}
$controller->run();
}
/**
* Add the rules (mainly global rules) for form.
*
* All local rules are added near the element
*
* @see valid_date
*/
public function addRules() {
$this->addFormRule(array('CRM_Case_Form_Search', 'formRule'));
}
/**
* Global validation rules for the form.
*
* @param array $fields
* Posted values of the form.
*
* @return array|bool
*/
public static function formRule($fields) {
$errors = array();
if (!empty($errors)) {
return $errors;
}
return TRUE;
}
/**
* Set the default form values.
*
*
* @return array
* the default array reference
*/
public function setDefaultValues() {
$defaults = array();
$defaults = $this->_formValues;
return $defaults;
}
public function fixFormValues() {
if (!$this->_force) {
return;
}
$caseStatus = CRM_Utils_Request::retrieve('status', 'Positive');
if ($caseStatus) {
$this->_formValues['case_status_id'] = $caseStatus;
$this->_defaults['case_status_id'] = $caseStatus;
}
$caseType = CRM_Utils_Request::retrieve('type', 'Positive');
if ($caseType) {
$this->_formValues['case_type_id'] = (array) $caseType;
$this->_defaults['case_type_id'] = (array) $caseType;
}
$caseFromDate = CRM_Utils_Request::retrieve('pstart', 'Date');
if ($caseFromDate) {
list($date) = CRM_Utils_Date::setDateDefaults($caseFromDate);
$this->_formValues['case_start_date_low'] = $date;
$this->_defaults['case_start_date_low'] = $date;
}
$caseToDate = CRM_Utils_Request::retrieve('pend', 'Date');
if ($caseToDate) {
list($date) = CRM_Utils_Date::setDateDefaults($caseToDate);
$this->_formValues['case_start_date_high'] = $date;
$this->_defaults['case_start_date_high'] = $date;
}
$cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
if ($cid) {
$cid = CRM_Utils_Type::escape($cid, 'Integer');
if ($cid > 0) {
$this->_formValues['contact_id'] = $cid;
list($display, $image) = CRM_Contact_BAO_Contact::getDisplayAndImage($cid);
$this->_defaults['sort_name'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $cid,
'sort_name'
);
// also assign individual mode to the template
$this->_single = TRUE;
}
}
else {
// First, if "all" is stored in the session, default to all cases, otherwise default to no selection.
$session = CRM_Core_Session::singleton();
if (CRM_Utils_Request::retrieve('all', 'Positive', $session)) {
$this->_formValues['case_owner'] = 1;
$this->_defaults['case_owner'] = 1;
}
else {
$this->_formValues['case_owner'] = 0;
$this->_defaults['case_owner'] = 0;
}
// Now if case_owner is set in the url/post, use that instead.
$caseOwner = CRM_Utils_Request::retrieve('case_owner', 'Positive');
if ($caseOwner) {
$this->_formValues['case_owner'] = $caseOwner;
$this->_defaults['case_owner'] = $caseOwner;
}
}
}
/**
* @return null
*/
public function getFormValues() {
return NULL;
}
/**
* Return a descriptive name for the page, used in wizard header
*
* @return string
*/
public function getTitle() {
return ts('Find Cases');
}
}

View file

@ -0,0 +1,170 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
/**
* This class generates task actions for CiviEvent.
*/
class CRM_Case_Form_Task extends CRM_Core_Form {
/**
* The task being performed
*
* @var int
*/
protected $_task;
/**
* The additional clause that we restrict the search with
*
* @var string
*/
protected $_componentClause = NULL;
/**
* The array that holds all the component ids
*
* @var array
*/
protected $_componentIds;
/**
* The array that holds all the case ids
*
* @var array
*/
public $_caseIds;
/**
* Build all the data structures needed to build the form.
*/
public function preProcess() {
self::preProcessCommon($this);
}
/**
* @param CRM_Core_Form $form
* @param bool $useTable
*/
public static function preProcessCommon(&$form, $useTable = FALSE) {
$form->_caseIds = array();
$values = $form->controller->exportValues($form->get('searchFormName'));
$form->_task = $values['task'];
$caseTasks = CRM_Case_Task::tasks();
$form->assign('taskName', $caseTasks[$form->_task]);
$ids = array();
if ($values['radio_ts'] == 'ts_sel') {
foreach ($values as $name => $value) {
if (substr($name, 0, CRM_Core_Form::CB_PREFIX_LEN) == CRM_Core_Form::CB_PREFIX) {
$ids[] = substr($name, CRM_Core_Form::CB_PREFIX_LEN);
}
}
}
else {
$queryParams = $form->get('queryParams');
$query = new CRM_Contact_BAO_Query($queryParams, NULL, NULL, FALSE, FALSE,
CRM_Contact_BAO_Query::MODE_CASE
);
$query->_distinctComponentClause = " ( civicrm_case.id )";
$query->_groupByComponentClause = " GROUP BY civicrm_case.id ";
$result = $query->searchQuery(0, 0, NULL);
while ($result->fetch()) {
$ids[] = $result->case_id;
}
}
if (!empty($ids)) {
$form->_componentClause = ' civicrm_case.id IN ( ' . implode(',', $ids) . ' ) ';
$form->assign('totalSelectedCases', count($ids));
}
$form->_caseIds = $form->_componentIds = $ids;
//set the context for redirection for any task actions
$qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $form);
$urlParams = 'force=1';
if (CRM_Utils_Rule::qfKey($qfKey)) {
$urlParams .= "&qfKey=$qfKey";
}
$session = CRM_Core_Session::singleton();
$searchFormName = strtolower($form->get('searchFormName'));
if ($searchFormName == 'search') {
$session->replaceUserContext(CRM_Utils_System::url('civicrm/case/search', $urlParams));
}
else {
$session->replaceUserContext(CRM_Utils_System::url("civicrm/contact/search/$searchFormName",
$urlParams
));
}
}
/**
* Given the signer id, compute the contact id
* since its used for things like send email
*/
public function setContactIDs() {
$this->_contactIds = &CRM_Core_DAO::getContactIDsFromComponent($this->_caseIds,
'civicrm_case_contact'
);
}
/**
* Simple shell that derived classes can call to add buttons to
* the form with a customized title for the main Submit
*
* @param string $title
* Title of the main button.
* @param string $nextType
* Button type for the form after processing.
* @param string $backType
* @param bool $submitOnce
*/
public function addDefaultButtons($title, $nextType = 'next', $backType = 'back', $submitOnce = FALSE) {
$this->addButtons(array(
array(
'type' => $nextType,
'name' => $title,
'isDefault' => TRUE,
),
array(
'type' => $backType,
'name' => ts('Cancel'),
),
)
);
}
}

View file

@ -0,0 +1,100 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
/**
* This class provides the functionality to delete a group of case records.
*/
class CRM_Case_Form_Task_Delete extends CRM_Case_Form_Task {
/**
* Are we operating in "single mode", i.e. deleting one
* specific case?
*
* @var boolean
*/
protected $_single = FALSE;
/**
* Are we moving case to Trash.
*
* @var boolean
*/
public $_moveToTrash = TRUE;
/**
* Build all the data structures needed to build the form.
*/
public function preProcess() {
if (!CRM_Core_Permission::checkActionPermission('CiviCase', CRM_Core_Action::DELETE)) {
CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
}
parent::preProcess();
}
/**
* Build the form object.
*/
public function buildQuickForm() {
$this->addDefaultButtons(ts('Delete cases'), 'done');
}
/**
* Process the form after the input has been submitted and validated.
*/
public function postProcess() {
$deleted = $failed = 0;
foreach ($this->_caseIds as $caseId) {
if (CRM_Case_BAO_Case::deleteCase($caseId, $this->_moveToTrash)) {
$deleted++;
}
else {
$failed++;
}
}
if ($deleted) {
if ($this->_moveToTrash) {
$msg = ts('%count case moved to trash.', array('plural' => '%count cases moved to trash.', 'count' => $deleted));
}
else {
$msg = ts('%count case permanently deleted.', array('plural' => '%count cases permanently deleted.', 'count' => $deleted));
}
CRM_Core_Session::setStatus($msg, ts('Removed'), 'success');
}
if ($failed) {
CRM_Core_Session::setStatus(ts('1 could not be deleted.', array('plural' => '%count could not be deleted.', 'count' => $failed)), ts('Error'), 'error');
}
}
}

View file

@ -0,0 +1,96 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
/**
* This class provides the functionality to create PDF letter for a group of contacts.
*/
class CRM_Case_Form_Task_PDF extends CRM_Case_Form_Task {
/**
* All the existing templates in the system.
*
* @var array
*/
public $_templates = NULL;
public $_single = NULL;
public $_cid = NULL;
/**
* Build all the data structures needed to build the form.
*/
public function preProcess() {
$this->skipOnHold = $this->skipDeceased = FALSE;
parent::preProcess();
$this->setContactIDs();
CRM_Contact_Form_Task_PDFLetterCommon::preProcess($this);
}
/**
* Set defaults for the pdf.
*
* @return array
*/
public function setDefaultValues() {
return CRM_Contact_Form_Task_PDFLetterCommon::setDefaultValues();
}
/**
* Build the form object.
*/
public function buildQuickForm() {
CRM_Contact_Form_Task_PDFLetterCommon::buildQuickForm($this);
}
/**
* Process the form after the input has been submitted and validated.
*/
public function postProcess() {
CRM_Contact_Form_Task_PDFLetterCommon::postProcess($this);
}
/**
* List available tokens for this form.
*
* @return array
*/
public function listTokens() {
$tokens = CRM_Core_SelectValues::contactTokens();
foreach ($this->_caseIds as $key => $caseId) {
$caseTypeId = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_Case', $caseId, 'case_type_id');
$tokens += CRM_Core_SelectValues::caseTokens($caseTypeId);
}
return $tokens;
}
}

View file

@ -0,0 +1,98 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
/**
* This class provides the functionality to save a search
* Saved Searches are used for saving frequently used queries
*/
class CRM_Case_Form_Task_Print extends CRM_Case_Form_Task {
/**
* Build all the data structures needed to build the form.
*/
public function preProcess() {
parent::preProcess();
// set print view, so that print templates are called
$this->controller->setPrint(1);
// get the formatted params
$queryParams = $this->get('queryParams');
$sortID = NULL;
if ($this->get(CRM_Utils_Sort::SORT_ID)) {
$sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID),
$this->get(CRM_Utils_Sort::SORT_DIRECTION)
);
}
$selector = new CRM_Case_Selector_Search($queryParams, $this->_action, $this->_componentClause);
$controller = new CRM_Core_Selector_Controller($selector, NULL, $sortID, CRM_Core_Action::VIEW, $this, CRM_Core_Selector_Controller::SCREEN);
$controller->setEmbedded(TRUE);
$controller->run();
}
/**
* Build the form object.
*
* It consists of
* - displaying the QILL (query in local language)
* - displaying elements for saving the search
*/
public function buildQuickForm() {
//
// just need to add a javacript to popup the window for printing
//
$this->addButtons(array(
array(
'type' => 'next',
'name' => ts('Print Case List'),
'js' => array('onclick' => 'window.print()'),
'isDefault' => TRUE,
),
array(
'type' => 'back',
'name' => ts('Done'),
),
)
);
}
/**
* Process the form after the input has been submitted and validated.
*/
public function postProcess() {
// redirect to the main search page after printing is over
}
}

View file

@ -0,0 +1,88 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
/**
* This class provides the functionality to restore a group of participations.
*/
class CRM_Case_Form_Task_Restore extends CRM_Case_Form_Task {
/**
* Are we operating in "single mode", i.e. deleting one
* specific case?
*
* @var boolean
*/
protected $_single = FALSE;
/**
* Build all the data structures needed to build the form.
*/
public function preProcess() {
parent::preProcess();
}
/**
* Build the form object.
*/
public function buildQuickForm() {
$this->addDefaultButtons(ts('Restore Cases'), 'done');
}
/**
* Process the form after the input has been submitted and validated.
*/
public function postProcess() {
$restoredCases = $failed = 0;
foreach ($this->_caseIds as $caseId) {
if (CRM_Case_BAO_Case::restoreCase($caseId)) {
$restoredCases++;
}
else {
$failed++;
}
}
if ($restoredCases) {
$msg = ts('%count case restored from trash.', array(
'plural' => '%count cases restored from trash.',
'count' => $restoredCases,
));
CRM_Core_Session::setStatus($msg, ts('Restored'), 'success');
}
if ($failed) {
CRM_Core_Session::setStatus(ts('1 could not be restored.', array('plural' => '%count could not be restored.', 'count' => $failed)), ts('Error'), 'error');
}
}
}

View file

@ -0,0 +1,59 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
/**
* Used for displaying results.
*/
class CRM_Case_Form_Task_Result extends CRM_Case_Form_Task {
/**
* Build all the data structures needed to build the form.
*/
public function preProcess() {
}
/**
* Build the form object.
*/
public function buildQuickForm() {
$this->addButtons(array(
array(
'type' => 'done',
'name' => ts('Done'),
'isDefault' => TRUE,
),
)
);
}
}

View file

@ -0,0 +1,85 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
*/
/**
* This class provides the functionality to save a search
* Saved Searches are used for saving frequently used queries
*/
class CRM_Case_Form_Task_SearchTaskHookSample extends CRM_Case_Form_Task {
/**
* Build all the data structures needed to build the form.
*/
public function preProcess() {
parent::preProcess();
$rows = array();
// display name and email of all contact ids
$caseIDs = implode(',', $this->_caseIds);
$statusId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'case_status', 'id', 'name');
$query = "
SELECT ct.display_name as display_name,
cs.start_date as start_date,
ov.label as status
FROM civicrm_case cs
INNER JOIN civicrm_case_contact cc ON ( cs.id = cc.case_id)
INNER JOIN civicrm_contact ct ON ( cc.contact_id = ct.id)
LEFT JOIN civicrm_option_value ov ON (cs.status_id = ov.value AND ov.option_group_id = {$statusId} )
WHERE cs.id IN ( {$caseIDs} )";
$dao = CRM_Core_DAO::executeQuery($query);
while ($dao->fetch()) {
$rows[] = array(
'display_name' => $dao->display_name,
'start_date' => CRM_Utils_Date::customFormat($dao->start_date),
'status' => $dao->status,
);
}
$this->assign('rows', $rows);
}
/**
* Build the form object.
*/
public function buildQuickForm() {
$this->addButtons(array(
array(
'type' => 'done',
'name' => ts('Done'),
'isDefault' => TRUE,
),
)
);
}
}