]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Calls/CallFormBase.php
Release 6.1.4
[Github/sugarcrm.git] / modules / Calls / CallFormBase.php
1 <?php
2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4  * SugarCRM 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: Call Form Base
41  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
42  * All Rights Reserved.
43  * Contributor(s): ______________________________________..
44  ********************************************************************************/
45
46 class CallFormBase{
47
48 function getFormBody($prefix, $mod='', $formname='',$cal_date='',$cal_time=''){
49 if(!ACLController::checkAccess('Calls', 'edit', true)){
50                 return '';
51         }
52 global $mod_strings;
53 $temp_strings = $mod_strings;
54 if(!empty($mod)){
55         global $current_language;
56         $mod_strings = return_module_language($current_language, $mod);
57 }
58 global $app_strings;
59 global $app_list_strings;
60 global $current_user;
61 global $theme;
62
63
64 $lbl_subject = $mod_strings['LBL_SUBJECT'];
65 // Unimplemented until jscalendar language files are fixed
66 // global $current_language;
67 // global $default_language;
68 // global $cal_codes;
69 // Unimplemented until jscalendar language files are fixed
70 // $cal_lang = (empty($cal_codes[$current_language])) ? $cal_codes[$default_language] : $cal_codes[$current_language];
71
72 global $timedate;
73 $cal_lang = "en";
74 $cal_dateformat = $timedate->get_cal_date_format();
75
76 $lbl_required_symbol = $app_strings['LBL_REQUIRED_SYMBOL'];
77 $lbl_date = $mod_strings['LBL_DATE'];
78 $lbl_time = $mod_strings['LBL_TIME'];
79 $ntc_date_format = $timedate->get_user_date_format();
80 $ntc_time_format = '('.$timedate->get_user_time_format().')';
81
82         $user_id = $current_user->id;
83 $default_status = $app_list_strings['call_status_default'];
84 $default_parent_type= $app_list_strings['record_type_default_key'];
85 $date = gmdate($GLOBALS['timedate']->get_db_date_time_format());
86 $default_date_start = $timedate->to_display_date($date,false);
87 $default_time_start = $timedate->to_display_time($date);
88 $time_ampm = $timedate->AMPMMenu($prefix,$default_time_start);
89 $lbl_save_button_title = $app_strings['LBL_SAVE_BUTTON_TITLE'];
90 $lbl_save_button_key = $app_strings['LBL_SAVE_BUTTON_KEY'];
91 $lbl_save_button_label = $app_strings['LBL_SAVE_BUTTON_LABEL'];
92         $form = <<<EOQ
93                         <form name="${formname}" onSubmit="return check_form('${formname}') "method="POST" action="index.php">
94                         <input type="hidden" name="${prefix}module" value="Calls">
95                         <input type="hidden" name="${prefix}action" value="Save">
96                                 <input type="hidden" name="${prefix}record" value="">
97                         <input type="hidden"  name="${prefix}direction" value="Outbound">
98                         <input type="hidden" name="${prefix}status" value="${default_status}">
99                         <input type="hidden" name="${prefix}parent_type" value="${default_parent_type}">
100                         <input type="hidden" name="${prefix}assigned_user_id" value='${user_id}'>
101                         <input type="hidden" name="${prefix}duration_hours" value="1">
102                         <input type="hidden" name="${prefix}duration_minutes" value="0">
103                         <input type="hidden" name="${prefix}user_id" value="${user_id}">
104
105                 <table cellspacing="1" cellpadding="0" border="0">
106 <tr>
107     <td colspan="2"><input type='radio' name='appointment' value='Call' class='radio' onchange='document.${formname}.module.value="Calls";' style='vertical-align: middle;' checked> <span scope="row">${mod_strings['LNK_NEW_CALL']}</span>
108 &nbsp;
109 &nbsp;
110 <input type='radio' name='appointment' value='Meeting' class='radio' onchange='document.${formname}.module.value="Meetings";'><span scope="row">${mod_strings['LNK_NEW_MEETING']}</span></td>
111 </tr>
112 <tr>
113     <td colspan="2"><span scope="row">$lbl_subject</span>&nbsp;<span class="required">$lbl_required_symbol</span></td>
114 </tr>
115 <tr><td valign=top><input name='${prefix}name' size='30' maxlength='255' type="text"></td>
116     <td><input name='${prefix}date_start' id='${formname}jscal_field' maxlength='10' type="hidden" value="${cal_date}"></td>
117     <td><input name='${prefix}time_start' type="hidden" maxlength='10' value="{$cal_time}"></td>
118
119                         <script type="text/javascript">
120 //              Calendar.setup ({
121 //                      inputField : "${formname}jscal_field", daFormat : "$cal_dateformat" ifFormat : "$cal_dateformat", showsTime : false, button : "${formname}jscal_trigger", singleClick : true, step : 1, weekNumbers:false
122 //              });
123                 </script>
124
125
126
127 EOQ;
128
129
130
131 $javascript = new javascript();
132 $javascript->setFormName($formname);
133 $javascript->setSugarBean(new Call());
134 $javascript->addRequiredFields($prefix);
135 $form .=$javascript->getScript();
136 $form .= "<td align=\"left\" valign=top><input title='$lbl_save_button_title' accessKey='$lbl_save_button_key' class='button' type='submit' name='button' value=' $lbl_save_button_label ' ></td></tr></table></form>";
137 $mod_strings = $temp_strings;
138 return $form;
139
140 }
141 function getFormHeader($prefix, $mod='', $title=''){
142         if(!ACLController::checkAccess('Calls', 'edit', true)){
143                 return '';
144         }
145         if(!empty($mod)){
146         global $current_language;
147         $mod_strings = return_module_language($current_language, $mod);
148 }else global $mod_strings;
149
150
151
152
153
154
155 if(!empty($title)){
156         $the_form = get_left_form_header($title);
157 }else{
158         $the_form = get_left_form_header($mod_strings['LBL_NEW_FORM_TITLE']);
159 }
160 $the_form .= <<<EOQ
161                 <form name="${prefix}CallSave" onSubmit="return check_form('${prefix}CallSave') "method="POST" action="index.php">
162                         <input type="hidden" name="${prefix}module" value="Calls">
163                         <input type="hidden" name="${prefix}action" value="Save">
164
165 EOQ;
166 return $the_form;
167 }
168 function getFormFooter($prefic, $mod=''){
169         if(!ACLController::checkAccess('Calls', 'edit', true)){
170                 return '';
171         }
172 global $app_strings;
173 global $app_list_strings;
174 $lbl_save_button_title = $app_strings['LBL_SAVE_BUTTON_TITLE'];
175 $lbl_save_button_key = $app_strings['LBL_SAVE_BUTTON_KEY'];
176 $lbl_save_button_label = $app_strings['LBL_SAVE_BUTTON_LABEL'];
177 $the_form = "   <p><input title='$lbl_save_button_title' accessKey='$lbl_save_button_key' class='button' type='submit' name='button' value=' $lbl_save_button_label ' ></p></form>";
178 $the_form .= get_left_form_footer();
179 $the_form .= get_validate_record_js();
180 return $the_form;
181 }
182
183 function getForm($prefix, $mod=''){
184         if(!ACLController::checkAccess('Calls', 'edit', true)){
185                 return '';
186         }
187 $the_form = $this->getFormHeader($prefix, $mod);
188 $the_form .= $this->getFormBody($prefix, $mod, "${prefix}CallSave");
189 $the_form .= $this->getFormFooter($prefix, $mod);
190
191 return $the_form;
192 }
193
194
195 function handleSave($prefix,$redirect=true,$useRequired=false) {
196
197
198         require_once('include/formbase.php');
199
200         global $current_user;
201         global $timedate;
202
203         //BUG 17418 MFH
204         if (isset($_POST[$prefix.'duration_hours'])){
205                 $_POST[$prefix.'duration_hours'] = trim($_POST[$prefix.'duration_hours']);
206         }
207
208         $focus = new Call();
209
210         if($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) {
211                 return null;
212         }
213     if ( !isset($_POST[$prefix.'reminder_checked']) or ($_POST[$prefix.'reminder_checked'] == 0)) {
214         $GLOBALS['log']->debug(__FILE__.'('.__LINE__.'): No reminder checked, resetting the reminder_time');
215         $_POST[$prefix.'reminder_time'] = -1;
216     }
217
218         if(!isset($_POST[$prefix.'reminder_time'])) {
219         $GLOBALS['log']->debug(__FILE__.'('.__LINE__.'): Getting the users default reminder time');
220                 $_POST[$prefix.'reminder_time'] = $current_user->getPreference('reminder_time');
221         }
222
223         $time_format = $timedate->get_user_time_format();
224     $time_separator = ":";
225     if(preg_match('/\d+([^\d])\d+([^\d]*)/s', $time_format, $match)) {
226        $time_separator = $match[1];
227     }
228
229         if(!empty($_POST[$prefix.'time_hour_start']) && empty($_POST[$prefix.'time_start'])) {
230                 $_POST[$prefix.'time_start'] = $_POST[$prefix.'time_hour_start']. $time_separator .$_POST[$prefix.'time_minute_start'];
231         }
232
233         if(isset($_POST[$prefix.'meridiem']) && !empty($_POST[$prefix.'meridiem'])) {
234                 $_POST[$prefix.'time_start'] = $timedate->merge_time_meridiem($_POST[$prefix.'time_start'],$timedate->get_time_format(true), $_POST[$prefix.'meridiem']);
235         }
236
237         if(isset($_POST[$prefix.'time_start']) && strlen($_POST[$prefix.'date_start']) == 10) {
238            $_POST[$prefix.'date_start'] = $_POST[$prefix.'date_start'] . ' ' . $_POST[$prefix.'time_start'];
239         }
240
241         // retrieve happens here
242         $focus = populateFromPost($prefix, $focus);
243         if(!$focus->ACLAccess('Save')) {
244            ACLController::displayNoAccess(true);
245            sugar_cleanup(true);
246         }
247
248         //add assigned user and current user if this is the first time bean is saved
249         if(empty($focus->id) && !empty($_REQUEST['return_module']) && $_REQUEST['return_module'] =='Calls' && !empty($_REQUEST['return_action']) && $_REQUEST['return_action'] =='DetailView'){
250                 //if return action is set to detail view and return module to call, then this is from the long form, do not add the assigned user (only the current user) 
251                 //The current user is already added to UI and we want to give the current user the option of opting out of meeting.
252                 if($current_user->id != $_POST['assigned_user_id']){
253                         $_POST['user_invitees'] .= ','.$_POST['assigned_user_id'].', ';
254                         $_POST['user_invitees'] = str_replace(',,', ',', $_POST['user_invitees']);
255                 }
256         }elseif (empty($focus->id) ){
257                 //this is not from long form so add assigned and current user automatically as there is no invitee list UI.  
258                 //This call could be through an ajax call from subpanels or shortcut bar
259                 $_POST['user_invitees'] .= ','.$_POST['assigned_user_id'].', ';
260                 
261                 //add current user if the assigned to user is different than current user.
262                 if($current_user->id != $_POST['assigned_user_id']){
263                         $_POST['user_invitees'] .= ','.$current_user->id.', ';
264                 }
265                 
266                 //remove any double comma's introduced during appending
267             $_POST['user_invitees'] = str_replace(',,', ',', $_POST['user_invitees']);
268         }
269         
270     if(isset($_POST['isSaveFromDetailView']) && $_POST['isSaveFromDetailView'] == 'true'){
271         $focus->save(true);
272         $return_id = $focus->id;
273     }else{
274         
275             if(empty($_REQUEST['return_module']) && empty($_REQUEST['return_action']) && $focus->status == 'Held'){
276                 //if we are closing the call, and the request does not have a return module AND return action set, then
277                 //the request is coming from a dashlet or subpanel close icon and there is no need to process user invitees, 
278                 //just save the current values.
279                 $focus->save(true);
280             }else{
281                 ///////////////////////////////////////////////////////////////////////////
282                 ////    REMOVE INVITEE RELATIONSHIPS
283                 if(!empty($_POST['user_invitees'])) {
284                    $userInvitees = explode(',', trim($_POST['user_invitees'], ','));
285                 } else {
286                    $userInvitees = array();
287                 }
288         
289                 // Calculate which users to flag as deleted and which to add
290                 $deleteUsers = array();
291                 $focus->load_relationship('users');
292                 // Get all users for the call
293                 $q = 'SELECT mu.user_id, mu.accept_status FROM calls_users mu WHERE mu.call_id = \''.$focus->id.'\'';
294                 $r = $focus->db->query($q);
295                 $acceptStatusUsers = array();
296                 while($a = $focus->db->fetchByAssoc($r)) {
297                           if(!in_array($a['user_id'], $userInvitees)) {
298                                  $deleteUsers[$a['user_id']] = $a['user_id'];
299                           } else {
300                              $acceptStatusUsers[$a['user_id']] = $a['accept_status'];
301                           }
302                 }
303         
304                 if(count($deleteUsers) > 0) {
305                         $sql = '';
306                         foreach($deleteUsers as $u) {
307                         $sql .= ",'" . $u . "'";
308                         }
309         
310                         $sql = substr($sql, 1);
311                         // We could run a delete SQL statement here, but will just mark as deleted instead
312                         $sql = "UPDATE calls_users set deleted = 1 where user_id in ($sql) AND call_id = '". $focus->id . "'";
313                         $focus->db->query($sql);
314                 }
315         
316                 // Get all contacts for the call
317                 if(!empty($_POST['contact_invitees'])) {
318                    $contactInvitees = explode(',', trim($_POST['contact_invitees'], ','));
319                 } else {
320                    $contactInvitees = array();
321                 }
322         
323                 $deleteContacts = array();
324                 $focus->load_relationship('contacts');
325                 $q = 'SELECT mu.contact_id, mu.accept_status FROM calls_contacts mu WHERE mu.call_id = \''.$focus->id.'\'';
326                 $r = $focus->db->query($q);
327                 $acceptStatusContacts = array();
328                 while($a = $focus->db->fetchByAssoc($r)) {
329                           if(!in_array($a['contact_id'], $contactInvitees)) {
330                                  $deleteContacts[$a['contact_id']] = $a['contact_id'];
331                           }     else {
332                                  $acceptStatusContacts[$a['contact_id']] = $a['accept_status'];
333                           }
334                 }
335         
336                 if(count($deleteContacts) > 0) {
337                         $sql = '';
338                         foreach($deleteContacts as $u) {
339                                 $sql .= ",'" . $u . "'";
340                         }
341                         $sql = substr($sql, 1);
342                         // We could run a delete SQL statement here, but will just mark as deleted instead
343                         $sql = "UPDATE calls_contacts set deleted = 1 where contact_id in ($sql) AND call_id = '". $focus->id . "'";
344                         $focus->db->query($sql);
345                 }
346                 if(!empty($_POST['lead_invitees'])) {
347                    $leadInvitees = explode(',', trim($_POST['lead_invitees'], ','));
348                 } else {
349                    $leadInvitees = array();
350                 }
351         
352                 // Calculate which leads to flag as deleted and which to add
353                 $deleteLeads = array();
354                 $focus->load_relationship('leads');
355                 // Get all leads for the call
356                 $q = 'SELECT mu.lead_id, mu.accept_status FROM calls_leads mu WHERE mu.call_id = \''.$focus->id.'\'';
357                 $r = $focus->db->query($q);
358                 $acceptStatusLeads = array();
359                 while($a = $focus->db->fetchByAssoc($r)) {
360                           if(!in_array($a['lead_id'], $leadInvitees)) {
361                                  $deleteLeads[$a['lead_id']] = $a['lead_id'];
362                           } else {
363                              $acceptStatusLeads[$a['user_id']] = $a['accept_status'];
364                           }
365                 }
366         
367                 if(count($deleteLeads) > 0) {
368                         $sql = '';
369                         foreach($deleteLeads as $u) {
370                         // make sure we don't delete the assigned user
371                         if ( $u != $focus->assigned_user_id )
372                                 $sql .= ",'" . $u . "'";
373                         }
374                         $sql = substr($sql, 1);
375                         // We could run a delete SQL statement here, but will just mark as deleted instead
376                         $sql = "UPDATE calls_leads set deleted = 1 where lead_id in ($sql) AND call_id = '". $focus->id . "'";
377                         $focus->db->query($sql);
378                 }
379                 ////    END REMOVE
380                 ///////////////////////////////////////////////////////////////////////////
381         
382         
383                 ///////////////////////////////////////////////////////////////////////////
384                 ////    REBUILD INVITEE RELATIONSHIPS
385                 $focus->users_arr = array();
386                 $focus->users_arr = $userInvitees;
387                 $focus->contacts_arr = array();
388                 $focus->contacts_arr = $contactInvitees;
389                 $focus->leads_arr = array();
390                 $focus->leads_arr = $leadInvitees;
391                 if(!empty($_POST['parent_id']) && $_POST['parent_type'] == 'Contacts') {
392                         $focus->contacts_arr[] = $_POST['parent_id'];
393                 }
394                 if(!empty($_POST['parent_id']) && $_POST['parent_type'] == 'Leads') {
395                         $focus->leads_arr[] = $_POST['parent_id'];
396                 }
397                 // Call the Call module's save function to handle saving other fields besides
398                 // the users and contacts relationships
399                 $focus->save(true);
400                 $return_id = $focus->id;
401         
402                 // Process users
403                 $existing_users = array();
404                 if(!empty($_POST['existing_invitees'])) {
405                    $existing_users =  explode(",", trim($_POST['existing_invitees'], ','));
406                 }
407         
408                 foreach($focus->users_arr as $user_id) {
409                     if(empty($user_id) || isset($existing_users[$user_id]) || isset($deleteUsers[$user_id])) {
410                                 continue;
411                         }
412         
413                         if(!isset($acceptStatusUsers[$user_id])) {
414                                 $focus->load_relationship('users');
415                                 $focus->users->add($user_id);
416                         } else {
417                                 // update query to preserve accept_status
418                                 $qU  = 'UPDATE calls_users SET deleted = 0, accept_status = \''.$acceptStatusUsers[$user_id].'\' ';
419                                 $qU .= 'WHERE call_id = \''.$focus->id.'\' ';
420                                 $qU .= 'AND user_id = \''.$user_id.'\'';
421                                 $focus->db->query($qU);
422                         }
423                 }
424         
425                 // Process contacts
426                 $existing_contacts =  array();
427                 if(!empty($_POST['existing_contact_invitees'])) {
428                    $existing_contacts =  explode(",", trim($_POST['existing_contact_invitees'], ','));
429                 }
430         
431                 foreach($focus->contacts_arr as $contact_id) {
432                         if(empty($contact_id) || isset($exiting_contacts[$contact_id]) || isset($deleteContacts[$contact_id])) {
433                                 continue;
434                         }
435         
436                         if(!isset($acceptStatusContacts[$contact_id])) {
437                                 $focus->load_relationship('contacts');
438                             $focus->contacts->add($contact_id);
439                         } else {
440                                 // update query to preserve accept_status
441                                 $qU  = 'UPDATE calls_contacts SET deleted = 0, accept_status = \''.$acceptStatusContacts[$contact_id].'\' ';
442                                 $qU .= 'WHERE call_id = \''.$focus->id.'\' ';
443                                 $qU .= 'AND contact_id = \''.$contact_id.'\'';
444                                 $focus->db->query($qU);
445                         }
446                 }
447                 // Process leads
448                 $existing_leads =  array();
449                 if(!empty($_POST['existing_lead_invitees'])) {
450                    $existing_leads =  explode(",", trim($_POST['existing_lead_invitees'], ','));
451                 }
452         
453                 foreach($focus->leads_arr as $lead_id) {
454                         if(empty($lead_id) || isset($existing_leads[$lead_id]) || isset($deleteLeads[$lead_id])) {
455                                 continue;
456                         }
457         
458                         if(!isset($acceptStatusLeads[$lead_id])) {
459                                 $focus->load_relationship('leads');
460                             $focus->leads->add($lead_id);
461                         } else {
462                                 // update query to preserve accept_status
463                                 $qU  = 'UPDATE calls_leads SET deleted = 0, accept_status = \''.$acceptStatusLeads[$lead_id].'\' ';
464                                 $qU .= 'WHERE call_id = \''.$focus->id.'\' ';
465                                 $qU .= 'AND lead_id = \''.$lead_id.'\'';
466                                 $focus->db->query($qU);
467                         }
468                 }
469         
470                 // CCL - Comment out call to set $current_user as invitee
471                 //set organizer to auto-accept
472                 //$focus->set_accept_status($current_user, 'accept');
473                 
474                 ////    END REBUILD INVITEE RELATIONSHIPS
475                 ///////////////////////////////////////////////////////////////////////////
476             }
477     }
478         if (isset($_REQUEST['return_module']) && $_REQUEST['return_module'] == 'Home'){
479                 header("Location: index.php?module=Home&action=index");
480         }
481         else if($redirect) {
482                 handleRedirect($return_id, 'Calls');
483         } else {
484                 return $focus;
485         }
486
487 } // end handleSave();
488
489 function getWideFormBody ($prefix, $mod='', $formname='', $wide =true){
490         if(!ACLController::checkAccess('Calls', 'edit', true)){
491                 return '';
492         }
493 global $mod_strings;
494 $temp_strings = $mod_strings;
495 if(!empty($mod)){
496         global $current_language;
497         $mod_strings = return_module_language($current_language, $mod);
498 }
499 global $app_strings;
500 global $app_list_strings;
501 global $current_user;
502 global $theme;
503
504 $lbl_subject = $mod_strings['LBL_SUBJECT'];
505 // Unimplemented until jscalendar language files are fixed
506 // global $current_language;
507 // global $default_language;
508 // global $cal_codes;
509 // Unimplemented until jscalendar language files are fixed
510 // $cal_lang = (empty($cal_codes[$current_language])) ? $cal_codes[$default_language] : $cal_codes[$current_language];
511 $cal_lang = "en";
512
513
514 $lbl_required_symbol = $app_strings['LBL_REQUIRED_SYMBOL'];
515         $lbl_date = $mod_strings['LBL_DATE'];
516 $lbl_time = $mod_strings['LBL_TIME'];
517 global $timedate;
518 $ntc_date_format = '('.$timedate->get_user_date_format(). ')';
519 $ntc_time_format = '('.$timedate->get_user_time_format(). ')';
520 $cal_dateformat = $timedate->get_cal_date_format();
521
522         $user_id = $current_user->id;
523 $default_status = $app_list_strings['call_status_default'];
524 $default_parent_type= $app_list_strings['record_type_default_key'];
525 $date = gmdate($GLOBALS['timedate']->get_db_date_time_format());
526 $default_date_start = $timedate->to_display_date($date);
527 $default_time_start = $timedate->to_display_time($date,true);
528 $time_ampm = $timedate->AMPMMenu($prefix,$default_time_start);
529         $form = <<<EOQ
530                         <input type="hidden"  name="${prefix}direction" value="Outbound">
531                         <input type="hidden" name="${prefix}record" value="">
532                         <input type="hidden" name="${prefix}status" value="${default_status}">
533                         <input type="hidden" name="${prefix}parent_type" value="${default_parent_type}">
534                         <input type="hidden" name="${prefix}assigned_user_id" value='${user_id}'>
535                         <input type="hidden" name="${prefix}duration_hours" value="1">
536                         <input type="hidden" name="${prefix}duration_minutes" value="0">
537                         <input type="hidden" name="${prefix}user_id" value="${user_id}">
538
539                 <table cellspacing='0' cellpadding='0' border='0' width="100%">
540 <tr>
541 EOQ;
542
543 if($wide){
544 $form .= <<<EOQ
545 <td scope='row' width="20%"><input type='radio' name='appointment' value='Call' class='radio' checked> ${mod_strings['LNK_NEW_CALL']}</td>
546 <td scope='row' width="80%">${mod_strings['LBL_DESCRIPTION']}</td>
547 </tr>
548
549 <tr>
550 <td scope='row'><input type='radio' name='appointment' value='Meeting' class='radio'> ${mod_strings['LNK_NEW_MEETING']}</td>
551
552 <td rowspan='8' ><textarea name='Appointmentsdescription' cols='50' rows='5'></textarea></td>
553 </tr>
554 EOQ;
555 }else{
556                 $form .= <<<EOQ
557 <td scope='row' width="20%"><input type='radio' name='appointment' value='Call' class='radio' onchange='document.$formname.module.value="Calls";' checked> ${mod_strings['LNK_NEW_CALL']}</td>
558 </tr>
559
560 <tr>
561 <td scope='row'><input type='radio' name='appointment' value='Meeting' class='radio' onchange='document.$formname.module.value="Meetings";'> ${mod_strings['LNK_NEW_MEETING']}</td>
562 </tr>
563 EOQ;
564 }
565 $jscalenderImage = SugarThemeRegistry::current()->getImageURL('jscalendar.gif');
566 $form .=        <<<EOQ
567
568
569 <tr>
570 <td scope='row'>$lbl_subject&nbsp;<span class="required">$lbl_required_symbol</span></td>
571 </tr>
572
573 <tr>
574 <td ><input name='${prefix}name' maxlength='255' type="text"></td>
575 </tr>
576
577 <tr>
578 <td scope='row'>$lbl_date&nbsp;<span class="required">$lbl_required_symbol</span>&nbsp;<span class="dateFormat">$ntc_date_format</span></td>
579 </tr>
580 <tr>
581 <td ><input onblur="parseDate(this, '$cal_dateformat');" name='${prefix}date_start' size="12" id='${prefix}jscal_field' maxlength='10' type="text" value="${default_date_start}"> <img src="{$jscalenderImage}" alt="{$app_strings['LBL_ENTER_DATE']}"  id="${prefix}jscal_trigger" align="absmiddle"></td>
582 </tr>
583
584 <tr>
585 <td scope='row'>$lbl_time&nbsp;<span class="required">$lbl_required_symbol</span>&nbsp;<span class="dateFormat">$ntc_time_format</span></td>
586 </tr>
587 <tr>
588 <td ><input name='${prefix}time_start' size="12" type="text" maxlength='5' value="{$default_time_start}">$time_ampm</td>
589 </tr>
590
591 </table>
592
593                 <script type="text/javascript">
594                 Calendar.setup ({
595                         inputField : "${prefix}jscal_field", daFormat : "$cal_dateformat", ifFormat : "$cal_dateformat", showsTime : false, button : "${prefix}jscal_trigger", singleClick : true, step : 1, weekNumbers:false
596                 });
597                 </script>
598 EOQ;
599
600
601 $javascript = new javascript();
602 $javascript->setFormName($formname);
603 $javascript->setSugarBean(new Call());
604 $javascript->addRequiredFields($prefix);
605 $form .=$javascript->getScript();
606 $mod_strings = $temp_strings;
607 return $form;
608
609 }
610
611
612
613 }
614 ?>