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-2012 SugarCRM Inc.
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.
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
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
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.
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.
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 ********************************************************************************/
38 /*********************************************************************************
40 * Description: TODO: To be written.
41 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
42 * All Rights Reserved.
43 * Contributor(s): ______________________________________..
44 ********************************************************************************/
46 require_once('include/SugarObjects/templates/person/Person.php');
48 class Prospect extends Person {
55 var $modified_user_id;
56 var $assigned_user_id;
59 var $modified_by_name;
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;
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;
102 var $importable = true;
103 // This is used to retrieve related fields from form posts.
104 var $additional_column_fields = Array('assigned_user_name');
107 function Prospect() {
111 function create_export_query(&$order_by, &$where, $relate_link_join='')
113 $custom_join = $this->custom_fields->getJOIN(true, true,$where);
115 $custom_join['join'] .= $relate_link_join;
117 prospects.*,email_addresses.email_address email_address,
118 users.user_name as assigned_user_name ";
120 $query .= $custom_join['select'];
122 $query .= " FROM prospects ";
123 $query .= "LEFT JOIN users
124 ON prospects.assigned_user_id=users.id ";
126 //join email address table too.
127 $query .= ' LEFT JOIN email_addr_bean_rel on prospects.id = email_addr_bean_rel.bean_id and email_addr_bean_rel.bean_module=\'Prospects\' and email_addr_bean_rel.primary_address=1 and email_addr_bean_rel.deleted=0';
128 $query .= ' LEFT JOIN email_addresses on email_addresses.id = email_addr_bean_rel.email_address_id ' ;
131 $query .= $custom_join['join'];
134 $where_auto = " prospects.deleted=0 ";
137 $query .= "where ($where) AND ".$where_auto;
139 $query .= "where ".$where_auto;
141 if(!empty($order_by))
142 $query .= " ORDER BY $order_by";
148 function fill_in_additional_list_fields()
150 parent::fill_in_additional_list_fields();
151 $this->_create_proper_name_field();
152 $this->email_and_name1 = $this->full_name." <".$this->email1.">";
155 function fill_in_additional_detail_fields()
157 parent::fill_in_additional_list_fields();
158 $this->_create_proper_name_field();
161 function get_list_view_data() {
162 global $current_user;
163 $this->_create_proper_name_field();
164 $temp_array = $this->get_list_view_array();
165 $temp_array["ENCODED_NAME"] = $this->full_name;
166 $temp_array["FULL_NAME"] = $this->full_name;
167 $temp_array["EMAIL1"] = $this->emailAddress->getPrimaryAddress($this);
168 $this->email1 = $temp_array['EMAIL1'];
169 $temp_array["EMAIL1_LINK"] = $current_user->getEmailLink('email1', $this, '', '', 'ListView');
175 builds a generic search based on the query string using or
176 do not include any $this-> because this is called on without having the class instantiated
178 function build_generic_where_clause ($the_query_string)
180 $where_clauses = Array();
181 $the_query_string = $GLOBALS['db']->quote($the_query_string);
183 array_push($where_clauses, "prospects.last_name like '$the_query_string%'");
184 array_push($where_clauses, "prospects.first_name like '$the_query_string%'");
185 array_push($where_clauses, "prospects.assistant like '$the_query_string%'");
187 if (is_numeric($the_query_string))
189 array_push($where_clauses, "prospects.phone_home like '%$the_query_string%'");
190 array_push($where_clauses, "prospects.phone_mobile like '%$the_query_string%'");
191 array_push($where_clauses, "prospects.phone_work like '%$the_query_string%'");
192 array_push($where_clauses, "prospects.phone_other like '%$the_query_string%'");
193 array_push($where_clauses, "prospects.phone_fax like '%$the_query_string%'");
194 array_push($where_clauses, "prospects.assistant_phone like '%$the_query_string%'");
198 foreach($where_clauses as $clause)
200 if($the_where != "") $the_where .= " or ";
201 $the_where .= $clause;
208 function converted_prospect($prospectid, $contactid, $accountid, $opportunityid){
209 $query = "UPDATE prospects set contact_id=$contactid, account_id=$accountid, opportunity_id=$opportunityid where id=$prospectid and deleted=0";
210 $this->db->query($query,true,"Error converting prospect: ");
211 //todo--status='Converted', converted='1',
213 function bean_implements($interface){
215 case 'ACL':return true;
221 * This method will be used by Mail Merge in order to retieve the targets as specified in the query
222 * @param query String - this is the query which contains the where clause for the query
224 function retrieveTargetList($query, $fields, $offset = 0, $limit= -99, $max = -99, $deleted = 0, $module = ''){
225 global $beanList, $beanFiles;
226 $module_name = $this->module_dir;
230 //The call to retrieveTargetList contains a query that may contain a pound token
231 $pattern = '/AND related_type = [\'#]([a-zA-Z]+)[\'#]/i';
232 if(preg_match($pattern, $query, $matches))
234 $module_name = $matches[1];
235 $query = preg_replace($pattern, "", $query);
239 $count = count($fields);
244 foreach($fields as $field){
246 $sel_fields .= 'prospect_lists_prospects.id id';
248 $sel_fields .= strtolower($module_name).".".$field;
257 $module_name = ucfirst($module_name);
258 $class_name = $beanList[$module_name];
259 require_once($beanFiles[$class_name]);
260 $seed = new $class_name();
261 if(empty($sel_fields)){
262 $sel_fields = $seed->table_name.'.*';
264 $select = "SELECT ".$sel_fields." FROM ".$seed->table_name;
265 $select .= " INNER JOIN prospect_lists_prospects ON prospect_lists_prospects.related_id = ".$seed->table_name.".id";
266 $select .= " INNER JOIN prospect_lists ON prospect_lists_prospects.prospect_list_id = prospect_lists.id";
267 $select .= " INNER JOIN prospect_list_campaigns ON prospect_list_campaigns.prospect_list_id = prospect_lists.id";
268 $select .= " INNER JOIN campaigns on campaigns.id = prospect_list_campaigns.campaign_id";
269 $select .= " WHERE prospect_list_campaigns.deleted = 0";
270 $select .= " AND prospect_lists_prospects.deleted = 0";
271 $select .= " AND prospect_lists.deleted = 0";
272 if (!empty($query)) {
273 $select .= " AND ".$query;
276 return $this->process_list_query($select, $offset, $limit, $max, $query);
280 * Given an id, looks up in the prospect_lists_prospects table
281 * and retrieve the correct type for this id
283 function retrieveTarget($id){
284 $query = "SELECT related_id, related_type FROM prospect_lists_prospects WHERE id = '".$this->db->quote($id)."'";
285 $result = $this->db->query($query);
286 if(($row = $this->db->fetchByAssoc($result))){
287 global $beanList, $beanFiles;
288 $module_name = $row['related_type'];
289 $class_name = $beanList[$module_name];
290 require_once($beanFiles[$class_name]);
291 $seed = new $class_name();
292 return $seed->retrieve($row['related_id']);
299 function get_unlinked_email_query($type=array()) {
301 return get_unlinked_email_query($type, $this);