/** * Get array that will be sent back to ajax frontend * @param SugarBean $bean * @return array */ static function getBeanDataArray(SugarBean $bean) { if (isset($bean->parent_name) && isset($_REQUEST['parent_name'])) { $bean->parent_name = $_REQUEST['parent_name']; } $users = array(); if ($bean->object_name == 'Call') { $users = $bean->get_call_users(); } else { if ($bean->object_name == 'Meeting') { $users = $bean->get_meeting_users(); } } $user_ids = array(); foreach ($users as $u) { $user_ids[] = $u->id; } $field_list = CalendarUtils::get_fields(); $field_arr = array(); foreach ($field_list[$bean->module_dir] as $field) { if ($field == 'related_to') { $focus = BeanFactory::getBean($bean->parent_type, $bean->parent_id); $field_arr[$field] = $focus->name; } else { $field_arr[$field] = $bean->{$field}; } } $date_field = "date_start"; if ($bean->object_name == 'Task') { $date_field = "date_due"; } $arr = array('access' => 'yes', 'type' => strtolower($bean->object_name), 'module_name' => $bean->module_dir, 'user_id' => $GLOBALS['current_user']->id, 'detail' => 1, 'edit' => 1, 'name' => $bean->name, 'record' => $bean->id, 'users' => $user_ids); if (!empty($bean->repeat_parent_id)) { $arr['repeat_parent_id'] = $bean->repeat_parent_id; } $arr = array_merge($arr, $field_arr); $arr = array_merge($arr, CalendarUtils::get_time_data($bean)); return $arr; }
/** * Load activities data to array */ public function load_activities() { $field_list = CalendarUtils::get_fields(); foreach ($this->acts_arr as $user_id => $acts) { foreach ($acts as $act) { $item = array(); $item['user_id'] = $user_id; $item['module_name'] = $act->sugar_bean->module_dir; $item['type'] = strtolower($act->sugar_bean->object_name); $item['assigned_user_id'] = $act->sugar_bean->assigned_user_id; $item['record'] = $act->sugar_bean->id; $item['name'] = $act->sugar_bean->name; $item['description'] = $act->sugar_bean->description; if (isset($act->sugar_bean->duration_hours)) { $item['duration_hours'] = $act->sugar_bean->duration_hours; $item['duration_minutes'] = $act->sugar_bean->duration_minutes; } $item['detail'] = 0; $item['edit'] = 0; if ($act->sugar_bean->ACLAccess('DetailView')) { $item['detail'] = 1; } if ($act->sugar_bean->ACLAccess('Save')) { $item['edit'] = 1; } if (empty($act->sugar_bean->id)) { $item['detail'] = 0; $item['edit'] = 0; } if (!empty($act->sugar_bean->repeat_parent_id)) { $item['repeat_parent_id'] = $act->sugar_bean->repeat_parent_id; } if ($item['detail'] == 1) { if (isset($field_list[$item['module_name']])) { foreach ($field_list[$item['module_name']] as $field) { if (!isset($item[$field]) && isset($act->sugar_bean->{$field})) { $item[$field] = $act->sugar_bean->{$field}; if (empty($item[$field])) { $item[$field] = ""; } } } } } if (!empty($act->sugar_bean->parent_type) && !empty($act->sugar_bean->parent_id)) { $focus = BeanFactory::getBean($act->sugar_bean->parent_type, $act->sugar_bean->parent_id); // If the bean wasn't loaded, e.g. insufficient permissions if (!empty($focus)) { $item['related_to'] = $focus->name; } } if (!isset($item['duration_hours']) || empty($item['duration_hours'])) { $item['duration_hours'] = 0; } if (!isset($item['duration_minutes']) || empty($item['duration_minutes'])) { $item['duration_minutes'] = 0; } $item = array_merge($item, CalendarUtils::get_time_data($act->sugar_bean)); $this->items[] = $item; } } }
/** * Load activities data to array */ public function load_activities() { $field_list = CalendarUtils::get_fields(); foreach ($this->acts_arr as $user_id => $acts) { foreach ($acts as $act) { $item = array(); $item['user_id'] = $user_id; $item['module_name'] = $act->sugar_bean->module_dir; $item['type'] = strtolower($act->sugar_bean->object_name); $item['assigned_user_id'] = $act->sugar_bean->assigned_user_id; $item['record'] = $act->sugar_bean->id; $item['name'] = $act->sugar_bean->name; if (isset($act->sugar_bean->duration_hours)) { $item['duration_hours'] = $act->sugar_bean->duration_hours; $item['duration_minutes'] = $act->sugar_bean->duration_minutes; } $item['detail'] = 0; $item['edit'] = 0; if ($act->sugar_bean->ACLAccess('DetailView')) { $item['detail'] = 1; } if ($act->sugar_bean->ACLAccess('Save')) { $item['edit'] = 1; } if (empty($act->sugar_bean->id)) { $item['detail'] = 0; $item['edit'] = 0; } if (!empty($act->sugar_bean->repeat_parent_id)) { $item['repeat_parent_id'] = $act->sugar_bean->repeat_parent_id; } if ($item['detail'] == 1) { if (isset($field_list[$item['module_name']])) { foreach ($field_list[$item['module_name']] as $field) { if (!isset($item[$field])) { $item[$field] = $act->sugar_bean->{$field}; if (empty($item[$field])) { $item[$field] = ""; } } } } } if (!isset($item['duration_hours']) || empty($item['duration_hours'])) { $item['duration_hours'] = 0; } if (!isset($item['duration_minutes']) || empty($item['duration_minutes'])) { $item['duration_minutes'] = 0; } $item = array_merge($item, CalendarUtils::get_time_data($act->sugar_bean)); $this->items[] = $item; } } }
/** * Get javascript objects of activities to be displayed on calendar * @return string */ public function get_activities_js() { $field_list = CalendarUtils::get_fields(); $a_str = ""; $ft = true; foreach ($this->items as $act) { if (!$ft) { $a_str .= ","; } $a_str .= "{"; $a_str .= ' "type" : "' . $act["type"] . '", "module_name" : "' . $act["module_name"] . '", "record" : "' . $act["id"] . '", "user_id" : "' . $act["user_id"] . '", "timestamp" : "' . $act["timestamp"] . '", "time_start" : "' . $act["time_start"] . '", "record_name": "' . $act["name"] . '",' . ''; foreach ($field_list[$act['module_name']] as $field) { if (!isset($act[$field])) { $act[$field] = ""; } $a_str .= ' "' . $field . '" : "' . $act[$field] . '", '; } $a_str .= ' "detail" : "' . $act["detail"] . '", "edit" : "' . $act["edit"] . '" '; $a_str .= "}"; $ft = false; } return $a_str; }
/** * Load activities data to array */ public function load_activities() { $field_list = CalendarUtils::get_fields(); $i = 0; foreach ($this->acts_arr as $user_id => $acts) { if (isset($acts) && empty($acts)) { //if no calendar items we add the user to the list. if ($GLOBALS['current_user']->getPreference('calendar_display_shared_separate')) { //$this->items[ $item['user_id'] ][] = $item; $this->items[$user_id][] = array(); } else { $this->items[$GLOBALS['current_user']->id][] = array(); } continue; } foreach ($acts as $act) { $item = array(); $item['user_id'] = $user_id; $item['module_name'] = $act->sugar_bean->module_dir; $item['type'] = strtolower($act->sugar_bean->object_name); $item['assigned_user_id'] = $act->sugar_bean->assigned_user_id; $item['record'] = $act->sugar_bean->id; $item['name'] = $act->sugar_bean->name . ' ' . $act->sugar_bean->assigned_user_name; $item['description'] = $act->sugar_bean->description; if (isset($act->sugar_bean->duration_hours)) { $item['duration_hours'] = $act->sugar_bean->duration_hours; $item['duration_minutes'] = $act->sugar_bean->duration_minutes; } $item['detail'] = 0; $item['edit'] = 0; if ($act->sugar_bean->ACLAccess('DetailView')) { $item['detail'] = 1; } if ($act->sugar_bean->ACLAccess('Save')) { $item['edit'] = 1; } if (empty($act->sugar_bean->id)) { $item['detail'] = 0; $item['edit'] = 0; } if (!empty($act->sugar_bean->repeat_parent_id)) { $item['repeat_parent_id'] = $act->sugar_bean->repeat_parent_id; } if ($item['detail'] == 1) { if (isset($field_list[$item['module_name']])) { foreach ($field_list[$item['module_name']] as $field) { if (!isset($item[$field]) && isset($act->sugar_bean->{$field})) { $item[$field] = $act->sugar_bean->{$field}; if (empty($item[$field])) { $item[$field] = ""; } } } } } if (!empty($act->sugar_bean->parent_type) && !empty($act->sugar_bean->parent_id)) { $focus = BeanFactory::getBean($act->sugar_bean->parent_type, $act->sugar_bean->parent_id); // If the bean wasn't loaded, e.g. insufficient permissions if (!empty($focus)) { $item['related_to'] = $focus->name; } } if (!isset($item['duration_hours']) || empty($item['duration_hours'])) { $item['duration_hours'] = 0; } if (!isset($item['duration_minutes']) || empty($item['duration_minutes'])) { $item['duration_minutes'] = 0; } if (isset($this->activityList[$act->sugar_bean->module_name]['start']) && !empty($this->activityList[$act->sugar_bean->module_name]['start'])) { $item = array_merge($item, CalendarUtils::get_time_data($act->sugar_bean, $this->activityList[$act->sugar_bean->module_name]['start'], $this->activityList[$act->sugar_bean->module_name]['end'])); } else { $item = array_merge($item, CalendarUtils::get_time_data($act->sugar_bean)); } if ($GLOBALS['current_user']->getPreference('calendar_display_shared_separate')) { $this->items[$item['user_id']][] = $item; } else { $this->items[$GLOBALS['current_user']->id][] = $item; } } $i++; } }
function display() { require_once "modules/Calendar/CalendarUtils.php"; $field_list = CalendarUtils::get_fields(); global $beanFiles, $beanList; $module = $_REQUEST['current_module']; require_once $beanFiles[$beanList[$module]]; $bean = new $beanList[$module](); $type = strtolower($beanList[$module]); $table_name = $bean->table_name; if (!empty($_REQUEST['record'])) { $bean->retrieve($_REQUEST['record']); } if (!$bean->ACLAccess('Save')) { $json_arr = array('success' => 'no'); echo json_encode($json_arr); die; } require_once 'include/formbase.php'; $bean = populateFromPost("", $bean); if (!$_REQUEST['reminder_checked']) { $bean->reminder_time = -1; } if (empty($_REQUEST['record']) && strpos($_POST['user_invitees'], $bean->assigned_user_id) === false) { $_POST['user_invitees'] .= "," . $bean->assigned_user_id; } // fill invites and save the entry $this->save_activity($bean); if ($r_id = $bean->id) { $u = new User(); $u->retrieve($bean->assigned_user_id); $arr_rec = array(); $bean->retrieve($r_id); if (isset($bean->parent_name)) { $bean->parent_name = $_REQUEST['parent_name']; } $bean->fill_in_additional_parent_fields(); global $timedate; $date_field = "date_start"; if ($_REQUEST['current_module'] == "Tasks") { $date_field = "date_due"; } $timestamp = SugarDateTime::createFromFormat($GLOBALS['timedate']->get_date_time_format(), $bean->{$date_field}, new DateTimeZone('UTC'))->format('U'); if ($_REQUEST['current_module'] == 'Calls') { $users = $bean->get_call_users(); } if ($_REQUEST['current_module'] == 'Meetings') { $users = $bean->get_meeting_users(); } $user_ids = array(); foreach ($users as $u) { $user_ids[] = $u->id; } $field_arr = array(); foreach ($field_list[$_REQUEST['current_module']] as $field) { $field_arr[$field] = $bean->{$field}; if ($bean->field_defs[$field]['type'] == 'text') { $t = $field_arr[$field]; if (strlen($t) > 300) { $t = substr($t, 0, 300); $t .= "..."; } $t = str_replace("\r\n", "<br>", $t); $t = str_replace("\r", "<br>", $t); $t = str_replace("\n", "<br>", $t); $t = html_entity_decode($t, ENT_QUOTES); $field_arr[$field] = $t; } } $json_arr = array('success' => 'yes', 'type' => $type, 'module_name' => $bean->module_dir, 'user_id' => $GLOBALS['current_user']->id, 'detail' => 1, 'edit' => 1, 'record_name' => html_entity_decode($bean->name, ENT_QUOTES), 'record' => $bean->id, 'users' => $user_ids); $json_arr = array_merge($json_arr, $field_arr); $json_arr = array_merge($json_arr, CalendarUtils::get_time_data($bean)); } else { $json_arr = array('success' => 'no'); } ob_clean(); echo json_encode($json_arr); }