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