/** * process the form after the input has been submitted and validated * * @access public * * @return void */ public function postProcess() { $deletedActivities = 0; foreach ($this->_activityHolderIds as $activityId['id']) { $moveToTrash = CRM_Case_BAO_Case::isCaseActivity($activityId['id']); if (CRM_Activity_BAO_Activity::deleteActivity($activityId, $moveToTrash)) { $deletedActivities++; } } CRM_Core_Session::setStatus($deletedActivities, ts('Deleted Activities'), "success"); CRM_Core_Session::setStatus("", ts('Total Selected Activities: %1', array(1 => count($this->_activityHolderIds))), "info"); }
/** * process the form after the input has been submitted and validated * * @access public * @return None */ public function postProcess() { $deletedActivities = 0; foreach ($this->_activityHolderIds as $activityId['id']) { require_once 'CRM/Case/BAO/Case.php'; $moveToTrash = CRM_Case_BAO_Case::isCaseActivity($activityId['id']); if (CRM_Activity_BAO_Activity::deleteActivity($activityId, $moveToTrash)) { $deletedActivities++; } } $status = array(ts('Deleted Activities: %1', array(1 => $deletedActivities)), ts('Total Selected Activities: %1', array(1 => count($this->_activityHolderIds)))); CRM_Core_Session::setStatus($status); }
/** * Process the form after the input has been submitted and validated. * * * @return void */ public function postProcess() { $deleted = $failed = 0; foreach ($this->_activityHolderIds as $activityId['id']) { $moveToTrash = CRM_Case_BAO_Case::isCaseActivity($activityId['id']); if (CRM_Activity_BAO_Activity::deleteActivity($activityId, $moveToTrash)) { $deleted++; } else { $failed++; } } if ($deleted) { $msg = ts('%count activity deleted.', array('plural' => '%count activities 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'); } }
/** * Does user has sufficient permission for view/edit activity record. * * @param int $activityId * Activity record id. * @param int $action * Edit/view. * * @return bool */ public static function checkPermission($activityId, $action) { $allow = FALSE; if (!$activityId || !in_array($action, array(CRM_Core_Action::UPDATE, CRM_Core_Action::VIEW))) { return $allow; } $activity = new CRM_Activity_DAO_Activity(); $activity->id = $activityId; if (!$activity->find(TRUE)) { return $allow; } // Component related permissions. $compPermissions = array('CiviCase' => array('administer CiviCase', 'access my cases and activities', 'access all cases and activities'), 'CiviMail' => array('access CiviMail'), 'CiviEvent' => array('access CiviEvent'), 'CiviGrant' => array('access CiviGrant'), 'CiviPledge' => array('access CiviPledge'), 'CiviMember' => array('access CiviMember'), 'CiviReport' => array('access CiviReport'), 'CiviContribute' => array('access CiviContribute'), 'CiviCampaign' => array('administer CiviCampaign')); // Return early when it is case activity. $isCaseActivity = CRM_Case_BAO_Case::isCaseActivity($activityId); // Check for civicase related permission. if ($isCaseActivity) { $allow = FALSE; foreach ($compPermissions['CiviCase'] as $per) { if (CRM_Core_Permission::check($per)) { $allow = TRUE; break; } } // Check for case specific permissions. if ($allow) { $oper = 'view'; if ($action == CRM_Core_Action::UPDATE) { $oper = 'edit'; } $allow = CRM_Case_BAO_Case::checkPermission($activityId, $oper, $activity->activity_type_id); } return $allow; } // First check the component permission. $sql = "\n SELECT component_id\n FROM civicrm_option_value val\nINNER JOIN civicrm_option_group grp ON ( grp.id = val.option_group_id AND grp.name = %1 )\n WHERE val.value = %2"; $params = array(1 => array('activity_type', 'String'), 2 => array($activity->activity_type_id, 'Integer')); $componentId = CRM_Core_DAO::singleValueQuery($sql, $params); if ($componentId) { $componentName = CRM_Core_Component::getComponentName($componentId); $compPermission = CRM_Utils_Array::value($componentName, $compPermissions); // Here we are interesting in any single permission. if (is_array($compPermission)) { foreach ($compPermission as $per) { if (CRM_Core_Permission::check($per)) { $allow = TRUE; break; } } } } // Check for this permission related to contact. $permission = CRM_Core_Permission::VIEW; if ($action == CRM_Core_Action::UPDATE) { $permission = CRM_Core_Permission::EDIT; } $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name'); $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts); $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts); $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts); // Check for source contact. if (!$componentId || $allow) { $sourceContactId = self::getActivityContact($activity->id, $sourceID); // Account for possibility of activity not having a source contact (as it may have been deleted). if ($sourceContactId) { $allow = CRM_Contact_BAO_Contact_Permission::allow($sourceContactId, $permission); } } // Check for target and assignee contacts. if ($allow) { // First check for supper permission. $supPermission = 'view all contacts'; if ($action == CRM_Core_Action::UPDATE) { $supPermission = 'edit all contacts'; } $allow = CRM_Core_Permission::check($supPermission); // User might have sufficient permission, through acls. if (!$allow) { $allow = TRUE; // Get the target contacts. $targetContacts = CRM_Activity_BAO_ActivityContact::retrieveContactIdsByActivityId($activity->id, $targetID); foreach ($targetContacts as $cnt => $contactId) { if (!CRM_Contact_BAO_Contact_Permission::allow($contactId, $permission)) { $allow = FALSE; break; } } // Get the assignee contacts. if ($allow) { $assigneeContacts = CRM_Activity_BAO_ActivityContact::retrieveContactIdsByActivityId($activity->id, $assigneeID); foreach ($assigneeContacts as $cnt => $contactId) { if (!CRM_Contact_BAO_Contact_Permission::allow($contactId, $permission)) { $allow = FALSE; break; } } } } } return $allow; }
/** * Process the form submission. * * * @param array $params * @return array|null */ public function postProcess($params = NULL) { if ($this->_action & CRM_Core_Action::DELETE) { $deleteParams = array('id' => $this->_activityId); $moveToTrash = CRM_Case_BAO_Case::isCaseActivity($this->_activityId); CRM_Activity_BAO_Activity::deleteActivity($deleteParams, $moveToTrash); // delete tags for the entity $tagParams = array('entity_table' => 'civicrm_activity', 'entity_id' => $this->_activityId); CRM_Core_BAO_EntityTag::del($tagParams); CRM_Core_Session::setStatus(ts("Selected Activity has been deleted successfully."), ts('Record Deleted'), 'success'); return NULL; } // store the submitted values in an array if (!$params) { $params = $this->controller->exportValues($this->_name); } // Set activity type id. if (empty($params['activity_type_id'])) { $params['activity_type_id'] = $this->_activityTypeId; } if (!empty($params['hidden_custom']) && !isset($params['custom'])) { $customFields = CRM_Core_BAO_CustomField::getFields('Activity', FALSE, FALSE, $this->_activityTypeId); $customFields = CRM_Utils_Array::crmArrayMerge($customFields, CRM_Core_BAO_CustomField::getFields('Activity', FALSE, FALSE, NULL, NULL, TRUE)); $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $this->_activityId, 'Activity'); } // store the date with proper format $params['activity_date_time'] = CRM_Utils_Date::processDate($params['activity_date_time'], $params['activity_date_time_time']); // format params as arrays foreach (array('target', 'assignee', 'followup_assignee') as $name) { if (!empty($params["{$name}_contact_id"])) { $params["{$name}_contact_id"] = explode(',', $params["{$name}_contact_id"]); } else { $params["{$name}_contact_id"] = array(); } } // get ids for associated contacts if (!$params['source_contact_id']) { $params['source_contact_id'] = $this->_currentUserId; } if (isset($this->_activityId)) { $params['id'] = $this->_activityId; } // add attachments as needed CRM_Core_BAO_File::formatAttachment($params, $params, 'civicrm_activity', $this->_activityId); $activity = array(); if (!empty($params['is_multi_activity']) && !CRM_Utils_Array::crmIsEmptyArray($params['target_contact_id'])) { $targetContacts = $params['target_contact_id']; foreach ($targetContacts as $targetContactId) { $params['target_contact_id'] = array($targetContactId); // save activity $activity[] = $this->processActivity($params); } } else { // save activity $activity = $this->processActivity($params); } $activityIds = empty($this->_activityIds) ? array($this->_activityId) : $this->_activityIds; foreach ($activityIds as $activityId) { // set params for repeat configuration in create mode $params['entity_id'] = $activityId; $params['entity_table'] = 'civicrm_activity'; if (!empty($params['entity_id']) && !empty($params['entity_table'])) { $checkParentExistsForThisId = CRM_Core_BAO_RecurringEntity::getParentFor($params['entity_id'], $params['entity_table']); if ($checkParentExistsForThisId) { $params['parent_entity_id'] = $checkParentExistsForThisId; $scheduleReminderDetails = CRM_Core_BAO_RecurringEntity::getReminderDetailsByEntityId($checkParentExistsForThisId, $params['entity_table']); } else { $params['parent_entity_id'] = $params['entity_id']; $scheduleReminderDetails = CRM_Core_BAO_RecurringEntity::getReminderDetailsByEntityId($params['entity_id'], $params['entity_table']); } if (property_exists($scheduleReminderDetails, 'id')) { $params['schedule_reminder_id'] = $scheduleReminderDetails->id; } } $params['dateColumns'] = array('activity_date_time'); // Set default repetition start if it was not provided. if (empty($params['repetition_start_date'])) { $params['repetition_start_date'] = $params['activity_date_time']; } // unset activity id unset($params['id']); $linkedEntities = array(array('table' => 'civicrm_activity_contact', 'findCriteria' => array('activity_id' => $activityId), 'linkedColumns' => array('activity_id'), 'isRecurringEntityRecord' => FALSE)); CRM_Core_Form_RecurringEntity::postProcess($params, 'civicrm_activity', $linkedEntities); } return array('activity' => $activity); }
/** * Function to process the form * * @access public * * @return void */ public function postProcess($params = NULL) { if ($this->_action & CRM_Core_Action::DELETE) { $deleteParams = array('id' => $this->_activityId); $moveToTrash = CRM_Case_BAO_Case::isCaseActivity($this->_activityId); CRM_Activity_BAO_Activity::deleteActivity($deleteParams, $moveToTrash); // delete tags for the entity $tagParams = array('entity_table' => 'civicrm_activity', 'entity_id' => $this->_activityId); CRM_Core_BAO_EntityTag::del($tagParams); CRM_Core_Session::setStatus(ts("Selected Activity has been deleted successfully."), ts('Record Deleted'), 'success'); return; } // store the submitted values in an array if (!$params) { $params = $this->controller->exportValues($this->_name); } //set activity type id if (empty($params['activity_type_id'])) { $params['activity_type_id'] = $this->_activityTypeId; } if (!empty($params['hidden_custom']) && !isset($params['custom'])) { $customFields = CRM_Core_BAO_CustomField::getFields('Activity', FALSE, FALSE, $this->_activityTypeId); $customFields = CRM_Utils_Array::crmArrayMerge($customFields, CRM_Core_BAO_CustomField::getFields('Activity', FALSE, FALSE, NULL, NULL, TRUE)); $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_activityId, 'Activity'); } // store the date with proper format $params['activity_date_time'] = CRM_Utils_Date::processDate($params['activity_date_time'], $params['activity_date_time_time']); // format with contact (target contact) values if (isset($params['contact'][1])) { $params['target_contact_id'] = explode(',', $params['contact'][1]); } else { $params['target_contact_id'] = array(); } // assigning formated value to related variable if (!empty($params['assignee_contact_id'])) { $params['assignee_contact_id'] = explode(',', $params['assignee_contact_id']); } else { $params['assignee_contact_id'] = array(); } // civicrm-10043 - 14/12/13 if (!empty($params['followup_assignee_contact_id'])) { $params['followup_assignee_contact_id'] = explode(',', $params['followup_assignee_contact_id']); } else { $params['followup_assignee_contact_id'] = array(); } // get ids for associated contacts if (!$params['source_contact_id']) { $params['source_contact_id'] = $this->_currentUserId; } if (isset($this->_activityId)) { $params['id'] = $this->_activityId; } // add attachments as needed CRM_Core_BAO_File::formatAttachment($params, $params, 'civicrm_activity', $this->_activityId); // format target params if (!$this->_single) { $params['target_contact_id'] = $this->_contactIds; } $activity = array(); if (!empty($params['is_multi_activity']) && !CRM_Utils_Array::crmIsEmptyArray($params['target_contact_id'])) { $targetContacts = $params['target_contact_id']; foreach ($targetContacts as $targetContactId) { $params['target_contact_id'] = array($targetContactId); // save activity $activity[] = $this->processActivity($params); } } else { // save activity $activity = $this->processActivity($params); } return array('activity' => $activity); }
/** * Function to process the form * * @access public * @return None */ public function postProcess($params = null) { if ($this->_action & CRM_Core_Action::DELETE) { $deleteParams = array('id' => $this->_activityId); require_once 'CRM/Case/BAO/Case.php'; $moveToTrash = CRM_Case_BAO_Case::isCaseActivity($this->_activityId); CRM_Activity_BAO_Activity::deleteActivity($deleteParams, $moveToTrash); // delete tags for the entity require_once 'CRM/Core/BAO/EntityTag.php'; $tagParams = array('entity_table' => 'civicrm_activity', 'entity_id' => $this->_activityId); CRM_Core_BAO_EntityTag::del($tagParams); CRM_Core_Session::setStatus(ts("Selected Activity has been deleted sucessfully.")); return; } // store the submitted values in an array if (!$params) { $params = $this->controller->exportValues($this->_name); } //set activity type id if (!CRM_Utils_Array::value('activity_type_id', $params)) { $params['activity_type_id'] = $this->_activityTypeId; } if (CRM_Utils_Array::value('hidden_custom', $params) && !isset($params['custom'])) { $customFields = CRM_Core_BAO_CustomField::getFields('Activity', false, false, $this->_activityTypeId); $customFields = CRM_Utils_Array::crmArrayMerge($customFields, CRM_Core_BAO_CustomField::getFields('Activity', false, false, null, null, true)); $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_activityId, 'Activity'); } // store the date with proper format $params['activity_date_time'] = CRM_Utils_Date::processDate($params['activity_date_time'], $params['activity_date_time_time']); // assigning formated value to related variable if (CRM_Utils_Array::value('target_contact_id', $params)) { $params['target_contact_id'] = explode(',', $params['target_contact_id']); } else { $params['target_contact_id'] = array(); } if (CRM_Utils_Array::value('assignee_contact_id', $params)) { $params['assignee_contact_id'] = explode(',', $params['assignee_contact_id']); } else { $params['assignee_contact_id'] = array(); } // get ids for associated contacts if (!$params['source_contact_id']) { $params['source_contact_id'] = $this->_currentUserId; } else { $params['source_contact_id'] = $this->_submitValues['source_contact_qid']; } if (isset($this->_activityId)) { $params['id'] = $this->_activityId; } // add attachments as needed CRM_Core_BAO_File::formatAttachment($params, $params, 'civicrm_activity', $this->_activityId); // format target params if (!$this->_single) { $params['target_contact_id'] = $this->_contactIds; } $activityAssigned = array(); // format assignee params if (!CRM_Utils_Array::crmIsEmptyArray($params['assignee_contact_id'])) { //skip those assignee contacts which are already assigned //while sending a copy.CRM-4509. $activityAssigned = array_flip($params['assignee_contact_id']); if ($this->_activityId) { $assigneeContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($this->_activityId); $activityAssigned = array_diff_key($activityAssigned, $assigneeContacts); } } // call begin post process. Idea is to let injecting file do // any processing before the activity is added/updated. $this->beginPostProcess($params); $activity = CRM_Activity_BAO_Activity::create($params); // add tags if exists $tagParams = array(); if (!empty($params['tag'])) { foreach ($params['tag'] as $tag) { $tagParams[$tag] = 1; } } //save static tags require_once 'CRM/Core/BAO/EntityTag.php'; CRM_Core_BAO_EntityTag::create($tagParams, 'civicrm_activity', $activity->id); //save free tags if (isset($params['taglist']) && !empty($params['taglist'])) { require_once 'CRM/Core/Form/Tag.php'; CRM_Core_Form_Tag::postProcess($params['taglist'], $activity->id, 'civicrm_activity', $this); } // call end post process. Idea is to let injecting file do any // processing needed, after the activity has been added/updated. $this->endPostProcess($params, $activity); // create follow up activity if needed $followupStatus = ''; if (CRM_Utils_Array::value('followup_activity_type_id', $params)) { $followupActivity = CRM_Activity_BAO_Activity::createFollowupActivity($activity->id, $params); $followupStatus = "A followup activity has been scheduled."; } // send copy to assignee contacts.CRM-4509 $mailStatus = ''; $config =& CRM_Core_Config::singleton(); if (!CRM_Utils_Array::crmIsEmptyArray($params['assignee_contact_id']) && $config->activityAssigneeNotification) { $mailToContacts = array(); $assigneeContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activity->id, true, false); //build an associative array with unique email addresses. foreach ($activityAssigned as $id => $dnc) { if (isset($id) && array_key_exists($id, $assigneeContacts)) { $mailToContacts[$assigneeContacts[$id]['email']] = $assigneeContacts[$id]; } } if (!CRM_Utils_array::crmIsEmptyArray($mailToContacts)) { //include attachments while sendig a copy of activity. $attachments =& CRM_Core_BAO_File::getEntityFile('civicrm_activity', $activity->id); require_once "CRM/Case/BAO/Case.php"; $result = CRM_Case_BAO_Case::sendActivityCopy(null, $activity->id, $mailToContacts, $attachments, null); $mailStatus .= ts("A copy of the activity has also been sent to assignee contacts(s)."); } } // set status message if (CRM_Utils_Array::value('subject', $params)) { $params['subject'] = "'" . $params['subject'] . "'"; } CRM_Core_Session::setStatus(ts('Activity %1 has been saved. %2. %3', array(1 => $params['subject'], 2 => $followupStatus, 3 => $mailStatus))); return array('activity' => $activity); }
/** * Does user has sufficient permission for view/edit activity record. * * @param int $activityId activity record id. * @param int $action edit/view * * @return boolean $allow true/false * @access public */ public function checkPermission($activityId, $action) { $allow = false; if (!$activityId || !in_array($action, array(CRM_Core_Action::UPDATE, CRM_Core_Action::VIEW))) { return $allow; } $activity = new CRM_Activity_DAO_Activity(); $activity->id = $activityId; if (!$activity->find(true)) { return $allow; } //component related permissions. $compPermissions = array('CiviCase' => array('administer CiviCase', 'access my cases and activities', 'access all cases and activities'), 'CiviMail' => array('access CiviMail'), 'CiviEvent' => array('access CiviEvent'), 'CiviGrant' => array('access CiviGrant'), 'CiviPledge' => array('access CiviPledge'), 'CiviMember' => array('access CiviMember'), 'CiviReport' => array('access CiviReport'), 'CiviContribute' => array('access CiviContribute'), 'CiviCampaign' => array('administer CiviCampaign')); //return early when it is case activity. require_once 'CRM/Case/BAO/Case.php'; $isCaseActivity = CRM_Case_BAO_Case::isCaseActivity($activityId); //check for civicase related permission. if ($isCaseActivity) { $allow = false; foreach ($compPermissions['CiviCase'] as $per) { if (CRM_Core_Permission::check($per)) { $allow = true; break; } } //check for case specific permissions. if ($allow) { $oper = 'view'; if ($action == CRM_Core_Action::UPDATE) { $oper = 'edit'; } $allow = CRM_Case_BAO_Case::checkPermission($activityId, $oper, $activity->activity_type_id); } return $allow; } require_once 'CRM/Core/Permission.php'; require_once 'CRM/Contact/BAO/Contact/Permission.php'; //first check the component permission. $sql = "\n SELECT component_id\n FROM civicrm_option_value val\nINNER JOIN civicrm_option_group grp ON ( grp.id = val.option_group_id AND grp.name = %1 )\n WHERE val.value = %2"; $params = array(1 => array('activity_type', 'String'), 2 => array($activity->activity_type_id, 'Integer')); $componentId = CRM_Core_DAO::singleValueQuery($sql, $params); if ($componentId) { require_once 'CRM/Core/Component.php'; $componentName = CRM_Core_Component::getComponentName($componentId); $compPermission = CRM_Utils_Array::value($componentName, $compPermissions); //here we are interesting in any single permission. if (is_array($compPermission)) { foreach ($compPermission as $per) { if (CRM_Core_Permission::check($per)) { $allow = true; break; } } } } //check for this permission related to contact. $permission = CRM_Core_Permission::VIEW; if ($action == CRM_Core_Action::UPDATE) { $permission = CRM_Core_Permission::EDIT; } //check for source contact. if (!$componentId || $allow) { $allow = CRM_Contact_BAO_Contact_Permission::allow($activity->source_contact_id, $permission); } //check for target and assignee contacts. if ($allow) { //first check for supper permission. $supPermission = 'view all contacts'; if ($action == CRM_Core_Action::UPDATE) { $supPermission = 'edit all contacts'; } $allow = CRM_Core_Permission::check($supPermission); //user might have sufficient permission, through acls. if (!$allow) { $allow = true; //get the target contacts. $targetContacts = CRM_Activity_BAO_ActivityTarget::retrieveTargetIdsByActivityId($activity->id); foreach ($targetContacts as $cnt => $contactId) { if (!CRM_Contact_BAO_Contact_Permission::allow($contactId, $permission)) { $allow = false; break; } } //get the assignee contacts. if ($allow) { $assigneeContacts = CRM_Activity_BAO_ActivityAssignment::retrieveAssigneeIdsByActivityId($activity->id); foreach ($assigneeContacts as $cnt => $contactId) { if (!CRM_Contact_BAO_Contact_Permission::allow($contactId, $permission)) { $allow = false; break; } } } } } return $allow; }