]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Prospects/Prospect.php
Release 6.5.14
[Github/sugarcrm.git] / modules / Prospects / Prospect.php
1 <?php
2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4  * SugarCRM Community Edition is a customer relationship management program developed by
5  * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
6  * 
7  * This program is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU Affero General Public License version 3 as published by the
9  * Free Software Foundation with the addition of the following permission added
10  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13  * 
14  * This program is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
17  * details.
18  * 
19  * You should have received a copy of the GNU Affero General Public License along with
20  * this program; if not, see http://www.gnu.org/licenses or write to the Free
21  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22  * 02110-1301 USA.
23  * 
24  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26  * 
27  * The interactive user interfaces in modified source and object code versions
28  * of this program must display Appropriate Legal Notices, as required under
29  * Section 5 of the GNU Affero General Public License version 3.
30  * 
31  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32  * these Appropriate Legal Notices must retain the display of the "Powered by
33  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34  * technical reasons, the Appropriate Legal Notices must display the words
35  * "Powered by SugarCRM".
36  ********************************************************************************/
37
38 /*********************************************************************************
39
40  * Description:  TODO: To be written.
41  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
42  * All Rights Reserved.
43  * Contributor(s): ______________________________________..
44  ********************************************************************************/
45
46 require_once('include/SugarObjects/templates/person/Person.php');
47
48 class Prospect extends Person {
49     var $field_name_map;
50         // Stored fields
51         var $id;
52         var $name = '';
53         var $date_entered;
54         var $date_modified;
55         var $modified_user_id;
56         var $assigned_user_id;
57         var $created_by;
58         var $created_by_name;
59         var $modified_by_name;
60         var $description;
61         var $salutation;
62         var $first_name;
63         var $last_name;
64         var $full_name;
65         var $title;
66         var $department;
67         var $birthdate;
68         var $do_not_call;
69         var $phone_home;
70         var $phone_mobile;
71         var $phone_work;
72         var $phone_other;
73         var $phone_fax;
74         var $email1;
75         var $email2;
76         var $email_and_name1;
77         var $assistant;
78         var $assistant_phone;
79         var $email_opt_out;
80         var $primary_address_street;
81         var $primary_address_city;
82         var $primary_address_state;
83         var $primary_address_postalcode;
84         var $primary_address_country;
85         var $alt_address_street;
86         var $alt_address_city;
87         var $alt_address_state;
88         var $alt_address_postalcode;
89         var $alt_address_country;
90         var $tracker_key;
91         var $lead_id;
92         var $account_name;
93         var $assigned_real_user_name;
94         // These are for related fields
95         var $assigned_user_name;
96         var $module_dir = 'Prospects';
97         var $table_name = "prospects";
98         var $object_name = "Prospect";
99         var $new_schema = true;
100         var $emailAddress;
101
102         var $importable = true;
103     // This is used to retrieve related fields from form posts.
104         var $additional_column_fields = Array('assigned_user_name');
105
106
107         function Prospect() {
108                 parent::Person();
109         }
110
111         function fill_in_additional_list_fields()
112         {
113                 parent::fill_in_additional_list_fields();
114                 $this->_create_proper_name_field();
115                 $this->email_and_name1 = $this->full_name." &lt;".$this->email1."&gt;";
116         }
117
118         function fill_in_additional_detail_fields()
119         {
120                 parent::fill_in_additional_list_fields();
121                 $this->_create_proper_name_field();
122         }
123
124         /**
125                 builds a generic search based on the query string using or
126                 do not include any $this-> because this is called on without having the class instantiated
127         */
128         function build_generic_where_clause ($the_query_string)
129         {
130                 $where_clauses = Array();
131                 $the_query_string = $GLOBALS['db']->quote($the_query_string);
132
133                 array_push($where_clauses, "prospects.last_name like '$the_query_string%'");
134                 array_push($where_clauses, "prospects.first_name like '$the_query_string%'");
135                 array_push($where_clauses, "prospects.assistant like '$the_query_string%'");
136
137                 if (is_numeric($the_query_string))
138                 {
139                         array_push($where_clauses, "prospects.phone_home like '%$the_query_string%'");
140                         array_push($where_clauses, "prospects.phone_mobile like '%$the_query_string%'");
141                         array_push($where_clauses, "prospects.phone_work like '%$the_query_string%'");
142                         array_push($where_clauses, "prospects.phone_other like '%$the_query_string%'");
143                         array_push($where_clauses, "prospects.phone_fax like '%$the_query_string%'");
144                         array_push($where_clauses, "prospects.assistant_phone like '%$the_query_string%'");
145                 }
146
147                 $the_where = "";
148                 foreach($where_clauses as $clause)
149                 {
150                         if($the_where != "") $the_where .= " or ";
151                         $the_where .= $clause;
152                 }
153
154
155                 return $the_where;
156         }
157
158     function converted_prospect($prospectid, $contactid, $accountid, $opportunityid){
159         $query = "UPDATE prospects set  contact_id=$contactid, account_id=$accountid, opportunity_id=$opportunityid where  id=$prospectid and deleted=0";
160                 $this->db->query($query,true,"Error converting prospect: ");
161                 //todo--status='Converted', converted='1',
162     }
163      function bean_implements($interface){
164                 switch($interface){
165                         case 'ACL':return true;
166                 }
167                 return false;
168         }
169
170     /**
171      *  This method will be used by Mail Merge in order to retieve the targets as specified in the query
172      *  @param query String - this is the query which contains the where clause for the query
173      */
174     function retrieveTargetList($query, $fields, $offset = 0, $limit= -99, $max = -99, $deleted = 0, $module = ''){
175         global  $beanList, $beanFiles;
176         $module_name = $this->module_dir;
177
178         if(empty($module))
179         {
180             //The call to retrieveTargetList contains a query that may contain a pound token
181             $pattern = '/AND related_type = [\'#]([a-zA-Z]+)[\'#]/i';
182             if(preg_match($pattern, $query, $matches))
183             {
184                 $module_name = $matches[1];
185                 $query = preg_replace($pattern, "", $query);
186             }
187         }
188
189         $count = count($fields);
190         $index = 1;
191         $sel_fields = "";
192         if(!empty($fields))
193         {
194             foreach($fields as $field){
195                 if($field == 'id'){
196                         $sel_fields .= 'prospect_lists_prospects.id id';
197                 }else{
198                         $sel_fields .= strtolower($module_name).".".$field;
199                 }
200                 if($index < $count){
201                     $sel_fields .= ",";
202                 }
203                 $index++;
204             }
205         }
206
207         $module_name = ucfirst($module_name);
208         $class_name = $beanList[$module_name];
209         require_once($beanFiles[$class_name]);
210         $seed = new $class_name();
211         if(empty($sel_fields)){
212             $sel_fields = $seed->table_name.'.*';
213         }
214         $select = "SELECT ".$sel_fields." FROM ".$seed->table_name;
215         $select .= " INNER JOIN prospect_lists_prospects ON prospect_lists_prospects.related_id = ".$seed->table_name.".id";
216         $select .= " INNER JOIN prospect_lists ON prospect_lists_prospects.prospect_list_id = prospect_lists.id";
217         $select .= " INNER JOIN prospect_list_campaigns ON prospect_list_campaigns.prospect_list_id = prospect_lists.id";
218         $select .= " INNER JOIN campaigns on campaigns.id = prospect_list_campaigns.campaign_id";
219         $select .= " WHERE prospect_list_campaigns.deleted = 0";
220         $select .= " AND prospect_lists_prospects.deleted = 0";
221         $select .= " AND prospect_lists.deleted = 0";
222         if (!empty($query)) {
223             $select .= " AND ".$query;
224         }
225
226         return $this->process_list_query($select, $offset, $limit, $max, $query);
227     }
228
229     /**
230      *  Given an id, looks up in the prospect_lists_prospects table
231      *  and retrieve the correct type for this id
232      */
233     function retrieveTarget($id){
234         $query = "SELECT related_id, related_type FROM prospect_lists_prospects WHERE id = '".$this->db->quote($id)."'";
235         $result = $this->db->query($query);
236         if(($row = $this->db->fetchByAssoc($result))){
237              global  $beanList, $beanFiles;
238              $module_name = $row['related_type'];
239              $class_name = $beanList[$module_name];
240              require_once($beanFiles[$class_name]);
241              $seed = new $class_name();
242              return $seed->retrieve($row['related_id']);
243         }else{
244             return null;
245         }
246     }
247
248
249         function get_unlinked_email_query($type=array()) {
250
251                 return get_unlinked_email_query($type, $this);
252         }
253 }