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: Base Form For Meetings
41 * Portions created by SugarCRM are Copyright(C) SugarCRM, Inc.
42 * All Rights Reserved.
43 * Contributor(s): ______________________________________..
44 ********************************************************************************/
46 require_once('include/SugarObjects/forms/FormBase.php');
48 class MeetingFormBase extends FormBase {
50 function getFormBody($prefix, $mod='', $formname=''){
51 if(!ACLController::checkAccess('Meetings', 'edit', true)){
56 global $app_list_strings;
61 $temp_strings = $mod_strings;
63 global $current_language;
64 $mod_strings = return_module_language($current_language, $mod);
66 // Unimplemented until jscalendar language files are fixed
67 // global $current_language;
68 // global $default_language;
72 $cal_dateformat = $timedate->get_cal_date_format();
74 $lbl_required_symbol = $app_strings['LBL_REQUIRED_SYMBOL'];
75 $lbl_date = $mod_strings['LBL_DATE'];
76 $lbl_time = $mod_strings['LBL_TIME'];
77 $ntc_date_format = $timedate->get_user_date_format();
78 $ntc_time_format = '('.$timedate->get_user_time_format().')';
80 $user_id = $current_user->id;
81 $default_status = $app_list_strings['meeting_status_default'];
82 $default_parent_type= $app_list_strings['record_type_default_key'];
83 $default_date_start = $timedate->nowDbDate();
84 $default_time_start = $timedate->nowDbTime();
85 $time_ampm = $timedate->AMPMMenu($prefix, $timedate->nowDbTime());
86 // Unimplemented until jscalendar language files are fixed
87 // $cal_lang =(empty($cal_codes[$current_language])) ? $cal_codes[$default_language] : $cal_codes[$current_language];
88 $jsCalendarImage = SugarThemeRegistry::current()->getImageURL('jscalendar.gif');
90 <input type="hidden" name="${prefix}record" value="">
91 <input type="hidden" name="${prefix}status" value="${default_status}">
92 <input type="hidden" name="${prefix}parent_type" value="${default_parent_type}">
93 <input type="hidden" name="${prefix}assigned_user_id" value='${user_id}'>
94 <input type="hidden" name="${prefix}duration_hours" value="1">
95 <input type="hidden" name="${prefix}duration_minutes" value="00">
96 <p>$lbl_subject<span class="required">$lbl_required_symbol</span><br>
97 <input name='${prefix}name' size='25' maxlength='255' type="text"><br>
98 $lbl_date <span class="required">$lbl_required_symbol</span> <span class="dateFormat">$ntc_date_format</span><br>
99 <input name='${prefix}date_start' id='jscal_field' onblur="parseDate(this, '$cal_dateformat');" type="text" maxlength="10" value="${default_date_start}"> <!--not_in_theme!--><img src="{$jscalendarImage}" alt="{$app_strings['LBL_ENTER_DATE']}" id="jscal_trigger" align="absmiddle"><br>
100 $lbl_time <span class="required">$lbl_required_symbol</span> <span class="dateFormat">$ntc_time_format</span><br>
101 <input name='${prefix}time_start' type="text" maxlength='5' value="${default_time_start}">{$time_ampm}</p>
102 <script type="text/javascript">
104 inputField : "jscal_field", daFormat : "$cal_dateformat", ifFormat : "$cal_dateformat", showsTime : false, button : "jscal_trigger", singleClick : true, step : 1, weekNumbers:false
110 $javascript = new javascript();
111 $javascript->setFormName($formname);
112 $javascript->setSugarBean(new Meeting());
113 $javascript->addRequiredFields($prefix);
114 $form .=$javascript->getScript();
115 $mod_strings = $temp_strings;
121 function getForm($prefix, $mod='Meetings'){
122 if(!ACLController::checkAccess('Meetings', 'edit', true)){
127 global $app_list_strings;
130 global $current_language;
131 $mod_strings = return_module_language($current_language, $mod);
136 $lbl_save_button_title = $app_strings['LBL_SAVE_BUTTON_TITLE'];
137 $lbl_save_button_key = $app_strings['LBL_SAVE_BUTTON_KEY'];
138 $lbl_save_button_label = $app_strings['LBL_SAVE_BUTTON_LABEL'];
141 $the_form = get_left_form_header($mod_strings['LBL_NEW_FORM_TITLE']);
145 <form name="${prefix}MeetingSave" onSubmit="return check_form('${prefix}MeetingSave')" method="POST" action="index.php">
146 <input type="hidden" name="${prefix}module" value="Meetings">
148 <input type="hidden" name="${prefix}action" value="Save">
151 $the_form .= $this->getFormBody($prefix, 'Meetings',"{$prefix}MeetingSave" );
153 <p><input title="$lbl_save_button_title" accessKey="$lbl_save_button_key" class="button" type="submit" name="button" value=" $lbl_save_button_label " ></p>
157 $the_form .= get_left_form_footer();
158 $the_form .= get_validate_record_js();
165 * handles save functionality for meetings
166 * @param string prefix
167 * @param bool redirect default True
168 * @param bool useRequired default True
170 function handleSave($prefix,$redirect=true, $useRequired=false) {
173 require_once('include/formbase.php');
175 global $current_user;
178 $focus = new Meeting();
180 if($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) {
184 if( !isset($_POST['reminder_checked']) or ( isset($_POST['reminder_checked']) && $_POST['reminder_checked'] == '0')) {
185 $_POST['reminder_time'] = -1;
187 if(!isset($_POST['reminder_time'])) {
188 $_POST['reminder_time'] = $current_user->getPreference('reminder_time');
189 $_POST['reminder_checked']=1;
191 $time_format = $timedate->get_user_time_format();
192 $time_separator = ":";
193 if(preg_match('/\d+([^\d])\d+([^\d]*)/s', $time_format, $match)) {
194 $time_separator = $match[1];
197 if(!empty($_POST[$prefix.'time_hour_start']) && empty($_POST['time_start'])) {
198 $_POST[$prefix.'time_start'] = $_POST[$prefix.'time_hour_start']. $time_separator .$_POST[$prefix.'time_minute_start'];
201 if(isset($_POST[$prefix.'meridiem']) && !empty($_POST[$prefix.'meridiem'])) {
202 $_POST[$prefix.'time_start'] = $timedate->merge_time_meridiem($_POST[$prefix.'time_start'],$timedate->get_time_format(), $_POST[$prefix.'meridiem']);
205 if(isset($_POST[$prefix.'time_start']) && strlen($_POST[$prefix.'date_start']) == 10) {
206 $_POST[$prefix.'date_start'] = $_POST[$prefix.'date_start'] . ' ' . $_POST[$prefix.'time_start'];
209 // retrieve happens here
210 $focus = populateFromPost($prefix, $focus);
211 if(!$focus->ACLAccess('Save')) {
212 ACLController::displayNoAccess(true);
216 //add assigned user and current user if this is the first time bean is saved
217 if(empty($focus->id) && !empty($_REQUEST['return_module']) && $_REQUEST['return_module'] =='Meetings' && !empty($_REQUEST['return_action']) && $_REQUEST['return_action'] =='DetailView'){
218 //if return action is set to detail view and return module to meeting, then this is from the long form, do not add the assigned user (only the current user)
219 //The current user is already added to UI and we want to give the current user the option of opting out of meeting.
220 //add current user if the assigned to user is different than current user.
221 if($current_user->id != $_POST['assigned_user_id']){
222 $_POST['user_invitees'] .= ','.$_POST['assigned_user_id'].', ';
223 $_POST['user_invitees'] = str_replace(',,', ',', $_POST['user_invitees']);
225 }elseif (empty($focus->id) ){
226 //this is not from long form so add assigned and current user automatically as there is no invitee list UI.
227 //This call could be through an ajax call from subpanels or shortcut bar
228 if(!isset($_POST['user_invitees']))
230 $_POST['user_invitees'] = '';
233 $_POST['user_invitees'] .= ','.$_POST['assigned_user_id'].', ';
235 //add current user if the assigned to user is different than current user.
236 if($current_user->id != $_POST['assigned_user_id']){
237 $_POST['user_invitees'] .= ','.$current_user->id.', ';
240 //remove any double comma's introduced during appending
241 $_POST['user_invitees'] = str_replace(',,', ',', $_POST['user_invitees']);
245 if( (isset($_POST['isSaveFromDetailView']) && $_POST['isSaveFromDetailView'] == 'true') ||
246 (isset($_POST['is_ajax_call']) && !empty($_POST['is_ajax_call']) && !empty($focus->id) )
249 $return_id = $focus->id;
251 if($focus->status == 'Held' && $this->isEmptyReturnModuleAndAction() && !$this->isSaveFromDCMenu()){
252 //if we are closing the meeting, and the request does not have a return module AND return action set and it is not a save
253 //being triggered by the DCMenu (shortcut bar) then the request is coming from a dashlet or subpanel close icon and there is no
254 //need to process user invitees, just save the current values.
257 ///////////////////////////////////////////////////////////////////////////
258 //// REMOVE INVITEE RELATIONSHIPS
259 if(!empty($_POST['user_invitees'])) {
260 $userInvitees = explode(',', trim($_POST['user_invitees'], ','));
262 $userInvitees = array();
265 // Calculate which users to flag as deleted and which to add
266 $deleteUsers = array();
267 $focus->load_relationship('users');
268 // Get all users for the meeting
269 $q = 'SELECT mu.user_id, mu.accept_status FROM meetings_users mu WHERE mu.meeting_id = \''.$focus->id.'\'';
270 $r = $focus->db->query($q);
271 $acceptStatusUsers = array();
272 while($a = $focus->db->fetchByAssoc($r)) {
273 if(!in_array($a['user_id'], $userInvitees)) {
274 $deleteUsers[$a['user_id']] = $a['user_id'];
276 $acceptStatusUsers[$a['user_id']] = $a['accept_status'];
280 if(count($deleteUsers) > 0) {
282 foreach($deleteUsers as $u) {
283 $sql .= ",'" . $u . "'";
285 $sql = substr($sql, 1);
286 // We could run a delete SQL statement here, but will just mark as deleted instead
287 $sql = "UPDATE meetings_users set deleted = 1 where user_id in ($sql) AND meeting_id = '". $focus->id . "'";
288 $focus->db->query($sql);
291 // Get all contacts for the meeting
292 if(!empty($_POST['contact_invitees'])) {
293 $contactInvitees = explode(',', trim($_POST['contact_invitees'], ','));
295 $contactInvitees = array();
298 $deleteContacts = array();
299 $focus->load_relationship('contacts');
300 $q = 'SELECT mu.contact_id, mu.accept_status FROM meetings_contacts mu WHERE mu.meeting_id = \''.$focus->id.'\'';
301 $r = $focus->db->query($q);
302 $acceptStatusContacts = array();
303 while($a = $focus->db->fetchByAssoc($r)) {
304 if(!in_array($a['contact_id'], $contactInvitees)) {
305 $deleteContacts[$a['contact_id']] = $a['contact_id'];
307 $acceptStatusContacts[$a['contact_id']] = $a['accept_status'];
311 if(count($deleteContacts) > 0) {
313 foreach($deleteContacts as $u) {
314 $sql .= ",'" . $u . "'";
316 $sql = substr($sql, 1);
317 // We could run a delete SQL statement here, but will just mark as deleted instead
318 $sql = "UPDATE meetings_contacts set deleted = 1 where contact_id in ($sql) AND meeting_id = '". $focus->id . "'";
319 $focus->db->query($sql);
321 if(!empty($_POST['lead_invitees'])) {
322 $leadInvitees = explode(',', trim($_POST['lead_invitees'], ','));
324 $leadInvitees = array();
327 $deleteLeads = array();
328 $focus->load_relationship('leads');
329 $q = 'SELECT mu.lead_id, mu.accept_status FROM meetings_leads mu WHERE mu.meeting_id = \''.$focus->id.'\'';
330 $r = $focus->db->query($q);
331 $acceptStatusLeads = array();
332 while($a = $focus->db->fetchByAssoc($r)) {
333 if(!in_array($a['lead_id'], $leadInvitees)) {
334 $deleteLeads[$a['lead_id']] = $a['lead_id'];
336 $acceptStatusLeads[$a['lead_id']] = $a['accept_status'];
340 if(count($deleteLeads) > 0) {
342 foreach($deleteLeads as $u) {
343 $sql .= ",'" . $u . "'";
345 $sql = substr($sql, 1);
346 // We could run a delete SQL statement here, but will just mark as deleted instead
347 $sql = "UPDATE meetings_leads set deleted = 1 where lead_id in ($sql) AND meeting_id = '". $focus->id . "'";
348 $focus->db->query($sql);
351 ///////////////////////////////////////////////////////////////////////////
354 ///////////////////////////////////////////////////////////////////////////
355 //// REBUILD INVITEE RELATIONSHIPS
356 $focus->users_arr = array();
357 $focus->users_arr = $userInvitees;
358 $focus->contacts_arr = array();
359 $focus->contacts_arr = $contactInvitees;
360 $focus->leads_arr = array();
361 $focus->leads_arr = $leadInvitees;
363 if(!empty($_POST['parent_id']) && $_POST['parent_type'] == 'Contacts') {
364 $focus->contacts_arr[] = $_POST['parent_id'];
366 if(!empty($_POST['parent_id']) && $_POST['parent_type'] == 'Leads') {
367 $focus->leads_arr[] = $_POST['parent_id'];
369 // Call the Meeting module's save function to handle saving other fields besides
370 // the users and contacts relationships
371 $focus->update_vcal = false; // Bug #49195 : don't update vcal b/s related users aren't saved yet, create vcal cache below
373 $return_id = $focus->id;
374 if(empty($return_id)){
375 //this is to handle the situation where the save fails, most likely because of a failure
376 //in the external api. bug: 42200
377 $_REQUEST['action'] = 'EditView';
378 $_REQUEST['return_action'] = 'EditView';
379 handleRedirect('', 'Meetings');
382 $existing_users = array();
383 if(!empty($_POST['existing_invitees'])) {
384 $existing_users = explode(",", trim($_POST['existing_invitees'], ','));
387 foreach($focus->users_arr as $user_id) {
388 if(empty($user_id) || isset($existing_users[$user_id]) || isset($deleteUsers[$user_id])) {
392 if(!isset($acceptStatusUsers[$user_id])) {
393 $focus->users->add($user_id);
395 // update query to preserve accept_status
396 $qU = 'UPDATE meetings_users SET deleted = 0, accept_status = \''.$acceptStatusUsers[$user_id].'\' ';
397 $qU .= 'WHERE meeting_id = \''.$focus->id.'\' ';
398 $qU .= 'AND user_id = \''.$user_id.'\'';
399 $focus->db->query($qU);
404 $existing_contacts = array();
405 if(!empty($_POST['existing_contact_invitees'])) {
406 $existing_contacts = explode(",", trim($_POST['existing_contact_invitees'], ','));
409 foreach($focus->contacts_arr as $contact_id) {
410 if(empty($contact_id) || isset($existing_contacts[$contact_id]) || isset($deleteContacts[$contact_id])) {
414 if(!isset($acceptStatusContacts[$contact_id])) {
415 $focus->contacts->add($contact_id);
417 // update query to preserve accept_status
418 $qU = 'UPDATE meetings_contacts SET deleted = 0, accept_status = \''.$acceptStatusContacts[$contact_id].'\' ';
419 $qU .= 'WHERE meeting_id = \''.$focus->id.'\' ';
420 $qU .= 'AND contact_id = \''.$contact_id.'\'';
421 $focus->db->query($qU);
425 $existing_leads = array();
426 if(!empty($_POST['existing_lead_invitees'])) {
427 $existing_leads = explode(",", trim($_POST['existing_lead_invitees'], ','));
430 foreach($focus->leads_arr as $lead_id) {
431 if(empty($lead_id) || isset($existing_leads[$lead_id]) || isset($deleteLeads[$lead_id])) {
435 if(!isset($acceptStatusLeads[$lead_id])) {
436 $focus->leads->add($lead_id);
438 // update query to preserve accept_status
439 $qU = 'UPDATE meetings_leads SET deleted = 0, accept_status = \''.$acceptStatusLeads[$lead_id].'\' ';
440 $qU .= 'WHERE meeting_id = \''.$focus->id.'\' ';
441 $qU .= 'AND lead_id = \''.$lead_id.'\'';
442 $focus->db->query($qU);
446 // Bug #49195 : update vcal
447 vCal::cache_sugar_vcal($current_user);
449 // CCL - Comment out call to set $current_user as invitee
450 // set organizer to auto-accept
451 //$focus->set_accept_status($current_user, 'accept');
453 //// END REBUILD INVITEE RELATIONSHIPS
454 ///////////////////////////////////////////////////////////////////////////
457 if (isset($_REQUEST['return_module']) && $_REQUEST['return_module'] == 'Home'){
458 header("Location: index.php?module=Home&action=index");
461 handleRedirect($return_id, 'Meetings');
466 } // end handleSave();