Ejemplo n.º 1
0
 /**
  * Create a new reminder
  *
  * @param string $name The text that will appear in the reminder
  * @param int $time Unix timestamp
  * @param string $model_name Optional model name and model id so that the reminder links to the dialog.
  * @param int $model_id
  * @param int $vtime The time that will be displayed in the reminder
  * 
  * @return Reminder 
  */
 public static function newInstance($name, $time, $model_name = '', $model_id = 0, $vtime = null)
 {
     $r = new Reminder();
     $r->name = \GO\Base\Util\String::cut_string($name, 100);
     $r->time = $time;
     $r->vtime = $vtime;
     $r->model_type_id = \GO::getModel($model_name)->modelTypeId();
     $r->model_id = $model_id;
     $r->save();
     return $r;
 }
Ejemplo n.º 2
0
 /**
  * [saveModel]
  * @param  boolean $reminder [description]
  * @return [type]            [description]
  */
 protected function saveModel($reminder = false)
 {
     if (Input::get('id')) {
         $reminder = Reminder::find(Input::get('id'));
     }
     if (!$reminder) {
         $reminder = new Reminder();
     }
     //$load_company_model = $project->company;
     $reminder->project_id = Input::get('project_id');
     $reminder->user_id = Input::get('user_id');
     $reminder->description = Input::get('description');
     $reminder->save();
     return $reminder;
 }
Ejemplo n.º 3
0
 /**
  * Modifies a current reservation, setting new start and end times or deleting it
  * @param array $all_invited_users array of all invited users to be used for DB insertion
  * @param array $users_to_invite array of newly invited users to be used for invitation emails
  * @param array $users_to_remove array of users that will be removed from invitation/participating in this reservation
  * @param array $unchanged_users array of users who have no status change at all
  * @param array $resources_to_add array of additional resources to add to this reservation
  * @param array $resources_to_remove array of additional resources to remove from this reservation
  * @param bool $del whether to delete it or not
  * @param boolean $mod_recur whether to modify all recurring reservations in this group
  */
 function mod_res($users_to_invite, $users_to_remove, $unchanged_users, $resources_to_add, $resources_to_remove, $del, $mod_recur)
 {
     $recurs = array();
     $valid_resids = array();
     $this->type = RES_TYPE_MODIFY;
     $orig_start_date = $this->start_date;
     // Store the original dates because they will be changed if we repeat
     $orig_end_date = $this->end_date;
     $accept_code = $this->db->get_new_id();
     if ($del) {
         // First, check if this should be deleted
         $this->del_res($mod_recur, mktime(0, 0, 0));
         return;
     }
     if (!$this->is_blackout) {
         $this->check_perms();
         // Check permissions
         $this->check_min_max();
         // Check min/max reservation times
     }
     if ($this->check_startdate()) {
         $this->check_times();
         // Check valid times
     }
     $this->is_repeat = $mod_recur;
     // If the mod_recur flag is set, it must be a recurring reservation
     $dates = array();
     // First, modify the current reservation
     if ($this->has_errors()) {
         // Print any errors generated above and kill app
         $this->print_all_errors(true);
     }
     $reminder = new Reminder();
     $reminder->setDB(new ReminderDB());
     $tmp_valid = false;
     $this->is_pending = $this->resource->get_property('approval');
     if ($this->is_repeat) {
         // Check and place all recurring reservations
         $recurs = $this->db->get_recur_ids($this->parentid, mktime(0, 0, 0));
         for ($i = 0; $i < count($recurs); $i++) {
             $this->id = $recurs[$i]['resid'];
             // Load reservation data
             $this->start_date = $recurs[$i]['start_date'];
             if ($this->is_repeat) {
                 // End date will always be the same as the start date for recurring reservations
                 $this->end_date = $this->start_date;
             }
             $is_valid = $this->check_res($resources_to_add);
             // Check overlap (dont kill)
             if ($is_valid) {
                 $tmp_valid = true;
                 // Only one recurring needs to pass
                 $this->db->mod_res($this, $users_to_invite, $users_to_remove, $resources_to_add, $resources_to_remove, $accept_code);
                 // And place the reservation
                 if (!empty($this->reminderid)) {
                     $reminder->update($this, $this->reminder_minutes_prior);
                 } else {
                     if ($this->reminder_minutes_prior != 0 && empty($this->reminderid)) {
                         $reminder->save($this, $this->reminder_minutes_prior);
                     }
                 }
                 $dates[] = $this->start_date;
                 $valid_resids[] = $this->id;
                 CmnFns::write_log($this->word . ' ' . $this->id . ' modified.  machid:' . $this->get_machid() . ', dates:' . $this->start_date . ' - ' . $this->end_date . ', start:' . $this->start . ', end:' . $this->end, $this->memberid, $_SERVER['REMOTE_ADDR']);
             }
         }
     } else {
         if ($this->check_res($resources_to_add)) {
             // Check overlap
             $this->db->mod_res($this, $users_to_invite, $users_to_remove, $resources_to_add, $resources_to_remove, $accept_code);
             // And place the reservation
             if (!empty($this->reminderid)) {
                 $reminder->update($this, $this->reminder_minutes_prior);
             } else {
                 if ($this->reminder_minutes_prior != 0 && empty($this->reminderid)) {
                     $reminder->save($this, $this->reminder_minutes_prior);
                 }
             }
             $dates[] = $this->start_date;
             $valid_resids[] = $this->id;
         }
     }
     // Restore original reservation dates
     $this->start_date = $orig_start_date;
     $this->end_date = $orig_end_date;
     if ($this->has_errors()) {
         // Print any errors generated when adding the reservations
         $this->print_all_errors(!$this->is_repeat);
     }
     if (!$this->is_blackout) {
         // Notify the user if they want
         $this->send_email('e_mod', null, $unchanged_users);
     }
     // Send out invites, if needed
     if (!$this->is_pending && count($users_to_invite) > 0) {
         $this->invite_users($users_to_invite, $dates, $accept_code);
     }
     if (!$this->is_pending && count($users_to_remove) > 0) {
         $this->remove_users_email($users_to_remove, $dates);
     }
     if (!$this->is_repeat || $tmp_valid) {
         $this->print_success('modified', $dates);
     }
 }
Ejemplo n.º 4
0
 public function testMigratorGoingDownDueToVersionTarget()
 {
     SMigrator::up(dirname(__FILE__) . '/fixtures/migrate', 1);
     SMigrator::migrate(dirname(__FILE__) . '/fixtures/migrate', 0);
     $this->assertFalse(in_array('last_name', array_keys(SActiveRecord::connection()->columns('people'))));
     $this->assertFalse(SActiveStore::tableExists('reminders'));
     SMigrator::migrate(dirname(__FILE__) . '/fixtures/migrate');
     $this->assertEqual(2, SMigrator::currentVersion());
     SActiveStore::resetAttributeInformation('people');
     $this->assertTrue(in_array('last_name', array_keys(SActiveRecord::connection()->columns('people'))));
     $r = new Reminder(array('content' => 'hello world', 'remind_at' => SDateTime::today()));
     $r->save();
     $this->assertEqual('hello world', SActiveStore::findFirst('reminder')->content);
 }
 function update_prefs()
 {
     prepare_company_website_controller($this, 'account');
     $user = logged_user();
     if (!$user instanceof User) {
         flash_error(lang('user dnx'));
         $this->redirectTo('dashboard');
     }
     // if
     $company = $user->getCompany();
     if (!$company instanceof Company) {
         flash_error(lang('company dnx'));
         $this->redirectToReferer(get_url('administration'));
     }
     // if
     if (!$user->canUpdateProfile(logged_user())) {
         flash_error(lang('no access permissions'));
         $this->redirectTo('dashboard');
     }
     // if
     $redirect_to = array_var($_GET, 'redirect_to');
     if (trim($redirect_to) == '' || !is_valid_url($redirect_to)) {
         $redirect_to = $user->getCardUrl();
     }
     // if
     $this->setTemplate('edit_preferences');
     $reminder_prefs = Reminders::findById(logged_user()->getId());
     if (!$reminder_prefs instanceof Reminder) {
         $reminder_prefs = new Reminder();
     }
     $prefs_form = array_var($_POST, 'prefs_form');
     $reminder_prefs->setUserId(logged_user()->getId());
     $reminder_prefs->setRemindersEnabled($prefs_form['reminders_enabled']);
     $reminder_prefs->setSummarizedBy($prefs_form['summarized_by']);
     $reminder_prefs->setRemindersFuture($prefs_form['future']);
     $reminder_prefs->setIncludeEveryone($prefs_form['ivsteam']);
     $weekArray = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
     $days = '';
     for ($i = 0; $i < 7; $i++) {
         if (isset($prefs_form[$weekArray[$i]])) {
             $days .= "" . $weekArray[$i] . ",";
         }
     }
     $reminder_prefs->setReminderDaysToSend($days);
     $reminder_prefs->setReportsEnabled($prefs_form['reports_enabled']);
     $reminder_prefs->setReportsSummarizedBy($prefs_form['reports_summarized']);
     $reminder_prefs->setReportsIncludeEveryone($prefs_form['ivsteam2']);
     $reminder_prefs->setReportDay($prefs_form['reportDay']);
     $reminder_prefs->setReportsIncludeActivity($prefs_form['report_activity']);
     try {
         DB::beginWork();
         $reminder_prefs->save();
         DB::commit();
         flash_success(lang('prefs updated'));
     } catch (Exception $e) {
         DB::rollback();
         flash_error('Error: ' . $e);
     }
     $dayOfWeek = ConfigOptions::getByName('calendar_first_day_of_week');
     tpl_assign('dayOfWeek', $dayOfWeek->getValue());
     tpl_assign('redirect_to', $redirect_to);
     tpl_assign('user', $user);
     tpl_assign('company', $company);
     tpl_assign('reminder_prefs', $reminder_prefs);
 }
Ejemplo n.º 6
0
/**
 * Do daily taks
 *
 * @param void
 * @return null
 */
function system_handle_on_daily()
{
    ProjectObjectViews::cleanUp();
    $priorities_images = array(PRIORITY_URGENT => 'assets/images/icons/priority/urgent.png', PRIORITY_HIGHEST => 'assets/images/icons/priority/highest.gif', PRIORITY_HIGH => 'assets/images/icons/priority/high.gif', PRIORITY_NORMAL => 'assets/images/icons/priority/normal.gif', PRIORITY_LOW => 'assets/images/icons/priority/low.gif', PRIORITY_LOWEST => 'assets/images/icons/priority/lowest.gif', PRIORITY_HOLD => 'assets/images/icons/priority/hold.png', '-99' => 'assets/images/icons/priority/unknown.png');
    $pages = array();
    $link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
    mysql_select_db(DB_NAME);
    $sql = "select id, name from healingcrystals_project_objects where project_id='" . TASK_LIST_PROJECT_ID . "' and type='Page'";
    $result = mysql_query($sql, $link);
    while ($entry = mysql_fetch_assoc($result)) {
        list($name, ) = explode('-', $entry['name']);
        $name = trim($name);
        $pages[$name] = $entry['id'];
    }
    $current_time = time();
    $users = Users::findAll();
    foreach ($users as $user) {
        $flag = 1;
        $message = '';
        $name = $user->getName();
        if (array_key_exists($name, $pages)) {
            $page = new Page($pages[$name]);
            if ($page) {
                $sql = "select id from healingcrystals_project_objects where parent_id='" . $pages[$name] . "' and parent_type='Page' and type='Task' and completed_on is null and priority is null and created_on>='" . date('Y-m-d H:i:s', $current_time - 1 * 24 * 60 * 60) . "' order by created_on";
                $result = mysql_query($sql, $link);
                if (mysql_num_rows($result)) {
                    $show_task_list = true;
                } else {
                    $show_task_list = false;
                }
                if (date('N') == '1' || $show_task_list) {
                    $message .= '<style>
		.odd {background-color:#ffffff;}
		.even{background-color:#eeeeee;}
	</style>
	<table>
		<tr>
			<td colspan="3">Task List: ' . $name . '</td>
		</tr>
		<tr>
			<td align="center">Priority</td>
			<td>Task</td>
			<td>&nbsp;</td>
		</tr>';
                    $tasks = Tasks::findOpenByObject($page);
                    foreach ($tasks as $task) {
                        $message .= '
		<tr class="' . ($flag % 2 === 1 ? 'odd' : 'even') . '">
			<td valign="top" align="center"><img  src="http://projects.ffbh.org/public/' . $priorities_images[$task->getPriority()] . '"/></td>
			<td valign="top">' . $task->getName() . '</td>
			<td valign="top"><a href="' . $task->getViewUrl() . '">View</a></td>
		</tr>';
                        $flag++;
                    }
                    $message .= '
	</table>';
                    $subject = 'projects: healingcrystals.com Task list';
                    $headers = 'MIME-Version: 1.0' . "\r\n";
                    $headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
                    $headers .= 'From: FFBH Reminder <*****@*****.**>' . "\r\n";
                    mail($user->getEmail(), $subject, $message, $headers);
                }
            }
        }
    }
    $sql = "select po.id, cast(if( pom.recurring_period_type='D', DATE_ADD(po.due_on, interval pom.recurring_period day), if(pom.recurring_period_type='W', DATE_ADD(po.due_on, interval pom.recurring_period week), if(pom.recurring_period_type='M', DATE_ADD(po.due_on, interval pom.recurring_period month), null ) ) ) as Date) as next_due_date, cast(DATE_ADD(now(), interval 0 day) as Date) as cur_date, cast(if(isnull(pom.email_reminder_unit), null, if( pom.email_reminder_unit='D', DATE_ADD(po.due_on, interval pom.email_reminder_period day), if(pom.email_reminder_unit='W', DATE_ADD(po.due_on, interval pom.email_reminder_period week), if(pom.email_reminder_unit='M', DATE_ADD(po.due_on, interval pom.email_reminder_period month), null ) ) )\t) as Date) as reminder_date from healingcrystals_project_objects po inner join  healingcrystals_project_object_misc pom on po.id=pom.object_id where po.type='Task' and po.due_on is not null and po.due_on<=now() and po.completed_on is null and pom.recurring_period_condition='after_due_date' and if(pom.recurring_end_date is not null and pom.recurring_end_date!='0000-00-00', if(pom.recurring_end_date>=now(), 1, 0), 1)=1 having next_due_date=cur_date";
    $result = mysql_query($sql);
    while ($entry = mysql_fetch_assoc($result)) {
        $task = new Task($entry['id']);
        $action = $task->complete(new AnonymousUser('auto', '*****@*****.**'));
        if (!empty($entry['reminder_date']) && $entry['cur_date'] == $entry['reminder_date']) {
            $sql02 = "select id from " . TABLE_PREFIX . "project_objects where type='Task' and project_id='" . $task->getProjectId() . "' and milestone_id='" . $task->getMilestoneId() . "' and parent_id='" . $task->getParentId() . "' order by id desc limit 0, 1";
            $result02 = mysql_query($sql02);
            if (mysql_num_rows($result02)) {
                $info = mysql_fetch_assoc($result02);
                $recurring_task = new Task($info['id']);
                $parent = $recurring_task->getParent();
                $project = $recurring_task->getProject();
                $assignees = $recurring_task->getAssignees();
                $priorities = array(PRIORITY_HIGHEST => lang('Highest'), PRIORITY_HIGH => lang('High'), PRIORITY_NORMAL => lang('Normal'), PRIORITY_LOW => lang('Low'), PRIORITY_LOWEST => lang('Lowest'), PRIORITY_ONGOING => lang('Ongoing'), PRIORITY_HOLD => lang('Hold'));
                $due_date = $task->getDueOn();
                $due_date = date('m/d/Y', strtotime($due_date));
                $reminder_date = date('m/d/Y', strtotime($entry['reminder_date']));
                foreach ($assignees as $assignee) {
                    $assignees_string .= $assignee->getDisplayName() . ', ';
                }
                if (!empty($assignees_string)) {
                    $assignees_string = substr($assignees_string, 0, -2);
                } else {
                    $assignees_string = '--';
                }
                $reminders_sent = array();
                foreach ($assignees as $user) {
                    //if ($user->getEmail()=='*****@*****.**'){
                    $reminder = new Reminder();
                    $reminder->setAttributes(array('user_id' => $user->getId(), 'object_id' => $recurring_task->getId(), 'comment' => $comment));
                    $save = $reminder->save();
                    if ($save && !is_error($save)) {
                        $reminders_sent[] = $user->getDisplayName();
                        ApplicationMailer::send($user, 'system/reminder', array('reminded_by_name' => 'AutoReminder', 'reminded_by_url' => '', 'object_name' => $recurring_task->getName(), 'object_url' => $recurring_task->getViewUrl(), 'object_type' => strtolower($recurring_task->getType()), 'comment_body' => $comment, 'project_name' => $project->getName(), 'project_url' => $project->getOverviewUrl(), 'ticket_name' => $parent->getName(), 'ticket_url' => $parent->getViewUrl(), 'object_priority' => $priorities[(string) $recurring_task->getPriority()], 'object_due_date' => $due_date, 'object_reminder_date_n_time' => $reminder_date, 'object_assignees' => $assignees_string, 'task_mark_complete_url' => $recurring_task->getCompleteUrl() . '&auto=1', 'display_status_for_complete_url' => $recurring_task->is_action_request_task() ? '' : 'none'), $recurring_task);
                    }
                    //}
                }
            }
        }
    }
    mysql_close($link);
}
 /**
  * Create a new reminder
  *
  * @param void
  * @return null
  */
 function add()
 {
     $this->wireframe->print_button = false;
     $parent = ProjectObjects::findById($this->request->getId('parent_id'));
     if (!instance_of($parent, 'ProjectObject')) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     $project = $parent->getProject();
     if (!instance_of($project, 'Project')) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     $assignees = $parent->getAssignees();
     $subscribers = $parent->getSubscribers();
     $commenters = Comments::findCommenters($parent, $this->logged_user);
     $reminder_data = $this->request->post('reminder');
     if (!is_array($reminder_data)) {
         $who = 'user';
         if (is_foreachable($assignees)) {
             $who = 'assignees';
         } elseif (is_foreachable($subscribers)) {
             $who = 'subscribers';
         } elseif (is_foreachable($commenters)) {
             $who = 'commenters';
         }
         // if
         $reminder_data = array('who' => $who);
     }
     // if
     $this->smarty->assign(array('parent' => $parent, 'assignees' => $assignees, 'subscribers' => $subscribers, 'commenters' => $commenters, 'project_users' => ProjectUsers::findUserIdsByProject($project), 'reminder_data' => $reminder_data));
     if ($this->request->isSubmitted()) {
         $send_to_users = null;
         switch ($reminder_data['who']) {
             case 'assignees':
                 $send_to_users = $assignees;
                 break;
             case 'subscribers':
                 $send_to_users = $subscribers;
                 break;
             case 'commenters':
                 $send_to_users = $commenters;
                 break;
             case 'user':
                 $user_id = (int) array_var($reminder_data, 'user_id');
                 if ($user_id) {
                     $user = Users::findById($user_id);
                     if (instance_of($user, 'User')) {
                         $send_to_users = array($user);
                     }
                     // if
                 }
                 // if
                 break;
         }
         // switch
         // Do reminder
         if (is_foreachable($send_to_users)) {
             $comment = trim(array_var($reminder_data, 'comment'));
             if ($comment) {
                 require_once SMARTY_PATH . '/plugins/modifier.clickable.php';
                 require_once ANGIE_PATH . '/classes/htmlpurifier/init.php';
                 $comment = strip_tags(prepare_html($comment, true));
                 // make sure we have clean text
                 $comment = nl2br(smarty_modifier_clickable($comment));
                 // preserve breaklines and convert links
             }
             // if
             db_begin_work();
             $reminders_sent = array();
             foreach ($send_to_users as $user) {
                 $reminder = new Reminder();
                 $reminder->setAttributes(array('user_id' => $user->getId(), 'object_id' => $parent->getId(), 'comment' => $comment));
                 $reminder->setCreatedBy($this->logged_user);
                 $save = $reminder->save();
                 if ($save && !is_error($save)) {
                     $reminders_sent[] = $user->getDisplayName();
                     ApplicationMailer::send($user, 'system/reminder', array('reminded_by_name' => $this->logged_user->getDisplayName(), 'reminded_by_url' => $this->logged_user->getViewUrl(), 'object_name' => $parent->getName(), 'object_url' => $parent->getViewUrl(), 'object_type' => strtolower($parent->getType()), 'comment_body' => $comment, 'project_name' => $project->getName(), 'project_url' => $project->getOverviewUrl()), $parent);
                 }
                 // if
             }
             // foreach
             db_commit();
             $message = lang('Users reminded: :users', array('users' => implode(', ', $reminders_sent)));
             if ($this->request->get('skip_layout')) {
                 $this->renderText($message);
             } else {
                 flash_success($message);
                 $this->redirectToUrl($parent->getViewUrl());
             }
             // if
             // No reminders
         } else {
             if ($this->request->get('skip_layout')) {
                 $this->renderText(lang('0 users reminded'));
             } else {
                 flash_success('0 users reminded');
                 $this->redirectToUrl($parent->getViewUrl());
             }
             // if
         }
         // if
     }
     // if
 }
Ejemplo n.º 8
0
/**
 * Do hourly tasks
 *
 * @param void
 * @return null
 */
function system_handle_on_hourly()
{
    $cache =& Cache::instance();
    if (instance_of($cache->backend, 'CacheBackend')) {
        $cache->backend->cleanup();
    }
    // if
    //BOF:mod
    $time_current = $time_end = time() - 4 * 60 * 60;
    $time_start = $time_end - 60 * 60;
    $comment = 'Auto Reminder';
    $link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
    mysql_select_db(DB_NAME);
    //BOF:mod 20120816
    /*
    //EOF:mod 20120816
        $query = "select distinct a.object_id from 
                  healingcrystals_project_object_misc a 
                  inner join healingcrystals_project_objects b on a.object_id=b.id where 
                  b.type='Task' and 
                  b.state='" . STATE_VISIBLE . "' and 
                  (b.completed_on is null or b.completed_on='') and 
                  a.reminder_date is not null and 
                  a.reminder_date<>'0000-00-00' and 
                  a.auto_email_status='1' and 
                  ((a.reminder_date between '" . date('Y-m-d H:i:s', $time_start) . "' and '" . date('Y-m-d H:i:s', $time_end) . "')
                      or (a.recurring_period_type = 'D' and recurring_period = '1' and recurring_period_condition = 'after_due_date' and (recurring_end_date > '".date('Y-m-d')."' or recurring_end_date = '0000-00-00') and date_format(a.reminder_date,'%H:%i:%s') between '" . date('H:i:s', $time_start) . "' and '" . date('H:i:s', $time_end) . "'))";
        mysql_query("insert into testing (date_added, content) values (now(), '" . mysql_real_escape_string($query) . "')");
    //BOF:mod 20120816
    */
    /*
        $query = "select distinct a.object_id, a.reminder_date from 
                  healingcrystals_project_object_misc a 
                  inner join healingcrystals_project_objects b on a.object_id=b.id where 
                  b.type='Task' and 
                  b.state='" . STATE_VISIBLE . "' and 
                  (b.completed_on is null or b.completed_on='') and 
                  a.reminder_date is not null and 
                  a.reminder_date<>'0000-00-00' and 
                  a.auto_email_status='1' and 
                  ((a.reminder_date between '" . date('Y-m-d H:i:s', $time_start) . "' and '" . date('Y-m-d H:i:s', $time_end) . "')
                      or (a.recurring_period_type = 'D' and recurring_period = '1' and recurring_period_condition = 'after_due_date' and (recurring_end_date > '".date('Y-m-d')."' or recurring_end_date = '0000-00-00') and date_format(a.reminder_date,'%H:%i:%s') between '" . date('H:i:s', $time_start) . "' and '" . date('H:i:s', $time_end) . "'))";
    */
    $query = "select distinct \n\t\t\t\ta.object_id, \n\t\t\t\tcast(if(a.email_reminder_unit='D', \n\t\t\t\t\tconcat(DATE_SUB(b.due_on, interval a.email_reminder_period day), ' ', a.email_reminder_time), \n\t\t\t\t\tif(a.email_reminder_unit='W', \n\t\t\t\t\t\tconcat(DATE_SUB(b.due_on, interval a.email_reminder_period week), ' ', a.email_reminder_time), \n\t\t\t\t\t\tif(a.email_reminder_unit='M', \n\t\t\t\t\t\t\tconcat(DATE_SUB(b.due_on, interval a.email_reminder_period month), ' ', a.email_reminder_time), \n\t\t\t\t\t\t\tnull\n\t\t\t\t\t\t)\n\t\t\t\t\t)\n\t\t\t\t) as datetime) as reminder \n\t\t\t  from \n\t\t\t\thealingcrystals_project_object_misc a \n\t\t\t\tinner join healingcrystals_project_objects b on a.object_id=b.id \n\t\t\t  where \n\t\t\t\tb.type='Task' and \n\t\t\t\tb.state='" . STATE_VISIBLE . "' and \n\t\t\t\t(b.completed_on is null or b.completed_on='') and \n\t\t\t\ta.auto_email_status='1' and \n\t\t\t\ta.email_reminder_unit is not null and \n\t\t\t\tb.due_on is not null and \n\t\t\t\t(a.snooze_datetime is null or a.snooze_datetime='0000-00-00 00:00:00' or a.snooze_datetime<'" . date('Y-m-d H:i:s', $time_current) . "') and \n\t\t\t\tcast(if(a.email_reminder_unit='D', \n\t\t\t\t\tconcat(DATE_SUB(b.due_on, interval a.email_reminder_period day), ' ', a.email_reminder_time), \n\t\t\t\t\tif(a.email_reminder_unit='W', \n\t\t\t\t\t\tconcat(DATE_SUB(b.due_on, interval a.email_reminder_period week), ' ', a.email_reminder_time), \n\t\t\t\t\t\tif(a.email_reminder_unit='M', \n\t\t\t\t\t\t\tconcat(DATE_SUB(b.due_on, interval a.email_reminder_period month), ' ', a.email_reminder_time), \n\t\t\t\t\t\t\tnull\n\t\t\t\t\t\t)\n\t\t\t\t\t)\n\t\t\t\t) as datetime) between '" . date('Y-m-d H:i:s', $time_start) . "' and '" . date('Y-m-d H:i:s', $time_end) . "'\n\t\t\t  ";
    //EOF:mod 20120816
    $result = mysql_query($query, $link);
    while ($entry = mysql_fetch_assoc($result)) {
        $task_obj = new Task($entry['object_id']);
        $parent = $task_obj->getParent();
        $project = $task_obj->getProject();
        $assignees = $task_obj->getAssignees();
        //BOF:mod 20120816
        $priorities = array(PRIORITY_HIGHEST => lang('Highest'), PRIORITY_HIGH => lang('High'), PRIORITY_NORMAL => lang('Normal'), PRIORITY_LOW => lang('Low'), PRIORITY_LOWEST => lang('Lowest'), PRIORITY_ONGOING => lang('Ongoing'), PRIORITY_HOLD => lang('Hold'));
        $due_date = $task_obj->getDueOn();
        if (!empty($due_date) && $due_date != '0000-00-00') {
            $due_date = date('m/d/Y', strtotime($due_date));
        } else {
            $due_date = '--';
        }
        $reminder_date = $entry['reminder'];
        //$reminder_date = $entry['reminder_date'];
        if (!empty($reminder_date) && $reminder_date != '0000-00-00 00:00:00') {
            $reminder_date = date('m/d/Y H:i', strtotime($reminder_date));
        } else {
            $reminder_date = '--';
        }
        foreach ($assignees as $assignee) {
            $assignees_string .= $assignee->getDisplayName() . ', ';
        }
        if (!empty($assignees_string)) {
            $assignees_string = substr($assignees_string, 0, -2);
        } else {
            $assignees_string = '--';
        }
        //EOF:mod 20120816
        $reminders_sent = array();
        foreach ($assignees as $user) {
            //if ($user->getEmail()=='*****@*****.**'){
            $reminder = new Reminder();
            $reminder->setAttributes(array('user_id' => $user->getId(), 'object_id' => $task_obj->getId(), 'comment' => $comment));
            //$reminder->setCreatedBy($this->logged_user);
            $save = $reminder->save();
            if ($save && !is_error($save)) {
                $reminders_sent[] = $user->getDisplayName();
                ApplicationMailer::send($user, 'system/reminder', array('reminded_by_name' => 'AutoReminder', 'reminded_by_url' => '', 'object_name' => $task_obj->getName(), 'object_url' => $task_obj->getViewUrl(), 'object_type' => strtolower($task_obj->getType()), 'comment_body' => $comment, 'project_name' => $project->getName(), 'project_url' => $project->getOverviewUrl(), 'ticket_name' => $parent->getName(), 'ticket_url' => $parent->getViewUrl(), 'object_priority' => $priorities[(string) $task_obj->getPriority()], 'object_due_date' => $due_date, 'object_reminder_date_n_time' => $reminder_date, 'object_assignees' => $assignees_string, 'task_mark_complete_url' => $task_obj->getCompleteUrl() . '&auto=1', 'display_status_for_complete_url' => ''), $task_obj);
            }
            // if
            //}
        }
        // foreach
    }
    mysql_close($link);
    //EOF:mod
}