more comment fixes
[civicrm-core.git] / CRM / Activity / Form / ActivityLinks.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2015
32 */
33
34 /**
35 * This class generates form components for Activity Links.
36 */
37 class CRM_Activity_Form_ActivityLinks extends CRM_Core_Form {
38 public function buildQuickForm() {
39 self::commonBuildQuickForm($this);
40 }
41
42 /**
43 * @param $self
44 */
45 public static function commonBuildQuickForm($self) {
46 $contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $self);
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
52 $activityTypes = $urls = array();
53
54 $emailTypeId = CRM_Core_OptionGroup::getValue('activity_type',
55 'Email',
56 'name'
57 );
58
59 $letterTypeId = CRM_Core_OptionGroup::getValue('activity_type',
60 'Print PDF Letter',
61 'name'
62 );
63 $SMSId = CRM_Core_OptionGroup::getValue('activity_type',
64 'Text Message (SMS)',
65 'label'
66 );
67
68 if (CRM_Utils_Mail::validOutBoundMail() && $contactId) {
69 list($name, $email, $doNotEmail, $onHold, $isDeseased) = CRM_Contact_BAO_Contact::getContactDetails($contactId);
70 if (!$doNotEmail && $email && !$isDeseased) {
71 $activityTypes = array($emailTypeId => ts('Send an Email'));
72 }
73 }
74
75 if ($contactId && CRM_SMS_BAO_Provider::activeProviderCount()) {
76 // Check for existence of a mobile phone and ! do not SMS privacy setting
77 $mobileTypeID = CRM_Core_OptionGroup::getValue('phone_type', 'Mobile', 'name');
78 list($name, $phone, $doNotSMS) = CRM_Contact_BAO_Contact_Location::getPhoneDetails($contactId, $mobileTypeID);
79
80 if (!$doNotSMS && $phone) {
81 $sendSMS = array($SMSId => ts('Send SMS'));
82 $activityTypes += $sendSMS;
83 }
84 }
85 // this returns activity types sorted by weight
86 $otherTypes = CRM_Core_PseudoConstant::activityType(FALSE);
87
88 $activityTypes += $otherTypes;
89
90 foreach (array_keys($activityTypes) as $typeId) {
91 if ($typeId == $emailTypeId) {
92 $urls[$typeId] = CRM_Utils_System::url('civicrm/activity/email/add',
93 "{$urlParams}{$typeId}", FALSE, NULL, FALSE
94 );
95 }
96 elseif ($typeId == $SMSId) {
97 $urls[$typeId] = CRM_Utils_System::url('civicrm/activity/sms/add',
98 "{$urlParams}{$typeId}", FALSE, NULL, FALSE
99 );
100 }
101 elseif ($typeId == $letterTypeId) {
102 $urls[$typeId] = CRM_Utils_System::url('civicrm/activity/pdf/add',
103 "{$urlParams}{$typeId}", FALSE, NULL, FALSE
104 );
105 }
106 else {
107 $urls[$typeId] = CRM_Utils_System::url('civicrm/activity/add',
108 "{$urlParams}{$typeId}", FALSE, NULL, FALSE
109 );
110 }
111 }
112
113 $self->assign('activityTypes', $activityTypes);
114 $self->assign('urls', $urls);
115
116 $self->assign('suppressForm', TRUE);
117 }
118
119 }