3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2015
32 * @copyright DharmaTech (c) 2009
37 require_once 'Engage/Report/Form/List.php';
40 * Generate a phone call list report
42 class Engage_Report_Form_CallList
extends Engage_Report_Form_List
{
43 function __construct() {
45 parent
::__construct();
47 $this->_columns
= array(
50 'dao' => 'CRM_Core_DAO_Phone',
53 'phone' => array('default' => TRUE,
56 'grouping' => 'location-fields',
58 array('phone' => array('title' => ts('Phone'),
64 'dao' => 'CRM_Core_DAO_Address',
68 array('default' => TRUE),
70 array('default' => TRUE),
76 'state_province_id' =>
77 array('title' => ts('State/Province'),
81 array('title' => ts('Country'),
86 'street_address' => NULL,
88 'postal_code' => array('title' => 'Zip'),
90 'grouping' => 'location-fields',
94 'dao' => 'CRM_Core_DAO_Email',
96 array('email' => NULL),
97 'grouping' => 'location-fields',
101 'dao' => 'CRM_Contact_DAO_Contact',
105 array('title' => ts('Contact ID'),
109 array('title' => ts('Contact Name'),
114 array('title' => ts('Sex'),
118 array('title' => ts('Age'),
120 'type' => CRM_Report_FORM
::OP_INT
,
126 array('title' => ts('Contact Name'),
127 'operator' => 'like',
130 'grouping' => 'contact-fields',
134 'dao' => 'CRM_Contact_DAO_Contact',
137 $this->_demoLangCol
=>
139 'type' => CRM_Report_FORM
::OP_STRING
,
141 'title' => ts('Language'),
146 $this->_demoLangCol
=>
148 'title' => ts('Language'),
149 'operatorType' => CRM_Report_FORM
::OP_SELECT
,
150 'type' => CRM_Report_FORM
::OP_STRING
,
151 'methodName' => 'selector',
152 'options' => $this->_languages
,
155 'grouping' => 'contact-fields',
157 $this->_coreInfoTable
=>
159 'dao' => 'CRM_Contact_DAO_Contact',
162 $this->_coreTypeCol
=>
164 'type' => CRM_Report_FORM
::OP_STRING
,
166 'title' => ts('Constituent Type'),
168 $this->_coreOtherCol
=>
170 'no_display' => TRUE,
171 'type' => CRM_Report_Form
::OP_STRING
,
175 'grouping' => 'contact-fields',
179 'dao' => 'CRM_Contact_DAO_GroupContact',
185 'name' => 'group_id',
186 'title' => ts('Group'),
187 'operatorType' => CRM_Report_Form
::OP_MULTISELECT
,
189 'options' => CRM_Core_PseudoConstant
::group(),
196 function preProcess() {
197 parent
::preProcess();
198 $reportDate = CRM_Utils_Date
::customFormat(date('Y-m-d H:i'));
199 $this->assign('reportTitle', "{$this->_orgName} - Call List <br /> {$reportDate}");
203 * Generate WHERE clauses for SQL SELECT
206 // Don't list anybody who doesn't have a phone
207 // or has do_not_phone = 1
209 "{$this->_aliases['civicrm_contact']}.do_not_phone != 1",
210 "NOT ISNULL({$this->_aliases['civicrm_phone']}.phone)",
213 foreach ($this->_columns
as $tableName => $table) {
214 //echo "where: table name $tableName<br>";
216 // Treatment of normal filters
217 if (array_key_exists('filters', $table)) {
218 foreach ($table['filters'] as $fieldName => $field) {
219 //echo " field name $fieldName<br>";
222 if (CRM_Utils_Array
::value('type', $field) & CRM_Utils_Type
::T_DATE
) {
223 $relative = CRM_Utils_Array
::value("{$fieldName}_relative", $this->_params
);
224 $from = CRM_Utils_Array
::value("{$fieldName}_from", $this->_params
);
225 $to = CRM_Utils_Array
::value("{$fieldName}_to", $this->_params
);
227 $clause = $this->dateClause($field['name'], $relative, $from, $to);
229 elseif ($fieldName == $this->_demoLangCol
) {
230 if (!empty($this->_params
[$this->_demoLangCol
. '_value'])) {
231 $clause = "{$field['dbAlias']}='" . $this->_params
[$this->_demoLangCol
. '_value'] . "'";
235 $op = CRM_Utils_Array
::value("{$fieldName}_op", $this->_params
);
240 $clause = $this->whereClause($field,
242 CRM_Utils_Array
::value("{$fieldName}_value", $this->_params
),
243 CRM_Utils_Array
::value("{$fieldName}_min", $this->_params
),
244 CRM_Utils_Array
::value("{$fieldName}_max", $this->_params
)
248 //echo " clause=";
250 if (!empty($clause)) {
251 if (!empty($field['group'])) {
252 $clauses[] = $this->engageWhereGroupClause($clause);
255 $clauses[] = $clause;
262 if (empty($clauses)) {
263 $this->_where
= "WHERE ( 1 ) ";
266 $this->_where
= "WHERE " . implode(' AND ', $clauses);
268 //echo $this->_where . "<br>";
272 * Process submitted form
274 function postProcess() {
275 parent
::postProcess();
279 * Convert contact type info from fields separated by \x01 to a
280 * string of fields separated by commas
282 function type2str($type) {
283 $typeArray = explode("\x01", $type);
284 foreach ($typeArray as $key => $value) {
286 unset($typeArray[$key]);
289 return implode(', ', $typeArray);
292 function alterDisplay(&$rows) {
293 // custom code to alter rows
294 $genderList = CRM_Core_PseudoConstant
::get('CRM_Contact_DAO_Contact', 'gender_id');
296 foreach ($rows as $rowNum => $row) {
297 // handle state province
298 if (array_key_exists('civicrm_address_state_province_id', $row)) {
299 if ($value = $row['civicrm_address_state_province_id']) {
300 $rows[$rowNum]['civicrm_address_state_province_id'] = CRM_Core_PseudoConstant
::stateProvince($value);
306 if (array_key_exists('civicrm_address_country_id', $row)) {
307 if ($value = $row['civicrm_address_country_id']) {
308 $rows[$rowNum]['civicrm_address_country_id'] = CRM_Core_PseudoConstant
::country($value);
313 // Handle contactType
314 if (!empty($row[$this->_coreInfoTable
. '_' . $this->_coreTypeCol
])) {
315 $rows[$rowNum][$this->_coreInfoTable
. '_' . $this->_coreTypeCol
] = $this->type2str($rows[$rowNum][$this->_coreInfoTable
. '_' . $this->_coreTypeCol
]);
319 // date of birth to age
320 if (!empty($row['civicrm_contact_birth_date'])) {
321 $rows[$rowNum]['civicrm_contact_birth_date'] = $this->dob2age($row['civicrm_contact_birth_date']);
326 if (!empty($row['civicrm_contact_gender_id'])) {
327 $rows[$rowNum]['civicrm_contact_gender_id'] = $genderList[$row['civicrm_contact_gender_id']];
331 if (($this->_outputMode
!= 'html') && !empty($row[$this->_coreInfoTable
. '_' . $this->_coreOtherCol
])) {
332 $rows[$rowNum]['civicrm_contact_display_name'] .= "<br />" . $row[$this->_coreInfoTable
. '_' . $this->_coreOtherCol
];
336 // skip looking further in rows, if first row itself doesn't
337 // have the column we need
343 $columnOrder = array(
344 'civicrm_phone_phone',
345 'civicrm_contact_display_name',
346 'civicrm_address_street_address',
347 'civicrm_contact_birth_date',
348 'civicrm_contact_gender_id',
349 $this->_demoTable
. '_' . $this->_demoLangCol
,
350 $this->_coreInfoTable
. '_' . $this->_coreTypeCol
,
351 'civicrm_contact_id',
353 if ($this->_outputMode
== 'print' ||
$this->_outputMode
== 'pdf') {
354 $this->_columnHeaders
= array(
355 'civicrm_phone_phone' => array(
357 'type' => CRM_Utils_Type
::T_STRING
,
358 'class' => 'width=68',
360 'civicrm_contact_display_name' => array(
362 'type' => CRM_Utils_Type
::T_STRING
,
363 'class' => 'width=83',
365 'civicrm_address_street_address' => array(
366 'title' => 'ADDRESS',
367 'type' => CRM_Utils_Type
::T_STRING
,
368 'class' => 'width=117',
370 'civicrm_contact_birth_date' => array(
372 'type' => CRM_Utils_Type
::T_STRING
,
373 'class' => 'width=25',
375 'civicrm_contact_gender_id' => array(
377 'type' => CRM_Utils_Type
::T_STRING
,
378 'class' => 'width=18',
380 $this->_demoTable
. '_' . $this->_demoLangCol
=>
383 'type' => CRM_Utils_Type
::T_STRING
,
384 'class' => 'width=27',
386 $this->_coreInfoTable
. '_' . $this->_coreTypeCol
=>
388 'title' => 'Contact Type',
389 'type' => CRM_Utils_Type
::T_STRING
,
390 'class' => 'width=48',
394 'type' => CRM_Utils_Type
::T_STRING
,
395 'class' => 'width=48',
397 'response_codes' => array(
398 'title' => 'RESPONSE CODES',
399 'type' => CRM_Utils_Type
::T_STRING
,
400 'class' => 'width=91',
404 'type' => CRM_Utils_Type
::T_STRING
,
405 'class' => 'width=70',
407 'civicrm_contact_id' => array(
409 'type' => CRM_Utils_Type
::T_STRING
,
410 'class' => 'width=100',
414 foreach ($columnOrder as $col) {
415 foreach ($rows as $rowNum => $row) {
416 $newRows[$rowNum][$col] = $row[$col];
417 $newRows[$rowNum]['notes'] = ' ';
418 $newRows[$rowNum]['status'] = 'NH MV D WN';
419 $newRows[$rowNum]['response_codes'] = '
420 Q1 Y N U D<br />
421 Q2 Y N U D<br />
422 Q3 Y N U D<br />
423 Q4 Y N U D';
427 $this->assign('pageTotal', ceil((count($newRows) / 7)));
430 // make sure column order is same as in print mode
431 $tempHeaders = $this->_columnHeaders
;
432 $this->_columnHeaders
= array();
433 foreach ($columnOrder as $col) {
434 if (array_key_exists($col, $tempHeaders)) {
435 $this->_columnHeaders
[$col] = $tempHeaders[$col];
436 unset($tempHeaders[$col]);
439 $this->_columnHeaders
= $this->_columnHeaders +
$tempHeaders;