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-2013 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 ********************************************************************************/
39 require_once("modules/Calendar/CalendarUtils.php");
41 class CalendarController extends SugarController
45 * Bean that is being handled by the Calendar's current action.
46 * @var SugarBean $currentBean
48 protected $currentBean = null;
54 protected function action_saveactivity()
58 if (!$this->retrieveCurrentBean('Save')) {
62 $module = $this->currentBean->module_dir;
63 $bean = $this->currentBean;
65 if (empty($_REQUEST['edit_all_recurrences'])) {
67 $repeat_fields = array('type', 'interval', 'count', 'until', 'dow', 'parent_id');
68 foreach ($repeat_fields as $suffix) {
69 unset($_POST['repeat_' . $suffix]);
72 }else if (!empty($_REQUEST['repeat_type']) && !empty($_REQUEST['date_start'])) {
75 'type' => $_REQUEST['repeat_type'],
76 'interval' => $_REQUEST['repeat_interval'],
77 'count' => $_REQUEST['repeat_count'],
78 'until' => $_REQUEST['repeat_until'],
79 'dow' => $_REQUEST['repeat_dow'],
82 $repeatArr = CalendarUtils::build_repeat_sequence($_REQUEST['date_start'], $params);
83 $limit = SugarConfig::getInstance()->get('calendar.max_repeat_count', 1000);
85 if (count($repeatArr) > ($limit - 1)) {
89 'limit_error' => 'true',
92 $this->view_object_map['jsonData'] = $jsonData;
99 $path = "modules/{$bean->module_dir}/{$bean->object_name}FormBase.php";
100 if (!file_exists($path)) {
101 $GLOBALS['log']->fatal("File {$bean->object_name}FormBase.php doesn't exist");
107 $FBObjectName = "{$bean->object_name}FormBase";
109 if (!class_exists($FBObjectName)) {
110 $GLOBALS['log']->fatal("Class {$bean->object_name}FormBase doesn't exist");
114 $formBase = new $FBObjectName();
115 $bean = $formBase->handleSave('', false, false);
116 unset($_REQUEST['send_invites'], $_POST['send_invites']); // prevent invites sending for recurring activities
118 if ($record = $bean->id) {
120 if ($module == "Meetings" || $module == "Calls") {
121 if (!empty($_REQUEST['edit_all_recurrences'])) {
122 CalendarUtils::markRepeatDeleted($bean);
124 if (isset($repeatArr) && is_array($repeatArr) && count($repeatArr) > 0) {
125 $repeatCreated = CalendarUtils::save_repeat_activities($bean, $repeatArr);
129 $bean->retrieve($record);
130 $jsonData = CalendarUtils::get_sendback_array($bean);
132 if (isset($repeatCreated) && is_array($repeatCreated)) {
133 $jsonData = array_merge($jsonData, array('repeat' => $repeatCreated));
136 if (!empty($_REQUEST['edit_all_recurrences'])) {
137 $jsonData['edit_all_recurrences'] = 'true';
146 $this->view_object_map['jsonData'] = $jsonData;
153 protected function action_quickedit()
155 $this->view = 'quickedit';
157 if (!$this->retrieveCurrentBean('Detail')) {
161 $this->view_object_map['currentModule'] = $this->currentBean->module_dir;
162 $this->view_object_map['currentBean'] = $this->currentBean;
168 * Used for drag & drop
170 protected function action_reschedule()
172 $this->view = 'json';
176 if (!$this->retrieveCurrentBean('Save')) {
180 $_REQUEST['parent_name'] = $this->currentBean->parent_name;
182 $dateField = "date_start";
183 if ($this->currentBean->module_dir == "Tasks") {
184 $dateField = "date_due";
187 if (!empty($_REQUEST['calendar_style']) && $_REQUEST['calendar_style'] == "basic") {
188 list($tmp, $time) = explode(" ", $this->currentBean->$dateField);
189 list($date, $tmp) = explode(" ", $_REQUEST['datetime']);
190 $_REQUEST['datetime'] = $date . " " . $time;
192 $_POST[$dateField] = $_REQUEST['datetime'];
194 if ($this->currentBean->module_dir == "Tasks" && !empty($this->currentBean->date_start)) {
195 if ($GLOBALS['timedate']->fromUser($_POST['date_due'])->ts < $GLOBALS['timedate']->fromUser($this->currentBean->date_start)->ts) {
196 $this->view_object_map['jsonData'] = array(
198 'errorMessage' => $GLOBALS['mod_strings']['LBL_DATE_END_ERROR'],
205 require_once('include/formbase.php');
206 $this->currentBean = populateFromPost("", $this->currentBean);
207 $this->currentBean->save();
208 $this->currentBean->retrieve($_REQUEST['record']);
210 $this->view_object_map['jsonData'] = CalendarUtils::get_sendback_array($this->currentBean);
217 protected function action_remove()
219 $this->view = 'json';
221 if (!$this->retrieveCurrentBean('Delete')) {
225 if ($this->currentBean->module_dir == "Meetings" || $this->currentBean->module_dir == "Calls") {
226 if (!empty($_REQUEST['remove_all_recurrences']) && $_REQUEST['remove_all_recurrences']) {
227 CalendarUtils::markRepeatDeleted($this->currentBean);
231 $this->currentBean->mark_deleted($_REQUEST['record']);
233 $this->view_object_map['jsonData'] = array(
241 * Used for drag & drop resizing
243 protected function action_resize()
245 $this->view = 'json';
247 if (!$this->retrieveCurrentBean('Save')) {
251 require_once('include/formbase.php');
252 $this->currentBean = populateFromPost("", $this->currentBean);
253 $this->currentBean->save();
255 $this->view_object_map['jsonData'] = array(
262 * Retrieves current activity bean and checks access to action
264 * @param string $actionToCheck
265 * @return bool Result of check
267 protected function retrieveCurrentBean($actionToCheck = false)
269 $module = $_REQUEST['current_module'];
271 if (!empty($_REQUEST['record'])) {
272 $record = $_REQUEST['record'];
275 require_once("data/BeanFactory.php");
276 $this->currentBean = BeanFactory::getBean($module, $record);
278 if (!empty($actionToCheck)) {
279 if (!$this->currentBean->ACLAccess($actionToCheck)) {
280 $this->view = 'json';
284 $this->view_object_map['jsonData'] = $jsonData;
292 protected function action_getActivities()
294 $this->view = 'json';
296 if(!ACLController::checkAccess('Calendar', 'list', true)){
297 ACLController::displayNoAccess(true);
300 require_once('modules/Calendar/Calendar.php');
301 $cal = new Calendar($_REQUEST['view']);
303 if (in_array($cal->view, array('day', 'week', 'month'))){
304 $cal->add_activities($GLOBALS['current_user']);
306 } else if ($cal->view == 'shared') {
308 $sharedUser = new User();
309 foreach ($cal->shared_ids as $member) {
310 $sharedUser->retrieve($member);
311 $cal->add_activities($sharedUser);
314 $cal->load_activities();
315 $this->view_object_map['jsonData'] = $cal->items;