Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
8c9251b3 | 6 | | Copyright CiviCRM LLC (c) 2004-2018 | |
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 | |
8c9251b3 | 31 | * @copyright CiviCRM LLC (c) 2004-2018 |
6a488035 TO |
32 | */ |
33 | ||
34 | /** | |
3819f101 | 35 | * This class generates form components for Activity Links. |
6a488035 TO |
36 | */ |
37 | class 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 | } | |
83a8a606 MW |
66 | list($name, $email, $doNotEmail, $onHold, $isDeceased) = CRM_Contact_BAO_Contact::getContactDetails($contactId); |
67 | if (!$doNotEmail && $email && !$isDeceased) { | |
00c2ff9e CW |
68 | $url = 'civicrm/activity/email/add'; |
69 | $act['label'] = ts('Send an Email'); | |
70 | } | |
71 | else { | |
72 | continue; | |
73 | } | |
6a488035 | 74 | } |
00c2ff9e | 75 | elseif ($act['name'] == 'SMS') { |
63483feb | 76 | if (!$contactId || !CRM_SMS_BAO_Provider::activeProviderCount() || !CRM_Core_Permission::check('send SMS')) { |
00c2ff9e CW |
77 | continue; |
78 | } | |
79 | // Check for existence of a mobile phone and ! do not SMS privacy setting | |
c9184ed3 MW |
80 | try { |
81 | $phone = civicrm_api3('Phone', 'getsingle', array( | |
82 | 'contact_id' => $contactId, | |
83 | 'phone_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Core_BAO_Phone', 'phone_type_id', 'Mobile'), | |
84 | 'return' => array('phone', 'contact_id'), | |
85 | 'options' => array('limit' => 1, 'sort' => "is_primary DESC"), | |
86 | 'api.Contact.getsingle' => array( | |
87 | 'id' => '$value.contact_id', | |
88 | 'return' => 'do_not_sms', | |
89 | ), | |
90 | )); | |
91 | } | |
92 | catch (CiviCRM_API3_Exception $e) { | |
93 | continue; | |
94 | } | |
95 | if (!$phone['api.Contact.getsingle']['do_not_sms'] && $phone['phone']) { | |
00c2ff9e CW |
96 | $url = 'civicrm/activity/sms/add'; |
97 | } | |
98 | else { | |
99 | continue; | |
100 | } | |
32864ccf | 101 | } |
00c2ff9e CW |
102 | elseif ($act['name'] == 'Print PDF Letter') { |
103 | $url = 'civicrm/activity/pdf/add'; | |
6a488035 | 104 | } |
00c2ff9e CW |
105 | elseif (!empty($act['filter']) || (!empty($act['component_id']) && $act['component_id'] != '1')) { |
106 | continue; | |
6a488035 | 107 | } |
00c2ff9e | 108 | $act['url'] = CRM_Utils_System::url($url, |
194b8168 | 109 | "{$urlParams}{$act['value']}", FALSE, NULL, FALSE |
00c2ff9e CW |
110 | ); |
111 | $act += array('icon' => 'fa-plus-square-o'); | |
112 | $activityTypes[$act['value']] = $act; | |
6a488035 TO |
113 | } |
114 | ||
cfcb7676 | 115 | $self->assign('activityTypes', $activityTypes); |
6a488035 | 116 | |
cfcb7676 | 117 | $self->assign('suppressForm', TRUE); |
6a488035 | 118 | } |
96025800 | 119 | |
6a488035 | 120 | } |