/**
 * Show the last comment by user and date of the object
 *
 * Parameters:
 * 
 * - object - object
 * 
 * @param array $params
 * @param Smarty $smarty
 * @return string
 */
function smarty_function_object_last_comment($params, &$smarty)
{
    $object = array_var($params, 'object');
    if (!instance_of($object, 'ProjectObject')) {
        return new InvalidParamError('object', $object, '$object is not valid instance of ProjectObject class', true);
    }
    // if
    $resp = '';
    $link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
    mysql_select_db(DB_NAME);
    //BOF:mod 20111104
    /*
    //EOF:mod 20111104
    	$query = "select created_by_id, created_on from healingcrystals_project_objects where parent_id='" . $object->getId() . "' and type='Comment' order by created_on desc limit 0, 1";
    //BOF:mod 20111104
    */
    $query = "select created_by_id, created_on from healingcrystals_project_objects where parent_id='" . $object->getId() . "' and type='Comment' and state='" . STATE_VISIBLE . "' order by created_on desc limit 0, 1";
    //EOF:mod 20111104
    $result = mysql_query($query, $link);
    if (mysql_num_rows($result)) {
        $info = mysql_fetch_assoc($result);
        if (!empty($info['created_by_id'])) {
            $created_on = strtotime($info['created_on']);
            //BOF:mod 20111215
            $offset = get_system_gmt_offset();
            $created_on += $offset;
            //EOF:mod 20111215
            $user_obj = new User($info['created_by_id']);
            //BOF:mod 20111215
            /*
            //EOF:mod 20111215
            $resp = ' <a href="' . $user_obj->getViewUrl() . '">' . $user_obj->getFirstName() . '</a> ' . date('m-d', strtotime($created_on)) . ' ';
            //BOF:mod 20111215
            */
            $resp = ' <a href="' . $user_obj->getViewUrl() . '">' . $user_obj->getFirstName() . '</a> ' . date('m-d', $created_on) . ' ';
            //EOF:mod 20111215
            unset($user_obj);
        } else {
            $resp = '--';
        }
    } else {
        $resp = '--';
    }
    mysql_close($link);
    return $resp;
}
 function snoozereminder()
 {
     $snooze = $this->request->post('snooze');
     $link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
     mysql_select_db(DB_NAME);
     if ($snooze) {
         /*mysql_query("update healingcrystals_project_object_misc set snooze_duration='" . (int)$snooze['duration'] . "', snooze_unit='" . $snooze['unit'] . "' where object_id='" . $this->active_task->getId() . "'");
         		$query = "select reminder_date from healingcrystals_project_object_misc where object_id='" . $this->active_task->getId() . "'";
         		$result = mysql_query($query);
         		if (mysql_num_rows($result)){
         			$info = mysql_fetch_assoc($result);
         			if (!empty($info['reminder_date']) && $info['reminder_date']!='0000-00-00 00:00:00'){
         				$base_date = strtotime($info['reminder_date']);
         				$modified_date = '';
         				if ($snooze['duration']>0){
         					switch($snooze['unit']){
         						case 'H':
         							$modified_date = strtotime('+ ' . $snooze['duration'] . ' hours', $base_date);
         							break;
         						case 'D':
         							$modified_date = strtotime('+ ' . $snooze['duration'] . ' days', $base_date);
         							break;
         						case 'W':
         							$modified_date = strtotime('+ ' . $snooze['duration'] . ' weeks', $base_date);
         							break;
         						case 'M':
         							$modified_date = strtotime('+ ' . $snooze['duration'] . ' months', $base_date);
         							break;
         					}
         					if (!empty($modified_date)){
         						mysql_query("update healingcrystals_project_object_misc set reminder_date='" . date('Y-m-d H:i:s', $modified_date) . "' where object_id='" . $this->active_task->getId() . "'");
         					}
         				}
         			}
         		}*/
         //$query = mysql_query("select now() as cur_time");
         //$info = mysql_fetch_assoc($query);
         //$base_date = strtotime($info['cur_time']);
         $base_date = new DateTimeValue();
         $base_date->advance(get_system_gmt_offset($this->logged_user), true);
         //$base_date->advance(get_user_gmt_offset($this->logged_user), true);
         $modified_date = '';
         if ($snooze['duration'] > 0) {
             switch ($snooze['unit']) {
                 case 'I':
                     $modified_date = strtotime('+ ' . $snooze['duration'] . ' minutes', $base_date->getTimestamp());
                     break;
                 case 'H':
                     $modified_date = strtotime('+ ' . $snooze['duration'] . ' hours', $base_date->getTimestamp());
                     break;
                 case 'D':
                     $modified_date = strtotime('+ ' . $snooze['duration'] . ' days', $base_date->getTimestamp());
                     break;
                 case 'W':
                     $modified_date = strtotime('+ ' . $snooze['duration'] . ' weeks', $base_date->getTimestamp());
                     break;
                 case 'M':
                     $modified_date = strtotime('+ ' . $snooze['duration'] . ' months', $base_date->getTimestamp());
                     break;
             }
             if (!empty($modified_date)) {
                 $sql = "select object_id from " . TABLE_PREFIX . "project_object_misc where object_id='" . $this->active_task->getId() . "'";
                 $result = mysql_query($sql);
                 if (mysql_num_rows($result)) {
                     mysql_query("update healingcrystals_project_object_misc set last_modified=now(),  snooze_datetime='" . date('Y-m-d H:i:s', $modified_date) . "' where object_id='" . $this->active_task->getId() . "'");
                 } else {
                     mysql_query("insert into " . TABLE_PREFIX . "project_object_misc (object_id, date_added, snooze_datetime) values ('" . $this->active_task->getId() . "', now(), '" . date('Y-m-d H:i:s', $modified_date) . "')");
                 }
             }
         }
         $this->redirectToUrl($this->active_task->getViewUrl() . '#task' . $this->active_task->getId());
     } else {
         /*$snooze = array('duration' => '', 'unit' => '');
         		$result = mysql_query("select snooze_duration, snooze_unit from healingcrystals_project_object_misc where object_id='" . $this->active_task->getId() . "'");
         		if (mysql_num_rows($result)){
         			$info = mysql_fetch_assoc($result);
         			if (!empty($info['snooze_duration'])) $snooze['duration'] = $info['snooze_duration'];
         			if (!empty($info['snooze_unit'])) $snooze['unit'] = $info['snooze_unit'];
         		}*/
         $snooze_date = 'Not Set';
         $result = mysql_query("select snooze_datetime from healingcrystals_project_object_misc where object_id='" . $this->active_task->getId() . "'");
         if (mysql_num_rows($result)) {
             $info = mysql_fetch_assoc($result);
             if (!empty($info['snooze_datetime'])) {
                 $snooze_date = date('m-d-Y H:i', strtotime($info['snooze_datetime']));
             }
         }
     }
     mysql_close($link);
     $this->smarty->assign(array('form_action_url' => assemble_url('project_task_snoozereminder', array('project_id' => $this->active_project->getId(), 'task_id' => $this->active_task->getId())), 'snooze_date' => $snooze_date));
 }
Exemplo n.º 3
0
/**
 * Return user GMT offset
 *
 * Return number of seconds that current user is away from the GMT. If user is
 * not logged in this function should return system offset
 *
 * @param User $user
 * @return integer
 */
function get_user_gmt_offset($user = null)
{
    static $offset = array();
    if (!instance_of($user, 'User')) {
        $user = get_logged_user();
    }
    // if
    if (!instance_of($user, 'User')) {
        return get_system_gmt_offset();
    }
    // if
    if (!isset($offset[$user->getId()])) {
        $timezone_offset = UserConfigOptions::getValue('time_timezone', $user);
        $dst = UserConfigOptions::getValue('time_dst', $user);
        $offset[$user->getId()] = $dst ? $timezone_offset + 3600 : $timezone_offset;
    }
    // if
    return $offset[$user->getId()];
}
Exemplo n.º 4
0
 /**
  * Return user GMT offset
  * 
  * Return number of seconds that current user is away from the GMT. If user is 
  * not logged in this function should return system offset
  *
  * @param void
  * @return integer
  */
 function get_user_gmt_offset()
 {
     return get_system_gmt_offset();
 }