]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/CampaignTrackers/CampaignTracker.php
Release 6.1.4
[Github/sugarcrm.git] / modules / CampaignTrackers / CampaignTracker.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2011 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 impelments
41  * all the basic database operations. Any custom behaviors can be implemented here by
42  * implemeting 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 varaible 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
102         /*This bean's constructor*/
103         function CampaignTracker() {
104                 parent::SugarBean();
105         }
106
107     function save() {
108             //make sure that the url has a scheme, if not then add http:// scheme
109             if ($this->is_optout!=1 ){
110                 $url = strtolower(trim($this->tracker_url));
111                     if(!preg_match('/^(http|https|ftp):\/\//i', $url)){
112                         $this->tracker_url = 'http://'.$url;
113                     }
114             }
115
116         parent::save(); 
117     }
118     
119         /* This method should return the summary text which is used to build the bread crumb navigation*/
120         /* Generally from this method you would return value of a field that is required and is of type string*/
121         function get_summary_text()
122         {
123                 return "$this->tracker_name";
124         }
125
126
127         /* This method is used to generate query for the list form. The base implementation of this method
128          * uses the table_name and list_field varaible to generate the basic query and then  adds the custom field
129          * join and team filter. If you are implementing this function do not forget to consider the additional conditions.
130          */
131
132         function fill_in_additional_detail_fields() {
133                 global $sugar_config;
134                 
135                 //setup campaign name.
136                 $query = "SELECT name from campaigns where id = '$this->campaign_id'";
137                 $result =$this->db->query($query,true," Error filling in additional detail fields: ");
138
139                 // Get the id and the name.
140                 $row = $this->db->fetchByAssoc($result);
141                 if($row != null) {
142                         $this->campaign_name=$row['name'];
143                 }
144                 
145                 if (!class_exists('Administration')) {
146                         
147                 }
148                 $admin=new Administration();
149                 $admin->retrieveSettings('massemailer'); //retrieve all admin settings.
150                 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']) ) {
151                         $this->message_url=$admin->settings['massemailer_tracking_entities_location'];
152                 } else {
153                         $this->message_url=$sugar_config['site_url'];
154                 }
155                 if ($this->is_optout == 1) {
156                         $this->message_url .= '/index.php?entryPoint=removeme&identifier={MESSAGE_ID}';
157                 } else {
158                         $this->message_url .= '/index.php?entryPoint=campaign_trackerv2&track=' . $this->id;
159                 }
160         }
161 }
162 ?>