Merge pull request #10394 from JMAConsulting/DonotExport
[civicrm-core.git] / CRM / Activity / Form / ActivityLinks.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
7e9e8871 4 | CiviCRM version 4.7 |
6a488035 5 +--------------------------------------------------------------------+
0f03f337 6 | Copyright CiviCRM LLC (c) 2004-2017 |
6a488035
TO
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
d25dd0ee 26 */
6a488035
TO
27
28/**
29 *
30 * @package CRM
0f03f337 31 * @copyright CiviCRM LLC (c) 2004-2017
6a488035
TO
32 */
33
34/**
3819f101 35 * This class generates form components for Activity Links.
6a488035
TO
36 */
37class CRM_Activity_Form_ActivityLinks extends CRM_Core_Form {
38 public function buildQuickForm() {
cfcb7676
DL
39 self::commonBuildQuickForm($this);
40 }
41
ffd93213
EM
42 /**
43 * @param $self
44 */
00be9182 45 public static function commonBuildQuickForm($self) {
cfcb7676 46 $contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $self);
6a488035
TO
47 if (!$contactId) {
48 $contactId = CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullObject, FALSE, NULL, $_REQUEST);
49 }
50 $urlParams = "action=add&reset=1&cid={$contactId}&selectedChild=activity&atype=";
51
00c2ff9e
CW
52 $allTypes = CRM_Utils_Array::value('values', civicrm_api3('OptionValue', 'get', array(
53 'option_group_id' => 'activity_type',
54 'is_active' => 1,
55 'options' => array('limit' => 0, 'sort' => 'weight'),
56 )));
6a488035 57
00c2ff9e 58 $activityTypes = array();
6a488035 59
194b8168 60 foreach ($allTypes as $act) {
00c2ff9e
CW
61 $url = 'civicrm/activity/add';
62 if ($act['name'] == 'Email') {
63 if (!CRM_Utils_Mail::validOutBoundMail() || !$contactId) {
64 continue;
65 }
66 list($name, $email, $doNotEmail, $onHold, $isDeseased) = CRM_Contact_BAO_Contact::getContactDetails($contactId);
67 if (!$doNotEmail && $email && !$isDeseased) {
68 $url = 'civicrm/activity/email/add';
69 $act['label'] = ts('Send an Email');
70 }
71 else {
72 continue;
73 }
6a488035 74 }
00c2ff9e
CW
75 elseif ($act['name'] == 'SMS') {
76 if (!$contactId || !CRM_SMS_BAO_Provider::activeProviderCount()) {
77 continue;
78 }
79 // Check for existence of a mobile phone and ! do not SMS privacy setting
d48ca839 80 $mobileTypeID = CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_Phone', 'phone_type_id', 'Mobile');
00c2ff9e
CW
81 list($name, $phone, $doNotSMS) = CRM_Contact_BAO_Contact_Location::getPhoneDetails($contactId, $mobileTypeID);
82 if (!$doNotSMS && $phone) {
83 $url = 'civicrm/activity/sms/add';
84 }
85 else {
86 continue;
87 }
32864ccf 88 }
00c2ff9e
CW
89 elseif ($act['name'] == 'Print PDF Letter') {
90 $url = 'civicrm/activity/pdf/add';
6a488035 91 }
00c2ff9e
CW
92 elseif (!empty($act['filter']) || (!empty($act['component_id']) && $act['component_id'] != '1')) {
93 continue;
6a488035 94 }
00c2ff9e 95 $act['url'] = CRM_Utils_System::url($url,
194b8168 96 "{$urlParams}{$act['value']}", FALSE, NULL, FALSE
00c2ff9e
CW
97 );
98 $act += array('icon' => 'fa-plus-square-o');
99 $activityTypes[$act['value']] = $act;
6a488035
TO
100 }
101
cfcb7676 102 $self->assign('activityTypes', $activityTypes);
6a488035 103
cfcb7676 104 $self->assign('suppressForm', TRUE);
6a488035 105 }
96025800 106
6a488035 107}