public function setup()
 {
     global $current_user;
     $current_user = SugarTestUserUtilities::createAnonymousUser();
     //for the purpose of this test, we need to create a campaign and relate it to a campaign tracker object
     //create campaign
     $c = new Campaign();
     $c->name = 'CT test ' . time();
     $c->campaign_type = 'Email';
     $c->status = 'Active';
     $timeDate = new TimeDate();
     $c->end_date = $timeDate->to_display_date(date('Y') + 1 . '-01-01');
     $c->assigned_id = $current_user->id;
     $c->team_id = '1';
     $c->team_set_id = '1';
     $c->save();
     $this->campaign = $c;
     //create campaign tracker
     $ct = new CampaignTracker();
     $ct->tracker_name = 'CampaignTrackerTest' . time();
     $ct->tracker_url = 'sugarcrm.com';
     $ct->campaign_id = $this->campaign->id;
     $ct->save();
     $this->campaign_tracker = $ct;
 }
Exemple #2
0
 /**
  * This function retrieves a record of the appropriate type from the DB.
  * It fills in all of the fields from the DB into the object it was called on.
  *
  * @param $id - If ID is specified, it overrides the current value of $this->id.  If not specified the current value of $this->id will be used.
  * @return this - The object that it was called apon or null if exactly 1 record was not found.
  *
  */
 function check_date_relationships_load()
 {
     global $disable_date_format;
     if (!empty($disable_date_format)) {
         return;
     }
     global $timedate;
     if (empty($timedate)) {
         $timedate = new TimeDate();
     }
     if (empty($this->field_defs)) {
         return;
     }
     foreach ($this->field_defs as $fieldDef) {
         $field = $fieldDef['name'];
         if (!isset($this->processed_dates_times[$field])) {
             $this->processed_dates_times[$field] = '1';
             if ($field == 'date_modified' || $field == 'date_entered') {
                 if (!empty($this->{$field})) {
                     $this->{$field} = $timedate->to_display_date_time($this->{$field});
                 }
             } elseif (!empty($this->{$field}) && isset($this->field_name_map[$field]['type'])) {
                 $type = $this->field_name_map[$field]['type'];
                 if ($type == 'relate' && isset($this->field_name_map[$field]['custom_module'])) {
                     $type = $this->field_name_map[$field]['type'];
                 }
                 if ($type == 'date') {
                     $this->{$field} = from_db_convert($this->{$field}, 'date');
                     if ($this->{$field} == '0000-00-00') {
                         $this->{$field} = '';
                     } elseif (!empty($this->field_name_map[$field]['rel_field'])) {
                         $rel_field = $this->field_name_map[$field]['rel_field'];
                         if (!empty($this->{$rel_field})) {
                             $this->{$rel_field} = from_db_convert($this->{$rel_field}, 'time');
                             $mergetime = $timedate->merge_date_time($this->{$field}, $this->{$rel_field});
                             $this->{$field} = $timedate->to_display_date($mergetime);
                             $this->{$rel_field} = $timedate->to_display_time($mergetime);
                         }
                     } else {
                         $this->{$field} = $timedate->to_display_date($this->{$field}, false);
                     }
                 } elseif ($type == 'datetime') {
                     if ($this->{$field} == '0000-00-00 00:00:00') {
                         $this->{$field} = '';
                     } else {
                         $this->{$field} = $timedate->to_display_date_time($this->{$field});
                     }
                 } elseif ($type == 'time') {
                     if ($this->{$field} == '00:00:00') {
                         $this->{$field} = '';
                     } else {
                         //$this->$field = from_db_convert($this->$field, 'time');
                         if (empty($this->field_name_map[$field]['rel_field'])) {
                             $this->{$field} = $timedate->to_display_time($this->{$field}, true, false);
                         }
                     }
                 } elseif ($type == 'encrypt') {
                     $this->{$field} = $this->decrypt_after_retrieve($this->{$field});
                 }
             }
         }
     }
 }
Exemple #3
0
 public function setUp()
 {
     $this->markTestIncomplete('Marking this skipped until we figure out why it is causing the SQL server connection to go away.');
     $this->clear_database = true;
     $this->remove_beans = true;
     $this->saved_current_user = $GLOBALS['current_user'];
     $user = new User();
     $user->retrieve('1');
     $GLOBALS['current_user'] = $user;
     $this->campaign = new Campaign();
     $this->campaign->name = 'Bug39665Test ' . time();
     $this->campaign->campaign_type = 'Email';
     $this->campaign->status = 'Active';
     $timeDate = new TimeDate();
     $this->campaign->end_date = $timeDate->to_display_date(date('Y') + 1 . '-01-01');
     $this->campaign->assigned_id = $user->id;
     $this->campaign->team_id = '1';
     $this->campaign->team_set_id = '1';
     $this->campaign->save();
     $this->emailmarketing = new EmailMarketing();
     $this->emailmarketing->name = $this->campaign->name . ' Email1';
     $this->emailmarketing->campaign_id = $this->campaign->id;
     $this->emailmarketing->from_name = 'SugarCRM';
     $this->emailmarketing->from_addr = '*****@*****.**';
     $this->emailmarketing->reply_to_name = 'SugarCRM';
     $this->emailmarketing->reply_to_addr = '*****@*****.**';
     $this->emailmarketing->status = 'active';
     $this->emailmarketing->all_prospect_lists = 1;
     $this->emailmarketing->date_start = $timeDate->to_display_date(date('Y') + 1 . '-01-01') . ' 00:00:00';
     $this->emailmarketing2 = new EmailMarketing();
     $this->emailmarketing2->name = $this->campaign->name . ' Email2';
     $this->emailmarketing2->campaign_id = $this->campaign->id;
     $this->emailmarketing2->from_name = 'SugarCRM';
     $this->emailmarketing2->from_addr = '*****@*****.**';
     $this->emailmarketing2->reply_to_name = 'SugarCRM';
     $this->emailmarketing2->reply_to_addr = '*****@*****.**';
     $this->emailmarketing2->status = 'active';
     $this->emailmarketing2->all_prospect_lists = 1;
     $this->emailmarketing2->date_start = $timeDate->to_display_date(date('Y') + 1 . '-01-01') . ' 00:00:00';
     $query = 'SELECT id FROM inbound_email WHERE deleted=0';
     $result = $GLOBALS['db']->query($query);
     while ($row = $GLOBALS['db']->fetchByAssoc($result)) {
         $this->emailmarketing->inbound_email_id = $row['id'];
         $this->emailmarketing2->inbound_email_id = $row['id'];
         break;
     }
     $query = 'SELECT id FROM email_templates WHERE deleted=0';
     while ($row = $GLOBALS['db']->fetchByAssoc($result)) {
         $this->emailmarketing->template_id = $row['id'];
         $this->emailmarketing2->template_id = $row['id'];
         break;
     }
     $this->emailmarketing->save();
     $this->emailmarketing2->save();
     $this->campaign->load_relationship('prospectlists');
     $this->prospectlist = new ProspectList();
     $this->prospectlist->name = $this->campaign->name . ' Prospect List1';
     $this->prospectlist->assigned_user_id = $GLOBALS['current_user']->id;
     $this->prospectlist->list_type = "default";
     $this->prospectlist->save();
     $this->campaign->prospectlists->add($this->prospectlist->id);
     $this->campaign->load_relationship('prospectlists');
     $this->prospectlist2 = new ProspectList();
     $this->prospectlist2->name = $this->campaign->name . ' Prospect List2';
     $this->prospectlist2->assigned_user_id = $GLOBALS['current_user']->id;
     $this->prospectlist2->list_type = "default";
     $this->prospectlist2->save();
     $this->campaign->prospectlists->add($this->prospectlist2->id);
     $campaign_log_states = array(0 => 'viewed', 1 => 'link', 2 => 'invalid email', 3 => 'send error', 4 => 'removed', 5 => 'blocked', 6 => 'lead', 7 => 'contact');
     for ($i = 0; $i < 10; $i++) {
         $contact = SugarTestContactUtilities::createContact();
         $contact->campaign_id = $this->campaign->id;
         $contact->email2 = 'contact' . mt_rand() . '@sugar.com';
         //Simulate a secondary email
         $contact->save();
         $contact->load_relationship('prospect_lists');
         $contact->prospect_lists->add($this->prospectlist->id);
         $contact->prospect_lists->add($this->prospectlist2->id);
         $this->create_campaign_log($this->campaign, $contact, $this->emailmarketing, $this->prospectlist, 'targeted');
         $this->create_campaign_log($this->campaign, $contact, $this->emailmarketing, $this->prospectlist, $campaign_log_states[mt_rand(0, 7)]);
         $this->create_campaign_log($this->campaign, $contact, $this->emailmarketing2, $this->prospectlist, 'targeted');
         $this->create_campaign_log($this->campaign, $contact, $this->emailmarketing2, $this->prospectlist, $campaign_log_states[mt_rand(0, 7)]);
     }
     for ($i = 0; $i < 10; $i++) {
         $lead = SugarTestLeadUtilities::createLead();
         $lead->campaign_id = $this->campaign->id;
         $lead->email2 = 'lead2' . mt_rand() . '@sugar.com';
         //Simulate a secondary email
         $lead->save();
         $lead->load_relationship('prospect_lists');
         $lead->prospect_lists->add($this->prospectlist->id);
         $lead->prospect_lists->add($this->prospectlist2->id);
         $this->create_campaign_log($this->campaign, $lead, $this->emailmarketing, $this->prospectlist, 'targeted');
         $this->create_campaign_log($this->campaign, $lead, $this->emailmarketing, $this->prospectlist, $campaign_log_states[mt_rand(0, 7)]);
         $this->create_campaign_log($this->campaign, $lead, $this->emailmarketing2, $this->prospectlist, 'targeted');
         $this->create_campaign_log($this->campaign, $lead, $this->emailmarketing2, $this->prospectlist, $campaign_log_states[mt_rand(0, 7)]);
     }
     //But wait, there's more... now we email the friggin thing to place it in the queue
     if ($this->campaign->db->dbType == 'oci8') {
     } else {
         $current_date = "'" . gmdate($GLOBALS['timedate']->get_db_date_time_format()) . "'";
     }
     //start scheduling now.....
     $emailmarketing_beans = array($this->emailmarketing, $this->emailmarketing2);
     foreach ($emailmarketing_beans as $marketing) {
         $mergedvalue = $GLOBALS['timedate']->merge_date_time($marketing->date_start, $marketing->time_start);
         if ($this->campaign->db->dbType == 'oci8') {
         } else {
             $send_date_time = "'" . $GLOBALS['timedate']->to_db_date($mergedvalue) . ' ' . $GLOBALS['timedate']->to_db_time($mergedvalue) . "'";
         }
         //find all prospect lists associated with this email marketing message.
         if ($marketing->all_prospect_lists == 1) {
             $query = "SELECT prospect_lists.id prospect_list_id from prospect_lists ";
             $query .= " INNER JOIN prospect_list_campaigns plc ON plc.prospect_list_id = prospect_lists.id";
             $query .= " WHERE plc.campaign_id='{$this->campaign->id}'";
             $query .= " AND prospect_lists.deleted=0";
             $query .= " AND plc.deleted=0";
             $query .= " AND prospect_lists.list_type!='test' AND prospect_lists.list_type not like 'exempt%'";
         } else {
             $query = "select email_marketing_prospect_lists.* FROM email_marketing_prospect_lists ";
             $query .= " inner join prospect_lists on prospect_lists.id = email_marketing_prospect_lists.prospect_list_id";
             $query .= " WHERE prospect_lists.deleted=0 and email_marketing_id = '{$marketing->id}' and email_marketing_prospect_lists.deleted=0";
             $query .= " AND prospect_lists.list_type!='test' AND prospect_lists.list_type not like 'exempt%'";
         }
         $result = $this->campaign->db->query($query);
         while (($row = $this->campaign->db->fetchByAssoc($result)) != null) {
             $prospect_list_id = $row['prospect_list_id'];
             //delete all messages for the current campaign and current email marketing message.
             $delete_emailman_query = "delete from emailman where campaign_id='{$this->campaign->id}' and marketing_id='{$marketing->id}' and list_id='{$prospect_list_id}'";
             $this->campaign->db->query($delete_emailman_query);
             $insert_query = "INSERT INTO emailman (date_entered, user_id, campaign_id, marketing_id,list_id, related_id, related_type, send_date_time";
             if ($this->campaign->db->dbType == 'oci8') {
             }
             $insert_query .= ')';
             $insert_query .= " SELECT {$current_date},'{$GLOBALS['current_user']->id}',plc.campaign_id,'{$marketing->id}',plp.prospect_list_id, plp.related_id, plp.related_type,{$send_date_time} ";
             if ($this->campaign->db->dbType == 'oci8') {
             }
             $insert_query .= "FROM prospect_lists_prospects plp ";
             $insert_query .= "INNER JOIN prospect_list_campaigns plc ON plc.prospect_list_id = plp.prospect_list_id ";
             $insert_query .= "WHERE plp.prospect_list_id = '{$prospect_list_id}' ";
             $insert_query .= "AND plp.deleted=0 ";
             $insert_query .= "AND plc.deleted=0 ";
             $insert_query .= "AND plc.campaign_id='{$this->campaign->id}'";
             if ($this->campaign->db->dbType == 'oci8') {
             }
             $this->campaign->db->query($insert_query);
         }
     }
 }
Exemple #4
0
 function action_get_end_date()
 {
     global $db, $timeDate;
     $timeDate = new TimeDate();
     $id = $_POST['task_id'];
     $lag = $_POST['lag'];
     //Get the end date of the projectTask in raw database format
     $query = "SELECT date_finish FROM project_task WHERE id = '{$id}'";
     $end_date = $db->getOne($query);
     //Add 1 day onto end date for first day of new task
     $start_date = date('Y-m-d', strtotime($end_date . ' + 1 days'));
     //Add lag onto start date
     $start_date = date('Y-m-d', strtotime($start_date . ' + ' . $lag . ' days'));
     echo $timeDate->to_display_date($start_date, true);
     die;
 }
Exemple #5
0
 public function draw($tasks)
 {
     global $mod_strings, $app_list_strings;
     // Instantiate the TimeDate Class
     $timeDate = new TimeDate();
     echo '<table id="Task_table" class="project_table_header">
             <tr class="disable_sort">
                 <td style="min-width:32px;" class="project_table_headings">' . $mod_strings['LBL_TASK_ID'] . '</td>
                 <td style="min-width:85px;" class="project_table_headings">' . $mod_strings['LBL_TASK_NAME'] . '</td>
                 <td style="min-width:100px;" class="project_table_headings">' . $mod_strings['LBL_PREDECESSORS'] . '</td>
                 <td style="min-width:100px;" class="project_table_headings">' . $mod_strings['LBL_START'] . '</td>
                 <td style="min-width:100px;" class="project_table_headings">' . $mod_strings['LBL_FINISH'] . '</td>
                 <td style="min-width:100px;" class="project_table_headings">' . $mod_strings['LBL_DURATION'] . '</td>
                 <td style="min-width:120px;" class="project_table_headings">' . $mod_strings['LBL_ASSIGNED_USER_ID'] . '</td>
                 <td style="min-width:48px;" class="project_table_headings">' . $mod_strings['LBL_PERCENT_COMPLETE'] . '</td>
                 <td style="min-width:80px;" class="project_table_headings">' . $mod_strings['LBL_MILESTONE_FLAG'] . '</td>
                 <td style="min-width:80px;" class="project_table_headings">' . $mod_strings['LBL_ACTUAL_DURATION'] . '</td>
                 <td style="min-width:30px;" class="project_table_headings"></td>
             </tr>
     ';
     $task_count = 0;
     if (!is_null($tasks)) {
         foreach ($tasks as $task) {
             //Get resources
             $project = new Project();
             $project->retrieve($task->project_id);
             //Get project resources (users & contacts)
             $resources1 = $project->get_linked_beans('project_users_1', 'User');
             $resources2 = $project->get_linked_beans('project_contacts_1', 'Contact');
             //Combine resources into array of objects
             $resource_array = array();
             foreach ($resources1 as $user) {
                 $resource = new stdClass();
                 $resource->id = $user->id;
                 $resource->name = $user->name;
                 $resource->type = 'user';
                 $resource_array[] = $resource;
             }
             foreach ($resources2 as $contact) {
                 $resource = new stdClass();
                 $resource->id = $contact->id;
                 $resource->name = $contact->name;
                 $resource->type = 'contact';
                 $resource_array[] = $resource;
             }
             echo '<tr class="row_sortable">
                     <td class="project_table_cells"><input class="order_number" name="order_number[]" rel="' . $task->id . '" type="hidden" value="' . $task->order_number . '" />' . $task->project_task_id . '</td>';
             if (ACLController::checkAccess('Project', 'edit', true)) {
                 echo '<td class="project_table_cells" ><span class="Task_name" ><a data = "' . $task->id . ',' . $task->predecessors . ',' . $task->relationship_type . ',' . $timeDate->to_display_date($task->date_start, true) . ',' . $task->duration . ',' . $task->duration_unit . ',' . $task->assigned_user_id . ',' . $task->milestone_flag . ',' . $task->percent_complete . ',' . $task->description . ',' . $task->actual_duration . '" onclick = "edit_task($(this));"title = "' . $mod_strings['LBL_TASK_TITLE'] . '" href = "#" > ' . $task->name . '</a ></span ></td>';
             } else {
                 echo '<td class="project_table_cells" ><span class="Task_name" >' . $task->name . '</span ></td>';
             }
             echo '<td class="project_table_cells">';
             foreach ($tasks as $predecessor) {
                 if ($predecessor->project_task_id == $task->predecessors) {
                     echo $predecessor->name;
                 }
             }
             echo '
                     </td>
                     <td class="project_table_cells">' . $timeDate->to_display_date($task->date_start, true) . '</td>
                     <td class="project_table_cells">' . $timeDate->to_display_date($task->date_finish, true) . '</td>
                     <td class="project_table_cells">' . $task->duration . ' ' . $app_list_strings['duration_unit_dom'][$task->duration_unit] . '</td>
                     <td style="min-width:105px;" class="project_table_cells" >';
             $rflag = '0';
             foreach ($resource_array as $resource) {
                 if ($resource->id == $task->assigned_user_id) {
                     if ($resource->type == 'user') {
                         echo '<a target="blank" href="index.php?module=Users&action=DetailView&record=' . $resource->id . '">' . $resource->name . '</a>';
                         $rflag = '1';
                     } elseif ($resource->type == 'contact') {
                         echo '<a target="blank" href="index.php?module=Contacts&action=DetailView&record=' . $resource->id . '">' . $resource->name . '</a>';
                         $rflag = '1';
                     }
                 }
             }
             if ($rflag == '0') {
                 echo $mod_strings['LBL_UNASSIGNED'];
             }
             if ($task->milestone_flag == '1') {
                 $checked = $app_list_strings['checkbox_dom']['1'];
             } else {
                 $checked = $app_list_strings['checkbox_dom']['2'];
             }
             echo '</td>
                     <td class="project_table_cells">' . $task->percent_complete . '</td>
                     <td class="project_table_cells">' . $checked . '</td>
                     <td class="project_table_cells">' . $task->actual_duration . '</td>
                     <td class="project_table_cells">
                         <span id="exportToPDFSpan">';
             if (ACLController::checkAccess('Project', 'delete', true)) {
                 echo '<button style = "height:20px;width:20px;" class="remove_button" value = "' . $task->id . '" class="gantt_button" > Delete Task </button >';
             } else {
                 echo '<button disabled="disabled" style = "height:20px;width:20px;" class="remove_button" value = "' . $task->id . '" class="gantt_button" > Delete Task </button >';
             }
             echo '</span>
                      </td>
                 </tr>';
             $task_count++;
         }
     }
     echo '</table>';
 }
 /**
  * test conversion from DB date to local date with TZ handling
  * @dataProvider dateTestSet
  */
 public function testToDisplayDateFormatsWithTz($db, $df, $tf, $tz, $display, $dbdate)
 {
     $this->_setPrefs($df, $tf, $tz);
     $result = $this->time_date->to_display_date($db, true);
     $this->assertEquals($this->_dateOnly($display), $this->_dateOnly($result), "Broken conversion for '{$df}' with date '{$dbdate}' and TZ {$tz}");
 }