2005-12-19 05:23:14 +01:00
|
|
|
<?php
|
2006-08-26 18:32:29 +02:00
|
|
|
/**
|
|
|
|
* TimeSheet - user interface
|
|
|
|
*
|
|
|
|
* @link http://www.egroupware.org
|
|
|
|
* @author Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
|
|
|
* @package timesheet
|
2008-03-09 08:33:42 +01:00
|
|
|
* @copyright (c) 2005-8 by Ralf Becker <RalfBecker-AT-outdoor-training.de>
|
2006-08-26 18:32:29 +02:00
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
2008-04-18 23:09:30 +02:00
|
|
|
* @version $Id$
|
2006-08-26 18:32:29 +02:00
|
|
|
*/
|
2005-12-19 05:23:14 +01:00
|
|
|
|
2008-04-18 23:09:30 +02:00
|
|
|
require_once(EGW_INCLUDE_ROOT.'/timesheet/inc/class.botimesheet.inc.php');
|
2005-12-19 05:23:14 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* User interface object of the TimeSheet
|
|
|
|
*/
|
|
|
|
class uitimesheet extends botimesheet
|
|
|
|
{
|
|
|
|
var $public_functions = array(
|
|
|
|
'view' => true,
|
|
|
|
'edit' => true,
|
|
|
|
'index' => true,
|
|
|
|
);
|
2006-09-12 17:21:23 +02:00
|
|
|
/**
|
2007-03-08 12:22:57 +01:00
|
|
|
* ProjectManager integration: 'none', 'full' or default null
|
2006-09-12 17:21:23 +02:00
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
var $pm_integration;
|
2005-12-19 05:23:14 +01:00
|
|
|
|
2007-03-08 12:22:57 +01:00
|
|
|
/**
|
|
|
|
* TimeSheet view type: 'short' or 'normal'
|
|
|
|
*
|
|
|
|
* @var string
|
2008-04-18 23:09:30 +02:00
|
|
|
*/
|
2007-03-08 12:22:57 +01:00
|
|
|
var $ts_viewtype;
|
2008-04-18 23:09:30 +02:00
|
|
|
|
2005-12-19 05:23:14 +01:00
|
|
|
function uitimesheet()
|
|
|
|
{
|
|
|
|
$this->botimesheet();
|
2008-04-18 23:09:30 +02:00
|
|
|
|
2008-03-09 08:33:42 +01:00
|
|
|
$this->pm_integration = $this->config_data['pm_integration'];
|
|
|
|
$this->ts_viewtype = $this->config_data['ts_viewtype'];
|
2007-03-08 12:22:57 +01:00
|
|
|
|
|
|
|
// our javascript
|
|
|
|
// to be moved in a seperate file if rewrite is over
|
|
|
|
$GLOBALS['egw_info']['flags']['java_script'] .= $this->js();
|
2005-12-19 05:23:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function view()
|
|
|
|
{
|
|
|
|
$this->edit(null,true);
|
|
|
|
}
|
2008-04-18 23:09:30 +02:00
|
|
|
|
2005-12-19 05:23:14 +01:00
|
|
|
function edit($content = null,$view = false)
|
|
|
|
{
|
2007-03-08 12:22:57 +01:00
|
|
|
$tabs = 'general|notes|links|customfields';
|
2006-09-12 17:21:23 +02:00
|
|
|
$etpl =& new etemplate('timesheet.edit');
|
2005-12-19 05:23:14 +01:00
|
|
|
|
|
|
|
if (!is_array($content))
|
|
|
|
{
|
|
|
|
if ($view || (int)$_GET['ts_id'])
|
|
|
|
{
|
|
|
|
if (!$this->read((int)$_GET['ts_id']))
|
|
|
|
{
|
|
|
|
$GLOBALS['egw']->common->egw_header();
|
|
|
|
echo "<script>alert('".lang('Permission denied!!!')."'); window.close();</script>\n";
|
|
|
|
$GLOBALS['egw']->common->egw_exit();
|
|
|
|
}
|
|
|
|
if (!$view && !$this->check_acl(EGW_ACL_EDIT))
|
|
|
|
{
|
|
|
|
$view = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // new entry
|
|
|
|
{
|
|
|
|
$this->data = array(
|
|
|
|
'ts_start' => $this->today,
|
2006-09-12 12:37:13 +02:00
|
|
|
'end_time' => $this->now - $this->today,
|
2005-12-19 05:23:14 +01:00
|
|
|
'ts_owner' => $GLOBALS['egw_info']['user']['account_id'],
|
|
|
|
'cat_id' => (int) $_REQUEST['cat_id'],
|
|
|
|
);
|
|
|
|
}
|
2008-04-18 23:09:30 +02:00
|
|
|
$referer = preg_match('/menuaction=([^&]+)/',$_SERVER['HTTP_REFERER'],$matches) ? $matches[1] :
|
2007-05-09 10:21:26 +02:00
|
|
|
(strpos($_SERVER['HTTP_REFERER'],'/infolog/index.php') !== false ? 'infolog.uiinfolog.index' : TIMESHEET_APP.'.uitimesheet.index');
|
2005-12-19 05:23:14 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-06-25 19:00:41 +02:00
|
|
|
//echo "<p>ts_start=$content[ts_start], start_time=$content[start_time], end_time=$content[end_time], ts_duration=$content[ts_duration], ts_quantity=$content[ts_quantity]</p>\n";
|
2006-09-12 12:37:13 +02:00
|
|
|
// we only need 2 out of 3 values from start-, end-time or duration (the date in ts_start is always required!)
|
|
|
|
if ($content['start_time']) // start-time specified
|
|
|
|
{
|
|
|
|
$content['ts_start'] += $content['start_time'];
|
|
|
|
}
|
2006-09-15 12:54:34 +02:00
|
|
|
if ($content['end_time'] && $content['start_time']) // start- & end-time --> calculate the duration
|
2006-09-12 12:37:13 +02:00
|
|
|
{
|
2006-09-15 12:54:34 +02:00
|
|
|
$content['ts_duration'] = ($content['end_time'] - $content['start_time']) / 60;
|
2006-09-12 12:37:13 +02:00
|
|
|
}
|
2006-09-15 12:54:34 +02:00
|
|
|
elseif ($content['ts_duration'] && $content['end_time']) // no start, calculate from end and duration
|
2006-09-12 12:37:13 +02:00
|
|
|
{
|
2006-09-15 12:54:34 +02:00
|
|
|
$content['ts_start'] += $content['end_time'] - 60*$content['ts_duration'];
|
2006-09-12 12:37:13 +02:00
|
|
|
}
|
2006-10-19 20:52:18 +02:00
|
|
|
if ($content['ts_duration'] > 0) unset($content['end_time']);
|
2006-09-12 12:37:13 +02:00
|
|
|
// now we only deal with start (date+time) and duration
|
2006-01-11 06:17:15 +01:00
|
|
|
list($button) = @each($content['button']);
|
2005-12-19 05:23:14 +01:00
|
|
|
$view = $content['view'];
|
|
|
|
$referer = $content['referer'];
|
|
|
|
$this->data = $content;
|
2006-09-12 17:21:23 +02:00
|
|
|
foreach(array('button','view','referer',$tabs,'start_time') as $key)
|
2005-12-19 05:23:14 +01:00
|
|
|
{
|
|
|
|
unset($this->data[$key]);
|
|
|
|
}
|
|
|
|
switch($button)
|
|
|
|
{
|
|
|
|
case 'edit':
|
|
|
|
if ($this->check_acl(EGW_ACL_EDIT)) $view = false;
|
|
|
|
break;
|
2008-04-18 23:09:30 +02:00
|
|
|
|
2005-12-19 05:23:14 +01:00
|
|
|
case 'save':
|
|
|
|
case 'save_new':
|
|
|
|
case 'apply':
|
2006-09-12 17:21:23 +02:00
|
|
|
if (!$this->data['ts_quantity'] && $this->data['ts_duration']) // set the quantity (in h) from the duration (in min)
|
2005-12-19 05:23:14 +01:00
|
|
|
{
|
|
|
|
$this->data['ts_quantity'] = $this->data['ts_duration'] / 60.0;
|
|
|
|
}
|
2006-09-12 17:21:23 +02:00
|
|
|
if (!$this->data['ts_quantity'])
|
|
|
|
{
|
|
|
|
$etpl->set_validation_error('ts_quantity',lang('Field must not be empty !!!'));
|
|
|
|
}
|
2007-06-25 19:00:41 +02:00
|
|
|
if ($this->data['ts_duration'] < 0) // for layout purpose we show the error behind the quantity field
|
2006-10-19 20:52:18 +02:00
|
|
|
{
|
|
|
|
$etpl->set_validation_error('ts_quantity',lang('Starttime has to be before endtime !!!'));
|
|
|
|
}
|
2007-06-25 19:00:41 +02:00
|
|
|
//echo "<p>ts_start=$content[ts_start], start_time=$content[start_time], end_time=$content[end_time], ts_duration=$content[ts_duration], ts_quantity=$content[ts_quantity]</p>\n";
|
2005-12-19 05:23:14 +01:00
|
|
|
if (!$this->data['ts_project']) $this->data['ts_project'] = $this->data['ts_project_blur'];
|
2008-04-18 23:09:30 +02:00
|
|
|
// set ts_title to ts_project if short viewtype (title is not editable)
|
|
|
|
if($this->ts_viewtype == 'short')
|
2007-05-25 10:31:05 +02:00
|
|
|
{
|
2008-04-18 23:09:30 +02:00
|
|
|
$this->data['ts_title'] = $this->data['ts_project'];
|
2007-05-25 10:31:05 +02:00
|
|
|
}
|
2006-09-12 17:21:23 +02:00
|
|
|
if (!$this->data['ts_title'])
|
|
|
|
{
|
2008-04-18 23:09:30 +02:00
|
|
|
$this->data['ts_title'] = $this->data['ts_title_blur'] ?
|
2007-06-09 16:56:49 +02:00
|
|
|
$this->data['ts_title_blur'] : $this->data['ts_project_blur'];
|
|
|
|
|
|
|
|
if (!$this->data['ts_title'])
|
|
|
|
{
|
|
|
|
$etpl->set_validation_error('ts_title',lang('Field must not be empty !!!'));
|
|
|
|
}
|
2006-09-12 17:21:23 +02:00
|
|
|
}
|
|
|
|
if ($etpl->validation_errors()) break; // the user need to fix the error, before we can save the entry
|
2005-12-19 05:23:14 +01:00
|
|
|
|
|
|
|
if ($this->save() != 0)
|
|
|
|
{
|
|
|
|
$msg = lang('Error saving the entry!!!');
|
|
|
|
$button = '';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$msg = lang('Entry saved');
|
2006-01-11 06:17:15 +01:00
|
|
|
if ((int) $this->data['pm_id'] != (int) $this->data['old_pm_id'])
|
|
|
|
{
|
|
|
|
// update links accordingly
|
|
|
|
if ($this->data['pm_id'])
|
|
|
|
{
|
2008-03-09 08:33:42 +01:00
|
|
|
egw_link::link(TIMESHEET_APP,$content['link_to']['to_id'],'projectmanager',$this->data['pm_id']);
|
2006-01-11 06:17:15 +01:00
|
|
|
}
|
|
|
|
if ($this->data['old_pm_id'])
|
|
|
|
{
|
2008-03-09 08:33:42 +01:00
|
|
|
egw_link::unlink2(0,TIMESHEET_APP,$content['link_to']['to_id'],0,'projectmanager',$this->data['old_pm_id']);
|
2006-01-11 06:17:15 +01:00
|
|
|
unset($this->data['old_pm_id']);
|
|
|
|
}
|
|
|
|
}
|
2005-12-19 05:23:14 +01:00
|
|
|
if (is_array($content['link_to']['to_id']) && count($content['link_to']['to_id']))
|
|
|
|
{
|
2008-03-09 08:33:42 +01:00
|
|
|
egw_link::link(TIMESHEET_APP,$this->data['ts_id'],$content['link_to']['to_id']);
|
2005-12-19 05:23:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$js = "opener.location.href='".$GLOBALS['egw']->link('/index.php',array(
|
|
|
|
'menuaction' => $referer,
|
|
|
|
'msg' => $msg,
|
|
|
|
))."';";
|
|
|
|
if ($button == 'apply') break;
|
|
|
|
if ($button == 'save_new')
|
|
|
|
{
|
2006-09-12 12:37:13 +02:00
|
|
|
$msg .= ', '.lang('creating new entry'); // giving some feedback to the user
|
|
|
|
|
|
|
|
if (!is_array($content['link_to']['to_id'])) // set links again, so new entry gets the same links as the existing one
|
|
|
|
{
|
|
|
|
$content['link_to']['to_id'] = 0;
|
2008-06-06 07:28:38 +02:00
|
|
|
foreach(egw_link::get_links(TIMESHEET_APP,$this->data['ts_id'],'!'.egw_link::VFS_APPNAME) as $link)
|
2006-09-12 12:37:13 +02:00
|
|
|
{
|
2008-03-09 08:33:42 +01:00
|
|
|
egw_link::link(TIMESHEET_APP,$content['link_to']['to_id'],$link['app'],$link['id'],$link['remark']);
|
2006-09-12 12:37:13 +02:00
|
|
|
}
|
|
|
|
}
|
2005-12-19 05:23:14 +01:00
|
|
|
// create a new entry
|
|
|
|
$this->data['ts_start'] += 60 * $this->data['ts_duration'];
|
|
|
|
foreach(array('ts_id','ts_title','ts_description','ts_duration','ts_quantity','ts_modified','ts_modifier') as $name)
|
|
|
|
{
|
|
|
|
unset($this->data[$name]);
|
|
|
|
}
|
2007-06-07 11:13:55 +02:00
|
|
|
// save the selected project, to delete the project-link, if the user changes the project
|
|
|
|
$this->data['old_pm_id'] = $this->data['pm_id'];
|
2005-12-19 05:23:14 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
// fall-through for save
|
|
|
|
case 'delete':
|
|
|
|
if ($button == 'delete')
|
|
|
|
{
|
2006-01-11 06:17:15 +01:00
|
|
|
if ($this->delete())
|
|
|
|
{
|
|
|
|
$msg = lang('Entry deleted');
|
|
|
|
$js = "opener.location.href=opener.location.href+'&msg=$msg';";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$msg = lang('Error deleting the entry!!!');
|
|
|
|
break; // dont close window
|
|
|
|
}
|
2005-12-19 05:23:14 +01:00
|
|
|
}
|
2006-01-11 06:17:15 +01:00
|
|
|
// fall-through for save
|
2005-12-19 05:23:14 +01:00
|
|
|
case 'cancel':
|
|
|
|
$js .= 'window.close();';
|
|
|
|
echo "<html>\n<body>\n<script>\n$js\n</script>\n</body>\n</html>\n";
|
|
|
|
$GLOBALS['egw']->common->egw_exit();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$preserv = $this->data + array(
|
|
|
|
'view' => $view,
|
|
|
|
'referer' => $referer,
|
2006-03-21 14:52:49 +01:00
|
|
|
'ts_title_blur' => $content['ts_title_blur'],
|
2005-12-19 05:23:14 +01:00
|
|
|
);
|
2006-01-11 06:17:15 +01:00
|
|
|
$content = array_merge($this->data,array(
|
2005-12-19 05:23:14 +01:00
|
|
|
'msg' => $msg,
|
|
|
|
'view' => $view,
|
|
|
|
$tabs => $content[$tabs],
|
|
|
|
'link_to' => array(
|
2006-09-12 12:37:13 +02:00
|
|
|
'to_id' => $this->data['ts_id'] ? $this->data['ts_id'] : $content['link_to']['to_id'],
|
2005-12-19 05:23:14 +01:00
|
|
|
'to_app' => TIMESHEET_APP,
|
|
|
|
),
|
|
|
|
'js' => "<script>\n$js\n</script>\n",
|
2006-03-27 14:20:06 +02:00
|
|
|
'ts_quantity_blur' => $this->data['ts_duration'] ? round($this->data['ts_duration'] / 60.0,3) : '',
|
2006-09-12 12:37:13 +02:00
|
|
|
'start_time' => $this->datetime2time($this->data['ts_start']),
|
2006-09-12 17:21:23 +02:00
|
|
|
'pm_integration' => $this->pm_integration,
|
2006-01-11 06:17:15 +01:00
|
|
|
));
|
2006-02-08 19:30:20 +01:00
|
|
|
$links = array();
|
2006-03-21 14:52:49 +01:00
|
|
|
// create links specified in the REQUEST (URL)
|
|
|
|
if (!$this->data['ts_id'] && isset($_REQUEST['link_app']) && isset($_REQUEST['link_id']) && !is_array($content['link_to']['to_id']))
|
2005-12-19 05:23:14 +01:00
|
|
|
{
|
2006-03-21 14:52:49 +01:00
|
|
|
$link_ids = is_array($_REQUEST['link_id']) ? $_REQUEST['link_id'] : array($_REQUEST['link_id']);
|
|
|
|
foreach(is_array($_REQUEST['link_app']) ? $_REQUEST['link_app'] : array($_REQUEST['link_app']) as $n => $link_app)
|
2005-12-19 05:23:14 +01:00
|
|
|
{
|
2006-03-21 14:52:49 +01:00
|
|
|
$link_id = $link_ids[$n];
|
|
|
|
if (preg_match('/^[a-z_0-9-]+:[:a-z_0-9-]+$/i',$link_app.':'.$link_id)) // gard against XSS
|
|
|
|
{
|
2008-03-09 08:33:42 +01:00
|
|
|
egw_link::link(TIMESHEET_APP,$content['link_to']['to_id'],$link_app,$link_id);
|
2006-03-21 14:52:49 +01:00
|
|
|
switch ($link_app)
|
|
|
|
{
|
|
|
|
case 'projectmanager':
|
|
|
|
$links[] = $link_id;
|
|
|
|
break;
|
|
|
|
case 'infolog':
|
2007-06-07 11:13:55 +02:00
|
|
|
// a preserved title blur is only set for other (non-project) links, it stays with Save&New!
|
2008-03-09 08:33:42 +01:00
|
|
|
$preserv['ts_title_blur'] = egw_link::title('infolog',$link_id);
|
2006-03-21 14:52:49 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2005-12-19 05:23:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
elseif ($this->data['ts_id'])
|
|
|
|
{
|
2008-03-09 08:33:42 +01:00
|
|
|
$links = egw_link::get_links(TIMESHEET_APP,$this->data['ts_id'],'projectmanager');
|
2005-12-19 05:23:14 +01:00
|
|
|
}
|
2007-01-12 02:27:37 +01:00
|
|
|
// make all linked projects availible for the pm-pricelist widget, to be able to choose prices from all
|
|
|
|
$content['all_pm_ids'] = array_values($links);
|
2008-04-18 23:09:30 +02:00
|
|
|
|
2007-05-25 10:31:05 +02:00
|
|
|
// set old id, pm selector (for later removal)
|
2008-04-18 23:09:30 +02:00
|
|
|
if (count($links) > 0)
|
|
|
|
{
|
2007-05-25 10:31:05 +02:00
|
|
|
$preserv['old_pm_id'] = array_shift($links);
|
|
|
|
}
|
2008-04-18 23:09:30 +02:00
|
|
|
if (!isset($this->data['pm_id']) && $preserv['old_pm_id'])
|
2007-06-03 17:01:27 +02:00
|
|
|
{
|
2007-05-25 10:31:05 +02:00
|
|
|
$content['pm_id'] = $preserv['old_pm_id'];
|
|
|
|
}
|
2006-01-11 06:17:15 +01:00
|
|
|
if ($content['pm_id'])
|
2005-12-19 05:23:14 +01:00
|
|
|
{
|
2008-03-09 08:33:42 +01:00
|
|
|
$preserv['ts_project_blur'] = $content['ts_project_blur'] = egw_link::title('projectmanager',$content['pm_id']);
|
2005-12-19 05:23:14 +01:00
|
|
|
}
|
2007-06-03 17:01:27 +02:00
|
|
|
if ($this->pm_integration == 'full')
|
|
|
|
{
|
|
|
|
$preserv['ts_project'] = $preserv['ts_project_blur'];
|
|
|
|
}
|
2007-06-07 11:13:55 +02:00
|
|
|
// the actual title-blur is either the preserved title blur (if we are called from infolog entry),
|
|
|
|
// or the preserved project-blur comming from the current selected project
|
|
|
|
$content['ts_title_blur'] = $preserv['ts_title_blur'] ? $preserv['ts_title_blur'] : $preserv['ts_project_blur'];
|
2006-03-21 14:52:49 +01:00
|
|
|
|
2005-12-19 05:23:14 +01:00
|
|
|
$readonlys = array(
|
|
|
|
'button[delete]' => !$this->data['ts_id'] || !$this->check_acl(EGW_ACL_DELETE),
|
|
|
|
'button[edit]' => !$view || !$this->check_acl(EGW_ACL_EDIT),
|
|
|
|
'button[save]' => $view,
|
|
|
|
'button[save_new]' => $view,
|
|
|
|
'button[apply]' => $view,
|
|
|
|
);
|
|
|
|
if ($view)
|
|
|
|
{
|
2006-01-11 06:17:15 +01:00
|
|
|
foreach(array_merge(array_keys($this->data),array('pm_id','pl_id','link_to')) as $key)
|
2005-12-19 05:23:14 +01:00
|
|
|
{
|
|
|
|
$readonlys[$key] = true;
|
|
|
|
}
|
2006-11-20 15:17:28 +01:00
|
|
|
$readonlys['start_time'] = $readonlys['end_time'] = true;
|
2005-12-19 05:23:14 +01:00
|
|
|
}
|
|
|
|
$edit_grants = $this->grant_list(EGW_ACL_EDIT);
|
|
|
|
if (count($edit_grants) == 1)
|
|
|
|
{
|
|
|
|
$readonlys['ts_owner'] = true;
|
|
|
|
}
|
|
|
|
$GLOBALS['egw_info']['flags']['app_header'] = lang('timesheet').' - '.
|
|
|
|
($view ? lang('View') : ($this->data['ts_id'] ? lang('Edit') : lang('Add')));
|
2008-04-18 23:09:30 +02:00
|
|
|
|
2006-01-11 06:17:15 +01:00
|
|
|
// supress unknow widget 'projectmanager-*', if projectmanager is not installed or old
|
|
|
|
if (!@file_exists(EGW_INCLUDE_ROOT.'/projectmanager/inc/class.projectmanager_widget.inc.php'))
|
|
|
|
{
|
|
|
|
$etpl->set_cell_attribute('pm_id','disabled',true);
|
|
|
|
$etpl->set_cell_attribute('pl_id','disabled',true);
|
2008-04-18 23:09:30 +02:00
|
|
|
}
|
2007-03-08 12:22:57 +01:00
|
|
|
|
2008-04-18 23:09:30 +02:00
|
|
|
if($this->ts_viewtype == 'short')
|
2007-06-03 17:01:27 +02:00
|
|
|
{
|
|
|
|
$content['ts_viewtype'] = $readonlys[$tabs]['notes'] = true;
|
2007-03-08 12:22:57 +01:00
|
|
|
}
|
2007-06-03 17:01:27 +02:00
|
|
|
if (!$this->customfields) $readonlys[$tabs]['customfields'] = true; // suppress tab if there are not customfields
|
2008-04-18 23:09:30 +02:00
|
|
|
|
2005-12-19 05:23:14 +01:00
|
|
|
return $etpl->exec(TIMESHEET_APP.'.uitimesheet.edit',$content,array(
|
|
|
|
'ts_owner' => $edit_grants,
|
|
|
|
),$readonlys,$preserv,2);
|
|
|
|
}
|
2008-04-18 23:09:30 +02:00
|
|
|
|
2006-09-12 12:37:13 +02:00
|
|
|
/**
|
|
|
|
* Calculate the time from a timestamp containing date & time
|
|
|
|
*
|
|
|
|
* @param int $datetime
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
function datetime2time($datetime)
|
|
|
|
{
|
|
|
|
if (!$datetime) return 0;
|
|
|
|
|
|
|
|
return $datetime - mktime(0,0,0,date('m',$datetime),date('d',$datetime),date('Y',$datetime));
|
|
|
|
}
|
2005-12-19 05:23:14 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* query projects for nextmatch in the projects-list
|
|
|
|
*
|
|
|
|
* reimplemented from so_sql to disable action-buttons based on the acl and make some modification on the data
|
|
|
|
*
|
2006-03-27 14:20:06 +02:00
|
|
|
* @param array &$query
|
2005-12-19 05:23:14 +01:00
|
|
|
* @param array &$rows returned rows/cups
|
|
|
|
* @param array &$readonlys eg. to disable buttons based on acl
|
2007-03-08 12:22:57 +01:00
|
|
|
* @param boolean $id_only=false if true only return (via $rows) an array of contact-ids, dont save state to session
|
|
|
|
* @return int total number of contacts matching the selection
|
2005-12-19 05:23:14 +01:00
|
|
|
*/
|
2007-03-08 12:22:57 +01:00
|
|
|
function get_rows(&$query_in,&$rows,&$readonlys,$id_only=false)
|
2005-12-19 05:23:14 +01:00
|
|
|
{
|
2006-03-27 14:20:06 +02:00
|
|
|
$this->show_sums = false;
|
|
|
|
if ($query_in['filter'])
|
|
|
|
{
|
|
|
|
$date_filter = $this->date_filter($query_in['filter'],$query_in['startdate'],$query_in['enddate']);
|
2008-04-18 23:09:30 +02:00
|
|
|
|
2006-03-27 14:20:06 +02:00
|
|
|
$start = explode('-',date('Y-m-d',$query_in['startdate']+12*60*60));
|
|
|
|
$end = explode('-',date('Y-m-d',$query_in['enddate'] ? $query_in['enddate'] : $query_in['startdate']+7.5*24*60*60));
|
2008-04-18 23:09:30 +02:00
|
|
|
|
2006-04-05 18:23:44 +02:00
|
|
|
// show year-sums, if we are year-aligned (show full years)?
|
|
|
|
if ((int)$start[2] == 1 && (int)$start[1] == 1 && (int)$end[2] == 31 && (int)$end[1] == 12)
|
|
|
|
{
|
|
|
|
$this->show_sums[] = 'year';
|
|
|
|
}
|
2006-03-27 14:20:06 +02:00
|
|
|
// show month-sums, if we are month-aligned (show full monthes)?
|
|
|
|
if ((int)$start[2] == 1 && (int)$end[2] == (int)date('d',mktime(12,0,0,$end[1]+1,0,$end[0])))
|
|
|
|
{
|
2006-04-05 18:23:44 +02:00
|
|
|
$this->show_sums[] = 'month';
|
2006-03-27 14:20:06 +02:00
|
|
|
}
|
|
|
|
// show week-sums, if we are week-aligned (show full weeks)?
|
|
|
|
$week_start_day = $GLOBALS['egw_info']['user']['preferences']['calendar']['weekdaystarts'];
|
|
|
|
if (!$week_start_day) $week_start_day = 'Sunday';
|
|
|
|
switch($week_start_day)
|
|
|
|
{
|
|
|
|
case 'Sunday': $week_end_day = 'Saturday'; break;
|
|
|
|
case 'Monday': $week_end_day = 'Sunday'; break;
|
|
|
|
case 'Saturday': $week_end_day = 'Friday'; break;
|
|
|
|
}
|
|
|
|
$filter_start_day = date('l',$query_in['startdate']+12*60*60);
|
|
|
|
$filter_end_day = $query_in['enddate'] ? date('l',$query_in['enddate']+12*60*60) : false;
|
|
|
|
//echo "<p align=right>prefs: $week_start_day - $week_end_day, filter: $filter_start_day - $filter_end_day</p>\n";
|
|
|
|
if ($filter_start_day == $week_start_day && (!$filter_end_day || $filter_end_day == $week_end_day))
|
|
|
|
{
|
2006-04-05 18:23:44 +02:00
|
|
|
$this->show_sums[] = 'week';
|
2006-03-27 14:20:06 +02:00
|
|
|
}
|
|
|
|
// show day-sums, if range <= 5 weeks
|
|
|
|
if (!$query_in['enddate'] || $query_in['enddate'] - $query_in['startdate'] < 36*24*60*60)
|
|
|
|
{
|
2006-04-05 18:23:44 +02:00
|
|
|
$this->show_sums[] = 'day';
|
2006-03-27 14:20:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
//echo "<p align=right>show_sums=".print_r($this->show_sums,true)."</p>\n";
|
|
|
|
$GLOBALS['egw']->session->appsession('index',TIMESHEET_APP,$query_in);
|
|
|
|
$query = $query_in; // keep the original query
|
2006-09-12 17:21:23 +02:00
|
|
|
|
|
|
|
// PM project filter for the PM integration
|
|
|
|
if ((string)$query['col_filter']['pm_id'] != '')
|
|
|
|
{
|
2008-03-09 08:33:42 +01:00
|
|
|
//$query['col_filter']['ts_id'] = egw_link::get_links('projectmanager',$query['col_filter']['pm_id'],'timesheet');
|
2007-03-08 12:22:57 +01:00
|
|
|
$query['col_filter']['ts_id'] = $this->get_ts_links($query['col_filter']['pm_id']);
|
2006-11-20 15:17:28 +01:00
|
|
|
if (!$query['col_filter']['ts_id']) $query['col_filter']['ts_id'] = 0;
|
2006-09-12 17:21:23 +02:00
|
|
|
}
|
|
|
|
unset($query['col_filter']['pm_id']);
|
2008-04-18 23:09:30 +02:00
|
|
|
|
2006-09-12 17:21:23 +02:00
|
|
|
// filter for no project
|
|
|
|
if ((string)$query['col_filter']['ts_project'] == '0') $query['col_filter']['ts_project'] = null;
|
|
|
|
|
2006-03-27 14:20:06 +02:00
|
|
|
if ((int)$query['filter2'] != (int)$GLOBALS['egw_info']['user']['preferences'][TIMESHEET_APP]['show_details'])
|
|
|
|
{
|
|
|
|
$GLOBALS['egw']->preferences->add(TIMESHEET_APP,'show_details',(int)$query['filter2']);
|
|
|
|
$GLOBALS['egw']->preferences->save_repository(true);
|
|
|
|
}
|
2006-09-12 17:21:23 +02:00
|
|
|
// category filter: cat_id or ''=All cats or 0=No cat
|
2005-12-19 05:23:14 +01:00
|
|
|
if ($query['cat_id'])
|
|
|
|
{
|
|
|
|
$cats = $GLOBALS['egw']->categories->return_all_children((int)$query['cat_id']);
|
|
|
|
$query['col_filter']['cat_id'] = count($cats) > 1 ? $cats : $query['cat_id'];
|
|
|
|
}
|
2006-09-12 17:21:23 +02:00
|
|
|
elseif ((string)$query['cat_id'] == '0') // no category
|
|
|
|
{
|
|
|
|
$query['col_filter']['cat_id'] = null;
|
|
|
|
}
|
|
|
|
else // all cats --> no filter
|
|
|
|
{
|
|
|
|
unset($query['col_filter']['cat_id']);
|
|
|
|
}
|
2006-03-21 23:18:29 +01:00
|
|
|
$GLOBALS['egw_info']['flags']['app_header'] = lang('timesheet');
|
|
|
|
if ($query['col_filter']['ts_owner'])
|
2005-12-19 05:23:14 +01:00
|
|
|
{
|
2006-03-21 23:18:29 +01:00
|
|
|
$GLOBALS['egw_info']['flags']['app_header'] .= ': '.$GLOBALS['egw']->common->grab_owner_name($query['col_filter']['ts_owner']);
|
2005-12-19 05:23:14 +01:00
|
|
|
}
|
2006-03-21 23:18:29 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
unset($query['col_filter']['ts_owner']);
|
|
|
|
}
|
|
|
|
if ($query['filter'])
|
|
|
|
{
|
2006-03-27 14:20:06 +02:00
|
|
|
$query['col_filter'][0] = $date_filter;
|
2008-04-18 23:09:30 +02:00
|
|
|
|
2006-03-27 14:20:06 +02:00
|
|
|
// generate a meaningful app-header / report title
|
|
|
|
if ($this->show_sums['month'])
|
2006-03-21 23:18:29 +01:00
|
|
|
{
|
2006-03-27 14:20:06 +02:00
|
|
|
if ((int)$start[1] == 1 && (int) $end[1] == 12) // whole year(s)
|
2006-03-21 23:18:29 +01:00
|
|
|
{
|
2006-03-27 14:20:06 +02:00
|
|
|
$GLOBALS['egw_info']['flags']['app_header'] .= ': ' . $start[0] . ($start[0] != $end[0] ? ' - '.$end[0] : '');
|
2006-03-21 23:18:29 +01:00
|
|
|
}
|
2006-03-27 14:20:06 +02:00
|
|
|
else
|
2006-03-21 23:18:29 +01:00
|
|
|
{
|
2006-03-27 14:20:06 +02:00
|
|
|
$GLOBALS['egw_info']['flags']['app_header'] .= ': ' . lang(date('F',$query['startdate']+12*60*60)) . ' ' . $start[0];
|
|
|
|
if ($start[0] != $end[0] || $start[1] != $end[1])
|
|
|
|
{
|
|
|
|
$GLOBALS['egw_info']['flags']['app_header'] .= ' - ' . lang(date('F',$query['enddate']+12*60*60)) . ' ' . $end[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elseif ($this->show_sums['week'])
|
|
|
|
{
|
|
|
|
$GLOBALS['egw_info']['flags']['app_header'] .= ': ' . lang('week') . ' ' . date('W',$query['startdate']+36*60*60) . '/' . $start[0];
|
|
|
|
if ($query['enddate'] && $query['enddate'] - $query['startdate'] > 10*24*60*60)
|
|
|
|
{
|
|
|
|
$GLOBALS['egw_info']['flags']['app_header'] .= ' - ' . date('W',$query['enddate']-36*60*60) . '/' . $end[0];
|
2006-03-21 23:18:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-03-27 14:20:06 +02:00
|
|
|
$df = $GLOBALS['egw_info']['user']['preferences']['common']['dateformat'];
|
|
|
|
$GLOBALS['egw_info']['flags']['app_header'] .= ': ' . $GLOBALS['egw']->common->show_date($query['startdate']+12*60*60,$df,false);
|
|
|
|
if ($start != $end)
|
|
|
|
{
|
|
|
|
$GLOBALS['egw_info']['flags']['app_header'] .= ' - '.$GLOBALS['egw']->common->show_date($query['enddate']+12*60*60,$df,false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($query['filter'] == 'custom') // show the custome dates
|
|
|
|
{
|
|
|
|
$GLOBALS['egw']->js->set_onload("set_style_by_class('*','custom_hide','visibility','visible');");
|
2006-03-21 23:18:29 +01:00
|
|
|
}
|
|
|
|
}
|
2005-12-19 05:23:14 +01:00
|
|
|
$total = parent::get_rows($query,$rows,$readonlys);
|
2008-04-18 23:09:30 +02:00
|
|
|
|
2008-03-09 08:33:42 +01:00
|
|
|
$ids = array();
|
|
|
|
foreach($rows as $row)
|
|
|
|
{
|
|
|
|
$ids[] = $row['ts_id'];
|
|
|
|
}
|
2007-03-08 12:22:57 +01:00
|
|
|
if ($id_only)
|
|
|
|
{
|
2008-03-09 08:33:42 +01:00
|
|
|
$rows = $ids;
|
2007-03-08 12:22:57 +01:00
|
|
|
return $this->total; // no need to set other fields or $readonlys
|
|
|
|
}
|
2008-03-09 08:33:42 +01:00
|
|
|
$links = egw_link::get_links_multiple(TIMESHEET_APP,$ids);
|
2007-03-08 12:22:57 +01:00
|
|
|
|
2005-12-19 05:23:14 +01:00
|
|
|
unset($query['col_filter'][0]);
|
2008-04-18 23:09:30 +02:00
|
|
|
|
2005-12-19 05:23:14 +01:00
|
|
|
$readonlys = array();
|
2006-09-20 15:31:41 +02:00
|
|
|
$have_cats = false;
|
2008-03-09 08:33:42 +01:00
|
|
|
foreach($rows as &$row)
|
2005-12-19 05:23:14 +01:00
|
|
|
{
|
2006-09-20 15:31:41 +02:00
|
|
|
if ($row['cat_id']) $have_cats = true;
|
|
|
|
|
2006-03-27 00:11:58 +02:00
|
|
|
$row['class'] = 'row';
|
|
|
|
if ($row['ts_id'] <= 0) // sums
|
|
|
|
{
|
|
|
|
$readonlys["view[$row[ts_id]]"] = $readonlys["edit[$row[ts_id]]"] = $readonlys["delete[$row[ts_id]]"] = true;
|
|
|
|
if ($query['sort'] == 'ASC') $row['ts_start'] -= 7200; // fix for DSL change
|
|
|
|
switch($row['ts_id'])
|
|
|
|
{
|
|
|
|
case 0: // day-sum
|
|
|
|
$row['ts_title'] = lang('Sum %1:',lang(date('l',$row['ts_start'])).' '.$GLOBALS['egw']->common->show_date($row['ts_start'],
|
|
|
|
$GLOBALS['egw_info']['user']['preferences']['common']['dateformat'],false));
|
|
|
|
break;
|
|
|
|
case -1: // week-sum
|
2006-04-05 18:23:44 +02:00
|
|
|
$row['ts_title'] = lang('Sum %1:',lang('week').' '.substr($row['ts_week'],4).'/'.substr($row['ts_week'],0,4));
|
2006-03-27 00:11:58 +02:00
|
|
|
break;
|
|
|
|
case -2: // month-sum
|
2006-04-05 18:23:44 +02:00
|
|
|
$row['ts_title'] = lang('Sum %1:',lang(date('F',$row['ts_start'])).' '.substr($row['ts_month'],0,4));
|
|
|
|
break;
|
|
|
|
case -3: // year-sum
|
|
|
|
$row['ts_title'] = lang('Sum %1:',$row['ts_year']);
|
2006-03-27 00:11:58 +02:00
|
|
|
break;
|
2008-04-18 23:09:30 +02:00
|
|
|
}
|
2007-07-10 09:34:30 +02:00
|
|
|
$row['ts_start'] = $row['ts_unitprice'] = '';
|
|
|
|
if (!$this->quantity_sum) $row['ts_quantity'] = '';
|
2006-03-27 00:11:58 +02:00
|
|
|
$row['class'] = 'th';
|
|
|
|
$row['titleClass'] = 'titleSum';
|
|
|
|
continue;
|
|
|
|
}
|
2005-12-19 05:23:14 +01:00
|
|
|
if (!$this->check_acl(EGW_ACL_EDIT,$row))
|
|
|
|
{
|
|
|
|
$readonlys["edit[$row[ts_id]]"] = true;
|
|
|
|
}
|
|
|
|
if (!$this->check_acl(EGW_ACL_DELETE,$row))
|
|
|
|
{
|
|
|
|
$readonlys["delete[$row[ts_id]]"] = true;
|
|
|
|
}
|
|
|
|
if ($query['col_filter']['ts_project'] || !$query['filter2'])
|
|
|
|
{
|
|
|
|
unset($row['ts_project']); // dont need or want to show it
|
|
|
|
}
|
2008-03-09 08:33:42 +01:00
|
|
|
elseif ($links[$row['ts_id']])
|
2005-12-19 05:23:14 +01:00
|
|
|
{
|
2008-03-09 08:33:42 +01:00
|
|
|
foreach($links[$row['ts_id']] as $link)
|
2005-12-19 05:23:14 +01:00
|
|
|
{
|
2008-03-09 08:33:42 +01:00
|
|
|
if ($link['app'] == 'projectmanager')
|
|
|
|
{
|
|
|
|
$row['ts_link'] = $link;
|
|
|
|
$row['ts_link']['title'] = $row['ts_project'];
|
|
|
|
break;
|
|
|
|
}
|
2005-12-19 05:23:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!$query['filter2'])
|
|
|
|
{
|
|
|
|
unset($row['ts_description']);
|
|
|
|
}
|
2006-03-27 00:11:58 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
$row['titleClass'] = 'titleDetails';
|
|
|
|
}
|
2005-12-19 05:23:14 +01:00
|
|
|
}
|
2007-03-07 13:31:48 +01:00
|
|
|
if (!$have_cats || $query['cat_id']) $rows['no_cat_id'] = true;
|
2006-03-27 14:20:06 +02:00
|
|
|
if ($query['col_filter']['ts_owner']) $rows['ownerClass'] = 'noPrint';
|
2005-12-19 05:23:14 +01:00
|
|
|
$rows['no_owner_col'] = $query['no_owner_col'];
|
|
|
|
if ($query['filter'])
|
|
|
|
{
|
2007-07-10 09:34:30 +02:00
|
|
|
$rows += $this->summary;
|
2005-12-19 05:23:14 +01:00
|
|
|
}
|
2006-09-12 17:21:23 +02:00
|
|
|
$rows['pm_integration'] = $this->pm_integration;
|
|
|
|
|
2007-03-08 12:22:57 +01:00
|
|
|
if($this->ts_viewtype == 'short') {
|
|
|
|
$rows['ts_viewtype'] = true;
|
|
|
|
}
|
2008-04-18 23:09:30 +02:00
|
|
|
|
|
|
|
return $total;
|
2005-12-19 05:23:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List timesheet entries
|
|
|
|
*
|
|
|
|
* @param array $content=null
|
2006-09-12 17:21:23 +02:00
|
|
|
* @param string $msg=''
|
2005-12-19 05:23:14 +01:00
|
|
|
*/
|
|
|
|
function index($content = null,$msg='')
|
|
|
|
{
|
|
|
|
$etpl =& new etemplate('timesheet.index');
|
2008-04-18 23:09:30 +02:00
|
|
|
|
2005-12-19 05:23:14 +01:00
|
|
|
if ($_GET['msg']) $msg = $_GET['msg'];
|
2008-04-18 23:09:30 +02:00
|
|
|
|
2006-01-11 06:17:15 +01:00
|
|
|
if ($content['nm']['rows']['delete'])
|
|
|
|
{
|
|
|
|
list($ts_id) = each($content['nm']['rows']['delete']);
|
|
|
|
if ($this->delete($ts_id))
|
|
|
|
{
|
|
|
|
$msg = lang('Entry deleted');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$msg = lang('Error deleting the entry!!!');
|
|
|
|
}
|
|
|
|
}
|
2005-12-19 05:23:14 +01:00
|
|
|
$content = array(
|
|
|
|
'nm' => $GLOBALS['egw']->session->appsession('index',TIMESHEET_APP),
|
|
|
|
'msg' => $msg,
|
2008-04-18 23:09:30 +02:00
|
|
|
);
|
2005-12-19 05:23:14 +01:00
|
|
|
if (!is_array($content['nm']))
|
|
|
|
{
|
|
|
|
$date_filters = array('All');
|
|
|
|
foreach($this->date_filters as $name => $date)
|
|
|
|
{
|
|
|
|
$date_filters[$name] = $name;
|
|
|
|
}
|
2006-03-21 23:18:29 +01:00
|
|
|
$date_filters['custom'] = 'custom';
|
|
|
|
|
2005-12-19 05:23:14 +01:00
|
|
|
$content['nm'] = array(
|
|
|
|
'get_rows' => TIMESHEET_APP.'.uitimesheet.get_rows',
|
|
|
|
'options-filter' => $date_filters,
|
|
|
|
'options-filter2' => array('No details','Details'),
|
|
|
|
'order' => 'ts_start',// IO name of the column to sort after (optional for the sortheaders)
|
|
|
|
'sort' => 'DESC',// IO direction of the sort: 'ASC' or 'DESC'
|
2006-09-12 12:37:13 +02:00
|
|
|
'header_left' => 'timesheet.index.dates',
|
|
|
|
'header_right' => 'timesheet.index.add',
|
2006-03-21 23:18:29 +01:00
|
|
|
'filter_onchange' => "set_style_by_class('*','custom_hide','visibility',this.value == 'custom' ? 'visible' : 'hidden'); if (this.value != 'custom') this.form.submit();",
|
2006-03-27 14:20:06 +02:00
|
|
|
'filter2' => (int)$GLOBALS['egw_info']['user']['preferences'][TIMESHEET_APP]['show_details'],
|
2005-12-19 05:23:14 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
$read_grants = $this->grant_list(EGW_ACL_READ);
|
|
|
|
$content['nm']['no_owner_col'] = count($read_grants) == 1;
|
2008-04-18 23:09:30 +02:00
|
|
|
|
2006-09-14 20:31:46 +02:00
|
|
|
$sel_options = array(
|
2005-12-19 05:23:14 +01:00
|
|
|
'ts_owner' => $read_grants,
|
2006-09-12 17:21:23 +02:00
|
|
|
'pm_id' => array(lang('No project')),
|
|
|
|
'cat_id' => array(lang('None')),
|
2006-09-14 20:31:46 +02:00
|
|
|
);
|
|
|
|
if ($this->pm_integration != 'full')
|
|
|
|
{
|
|
|
|
$projects =& $this->query_list('ts_project');
|
|
|
|
if (!is_array($projects)) $projects = array();
|
|
|
|
$sel_options['ts_project'] = $projects + array(lang('No project'));
|
|
|
|
}
|
2007-05-09 10:21:26 +02:00
|
|
|
// dont show [Export] button if app is not availible to the user or we are on php4
|
|
|
|
$readonlys['export'] = !$GLOBALS['egw_info']['user']['apps']['importexport'] || (int) phpversion() < 5;
|
|
|
|
|
2006-09-14 20:31:46 +02:00
|
|
|
return $etpl->exec(TIMESHEET_APP.'.uitimesheet.index',$content,$sel_options,$readonlys,$preserv);
|
2005-12-19 05:23:14 +01:00
|
|
|
}
|
2007-03-08 12:22:57 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function js()
|
|
|
|
{
|
|
|
|
return '<script LANGUAGE="JavaScript">
|
|
|
|
|
|
|
|
function timesheet_export()
|
|
|
|
{
|
|
|
|
egw_openWindowCentered(
|
|
|
|
"'. $GLOBALS['egw']->link('/index.php','menuaction=importexport.uiexport.export_dialog&appname=timesheet&selection=use_all') . '",
|
|
|
|
"Export",400,400);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
</script>';
|
|
|
|
}
|
|
|
|
|
2006-01-11 06:17:15 +01:00
|
|
|
}
|