/** * build all the data structures needed to build the form * * @return void * @access public */ function preProcess() { parent::preProcess(); require_once 'CRM/Utils/Rule.php'; $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this); $urlParams = 'force=1'; if (CRM_Utils_Rule::qfKey($qfKey)) { $urlParams .= '&qfKey=' . $qfKey; } $session = CRM_Core_Session::singleton(); $url = CRM_Utils_System::url('civicrm/contact/search/custom', $urlParams); $session->replaceUserContext($url); //get the survey id from user submitted values. $this->_surveyId = CRM_Utils_Array::value('survey_id', $this->get('formValues')); $isHeld = CRM_Utils_Array::value('status_id', $this->get('formValues')); if (!$this->_surveyId || !$isHeld) { CRM_Core_Error::statusBounce(ts("Please search with 'Is Held' and 'Survey Id' filters to apply this action.")); } $session = CRM_Core_Session::singleton(); if (empty($this->_contactIds) || !$session->get('userID')) { CRM_Core_Error::statusBounce(ts("Could not find contacts for release voters resevation Or Missing Interviewer contact.")); } $this->_interviewerId = $session->get('userID'); $surveyDetails = array(); $params = array('id' => $this->_surveyId); $this->_surveyDetails = CRM_Campaign_BAO_Survey::retrieve($params, $surveyDetails); $numVoters = CRM_Core_DAO::singleValueQuery("SELECT COUNT(*) FROM " . self::ACTIVITY_SURVEY_DETAIL_TABLE . " WHERE status_id = 'H' AND survey_id = %1 AND interviewer_id = %2", array(1 => array($this->_surveyId, 'Integer'), 2 => array($this->_interviewerId, 'Integer'))); if (!isset($numVoters) || $numVoters < 1) { CRM_Core_Error::statusBounce(ts("All voters held by you are already released for this survey.")); } $this->assign('surveyTitle', $surveyDetails['title']); }
public function preProcess() { if (!CRM_Campaign_BAO_Campaign::accessCampaign()) { CRM_Utils_System::permissionDenied(); } $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add', 'REQUEST'); $this->_surveyId = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE); if ($this->_surveyId) { $this->_single = TRUE; $params = array('id' => $this->_surveyId); CRM_Campaign_BAO_Survey::retrieve($params, $surveyInfo); $this->_surveyTitle = $surveyInfo['title']; $this->assign('surveyTitle', $this->_surveyTitle); CRM_Utils_System::setTitle(ts('Configure Survey - %1', array(1 => $this->_surveyTitle))); } $this->assign('action', $this->_action); $this->assign('surveyId', $this->_surveyId); // when custom data is included in this page if (!empty($_POST['hidden_custom'])) { $this->set('type', 'Event'); $this->set('entityId', $this->_surveyId); CRM_Custom_Form_CustomData::preProcess($this, NULL, NULL, 1, 'Survey', $this->_surveyId); CRM_Custom_Form_CustomData::buildQuickForm($this); CRM_Custom_Form_CustomData::setDefaultValues($this); } // CRM-11480, CRM-11682 // Preload libraries required by the "Questions" tab CRM_UF_Page_ProfileEditor::registerProfileScripts(); CRM_UF_Page_ProfileEditor::registerSchemas(array('IndividualModel', 'ActivityModel')); CRM_Campaign_Form_Survey_TabHeader::build($this); }
public function preProcess() { parent::preProcess(); $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this); $this->assign('context', $this->_context); $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this); if ($this->_action & CRM_Core_Action::UPDATE) { CRM_Utils_System::setTitle(ts('Configure Survey') . ' - ' . $this->_surveyTitle); } // when custom data is included in this page if (!empty($_POST['hidden_custom'])) { CRM_Custom_Form_CustomData::preProcess($this); CRM_Custom_Form_CustomData::buildQuickForm($this); } if ($this->_name != 'Petition') { $url = CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=survey'); CRM_Utils_System::appendBreadCrumb(array(array('title' => ts('Survey Dashboard'), 'url' => $url))); } $this->_values = $this->get('values'); if (!is_array($this->_values)) { $this->_values = array(); if ($this->_surveyId) { $params = array('id' => $this->_surveyId); CRM_Campaign_BAO_Survey::retrieve($params, $this->_values); } $this->set('values', $this->_values); } $this->assign('action', $this->_action); $this->assign('surveyId', $this->_surveyId); // for custom data $this->assign('entityID', $this->_surveyId); }
public function preProcess() { if (!CRM_Campaign_BAO_Campaign::accessCampaign()) { CRM_Utils_System::permissionDenied(); } $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this); $this->assign('context', $this->_context); $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this); if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::DELETE)) { $this->_surveyId = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE); if ($this->_action & CRM_Core_Action::UPDATE) { CRM_Utils_System::setTitle(ts('Edit Survey')); } else { CRM_Utils_System::setTitle(ts('Delete Survey')); } } $this->_cdType = CRM_Utils_Array::value('type', $_GET); $this->assign('cdType', FALSE); if ($this->_cdType) { $this->assign('cdType', TRUE); return CRM_Custom_Form_CustomData::preProcess($this); } // when custom data is included in this page if (!empty($_POST['hidden_custom'])) { CRM_Custom_Form_CustomData::preProcess($this); CRM_Custom_Form_CustomData::buildQuickForm($this); } $session = CRM_Core_Session::singleton(); $url = CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=survey'); $session->pushUserContext($url); $this->_values = $this->get('values'); if (!is_array($this->_values)) { $this->_values = array(); if ($this->_surveyId) { $params = array('id' => $this->_surveyId); CRM_Campaign_BAO_Survey::retrieve($params, $this->_values); } $this->set('values', $this->_values); } $this->assign('action', $this->_action); $this->assign('surveyId', $this->_surveyId); // for custom data $this->assign('entityID', $this->_surveyId); if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::DELETE)) { $this->_surveyId = CRM_Utils_Request::retrieve('id', 'Positive', $this, TRUE); if ($this->_action & CRM_Core_Action::UPDATE) { CRM_Utils_System::setTitle(ts('Edit Petition')); } else { CRM_Utils_System::setTitle(ts('Delete Petition')); } } $session = CRM_Core_Session::singleton(); $url = CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=petition'); $session->pushUserContext($url); CRM_Utils_System::appendBreadCrumb(array(array('title' => ts('Petition Dashboard'), 'url' => $url))); }
/** * Function to set variables up before form is built * * @return void * @access public */ public function preProcess() { if (!CRM_Campaign_BAO_Campaign::accessCampaign()) { CRM_Utils_System::permissionDenied(); } $this->_surveyId = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE); $params = array('id' => $this->_surveyId); CRM_Campaign_BAO_Survey::retrieve($params, $surveyInfo); $this->_surveyTitle = $surveyInfo['title']; $this->assign('surveyTitle', $this->_surveyTitle); CRM_Utils_System::setTitle(ts('Delete Survey') . ' - ' . $this->_surveyTitle); }
public function preProcess() { parent::preProcess(); $this->_values = $this->get('values'); if (!is_array($this->_values)) { $this->_values = array(); if ($this->_surveyId) { $params = array('id' => $this->_surveyId); CRM_Campaign_BAO_Survey::retrieve($params, $this->_values); } $this->set('values', $this->_values); } $query = "SELECT MAX(id) as id, title FROM civicrm_report_instance WHERE name = %1"; $params = array(1 => array("survey_{$this->_surveyId}", 'String')); $result = CRM_Core_DAO::executeQuery($query, $params); if ($result->fetch()) { $this->_reportId = $result->id; $this->_reportTitle = $result->title; } }
/** * Build all the data structures needed to build the form. */ public function preProcess() { parent::preProcess(); //get the survey id from user submitted values. $this->_surveyId = $this->get('surveyId'); $this->_interviewerId = $this->get('interviewerId'); if (!$this->_surveyId) { CRM_Core_Error::statusBounce(ts("Could not find Survey Id.")); } if (!$this->_interviewerId) { CRM_Core_Error::statusBounce(ts("Missing Interviewer contact.")); } if (!is_array($this->_contactIds) || empty($this->_contactIds)) { CRM_Core_Error::statusBounce(ts("Could not find contacts for reservation.")); } $params = array('id' => $this->_surveyId); CRM_Campaign_BAO_Survey::retrieve($params, $this->_surveyDetails); //get the survey activities. $activityStatus = CRM_Core_PseudoConstant::activityStatus('name'); $statusIds = array(); foreach (array('Scheduled') as $name) { if ($statusId = array_search($name, $activityStatus)) { $statusIds[] = $statusId; } } // these are the activities count that are linked to the current // interviewer and current survey and not the list of ALL survey activities $this->_numVoters = CRM_Campaign_BAO_Survey::getSurveyActivities($this->_surveyId, $this->_interviewerId, $statusIds, NULL, TRUE); //validate the selected survey. $this->validateSurvey(); $this->assign('surveyTitle', $this->_surveyDetails['title']); $this->assign('activityType', $this->_surveyDetails['activity_type_id']); $this->assign('surveyId', $this->_surveyId); //append breadcrumb to survey dashboard. if (CRM_Campaign_BAO_Campaign::accessCampaign()) { $url = CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=survey'); CRM_Utils_System::appendBreadCrumb(array(array('title' => ts('Survey(s)'), 'url' => $url))); } //set the title. CRM_Utils_System::setTitle(ts('Reserve Respondents')); }
/** * @return string * @throws Exception */ public function run() { CRM_Utils_System::addHTMLHead('<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">'); $contact_id = CRM_Utils_Request::retrieve('cid', 'Integer', CRM_Core_DAO::$_nullObject); $subscribe_id = CRM_Utils_Request::retrieve('sid', 'Integer', CRM_Core_DAO::$_nullObject); $hash = CRM_Utils_Request::retrieve('h', 'String', CRM_Core_DAO::$_nullObject); $activity_id = CRM_Utils_Request::retrieve('a', 'String', CRM_Core_DAO::$_nullObject); $petition_id = CRM_Utils_Request::retrieve('pid', 'String', CRM_Core_DAO::$_nullObject); if (!$petition_id) { $petition_id = CRM_Utils_Request::retrieve('p', 'String', CRM_Core_DAO::$_nullObject); } if (!$contact_id || !$subscribe_id || !$hash) { CRM_Core_Error::fatal(ts("Missing input parameters")); } $result = $this->confirm($contact_id, $subscribe_id, $hash, $activity_id, $petition_id); if ($result === FALSE) { $this->assign('success', $result); } else { $this->assign('success', TRUE); // $this->assign( 'group' , $result ); } list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contact_id); $this->assign('display_name', $displayName); $this->assign('email', $email); $this->assign('petition_id', $petition_id); $this->assign('survey_id', $petition_id); $pparams['id'] = $petition_id; $this->petition = array(); CRM_Campaign_BAO_Survey::retrieve($pparams, $this->petition); $this->assign('is_share', CRM_Utils_Array::value('is_share', $this->petition)); $this->assign('thankyou_title', CRM_Utils_Array::value('thankyou_title', $this->petition)); $this->assign('thankyou_text', CRM_Utils_Array::value('thankyou_text', $this->petition)); CRM_Utils_System::setTitle(CRM_Utils_Array::value('thankyou_title', $this->petition)); // send thank you email $params['contactId'] = $contact_id; $params['email-Primary'] = $email; $params['sid'] = $petition_id; $params['activityId'] = $activity_id; CRM_Campaign_BAO_Petition::sendEmail($params, CRM_Campaign_Form_Petition_Signature::EMAIL_THANK); return parent::run(); }
function run() { $id = CRM_Utils_Request::retrieve('id', 'Positive', $this); $petition_id = CRM_Utils_Request::retrieve('pid', 'Positive', $this); $params['id'] = $petition_id; $this->petition = array(); CRM_Campaign_BAO_Survey::retrieve($params, $this->petition); $this->assign('petitionTitle', $this->petition['title']); $this->assign('thankyou_title', CRM_Utils_Array::value('thankyou_title', $this->petition)); $this->assign('thankyou_text', CRM_Utils_Array::value('thankyou_text', $this->petition)); $this->assign('survey_id', $petition_id); $this->assign('status_id', $id); CRM_Utils_System::setTitle(CRM_Utils_Array::value('thankyou_title', $this->petition)); // send thank you or email verification emails /* * sendEmailMode * 1 = connected user via login/pwd - thank you * or dedupe contact matched who doesn't have a tag CIVICRM_TAG_UNCONFIRMED - thank you * login using fb connect - thank you + click to add msg to fb wall * 2 = send a confirmation request email */ return parent::run(); }
public function preProcess() { if (!CRM_Campaign_BAO_Campaign::accessCampaign()) { CRM_Utils_System::permissionDenied(); } $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add', 'REQUEST'); $this->_surveyId = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE); if ($this->_surveyId) { $this->_single = TRUE; $params = array('id' => $this->_surveyId); CRM_Campaign_BAO_Survey::retrieve($params, $surveyInfo); $this->_surveyTitle = $surveyInfo['title']; $this->assign('surveyTitle', $this->_surveyTitle); CRM_Utils_System::setTitle(ts('Configure Survey - %1', array(1 => $this->_surveyTitle))); } $this->assign('action', $this->_action); $this->assign('surveyId', $this->_surveyId); // CRM-11480, CRM-11682 // Preload libraries required by the "Questions" tab CRM_UF_Page_ProfileEditor::registerProfileScripts(); CRM_UF_Page_ProfileEditor::registerSchemas(array('IndividualModel', 'ActivityModel')); CRM_Campaign_Form_Survey_TabHeader::build($this); }
/** * Form submission of petition signature * * @access public * @return None */ public function postProcess() { if (defined('CIVICRM_TAG_UNCONFIRMED')) { // Check if contact 'email confirmed' tag exists, else create one // This should be in the petition module initialise code to create a default tag for this require_once 'api/v2/Tag.php'; $tag_params['name'] = CIVICRM_TAG_UNCONFIRMED; $tag = civicrm_tag_get($tag_params); if ($tag['is_error'] == 1) { //create tag $tag_params['description'] = CIVICRM_TAG_UNCONFIRMED; $tag_params['is_reserved'] = 1; $tag_params['used_for'] = 'civicrm_contact'; $tag = civicrm_tag_create($tag_params); $this->_tagId = $tag['tag_id']; } else { $this->_tagId = $tag['id']; } } // export the field values to be used for saving the profile form $params = $this->controller->exportValues($this->_name); $session = CRM_Core_Session::singleton(); // format params $params['last_modified_id'] = $session->get('userID'); $params['last_modified_date'] = date('YmdHis'); if ($this->_action & CRM_Core_Action::ADD) { $params['created_id'] = $session->get('userID'); $params['created_date'] = date('YmdHis'); } if (isset($this->_surveyId)) { $params['sid'] = $this->_surveyId; } if (isset($this->_contactId)) { $params['contactId'] = $this->_contactId; } // if logged in user, skip dedupe if ($this->_loggedIn) { $ids[0] = $this->_contactId; } else { // dupeCheck - check if contact record already exists // code modified from api/v2/Contact.php-function civicrm_contact_check_params() require_once 'CRM/Dedupe/Finder.php'; $params['contact_type'] = $this->_ctype; //TODO - current dedupe finds soft deleted contacts - adding param is_deleted not working //$params['is_deleted'] = 0; // ignore soft deleted contacts $dedupeParams = CRM_Dedupe_Finder::formatParams($params, $params['contact_type']); $dedupeParams['check_permission'] = ''; //dupesByParams($params, $ctype, $level = 'Strict', $except = array()) $ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, $params['contact_type']); } switch (count($ids)) { case 0: //no matching contacts - create a new contact require_once 'CRM/Campaign/BAO/Survey.php'; $petition_params['id'] = $this->_surveyId; $petition = array(); CRM_Campaign_BAO_Survey::retrieve($petition_params, $petition); // Add a source for this new contact $params['source'] = ts('Petition Signature') . ' ' . $this->petition['title']; $this->_sendEmailMode = self::EMAIL_CONFIRM; // Set status for signature activity to scheduled until email is verified $params['statusId'] = 1; break; case 1: $this->_contactId = $ids[0]; // check if user has already signed this petition - redirects to Thank You if true $this->redirectIfSigned($params); // dedupe matched single contact, check for 'unconfirmed' tag if (defined('CIVICRM_TAG_UNCONFIRMED')) { require_once 'CRM/Core/DAO/EntityTag.php'; $tag =& new CRM_Core_DAO_EntityTag(); $tag->entity_id = $this->_contactId; $tag->tag_id = $this->_tagId; if (!$tag->find()) { // send thank you email directly, the user is known and validated $this->_sendEmailMode = self::EMAIL_THANK; // Set status for signature activity to completed $params['statusId'] = 2; } else { // send email verification email $this->_sendEmailMode = self::EMAIL_CONFIRM; // Set status for signature activity to scheduled until email is verified $params['statusId'] = 1; } } break; default: // more than 1 matching contact // for time being, take the first matching contact (not sure that's the best strategy, but better than creating another duplicate) $this->_contactId = $ids[0]; // check if user has already signed this petition - redirects to Thank You if true $this->redirectIfSigned($params); if (defined('CIVICRM_TAG_UNCONFIRMED')) { require_once 'CRM/Core/DAO/EntityTag.php'; $tag =& new CRM_Core_DAO_EntityTag(); $tag->entity_id = $this->_contactId; $tag->tag_id = $this->_tagId; if (!$tag->find()) { // send thank you email $this->_sendEmailMode = self::EMAIL_THANK; // Set status for signature activity to completed $params['statusId'] = 2; } else { // send email verification email $this->_sendEmailMode = self::EMAIL_CONFIRM; // Set status for signature activity to scheduled until email is verified $params['statusId'] = 1; } } break; } require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); $addToGroupID = isset($this->_addToGroupID) ? $this->_addToGroupID : null; $this->_contactId = CRM_Contact_BAO_Contact::createProfileContact($params, $this->_contactProfileFields, $this->_contactId, $addToGroupID, $this->_contactProfileId, $this->_ctype, true); // get additional custom activity profile field data // to save with new signature activity record $surveyInfo = $this->bao->getSurveyInfo($this->_surveyId); $customActivityFields = CRM_Core_BAO_CustomField::getFields('Activity', false, false, $surveyInfo['activity_type_id']); $customActivityFields = CRM_Utils_Array::crmArrayMerge($customActivityFields, CRM_Core_BAO_CustomField::getFields('Activity', false, false, null, null, true)); $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customActivityFields, null, 'Activity'); // create the signature activity record $params['contactId'] = $this->_contactId; $result = $this->bao->createSignature($params); // send thank you or email verification emails // if logged in using Facebook connect and email on form matches Fb email, // no need for email confirmation, send thank you email if ($this->forceEmailConfirmed['flag'] && $this->forceEmailConfirmed['email'] == $params['email-Primary']) { $this->_sendEmailMode = self::EMAIL_THANK; } switch ($this->_sendEmailMode) { case self::EMAIL_THANK: // mark the signature activity as completed and set confirmed cookie $this->bao->confirmSignature($result->id, $this->_contactId, $this->_surveyId); break; case self::EMAIL_CONFIRM: // set 'Unconfirmed' tag for this new contact if (defined('CIVICRM_TAG_UNCONFIRMED')) { require_once 'api/v2/EntityTag.php'; unset($tag_params); $tag_params['contact_id'] = $this->_contactId; $tag_params['tag_id'] = $this->_tagId; $tag_value = civicrm_entity_tag_add($tag_params); } break; } //send email $params['activityId'] = $result->id; $params['tagId'] = $this->_tagId; $this->bao->sendEmail($params, $this->_sendEmailMode); $transaction->commit(); if ($result) { // set the template to thank you CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/petition/thankyou', 'pid=' . $this->_surveyId . '&id=' . $this->_sendEmailMode . '&reset=1')); } }
/** * Build all the data structures needed to build the form. */ public function preProcess() { $this->_votingTab = $this->get('votingTab'); $this->_reserveToInterview = $this->get('reserveToInterview'); if ($this->_reserveToInterview || $this->_votingTab) { //user came from voting tab / reserve form. foreach (array('surveyId', 'contactIds', 'interviewerId') as $fld) { $this->{"_{$fld}"} = $this->get($fld); } //get the target voter ids. if ($this->_votingTab) { $this->getVoterIds(); } } else { parent::preProcess(); //get the survey id from user submitted values. $this->_surveyId = CRM_Utils_Array::value('campaign_survey_id', $this->get('formValues')); $this->_interviewerId = CRM_Utils_Array::value('survey_interviewer_id', $this->get('formValues')); } if ($this->_surveyId) { $params = array('id' => $this->_surveyId); CRM_Campaign_BAO_Survey::retrieve($params, $this->_surveyDetails); } $orderClause = FALSE; $buttonName = $this->controller->getButtonName(); if ($buttonName == '_qf_Interview_submit_orderBy' && !empty($_POST['order_bys'])) { $orderByParams = CRM_Utils_Array::value('order_bys', $_POST); } elseif (CRM_Core_OptionGroup::getValue('activity_type', 'WalkList') == $this->_surveyDetails['activity_type_id']) { $orderByParams = array(1 => array('column' => 'civicrm_address.street_name', 'order' => 'ASC'), 2 => array('column' => 'civicrm_address.street_number%2', 'order' => 'ASC'), 3 => array('column' => 'civicrm_address.street_number', 'order' => 'ASC'), 4 => array('column' => 'contact_a.sort_name', 'order' => 'ASC')); } $orderBy = array(); if (!empty($orderByParams)) { foreach ($orderByParams as $key => $val) { if (!empty($val['column'])) { $orderBy[] = "{$val['column']} {$val['order']}"; } } if (!empty($orderBy)) { $orderClause = "ORDER BY " . implode(', ', $orderBy); } } $this->_contactIds = array_unique($this->_contactIds); if (!empty($this->_contactIds) && $orderClause) { $clause = 'contact_a.id IN ( ' . implode(',', $this->_contactIds) . ' ) '; $sql = "\nSELECT contact_a.id\nFROM civicrm_contact contact_a\nLEFT JOIN civicrm_address ON contact_a.id = civicrm_address.contact_id\nWHERE {$clause}\n{$orderClause}"; $this->_contactIds = array(); $dao = CRM_Core_DAO::executeQuery($sql); while ($dao->fetch()) { $this->_contactIds[] = $dao->id; } } //get the contact read only fields to display. $readOnlyFields = array_merge(array('contact_type' => '', 'sort_name' => ts('Name'))); //get the read only field data. $returnProperties = array_fill_keys(array_keys($readOnlyFields), 1); $returnProperties['contact_sub_type'] = TRUE; //validate all voters for required activity. //get the survey activities for given voters. $this->_surveyActivityIds = CRM_Campaign_BAO_Survey::voterActivityDetails($this->_surveyId, $this->_contactIds, $this->_interviewerId); $activityStatus = CRM_Core_PseudoConstant::activityStatus('name'); $scheduledStatusId = array_search('Scheduled', $activityStatus); $activityIds = array(); foreach ($this->_contactIds as $key => $voterId) { $actVals = CRM_Utils_Array::value($voterId, $this->_surveyActivityIds); $statusId = CRM_Utils_Array::value('status_id', $actVals); $activityId = CRM_Utils_Array::value('activity_id', $actVals); if ($activityId && $statusId && $scheduledStatusId == $statusId) { $activityIds["activity_id_{$voterId}"] = $activityId; } else { unset($this->_contactIds[$key]); } } //retrieve the contact details. $voterDetails = CRM_Campaign_BAO_Survey::voterDetails($this->_contactIds, $returnProperties); $this->_allowAjaxReleaseButton = FALSE; if ($this->_votingTab && (CRM_Core_Permission::check('manage campaign') || CRM_Core_Permission::check('administer CiviCampaign') || CRM_Core_Permission::check('release campaign contacts'))) { $this->_allowAjaxReleaseButton = TRUE; } //validate voter ids across profile. $this->filterVoterIds(); $this->assign('votingTab', $this->_votingTab); $this->assign('componentIds', $this->_contactIds); $this->assign('componentIdsJson', json_encode($this->_contactIds)); $this->assign('voterDetails', $voterDetails); $this->assign('readOnlyFields', $readOnlyFields); $this->assign('interviewerId', $this->_interviewerId); $this->assign('surveyActivityIds', json_encode($activityIds)); $this->assign('allowAjaxReleaseButton', $this->_allowAjaxReleaseButton); //get the survey values. $this->_surveyValues = $this->get('surveyValues'); if (!is_array($this->_surveyValues)) { $this->_surveyValues = array(); if ($this->_surveyId) { $surveyParams = array('id' => $this->_surveyId); CRM_Campaign_BAO_Survey::retrieve($surveyParams, $this->_surveyValues); } $this->set('surveyValues', $this->_surveyValues); } $this->assign('surveyValues', $this->_surveyValues); $result = CRM_Campaign_BAO_Survey::getReportID($this->_surveyId); $this->assign("instanceId", $result); //get the survey result options. $this->_resultOptions = $this->get('resultOptions'); if (!is_array($this->_resultOptions)) { $this->_resultOptions = array(); if ($resultOptionId = CRM_Utils_Array::value('result_id', $this->_surveyValues)) { $this->_resultOptions = CRM_Core_OptionGroup::valuesByID($resultOptionId); } $this->set('resultOptions', $this->_resultOptions); } //validate the required ids. $this->validateIds(); //append breadcrumb to survey dashboard. if (CRM_Campaign_BAO_Campaign::accessCampaign()) { $url = CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=survey'); CRM_Utils_System::appendBreadCrumb(array(array('title' => ts('Survey(s)'), 'url' => $url))); } //set the title. $activityTypes = CRM_Core_PseudoConstant::activityType(FALSE, TRUE, FALSE, 'label', TRUE); $this->_surveyTypeId = CRM_Utils_Array::value('activity_type_id', $this->_surveyValues); CRM_Utils_System::setTitle(ts('Record %1 Responses', array(1 => $activityTypes[$this->_surveyTypeId]))); }
/** * takes an associative array and sends a thank you or email verification email * * @param array $params (reference ) an assoc array of name/value pairs * * @param $sendEmailMode * * @throws Exception * @return void @access public * @static */ public static function sendEmail($params, $sendEmailMode) { /* sendEmailMode * CRM_Campaign_Form_Petition_Signature::EMAIL_THANK * connected user via login/pwd - thank you * or dedupe contact matched who doesn't have a tag CIVICRM_TAG_UNCONFIRMED - thank you * or login using fb connect - thank you + click to add msg to fb wall * * CRM_Campaign_Form_Petition_Signature::EMAIL_CONFIRM * send a confirmation request email */ // check if the group defined by CIVICRM_PETITION_CONTACTS exists, else create it $petitionGroupName = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'petition_contacts', NULL, 'Petition Contacts'); $dao = new CRM_Contact_DAO_Group(); $dao->title = $petitionGroupName; if (!$dao->find(TRUE)) { $dao->is_active = 1; $dao->visibility = 'User and User Admin Only'; $dao->save(); } $group_id = $dao->id; // get petition info $petitionParams['id'] = $params['sid']; $petitionInfo = array(); CRM_Campaign_BAO_Survey::retrieve($petitionParams, $petitionInfo); if (empty($petitionInfo)) { CRM_Core_Error::fatal('Petition doesn\'t exist.'); } //get the default domain email address. list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail(); $emailDomain = CRM_Core_BAO_MailSettings::defaultDomain(); $toName = CRM_Contact_BAO_Contact::displayName($params['contactId']); $replyTo = "do-not-reply@{$emailDomain}"; // set additional general message template params (custom tokens to use in email msg templates) // tokens then available in msg template as {$petition.title}, etc $petitionTokens['title'] = $petitionInfo['title']; $petitionTokens['petitionId'] = $params['sid']; $tplParams['petition'] = $petitionTokens; switch ($sendEmailMode) { case CRM_Campaign_Form_Petition_Signature::EMAIL_THANK: // add this contact to the CIVICRM_PETITION_CONTACTS group // Cannot pass parameter 1 by reference $p = array($params['contactId']); CRM_Contact_BAO_GroupContact::addContactsToGroup($p, $group_id, 'API'); if ($params['email-Primary']) { CRM_Core_BAO_MessageTemplate::sendTemplate(array('groupName' => 'msg_tpl_workflow_petition', 'valueName' => 'petition_sign', 'contactId' => $params['contactId'], 'tplParams' => $tplParams, 'from' => "\"{$domainEmailName}\" <{$domainEmailAddress}>", 'toName' => $toName, 'toEmail' => $params['email-Primary'], 'replyTo' => $replyTo, 'petitionId' => $params['sid'], 'petitionTitle' => $petitionInfo['title'])); } break; case CRM_Campaign_Form_Petition_Signature::EMAIL_CONFIRM: // create mailing event subscription record for this contact // this will allow using a hash key to confirm email address by sending a url link $se = CRM_Mailing_Event_BAO_Subscribe::subscribe($group_id, $params['email-Primary'], $params['contactId'], 'profile'); // require_once 'CRM/Core/BAO/Domain.php'; // $domain = CRM_Core_BAO_Domain::getDomain(); $config = CRM_Core_Config::singleton(); $localpart = CRM_Core_BAO_MailSettings::defaultLocalpart(); $replyTo = implode($config->verpSeparator, array($localpart . 'c', $se->contact_id, $se->id, $se->hash)) . "@{$emailDomain}"; $confirmUrl = CRM_Utils_System::url('civicrm/petition/confirm', "reset=1&cid={$se->contact_id}&sid={$se->id}&h={$se->hash}&a={$params['activityId']}&p={$params['sid']}", TRUE); $confirmUrlPlainText = CRM_Utils_System::url('civicrm/petition/confirm', "reset=1&cid={$se->contact_id}&sid={$se->id}&h={$se->hash}&a={$params['activityId']}&p={$params['sid']}", TRUE, NULL, FALSE); // set email specific message template params and assign to tplParams $petitionTokens['confirmUrl'] = $confirmUrl; $petitionTokens['confirmUrlPlainText'] = $confirmUrlPlainText; $tplParams['petition'] = $petitionTokens; if ($params['email-Primary']) { CRM_Core_BAO_MessageTemplate::sendTemplate(array('groupName' => 'msg_tpl_workflow_petition', 'valueName' => 'petition_confirmation_needed', 'contactId' => $params['contactId'], 'tplParams' => $tplParams, 'from' => "\"{$domainEmailName}\" <{$domainEmailAddress}>", 'toName' => $toName, 'toEmail' => $params['email-Primary'], 'replyTo' => $replyTo, 'petitionId' => $params['sid'], 'petitionTitle' => $petitionInfo['title'], 'confirmUrl' => $confirmUrl)); } break; } }
/** * Build all the data structures needed to build the form. */ public function preProcess() { $this->_interviewToRelease = $this->get('interviewToRelease'); if ($this->_interviewToRelease) { //user came from interview form. foreach (array('surveyId', 'contactIds', 'interviewerId') as $fld) { $this->{"_{$fld}"} = $this->get($fld); } if (!empty($this->_contactIds)) { $this->assign('totalSelectedContacts', count($this->_contactIds)); } } else { parent::preProcess(); //get the survey id from user submitted values. $this->_surveyId = CRM_Utils_Array::value('campaign_survey_id', $this->get('formValues')); $this->_interviewerId = CRM_Utils_Array::value('survey_interviewer_id', $this->get('formValues')); } if (!$this->_surveyId) { CRM_Core_Error::statusBounce(ts("Please search with 'Survey', to apply this action.")); } if (!$this->_interviewerId) { CRM_Core_Error::statusBounce(ts('Missing Interviewer contact.')); } if (!is_array($this->_contactIds) || empty($this->_contactIds)) { CRM_Core_Error::statusBounce(ts('Could not find respondents to release.')); } $surveyDetails = array(); $params = array('id' => $this->_surveyId); $this->_surveyDetails = CRM_Campaign_BAO_Survey::retrieve($params, $surveyDetails); $activityStatus = CRM_Core_PseudoConstant::activityStatus('name'); $statusIds = array(); foreach (array('Scheduled') as $name) { if ($statusId = array_search($name, $activityStatus)) { $statusIds[] = $statusId; } } //fetch the target survey activities. $this->_surveyActivities = CRM_Campaign_BAO_Survey::voterActivityDetails($this->_surveyId, $this->_contactIds, $this->_interviewerId, $statusIds); if (count($this->_surveyActivities) < 1) { CRM_Core_Error::statusBounce(ts('We could not found respondent for this survey to release.')); } $this->assign('surveyTitle', $surveyDetails['title']); //append breadcrumb to survey dashboard. if (CRM_Campaign_BAO_Campaign::accessCampaign()) { $url = CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=survey'); CRM_Utils_System::appendBreadCrumb(array(array('title' => ts('Survey(s)'), 'url' => $url))); } //set the title. CRM_Utils_System::setTitle(ts('Release Respondents')); }
/** * Form submission of petition signature. */ public function postProcess() { $tag_name = Civi::settings()->get('tag_unconfirmed'); if ($tag_name) { // Check if contact 'email confirmed' tag exists, else create one // This should be in the petition module initialise code to create a default tag for this $tag_params['name'] = $tag_name; $tag_params['version'] = 3; $tag = civicrm_api('tag', 'get', $tag_params); if ($tag['count'] == 0) { //create tag $tag_params['description'] = $tag_name; $tag_params['is_reserved'] = 1; $tag_params['used_for'] = 'civicrm_contact'; $tag = civicrm_api('tag', 'create', $tag_params); } $this->_tagId = $tag['id']; } // export the field values to be used for saving the profile form $params = $this->controller->exportValues($this->_name); $session = CRM_Core_Session::singleton(); // format params $params['last_modified_id'] = $session->get('userID'); $params['last_modified_date'] = date('YmdHis'); if ($this->_action & CRM_Core_Action::ADD) { $params['created_id'] = $session->get('userID'); $params['created_date'] = date('YmdHis'); } if (isset($this->_surveyId)) { $params['sid'] = $this->_surveyId; } if (isset($this->_contactId)) { $params['contactId'] = $this->_contactId; } // if logged in user, skip dedupe if ($this->_loggedIn) { $ids[0] = $this->_contactId; } else { // dupeCheck - check if contact record already exists // code modified from api/v2/Contact.php-function civicrm_contact_check_params() $params['contact_type'] = $this->_ctype; //TODO - current dedupe finds soft deleted contacts - adding param is_deleted not working // ignore soft deleted contacts //$params['is_deleted'] = 0; $dedupeParams = CRM_Dedupe_Finder::formatParams($params, $params['contact_type']); $dedupeParams['check_permission'] = ''; //dupesByParams($params, $ctype, $level = 'Unsupervised', $except = array()) $ids = CRM_Dedupe_Finder::dupesByParams($dedupeParams, $params['contact_type']); } $petition_params['id'] = $this->_surveyId; $petition = array(); CRM_Campaign_BAO_Survey::retrieve($petition_params, $petition); switch (count($ids)) { case 0: //no matching contacts - create a new contact // Add a source for this new contact $params['source'] = ts('Petition Signature') . ' ' . $this->petition['title']; if ($this->petition['bypass_confirm']) { // send thank you email directly, bypassing confirmation $this->_sendEmailMode = self::EMAIL_THANK; // Set status for signature activity to completed $params['statusId'] = 2; } else { $this->_sendEmailMode = self::EMAIL_CONFIRM; // Set status for signature activity to scheduled until email is verified $params['statusId'] = 1; } break; case 1: $this->_contactId = $params['contactId'] = $ids[0]; // check if user has already signed this petition - redirects to Thank You if true $this->redirectIfSigned($params); if ($this->petition['bypass_confirm']) { // send thank you email directly, bypassing confirmation $this->_sendEmailMode = self::EMAIL_THANK; // Set status for signature activity to completed $params['statusId'] = 2; break; } // dedupe matched single contact, check for 'unconfirmed' tag if ($tag_name) { $tag = new CRM_Core_DAO_EntityTag(); $tag->entity_id = $this->_contactId; $tag->tag_id = $this->_tagId; if (!$tag->find()) { // send thank you email directly, the user is known and validated $this->_sendEmailMode = self::EMAIL_THANK; // Set status for signature activity to completed $params['statusId'] = 2; } else { // send email verification email $this->_sendEmailMode = self::EMAIL_CONFIRM; // Set status for signature activity to scheduled until email is verified $params['statusId'] = 1; } } break; default: // more than 1 matching contact // for time being, take the first matching contact (not sure that's the best strategy, but better than creating another duplicate) $this->_contactId = $params['contactId'] = $ids[0]; // check if user has already signed this petition - redirects to Thank You if true $this->redirectIfSigned($params); if ($this->petition['bypass_confirm']) { // send thank you email directly, bypassing confirmation $this->_sendEmailMode = self::EMAIL_THANK; // Set status for signature activity to completed $params['statusId'] = 2; break; } if ($tag_name) { $tag = new CRM_Core_DAO_EntityTag(); $tag->entity_id = $this->_contactId; $tag->tag_id = $this->_tagId; if (!$tag->find()) { // send thank you email $this->_sendEmailMode = self::EMAIL_THANK; // Set status for signature activity to completed $params['statusId'] = 2; } else { // send email verification email $this->_sendEmailMode = self::EMAIL_CONFIRM; // Set status for signature activity to scheduled until email is verified $params['statusId'] = 1; } } break; } $transaction = new CRM_Core_Transaction(); // CRM-17029 - get the add_to_group_id from the _contactProfileFields array. // There's a much more elegant solution with // array_values($this->_contactProfileFields)[0] but it's PHP 5.4+ only. $slice = array_slice($this->_contactProfileFields, 0, 1); $firstField = array_shift($slice); $addToGroupID = isset($firstField['add_to_group_id']) ? $firstField['add_to_group_id'] : NULL; $this->_contactId = CRM_Contact_BAO_Contact::createProfileContact($params, $this->_contactProfileFields, $this->_contactId, $addToGroupID, $this->_contactProfileId, $this->_ctype, TRUE); // get additional custom activity profile field data // to save with new signature activity record $surveyInfo = $this->bao->getSurveyInfo($this->_surveyId); $customActivityFields = CRM_Core_BAO_CustomField::getFields('Activity', FALSE, FALSE, $surveyInfo['activity_type_id']); $customActivityFields = CRM_Utils_Array::crmArrayMerge($customActivityFields, CRM_Core_BAO_CustomField::getFields('Activity', FALSE, FALSE, NULL, NULL, TRUE)); $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, NULL, 'Activity'); // create the signature activity record $params['contactId'] = $this->_contactId; $params['activity_campaign_id'] = CRM_Utils_Array::value('campaign_id', $this->petition); $result = $this->bao->createSignature($params); // send thank you or email verification emails // if logged in using Facebook connect and email on form matches Fb email, // no need for email confirmation, send thank you email if ($this->forceEmailConfirmed['flag'] && $this->forceEmailConfirmed['email'] == $params['email-Primary']) { $this->_sendEmailMode = self::EMAIL_THANK; } switch ($this->_sendEmailMode) { case self::EMAIL_THANK: // mark the signature activity as completed and set confirmed cookie $this->bao->confirmSignature($result->id, $this->_contactId, $this->_surveyId); break; case self::EMAIL_CONFIRM: // set 'Unconfirmed' tag for this new contact if ($tag_name) { unset($tag_params); $tag_params['contact_id'] = $this->_contactId; $tag_params['tag_id'] = $this->_tagId; $tag_params['version'] = 3; $tag_value = civicrm_api('entity_tag', 'create', $tag_params); } break; } //send email $params['activityId'] = $result->id; $params['tagId'] = $this->_tagId; $transaction->commit(); $this->bao->sendEmail($params, $this->_sendEmailMode); if ($result) { // call the hook before we redirect $this->postProcessHook(); // set the template to thank you $url = CRM_Utils_System::url('civicrm/petition/thankyou', 'pid=' . $this->_surveyId . '&id=' . $this->_sendEmailMode . '&reset=1'); CRM_Utils_System::redirect($url); } }
/** * build all the data structures needed to build the form * * @return void * @access public */ function preProcess() { $this->_votingTab = $this->get('votingTab'); $this->_reserveToInterview = $this->get('reserveToInterview'); if ($this->_reserveToInterview || $this->_votingTab) { //user came from voting tab / reserve form. foreach (array('surveyId', 'contactIds', 'interviewerId') as $fld) { $this->{"_{$fld}"} = $this->get($fld); } //get the target voter ids. if ($this->_votingTab) { $this->getVoterIds(); } } else { parent::preProcess(); //get the survey id from user submitted values. $this->_surveyId = CRM_Utils_Array::value('campaign_survey_id', $this->get('formValues')); $this->_interviewerId = CRM_Utils_Array::value('survey_interviewer_id', $this->get('formValues')); } //get the contact read only fields to display. require_once 'CRM/Core/BAO/Preferences.php'; $readOnlyFields = array_merge(array('contact_type' => '', 'sort_name' => ts('Name'))); //get the read only field data. $returnProperties = array_fill_keys(array_keys($readOnlyFields), 1); $returnProperties['contact_sub_type'] = true; //get the profile id. require_once 'CRM/Core/BAO/UFJoin.php'; $ufJoinParams = array('entity_id' => $this->_surveyId, 'entity_table' => 'civicrm_survey', 'module' => 'CiviCampaign'); $this->_ufGroupId = CRM_Core_BAO_UFJoin::findUFGroupId($ufJoinParams); $this->assign('ufGroupId', $this->_ufGroupId); //validate all voters for required activity. //get the survey activities for given voters. require_once 'CRM/Campaign/BAO/Survey.php'; $this->_surveyActivityIds = CRM_Campaign_BAO_Survey::voterActivityDetails($this->_surveyId, $this->_contactIds, $this->_interviewerId); require_once 'CRM/Core/PseudoConstant.php'; $activityStatus = CRM_Core_PseudoConstant::activityStatus('name'); $scheduledStatusId = array_search('Scheduled', $activityStatus); $activityIds = array(); foreach ($this->_contactIds as $key => $voterId) { $actVals = CRM_Utils_Array::value($voterId, $this->_surveyActivityIds); $statusId = CRM_Utils_Array::value('status_id', $actVals); $activityId = CRM_Utils_Array::value('activity_id', $actVals); if ($activityId && $statusId && $scheduledStatusId == $statusId) { $activityIds["activity_id_{$voterId}"] = $activityId; } else { unset($this->_contactIds[$key]); } } //retrieve the contact details. $voterDetails = CRM_Campaign_BAO_Survey::voterDetails($this->_contactIds, $returnProperties); $this->_allowAjaxReleaseButton = false; if ($this->_votingTab && (CRM_Core_Permission::check('manage campaign') || CRM_Core_Permission::check('administer CiviCampaign') || CRM_Core_Permission::check('release campaign contacts'))) { $this->_allowAjaxReleaseButton = true; } $this->assign('votingTab', $this->_votingTab); $this->assign('componentIds', $this->_contactIds); $this->assign('voterDetails', $voterDetails); $this->assign('readOnlyFields', $readOnlyFields); $this->assign('interviewerId', $this->_interviewerId); $this->assign('surveyActivityIds', json_encode($activityIds)); $this->assign('allowAjaxReleaseButton', $this->_allowAjaxReleaseButton); //get the survey values. $this->_surveyValues = $this->get('surveyValues'); if (!is_array($this->_surveyValues)) { $this->_surveyValues = array(); if ($this->_surveyId) { require_once 'CRM/Campaign/BAO/Survey.php'; $surveyParams = array('id' => $this->_surveyId); CRM_Campaign_BAO_Survey::retrieve($surveyParams, $this->_surveyValues); } $this->set('surveyValues', $this->_surveyValues); } $this->assign('surveyValues', $this->_surveyValues); //get the survey result options. $this->_resultOptions = $this->get('resultOptions'); if (!is_array($this->_resultOptions)) { $this->_resultOptions = array(); if ($resultOptionId = CRM_Utils_Array::value('result_id', $this->_surveyValues)) { require_once 'CRM/Core/OptionGroup.php'; $this->_resultOptions = CRM_Core_OptionGroup::valuesByID($resultOptionId); } $this->set('resultOptions', $this->_resultOptions); } //validate the required ids. $this->validateIds(); //append breadcrumb to survey dashboard. require_once 'CRM/Campaign/BAO/Campaign.php'; if (CRM_Campaign_BAO_Campaign::accessCampaignDashboard()) { $url = CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=survey'); CRM_Utils_System::appendBreadCrumb(array(array('title' => ts('Survey(s)'), 'url' => $url))); } //set the title. require_once 'CRM/Core/PseudoConstant.php'; $activityTypes = CRM_Core_PseudoConstant::activityType(false, true, false, 'label', true); $this->_surveyTypeId = CRM_Utils_Array::value('activity_type_id', $this->_surveyValues); CRM_Utils_System::setTitle(ts('Record %1 Responses', array(1 => $activityTypes[$this->_surveyTypeId]))); }
/** * takes an associative array and sends a thank you or email verification email * * @param array $params (reference ) an assoc array of name/value pairs * * @return * @access public * @static */ function sendEmail($params, $sendEmailMode) { /* sendEmailMode * CRM_Campaign_Form_Petition_Signature::EMAIL_THANK * connected user via login/pwd - thank you * or dedupe contact matched who doesn't have a tag CIVICRM_TAG_UNCONFIRMED - thank you * or login using fb connect - thank you + click to add msg to fb wall * * CRM_Campaign_Form_Petition_Signature::EMAIL_CONFIRM * send a confirmation request email */ require_once 'CRM/Campaign/Form/Petition/Signature.php'; // define constant CIVICRM_PETITION_CONTACTS, if not exist in civicrm.settings.php if (!defined('CIVICRM_PETITION_CONTACTS')) { define('CIVICRM_PETITION_CONTACTS', 'Petition Contacts'); } // check if the group defined by CIVICRM_PETITION_CONTACTS exists, else create it require_once 'api/v2/Group.php'; $group_params['title'] = CIVICRM_PETITION_CONTACTS; $groups = civicrm_group_get($group_params); if (CRM_Utils_Array::value('is_error', $groups) == 1 && CRM_Utils_Array::value('error_message', $groups) == 'No such group exists') { $group_params['is_active'] = 1; $group_params['visibility'] = 'Public Pages'; $newgroup = civicrm_group_add($group_params); if ($newgroup['is_error'] == 0) { $group_id[0] = $newgroup['result']; } } else { $group_id = array_keys($groups); } // get petition info $petitionParams['id'] = $params['sid']; $petitionInfo = array(); CRM_Campaign_BAO_Survey::retrieve($petitionParams, $petitionInfo); if (empty($petitionInfo)) { CRM_Core_Error::fatal('Petition doesn\'t exist.'); } require_once 'CRM/Core/BAO/Domain.php'; //get the default domain email address. list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail(); require_once 'CRM/Core/BAO/MailSettings.php'; $emailDomain = CRM_Core_BAO_MailSettings::defaultDomain(); require_once 'CRM/Contact/BAO/Contact.php'; $toName = CRM_Contact_BAO_Contact::displayName($params['contactId']); $replyTo = "do-not-reply@{$emailDomain}"; // set additional general message template params (custom tokens to use in email msg templates) // tokens then available in msg template as {$petition.title}, etc $petitionTokens['title'] = $petitionInfo['title']; $petitionTokens['petitionId'] = $params['sid']; $tplParams['petition'] = $petitionTokens; switch ($sendEmailMode) { case CRM_Campaign_Form_Petition_Signature::EMAIL_THANK: //add this contact to the CIVICRM_PETITION_CONTACTS group require_once 'api/v2/GroupContact.php'; $params['group_id'] = $group_id[0]; $params['contact_id'] = $params['contactId']; civicrm_group_contact_add($params); require_once 'CRM/Core/BAO/MessageTemplates.php'; if ($params['email-Primary']) { CRM_Core_BAO_MessageTemplates::sendTemplate(array('groupName' => 'msg_tpl_workflow_petition', 'valueName' => 'petition_sign', 'contactId' => $params['contactId'], 'tplParams' => $tplParams, 'from' => "\"{$domainEmailName}\" <{$domainEmailAddress}>", 'toName' => $toName, 'toEmail' => $params['email-Primary'], 'replyTo' => $replyTo, 'petitionId' => $params['sid'], 'petitionTitle' => $petitionInfo['title'])); } break; case CRM_Campaign_Form_Petition_Signature::EMAIL_CONFIRM: // create mailing event subscription record for this contact // this will allow using a hash key to confirm email address by sending a url link require_once 'CRM/Mailing/Event/BAO/Subscribe.php'; $se = CRM_Mailing_Event_BAO_Subscribe::subscribe($group_id[0], $params['email-Primary'], $params['contactId']); // require_once 'CRM/Core/BAO/Domain.php'; // $domain =& CRM_Core_BAO_Domain::getDomain(); $config = CRM_Core_Config::singleton(); $localpart = CRM_Core_BAO_MailSettings::defaultLocalpart(); require_once 'CRM/Utils/Verp.php'; $replyTo = implode($config->verpSeparator, array($localpart . 'c', $se->contact_id, $se->id, $se->hash)) . "@{$emailDomain}"; $confirmUrl = CRM_Utils_System::url('civicrm/petition/confirm', "reset=1&cid={$se->contact_id}&sid={$se->id}&h={$se->hash}&a={$params['activityId']}&p={$params['sid']}", true); $confirmUrlPlainText = CRM_Utils_System::url('civicrm/petition/confirm', "reset=1&cid={$se->contact_id}&sid={$se->id}&h={$se->hash}&a={$params['activityId']}&p={$params['sid']}", true, null, false); // set email specific message template params and assign to tplParams $petitionTokens['confirmUrl'] = $confirmUrl; $petitionTokens['confirmUrlPlainText'] = $confirmUrlPlainText; $tplParams['petition'] = $petitionTokens; require_once 'CRM/Core/BAO/MessageTemplates.php'; if ($params['email-Primary']) { CRM_Core_BAO_MessageTemplates::sendTemplate(array('groupName' => 'msg_tpl_workflow_petition', 'valueName' => 'petition_confirmation_needed', 'contactId' => $params['contactId'], 'tplParams' => $tplParams, 'from' => "\"{$domainEmailName}\" <{$domainEmailAddress}>", 'toName' => $toName, 'toEmail' => $params['email-Primary'], 'replyTo' => $replyTo, 'petitionId' => $params['sid'], 'petitionTitle' => $petitionInfo['title'], 'confirmUrl' => $confirmUrl)); } break; } }
static function formRule($params, $rules, &$form) { $errors = array(); $surveyDetails = array(); if (CRM_Utils_Array::value('survey_id', $params)) { $form->_surveyId = $params['survey_id']; $params = array('id' => $form->_surveyId); $form->_surveyDetails = CRM_Campaign_BAO_Survey::retrieve($params, $surveyDetails); $numVoters = CRM_Core_DAO::singleValueQuery("SELECT COUNT(*) FROM " . self::ACTIVITY_SURVEY_DETAIL_TABLE . " WHERE status_id = 'H' AND survey_id = %1 ", array(1 => array($form->_surveyId, 'Integer'))); $form->_numVoters = isset($numVoters) ? $numVoters : 0; if (CRM_Utils_Array::value('max_number_of_contacts', $surveyDetails) && $form->_numVoters && $surveyDetails['max_number_of_contacts'] <= $form->_numVoters) { $errors['survey_id'] = ts("Voter Reservation is full for this survey."); } else { if (CRM_Utils_Array::value('default_number_of_contacts', $surveyDetails)) { if (count($form->_contactIds) > $surveyDetails['default_number_of_contacts']) { $errors['survey_id'] = ts("You can select maximum %1 contact(s) at a time for voter reservation of this survey.", array(1 => $surveyDetails['default_number_of_contacts'])); } } } } return $errors; }
public function preProcess() { require_once 'CRM/Campaign/BAO/Campaign.php'; if (!CRM_Campaign_BAO_Campaign::accessCampaignDashboard()) { CRM_Utils_System::permissionDenied(); } $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this); if ($this->_context) { $this->assign('context', $this->_context); } $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this); if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::DELETE)) { $this->_surveyId = CRM_Utils_Request::retrieve('id', 'Positive', $this, true); if ($this->_action & CRM_Core_Action::UPDATE) { CRM_Utils_System::setTitle(ts('Edit Survey')); } else { CRM_Utils_System::setTitle(ts('Delete Survey')); } } $session = CRM_Core_Session::singleton(); $url = CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=survey'); $session->pushUserContext($url); if ($this->_name != 'Petition') { CRM_Utils_System::appendBreadCrumb(array(array('title' => ts('Survey Dashboard'), 'url' => $url))); } $this->_values = array(); if ($this->_surveyId) { $this->assign('surveyId', $this->_surveyId); $values = $this->get('values'); // get contact values. if (!empty($values)) { $this->_values = $values; } else { $params = array('id' => $this->_surveyId); CRM_Campaign_BAO_Survey::retrieve($params, $this->_values, true); $this->set('values', $this->_values); } } $this->assign('action', $this->_action); }