This class provides some handy methods for working with timestamps and extracting data from them
Inheritance: extends DateValue
 function ExecuteQuery()
 {
     $this->data = array();
     $parameters = $this->getParameters();
     $this->acum = 0;
     $this->acumExec = 0;
     foreach ($parameters as $p) {
         $value = $p->getValue();
         $id = $p->getId();
         $series = 0;
         if ($id > 1000) {
             $series = 1;
             $id = $id % 1000;
             $this->acum += (int) $value;
         } else {
             $this->acumExec += (int) $value;
         }
         $date = new DateTimeValue(mktime(12, 0, 0, $id, 1, 2008));
         $this->data['values'][$series]['labels'][] = $date->format("F");
         $this->data['values'][$series]['values'][] = (int) $value;
     }
     // foreach
     $this->data['values'][0]['name'] = lang('executed');
     $this->data['values'][1]['name'] = lang('budgeted');
 }
/**
*
* @param array $params
* @param Smarty $smarty
* @return string
*/
function smarty_function_reminder($params, &$smarty)
{
    $object = array_var($params, 'object');
    $reminder_date = null;
    if (instance_of($object, 'ProjectObject')) {
        if ($object->isCompleted()) {
            return '';
        }
        // if
        $link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
        mysql_select_db(DB_NAME, $link);
        $query = "select reminder_date from healingcrystals_project_object_misc where object_id='" . $object->getId() . "'";
        $result = mysql_query($query);
        if (mysql_num_rows($result)) {
            $info = mysql_fetch_assoc($result);
            if (!empty($info['reminder_date'])) {
                $reminder_date = DateTimeValue::makeFromString($info['reminder_date']);
            }
        }
        mysql_close($link);
    } else {
        return new InvalidParamError('object', $object, '$object is not expected to be an instance of ProjectObject', true);
    }
    // if
    $offset = get_user_gmt_offset();
    if (instance_of($reminder_date, 'DateTimeValue')) {
        require_once SMARTY_PATH . '/plugins/modifier.datetime.php';
        $date = smarty_modifier_datetime($reminder_date, 0);
        // just printing date, offset is 0!
        if ($reminder_date->isToday($offset)) {
            return '<span class="today"><span class="number">Reminder set for: ' . lang('Today') . ' ' . date('h:i A', $reminder_date->getTimestamp()) . '</span></span>';
        } elseif ($reminder_date->isYesterday($offset)) {
            return '<span class="late" title="' . clean($date) . '">Reminder set for: ' . lang('<span class="number">Yesterday ' . date('h:i A', $reminder_date->getTimestamp()) . '</span>') . '</span>';
        } elseif ($reminder_date->isTomorrow($offset)) {
            return '<span class="upcoming" title="' . clean($date) . '">Reminder set for: <span class="number">' . lang('Tomorrow') . ' ' . date('h:i A', $reminder_date->getTimestamp()) . '</span></span>';
        } else {
            $now = new DateTimeValue();
            $now->advance($offset);
            $now = $now->beginningOfDay();
            $reminder_date->beginningOfDay();
            if ($reminder_date->getTimestamp() > $now->getTimestamp()) {
                return '<span class="upcoming" title="' . clean($date) . '">Reminder set for: ' . date('F d, Y h:i A', $reminder_date->getTimestamp()) . lang(' (<span class="number">:days</span> Days)', array('days' => floor(($reminder_date->getTimestamp() - $now->getTimestamp()) / 86400))) . '</span>';
            } else {
                return '<span class="late" title="' . clean($date) . '">Reminder set for: ' . date('F d, Y h:i A', $reminder_date->getTimestamp()) . lang(' (<span class="number">:days</span> Days Late)', array('days' => floor(($now->getTimestamp() - $reminder_date->getTimestamp()) / 86400))) . '</span>';
            }
            // if
        }
        // if
    } else {
        return '';
    }
    // if
}
Ejemplo n.º 3
0
/**
 * Return '*** ago' message
 *
 * @param DateTimeValue $input
 * @param integer $offset
 * @return string
 */
function smarty_modifier_ago($input, $offset = null)
{
    if (!instance_of($input, 'DateValue')) {
        return '<span class="ago">' . lang('-- Unknown --') . '</span>';
    }
    // if
    if ($offset === null) {
        $offset = get_user_gmt_offset();
    }
    // if
    $datetime = new DateTimeValue($input->getTimestamp() + $offset);
    $reference = new DateTimeValue(time() + $offset);
    $diff = $reference->getTimestamp() - $datetime->getTimestamp();
    // Get exact number of seconds between current time and yesterday morning
    $reference_timestamp = $reference->getTimestamp();
    $yesterday_begins_at = 86400 + date('G', $reference_timestamp) * 3600 + date('i', $reference_timestamp) * 60 + date('s', $reference_timestamp);
    if ($diff < 60) {
        $value = lang('Few seconds ago');
    } elseif ($diff < 120) {
        $value = lang('A minute ago');
    } elseif ($diff < 3600) {
        $value = lang(':num minutes ago', array('num' => floor($diff / 60)));
    } elseif ($diff < 7200) {
        $value = lang('An hour ago');
    } elseif ($diff < 86400) {
        if (date('j', $datetime->getTimestamp()) != date('j', $reference->getTimestamp())) {
            $value = lang('Yesterday');
        } else {
            $mod = $diff % 3600;
            if ($mod < 900) {
                $value = lang(':num hours ago', array('num' => floor($diff / 3600)));
            } elseif ($mod > 2700) {
                $value = lang(':num hours ago', array('num' => ceil($diff / 3600)));
            } else {
                $value = lang(':num and a half hours ago', array('num' => floor($diff / 3600)));
            }
            // if
        }
        // if
    } elseif ($diff <= $yesterday_begins_at) {
        $value = lang('Yesterday');
    } elseif ($diff < 2592000) {
        $value = lang(':num days ago', array('num' => floor($diff / 86400)));
    } else {
        require_once SMARTY_PATH . '/plugins/modifier.date.php';
        require_once SMARTY_PATH . '/plugins/modifier.datetime.php';
        return '<span class="ago" title="' . clean(smarty_modifier_datetime($datetime, 0)) . '">' . lang('On') . ' ' . smarty_modifier_date($datetime, 0) . '</span>';
    }
    // if
    require_once SMARTY_PATH . '/plugins/modifier.datetime.php';
    return '<span class="ago" title="' . clean(smarty_modifier_datetime($datetime, 0)) . '">' . $value . '</span>';
}
Ejemplo n.º 4
0
	function cvs_total_task_times_table($objects, $pad_str, $options, $group_name, &$sub_total = 0) {
		
		echo lang('date') . ';';
		echo lang('title') . ';';
		echo lang('description') . ';';
		echo lang('person') . ';';
		echo lang('time') .'('.lang('hours').')'. ';';
		echo "\n";
		
		$sub_total = 0;
		
		foreach ($objects as $ts) {
			echo $pad_str . format_date($ts->getStartTime()) . ';';
			
			$name = ($ts->getRelObjectId() == 0 ? $ts->getObjectName() : $ts->getRelObject()->getObjectName());
			$name = str_replace("\r", " ", str_replace("\n", " ", str_replace("\r\n", " ", $name)));
			echo $name . ';';
			
			$desc = $ts->getDescription();
			$desc = str_replace("\r", " ", str_replace("\n", " ", str_replace("\r\n", " ", $desc)));
			$desc = '"'.$desc.'"';
			echo $desc .';';
			
			echo ($ts->getUser() instanceof Contact ? $ts->getUser()->getObjectName() : '') .';';
			$lastStop = $ts->getEndTime() != null ? $ts->getEndTime() : ($ts->isPaused() ? $ts->getPausedOn() : DateTimeValueLib::now());
			$mystring = DateTimeValue::FormatTimeDiff($ts->getStartTime(), $lastStop, "m", 60, $ts->getSubtract());
			$resultado = ereg_replace("[^0-9]", "", $mystring);
			$resultado = round(($resultado/60),5);
			echo $resultado;
			$sub_total += $resultado;
			echo "\n";
		}
	}
Ejemplo n.º 5
0
  		function ExecuteQuery(){
  			$this->data = array();
  			$parameters = $this->getParameters();
			
	    	foreach ($parameters as $p){
	    		$value = $p->getValue();
	    		$date = new DateTimeValue(mktime(12,0,0,$p->getId(),1,2008));
	    		$this->data['values'][0]['labels'][] = $date->format("F");
	    		$this->data['values'][0]['values'][] =  (int)$value;
	    		$this->data['values'][1]['labels'][] = $date->format("F");
	    		$this->data['values'][1]['values'][] =  10000;
	    	} // foreach
	    	
	    	$this->data['values'][0]['name'] = lang('current');
	    	$this->data['values'][1]['name'] = lang('budgeted');
  		}
Ejemplo n.º 6
0
 function ExecuteQuery()
 {
     $this->data = array();
     $date = new DateTimeValue(Time());
     $notYet = ProjectTasks::findAll(array('conditions' => 'created_by_id = ' . logged_user()->getId() . ' AND ( due_date = \'0000-00-00 00:00:00\' OR due_date > \'' . substr($date->toMySQL(), 0, strpos($date->toMySQL(), ' ')) . "')"));
     $today = ProjectTasks::findAll(array('conditions' => 'created_by_id = ' . logged_user()->getId() . ' AND due_date = \'' . substr($date->toMySQL(), 0, strpos($date->toMySQL(), ' ')) . "'"));
     $past = ProjectTasks::findAll(array('conditions' => 'created_by_id = ' . logged_user()->getId() . ' AND due_date > \'1900-01-01 00:00:00\' AND due_date < \'' . substr($date->toMySQL(), 0, strpos($date->toMySQL(), ' ')) . "'"));
     $value = 0;
     if (isset($past)) {
         $value = count($past);
     }
     $this->data['values'][0]['labels'][] = 'Overdue';
     $this->data['values'][0]['values'][] = $value;
     $value = 0;
     if (isset($notYet)) {
         $value = count($notYet);
     }
     $this->data['values'][0]['labels'][] = 'Not yet due';
     $this->data['values'][0]['values'][] = $value;
     $value = 0;
     if (isset($today)) {
         $value = count($today);
     }
     $this->data['values'][0]['labels'][] = 'Due today';
     $this->data['values'][0]['values'][] = $value;
 }
 /**
  * Index
  *
  * @param voi
  * @return null
  */
 function index()
 {
     require_once CALENDAR_MODULE_PATH . '/models/generators/ProjectCalendarGenerator.class.php';
     $today = new DateTimeValue(time() + get_user_gmt_offset());
     if ($this->request->get('month') && $this->request->get('year')) {
         $month = $this->request->get('month');
         $year = $this->request->get('year');
     } else {
         $month = $today->getMonth();
         $year = $today->getYear();
     }
     // if
     $first_weekday = UserConfigOptions::getValue('time_first_week_day', $this->logged_user);
     $generator = new ProjectCalendarGenerator($month, $year, $first_weekday);
     $generator->setProject($this->active_project);
     $generator->setData(Calendar::getProjectData($this->logged_user, $this->active_project, $month, $year));
     $this->smarty->assign(array('month' => $month, 'year' => $year, 'calendar' => $generator, 'page_tab' => 'calendar', 'navigation_pattern' => Calendar::getProjectMonthUrl($this->active_project, '-YEAR-', '-MONTH-')));
 }
Ejemplo n.º 8
0
 /**
  * Get recent activity for a repository
  *
  * @param Repository $repository
  * @param int $from_days_before
  * @return array
  */
 function getRecentActivity($repository, $from_days_before = 15)
 {
     $from = new DateTimeValue($from_days_before - 1 . ' days ago');
     $last_commit = $repository->getLastcommit();
     $beginning_of_day = $from->beginningOfDay();
     $max_commits = Commits::count(array("parent_id = ? AND created_on >= ? GROUP BY DAY(created_on) ORDER BY row_count DESC LIMIT 1", $repository->getId(), $beginning_of_day));
     $from_days_before--;
     for ($i = $from_days_before; $i >= 0; $i--) {
         $date = new DateTimeValue($i . 'days ago');
         $this_date_beginning = $date->beginningOfDay();
         $this_date_end = $date->endOfDay();
         $commits_count = Commits::count(array("parent_id = ? AND created_on >= ? AND created_on <= ?", $repository->getId(), $this_date_beginning, $this_date_end));
         $activity[$i]['commits'] = $commits_count;
         $activity[$i]['created_on'] = date('F d, Y', $date->getTimestamp());
         $activity[$i]['percentage'] = round($commits_count * 100 / $max_commits);
     }
     return $activity;
 }
/**
 * Render select datetime format widget
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 */
function smarty_function_select_datetime_format($params, &$smarty)
{
    $e = DIRECTORY_SEPARATOR == '\\' ? '%d' : '%e';
    // Windows does not support %e
    $presets = array('date' => array("%b {$e}. %Y", "%a, %b {$e}. %Y", "{$e} %b %Y", "%Y/%m/{$e}", "%m/{$e}/%Y"), 'time' => array('%I:%M %p', '%H:%M'));
    $mode = 'date';
    if (array_key_exists('mode', $params)) {
        $mode = $params['mode'];
        unset($params['mode']);
    }
    // if
    $value = null;
    if (array_key_exists('value', $params)) {
        $value = $params['value'];
        unset($params['value']);
    }
    // if
    $optional = false;
    if (array_key_exists('optional', $params)) {
        $optional = (bool) $params['optional'];
        unset($params['optional']);
    }
    // if
    $reference_time = new DateTimeValue('2007-11-21 20:45:15');
    $options = array();
    if ($optional) {
        $default_format = ConfigOptions::getValue("format_{$mode}");
        $default_value = strftime($default_format, $reference_time->getTimestamp());
        $options[] = option_tag(lang('-- System Default (:value) --', array('value' => $default_value)), '');
        $options[] = option_tag('', '');
    }
    // if
    foreach ($presets[$mode] as $v) {
        $option_attributes = $v === $value ? array('selected' => true) : null;
        $options[] = option_tag(strftime($v, $reference_time->getTimestamp()), $v, $option_attributes);
    }
    // foreach
    return select_box($options, $params);
}
 /**
  * Calendar
  *
  * @param void
  * @return null
  */
 function index()
 {
     require_once CALENDAR_MODULE_PATH . '/models/generators/DashboardCalendarGenerator.class.php';
     if ($this->request->get('month') && $this->request->get('year')) {
         $month = $this->request->get('month');
         $year = $this->request->get('year');
     } else {
         $today = new DateTimeValue(time() + get_user_gmt_offset());
         $month = $today->getMonth();
         $year = $today->getYear();
     }
     // if
     $first_weekday = UserConfigOptions::getValue('time_first_week_day', $this->logged_user);
     $generator = new DashboardCalendarGenerator($month, $year, $first_weekday);
     $generator->setData(Calendar::getActiveProjectsData($this->logged_user, $month, $year));
     $this->smarty->assign(array('month' => $month, 'year' => $year, 'calendar' => $generator, 'navigation_pattern' => Calendar::getDashboardMonthUrl('-YEAR-', '-MONTH-')));
     //BOF:mod 20110623
     $tabs = new NamedList();
     $tabs->add('dashboard', array('text' => 'Active Teams', 'url' => assemble_url('dashboard')));
     $tabs->add('home_page', array('text' => 'Home Page', 'url' => assemble_url('goto_home_tab')));
     $this->smarty->assign('page_tabs', $tabs);
     //EOF:mod 20110623
 }
Ejemplo n.º 11
0
	function total_task_times_print_table($objects, $left, $options, $group_name, &$sub_total = 0, &$sub_total_billing = 0) {
		
		echo '<div style="padding-left:'. $left .'px;">';
		echo '<table class="reporting-table"><tr class="reporting-table-heading">';
		echo '<th>' . lang('date') . '</th>';
		echo '<th>' . lang('title') . '</th>';
		echo '<th>' . lang('description') . '</th>';
		echo '<th>' . lang('person') . '</th>';
		if (array_var($options, 'show_billing') == 'checked') {
			echo '<th class="right">' . lang('billing') . '</th>';
		}
		echo '<th class="right">' . lang('time') . '</th>';
		echo '</tr>';
		
		$sub_total = 0;
		
		$alt_cls = "";
		foreach ($objects as $ts) { /* @var $ts Timeslot */
			echo "<tr $alt_cls>";
			echo "<td class='date'>" . format_date($ts->getStartTime()) . "</td>";
			echo "<td class='name'>" . ($ts->getRelObjectId() == 0 ? clean($ts->getObjectName()) : clean($ts->getRelObject()->getObjectName())) ."</td>";
			echo "<td class='name'>" . clean($ts->getDescription()) ."</td>";
			echo "<td class='person'>" . clean($ts->getUser() instanceof Contact ? $ts->getUser()->getObjectName() : '') ."</td>";
			if (array_var($options, 'show_billing') == 'checked') {
				if($ts->getIsFixedBilling()){
					echo "<td class='nobr right'>" . config_option('currency_code', '$') . " " . number_format($ts->getFixedBilling(), 2) . "</td>";
					$sub_total_billing += $ts->getFixedBilling();
				}else{
					$min = $ts->getMinutes();
					echo "<td class='nobr right'>" . config_option('currency_code', '$') . " " . number_format(($ts->getHourlyBilling()/60) * $min, 2) . "</td>";
					$sub_total_billing += ($ts->getHourlyBilling()/60) * $min;
				}
			}
			$lastStop = $ts->getEndTime() != null ? $ts->getEndTime() : ($ts->isPaused() ? $ts->getPausedOn() : DateTimeValueLib::now());
			echo "<td class='time nobr right'>" . DateTimeValue::FormatTimeDiff($ts->getStartTime(), $lastStop, "hm", 60, $ts->getSubtract()) ."</td>";
			echo "</tr>";
			
			$sub_total += $ts->getMinutes();
			$alt_cls = $alt_cls == "" ? 'class="alt-row"' : "";
		}
		
		echo '</table></div>';
	}
Ejemplo n.º 12
0
function cvs_total_task_times_table($objects, $pad_str, $options, $group_name, &$sub_total = 0)
{
    echo lang('date') . ';';
    echo lang('title') . ';';
    echo lang('description') . ';';
    echo lang('person') . ';';
    echo lang('time') . ';';
    echo "\n";
    $sub_total = 0;
    foreach ($objects as $ts) {
        echo $pad_str . format_date($ts->getStartTime()) . ';';
        echo ($ts->getRelObjectId() == 0 ? clean($ts->getObjectName()) : clean($ts->getRelObject()->getObjectName())) . ';';
        echo clean($ts->getDescription()) . ';';
        echo clean($ts->getUser()->getObjectName()) . ';';
        $lastStop = $ts->getEndTime() != null ? $ts->getEndTime() : ($ts->isPaused() ? $ts->getPausedOn() : DateTimeValueLib::now());
        echo DateTimeValue::FormatTimeDiff($ts->getStartTime(), $lastStop, "hm", 60, $ts->getSubtract()) . ';';
        $sub_total += $ts->getMinutes();
        echo "\n";
    }
}
/**
 * Render calendar
 * 
 * Params:
 * 
 * - data  - Calendar data
 * - first_week_day - Value for first day in week from settings
 * @param array $params
 * @return string
 */
function smarty_function_calendar($params, &$smarty)
{
    $first_week_day = 0;
    if (isset($params['first_week_day'])) {
        $first_week_day = (int) array_var($params, 'first_week_day');
        unset($params['first_week_day']);
    }
    // if
    $data = array();
    if (isset($params['data'])) {
        $data = array_var($params, 'data');
        unset($params['first_week_day']);
    }
    // if
    $days = array(0 => lang('Sunday'), 1 => lang('Monday'), 2 => lang('Tuesday '), 3 => lang('Wednesday'), 4 => lang('Thursday'), 5 => lang('Friday'), 6 => lang('Saturday'));
    $data_keys = array_keys($data);
    $date = $data_keys[0];
    $date = explode('-', $date);
    $year = $date[0];
    // year to render
    $month = $date[1];
    // month to render
    $begining_of_month = DateTimeValue::beginningOfMonth($month, $year);
    $end_of_month = DateTimeValue::endOfMonth($month, $year);
    $first_month_day = date('w', $begining_of_month->getTimestamp());
    $calendar = "<div id=\"calendar\">\n<table>\n";
    // header
    $calendar .= "\t<thead>\n";
    $from = $first_week_day;
    $start_point = null;
    for ($i = 0; $i < 7; $i++) {
        $day = $from > 6 ? $days[$from - 7] : $days[$from];
        $calendar .= "\t\t<th>{$day}</th>\n";
        $from++;
        if ($day == $days[$first_month_day]) {
            $start_point = $i;
        }
        // if
    }
    $calendar .= "\t</thead>\n";
    // data
    $calendar .= "\t<tr>\n";
    $curr_day = 1;
    for ($i = 1; $i < 36; $i++) {
        if ($i - 1 >= $start_point) {
            if ($curr_day <= $end_of_month->getDay()) {
                $calendar .= "\t\t<td><span>{$curr_day}</span>";
                $items = $data[$year . '-' . $month . '-' . $curr_day]['items'];
                $counts = $data[$year . '-' . $month . '-' . $curr_day]['counts'];
                // milestones
                foreach ($items as $milestone) {
                    if (instance_of($milestone, 'Milestone')) {
                        $calendar .= "<p>" . $milestone->getName() . "</p>";
                    }
                }
                // foreach
                if ($counts) {
                    if ($counts['Ticket']) {
                        $calendar .= "<p>(" . $counts['Ticket'] . ')' . lang('Tickets') . "</p>";
                    }
                    // if
                    if ($counts['Task']) {
                        $calendar .= "<p>(" . $counts['Task'] . ')' . lang('Tasks') . "</p>";
                    }
                    // if
                }
                // if
                $calendar .= "</td>\n";
                $curr_day++;
            } else {
                $calendar .= "\t\t<td></td>\n";
            }
            // if
        } else {
            $calendar .= "\t\t<td></td>\n";
        }
        $calendar .= $i % 7 == 0 && $i < 35 ? "\t</tr>\n\t<tr>\n" : null;
    }
    $calendar .= "\t</tr>\n";
    $calendar .= "</table>\n</div>\n";
    return $calendar;
}
 /**
  * Return Day milestones
  *
  * @access public
  * @param DateTimeValue $date_start in user gmt
  * @param DateTimeValue $date_end	in user gmt	 * 
  */
 function getRangeMilestones(DateTimeValue $date_start, DateTimeValue $date_end, $archived = false)
 {
     $from_date = new DateTimeValue($date_start->getTimestamp());
     $from_date = $from_date->beginningOfDay();
     $to_date = new DateTimeValue($date_end->getTimestamp());
     $to_date = $to_date->endOfDay();
     //set dates to gmt 0 for sql
     $from_date->advance(-logged_user()->getTimezone() * 3600);
     $to_date->advance(-logged_user()->getTimezone() * 3600);
     $archived_cond = " AND `archived_on` " . ($archived ? "<>" : "=") . " 0";
     $conditions = DB::prepareString(' AND `is_template` = false AND `completed_on` = ? AND (`due_date` >= ? AND `due_date` < ?) ' . $archived_cond, array(EMPTY_DATETIME, $from_date, $to_date));
     $result = self::instance()->listing(array("extra_conditions" => $conditions));
     return $result->objects;
 }
 /**
  * Return upcoming objects in a given projects
  *
  * @param User $user
  * @param Project $project
  * @param array $types
  * @param integer $page
  * @param integer $per_page
  * @return array
  */
 function findUpcoming($user, $project = null, $types = null, $page = null, $per_page = null)
 {
     if (instance_of($project, 'Project')) {
         $type_filter = ProjectUsers::getVisibleTypesFilterByProject($user, $project, $types);
     } else {
         $type_filter = ProjectUsers::getVisibleTypesFilter($user, array(PROJECT_STATUS_ACTIVE), $types);
     }
     if ($type_filter) {
         $today = new DateTimeValue();
         $today->advance(get_user_gmt_offset());
         $newer_than = $today->endOfDay();
         $conditions = array($type_filter . ' AND due_on > ? AND state >= ? AND visibility >= ? AND completed_on IS NULL', $newer_than, STATE_VISIBLE, $user->getVisibility());
         if ($page !== null && $per_page !== null) {
             return ProjectObjects::paginate(array('conditions' => $conditions, 'order' => 'due_on, priority DESC'), $page, $per_page);
         } else {
             return ProjectObjects::find(array('conditions' => $conditions, 'order' => 'due_on, priority DESC'));
         }
         // if
     }
     // if
     return null;
 }
Ejemplo n.º 16
0
 /**
  * Returns all events for the given range, tag and considers the active project
  *
  * @param DateTimeValue $date
  * @param String $tags
  * @return unknown
  */
 static function getRangeProjectEvents(DateTimeValue $start_date, DateTimeValue $end_date, $tags = '', $project = null, $archived = false)
 {
     $start_year = date("Y", mktime(0, 0, 1, $start_date->getMonth(), $start_date->getDay(), $start_date->getYear()));
     $start_month = date("m", mktime(0, 0, 1, $start_date->getMonth(), $start_date->getDay(), $start_date->getYear()));
     $start_day = date("d", mktime(0, 0, 1, $start_date->getMonth(), $start_date->getDay(), $start_date->getYear()));
     $end_year = date("Y", mktime(0, 0, 1, $end_date->getMonth(), $end_date->getDay(), $end_date->getYear()));
     $end_month = date("m", mktime(0, 0, 1, $end_date->getMonth(), $end_date->getDay(), $end_date->getYear()));
     $end_day = date("d", mktime(0, 0, 1, $end_date->getMonth(), $end_date->getDay(), $end_date->getYear()));
     if (!is_numeric($start_day) or !is_numeric($start_month) or !is_numeric($start_year) or !is_numeric($end_day) or !is_numeric($end_month) or !is_numeric($end_year)) {
         return NULL;
     }
     //permission check
     $permissions = ' AND ( ' . permissions_sql_for_listings(ProjectEvents::instance(), ACCESS_LEVEL_READ, logged_user()) . ')';
     if ($project instanceof Project) {
         $pids = $project->getAllSubWorkspacesQuery(!$archived);
         $wsstring = " AND " . self::getWorkspaceString($pids);
     } else {
         $wsstring = "";
     }
     if (isset($tags) && $tags && $tags != '') {
         $tag_str = " AND EXISTS (SELECT * FROM `" . TABLE_PREFIX . "tags` `t` WHERE `tag` IN (" . DB::escape($tags) . ") AND `" . TABLE_PREFIX . "project_events`.`id` = `t`.`rel_object_id` AND `t`.`rel_object_manager` = 'ProjectEvents') ";
     } else {
         $tag_str = "";
     }
     $invited = " AND `id` IN (SELECT `event_id` FROM `" . TABLE_PREFIX . "event_invitations` WHERE `user_id` = " . logged_user()->getId() . ")";
     if ($archived) {
         $archived_cond = " AND `archived_by_id` <> 0";
     } else {
         $archived_cond = " AND `archived_by_id` = 0";
     }
     $tz_hm = "'" . floor(logged_user()->getTimezone()) . ":" . abs(logged_user()->getTimezone()) % 1 * 60 . "'";
     $s_date = new DateTimeValue($start_date->getTimestamp() - logged_user()->getTimezone() * 3600);
     $e_date = new DateTimeValue($end_date->getTimestamp() - logged_user()->getTimezone() * 3600);
     $e_date->add("d", 1);
     $start_date_str = $s_date->format("Y-m-d H:i:s");
     $end_date_str = $e_date->format("Y-m-d H:i:s");
     $first_d = $start_day;
     while ($first_d > 7) {
         $first_d -= 7;
     }
     $week_of_first_day = date("W", mktime(0, 0, 0, $start_month, $first_d, $start_year));
     $conditions = "\t((\n\t\t\t\t-- \n\t\t\t\t-- THIS RETURNS EVENTS ON THE ACTUAL DAY IT'S SET FOR (ONE TIME EVENTS)\n\t\t\t\t-- \n\t\t\t\t(\n\t\t\t\t\t`repeat_h` = 0 \n\t\t\t\t\tAND `duration` >= '{$start_date_str}' \n\t\t\t\t\tAND `start` < '{$end_date_str}' \n\t\t\t\t) \n\t\t\t\t-- \n\t\t\t\t-- THIS RETURNS REGULAR REPEATING EVENTS - DAILY, WEEKLY, MONTHLY, OR YEARLY.\n\t\t\t\t-- \n\t\t\t\tOR \n\t\t\t\t(\n\t\t\t\t\t`repeat_h` = 0 \n\t\t\t\t\tAND\n\t\t\t\t\tDATE(`start`) < '{$end_date_str}'\n\t\t\t\t\tAND\n\t\t\t\t\t(\t\t\t\t\t\t\t\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\tDATE_ADD(`start`, INTERVAL (`repeat_num`-1)*`repeat_d` DAY) >= '{$start_date_str}' \n\t\t\t\t\t\t\tOR\n\t\t\t\t\t\t\trepeat_forever = 1\n\t\t\t\t\t\t\tOR\n\t\t\t\t\t\t\trepeat_end >= '{$start_year}-{$start_month}-{$start_day}'\n\t\t\t\t\t\t)\n\t\t\t\t\t\tOR\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\tDATE_ADD(`start`, INTERVAL (`repeat_num`-1)*`repeat_m` MONTH) >= '{$start_date_str}' \n\t\t\t\t\t\t\tOR\n\t\t\t\t\t\t\trepeat_forever = 1\n\t\t\t\t\t\t\tOR\n\t\t\t\t\t\t\trepeat_end >= '{$start_year}-{$start_month}-{$start_day}'\n\t\t\t\t\t\t)\n\t\t\t\t\t\tOR\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\tDATE_ADD(`start`, INTERVAL (`repeat_num`-1)*`repeat_y` YEAR) >= '{$start_date_str}' \n\t\t\t\t\t\t\tOR\n\t\t\t\t\t\t\trepeat_forever = 1\n\t\t\t\t\t\t\tOR\n\t\t\t\t\t\t\trepeat_end >= '{$start_year}-{$start_month}-{$start_day}'\n\t\t\t\t\t\t)\n\t\t\t\t\t)\t\t\n\t\t\t\t)\n\t\t\t\t-- \n\t\t\t\t-- THIS RETURNS EVENTS SET TO BE A CERTAIN DAY OF THE WEEK IN A CERTAIN WEEK EVERY CERTAIN AMOUNT OF MONTHS\n\t\t\t\t-- \n\t\t\t\tOR\n\t\t\t\t(\n\t\t\t\t\tDATE(`start`) <= '{$start_date_str}'\n\t\t\t\t\tAND\n\t\t\t\t\t`repeat_h` = 1 \n\t\t\t\t\tAND\n\t\t\t\t\t`repeat_dow` = DAYOFWEEK('{$start_date_str}') \n\t\t\t\t\tAND\n\t\t\t\t\t`repeat_wnum` + {$week_of_first_day} - 1 = WEEK('{$start_date_str}', 3) \n\t\t\t\t\tAND\n\t\t\t\t\tMOD( PERIOD_DIFF(DATE_FORMAT(`start`, '%Y%m'), DATE_FORMAT('{$start_date_str}', '%Y%m')), `repeat_mjump`) = 0\n\t\t\t\t)\t\t\t\t\n\t\t\t)\n\t\t\t{$wsstring}\n\t\t\t{$permissions} {$invited}\n\t\t\t{$tag_str} {$archived_cond} )";
     $result_events = self::findAll(array('conditions' => $conditions, 'order' => '`start`'));
     // Find invitations for events and logged user
     ProjectEvents::addInvitations($result_events);
     return $result_events;
 }
Ejemplo n.º 17
0
function format_value_to_print($col, $value, $type, $obj_type_id, $textWrapper = '', $dateformat = 'Y-m-d')
{
    switch ($type) {
        case DATA_TYPE_STRING:
            if (preg_match(EMAIL_FORMAT, strip_tags($value))) {
                $formatted = strip_tags($value);
            } else {
                if ($col == 'is_user') {
                    $formatted = $value == 1 ? lang('yes') : lang('no');
                } else {
                    if (strpos($value, "�") !== false) {
                        $value = preg_replace('/\\xA0/s', ' ', $value);
                    }
                    $value = utf8_safe($value);
                    $formatted = $textWrapper . $value . $textWrapper;
                }
            }
            break;
        case DATA_TYPE_INTEGER:
            if ($col == 'priority') {
                switch ($value) {
                    case 100:
                        $formatted = lang('low priority');
                        break;
                    case 200:
                        $formatted = lang('normal priority');
                        break;
                    case 300:
                        $formatted = lang('high priority');
                        break;
                    case 400:
                        $formatted = lang('urgent priority');
                        break;
                    default:
                        $formatted = clean($value);
                }
            } elseif ($col == 'time_estimate') {
                if ($value > 0) {
                    $formatted = DateTimeValue::FormatTimeDiff(new DateTimeValue(0), new DateTimeValue($value * 60), 'hm', 60);
                } else {
                    $formatted = clean($value);
                }
            } else {
                $formatted = clean($value);
            }
            break;
        case DATA_TYPE_BOOLEAN:
            $formatted = $value == 1 ? lang('yes') : lang('no');
            break;
        case DATA_TYPE_DATE:
            if ($value != 0) {
                if (str_ends_with($value, "00:00:00")) {
                    $dateformat .= " H:i:s";
                }
                try {
                    $dtVal = DateTimeValueLib::dateFromFormatAndString($dateformat, $value);
                } catch (Exception $e) {
                    $formatted = $value;
                }
                if (!isset($formatted)) {
                    $formatted = format_date($dtVal, null, 0);
                }
            } else {
                $formatted = '';
            }
            break;
        case DATA_TYPE_DATETIME:
            if ($value != 0) {
                try {
                    $dtVal = DateTimeValueLib::dateFromFormatAndString("{$dateformat} H:i:s", $value);
                } catch (Exception $e) {
                    $formatted = $value;
                }
                if ($dtVal instanceof DateTimeValue) {
                    if ($obj_type_id == ProjectEvents::instance()->getObjectTypeId() || $obj_type_id == ProjectTasks::instance()->getObjectTypeId()) {
                        $dtVal->advance(logged_user()->getTimezone() * 3600, true);
                    }
                    if ($obj_type_id == ProjectEvents::instance()->getObjectTypeId() && ($col == 'start' || $col == 'duration')) {
                        $formatted = format_datetime($dtVal);
                    } else {
                        $formatted = format_date($dtVal, null, 0);
                    }
                }
            } else {
                $formatted = '';
            }
            break;
        default:
            $formatted = $value;
    }
    if ($formatted == '') {
        $formatted = '--';
    }
    return $formatted;
}
Ejemplo n.º 18
0
 /**
  * Prepare project data for a given month
  *
  * @param integer $month
  * @param integer $year
  * @param mixed $additional_conditions
  * @param boolean $include_assignments_table
  * @return array
  */
 function getMonthData($month, $year, $additional_conditions, $include_assignments_table = false)
 {
     $first_day = DateTimeValue::beginningOfMonth($month, $year);
     $last_day = DateTimeValue::endOfMonth($month, $year);
     // Than we define empty result...
     $result = array();
     for ($i = 1; $i <= $last_day->getDay(); $i++) {
         $result["{$year}-{$month}-{$i}"] = array();
     }
     // for
     $objects_table = TABLE_PREFIX . 'project_objects';
     $assignments_table = TABLE_PREFIX . 'assignments';
     $conditions = db_prepare_string("{$objects_table}.due_on BETWEEN ? AND ?", array($first_day, $last_day));
     if ($additional_conditions) {
         $conditions .= " AND {$additional_conditions}";
     }
     // if
     // If we don't have user ID-s filter we can exclude assignments table
     $tables = $include_assignments_table ? "{$objects_table}, {$assignments_table}" : $objects_table;
     $objects = ProjectObjects::findBySQL("SELECT DISTINCT {$objects_table}.* FROM {$tables} WHERE {$conditions} ORDER BY type, due_on");
     if (is_foreachable($objects)) {
         foreach ($objects as $object) {
             $due_on = $object->getDueOn();
             $result[$due_on->getYear() . '-' . $due_on->getMonth() . '-' . $due_on->getDay()][] = $object;
         }
         // foreach
     }
     // if
     return $result;
 }
Ejemplo n.º 19
0
/**
 * Print due on string (due in, due today or late) for a given object
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 */
function smarty_function_due($params, &$smarty)
{
    $object = array_var($params, 'object');
    $due_date = null;
    if (instance_of($object, 'ProjectObject')) {
        if ($object->can_be_completed) {
            if ($object->isCompleted()) {
                return lang('Completed');
            }
            // if
            $due_date = $object->getDueOn();
        } else {
            return '--';
        }
        // if
    } elseif (instance_of($object, 'Invoice')) {
        if ($object->getStatus() == INVOICE_STATUS_ISSUED) {
            $due_date = $object->getDueOn();
        } else {
            return '--';
        }
        // if
    } else {
        return new InvalidParamError('object', $object, '$object is not expected to be an instance of ProjectObject or Invoice class', true);
    }
    // if
    $offset = get_user_gmt_offset();
    if (instance_of($due_date, 'DateValue')) {
        require_once SMARTY_PATH . '/plugins/modifier.date.php';
        $date = smarty_modifier_date($due_date, 0);
        // just printing date, offset is 0!
        $reminder_string_begining = '';
        $reminder_string_end = '';
        $sql = "select auto_email_status, email_reminder_period, email_reminder_unit, email_reminder_time from healingcrystals_project_object_misc where object_id=? and auto_email_status='1'";
        $arguments = array($object->getId());
        $sql = db_prepare_string($sql, $arguments);
        $row = db_execute_all($sql);
        if (!empty($row)) {
            $entry = $row[0];
            $auto_email_status = array_var($entry, 'auto_email_status');
            $email_reminder_period = array_var($entry, 'email_reminder_period', '0');
            $email_reminder_unit = array_var($entry, 'email_reminder_unit', 'D');
            $email_reminder_time = array_var($entry, 'email_reminder_time', '06:00');
            $meridian = '';
            list($h, $m) = explode(':', $email_reminder_time);
            $h = (int) $h;
            if ($h > 12) {
                $h -= 12;
                $meridian = 'PM';
            } elseif ($h == 12) {
                $meridian = 'PM';
            } elseif ($h == 0) {
                $meridian = 'AM';
            } else {
                $meridian = 'AM';
            }
            $email_reminder_time = str_pad($h, 2, '0', STR_PAD_LEFT) . ':' . $m . ' ' . $meridian;
            $reminder_string_begining = 'Reminder set for ' . $email_reminder_period . ' ' . ($email_reminder_unit == 'D' ? 'Day(s)' : ($email_reminder_unit == 'W' ? 'Week(s)' : ($email_reminder_unit == 'M' ? 'Month(s)' : ''))) . " from Due Date: ";
            $reminder_string_end = " at " . $email_reminder_time;
        }
        if ($due_date->isToday($offset)) {
            if (!empty($reminder_string_begining)) {
                return '<span class="today">' . $reminder_string_begining . '<span class="number">' . lang('Today') . '</span>' . $reminder_string_end . '</span>';
            } else {
                return '<span class="today"><span class="number">' . lang('Due Today') . '</span></span>';
            }
        } elseif ($due_date->isYesterday($offset)) {
            if (!empty($reminder_string_begining)) {
                return '<span class="late" title="' . clean($date) . '">' . $reminder_string_begining . lang('<span class="number">1 Day Late</span>') . $reminder_string_end . '</span>';
            } else {
                return '<span class="late" title="' . clean($date) . '">' . lang('<span class="number">1 Day Late</span>') . '</span>';
            }
        } elseif ($due_date->isTomorrow($offset)) {
            if (!empty($reminder_string_begining)) {
                return '<span class="upcoming" title="' . clean($date) . '">' . $reminder_string_begining . '<span class="number">' . lang('Tomorrow') . '</span>' . $reminder_string_end . '</span>';
            } else {
                return '<span class="upcoming" title="' . clean($date) . '"><span class="number">' . lang('Due Tomorrow') . '</span></span>';
            }
        } else {
            $now = new DateTimeValue();
            $now->advance($offset);
            $now = $now->beginningOfDay();
            $due_date->beginningOfDay();
            if ($due_date->getTimestamp() > $now->getTimestamp()) {
                //return '<span class="upcoming" title="' . clean($date) . '">' . lang('Due in <span class="number">:days</span> Days', array('days' => floor(($due_date->getTimestamp() - $now->getTimestamp()) / 86400))) . '</span>';
                //return '<span class="upcoming" title="' . clean($date) . '">' . lang('<span class="number">:days</span> Days', array('days' => floor(($due_date->getTimestamp() - $now->getTimestamp()) / 86400))) . '</span>';
                if (!empty($reminder_string_begining)) {
                    return '<span class="upcoming" title="' . clean($date) . '">' . $reminder_string_begining . date('F d, Y', $due_date->getTimestamp()) . lang(' (<span class="number">:days</span> Days)', array('days' => floor(($due_date->getTimestamp() - $now->getTimestamp()) / 86400))) . $reminder_string_end . '</span>';
                } else {
                    return '<span class="upcoming" title="' . clean($date) . '">Due ' . date('F d, Y', $due_date->getTimestamp()) . lang(' (<span class="number">:days</span> Days)', array('days' => floor(($due_date->getTimestamp() - $now->getTimestamp()) / 86400))) . '</span>';
                }
            } else {
                //return '<span class="late" title="' . clean($date) . '">' . lang('<span class="number">:days</span> Days Late', array('days' => floor(($now->getTimestamp() - $due_date->getTimestamp()) / 86400))) . '</span>';
                if (!empty($reminder_string_begining)) {
                    return '<span class="late" title="' . clean($date) . '">' . $reminder_string_begining . date('F d, Y', $due_date->getTimestamp()) . lang(' (<span class="number">:days</span> Days Late)', array('days' => floor(($now->getTimestamp() - $due_date->getTimestamp()) / 86400))) . $reminder_string_end . '</span>';
                } else {
                    return '<span class="late" title="' . clean($date) . '">Due ' . date('F d, Y', $due_date->getTimestamp()) . lang(' (<span class="number">:days</span> Days Late)', array('days' => floor(($now->getTimestamp() - $due_date->getTimestamp()) / 86400))) . '</span>';
                }
            }
            // if
        }
        // if
    } else {
        //return lang('No Due Date');
        return lang('--');
    }
    // if
}
Ejemplo n.º 20
0
function format_value_to_print($col, $value, $type, $obj_type_id, $textWrapper = '', $dateformat = 'Y-m-d')
{
    switch ($type) {
        case DATA_TYPE_STRING:
            if (preg_match(EMAIL_FORMAT, strip_tags($value))) {
                $formatted = strip_tags($value);
            } else {
                $formatted = $textWrapper . clean($value) . $textWrapper;
            }
            break;
        case DATA_TYPE_INTEGER:
            if ($col == 'priority') {
                switch ($value) {
                    case 100:
                        $formatted = lang('low priority');
                        break;
                    case 200:
                        $formatted = lang('normal priority');
                        break;
                    case 300:
                        $formatted = lang('high priority');
                        break;
                    case 400:
                        $formatted = lang('urgent priority');
                        break;
                    default:
                        $formatted = clean($value);
                }
            } elseif ($col == 'time_estimate') {
                if ($value > 0) {
                    $formatted = DateTimeValue::FormatTimeDiff(new DateTimeValue(0), new DateTimeValue($value * 60), 'hm', 60);
                } else {
                    $formatted = clean($value);
                }
            } else {
                $formatted = clean($value);
            }
            break;
        case DATA_TYPE_BOOLEAN:
            $formatted = $value == 1 ? lang('yes') : lang('no');
            break;
        case DATA_TYPE_DATE:
            if ($value != 0) {
                if (str_ends_with($value, "00:00:00")) {
                    $dateformat .= " H:i:s";
                }
                $dtVal = DateTimeValueLib::dateFromFormatAndString($dateformat, $value);
                $formatted = format_date($dtVal, null, 0);
            } else {
                $formatted = '';
            }
            break;
        case DATA_TYPE_DATETIME:
            if ($value != 0) {
                $dtVal = DateTimeValueLib::dateFromFormatAndString("{$dateformat} H:i:s", $value);
                if ($obj_type_id == ProjectEvents::instance()->getObjectTypeId() && $col == 'start') {
                    $formatted = format_datetime($dtVal);
                } else {
                    $formatted = format_date($dtVal, null, 0);
                }
            } else {
                $formatted = '';
            }
            break;
        default:
            $formatted = $value;
    }
    if ($formatted == '') {
        $formatted = '--';
    }
    return $formatted;
}
Ejemplo n.º 21
0
     $subject = clean($event->getObjectName());
     $img_url = image_url('/16x16/milestone.png');
     $divtype = '<span class="italic">' . lang('milestone') . '</span> - ';
     $tipBody = clean($event->getDescription());
 } elseif ($event instanceof ProjectTask) {
     $start_of_task = false;
     $end_of_task = false;
     if ($event->getDueDate() instanceof DateTimeValue) {
         $due_date = new DateTimeValue($event->getDueDate()->getTimestamp() + logged_user()->getTimezone() * 3600);
         if ($dtv->getTimestamp() == mktime(0, 0, 0, $due_date->getMonth(), $due_date->getDay(), $due_date->getYear())) {
             $end_of_task = true;
             $start_of_task = true;
         }
     }
     if ($event->getStartDate() instanceof DateTimeValue) {
         $start_date = new DateTimeValue($event->getStartDate()->getTimestamp() + logged_user()->getTimezone() * 3600);
         if ($dtv->getTimestamp() == mktime(0, 0, 0, $start_date->getMonth(), $start_date->getDay(), $start_date->getYear())) {
             $start_of_task = true;
             $end_of_task = true;
         }
     }
     if ($start_of_task && $end_of_task) {
         $tip_title = lang('task');
         $img_url = image_url('/16x16/tasks.png');
         $tip_pre = '';
     } else {
         if ($end_of_task) {
             $tip_title = lang('end of task');
             $img_url = image_url('/16x16/task_end.png');
             $tip_pre = 'end_';
         } else {
 function total_task_times_csv($report_data, $columns, $timeslotsArray, $skip_ws = false)
 {
     //$types = self::get_report_column_types($report->getId());
     $filename = str_replace(' ', '_', lang('task time report')) . date('_YmdHis');
     header('Expires: 0');
     header('Cache-control: private');
     header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
     header('Content-Description: File Transfer');
     header('Content-Type: application/csv');
     header('Content-disposition: attachment; filename=' . $filename . '.csv');
     // titles
     $titles = lang('date') . ";" . lang('title') . ";" . lang('description') . ";" . lang('user') . ";" . lang('time') . ";";
     if (array_var($report_data, 'show_billing', false)) {
         $titles .= lang('billing') . ";";
     }
     foreach ($columns as $id => $pos) {
         if ($pos == 0) {
             continue;
         }
         if (!is_numeric($id)) {
             $col_name = lang("field ProjectTasks " . $id);
         } else {
             $cp = CustomProperties::getCustomProperty($id);
             $col_name = $cp->getName();
         }
         $titles .= $col_name . ";";
     }
     $titles = iconv(mb_internal_encoding(), "ISO-8859-1", html_entity_decode($titles, ENT_COMPAT));
     echo "{$titles}\n";
     // data
     foreach ($timeslotsArray as $tsRow) {
         $ts = $tsRow["ts"];
         if ($skip_ws && $ts->getObjectManager() == 'Projects') {
             continue;
         }
         $to_print = format_date($ts->getStartTime()) . ";";
         if ($ts->getObject() instanceof ProjectTask) {
             $to_print .= $ts->getObject()->getTitle() . ";";
             $to_print .= $ts->getObject()->getText() . ";";
         } else {
             if ($ts->getObject() instanceof Project) {
                 $ws_name = lang('workspace') . ' ' . clean($ts->getObject()->getName());
                 $to_print .= "{$ws_name};;";
             } else {
                 $to_print .= ";;";
             }
         }
         $to_print .= clean(Users::getUserDisplayName($ts->getUserId())) . ";";
         $lastStop = $ts->getEndTime() != null ? $ts->getEndTime() : ($ts->isPaused() ? $ts->getPausedOn() : DateTimeValueLib::now()) . ";";
         $to_print .= DateTimeValue::FormatTimeDiff($ts->getStartTime(), $lastStop, "hm", 60, $ts->getSubtract()) . ";";
         if (array_var($report_data, 'show_billing', false)) {
             $to_print .= config_option('currency_code', '$') . " " . $ts->getFixedBilling();
         }
         // other columns
         foreach ($columns as $id => $pos) {
             if ($pos == 0) {
                 continue;
             }
             if ($ts->getObject() instanceof ProjectTask) {
                 if (!is_numeric($id)) {
                     $col_value = self::format_value_to_print($id, $ts->getObject()->getColumnValue($id), $ts->getObject()->manager()->getColumnType($id), $ts->getObject()->getObjectManagerName());
                 } else {
                     $cp = CustomProperties::getCustomProperty($id);
                     $cpv = CustomPropertyValues::getCustomPropertyValue($ts->getObject()->getId(), $cp->getId());
                     if ($cpv instanceof CustomPropertyValue) {
                         $col_value = self::format_value_to_print($cp->getName(), $cpv->getValue(), $cp->getOgType(), $ts->getObject()->getObjectManagerName());
                     } else {
                         $col_value = "";
                     }
                 }
             } else {
                 $col_value = "";
             }
             $to_print .= $col_value . ";";
         }
         $to_print = iconv(mb_internal_encoding(), "ISO-8859-1", html_entity_decode($to_print, ENT_COMPAT));
         echo "{$to_print}\n";
     }
     die;
 }
Ejemplo n.º 23
0
 /**
  * Difference to another DateTime
  *
  * @param void
  * @param integer $input 
  * @return integer $seconds
  */
 function difference(DateTimeValue $input)
 {
     return $this->getTimestamp() - $input->getTimestamp();
 }
Ejemplo n.º 24
0
 function change_start_due_date()
 {
     $task = ProjectTasks::findById(get_id());
     if (!$task->canEdit(logged_user())) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     $tochange = array_var($_GET, 'tochange', '');
     if (($tochange == 'both' || $tochange == 'due') && $task->getDueDate() instanceof DateTimeValue) {
         $year = array_var($_GET, 'year', $task->getDueDate()->getYear());
         $month = array_var($_GET, 'month', $task->getDueDate()->getMonth());
         $day = array_var($_GET, 'day', $task->getDueDate()->getDay());
         $hour = array_var($_GET, 'hour', $task->getDueDate()->getHour());
         $minute = array_var($_GET, 'min', $task->getDueDate()->getMinute());
         $new_date = new DateTimeValue(mktime($hour, $minute, 0, $month, $day, $year));
         if (isset($_GET['hour']) && isset($_GET['min'])) {
             $new_date->advance(logged_user()->getTimezone() * -3600);
         }
         $task->setDueDate($new_date);
     }
     if (($tochange == 'both' || $tochange == 'start') && $task->getStartDate() instanceof DateTimeValue) {
         $year = array_var($_GET, 'year', $task->getStartDate()->getYear());
         $month = array_var($_GET, 'month', $task->getStartDate()->getMonth());
         $day = array_var($_GET, 'day', $task->getStartDate()->getDay());
         $hour = array_var($_GET, 'hour', $task->getStartDate()->getHour());
         $minute = array_var($_GET, 'min', $task->getStartDate()->getMinute());
         $new_date = new DateTimeValue(mktime($hour, $minute, 0, $month, $day, $year));
         if (isset($_GET['hour']) && isset($_GET['min'])) {
             $new_date->advance(logged_user()->getTimezone() * -3600);
         }
         $task->setStartDate($new_date);
     }
     try {
         DB::beginWork();
         $task->save();
         DB::commit();
     } catch (Exception $e) {
         DB::rollback();
         flash_error(lang('error change date'));
     }
     // try
     ajx_current("empty");
 }
function smarty_function_recurring_info($params, &$smarty)
{
    $object = array_var($params, 'object');
    if (!instance_of($object, 'ProjectObject')) {
        return new InvalidParamError('object', $object, '$object is expected to be an instance of ProjectObject', true);
    }
    $info = '';
    $sql = "select recurring_period, recurring_period_type, recurring_period_condition, recurring_end_date from healingcrystals_project_object_misc where object_id=?";
    $arguments = array($object->getId());
    $sql = db_prepare_string($sql, $arguments);
    $row = db_execute_all($sql);
    if (!empty($row)) {
        $entry = $row[0];
        $recurring_period = array_var($entry, 'recurring_period');
        $recurring_period_type = array_var($entry, 'recurring_period_type');
        $recurring_period_condition = array_var($entry, 'recurring_period_condition');
        $recurring_end_date = array_var($entry, 'recurring_end_date');
        if (!empty($recurring_period) && !empty($recurring_period_type) && $recurring_period_condition) {
            $info = 'Recurring every ' . $recurring_period . ' ';
            switch ($recurring_period_type) {
                case 'D':
                    $info .= ' day(s) ';
                    break;
                case 'W':
                    $info .= ' week(s) ';
                    break;
                case 'M':
                    $info .= ' month(s) ';
                    break;
            }
            switch ($recurring_period_condition) {
                case 'after_due_date':
                    $info .= 'after Task is Due';
                    break;
                case 'after_task_complete':
                    $info .= 'after Task has been Completed';
                    break;
            }
            $info = '<span class="recurring">' . $info . '</span>';
        }
    }
    return $info;
    if (instance_of($due_date, 'DateValue')) {
        require_once SMARTY_PATH . '/plugins/modifier.date.php';
        $date = smarty_modifier_date($due_date, 0);
        // just printing date, offset is 0!
        $reminder_string_begining = '';
        $reminder_string_end = '';
        $sql = "select auto_email_status, email_reminder_period, email_reminder_unit, email_reminder_time from healingcrystals_project_object_misc where object_id=?";
        $arguments = array($object->getId());
        $sql = db_prepare_string($sql, $arguments);
        $row = db_execute_all($sql);
        if (!empty($row)) {
            $entry = $row[0];
            $auto_email_status = array_var($entry, 'auto_email_status');
            $email_reminder_period = array_var($entry, 'email_reminder_period', '0');
            $email_reminder_unit = array_var($entry, 'email_reminder_unit', 'D');
            $email_reminder_time = array_var($entry, 'email_reminder_time', '06:00');
            $meridian = '';
            list($h, $m) = explode(':', $email_reminder_time);
            $h = (int) $h;
            if ($h > 12) {
                $h -= 12;
                $meridian = 'PM';
            } elseif ($h == 0) {
                $meridian = 'PM';
            } else {
                $meridian = 'AM';
            }
            $email_reminder_time = str_pad($h, 2, '0', STR_PAD_LEFT) . ':' . $m . ' ' . $meridian;
            $reminder_string_begining = 'Reminder set for ' . $email_reminder_period . ' ' . ($email_reminder_unit == 'D' ? 'Day(s)' : ($email_reminder_unit == 'W' ? 'Week(s)' : ($email_reminder_unit == 'M' ? 'Month(s)' : ''))) . " from Due Date: ";
            $reminder_string_end = " at " . $email_reminder_time;
        }
        if ($due_date->isToday($offset)) {
            if (!empty($reminder_string_begining)) {
                return '<span class="today">' . $reminder_string_begining . '<span class="number">' . lang('Today') . '</span>' . $reminder_string_end . '</span>';
            } else {
                return '<span class="today"><span class="number">' . lang('Due Today') . '</span></span>';
            }
        } elseif ($due_date->isYesterday($offset)) {
            if (!empty($reminder_string_begining)) {
                return '<span class="late" title="' . clean($date) . '">' . $reminder_string_begining . lang('<span class="number">1 Day Late</span>') . $reminder_string_end . '</span>';
            } else {
                return '<span class="late" title="' . clean($date) . '">' . lang('<span class="number">1 Day Late</span>') . '</span>';
            }
        } elseif ($due_date->isTomorrow($offset)) {
            if (!empty($reminder_string_begining)) {
                return '<span class="upcoming" title="' . clean($date) . '">' . $reminder_string_begining . '<span class="number">' . lang('Tomorrow') . '</span>' . $reminder_string_end . '</span>';
            } else {
                return '<span class="upcoming" title="' . clean($date) . '"><span class="number">' . lang('Due Tomorrow') . '</span></span>';
            }
        } else {
            $now = new DateTimeValue();
            $now->advance($offset);
            $now = $now->beginningOfDay();
            $due_date->beginningOfDay();
            if ($due_date->getTimestamp() > $now->getTimestamp()) {
                //return '<span class="upcoming" title="' . clean($date) . '">' . lang('Due in <span class="number">:days</span> Days', array('days' => floor(($due_date->getTimestamp() - $now->getTimestamp()) / 86400))) . '</span>';
                //return '<span class="upcoming" title="' . clean($date) . '">' . lang('<span class="number">:days</span> Days', array('days' => floor(($due_date->getTimestamp() - $now->getTimestamp()) / 86400))) . '</span>';
                if (!empty($reminder_string_begining)) {
                    return '<span class="upcoming" title="' . clean($date) . '">' . $reminder_string_begining . date('F d, Y', $due_date->getTimestamp()) . lang(' (<span class="number">:days</span> Days)', array('days' => floor(($due_date->getTimestamp() - $now->getTimestamp()) / 86400))) . $reminder_string_end . '</span>';
                } else {
                    return '<span class="upcoming" title="' . clean($date) . '">Due ' . date('F d, Y', $due_date->getTimestamp()) . lang(' (<span class="number">:days</span> Days)', array('days' => floor(($due_date->getTimestamp() - $now->getTimestamp()) / 86400))) . '</span>';
                }
            } else {
                //return '<span class="late" title="' . clean($date) . '">' . lang('<span class="number">:days</span> Days Late', array('days' => floor(($now->getTimestamp() - $due_date->getTimestamp()) / 86400))) . '</span>';
                if (!empty($reminder_string_begining)) {
                    return '<span class="late" title="' . clean($date) . '">' . $reminder_string_begining . date('F d, Y', $due_date->getTimestamp()) . lang(' (<span class="number">:days</span> Days Late)', array('days' => floor(($now->getTimestamp() - $due_date->getTimestamp()) / 86400))) . $reminder_string_end . '</span>';
                } else {
                    return '<span class="late" title="' . clean($date) . '">Due ' . date('F d, Y', $due_date->getTimestamp()) . lang(' (<span class="number">:days</span> Days Late)', array('days' => floor(($now->getTimestamp() - $due_date->getTimestamp()) / 86400))) . '</span>';
                }
            }
            // if
        }
        // if
    } else {
        //return lang('No Due Date');
        return lang('--');
    }
    // if
}
Ejemplo n.º 26
0
                $divtype = '<span class="italic">' . $tip_title . '</span> - ';
                $tipBody = lang('assigned to') . ': ' . clean($event->getAssignedToName()) . (trim(clean($event->getText())) != '' ? '<br><br>' . trim(clean($event->getText())) : '');
            } elseif ($event instanceof ProjectEvent) {
                $div_prefix = 'w5_ev_div_';
                $objType = 'event';
                $subject = clean($event->getObjectName());
                $img_url = image_url('/16x16/calendar.png');
                /* @var $event ProjectEvent */
                $divtype = '<span class="italic">' . lang('event') . '</span> - ';
                $tipBody = trim(clean($event->getDescription())) != '' ? '<br>' . clean($event->getDescription()) : '';
            } elseif ($event instanceof Contact) {
                $div_prefix = 'w5_bd_div_';
                $objType = 'contact';
                $subject = clean($event->getObjectName());
                $img_url = image_url('/16x16/contacts.png');
                $due_date = new DateTimeValue(mktime(0, 0, 0, $event->getOBirthday()->getMonth(), $event->getOBirthday()->getDay(), $dates[$day_of_week]->getYear()));
                $divtype = '<span class="italic">' . lang('birthday') . '</span> - ';
            }
            $tipBody = str_replace("\r", '', $tipBody);
            $tipBody = str_replace("\n", '<br>', $tipBody);
            if (strlen_utf($tipBody) > 200) {
                $tipBody = substr_utf($tipBody, 0, strpos($tipBody, ' ', 200)) . ' ...';
            }
            if ($event instanceof ProjectMilestone || $event instanceof ProjectEvent || $due_date instanceof DateTimeValue && $dates[$day_of_week]->getTimestamp() == mktime(0, 0, 0, $due_date->getMonth(), $due_date->getDay(), $due_date->getYear()) || $start_date instanceof DateTimeValue && $dates[$day_of_week]->getTimestamp() == mktime(0, 0, 0, $start_date->getMonth(), $start_date->getDay(), $start_date->getYear())) {
                $ws_color = $event->getObjectColor($event instanceof ProjectEvent ? 1 : 12);
                cal_get_ws_color($ws_color, $ws_style, $ws_class, $txt_color, $border_color);
                ?>
					<div id="<?php 
                echo $div_prefix . $event->getId();
                ?>
" class="adc" style="left: 4%; top: <?php 
Ejemplo n.º 27
0
 /**
  * Return formated time
  *
  * @access public
  * @param DateTimeValue $date
  * @param float $timezone Timezone offset in hours
  * @return string
  */
 function formatTime(DateTimeValue $date, $timezone = 0)
 {
     $lang_time_format = $this->langs->get('time format', null);
     $time_format = $lang_time_format ? $lang_time_format : $this->time_format;
     return $this->date_lang($time_format, $date->getTimestamp() + $timezone * 3600);
 }
Ejemplo n.º 28
0
			<tr class="timeslot <?php echo $counter % 2 ? 'even' : 'odd'; echo $timeslot->isOpen() ? ' openTimeslot' : '' ?>" id="timeslot<?php echo $timeslot->getId() ?>">
			<td style="padding-right:10px"><b><?php echo $counter ?>.</b></td>
			<?php if ($timeslot->getUser() instanceof Contact) { ?>
				<td style="padding-right:10px"><b><a class="internalLink" href="<?php echo $timeslot->getUser()->getCardUserUrl()?>" title=" <?php echo lang('user card of', clean($timeslot->getUser()->getObjectName())) ?>"><?php echo clean($timeslot->getUser()->getObjectName()) ?></a></b></td>
			<?php } else {?>
				<td style="padding-right:10px"><b><?php echo lang("n/a") ?></b></td>
			<?php } ?>
			<td style="padding-right:10px"><?php echo format_datetime($timeslot->getStartTime())?>
				&nbsp;-&nbsp;<?php echo $timeslot->isOpen() ? ('<b>' . lang('work in progress') . '</b>') : 
				( (format_date($timeslot->getEndTime()) != format_date($timeslot->getStartTime()))?  format_datetime($timeslot->getEndTime()): format_time($timeslot->getEndTime())) ?></td>
			<td style="padding-right:10px">
				<?php 
					echo DateTimeValue::FormatTimeDiff($timeslot->getStartTime(), $timeslot->getEndTime(), "hm", 60, $timeslot->getSubtract());
					if ($timeslot->getSubtract() > 0) {
						$now = DateTimeValueLib::now();
						echo " <span class='desc'>(" . lang('paused time') . ": " . DateTimeValue::FormatTimeDiff($now, $now, "hm", 60, $timeslot->getSubtract()) .")</span>";
					}
				?>
			</td>
			<td align="right">
			<?php if(count($options)) { ?>
					<?php echo implode(' | ', $options) ?>
			<?php } // if ?>
			</td>
			</tr>
			
			<?php if ($timeslot->getDescription() != '') {?>
				<tr class="timeslot <?php echo $counter % 2 ? 'even' : 'odd'; echo $timeslot->isOpen() ? ' openTimeslot' : '' ?>" ><td></td>
				<td colspan=6 style="color:#666666"><?php echo clean($timeslot->getDescription()) ?></td></tr>
			<?php } //if ?>
		<?php } //if 
 /**
  * Return difference between specific datetime and due date time in seconds
  *
  * @access public
  * @param DateTime $diff_to
  * @return integer
  */
 private function getDueDateDiff(DateTimeValue $diff_to)
 {
     return $this->getDueDate()->getTimestamp() - $diff_to->getTimestamp();
 }
Ejemplo n.º 30
0
    for ($i = $event_start->getHour() + 1; $i < $event_duration->getHour(); $i++) {
        $occup[$i][0][$posHoriz] = true;
        $occup[$i][1][$posHoriz] = true;
    }
    if ($event_duration->getMinute() > 0) {
        $occup[$event_duration->getHour()][0][$posHoriz] = true;
        if ($event_duration->getMinute() > 30) {
            $occup[$event_duration->getHour()][1][$posHoriz] = true;
        }
    }
    //if ($posHoriz+1 == $evs_same_time) $width = $width - 0.75;
    $procesados[$hr_start]++;
    $event_duration->add('s', 1);
    $ev_duration = DateTimeValueLib::get_time_difference($event_start->getTimestamp(), $event_duration->getTimestamp());
    $real_start = new DateTimeValue($event->getStart()->getTimestamp() + 3600 * logged_user()->getTimezone());
    $real_duration = new DateTimeValue($event->getDuration()->getTimestamp() + 3600 * logged_user()->getTimezone());
    $pre_tf = $real_start->getDay() == $real_duration->getDay() ? '' : 'D j, ';
    $ev_hour_text = format_date($real_start, $pre_tf . $timeformat, 0) . " - " . format_date($real_duration, $pre_tf . $timeformat, 0);
    $tipBody = $ev_hour_text . (trim(clean($event->getDescription())) != '' ? '<br><br>' . clean($event->getDescription()) : '');
    $tipBody = str_replace(array("\r", "\n"), array(' ', '<br>'), $tipBody);
    if (strlen_utf($tipBody) > 200) {
        $tipBody = substr_utf($tipBody, 0, strpos($tipBody, ' ', 200)) . ' ...';
    }
    ?>
												<script>
													if (<?php 
    echo $top;
    ?>
 < scroll_to || scroll_to == -1) {
														scroll_to = <?php 
    echo $top;