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,875 @@
<?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 contains all campaign related functions that are called using AJAX (jQuery)
*/
class CRM_Campaign_Page_AJAX {
public static function registerInterview() {
$fields = array(
'result',
'voter_id',
'survey_id',
'activity_id',
'surveyTitle',
'interviewer_id',
'activity_type_id',
);
$params = array();
foreach ($fields as $fld) {
$params[$fld] = CRM_Utils_Array::value($fld, $_POST);
}
$params['details'] = CRM_Utils_Array::value('note', $_POST);
$voterId = $params['voter_id'];
$activityId = $params['activity_id'];
$customKey = "field_{$voterId}_custom";
foreach ($_POST as $key => $value) {
if (strpos($key, $customKey) !== FALSE) {
$customFieldKey = str_replace(str_replace(substr($customKey, -6), '', $customKey), '', $key);
$params[$customFieldKey] = $value;
}
}
if (isset($_POST['field']) && !empty($_POST['field'][$voterId]) &&
is_array($_POST['field'][$voterId])
) {
foreach ($_POST['field'][$voterId] as $fieldKey => $value) {
$params[$fieldKey] = $value;
}
}
//lets pickup contat related fields.
foreach ($_POST as $key => $value) {
if (strpos($key, "field_{$voterId}_") !== FALSE &&
strpos($key, "field_{$voterId}_custom") === FALSE
) {
$key = substr($key, strlen("field_{$voterId}_"));
$params[$key] = $value;
}
}
$result = array(
'status' => 'fail',
'voter_id' => $voterId,
'activity_id' => $params['interviewer_id'],
);
//time to validate custom data.
$errors = CRM_Core_BAO_CustomField::validateCustomData($params);
if (is_array($errors) && !empty($errors)) {
$result['errors'] = $errors;
CRM_Utils_JSON::output($result);
}
//process the response/interview data.
$activityId = CRM_Campaign_Form_Task_Interview::registerInterview($params);
if ($activityId) {
$result['status'] = 'success';
}
CRM_Utils_JSON::output($result);
}
public static function loadOptionGroupDetails() {
$id = CRM_Utils_Request::retrieve('option_group_id', 'Integer', CRM_Core_DAO::$_nullObject, FALSE, NULL, 'POST');
$status = 'fail';
$opValues = array();
if ($id) {
$groupParams['id'] = $id;
CRM_Core_OptionValue::getValues($groupParams, $opValues);
}
$surveyId = CRM_Utils_Request::retrieve('survey_id', 'Integer', CRM_Core_DAO::$_nullObject, FALSE, NULL, 'POST');
if ($surveyId) {
$survey = new CRM_Campaign_DAO_Survey();
$survey->id = $surveyId;
$survey->result_id = $id;
if ($survey->find(TRUE)) {
if ($survey->recontact_interval) {
$recontactInterval = unserialize($survey->recontact_interval);
foreach ($opValues as $opValId => $opVal) {
if (is_numeric($recontactInterval[$opVal['label']])) {
$opValues[$opValId]['interval'] = $recontactInterval[$opVal['label']];
}
}
}
}
}
if (!empty($opValues)) {
$status = 'success';
}
$result = array(
'status' => $status,
'result' => $opValues,
);
CRM_Utils_JSON::output($result);
}
public function voterList() {
//get the search criteria params.
$searchCriteria = CRM_Utils_Request::retrieve('searchCriteria', 'String', CRM_Core_DAO::$_nullObject, FALSE, NULL, 'POST');
$searchParams = explode(',', $searchCriteria);
$params = $searchRows = array();
foreach ($searchParams as $param) {
if (!empty($_POST[$param])) {
$params[$param] = $_POST[$param];
}
}
//format multi-select group and contact types.
foreach (array(
'group',
'contact_type',
) as $param) {
$paramValue = CRM_Utils_Array::value($param, $params);
if ($paramValue) {
unset($params[$param]);
$paramValue = explode(',', $paramValue);
foreach ($paramValue as $key => $value) {
$params[$param][$value] = 1;
}
}
}
$voterClauseParams = array();
foreach (array(
'campaign_survey_id',
'survey_interviewer_id',
'campaign_search_voter_for',
) as $fld) {
$voterClauseParams[$fld] = CRM_Utils_Array::value($fld, $params);
}
$interviewerId = $surveyTypeId = $surveyId = NULL;
$searchVoterFor = $params['campaign_search_voter_for'];
if ($searchVoterFor == 'reserve') {
if (!empty($params['campaign_survey_id'])) {
$survey = new CRM_Campaign_DAO_Survey();
$survey->id = $surveyId = $params['campaign_survey_id'];
$survey->selectAdd('campaign_id, activity_type_id');
$survey->find(TRUE);
$campaignId = $survey->campaign_id;
$surveyTypeId = $survey->activity_type_id;
//allow voter search in sub-part of given constituents,
//but make sure in case user does not select any group.
//get all associated campaign groups in where filter, CRM-7406
$groups = CRM_Utils_Array::value('group', $params);
if ($campaignId && CRM_Utils_System::isNull($groups)) {
$campaignGroups = CRM_Campaign_BAO_Campaign::getCampaignGroups($campaignId);
foreach ($campaignGroups as $id => $group) {
$params['group'][$id] = 1;
}
}
//apply filter of survey contact type for search.
$contactType = CRM_Campaign_BAO_Survey::getSurveyContactType($surveyId);
if ($contactType) {
$params['contact_type'][$contactType] = 1;
}
unset($params['campaign_survey_id']);
}
unset($params['survey_interviewer_id']);
}
else {
//get the survey status in where clause.
$scheduledStatusId = array_search('Scheduled', CRM_Core_PseudoConstant::activityStatus('name'));
if ($scheduledStatusId) {
$params['survey_status_id'] = $scheduledStatusId;
}
//BAO/Query knows reserve/release/interview processes.
if ($params['campaign_search_voter_for'] == 'gotv') {
$params['campaign_search_voter_for'] = 'release';
}
}
$selectorCols = array(
'sort_name',
'street_address',
'street_name',
'street_number',
'street_unit',
);
// get the data table params.
$dataTableParams = array(
'sEcho' => array(
'name' => 'sEcho',
'type' => 'Integer',
'default' => 0,
),
'offset' => array(
'name' => 'iDisplayStart',
'type' => 'Integer',
'default' => 0,
),
'rowCount' => array(
'name' => 'iDisplayLength',
'type' => 'Integer',
'default' => 25,
),
'sort' => array(
'name' => 'iSortCol_0',
'type' => 'Integer',
'default' => 'sort_name',
),
'sortOrder' => array(
'name' => 'sSortDir_0',
'type' => 'String',
'default' => 'asc',
),
);
foreach ($dataTableParams as $pName => $pValues) {
$$pName = $pValues['default'];
if (!empty($_POST[$pValues['name']])) {
$$pName = CRM_Utils_Type::escape($_POST[$pValues['name']], $pValues['type']);
if ($pName == 'sort') {
$$pName = $selectorCols[$$pName];
}
}
}
$queryParams = CRM_Contact_BAO_Query::convertFormValues($params);
$query = new CRM_Contact_BAO_Query($queryParams,
NULL, NULL, FALSE, FALSE,
CRM_Contact_BAO_Query::MODE_CAMPAIGN,
TRUE
);
//get the voter clause to restrict and validate search.
$voterClause = CRM_Campaign_BAO_Query::voterClause($voterClauseParams);
$searchCount = $query->searchQuery(0, 0, NULL,
TRUE, FALSE,
FALSE, FALSE,
FALSE,
CRM_Utils_Array::value('whereClause', $voterClause),
NULL,
CRM_Utils_Array::value('fromClause', $voterClause)
);
$iTotal = $searchCount;
$selectorCols = array(
'contact_type',
'sort_name',
'street_address',
'street_name',
'street_number',
'street_unit',
);
$extraVoterColName = 'is_interview_conducted';
if ($params['campaign_search_voter_for'] == 'reserve') {
$extraVoterColName = 'reserve_voter';
}
if ($searchCount > 0) {
if ($searchCount < $offset) {
$offset = 0;
}
$config = CRM_Core_Config::singleton();
// get the result of the search
$result = $query->searchQuery($offset, $rowCount, $sort,
FALSE, FALSE,
FALSE, FALSE,
FALSE,
CRM_Utils_Array::value('whereClause', $voterClause),
$sortOrder,
CRM_Utils_Array::value('fromClause', $voterClause)
);
while ($result->fetch()) {
$contactID = $result->contact_id;
$typeImage = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type,
FALSE,
$result->contact_id
);
$searchRows[$contactID] = array('id' => $contactID);
foreach ($selectorCols as $col) {
$val = $result->$col;
if ($col == 'contact_type') {
$val = $typeImage;
}
$searchRows[$contactID][$col] = $val;
}
if ($searchVoterFor == 'reserve') {
$voterExtraColHtml = '<input type="checkbox" id="survey_activity[' . $contactID . ']" name="survey_activity[' . $contactID . ']" value=' . $contactID . ' onClick="processVoterData( this, \'reserve\' );" />';
$msg = ts('Respondent Reserved.');
$voterExtraColHtml .= "&nbsp;<span id='success_msg_{$contactID}' class='ok' style='display:none;'>$msg</span>";
}
elseif ($searchVoterFor == 'gotv') {
$surveyActId = $result->survey_activity_id;
$voterExtraColHtml = '<input type="checkbox" id="survey_activity[' . $surveyActId . ']" name="survey_activity[' . $surveyActId . ']" value=' . $surveyActId . ' onClick="processVoterData( this, \'gotv\' );" />';
$msg = ts('Vote Recorded.');
$voterExtraColHtml .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span id='success_msg_{$surveyActId}' class='ok' style='display:none;'>$msg</span>";
}
else {
$surveyActId = $result->survey_activity_id;
$voterExtraColHtml = '<input type="checkbox" id="survey_activity[' . $surveyActId . ']" name="survey_activity[' . $surveyActId . ']" value=' . $surveyActId . ' onClick="processVoterData( this, \'release\' );" />';
$msg = ts('Vote Recorded.');
$voterExtraColHtml .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span id='success_msg_{$surveyActId}' class='ok' style='display:none;'>$msg</span>";
}
$searchRows[$contactID][$extraVoterColName] = $voterExtraColHtml;
}
}
$selectorElements = array_merge($selectorCols, array($extraVoterColName));
$iFilteredTotal = $iTotal;
CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
echo CRM_Utils_JSON::encodeDataTableSelector($searchRows, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
CRM_Utils_System::civiExit();
}
public function processVoterData() {
$status = NULL;
$operation = CRM_Utils_Type::escape($_POST['operation'], 'String');
if ($operation == 'release') {
$activityId = CRM_Utils_Type::escape($_POST['activity_id'], 'Integer');
$isDelete = CRM_Utils_String::strtoboolstr(CRM_Utils_Type::escape($_POST['isDelete'], 'String'));
if ($activityId &&
CRM_Core_DAO::setFieldValue('CRM_Activity_DAO_Activity',
$activityId,
'is_deleted',
$isDelete
)
) {
$status = 'success';
}
}
elseif ($operation == 'reserve') {
$activityId = NULL;
$createActivity = TRUE;
if (!empty($_POST['activity_id'])) {
$activityId = CRM_Utils_Type::escape($_POST['activity_id'], 'Integer');
if ($activityId) {
$createActivity = FALSE;
$activityUpdated = CRM_Core_DAO::setFieldValue('CRM_Activity_DAO_Activity',
$activityId,
'is_deleted',
0
);
if ($activityUpdated) {
$status = 'success';
}
}
}
if ($createActivity) {
$ids = array(
'source_record_id',
'source_contact_id',
'target_contact_id',
'assignee_contact_id',
);
$activityParams = array();
foreach ($ids as $id) {
$val = CRM_Utils_Array::value($id, $_POST);
if (!$val) {
$createActivity = FALSE;
break;
}
$activityParams[$id] = CRM_Utils_Type::escape($val, 'Integer');
}
}
if ($createActivity) {
$isReserved = CRM_Utils_String::strtoboolstr(CRM_Utils_Type::escape($_POST['isReserved'], 'String'));
$activityStatus = CRM_Core_PseudoConstant::activityStatus('name');
$scheduledStatusId = array_search('Scheduled', $activityStatus);
if ($isReserved) {
$surveyValues = array();
$surveyParams = array('id' => $activityParams['source_record_id']);
CRM_Core_DAO::commonRetrieve('CRM_Campaign_DAO_Survey',
$surveyParams,
$surveyValues,
array('title', 'activity_type_id', 'campaign_id')
);
$activityTypeId = $surveyValues['activity_type_id'];
$surveytitle = CRM_Utils_Array::value('surveyTitle', $_POST);
if (!$surveytitle) {
$surveytitle = $surveyValues['title'];
}
$subject = $surveytitle . ' - ' . ts('Respondent Reservation');
$activityParams['subject'] = $subject;
$activityParams['status_id'] = $scheduledStatusId;
$activityParams['skipRecentView'] = 1;
$activityParams['activity_date_time'] = date('YmdHis');
$activityParams['activity_type_id'] = $activityTypeId;
$activityParams['campaign_id'] = isset($surveyValues['campaign_id']) ? $surveyValues['campaign_id'] : NULL;
$activity = CRM_Activity_BAO_Activity::create($activityParams);
if ($activity->id) {
$status = 'success';
}
}
else {
//delete reserved activity for given voter.
$voterIds = array($activityParams['target_contact_id']);
$activities = CRM_Campaign_BAO_Survey::voterActivityDetails($activityParams['source_record_id'],
$voterIds,
$activityParams['source_contact_id'],
array($scheduledStatusId)
);
foreach ($activities as $voterId => $values) {
$activityId = CRM_Utils_Array::value('activity_id', $values);
if ($activityId && ($values['status_id'] == $scheduledStatusId)) {
CRM_Core_DAO::setFieldValue('CRM_Activity_DAO_Activity',
$activityId,
'is_deleted',
TRUE
);
$status = 'success';
break;
}
}
}
}
}
elseif ($operation == 'gotv') {
$activityId = CRM_Utils_Type::escape($_POST['activity_id'], 'Integer');
$hasVoted = CRM_Utils_String::strtoboolstr(CRM_Utils_Type::escape($_POST['hasVoted'], 'String'));
if ($activityId) {
if ($hasVoted) {
$statusValue = 2;
}
else {
$statusValue = 1;
}
CRM_Core_DAO::setFieldValue('CRM_Activity_DAO_Activity',
$activityId,
'status_id',
$statusValue
);
$status = 'success';
}
}
CRM_Utils_JSON::output(array('status' => $status));
}
public function allActiveCampaigns() {
$currentCampaigns = CRM_Campaign_BAO_Campaign::getCampaigns();
$campaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, TRUE, FALSE, TRUE);
$options = array(
array(
'value' => '',
'title' => ts('- select -'),
),
);
foreach ($campaigns as $value => $title) {
$class = NULL;
if (!array_key_exists($value, $currentCampaigns)) {
$class = 'status-past';
}
$options[] = array(
'value' => $value,
'title' => $title,
'class' => $class,
);
}
$status = 'fail';
if (count($options) > 1) {
$status = 'success';
}
$results = array(
'status' => $status,
'campaigns' => $options,
);
CRM_Utils_JSON::output($results);
}
public function campaignGroups() {
$surveyId = CRM_Utils_Request::retrieve('survey_id', 'Positive',
CRM_Core_DAO::$_nullObject, FALSE, NULL, 'POST'
);
$campGroups = array();
if ($surveyId) {
$campaignId = CRM_Core_DAO::getFieldValue('CRM_Campaign_DAO_Survey', $surveyId, 'campaign_id');
if ($campaignId) {
$campGroups = CRM_Campaign_BAO_Campaign::getCampaignGroups($campaignId);
}
}
//CRM-7406 --If there is no campaign or no group associated with
//campaign of given survey, lets allow to search across all groups.
if (empty($campGroups)) {
$campGroups = CRM_Core_PseudoConstant::group();
}
$groups = array(
array(
'value' => '',
'title' => ts('- select -'),
),
);
foreach ($campGroups as $grpId => $title) {
$groups[] = array(
'value' => $grpId,
'title' => $title,
);
}
$results = array(
'status' => 'success',
'groups' => $groups,
);
CRM_Utils_JSON::output($results);
}
/**
* This function uses the deprecated v1 datatable api and needs updating. See CRM-16353.
* @deprecated
*/
public static function campaignList() {
//get the search criteria params.
$searchCriteria = CRM_Utils_Request::retrieve('searchCriteria', 'String', CRM_Core_DAO::$_nullObject, FALSE, NULL, 'POST');
$searchParams = explode(',', $searchCriteria);
$params = $searchRows = array();
foreach ($searchParams as $param) {
if (isset($_POST[$param])) {
$params[$param] = $_POST[$param];
}
}
//this is sequence columns on datatable.
$selectorCols = array(
'id',
'name',
'title',
'description',
'start_date',
'end_date',
'campaign_type_id',
'campaign_type',
'status_id',
'status',
'is_active',
'isActive',
'action',
);
// get the data table params.
$dataTableParams = array(
'sEcho' => array(
'name' => 'sEcho',
'type' => 'Integer',
'default' => 0,
),
'offset' => array(
'name' => 'iDisplayStart',
'type' => 'Integer',
'default' => 0,
),
'rowCount' => array(
'name' => 'iDisplayLength',
'type' => 'Integer',
'default' => 25,
),
'sort' => array(
'name' => 'iSortCol_0',
'type' => 'Integer',
'default' => 'start_date',
),
'sortOrder' => array(
'name' => 'sSortDir_0',
'type' => 'String',
'default' => 'desc',
),
);
foreach ($dataTableParams as $pName => $pValues) {
$$pName = $pValues['default'];
if (!empty($_POST[$pValues['name']])) {
$$pName = CRM_Utils_Type::escape($_POST[$pValues['name']], $pValues['type']);
if ($pName == 'sort') {
$$pName = $selectorCols[$$pName];
}
}
}
foreach (array(
'sort',
'offset',
'rowCount',
'sortOrder',
) as $sortParam) {
$params[$sortParam] = $$sortParam;
}
$searchCount = CRM_Campaign_BAO_Campaign::getCampaignSummary($params, TRUE);
$campaigns = CRM_Campaign_Page_DashBoard::getCampaignSummary($params);
$iTotal = $searchCount;
if ($searchCount > 0) {
if ($searchCount < $offset) {
$offset = 0;
}
foreach ($campaigns as $campaignID => $values) {
foreach ($selectorCols as $col) {
$searchRows[$campaignID][$col] = CRM_Utils_Array::value($col, $values);
}
}
}
$selectorElements = $selectorCols;
$iFilteredTotal = $iTotal;
CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
echo CRM_Utils_JSON::encodeDataTableSelector($searchRows, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
CRM_Utils_System::civiExit();
}
/**
* This function uses the deprecated v1 datatable api and needs updating. See CRM-16353.
* @deprecated
*/
public function surveyList() {
//get the search criteria params.
$searchCriteria = CRM_Utils_Request::retrieve('searchCriteria', 'String', CRM_Core_DAO::$_nullObject, FALSE, NULL, 'POST');
$searchParams = explode(',', $searchCriteria);
$params = $searchRows = array();
foreach ($searchParams as $param) {
if (!empty($_POST[$param])) {
$params[$param] = $_POST[$param];
}
}
//this is sequence columns on datatable.
$selectorCols = array(
'id',
'title',
'campaign_id',
'campaign',
'activity_type_id',
'activity_type',
'release_frequency',
'default_number_of_contacts',
'max_number_of_contacts',
'is_default',
'is_active',
'isActive',
'result_id',
'action',
'voterLinks',
);
// get the data table params.
$dataTableParams = array(
'sEcho' => array(
'name' => 'sEcho',
'type' => 'Integer',
'default' => 0,
),
'offset' => array(
'name' => 'iDisplayStart',
'type' => 'Integer',
'default' => 0,
),
'rowCount' => array(
'name' => 'iDisplayLength',
'type' => 'Integer',
'default' => 25,
),
'sort' => array(
'name' => 'iSortCol_0',
'type' => 'Integer',
'default' => 'created_date',
),
'sortOrder' => array(
'name' => 'sSortDir_0',
'type' => 'String',
'default' => 'desc',
),
);
foreach ($dataTableParams as $pName => $pValues) {
$$pName = $pValues['default'];
if (!empty($_POST[$pValues['name']])) {
$$pName = CRM_Utils_Type::escape($_POST[$pValues['name']], $pValues['type']);
if ($pName == 'sort') {
$$pName = $selectorCols[$$pName];
}
}
}
foreach (array(
'sort',
'offset',
'rowCount',
'sortOrder',
) as $sortParam) {
$params[$sortParam] = $$sortParam;
}
$surveys = CRM_Campaign_Page_DashBoard::getSurveySummary($params);
$searchCount = CRM_Campaign_BAO_Survey::getSurveySummary($params, TRUE);
$iTotal = $searchCount;
if ($searchCount > 0) {
if ($searchCount < $offset) {
$offset = 0;
}
foreach ($surveys as $surveyID => $values) {
foreach ($selectorCols as $col) {
$searchRows[$surveyID][$col] = CRM_Utils_Array::value($col, $values);
}
}
}
$selectorElements = $selectorCols;
$iFilteredTotal = $iTotal;
CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
echo CRM_Utils_JSON::encodeDataTableSelector($searchRows, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
CRM_Utils_System::civiExit();
}
/**
* This function uses the deprecated v1 datatable api and needs updating. See CRM-16353.
* @deprecated
*/
public function petitionList() {
//get the search criteria params.
$searchCriteria = CRM_Utils_Request::retrieve('searchCriteria', 'String', CRM_Core_DAO::$_nullObject, FALSE, NULL, 'POST');
$searchParams = explode(',', $searchCriteria);
$params = $searchRows = array();
foreach ($searchParams as $param) {
if (!empty($_POST[$param])) {
$params[$param] = $_POST[$param];
}
}
//this is sequence columns on datatable.
$selectorCols = array(
'id',
'title',
'campaign_id',
'campaign',
'activity_type_id',
'activity_type',
'is_default',
'is_active',
'isActive',
'action',
);
// get the data table params.
$dataTableParams = array(
'sEcho' => array(
'name' => 'sEcho',
'type' => 'Integer',
'default' => 0,
),
'offset' => array(
'name' => 'iDisplayStart',
'type' => 'Integer',
'default' => 0,
),
'rowCount' => array(
'name' => 'iDisplayLength',
'type' => 'Integer',
'default' => 25,
),
'sort' => array(
'name' => 'iSortCol_0',
'type' => 'Integer',
'default' => 'created_date',
),
'sortOrder' => array(
'name' => 'sSortDir_0',
'type' => 'String',
'default' => 'desc',
),
);
foreach ($dataTableParams as $pName => $pValues) {
$$pName = $pValues['default'];
if (!empty($_POST[$pValues['name']])) {
$$pName = CRM_Utils_Type::escape($_POST[$pValues['name']], $pValues['type']);
if ($pName == 'sort') {
$$pName = $selectorCols[$$pName];
}
}
}
foreach (array(
'sort',
'offset',
'rowCount',
'sortOrder',
) as $sortParam) {
$params[$sortParam] = $$sortParam;
}
$petitions = CRM_Campaign_Page_DashBoard::getPetitionSummary($params);
$searchCount = CRM_Campaign_BAO_Petition::getPetitionSummary($params, TRUE);
$iTotal = $searchCount;
if ($searchCount > 0) {
if ($searchCount < $offset) {
$offset = 0;
}
foreach ($petitions as $petitionID => $values) {
foreach ($selectorCols as $col) {
$searchRows[$petitionID][$col] = CRM_Utils_Array::value($col, $values);
}
}
}
$selectorElements = $selectorCols;
$iFilteredTotal = $iTotal;
CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
echo CRM_Utils_JSON::encodeDataTableSelector($searchRows, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
CRM_Utils_System::civiExit();
}
}

View file

@ -0,0 +1,511 @@
<?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
*/
/**
* Page for displaying Campaigns.
*/
class CRM_Campaign_Page_DashBoard extends CRM_Core_Page {
/**
* The action links that we need to display for the browse screen.
*
* @var array
*/
private static $_campaignActionLinks;
private static $_surveyActionLinks;
private static $_petitionActionLinks;
/**
* Get the action links for this page.
*
* @return array
*/
public static function campaignActionLinks() {
// check if variable _actionsLinks is populated
if (!isset(self::$_campaignActionLinks)) {
self::$_campaignActionLinks = array(
CRM_Core_Action::UPDATE => array(
'name' => ts('Edit'),
'url' => 'civicrm/campaign/add',
'qs' => 'reset=1&action=update&id=%%id%%',
'title' => ts('Update Campaign'),
),
CRM_Core_Action::DISABLE => array(
'name' => ts('Disable'),
'title' => ts('Disable Campaign'),
'ref' => 'crm-enable-disable',
),
CRM_Core_Action::ENABLE => array(
'name' => ts('Enable'),
'title' => ts('Enable Campaign'),
'ref' => 'crm-enable-disable',
),
CRM_Core_Action::DELETE => array(
'name' => ts('Delete'),
'url' => 'civicrm/campaign/add',
'qs' => 'action=delete&reset=1&id=%%id%%',
'title' => ts('Delete Campaign'),
),
);
}
return self::$_campaignActionLinks;
}
/**
* @return array
*/
public static function surveyActionLinks() {
// check if variable _actionsLinks is populated
if (!isset(self::$_surveyActionLinks)) {
self::$_surveyActionLinks = array(
CRM_Core_Action::UPDATE => array(
'name' => ts('Edit'),
'url' => 'civicrm/survey/configure/main',
'qs' => 'action=update&id=%%id%%&reset=1',
'title' => ts('Update Survey'),
),
CRM_Core_Action::DISABLE => array(
'name' => ts('Disable'),
'ref' => 'crm-enable-disable',
'title' => ts('Disable Survey'),
),
CRM_Core_Action::ENABLE => array(
'name' => ts('Enable'),
'ref' => 'crm-enable-disable',
'title' => ts('Enable Survey'),
),
CRM_Core_Action::DELETE => array(
'name' => ts('Delete'),
'url' => 'civicrm/survey/delete',
'qs' => 'id=%%id%%&reset=1',
'title' => ts('Delete Survey'),
),
);
}
return self::$_surveyActionLinks;
}
/**
* @return array
*/
public static function petitionActionLinks() {
if (!isset(self::$_petitionActionLinks)) {
self::$_petitionActionLinks = self::surveyActionLinks();
self::$_petitionActionLinks[CRM_Core_Action::UPDATE] = array(
'name' => ts('Edit'),
'url' => 'civicrm/petition/add',
'qs' => 'action=update&id=%%id%%&reset=1',
'title' => ts('Update Petition'),
);
self::$_petitionActionLinks[CRM_Core_Action::DISABLE] = array(
'name' => ts('Disable'),
'ref' => 'crm-enable-disable',
'title' => ts('Disable Petition'),
);
self::$_petitionActionLinks[CRM_Core_Action::ENABLE] = array(
'name' => ts('Enable'),
'ref' => 'crm-enable-disable',
'title' => ts('Enable Petition'),
);
self::$_petitionActionLinks[CRM_Core_Action::DELETE] = array(
'name' => ts('Delete'),
'url' => 'civicrm/petition/add',
'qs' => 'action=delete&id=%%id%%&reset=1',
'title' => ts('Delete Petition'),
);
self::$_petitionActionLinks[CRM_Core_Action::PROFILE] = array(
'name' => ts('Sign'),
'url' => 'civicrm/petition/sign',
'qs' => 'sid=%%id%%&reset=1',
'title' => ts('Sign Petition'),
'fe' => TRUE,
//CRM_Core_Action::PROFILE is used because there isn't a specific action for sign
);
self::$_petitionActionLinks[CRM_Core_Action::BROWSE] = array(
'name' => ts('Signatures'),
'url' => 'civicrm/activity/search',
'qs' => 'survey=%%id%%&force=1',
'title' => ts('List the signatures'),
//CRM_Core_Action::PROFILE is used because there isn't a specific action for sign
);
}
return self::$_petitionActionLinks;
}
/**
* @return mixed
*/
public function browseCampaign() {
// ensure valid javascript (these must have a value set)
$this->assign('searchParams', json_encode(NULL));
$this->assign('campaignTypes', json_encode(NULL));
$this->assign('campaignStatus', json_encode(NULL));
$this->assign('addCampaignUrl', CRM_Utils_System::url('civicrm/campaign/add', 'reset=1&action=add'));
$campaignCount = CRM_Campaign_BAO_Campaign::getCampaignCount();
//don't load find interface when no campaigns in db.
if (!$campaignCount) {
$this->assign('hasCampaigns', FALSE);
return;
}
$this->assign('hasCampaigns', TRUE);
//build the ajaxify campaign search and selector.
$controller = new CRM_Core_Controller_Simple('CRM_Campaign_Form_Search_Campaign', ts('Search Campaigns'));
$controller->set('searchTab', 'campaign');
$controller->setEmbedded(TRUE);
$controller->process();
return $controller->run();
}
/**
* @param array $params
*
* @return array
*/
public static function getCampaignSummary($params = array()) {
$campaignsData = array();
//get the campaigns.
$campaigns = CRM_Campaign_BAO_Campaign::getCampaignSummary($params);
if (!empty($campaigns)) {
$config = CRM_Core_Config::singleton();
$campaignType = CRM_Campaign_PseudoConstant::campaignType();
$campaignStatus = CRM_Campaign_PseudoConstant::campaignStatus();
$properties = array(
'id',
'name',
'title',
'status_id',
'description',
'campaign_type_id',
'is_active',
'start_date',
'end_date',
);
foreach ($campaigns as $cmpid => $campaign) {
foreach ($properties as $prop) {
$campaignsData[$cmpid][$prop] = CRM_Utils_Array::value($prop, $campaign);
}
$statusId = CRM_Utils_Array::value('status_id', $campaign);
$campaignsData[$cmpid]['status'] = CRM_Utils_Array::value($statusId, $campaignStatus);
$campaignsData[$cmpid]['campaign_id'] = $campaign['id'];
$campaignsData[$cmpid]['campaign_type'] = $campaignType[$campaign['campaign_type_id']];
$action = array_sum(array_keys(self::campaignActionLinks()));
if ($campaign['is_active']) {
$action -= CRM_Core_Action::ENABLE;
}
else {
$action -= CRM_Core_Action::DISABLE;
}
$isActive = ts('No');
if ($campaignsData[$cmpid]['is_active']) {
$isActive = ts('Yes');
}
$campaignsData[$cmpid]['isActive'] = $isActive;
if (!empty($campaignsData[$cmpid]['start_date'])) {
$campaignsData[$cmpid]['start_date'] = CRM_Utils_Date::customFormat($campaignsData[$cmpid]['start_date'],
$config->dateformatFull
);
}
if (!empty($campaignsData[$cmpid]['end_date'])) {
$campaignsData[$cmpid]['end_date'] = CRM_Utils_Date::customFormat($campaignsData[$cmpid]['end_date'],
$config->dateformatFull
);
}
$campaignsData[$cmpid]['action'] = CRM_Core_Action::formLink(self::campaignActionLinks(),
$action,
array('id' => $campaign['id']),
ts('more'),
FALSE,
'campaign.dashboard.row',
'Campaign',
$campaign['id']
);
}
}
return $campaignsData;
}
/**
* @return mixed
*/
public function browseSurvey() {
// ensure valid javascript - this must have a value set
$this->assign('searchParams', json_encode(NULL));
$this->assign('surveyTypes', json_encode(NULL));
$this->assign('surveyCampaigns', json_encode(NULL));
$this->assign('addSurveyUrl', CRM_Utils_System::url('civicrm/survey/add', 'reset=1&action=add'));
$surveyCount = CRM_Campaign_BAO_Survey::getSurveyCount();
//don't load find interface when no survey in db.
if (!$surveyCount) {
$this->assign('hasSurveys', FALSE);
return;
}
$this->assign('hasSurveys', TRUE);
//build the ajaxify survey search and selector.
$controller = new CRM_Core_Controller_Simple('CRM_Campaign_Form_Search_Survey', ts('Search Survey'));
$controller->set('searchTab', 'survey');
$controller->setEmbedded(TRUE);
$controller->process();
return $controller->run();
}
/**
* @param array $params
*
* @return array
*/
public static function getSurveySummary($params = array()) {
$surveysData = array();
//get the survey.
$config = CRM_Core_Config::singleton();
$surveys = CRM_Campaign_BAO_Survey::getSurveySummary($params);
if (!empty($surveys)) {
$campaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
$surveyType = CRM_Campaign_BAO_Survey::getSurveyActivityType();
foreach ($surveys as $sid => $survey) {
$surveysData[$sid] = $survey;
$campaignId = CRM_Utils_Array::value('campaign_id', $survey);
$surveysData[$sid]['campaign'] = CRM_Utils_Array::value($campaignId, $campaigns);
$surveysData[$sid]['activity_type'] = $surveyType[$survey['activity_type_id']];
if (!empty($survey['release_frequency'])) {
$surveysData[$sid]['release_frequency'] = ts('1 Day', array('plural' => '%count Days', 'count' => $survey['release_frequency']));
}
$action = array_sum(array_keys(self::surveyActionLinks($surveysData[$sid]['activity_type'])));
if ($survey['is_active']) {
$action -= CRM_Core_Action::ENABLE;
}
else {
$action -= CRM_Core_Action::DISABLE;
}
$isActive = ts('No');
if ($surveysData[$sid]['is_active']) {
$isActive = ts('Yes');
}
$surveysData[$sid]['isActive'] = $isActive;
$isDefault = NULL;
if ($surveysData[$sid]['is_default']) {
$isDefault = '<img src="' . $config->resourceBase . 'i/check.gif" alt="' . ts('Default') . '" />';
}
$surveysData[$sid]['is_default'] = $isDefault;
if ($surveysData[$sid]['result_id']) {
$resultSet = '<a href= "javascript:displayResultSet( ' . $sid . ',' . "'" . $surveysData[$sid]['title'] . "'" . ', ' . $surveysData[$sid]['result_id'] . ' )" title="' . ts('view result set') . '">' . ts('Result Set') . '</a>';
$surveysData[$sid]['result_id'] = $resultSet;
}
else {
$resultUrl = CRM_Utils_System::url("civicrm/survey/configure/results", "action=update&id={$sid}&reset=1");
$surveysData[$sid]['result_id'] = "<a href='{$resultUrl}' class='status-warning'>(" . ts('Incomplete. Click to configure result set.') . ')</a>';
}
$surveysData[$sid]['action'] = CRM_Core_Action::formLink(self::surveyActionLinks($surveysData[$sid]['activity_type']),
$action,
array('id' => $sid),
ts('more'),
FALSE,
'survey.dashboard.row',
'Survey',
$sid
);
if (CRM_Utils_Array::value('activity_type', $surveysData[$sid]) != 'Petition') {
$surveysData[$sid]['voterLinks'] = CRM_Campaign_BAO_Survey::buildPermissionLinks($sid,
TRUE,
ts('more')
);
}
if ($reportID = CRM_Campaign_BAO_Survey::getReportID($sid)) {
$url = CRM_Utils_System::url("civicrm/report/instance/{$reportID}", 'reset=1');
$surveysData[$sid]['title'] = "<a href='{$url}' title='View Survey Report'>{$surveysData[$sid]['title']}</a>";
}
}
}
return $surveysData;
}
/**
* Browse petitions.
*
* @return mixed|null
*/
public function browsePetition() {
// Ensure valid javascript - this must have a value set
$this->assign('searchParams', json_encode(NULL));
$this->assign('petitionCampaigns', json_encode(NULL));
$this->assign('addPetitionUrl', CRM_Utils_System::url('civicrm/petition/add', 'reset=1&action=add'));
$petitionCount = CRM_Campaign_BAO_Petition::getPetitionCount();
//don't load find interface when no petition in db.
if (!$petitionCount) {
$this->assign('hasPetitions', FALSE);
return NULL;
}
$this->assign('hasPetitions', TRUE);
// Build the ajax petition search and selector.
$controller = new CRM_Core_Controller_Simple('CRM_Campaign_Form_Search_Petition', ts('Search Petition'));
$controller->set('searchTab', 'petition');
$controller->setEmbedded(TRUE);
$controller->process();
return $controller->run();
}
/**
* @param array $params
*
* @return array
*/
public static function getPetitionSummary($params = array()) {
$config = CRM_Core_Config::singleton();
$petitionsData = array();
//get the petitions.
$petitions = CRM_Campaign_BAO_Petition::getPetitionSummary($params);
if (!empty($petitions)) {
$campaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
$petitionType = CRM_Campaign_BAO_Survey::getSurveyActivityType('label', TRUE);
foreach ($petitions as $pid => $petition) {
$petitionsData[$pid] = $petition;
$camapignId = CRM_Utils_Array::value('campaign_id', $petition);
$petitionsData[$pid]['campaign'] = CRM_Utils_Array::value($camapignId, $campaigns);
$petitionsData[$pid]['activity_type'] = $petitionType[$petition['activity_type_id']];
$action = array_sum(array_keys(self::petitionActionLinks()));
if ($petition['is_active']) {
$action -= CRM_Core_Action::ENABLE;
}
else {
$action -= CRM_Core_Action::DISABLE;
}
$isActive = ts('No');
if ($petitionsData[$pid]['is_active']) {
$isActive = ts('Yes');
}
$petitionsData[$pid]['isActive'] = $isActive;
$isDefault = NULL;
if ($petitionsData[$pid]['is_default']) {
$isDefault = '<img src="' . $config->resourceBase . 'i/check.gif" alt="' . ts('Default') . '" />';
}
$petitionsData[$pid]['is_default'] = $isDefault;
$petitionsData[$pid]['action'] = CRM_Core_Action::formLink(self::petitionActionLinks(),
$action,
array('id' => $pid),
ts('more'),
FALSE,
'petition.dashboard.row',
'Petition',
$pid
);
}
}
return $petitionsData;
}
public function browse() {
$this->_tabs = array(
'campaign' => ts('Campaigns'),
'survey' => ts('Surveys'),
'petition' => ts('Petitions'),
);
$subPageType = CRM_Utils_Request::retrieve('type', 'String', $this);
if ($subPageType) {
if (!isset($this->_tabs[$subPageType])) {
CRM_Utils_System::permissionDenied();
}
//load the data in tabs.
$this->{'browse' . ucfirst($subPageType)}();
$this->assign('subPageType', ucfirst($subPageType));
}
else {
//build the tabs.
$this->buildTabs();
}
CRM_Core_Resources::singleton()
->addScriptFile('civicrm', 'templates/CRM/common/TabHeader.js', 1, 'html-header')
->addSetting(array(
'tabSettings' => array(
'active' => strtolower(CRM_Utils_Array::value('subPage', $_GET, 'campaign')),
),
));
}
/**
* @return string
*/
public function run() {
if (!CRM_Campaign_BAO_Campaign::accessCampaign()) {
CRM_Utils_System::permissionDenied();
}
$this->browse();
return parent::run();
}
public function buildTabs() {
$allTabs = array();
foreach ($this->_tabs as $name => $title) {
$allTabs[$name] = array(
'title' => $title,
'valid' => TRUE,
'active' => TRUE,
'link' => CRM_Utils_System::url('civicrm/campaign', "reset=1&type=$name"),
);
}
$allTabs['campaign']['class'] = 'livePage';
$this->assign('tabHeader', $allTabs);
}
}

View file

@ -0,0 +1,61 @@
<?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
*/
/**
* Page for displaying Petition Signatures.
*/
class CRM_Campaign_Page_Petition extends CRM_Core_Page {
public function browse() {
//get the survey id
$surveyId = CRM_Utils_Request::retrieve('sid', 'Positive', $this);
$signatures = CRM_Campaign_BAO_Petition::getPetitionSignature($surveyId);
$this->assign('signatures', $signatures);
}
/**
* @return string
*/
public function run() {
$action = CRM_Utils_Request::retrieve('action', 'String',
$this, FALSE, 0
);
$this->assign('action', $action);
$this->browse();
return parent::run();
}
}

View file

@ -0,0 +1,133 @@
<?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
*/
class CRM_Campaign_Page_Petition_Confirm extends CRM_Core_Page {
/**
* @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');
$subscribe_id = CRM_Utils_Request::retrieve('sid', 'Integer');
$hash = CRM_Utils_Request::retrieve('h', 'String');
$activity_id = CRM_Utils_Request::retrieve('a', 'String');
$petition_id = CRM_Utils_Request::retrieve('pid', 'String');
if (!$petition_id) {
$petition_id = CRM_Utils_Request::retrieve('p', 'String');
}
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();
}
/**
* Confirm email verification.
*
* @param int $contact_id
* The id of the contact.
* @param int $subscribe_id
* The id of the subscription event.
* @param string $hash
* The hash.
*
* @param int $activity_id
* @param int $petition_id
*
* @return bool
* True on success
*/
public static function confirm($contact_id, $subscribe_id, $hash, $activity_id, $petition_id) {
$se = CRM_Mailing_Event_BAO_Subscribe::verify($contact_id, $subscribe_id, $hash);
if (!$se) {
return FALSE;
}
$transaction = new CRM_Core_Transaction();
$ce = new CRM_Mailing_Event_BAO_Confirm();
$ce->event_subscribe_id = $se->id;
$ce->time_stamp = date('YmdHis');
$ce->save();
CRM_Contact_BAO_GroupContact::addContactsToGroup(
array($contact_id),
$se->group_id,
'Email',
'Added',
$ce->id
);
$bao = new CRM_Campaign_BAO_Petition();
$bao->confirmSignature($activity_id, $contact_id, $petition_id);
}
}

View file

@ -0,0 +1,65 @@
<?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
*/
class CRM_Campaign_Page_Petition_ThankYou extends CRM_Core_Page {
/**
* Run page.
*
* @return string
*/
public 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);
$this->assign('is_share', CRM_Utils_Array::value('is_share', $this->petition));
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();
}
}

View file

@ -0,0 +1,209 @@
<?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
*/
/**
* Page for displaying list of Gender.
*/
class CRM_Campaign_Page_SurveyType extends CRM_Core_Page_Basic {
public $useLivePageJS = TRUE;
/**
* The action links that we need to display for the browse screen.
*
* @var array
*/
static $_links = NULL;
/**
* The option group name.
*
* @var array
*/
protected $_gName;
/**
* The option group name in display format (capitalized, without underscores...etc)
*
* @var array
*/
protected $_GName;
/**
* The option group id.
*
* @var array
*/
protected $_gid = NULL;
/**
* Obtains the group name from url and sets the title.
*/
public function preProcess() {
$this->_gName = 'activity_type';
$this->_gid = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $this->_gName, 'id', 'name');
$this->_GName = 'Survey Type';
$this->assign('gName', $this->_gName);
$this->assign('GName', $this->_GName);
CRM_Utils_System::setTitle(ts('%1 Options', array(1 => $this->_GName)));
$this->assign('addSurveyType', array("civicrm/admin/campaign/surveyType", "reset=1&action=add"));
}
/**
* Get BAO Name.
*
* @return string
* Classname of BAO.
*/
public function getBAOName() {
return 'CRM_Core_BAO_OptionValue';
}
/**
* Get action Links.
*
* @return array
* (reference) of action links
*/
public function &links() {
if (!(self::$_links)) {
self::$_links = array(
CRM_Core_Action::UPDATE => array(
'name' => ts('Edit'),
'url' => 'civicrm/admin/campaign/surveyType',
'qs' => 'action=update&id=%%id%%&reset=1',
'title' => ts('Edit %1', array(1 => $this->_gName)),
),
CRM_Core_Action::DISABLE => array(
'name' => ts('Disable'),
'ref' => 'crm-enable-disable',
'title' => ts('Disable %1', array(1 => $this->_gName)),
),
CRM_Core_Action::ENABLE => array(
'name' => ts('Enable'),
'ref' => 'crm-enable-disable',
'title' => ts('Enable %1', array(1 => $this->_gName)),
),
CRM_Core_Action::DELETE => array(
'name' => ts('Delete'),
'url' => 'civicrm/admin/campaign/surveyType',
'qs' => 'action=delete&id=%%id%%',
'title' => ts('Delete %1 Type', array(1 => $this->_gName)),
),
);
}
return self::$_links;
}
/**
* Run the basic page (run essentially starts execution for that page).
*/
public function run() {
$this->preProcess();
return parent::run();
}
/**
* Browse all options.
*/
public function browse() {
$campaingCompId = CRM_Core_Component::getComponentID('CiviCampaign');
$groupParams = array('name' => $this->_gName);
$optionValues = CRM_Core_OptionValue::getRows($groupParams, $this->links(), 'component_id,weight');
foreach ($optionValues as $key => $optionValue) {
if (CRM_Utils_Array::value('component_id', $optionValue) != $campaingCompId) {
unset($optionValues[$key]);
}
}
$returnURL = CRM_Utils_System::url("civicrm/admin/campaign/surveyType",
"reset=1"
);
$filter = "option_group_id = " . $this->_gid;
CRM_Utils_Weight::addOrder($optionValues, 'CRM_Core_DAO_OptionValue',
'id', $returnURL, $filter
);
$this->assign('rows', $optionValues);
}
/**
* Get name of edit form.
*
* @return string
* Classname of edit form.
*/
public function editForm() {
return 'CRM_Campaign_Form_SurveyType';
}
/**
* Get edit form name.
*
* @return string
* name of this page.
*/
public function editName() {
return $this->_GName;
}
/**
* Get user context.
*
* @param null $mode
*
* @return string
* user context.
*/
public function userContext($mode = NULL) {
return 'civicrm/admin/campaign/surveyType';
}
/**
* Get userContext params.
*
* @param int $mode
* Mode that we are in.
*
* @return string
*/
public function userContextParams($mode = NULL) {
return 'reset=1';
}
}

View file

@ -0,0 +1,145 @@
<?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
*/
/**
* Page for voting tab interface.
*/
class CRM_Campaign_Page_Vote extends CRM_Core_Page {
private $_surveyId;
private $_interviewerId;
/**
* @return mixed
*/
public function reserve() {
//build ajax voter search and selector.
$controller = new CRM_Core_Controller_Simple('CRM_Campaign_Form_Gotv', ts('Reserve Respondents'));
$controller->set('votingTab', TRUE);
$controller->set('subVotingTab', 'searchANDReserve');
$controller->process();
return $controller->run();
}
/**
* @return mixed
*/
public function interview() {
//build interview and release voter interface.
$controller = new CRM_Core_Controller_Simple('CRM_Campaign_Form_Task_Interview', ts('Interview Respondents'));
$controller->set('votingTab', TRUE);
$controller->set('subVotingTab', 'searchANDInterview');
if ($this->_surveyId) {
$controller->set('surveyId', $this->_surveyId);
}
if ($this->_interviewerId) {
$controller->set('interviewerId', $this->_interviewerId);
}
$controller->process();
return $controller->run();
}
public function browse() {
$this->_tabs = array(
'reserve' => ts('Reserve Respondents'),
'interview' => ts('Interview Respondents'),
);
$this->_surveyId = CRM_Utils_Request::retrieve('sid', 'Positive', $this);
$this->_interviewerId = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
$subPageType = CRM_Utils_Request::retrieve('type', 'String', $this);
if ($subPageType) {
$session = CRM_Core_Session::singleton();
$session->pushUserContext(CRM_Utils_System::url('civicrm/campaign/vote', "reset=1&subPage={$subPageType}"));
//load the data in tabs.
$this->{$subPageType}();
}
else {
//build the tabs.
$this->buildTabs();
}
$this->assign('subPageType', $subPageType);
CRM_Core_Resources::singleton()
->addScriptFile('civicrm', 'templates/CRM/common/TabHeader.js', 1, 'html-header')
->addSetting(array(
'tabSettings' => array(
'active' => strtolower(CRM_Utils_Array::value('subPage', $_GET, 'reserve')),
),
));
}
/**
* @return string
*/
public function run() {
$this->browse();
return parent::run();
}
public function buildTabs() {
$allTabs = array();
foreach ($this->_tabs as $name => $title) {
// check for required permissions.
if (!CRM_Core_Permission::check(array(
array(
'manage campaign',
'administer CiviCampaign',
"{$name} campaign contacts",
),
))
) {
continue;
}
$urlParams = "type={$name}";
if ($this->_surveyId) {
$urlParams .= "&sid={$this->_surveyId}";
}
if ($this->_interviewerId) {
$urlParams .= "&cid={$this->_interviewerId}";
}
$allTabs[$name] = array(
'title' => $title,
'valid' => TRUE,
'active' => TRUE,
'link' => CRM_Utils_System::url('civicrm/campaign/vote', $urlParams),
);
}
$this->assign('tabHeader', empty($allTabs) ? FALSE : $allTabs);
}
}