Esempio n. 1
0
 /**
  * Action SaveActivity
  */
 protected function action_saveactivity()
 {
     $this->view = 'json';
     if (!$this->retrieveCurrentBean('Save')) {
         return;
     }
     $module = $this->currentBean->module_dir;
     $bean = $this->currentBean;
     if (empty($_REQUEST['edit_all_recurrences'])) {
         $repeat_fields = array('type', 'interval', 'count', 'until', 'dow', 'parent_id');
         foreach ($repeat_fields as $suffix) {
             unset($_POST['repeat_' . $suffix]);
         }
     } else {
         if (!empty($_REQUEST['repeat_type']) && !empty($_REQUEST['date_start'])) {
             $params = array('type' => $_REQUEST['repeat_type'], 'interval' => $_REQUEST['repeat_interval'], 'count' => $_REQUEST['repeat_count'], 'until' => $_REQUEST['repeat_until'], 'dow' => $_REQUEST['repeat_dow']);
             $repeatArr = CalendarUtils::build_repeat_sequence($_REQUEST['date_start'], $params);
             $limit = SugarConfig::getInstance()->get('calendar.max_repeat_count', 1000);
             if (count($repeatArr) > $limit - 1) {
                 ob_clean();
                 $jsonData = array('access' => 'yes', 'limit_error' => 'true', 'limit' => $limit);
                 $this->view_object_map['jsonData'] = $jsonData;
                 return;
             }
         }
     }
     $path = "modules/{$bean->module_dir}/{$bean->object_name}FormBase.php";
     if (!file_exists($path)) {
         $GLOBALS['log']->fatal("File {$bean->object_name}FormBase.php doesn't exist");
         sugar_cleanup(true);
     }
     require_once $path;
     $FBObjectName = "{$bean->object_name}FormBase";
     if (!class_exists($FBObjectName)) {
         $GLOBALS['log']->fatal("Class {$bean->object_name}FormBase doesn't exist");
         sugar_cleanup(true);
     }
     $formBase = new $FBObjectName();
     $bean = $formBase->handleSave('', false, false);
     unset($_REQUEST['send_invites'], $_POST['send_invites']);
     // prevent invites sending for recurring activities
     if ($record = $bean->id) {
         if ($module == "Meetings" || $module == "Calls") {
             if (!empty($_REQUEST['edit_all_recurrences'])) {
                 CalendarUtils::markRepeatDeleted($bean);
             }
             if (isset($repeatArr) && is_array($repeatArr) && count($repeatArr) > 0) {
                 $repeatCreated = CalendarUtils::save_repeat_activities($bean, $repeatArr);
             }
         }
         $bean->retrieve($record);
         $jsonData = CalendarUtils::get_sendback_array($bean);
         if (isset($repeatCreated) && is_array($repeatCreated)) {
             $jsonData = array_merge($jsonData, array('repeat' => $repeatCreated));
         }
         if (!empty($_REQUEST['edit_all_recurrences'])) {
             $jsonData['edit_all_recurrences'] = 'true';
         }
     } else {
         $jsonData = array('access' => 'no');
     }
     $this->view_object_map['jsonData'] = $jsonData;
 }