PageRenderTime 56ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/Calendar/Save.php

https://bitbucket.org/yousef_fadila/vtiger
PHP | 350 lines | 294 code | 26 blank | 30 comment | 104 complexity | 662d94808c6feb8c51b432778c6b06f8 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0
  1. <?php
  2. /*********************************************************************************
  3. * The contents of this file are subject to the SugarCRM Public License Version 1.1.2
  4. * ("License"); You may not use this file except in compliance with the
  5. * License. You may obtain a copy of the License at http://www.sugarcrm.com/SPL
  6. * Software distributed under the License is distributed on an "AS IS" basis,
  7. * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
  8. * the specific language governing rights and limitations under the License.
  9. * The Original Code is: SugarCRM Open Source
  10. * The Initial Developer of the Original Code is SugarCRM, Inc.
  11. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.;
  12. * All Rights Reserved.
  13. * Contributor(s): ______________________________________.
  14. ********************************************************************************/
  15. /*********************************************************************************
  16. * $Header: /advent/projects/wesat/vtiger_crm/sugarcrm/modules/Activities/Save.php,v 1.11 2005/04/18 10:37:49 samk Exp $
  17. * Description: Saves an Account record and then redirects the browser to the
  18. * defined return URL.
  19. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
  20. * All Rights Reserved.
  21. * Contributor(s): ______________________________________..
  22. ********************************************************************************/
  23. require_once('modules/Calendar/Activity.php');
  24. require_once('include/logging.php');
  25. require_once("config.php");
  26. require_once('include/database/PearDatabase.php');
  27. require_once('modules/Calendar/CalendarCommon.php');
  28. global $adb,$theme;
  29. $local_log =& LoggerManager::getLogger('index');
  30. $focus = new Activity();
  31. $activity_mode = vtlib_purify($_REQUEST['activity_mode']);
  32. $tab_type = 'Calendar';
  33. //added to fix 4600
  34. $search=vtlib_purify($_REQUEST['search_url']);
  35. $focus->column_fields["activitytype"] = 'Task';
  36. if(isset($_REQUEST['record']))
  37. {
  38. $focus->id = $_REQUEST['record'];
  39. $local_log->debug("id is ".$id);
  40. }
  41. if(isset($_REQUEST['mode']))
  42. {
  43. $focus->mode = $_REQUEST['mode'];
  44. }
  45. if((isset($_REQUEST['change_status']) && $_REQUEST['change_status']) && ($_REQUEST['status']!='' || $_REQUEST['eventstatus']!=''))
  46. {
  47. $status ='';
  48. $activity_type='';
  49. $return_id = $focus->id;
  50. if(isset($_REQUEST['status']))
  51. {
  52. $status = $_REQUEST['status'];
  53. $activity_type = "Task";
  54. }
  55. elseif(isset($_REQUEST['eventstatus']))
  56. {
  57. $status = $_REQUEST['eventstatus'];
  58. $activity_type = "Events";
  59. }
  60. if(isPermitted("Calendar","EditView",$_REQUEST['record']) == 'yes')
  61. {
  62. ChangeStatus($status,$return_id,$activity_type);
  63. }
  64. else
  65. {
  66. echo "<link rel='stylesheet' type='text/css' href='themes/$theme/style.css'>";
  67. echo "<table border='0' cellpadding='5' cellspacing='0' width='100%' height='450px'><tr><td align='center'>";
  68. echo "<div style='border: 3px solid rgb(153, 153, 153); background-color: rgb(255, 255, 255); width: 55%; position: relative; z-index: 10000000;'>
  69. <table border='0' cellpadding='5' cellspacing='0' width='98%'>
  70. <tbody><tr>
  71. <td rowspan='2' width='11%'><img src='<?php echo vtiger_imageurl('denied.gif', $theme). ?>' ></td>
  72. <td style='border-bottom: 1px solid rgb(204, 204, 204);' nowrap='nowrap' width='70%'><span class='genHeaderSmall'>$app_strings[LBL_PERMISSION]</span></td>
  73. </tr>
  74. <tr>
  75. <td class='small' align='right' nowrap='nowrap'>
  76. <a href='javascript:window.history.back();'>$app_strings[LBL_GO_BACK]</a><br> </td>
  77. </tr>
  78. </tbody></table>
  79. </div>";
  80. echo "</td></tr></table>";die;
  81. }
  82. $invitee_qry = "select * from vtiger_invitees where activityid=?";
  83. $invitee_res = $adb->pquery($invitee_qry, array($return_id));
  84. $count = $adb->num_rows($invitee_res);
  85. if($count != 0)
  86. {
  87. for($j = 0; $j < $count; $j++)
  88. {
  89. $invitees_ids[]= $adb->query_result($invitee_res,$j,"inviteeid");
  90. }
  91. $invitees_ids_string = implode(';',$invitees_ids);
  92. sendInvitation($invitees_ids_string,$activity_type,$mail_data['subject'],$mail_data);
  93. }
  94. }
  95. else
  96. {
  97. $timeFields = array('time_start', 'time_end');
  98. $tabId = getTabid($tab_type);
  99. foreach($focus->column_fields as $fieldname => $val)
  100. {
  101. $fieldInfo = getFieldRelatedInfo($tabId, $fieldname);
  102. $uitype = $fieldInfo['uitype'];
  103. $typeofdata = $fieldInfo['typeofdata'];
  104. if(isset($_REQUEST[$fieldname]))
  105. {
  106. if(is_array($_REQUEST[$fieldname]))
  107. $value = $_REQUEST[$fieldname];
  108. else
  109. $value = trim($_REQUEST[$fieldname]);
  110. if((($typeofdata == 'T~M') || ($typeofdata == 'T~O')) && ($uitype == 2 || $uitype == 70 )) {
  111. if(!in_array($fieldname, $timeFields)) {
  112. $date = DateTimeField::convertToDBTimeZone($value);
  113. $value = $date->format('H:i');
  114. }
  115. $focus->column_fields[$fieldname] = $value;
  116. }else{
  117. $focus->column_fields[$fieldname] = $value;
  118. }
  119. if(($fieldname == 'notime') && ($focus->column_fields[$fieldname]))
  120. {
  121. $focus->column_fields['time_start'] = '';
  122. $focus->column_fields['duration_hours'] = '';
  123. $focus->column_fields['duration_minutes'] = '';
  124. }
  125. if(($fieldname == 'recurringtype') && ! isset($_REQUEST['recurringcheck']))
  126. $focus->column_fields['recurringtype'] = '--None--';
  127. }
  128. }
  129. if(isset($_REQUEST['visibility']) && $_REQUEST['visibility']!= '')
  130. $focus->column_fields['visibility'] = $_REQUEST['visibility'];
  131. else
  132. $focus->column_fields['visibility'] = 'Private';
  133. if($_REQUEST['assigntype'] == 'U') {
  134. $focus->column_fields['assigned_user_id'] = $_REQUEST['assigned_user_id'];
  135. } elseif($_REQUEST['assigntype'] == 'T') {
  136. $focus->column_fields['assigned_user_id'] = $_REQUEST['assigned_group_id'];
  137. }
  138. $dateField = 'date_start';
  139. $fieldname = 'time_start';
  140. $date = new DateTimeField($_REQUEST[$dateField]. ' ' . $_REQUEST[$fieldname]);
  141. $focus->column_fields[$dateField] = $date->getDBInsertDateValue();
  142. $focus->column_fields[$fieldname] = $date->getDBInsertTimeValue();
  143. if(empty($_REQUEST['time_end'])) {
  144. $_REQUEST['time_end'] = date('H:i', strtotime('+10 minutes',
  145. strtotime($focus->column_fields['date_start'].' '.$_REQUEST['time_start'])));
  146. }
  147. $dateField = 'due_date';
  148. $fieldname = 'time_end';
  149. $date = new DateTimeField($_REQUEST[$dateField]. ' ' . $_REQUEST[$fieldname]);
  150. $focus->column_fields[$dateField] = $date->getDBInsertDateValue();
  151. $focus->column_fields[$fieldname] = $date->getDBInsertTimeValue();
  152. $focus->save($tab_type);
  153. /* For Followup START -- by Minnie */
  154. if(isset($_REQUEST['followup']) && $_REQUEST['followup'] == 'on' && $activity_mode == 'Events' && isset($_REQUEST['followup_time_start']) && $_REQUEST['followup_time_start'] != '')
  155. {
  156. $heldevent_id = $focus->id;
  157. $focus->column_fields['subject'] = '[Followup] '.$focus->column_fields['subject'];
  158. $startDate = new DateTimeField($_REQUEST['followup_date'].' '.
  159. $_REQUEST['followup_time_start']);
  160. $endDate = new DateTimeField($_REQUEST['followup_due_date'].' '.
  161. $_REQUEST['followup_time_end']);
  162. $focus->column_fields['date_start'] = $startDate->getDBInsertDateValue();
  163. $focus->column_fields['due_date'] = $endDate->getDBInsertDateValue();
  164. $focus->column_fields['time_start'] = $startDate->getDBInsertTimeValue();
  165. $focus->column_fields['time_end'] = $endDate->getDBInsertTimeValue();
  166. $focus->column_fields['eventstatus'] = 'Planned';
  167. $focus->mode = 'create';
  168. $focus->save($tab_type);
  169. }
  170. /* For Followup END -- by Minnie */
  171. $return_id = $focus->id;
  172. }
  173. if(isset($_REQUEST['return_module']) && $_REQUEST['return_module'] != "")
  174. $return_module = vtlib_purify($_REQUEST['return_module']);
  175. else
  176. $return_module = "Calendar";
  177. if(isset($_REQUEST['return_action']) && $_REQUEST['return_action'] != "")
  178. $return_action = vtlib_purify($_REQUEST['return_action']);
  179. else
  180. $return_action = "DetailView";
  181. if(isset($_REQUEST['return_id']) && $_REQUEST['return_id'] != "")
  182. $return_id = vtlib_purify($_REQUEST['return_id']);
  183. $activemode = "";
  184. if($activity_mode != '')
  185. $activemode = "&activity_mode=".$activity_mode;
  186. function getRequestData($return_id)
  187. {
  188. global $adb;
  189. $cont_qry = "select * from vtiger_cntactivityrel where activityid=?";
  190. $cont_res = $adb->pquery($cont_qry, array($return_id));
  191. $noofrows = $adb->num_rows($cont_res);
  192. $cont_id = array();
  193. if($noofrows > 0) {
  194. for($i=0; $i<$noofrows; $i++) {
  195. $cont_id[] = $adb->query_result($cont_res,$i,"contactid");
  196. }
  197. }
  198. $cont_name = '';
  199. foreach($cont_id as $key=>$id) {
  200. if($id != '') {
  201. $displayValueArray = getEntityName('Contacts', $id);
  202. if (!empty($displayValueArray)) {
  203. foreach ($displayValueArray as $key => $field_value) {
  204. $contact_name = $field_value;
  205. }
  206. }
  207. $cont_name .= $contact_name .', ';
  208. }
  209. }
  210. $cont_name = trim($cont_name,', ');
  211. $mail_data = Array();
  212. $mail_data['user_id'] = $_REQUEST['assigned_user_id'];
  213. $mail_data['subject'] = $_REQUEST['subject'];
  214. $mail_data['status'] = (($_REQUEST['activity_mode']=='Task')?($_REQUEST['taskstatus']):($_REQUEST['eventstatus']));
  215. $mail_data['activity_mode'] = $_REQUEST['activity_mode'];
  216. $mail_data['taskpriority'] = $_REQUEST['taskpriority'];
  217. $mail_data['relatedto'] = $_REQUEST['parent_name'];
  218. $mail_data['contact_name'] = $cont_name;
  219. $mail_data['description'] = $_REQUEST['description'];
  220. $mail_data['assign_type'] = $_REQUEST['assigntype'];
  221. $mail_data['group_name'] = getGroupName($_REQUEST['assigned_group_id']);
  222. $mail_data['mode'] = $_REQUEST['mode'];
  223. $value = getaddEventPopupTime($_REQUEST['time_start'],$_REQUEST['time_end'],'24');
  224. $start_hour = $value['starthour'].':'.$value['startmin'].''.$value['startfmt'];
  225. if($_REQUEST['activity_mode']!='Task')
  226. $end_hour = $value['endhour'] .':'.$value['endmin'].''.$value['endfmt'];
  227. $startDate = new DateTimeField($_REQUEST['date_start']." ".$start_hour);
  228. $endDate = new DateTimeField($_REQUEST['due_date']." ".$end_hour);
  229. $mail_data['st_date_time'] = $startDate->getDBInsertDateTimeValue();
  230. $mail_data['end_date_time'] = $endDate->getDBInsertDateTimeValue();
  231. $mail_data['location']=vtlib_purify($_REQUEST['location']);
  232. return $mail_data;
  233. }
  234. function getFieldRelatedInfo($tabId, $fieldName){
  235. $fieldInfo = VTCacheUtils::lookupFieldInfo($tabId, $fieldName);
  236. if($fieldInfo === false) {
  237. getColumnFields(getTabModuleName($tabid));
  238. $fieldInfo = VTCacheUtils::lookupFieldInfo($tabId, $fieldName);
  239. }
  240. return $fieldInfo;
  241. }
  242. if(isset($_REQUEST['contactidlist']) && $_REQUEST['contactidlist'] != '')
  243. {
  244. //split the string and store in an array
  245. $storearray = explode (";",$_REQUEST['contactidlist']);
  246. $del_sql = "delete from vtiger_cntactivityrel where activityid=?";
  247. $adb->pquery($del_sql, array($record));
  248. $record = $focus->id;
  249. foreach($storearray as $id)
  250. {
  251. if($id != '')
  252. {
  253. $sql = "insert into vtiger_cntactivityrel values (?,?)";
  254. $adb->pquery($sql, array($id, $record));
  255. if(!empty($heldevent_id)) {
  256. $sql = "insert into vtiger_cntactivityrel values (?,?)";
  257. $adb->pquery($sql, array($id, $heldevent_id));
  258. }
  259. }
  260. }
  261. }
  262. //code added to send mail to the vtiger_invitees
  263. if(isset($_REQUEST['inviteesid']) && $_REQUEST['inviteesid']!='')
  264. {
  265. $mail_contents = getRequestData($return_id);
  266. sendInvitation($_REQUEST['inviteesid'],$_REQUEST['activity_mode'],$_REQUEST['subject'],$mail_contents);
  267. }
  268. //to delete contact account relation while editing event
  269. if(isset($_REQUEST['deletecntlist']) && $_REQUEST['deletecntlist'] != '' && $_REQUEST['mode'] == 'edit')
  270. {
  271. //split the string and store it in an array
  272. $storearray = explode (";",$_REQUEST['deletecntlist']);
  273. foreach($storearray as $id)
  274. {
  275. if($id != '')
  276. {
  277. $record = $focus->id;
  278. $sql = "delete from vtiger_cntactivityrel where contactid=? and activityid=?";
  279. $adb->pquery($sql, array($id, $record));
  280. }
  281. }
  282. }
  283. //to delete activity and its parent table relation
  284. if(isset($_REQUEST['del_actparent_rel']) && $_REQUEST['del_actparent_rel'] != '' && $_REQUEST['mode'] == 'edit')
  285. {
  286. $parnt_id = $_REQUEST['del_actparent_rel'];
  287. $sql= 'delete from vtiger_seactivityrel where crmid=? and activityid=?';
  288. $adb->pquery($sql, array($parnt_id, $record));
  289. }
  290. if(isset($_REQUEST['view']) && $_REQUEST['view']!='')
  291. $view=vtlib_purify($_REQUEST['view']);
  292. if(isset($_REQUEST['hour']) && $_REQUEST['hour']!='')
  293. $hour=vtlib_purify($_REQUEST['hour']);
  294. if(isset($_REQUEST['day']) && $_REQUEST['day']!='')
  295. $day=vtlib_purify($_REQUEST['day']);
  296. if(isset($_REQUEST['month']) && $_REQUEST['month']!='')
  297. $month=vtlib_purify($_REQUEST['month']);
  298. if(isset($_REQUEST['year']) && $_REQUEST['year']!='')
  299. $year=vtlib_purify($_REQUEST['year']);
  300. if(isset($_REQUEST['viewOption']) && $_REQUEST['viewOption']!='')
  301. $viewOption=vtlib_purify($_REQUEST['viewOption']);
  302. if(isset($_REQUEST['subtab']) && $_REQUEST['subtab']!='')
  303. $subtab=vtlib_purify($_REQUEST['subtab']);
  304. if($_REQUEST['recurringcheck']) {
  305. include_once dirname(__FILE__) . '/RepeatEvents.php';
  306. Calendar_RepeatEvents::repeatFromRequest($focus);
  307. }
  308. //code added for returning back to the current view after edit from list view
  309. if($_REQUEST['return_viewname'] == '')
  310. $return_viewname='0';
  311. if($_REQUEST['return_viewname'] != '')
  312. $return_viewname=vtlib_purify($_REQUEST['return_viewname']);
  313. $parenttab=getParentTab();
  314. if(!empty($_REQUEST['start'])) {
  315. $page='&start='.vtlib_purify($_REQUEST['start']);
  316. }
  317. if(!empty($_REQUEST['pagenumber'])){
  318. $page = "&start=".vtlib_purify($_REQUEST['pagenumber']);
  319. }
  320. if($_REQUEST['maintab'] == 'Calendar')
  321. header("Location: index.php?action=".$return_action."&module=".$return_module."&view=".$view."&hour=".$hour."&day=".$day."&month=".$month."&year=".$year."&record=".$return_id."&viewOption=".$viewOption."&subtab=".$subtab."&parenttab=$parenttab");
  322. else
  323. header("Location: index.php?action=$return_action&module=$return_module$view$hour$day$month$year&record=$return_id$activemode&viewname=$return_viewname$page&parenttab=$parenttab$search");
  324. ?>