]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/CampaignTrackers/CampaignTracker.php
Release 6.5.0
[Github/sugarcrm.git] / modules / CampaignTrackers / CampaignTracker.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
5  * 
6  * This program is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  * 
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
16  * details.
17  * 
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  * 
23  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
24  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
25  * 
26  * The interactive user interfaces in modified source and object code versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  * 
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the "Powered by
32  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
33  * technical reasons, the Appropriate Legal Notices must display the words
34  * "Powered by SugarCRM".
35  ********************************************************************************/
36
37 /*********************************************************************************
38
39  * Description: The primary Function of this file is to manage all the data
40  * used by other files in this nodule. It should extend the SugarBean which implements
41  * all the basic database operations. Any custom behaviors can be implemented here by
42  * implementing functions available in the SugarBean.
43  ********************************************************************************/
44
45
46
47
48
49
50 class CampaignTracker extends SugarBean {
51     /* Foreach instance of the bean you will need to access the fields in the table.
52     * So define a variable for each one of them, the variable name should be same as the field name
53     * Use this module's vardef file as a reference to create these variables.
54     */
55     var $id;
56     var $date_entered;
57     var $created_by;
58     var $date_modified;
59     var $modified_by;
60     var $deleted;
61     var $tracker_key;
62     var $tracker_url;
63     var $tracker_name;
64     var $campaign_id;
65     var $campaign_name;
66     var $message_url;
67     var $is_optout;
68
69     /* End field definitions*/
70
71     /* variable $table_name is used by SugarBean and methods in this file to constructs queries
72     * set this variables value to the table associated with this bean.
73     */
74     var $table_name = 'campaign_trkrs';
75
76     /*This  variable overrides the object_name variable in SugarBean, wher it has a value of null.*/
77     var $object_name = 'CampaignTracker';
78
79     /**/
80     var $module_dir = 'CampaignTrackers';
81
82     /* This is a legacy variable, set its value to true for new modules*/
83     var $new_schema = true;
84
85     /* $column_fields holds a list of columns that exist in this bean's table. This list is referenced
86     * when fetching or saving data for the bean. As you modify a table you need to keep this up to date.
87     */
88     var $column_fields = Array(
89             'id'
90             ,'tracker_key'
91             ,'tracker_url'
92             ,'tracker_name'
93             ,'campaign_id'
94     );
95
96     // This is used to retrieve related fields from form posts.
97     var $additional_column_fields = Array('campaign_id');
98     var $relationship_fields = Array('campaing_id'=>'campaign');
99
100     var $required_fields =  array('tracker_name'=>1,'tracker_url'=>1);
101     /*This bean's constructor*/
102     function CampaignTracker() {
103         parent::SugarBean();
104     }
105
106     function save() {
107         //make sure that the url has a scheme, if not then add http:// scheme
108         if ($this->is_optout!=1 ){
109             $url = strtolower(trim($this->tracker_url));
110             if(!preg_match('/^(http|https|ftp):\/\//i', $url)){
111                 $this->tracker_url = 'http://'.$url;
112             }
113         }
114
115         parent::save();
116     }
117
118     /* This method should return the summary text which is used to build the bread crumb navigation*/
119     /* Generally from this method you would return value of a field that is required and is of type string*/
120     function get_summary_text()
121     {
122         return "$this->tracker_name";
123     }
124
125
126     /* This method is used to generate query for the list form. The base implementation of this method
127     * uses the table_name and list_field variable to generate the basic query and then  adds the custom field
128     * join and team filter. If you are implementing this function do not forget to consider the additional conditions.
129     */
130
131     function fill_in_additional_detail_fields() {
132         global $sugar_config;
133
134         //setup campaign name.
135         $query = "SELECT name from campaigns where id = '$this->campaign_id'";
136         $result =$this->db->query($query,true," Error filling in additional detail fields: ");
137
138         // Get the id and the name.
139         $row = $this->db->fetchByAssoc($result);
140         if($row != null) {
141             $this->campaign_name=$row['name'];
142         }
143
144         if (!class_exists('Administration')) {
145
146         }
147         $admin=new Administration();
148         $admin->retrieveSettings('massemailer'); //retrieve all admin settings.
149         if (isset($admin->settings['massemailer_tracking_entities_location_type']) and $admin->settings['massemailer_tracking_entities_location_type']=='2'  and isset($admin->settings['massemailer_tracking_entities_location']) ) {
150             $this->message_url=$admin->settings['massemailer_tracking_entities_location'];
151         } else {
152             $this->message_url=$sugar_config['site_url'];
153         }
154         if ($this->is_optout == 1) {
155             $this->message_url .= '/index.php?entryPoint=removeme&identifier={MESSAGE_ID}';
156         } else {
157             $this->message_url .= '/index.php?entryPoint=campaign_trackerv2&track=' . $this->id;
158         }
159     }
160 }
161 ?>