Exemplo n.º 1
0
 /**
  * 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;
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Save repeat activities
  * @param SugarBean $bean
  * @param array $timeArray array of datetimes
  * @return array
  */
 static function saveRecurring(SugarBean $bean, $timeArray)
 {
     // Here we will create single big inserting query for each invitee relationship
     // rather than using relationships framework due to performance issues.
     // Relationship framework runs very slowly
     $db = $GLOBALS['db'];
     $id = $bean->id;
     $date_modified = $GLOBALS['timedate']->nowDb();
     $lower_name = strtolower($bean->object_name);
     $qu = "SELECT * FROM {$bean->rel_users_table} WHERE deleted = 0 AND {$lower_name}_id = '{$id}'";
     $re = $db->query($qu);
     $users_rel_arr = array();
     // If the bean has a users_arr then related records for those ids will have
     // already been created. This prevents duplicates of those records for
     // users, contacts and leads (handled below)
     $exclude_users = empty($bean->users_arr) ? array() : array_flip($bean->users_arr);
     while ($ro = $db->fetchByAssoc($re)) {
         if (!isset($exclude_users[$ro['user_id']])) {
             $users_rel_arr[] = $ro['user_id'];
         }
     }
     $qu = "SELECT * FROM {$bean->rel_contacts_table} WHERE deleted = 0 AND {$lower_name}_id = '{$id}'";
     $re = $db->query($qu);
     $contacts_rel_arr = array();
     while ($ro = $db->fetchByAssoc($re)) {
         $contacts_rel_arr[] = $ro['contact_id'];
     }
     $qu = "SELECT * FROM {$bean->rel_leads_table} WHERE deleted = 0 AND {$lower_name}_id = '{$id}'";
     $re = $db->query($qu);
     $leads_rel_arr = array();
     while ($ro = $db->fetchByAssoc($re)) {
         $leads_rel_arr[] = $ro['lead_id'];
     }
     $qu_contacts = array();
     $qu_users = array();
     $qu_leads = array();
     $arr = array();
     $i = 0;
     Activity::disable();
     $clone = clone $bean;
     //this is a new bean being created - so throw away cloned fetched_row
     //attribute that incorrectly makes it look like an existing bean
     $clone->fetched_row = false;
     foreach ($timeArray as $date_start) {
         $clone->id = "";
         $clone->date_start = $date_start;
         // TODO CHECK DATETIME VARIABLE
         $date = SugarDateTime::createFromFormat($GLOBALS['timedate']->get_date_time_format(), $date_start);
         $date = $date->get("+{$bean->duration_hours} Hours")->get("+{$bean->duration_minutes} Minutes");
         $date_end = $date->format($GLOBALS['timedate']->get_date_time_format());
         $clone->date_end = $date_end;
         $clone->recurring_source = "Sugar";
         $clone->repeat_parent_id = $id;
         $clone->update_vcal = false;
         $clone->save(false);
         if ($clone->id) {
             foreach ($users_rel_arr as $user_id) {
                 $qu_users[] = array('id' => create_guid(), 'user_id' => $user_id, $lower_name . '_id' => $clone->id, 'date_modified' => $date_modified);
             }
             foreach ($contacts_rel_arr as $contact_id) {
                 $qu_contacts[] = array('id' => create_guid(), 'contact_id' => $contact_id, $lower_name . '_id' => $clone->id, 'date_modified' => $date_modified);
             }
             foreach ($leads_rel_arr as $lead_id) {
                 $qu_leads[] = array('id' => create_guid(), 'lead_id' => $lead_id, $lower_name . '_id' => $clone->id, 'date_modified' => $date_modified);
             }
             if ($i < 44) {
                 $clone->date_start = $date_start;
                 $clone->date_end = $date_end;
                 $arr[] = array_merge(array('id' => $clone->id), CalendarUtils::get_time_data($clone));
             }
             $i++;
         }
     }
     Activity::enable();
     if (!empty($qu_users)) {
         $fields = array('id' => array('name' => 'id', 'type' => 'id'), 'user_id' => array('name' => 'user_id', 'type' => 'id'), $lower_name . '_id' => array('name' => $lower_name . '_id', 'type' => 'id'), 'date_modified' => array('name' => 'date_modified', 'type' => 'datetime'));
         foreach ($qu_users as $qu_user) {
             $db->insertParams($bean->rel_users_table, $fields, $qu_user);
         }
     }
     if (!empty($qu_contacts)) {
         $fields = array('id' => array('name' => 'id', 'type' => 'id'), 'contact_id' => array('name' => 'contact_id', 'type' => 'id'), $lower_name . '_id' => array('name' => $lower_name . '_id', 'type' => 'id'), 'date_modified' => array('name' => 'date_modified', 'type' => 'datetime'));
         foreach ($qu_contacts as $qu_contact) {
             $db->insertParams($bean->rel_contacts_table, $fields, $qu_contact);
         }
     }
     if (!empty($qu_leads)) {
         $fields = array('id' => array('name' => 'id', 'type' => 'id'), 'lead_id' => array('name' => 'lead_id', 'type' => 'id'), $lower_name . '_id' => array('name' => $lower_name . '_id', 'type' => 'id'), 'date_modified' => array('name' => 'date_modified', 'type' => 'datetime'));
         foreach ($qu_leads as $qu_lead) {
             $db->insertParams($bean->rel_leads_table, $fields, $qu_lead);
         }
     }
     vCal::cache_sugar_vcal($GLOBALS['current_user']);
     return $arr;
 }
Exemplo n.º 3
0
 /**
  * Save repeat activities
  * @param SugarBean $bean
  * @param array $time_arr array of datetimes
  * @return array
  */
 static function save_repeat_activities(SugarBean $bean, $time_arr)
 {
     // Here we will create single big inserting query for each invitee relationship
     // rather than using relationships framework due to performance issues.
     // Relationship framework runs very slowly
     global $db;
     $id = $bean->id;
     $date_modified = $GLOBALS['timedate']->nowDb();
     $lower_name = strtolower($bean->object_name);
     $qu = "SELECT * FROM {$bean->rel_users_table} WHERE deleted = 0 AND {$lower_name}_id = '{$id}'";
     $re = $db->query($qu);
     $users_rel_arr = array();
     while ($ro = $db->fetchByAssoc($re)) {
         $users_rel_arr[] = $ro['user_id'];
     }
     $qu_users = "\n\t\t\t\tINSERT INTO {$bean->rel_users_table}\n\t\t\t\t(id,user_id,{$lower_name}_id,date_modified)\n\t\t\t\tVALUES\n\t\t";
     $users_filled = false;
     $qu = "SELECT * FROM {$bean->rel_contacts_table} WHERE deleted = 0 AND {$lower_name}_id = '{$id}'";
     $re = $db->query($qu);
     $contacts_rel_arr = array();
     while ($ro = $db->fetchByAssoc($re)) {
         $contacts_rel_arr[] = $ro['contact_id'];
     }
     $qu_contacts = "\n\t\t\t\tINSERT INTO {$bean->rel_contacts_table}\n\t\t\t\t(id,contact_id,{$lower_name}_id,date_modified)\n\t\t\t\tVALUES\n\t\t";
     $contacts_filled = false;
     $qu = "SELECT * FROM {$bean->rel_leads_table} WHERE deleted = 0 AND {$lower_name}_id = '{$id}'";
     $re = $db->query($qu);
     $leads_rel_arr = array();
     while ($ro = $db->fetchByAssoc($re)) {
         $leads_rel_arr[] = $ro['lead_id'];
     }
     $qu_leads = "\n\t\t\t\tINSERT INTO {$bean->rel_leads_table}\n\t\t\t\t(id,lead_id,{$lower_name}_id,date_modified)\n\t\t\t\tVALUES\n\t\t";
     $leads_filled = false;
     $arr = array();
     $i = 0;
     foreach ($time_arr as $date_start) {
         $clone = $bean;
         // we don't use clone keyword cause not necessary
         $clone->id = "";
         $clone->date_start = $date_start;
         // TODO CHECK DATETIME VARIABLE
         $date = SugarDateTime::createFromFormat($GLOBALS['timedate']->get_date_time_format(), $date_start);
         $date = $date->get("+{$bean->duration_hours} Hours")->get("+{$bean->duration_minutes} Minutes");
         $date_end = $date->format($GLOBALS['timedate']->get_date_time_format());
         $clone->date_end = $date_end;
         $clone->recurring_source = "Sugar";
         $clone->repeat_parent_id = $id;
         $clone->update_vcal = false;
         $clone->save(false);
         if ($clone->id) {
             foreach ($users_rel_arr as $user_id) {
                 if ($users_filled) {
                     $qu_users .= "," . PHP_EOL;
                 }
                 $qu_users .= "('" . create_guid() . "','{$user_id}','{$clone->id}','{$date_modified}')";
                 $users_filled = true;
             }
             foreach ($contacts_rel_arr as $contact_id) {
                 if ($contacts_filled) {
                     $qu_contacts .= "," . PHP_EOL;
                 }
                 $qu_contacts .= "('" . create_guid() . "','{$contact_id}','{$clone->id}','{$date_modified}')";
                 $contacts_filled = true;
             }
             foreach ($leads_rel_arr as $lead_id) {
                 if ($leads_filled) {
                     $qu_leads .= "," . PHP_EOL;
                 }
                 $qu_leads .= "('" . create_guid() . "','{$lead_id}','{$clone->id}','{$date_modified}')";
                 $leads_filled = true;
             }
             if ($i < 44) {
                 $clone->date_start = $date_start;
                 $clone->date_end = $date_end;
                 $arr[] = array_merge(array('id' => $clone->id), CalendarUtils::get_time_data($clone));
             }
             $i++;
         }
     }
     if ($users_filled) {
         $db->query($qu_users);
     }
     if ($contacts_filled) {
         $db->query($qu_contacts);
     }
     if ($leads_filled) {
         $db->query($qu_leads);
     }
     vCal::cache_sugar_vcal($GLOBALS['current_user']);
     return $arr;
 }
Exemplo n.º 4
0
 /**
  * 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;
         }
     }
 }
Exemplo n.º 5
0
 /**
  * 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['id'] = $act->sugar_bean->id;
             $item['name'] = $act->sugar_bean->name;
             $item['status'] = $act->sugar_bean->status;
             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 ($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 ($act->sugar_bean->field_defs[$field]['type'] == 'text') {
                                 $t = $item[$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);
                                 $item[$field] = $t;
                             }
                         }
                     }
                 }
             }
             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;
         }
     }
 }
Exemplo n.º 6
0
 /**
  * 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);
 }