]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Leads/Lead.php
Release 6.4.0
[Github/sugarcrm.git] / modules / Leads / Lead.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-2011 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
49
50
51
52
53
54
55 require_once('include/SugarObjects/templates/person/Person.php');
56
57 // Lead is used to store profile information for people who may become customers.
58 class Lead extends Person {
59         var $field_name_map;
60         // Stored fields
61         var $id;
62         var $date_entered;
63         var $date_modified;
64         var $modified_user_id;
65         var $assigned_user_id;
66         var $created_by;
67         var $created_by_name;
68         var $modified_by_name;
69         var $description;
70         var $salutation;
71         var $first_name;
72         var $last_name;
73         var $title;
74         var $department;
75         var $reports_to_id;
76         var $do_not_call;
77         var $phone_home;
78         var $phone_mobile;
79         var $phone_work;
80         var $phone_other;
81         var $phone_fax;
82         var $refered_by;
83         var $email1;
84         var $email2;
85         var $primary_address_street;
86         var $primary_address_city;
87         var $primary_address_state;
88         var $primary_address_postalcode;
89         var $primary_address_country;
90         var $alt_address_street;
91         var $alt_address_city;
92         var $alt_address_state;
93         var $alt_address_postalcode;
94         var $alt_address_country;
95         var $name;
96         var $full_name;
97         var $portal_name;
98         var $portal_app;
99         var $contact_id;
100         var $contact_name;
101         var $account_id;
102         var $opportunity_id;
103         var $opportunity_name;
104         var $opportunity_amount;
105         //used for vcard export only
106         var $birthdate;
107         var $status;
108         var $status_description;
109
110         var $lead_source;
111         var $lead_source_description;
112         // These are for related fields
113         var $account_name;
114         var $acc_name_from_accounts;
115         var $account_site;
116         var $account_description;
117         var $case_role;
118         var $case_rel_id;
119         var $case_id;
120         var $task_id;
121         var $note_id;
122         var $meeting_id;
123         var $call_id;
124         var $email_id;
125         var $assigned_user_name;
126         var $campaign_id;
127         var $campaign_name;
128     var $alt_address_street_2;
129     var $alt_address_street_3;
130     var $primary_address_street_2;
131     var $primary_address_street_3;
132
133
134         var $table_name = "leads";
135         var $object_name = "Lead";
136         var $object_names = "Leads";
137         var $module_dir = "Leads";
138         var $new_schema = true;
139         var $emailAddress;
140
141         var $importable = true;
142     
143         // This is used to retrieve related fields from form posts.
144         var $additional_column_fields = Array('assigned_user_name', 'task_id', 'note_id', 'meeting_id', 'call_id', 'email_id');
145         var $relationship_fields = Array('email_id'=>'emails','call_id'=>'calls','meeting_id'=>'meetings','task_id'=>'tasks',);
146
147         function Lead() {
148                 parent::Person();
149         }
150
151         function get_account()
152         {
153                 if(isset($this->account_id) && !empty($this->account_id)){
154                         $query = "SELECT name , assigned_user_id account_name_owner FROM accounts WHERE id='{$this->account_id}'";
155
156                 //requireSingleResult has beeen deprecated.
157                         //$result = $this->db->requireSingleResult($query);
158                         $result = $this->db->limitQuery($query,0,1,true, "Want only a single row");
159
160                         if(!empty($result)){
161                                 $row = $this->db->fetchByAssoc($result);
162                                 $this->account_name = $row['name'];
163                                 $this->account_name_owner = $row['account_name_owner'];
164                                 $this->account_name_mod = 'Accounts';
165                         }
166
167         }}
168         function get_opportunity()
169         {
170                 if(isset($this->opportunity_id) && !empty($this->opportunity_id)){
171                         $query = "SELECT name, assigned_user_id opportunity_name_owner FROM opportunities WHERE id='{$this->opportunity_id}'";
172
173                 //requireSingleResult has beeen deprecated.
174                         //$result = $this->db->requireSingleResult($query);
175                         $result = $this->db->limitQuery($query,0,1,true, "Want only a single row");
176
177                         if(!empty($result)){
178                                 $row = $this->db->fetchByAssoc($result);
179                                 $this->opportunity_name = $row['name'];
180                                 $this->opportunity_name_owner = $row['opportunity_name_owner'];
181                                 $this->opportunity_name_mod = 'Opportunities';
182                         }
183
184         }}
185         function get_contact()
186         {
187                 global $locale;
188                 if(isset($this->contact_id) && !empty($this->contact_id)){
189                         $query = "SELECT first_name, last_name, assigned_user_id contact_name_owner FROM contacts WHERE id='{$this->contact_id}'";
190
191                 //requireSingleResult has beeen deprecated.
192                         //$result = $this->db->requireSingleResult($query);
193                         $result = $this->db->limitQuery($query,0,1,true, "Want only a single row");
194                         if(!empty($result)){
195                                 $row= $this->db->fetchByAssoc($result);
196                                 $this->contact_name = $locale->getLocaleFormattedName($row['first_name'], $row['last_name']);
197                                 $this->contact_name_owner = $row['contact_name_owner'];
198                                 $this->contact_name_mod = 'Contacts';
199                         }
200
201         }}
202
203         function create_list_query($order_by, $where, $show_deleted=0)
204         {
205                 $custom_join = $this->custom_fields->getJOIN();
206                 $query = "SELECT ";
207
208
209                         $query .= "$this->table_name.*, users.user_name assigned_user_name";
210                         if($custom_join){
211                                 $query .= $custom_join['select'];
212                         }
213             $query .= " FROM leads ";
214
215                         $query .= "                     LEFT JOIN users
216                                 ON leads.assigned_user_id=users.id ";
217                         $query .= "LEFT JOIN email_addr_bean_rel eabl  ON eabl.bean_id = leads.id AND eabl.bean_module = 'Leads' and eabl.primary_address = 1 and eabl.deleted=0 ";
218                 $query .= "LEFT JOIN email_addresses ea ON (ea.id = eabl.email_address_id) ";
219                         if($custom_join){
220                                 $query .= $custom_join['join'];
221                         }
222                         $where_auto = '1=1';
223                         if($show_deleted == 0){
224                                 $where_auto = " leads.deleted=0 ";
225                         }else if($show_deleted == 1){
226                                 $where_auto = " leads.deleted=1 ";
227                         }
228
229                 if($where != "")
230                         $query .= "where ($where) AND ".$where_auto;
231                 else
232                         $query .= "where ".$where_auto; //."and (leads.converted='0')";
233
234                 if(!empty($order_by))
235                         $query .= " ORDER BY $order_by";
236
237                 return $query;
238         }
239
240         function create_new_list_query($order_by, $where,$filter=array(),$params=array(), $show_deleted = 0,$join_type='', $return_array = false, $parentbean = null, $singleSelect = false){
241                 
242                 $ret_array = parent::create_new_list_query($order_by, $where, $filter, $params, $show_deleted, $join_type, true, $parentbean, $singleSelect);
243                 if(strpos($ret_array['select'],"leads.account_name") == false && strpos($ret_array['select'],"leads.*") == false)
244                         $ret_array['select'] .= " ,leads.account_name";
245         if ( !$return_array )
246             return  $ret_array['select'] . $ret_array['from'] . $ret_array['where']. $ret_array['order_by'];
247         return $ret_array;
248         }       
249         
250     function create_export_query(&$order_by, &$where, $relate_link_join='')
251     {
252         $custom_join = $this->custom_fields->getJOIN(true, true,$where);
253                 if($custom_join)
254                                 $custom_join['join'] .= $relate_link_join;
255                          $query = "SELECT
256                                 leads.*, email_addresses.email_address email_address,
257                                 users.user_name assigned_user_name";
258                          if($custom_join){
259                                                         $query .= $custom_join['select'];
260                                                 }
261                          $query .= " FROM leads ";
262                         $query .= "                     LEFT JOIN users
263                                 ON leads.assigned_user_id=users.id ";
264
265                                 //join email address table too.
266                                 $query .=  ' LEFT JOIN  email_addr_bean_rel on leads.id = email_addr_bean_rel.bean_id and email_addr_bean_rel.bean_module=\'Leads\' and email_addr_bean_rel.deleted=0 and email_addr_bean_rel.primary_address=1 ';
267                                 $query .=  ' LEFT JOIN email_addresses on email_addresses.id = email_addr_bean_rel.email_address_id ' ;
268                                                 
269             
270                 if($custom_join){
271                                         $query .= $custom_join['join'];
272                                 }
273
274                         $where_auto = " leads.deleted=0 ";
275
276                 if($where != "")
277                         $query .= "where ($where) AND ".$where_auto;
278                 else
279                         $query .= "where ".$where_auto;
280
281                 if(!empty($order_by))
282                         $query .= " ORDER BY $order_by";
283                 return $query;
284         }
285
286     function converted_lead($leadid, $contactid, $accountid, $opportunityid){
287         $query = "UPDATE leads set converted='1', contact_id=$contactid, account_id=$accountid, opportunity_id=$opportunityid where  id=$leadid and deleted=0";
288                 $this->db->query($query,true,"Error converting lead: ");
289
290                 //we must move the status out here in order to be able to capture workflow conditions
291                 $leadid = str_replace("'","", $leadid);
292                 $lead = new Lead();
293                 $lead->retrieve($leadid);
294                 $lead->status='Converted';
295                 $lead->save();
296     }
297
298         function fill_in_additional_list_fields()
299         {
300                 parent::fill_in_additional_list_fields();
301                 $this->_create_proper_name_field();
302                 $this->get_account();
303
304         }
305
306         function fill_in_additional_detail_fields()
307         {
308                 //Fill in the assigned_user_name
309                 //if(!empty($this->status))
310                 //$this->status = translate('lead_status_dom', '', $this->status);
311             parent::fill_in_additional_detail_fields();
312             $this->_create_proper_name_field();
313                 $this->get_contact();
314                 $this->get_opportunity();
315                 $this->get_account();
316
317                 if(!empty($this->campaign_id)){
318                         
319                         $camp = new Campaign();
320                         $where = "campaigns.id='$this->campaign_id'";
321                         $campaign_list = $camp->get_full_list("campaigns.name", $where, true);
322                         if(!empty($campaign_list))
323                                 $this->campaign_name = $campaign_list[0]->name; 
324                 }
325         }
326
327         function get_list_view_data(){
328                 /*global $app_list_strings;
329                 global $current_user;
330
331                 $temp_array = $this->get_list_view_array();
332                 $temp_array['STATUS'] = (empty($temp_array['STATUS'])) ? '' : $temp_array['STATUS'];
333                 $temp_array['ENCODED_NAME']=$this->name;
334                 $temp_array['NAME']=$this->name;
335                 $temp_array['EMAIL1'] = $this->emailAddress->getPrimaryAddress($this);
336                 $this->email1 = $temp_array['EMAIL1'];
337                 $temp_array['EMAIL1_LINK'] = $current_user->getEmailLink('email1', $this, '', '', 'ListView');
338         $temp_array['ACC_NAME_FROM_ACCOUNTS'] = empty($temp_array['ACC_NAME_FROM_ACCOUNTS']) ? ($temp_array['ACCOUNT_NAME']) : ($temp_array['ACC_NAME_FROM_ACCOUNTS']);
339                 return $temp_array;
340                 */
341                 $this->_create_proper_name_field();
342                 $temp_array = parent::get_list_view_data();
343                 $temp_array['ACC_NAME_FROM_ACCOUNTS'] = empty($temp_array['ACC_NAME_FROM_ACCOUNTS']) ? ($temp_array['ACCOUNT_NAME']) : ($temp_array['ACC_NAME_FROM_ACCOUNTS']);
344                 return $temp_array;             
345         }
346         
347     /**
348      * Returns an array of fields that are of type link.
349      *
350      * @return array List of fields.
351      *
352      * Internal function, do not override.
353      */
354         //fix for bug 27339 Shine
355     function get_linked_fields()
356     {
357         $linked_fields=array();
358         $fieldDefs = $this->getFieldDefinitions();
359
360         //find all definitions of type link.
361         if (!empty($fieldDefs))
362         {
363                 foreach ($fieldDefs as $name=>$properties)
364                 {
365                         if ($name == 'oldmeetings' || $name == 'oldcalls') { continue; }
366                         elseif (array_search('link',$properties) === 'type')
367                         {
368                                 $linked_fields[$name]=$properties;
369                         }
370                 }
371         }
372         return $linked_fields;
373     }
374
375         /**
376                 builds a generic search based on the query string using or
377                 do not include any $this-> because this is called on without having the class instantiated
378         */
379         function build_generic_where_clause ($the_query_string) {
380         $where_clauses = Array();
381         $the_query_string = $GLOBALS['db']->quote($the_query_string);
382
383         array_push($where_clauses, "leads.last_name like '$the_query_string%'");
384         array_push($where_clauses, "leads.account_name like '$the_query_string%'");
385         array_push($where_clauses, "leads.first_name like '$the_query_string%'");
386         array_push($where_clauses, "ea.email_address like '$the_query_string%'");
387         
388         if (is_numeric($the_query_string)) {
389                 array_push($where_clauses, "leads.phone_home like '%$the_query_string%'");
390                 array_push($where_clauses, "leads.phone_mobile like '%$the_query_string%'");
391                 array_push($where_clauses, "leads.phone_work like '%$the_query_string%'");
392                 array_push($where_clauses, "leads.phone_other like '%$the_query_string%'");
393                 array_push($where_clauses, "leads.phone_fax like '%$the_query_string%'");
394
395         }
396
397         $the_where = "";
398         foreach($where_clauses as $clause)
399         {
400                 if($the_where != "") $the_where .= " or ";
401                 $the_where .= $clause;
402         }
403
404
405         return $the_where;
406         }
407
408         function set_notification_body($xtpl, $lead)
409         {
410                 global $app_list_strings;
411         global $locale;
412
413                 $xtpl->assign("LEAD_NAME", $locale->getLocaleFormattedName($lead->first_name, $lead->last_name, $lead->salutation));
414                 $xtpl->assign("LEAD_SOURCE", (isset($lead->lead_source) ? $app_list_strings['lead_source_dom'][$lead->lead_source] : ""));
415                 $xtpl->assign("LEAD_STATUS", (isset($lead->status)? $app_list_strings['lead_status_dom'][$lead->status]:""));
416                 $xtpl->assign("LEAD_DESCRIPTION", $lead->description);
417
418                 return $xtpl;
419         }
420
421         function bean_implements($interface){
422                 switch($interface){
423                         case 'ACL':return true;
424                 }
425                 return false;
426         }
427         function listviewACLHelper(){
428                 $array_assign = parent::listviewACLHelper();
429                 $is_owner = false;
430                 if(!empty($this->account_name)){
431
432                         if(!empty($this->account_name_owner)){
433                                 global $current_user;
434                                 $is_owner = $current_user->id == $this->account_name_owner;
435                         }
436                 }
437                         if( ACLController::checkAccess('Accounts', 'view', $is_owner)){
438                                 $array_assign['ACCOUNT'] = 'a';
439                         }else{
440                                 $array_assign['ACCOUNT'] = 'span';
441                         }
442                 $is_owner = false;
443                 if(!empty($this->opportunity_name)){
444
445                         if(!empty($this->opportunity_name_owner)){
446                                 global $current_user;
447                                 $is_owner = $current_user->id == $this->opportunity_name_owner;
448                         }
449                 }
450                         if( ACLController::checkAccess('Opportunities', 'view', $is_owner)){
451                                 $array_assign['OPPORTUNITY'] = 'a';
452                         }else{
453                                 $array_assign['OPPORTUNITY'] = 'span';
454                         }
455
456
457                 $is_owner = false;
458                 if(!empty($this->contact_name)){
459
460                         if(!empty($this->contact_name_owner)){
461                                 global $current_user;
462                                 $is_owner = $current_user->id == $this->contact_name_owner;
463                         }
464                 }
465                         if( ACLController::checkAccess('Contacts', 'view', $is_owner)){
466                                 $array_assign['CONTACT'] = 'a';
467                         }else{
468                                 $array_assign['CONTACT'] = 'span';
469                         }
470
471                 return $array_assign;
472         }
473
474 //carrys forward custom lead fields to contacts, accounts, opportunities during Lead Conversion
475         function convertCustomFieldsForm(&$form, &$tempBean, &$prefix) {
476
477                 global $mod_strings, $app_list_strings, $app_strings, $lbl_required_symbol;
478
479                 foreach($this->field_defs as $field => $value) {
480
481                         if(!empty($value['source']) && $value['source'] == 'custom_fields') {
482                                 if( !empty($tempBean->field_defs[$field]) AND isset($tempBean->field_defs[$field]) ) {
483                                         $form .= "<tr><td nowrap colspan='4' class='dataLabel'>".$mod_strings[$tempBean->field_defs[$field]['vname']].":";
484
485                                         if( !empty($tempBean->custom_fields->avail_fields[$field]['required']) AND ( ($tempBean->custom_fields->avail_fields[$field]['required']== 1) OR ($tempBean->custom_fields->avail_fields[$field]['required']== '1') OR ($tempBean->custom_fields->avail_fields[$field]['required']== 'true') OR ($tempBean->custom_fields->avail_fields[$field]['required']== true) ) ) {
486                                                 $form .= "&nbsp;<span class='required'>".$lbl_required_symbol."</span>";
487                                         }
488                                         $form .= "</td></tr>";
489                                         $form .= "<tr><td nowrap colspan='4' class='dataField' nowrap>";
490
491                                         if(isset($value['isMultiSelect']) && $value['isMultiSelect'] == 1){
492                                                 $this->$field = unencodeMultienum($this->$field);
493                                                 $multiple = "multiple";
494                                                 $array = '[]';
495                                         } else {
496                                                 $multiple = null;
497                                                 $array = null;
498                                         }
499
500                                         if(!empty($value['options']) AND isset($value['options']) ) {
501                                                 $form .= "<select " . $multiple . " name='".$prefix.$field.$array."'>";
502                                                 $form .= get_select_options_with_id($app_list_strings[$value['options']], $this->$field);
503                                                 $form .= "</select";
504                                         } elseif($value['type'] == 'bool' ) {
505                                                 if( ($this->$field == 1) OR ($this->$field == '1') ) { $checked = 'checked'; } else { $checked = ''; }
506                                                 $form .= "<input type='checkbox' name='".$prefix.$field."' id='".$prefix.$field."'  value='1' ".$checked."/>";
507                                         } elseif($value['type'] == 'text' ) {
508                                                 $form .= "<textarea name='".$prefix.$field."' rows='6' cols='50'>".$this->$field."</textarea>";
509                                         } elseif($value['type'] == 'date' ) {
510                                                 $form .= "<input name='".$prefix.$field."' id='jscal_field".$field."' type='text'  size='11' maxlength='10' value='".$this->$field."'>&nbsp;".SugarThemeRegistry::current()->getImage("jscalendar", "id='jscal_trigger".$field."' align='absmiddle'", null, null, ".gif", $mod_strings['LBL_ENTERDATE'])."' <span class='dateFormat'>yyyy-mm-dd</span><script type='text/javascript'>Calendar.setup ({inputField : 'jscal_field".$field."', ifFormat : '%Y-%m-%d', showsTime : false, button : 'jscal_trigger".$field."', singleClick : true, step : 1, weekNumbers:false}); addToValidate('ConvertLead', '".$field."', 'date', false,'".$mod_strings[$tempBean->field_defs[$field]['vname']]."' );</script>";
511                                         } else {
512                                                 $form .= "<input name='".$prefix.$field."' type='text' value='".$this->$field."'>";
513
514                                                 if($this->custom_fields->avail_fields[$field]['type'] == 'int') {
515                                                         $form .= "<script>addToValidate('ConvertLead', '".$prefix.$field."', 'int', false,'".$prefix.":".$mod_strings[$tempBean->field_defs[$field]['vname']]."' );</script>";
516                                                 }
517                                                 elseif($this->custom_fields->avail_fields[$field]['type'] == 'float') {
518                                                         $form .= "<script>addToValidate('ConvertLead', '".$prefix.$field."', 'float', false,'".$prefix.":".$mod_strings[$tempBean->field_defs[$field]['vname']]."' );</script>";
519                                                 }
520
521                                         }
522
523                                         if( !empty($tempBean->custom_fields->avail_fields[$field]['required']) AND ( ($tempBean->custom_fields->avail_fields[$field]['required']== 1) OR ($tempBean->custom_fields->avail_fields[$field]['required']== '1') OR ($tempBean->custom_fields->avail_fields[$field]['required']== 'true') OR ($tempBean->custom_fields->avail_fields[$field]['required']== true) ) ) {
524                                                         $form .= "<script>addToValidate('ConvertLead', '".$prefix.$field."', 'relate', true,'".$prefix.":".$mod_strings[$tempBean->field_defs[$field]['vname']]."' );</script>";
525                                                 }
526
527                                         $form .= "</td></tr>";
528
529
530                                 }
531                         }
532
533                 }
534
535                 return true;
536         }
537
538         function save($check_notify = false) {
539                 if(empty($this->status))
540                         $this->status = 'New';
541                 // call save first so that $this->id will be set
542                 $value = parent::save($check_notify);
543                 return $value;
544         }
545         function get_unlinked_email_query($type=array()) {
546                 
547                 return get_unlinked_email_query($type, $this);
548         }
549     
550     /**
551      * Returns query to find the related calls created pre-5.1
552      *
553      * @return string SQL statement
554      */
555     public function get_old_related_calls()
556     {
557         $return_array['select']='SELECT calls.id ';
558         $return_array['from']='FROM calls ';
559         $return_array['where']=" WHERE calls.parent_id = '$this->id' 
560             AND calls.parent_type = 'Leads' AND calls.id NOT IN ( SELECT call_id FROM calls_leads ) ";
561         $return_array['join'] = "";
562         $return_array['join_tables'][0] = '';
563         
564         return $return_array;
565     }
566
567     /**
568      * Returns array of lead conversion activity options
569      *
570      * @return string SQL statement
571      */
572     public static function getActivitiesOptions() {
573
574         if (isset($GLOBALS['app_list_strings']['lead_conv_activity_opt'])) {
575             return $GLOBALS['app_list_strings']['lead_conv_activity_opt'];
576         }
577         else {
578             return array();
579         }
580     }
581
582     /**
583      * Returns query to find the related meetings created pre-5.1
584      *
585      * @return string SQL statement
586      */
587     public function get_old_related_meetings()
588     {
589         $return_array['select']='SELECT meetings.id ';
590         $return_array['from']='FROM meetings ';
591         $return_array['where']=" WHERE meetings.parent_id = '$this->id' 
592             AND meetings.parent_type = 'Leads' AND meetings.id NOT IN ( SELECT meeting_id FROM meetings_leads ) ";
593         $return_array['join'] = "";
594         $return_array['join_tables'][0] = '';
595         
596         return $return_array;
597     }
598 }
599
600 ?>