phpgroupware-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Phpgroupware-cvs] projects/inc class.uiprojecthours.inc.php, 1.82 class


From: ceb
Subject: [Phpgroupware-cvs] projects/inc class.uiprojecthours.inc.php, 1.82 class.uiconfig.inc.php, 1.30 class.uiprojects.inc.php, 1.153 class.uistatistics.inc.php, 1.56 hook_home.inc.php, 1.4 hook_admin.inc.php, 1.21 class.soprojects.inc.php, 1.107 class.soprojecthours.inc.php, 1.39 class.attached_files.inc.php, 1.2 class.boconfig.inc.php, 1.21 class.boprojecthours.inc.php, 1.35 class.soconfig.inc.php, 1.18 class.boprojects.inc.php, 1.151 hook_sidebox_menu.inc.php, 1.12
Date: Mon, 14 Mar 2005 18:39:00 +0100

Update of projects/inc

Modified Files:
     Branch: MAIN
            class.uiprojecthours.inc.php lines: +1112 -394
            class.uiconfig.inc.php lines: +438 -94
            class.uiprojects.inc.php lines: +1332 -659
            class.uistatistics.inc.php lines: +442 -162
            hook_home.inc.php lines: +16 -14
            hook_admin.inc.php lines: +6 -2
            class.soprojects.inc.php lines: +288 -75
            class.soprojecthours.inc.php lines: +186 -67
            class.attached_files.inc.php lines: +11 -5
            class.boconfig.inc.php lines: +348 -21
            class.boprojecthours.inc.php lines: +495 -55
            class.soconfig.inc.php lines: +39 -12
            class.boprojects.inc.php lines: +1736 -149
            hook_sidebox_menu.inc.php lines: +31 -23

Log Message:
update to current projects version

====================================================
Index: projects/inc/class.uiprojecthours.inc.php
diff -u projects/inc/class.uiprojecthours.inc.php:1.81 
projects/inc/class.uiprojecthours.inc.php:1.82
--- projects/inc/class.uiprojecthours.inc.php:1.81      Wed Aug 11 15:05:13 2004
+++ projects/inc/class.uiprojecthours.inc.php   Mon Mar 14 17:39:39 2005
@@ -6,6 +6,7 @@
        *                                                                   *
        * Project Manager                                                   *
        * Written by Bettina Gille address@hidden                   *
+       *            Philipp Kamps address@hidden                 *
        * -----------------------------------------------                   *
        * Copyright 2000 - 2004 Free Software Foundation, Inc.              *
        *                                                                   *
@@ -36,28 +37,37 @@
                var $state;
                var $cat_id;
                var $project_id;
+               var $ui_base;

                var $public_functions = array
                (
-                       'list_hours'    => True,
-                       'edit_hours'    => True,
-                       'delete_hours'  => True,
-                       'view_hours'    => True,
-                       'list_projects' => True,
-                       'ttracker'              => True,
-                       'edit_ttracker' => True
+                       'list_hours'                            => True,
+                       'edit_hours'                            => True,
+                       'delete_hours'                          => True,
+                       'view_hours'                            => True,
+                       'list_projects'                         => True,
+                       'ttracker'                                      => True,
+                       'edit_ttracker'                         => True,
+                       'unbook_hours'                          => True,
+                       'controlling_sheet'                     => True,
+                       'import_controlling_sheet'      => True
                );

                function uiprojecthours()
                {
+                       $this->ui_base                                  = 
CreateObject('projects.uiprojects_base');
+                       $this->boprojects                               = 
$this->ui_base->boprojects;
+
                        $this->bohours                                  = 
CreateObject('projects.boprojecthours');
-                       $this->boprojects                               = 
$this->bohours->boprojects;
+
                        $this->nextmatchs                               = 
CreateObject('phpgwapi.nextmatchs');
-                       //$this->sbox                                           
= CreateObject('phpgwapi.sbox');
                        $this->account                                  = 
$GLOBALS['phpgw_info']['user']['account_id'];
+
                        $this->grants                                   = 
$GLOBALS['phpgw']->acl->get_grants('projects');
                        $this->grants[$this->account]   = PHPGW_ACL_READ + 
PHPGW_ACL_ADD + PHPGW_ACL_EDIT + PHPGW_ACL_DELETE;

+                       //$this->attached_files                 = 
CreateObject('projects.attached_files');
+
                        $this->start                                    = 
$this->bohours->start;
                        $this->query                                    = 
$this->bohours->query;
                        $this->filter                                   = 
$this->bohours->filter;
@@ -67,6 +77,7 @@
                        $this->state                                    = 
$this->bohours->state;
                        $this->cat_id                                   = 
$this->bohours->cat_id;
                        $this->project_id                               = 
$this->bohours->project_id;
+
                        $this->siteconfig                               = 
$this->bohours->siteconfig;
                }

@@ -74,171 +85,24 @@
                {
                        $data = array
                        (
-                               'start'                 => $this->start,
-                               'query'                 => $this->query,
-                               'filter'                => $this->filter,
-                               'order'                 => $this->order,
-                               'sort'                  => $this->sort,
-                               'status'                => $this->status,
-                               'state'                 => $this->state,
-                               'project_id'    => $this->project_id,
-                               'cat_id'                => $this->cat_id
+                               'start'      => $this->start,
+                               'query'      => $this->query,
+                               'filter'     => $this->filter,
+                               'order'      => $this->order,
+                               'sort'       => $this->sort,
+                               'status'     => $this->status,
+                               'state'      => $this->state,
+                               'project_id' => $this->project_id,
+                               'cat_id'     => $this->cat_id
                        );
                        $this->boprojects->save_sessiondata($data,$action);
                }

-               function set_app_langs()
-               {
-                       
$GLOBALS['phpgw']->template->set_var('th_bg',$GLOBALS['phpgw_info']['theme']['th_bg']);
-                       
$GLOBALS['phpgw']->template->set_var('row_on',$GLOBALS['phpgw_info']['theme']['row_on']);
-                       
$GLOBALS['phpgw']->template->set_var('row_off',$GLOBALS['phpgw_info']['theme']['row_off']);
-
-                       
$GLOBALS['phpgw']->template->set_var('lang_category',lang('Category'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_select',lang('Select'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_descr',lang('Description'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_title',lang('Title'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_none',lang('None'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_start_date',lang('Start Date'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_end_date',lang('End Date'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_date_due',lang('Date due'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_access',lang('Private'));
-
-                       
$GLOBALS['phpgw']->template->set_var('lang_projects',lang('Projects'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_jobs',lang('Jobs'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_statistics',lang('Statistics'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_ttracker',lang('time tracker'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_archiv',lang('archive'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_roles',lang('roles'));
-
-                       
$GLOBALS['phpgw']->template->set_var('lang_number',lang('Project ID'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_title',lang('Title'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_status',lang('Status'));
-
-                       
$GLOBALS['phpgw']->template->set_var('lang_save',lang('Save'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_edit',lang('Edit'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_cancel',lang('Cancel'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_done',lang('done'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_apply',lang('apply'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_view',lang('View'));
-
-                       
$GLOBALS['phpgw']->template->set_var('lang_budget',lang('Budget'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_customer',lang('Customer'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_coordinator',lang('Coordinator'));
-
-                       
$GLOBALS['phpgw']->template->set_var('lang_date',lang('date'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_time',lang('time'));
-
-                       
$GLOBALS['phpgw']->template->set_var('lang_activity',lang('Activity'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_project',lang('Project'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_descr',lang('Short description'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_remark',lang('Remark'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_status',lang('Status'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_employee',lang('Employee'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_work_date',lang('Work date'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_start_date',lang('Start date'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_end_date',lang('End date'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_work_time',lang('Work time'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_start_time',lang('Start time'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_end_time',lang('End time'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_select_project',lang('Select 
project'));
-
-                       
$GLOBALS['phpgw']->template->set_var('lang_minperae',lang('Minutes per 
workunit'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_billperae',lang('Bill per 
hour/workunit'));
-
-                       
$GLOBALS['phpgw']->template->set_var('lang_till',lang('till'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_from',lang('from'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_entry',lang('entry'));
-
-                       
$GLOBALS['phpgw']->template->set_var('lang_url',lang('project url'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_main',lang('Main project'));
-
-                       
$GLOBALS['phpgw']->template->set_var('lang_planned',lang('planned'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_used',lang('used'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_used_total',lang('used total'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_available',lang('available'));
-
-                       
$GLOBALS['phpgw']->template->set_var('lang_hours',lang('Work hours'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_plus_jobs',lang('+ jobs'));
-
-                       
$GLOBALS['phpgw']->template->set_var('lang_budget_planned',lang('budget 
planned'));
-
-                       
$GLOBALS['phpgw']->template->set_var('lang_used_billable',lang('used 
billable'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_used_not_billable',lang('used not 
billable'));
-
-                       
$GLOBALS['phpgw']->template->set_var('lang_utime_billable',lang('time used 
billable'));
-
-                       
$GLOBALS['phpgw']->template->set_var('lang_total_time',lang('time used total'));
-
-                       
$GLOBALS['phpgw']->template->set_var('lang_ttracker_actions',lang('time 
tracking actions'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_manuell_entries',lang('manuell 
entries'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_non_billable',lang('not billable'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_time_of_journey',lang('time of 
journey'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_distance',lang('distance'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_surcharge',lang('surcharge'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_select_surcharge',lang('select 
surcharge'));
-               }
-
-               function display_app_header()
-               {
-                       if 
($GLOBALS['phpgw_info']['user']['preferences']['common']['template_set'] != 
'idots')
-                       {
-                               
$GLOBALS['phpgw']->template->set_file(array('header' => 'header.tpl'));
-                               
$GLOBALS['phpgw']->template->set_block('header','projects_header');
-                               
$GLOBALS['phpgw']->template->set_block('header','projects_admin_header');
-
-                               if ($this->boprojects->isprojectadmin('pad') || 
$this->boprojects->isprojectadmin('pmanager'))
-                               {
-                                       switch($this->siteconfig['accounting'])
-                                       {
-                                               case 'activity':
-                                                       
$GLOBALS['phpgw']->template->set_var('link_accounting',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiconfig.list_activities&action=act'));
-                                                       
$GLOBALS['phpgw']->template->set_var('lang_accounting',lang('Activities'));
-                                                       break;
-                                               default:
-                                                       
$GLOBALS['phpgw']->template->set_var('link_accounting',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiconfig.list_employees&action=accounting'));
-                                                       
$GLOBALS['phpgw']->template->set_var('lang_accounting',lang('Accounting'));
-                                       }
-                                       
$GLOBALS['phpgw']->template->set_var('link_budget',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojects.list_budget&action=mains'));
-                                       
$GLOBALS['phpgw']->template->fp('admin_header','projects_admin_header');
-                               }
-
-                               
$GLOBALS['phpgw']->template->set_var('link_jobs',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojects.list_projects&action=subs'));
-                               
$GLOBALS['phpgw']->template->set_var('link_hours',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojecthours.list_projects&action=mains'));
-                               
$GLOBALS['phpgw']->template->set_var('link_ttracker',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojecthours.ttracker'));
-                               
$GLOBALS['phpgw']->template->set_var('link_statistics',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uistatistics.list_projects&action=mains'));
-                               
$GLOBALS['phpgw']->template->set_var('link_projects',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojects.list_projects&action=mains'));
-                               
$GLOBALS['phpgw']->template->set_var('link_archiv',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojects.archive&action=amains'));
-                               
$GLOBALS['phpgw']->template->fp('app_header','projects_header');
-                       }
-                       $GLOBALS['phpgw']->common->phpgw_header();
-                       echo parse_navbar();
-                       $this->set_app_langs();
-               }
-
-               function admin_header_info()
-               {
-                       if ($this->boprojects->isprojectadmin('pad'))
-                       {
-                               $pa = True;
-                       }
-
-                       if ($this->boprojects->isprojectadmin('pmanager'))
-                       {
-                               $pm = True;
-                       }
-
-                       if ($this->boprojects->isprojectadmin('psale'))
-                       {
-                               $ps = True;
-                       }
-                       return ($pa?' > ' . 
lang('administrator'):'') . ($pm?' > ' . lang('manager'):'')
-                                       . ($ps?' > ' . 
lang('salesman'):'');
-               }
-
                function list_projects()
                {
                        $action         = get_var('action',array('POST','GET'));
                        $pro_main       = 
get_var('pro_main',array('POST','GET'));
+                       $project_id     = 
get_var('project_id',array('POST','GET'));

                        if ($_GET['cat_id'])
                        {
@@ -247,36 +111,49 @@

                        if (!$action)
                        {
-                               $action = 'mains';
+                               if (strlen($project_id))
+                               {
+                                       $action = 'mainsubsorted';
+                                       $pro_main = $project_id;
+                               }
+                               else
+                               {
+                                       $action = 'mains';
+                               }
                        }

                        $link_data = array
                        (
-                               'menuaction'    => 
'projects.uiprojecthours.list_projects',
-                               'pro_main'              => $pro_main,
-                               'action'                => $action
+                               'menuaction' => 
'projects.uiprojecthours.list_projects',
+                               'pro_main'   => $pro_main,
+                               'action'     => $action
                        );

-                       $pro = $this->boprojects->list_projects(array('action' 
=> $action,'parent' => $pro_main,'page' => 'hours'));
-
-                       if($action=='subs' && !is_array($pro))
+                       if ($action == 'mainsubsorted')
                        {
-                                       
$GLOBALS['phpgw']->redirect_link('/index.php','menuaction=projects.uiprojecthours.list_hours&project_id='
-                                                                               
                        . $pro_main . '&action=hours');
+                               $pro = 
$this->boprojects->list_projects(array('action' => $action,'project_id' => 
$pro_main,'page' => 'hours'));
                        }
+                       else
+                       {
+                               $pro = 
$this->boprojects->list_projects(array('action' => $action,'parent' => 
$pro_main,'page' => 'hours'));
+                       }
+
+                       //if($action=='subs' && !is_array($pro))
+                       //{
+                       //              
$GLOBALS['phpgw']->redirect_link('/index.php','menuaction=projects.uiprojecthours.list_hours&project_id='
+                       //                                                      
                        . $pro_main . '&action=hours');
+                       //}

-                       $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . ($pro_main?lang('list jobs'):lang('list projects'))
-                                                                               
                                        . $this->admin_header_info();
+                       //$GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . lang('list projects')
+                       //                                                      
                                        . $this->admin_header_info();

-                       $this->display_app_header();
+                       $this->ui_base->display_app_header();

                        
$GLOBALS['phpgw']->template->set_file(array('projects_list_t' => 
'list_pro_hours.tpl'));
                        
$GLOBALS['phpgw']->template->set_block('projects_list_t','projects_list','list');
                        
$GLOBALS['phpgw']->template->set_block('projects_list_t','project_main','main');

-
-
-                       if($pro_main)
+                       if($pro_main && $action != 'mainsubsorted')
                        {
                                $main = 
$this->boprojects->read_single_project($pro_main,'hours');
                                
$GLOBALS['phpgw']->template->set_var('title_main',$main['title']);
@@ -286,9 +163,10 @@
                                
$GLOBALS['phpgw']->template->set_var('number_main',$main['number']);
                                
$GLOBALS['phpgw']->template->set_var('customer_main',$main['customerout']);
                                
$GLOBALS['phpgw']->template->set_var('url_main',$main['url']);
-                               
$GLOBALS['phpgw']->template->set_var('utime_main',$main['uhours_jobs']);
-                               
$GLOBALS['phpgw']->template->set_var('ptime_main',$main['ptime']);
-                               
$GLOBALS['phpgw']->template->set_var('atime_main',$main['ahours_jobs']);
+                               
$GLOBALS['phpgw']->template->set_var('utime_main',str_replace(".", ":", 
$main['uhours_jobs']));
+                               
$GLOBALS['phpgw']->template->set_var('ptime_main',str_replace(".", ":", 
sprintf("%1.02f",$main['ptime'])));
+                               
$GLOBALS['phpgw']->template->set_var('atime_main',str_replace(".", ":", 
sprintf("%1.02f",$main['ahours_jobs'])));
+
                                
$GLOBALS['phpgw']->template->parse('main','project_main',True);
                        }

@@ -303,34 +181,33 @@

 // ------------------------- end nextmatch template 
--------------------------------------

-                       if ($action == 'mains')
-                       {
+                       //if ($action == 'mains')
+                       //{
                                $action_list= '<select name="cat_id" 
onChange="this.form.submit();"><option value="none">' . lang('Select category') 
. '</option>' . "\n"
                                                        . 
$this->boprojects->cats->formatted_list('select','all',$this->cat_id,True) . 
'</select>';
-                       }
-                       else
-                       {
-                               $action_list= '<select name="pro_main" 
onChange="this.form.submit();"><option value="">' . lang('Select main project') 
. '</option>' . "\n"
-                                                       . 
$this->boprojects->select_project_list(array('status' => $this->status, 
'selected' => $pro_main)) . '</select>';
-                       }
+                       //}
+                       //else
+                       //{
+                       //      $action_list= '<select name="pro_main" 
onChange="this.form.submit();"><option value="">' . lang('Select main project') 
. '</option>' . "\n"
+                       //                              . 
$this->boprojects->select_project_list(array('status' => $this->status, 
'selected' => $pro_main)) . '</select>';
+                       //}

                        
$GLOBALS['phpgw']->template->set_var('action_list',$action_list);
                        
$GLOBALS['phpgw']->template->set_var('action_url',$GLOBALS['phpgw']->link('/index.php',$link_data));
                        
$GLOBALS['phpgw']->template->set_var('filter_list',$this->nextmatchs->new_filter($this->filter));
                        
$GLOBALS['phpgw']->template->set_var('search_list',$this->nextmatchs->search(array('query'
 => $this->query)));
-                       
$GLOBALS['phpgw']->template->set_var('status_list',$this->status_format_pro($this->status));
+                       
$GLOBALS['phpgw']->template->set_var('status_list',$this->ui_base->status_format($this->status));

 // ---------------- list header variable template-declarations 
--------------------------

-                       
$GLOBALS['phpgw']->template->set_var('sort_number',$this->nextmatchs->show_sort_order($this->sort,'num',$this->order,'/index.php',(isset($pro_main)?lang('job
 id'):lang('Project ID')),$link_data));
-
+                       
$GLOBALS['phpgw']->template->set_var('sort_number',$this->nextmatchs->show_sort_order($this->sort,'p_number',$this->order,'/index.php',lang('project
 id'),$link_data));
                        
$GLOBALS['phpgw']->template->set_var('sort_planned',$this->nextmatchs->show_sort_order($this->sort,'time_planned',$this->order,'/index.php',lang('planned'),$link_data));
                        
$GLOBALS['phpgw']->template->set_var('sort_title',$this->nextmatchs->show_sort_order($this->sort,'title',$this->order,'/index.php',lang('Title'),$link_data));

 // -------------- end header declaration 
---------------------------------------

                        for ($i=0;$i<count($pro);$i++)
-            {
+                       {
                                
$this->nextmatchs->template_alternate_row_color(&$GLOBALS['phpgw']->template);

 // --------------- template declaration for list records 
-------------------------------------
@@ -353,15 +230,21 @@
                                        'number'                                
=> $pro[$i]['number'],
                                        'title'                                 
=> $pro[$i]['title']?$pro[$i]['title']:lang('browse'),
                                        'projects_url'                  => 
$projects_url,
-                                       'phours'                                
=> $pro[$i]['phours'],
-                                       'uhours_pro'                    => 
$pro[$i]['uhours_pro'],
-                                       'uhours_jobs'                   => 
$pro[$i]['uhours_jobs'],
-                                       'uhours_pro_nobill'             => 
$pro[$i]['uhours_pro_nobill'],
-                                       'uhours_jobs_nobill'    => 
$pro[$i]['uhours_jobs_nobill'],
-                                       'uhours_pro_bill'               => 
$pro[$i]['uhours_pro_bill'],
-                                       'uhours_jobs_bill'              => 
$pro[$i]['uhours_jobs_bill'],
-                                       'ahours_pro'                    => 
$pro[$i]['ahours_pro'],
-                                       'ahours_jobs'                   => 
$pro[$i]['ahours_jobs']
+                                       'phours_pro'                    => 
$this->bohours->sohours->min2str($pro[$i]['item_planned_time']),
+                                       'phours'                                
=> $this->bohours->sohours->min2str($pro[$i]['sum_planned_time']),
+                                       'uhours_pro'                    => 
$this->bohours->sohours->min2str($pro[$i]['item_used_time']),
+                                       'uhours_jobs'                   => 
$this->bohours->sohours->min2str($pro[$i]['sum_used_time']),
+                                       'uhours_pro_nobill'             => 
$this->bohours->sohours->min2str($pro[$i]['item_nobill_time']),
+                                       'uhours_jobs_nobill'    => 
$this->bohours->sohours->min2str($pro[$i]['sum_nobill_time']),
+                                       'uhours_pro_bill'               => 
$this->bohours->sohours->min2str($pro[$i]['item_bill_time']),
+                                       'uhours_jobs_bill'              => 
$this->bohours->sohours->min2str($pro[$i]['sum_bill_time']),
+                                       'ahours_pro'                    => 
$this->bohours->sohours->min2str($pro[$i]['item_avail_time']),
+                                       'ahours_jobs'                   => 
$this->bohours->sohours->min2str($pro[$i]['sum_avail_time']),
+
+                                       'list_class_sum'                => 
$pro[$i]['is_leaf']?'leaf_sum':'node_sum',
+                                       'list_class_item'               => 
$pro[$i]['is_leaf']?'leaf_item':'node_item',
+                                       'value_class_sum'               => 
'value_'.$pro[$i]['sum_time_status'],
+                                       'value_class_item'              => 
'value_'.$pro[$i]['item_time_status']
                                ));
                                
$GLOBALS['phpgw']->template->parse('list','projects_list',True);
                        }
@@ -370,6 +253,32 @@

 // --------------- template declaration for Add Form --------------------------

+                       if ($action=='subs' && $pro_main && is_array($main) && 
$this->bohours->add_perms(array('main' => $pro_main,'main_co' => 
$main['coordinator'])))
+                       {
+                               $link_data['menuaction'] = 
'projects.uiprojecthours.edit_hours';
+                               $link_data['project_id'] = $pro_main;
+                               $link_data['action'] = 'hours';
+                               unset($link_data['hours_id']);
+                               
$GLOBALS['phpgw']->template->set_var('add','<form method="POST" action="' . 
$GLOBALS['phpgw']->link('/index.php',$link_data)
+                                                                               
                                                . '"><input type="submit" 
value="' . lang('add work hours to the main project') . '"></form>');
+                       }
+
+                       if ($action=='subs' && $pro_main)
+                       {
+                               unset($link_data);
+                               $link_data['menuaction'] = 
'projects.uiprojecthours.list_hours';
+                               $link_data['project_id'] = $pro_main;
+                               $link_data['pro_main'] = $pro_main;
+                               $link_data['action'] = 'hours';
+                               
$GLOBALS['phpgw']->template->set_var('view_hours','<form method="POST" 
action="' . $GLOBALS['phpgw']->link('/index.php',$link_data)
+                                                                               
                                                . '"><input type="submit" 
value="' . lang('View work hours of the main project') . '"></form>');
+                       }
+
+                       unset($link_data);
+                       $link_data['menuaction'] = 
'projects.uiprojecthours.controlling_sheet';
+                       
$GLOBALS['phpgw']->template->set_var('view_controlling_sheet','<form 
method="POST" action="' . $GLOBALS['phpgw']->link('/index.php',$link_data)
+                                                                               
                                        . '"><input type="hidden" 
name="datum[start]" value="'.$start.'"><input type="hidden" name="datum[end]" 
value="'.$end.'"><input type="submit" name="view" value="' . lang('View 
controlling sheet') . '"></form>');
+
                        $this->project_id = $pro_main;
                        if ($this->bohours->add_perms(array('main' => 
$pro_main,'main_co' => $main['coordinator'])) && $pro_main > 0)
                        {
@@ -386,13 +295,40 @@
                }

                function list_hours()
-               {
-                       $action         = get_var('action',array('POST','GET'));
-                       $project_id     = 
get_var('project_id',array('POST','GET'));
-                       $pro_main       = 
get_var('pro_main',array('POST','GET'));
+               {
+                       $action                 = 
get_var('action',array('POST','GET'));
+                       $project_id             = 
get_var('project_id',array('POST','GET'));
+                       $pro_main               = 
get_var('pro_main',array('POST','GET'));
+                       $this->state    = get_var('state',array('POST','GET'));
+                       $values                 = 
get_var('values',array('POST','GET'));
+
+                       $jscal = CreateObject('phpgwapi.jscalendar');   // 
before phpgw_header() !!!
+
+                       $sdate = get_var('sdate',array('POST','GET'));
+                       if($sdate)
+                       {
+                               $start_array = $jscal->input2date($sdate);
+                               $start = 
mktime(0,0,0,$start_array['month'],$start_array['day'],$start_array['year']);
+                       }
+                       else
+                       {
+                               $start = mktime(0,0,0,date('m'),1,date('Y'));
+                       }
+
+                       $edate = get_var('edate',array('POST','GET'));
+                       if($edate)
+                       {
+                               $end_array = $jscal->input2date($edate);
+                               $end = 
mktime(23,59,59,$end_array['month'],$end_array['day'],$end_array['year']);
+                       }
+                       else
+                       {
+                               $end = mktime(23,59,59,date('m')+1,0,date('Y'));
+                       }
+
+                       //$GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . lang('list work hours') . $this->admin_header_info();

-                       $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . lang('list work hours') . $this->admin_header_info();
-                       $this->display_app_header();
+                       $this->ui_base->display_app_header();

                        $this->project_id = intval($project_id);

@@ -410,45 +346,92 @@

                        if($this->project_id)
                        {
-                               $this->attached_files = 
CreateObject('projects.attached_files');
+                               //$this->attached_files = 
CreateObject('projects.attached_files');
                                $main = 
$this->boprojects->read_single_project($this->boprojects->return_value('main',$this->project_id),'hours');
                                
$GLOBALS['phpgw']->template->set_var('title_main',$main['title']);
-                               
$GLOBALS['phpgw']->template->set_var('main_url',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojects.view_project&action=mains&project_id='
-                                                                               
                                                                                
                . $main['project_id']));
+                               
$GLOBALS['phpgw']->template->set_var('main_url',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojects.view_project&action=mains&project_id='.$main['project_id']));
                                
$GLOBALS['phpgw']->template->set_var('coordinator_main',$main['coordinatorout']);
                                
$GLOBALS['phpgw']->template->set_var('number_main',$main['number']);
                                
$GLOBALS['phpgw']->template->set_var('customer_main',$main['customerout']);
                                
$GLOBALS['phpgw']->template->set_var('url_main',$main['url']);
                                
$GLOBALS['phpgw']->template->set_var('utime_main',$main['uhours_jobs']);
-                               
$GLOBALS['phpgw']->template->set_var('ptime_main',$main['ptime']);
-                               
$GLOBALS['phpgw']->template->set_var('atime_main',$main['ahours_jobs']);
+                               
$GLOBALS['phpgw']->template->set_var('ptime_main',str_replace(".", ":", 
sprintf("%1.02f",$main['ptime'])));
+                               
$GLOBALS['phpgw']->template->set_var('atime_main',str_replace(".", ":", 
sprintf("%1.02f",$main['ahours_jobs'])));
                                
$GLOBALS['phpgw']->template->parse('main','project_main',True);
-                               
$GLOBALS['phpgw']->template->set_var('attachment',$this->attached_files->get_files($this->project_id));
+                               
//$GLOBALS['phpgw']->template->set_var('attachment',$this->attached_files->get_files($this->project_id));
                                
$GLOBALS['phpgw']->template->set_var('lang_files',lang('Files'));
                        }

                        
$GLOBALS['phpgw']->template->set_var('action_url',$GLOBALS['phpgw']->link('/index.php',$link_data));
-                       
$GLOBALS['phpgw']->template->set_var('filter_list',$this->nextmatchs->new_filter(array('format'
 => 'yours','filter' => $this->filter)));
+                       
$GLOBALS['phpgw']->template->set_var('sdate_select',$jscal->input('sdate',$start));
+                       
$GLOBALS['phpgw']->template->set_var('edate_select',$jscal->input('edate',$end));
+                       
$GLOBALS['phpgw']->template->set_var('project_list',$this->boprojects->select_project_list(array('action'
 => 'all','status' => $this->status,'selected' => $this->project_id)));
+                       
$GLOBALS['phpgw']->template->set_var('lang_update',lang('update'));
+
                        
$GLOBALS['phpgw']->template->set_var('search_list',$this->nextmatchs->search(array('query'
 => $this->query)));

-                       
$GLOBALS['phpgw']->template->set_var('project_list',$this->boprojects->select_project_list(array('action'
 => 'all','status' => $this->status,'selected' => $this->project_id)));
+                       if ( ($main['coordinator'] == 
$GLOBALS['phpgw_info']['user']['account_id'])
+                         || 
($this->boprojects->return_value('coordinator',$this->project_id) == 
$GLOBALS['phpgw_info']['user']['account_id'])
+                         || ($this->boprojects->isprojectadmin('pad'))
+                         || ($this->boprojects->isprojectadmin('pmanager'))
+                          )
+                       {
+                               
//$GLOBALS['phpgw']->template->set_var('filter_list',$this->nextmatchs->new_filter(array('format'
 => 'yours','filter' => 'employee')));
+
+                               $employee       = get_var('employee', 
array('POST','GET'));
+                               if(!$employee)
+                               {
+                                       $employee       = 
$GLOBALS['phpgw_info']['user']['account_id'];
+                               }
+
+                               $format_data = array(
+                                       'project_only' => True,
+                                       'project_id'   => $this->project_id,
+                                       'selected'     => array($employee)
+                               );
+
+                               $filter_employee  = '<select name="employee">';
+                               $filter_employee .= '<option value="-1">' . 
lang('show all') . '</option>';
+                               $filter_employee .=     
$this->ui_base->employee_format($format_data);
+                               $filter_employee .= '</select>';

+                               if($employee > 0)
+                               {
+                                       $this->filter   = 
$this->bohours->filter = 'employee';
+                                       $this->employee = 
$this->bohours->sohours->employee = $employee;
+                               }
+                               else
+                               {
+                                       $this->filter = $this->bohours->filter 
= 'none';
+                               }
+                       }
+                       else
+                       {
+                               $this->filter = $this->bohours->filter = 
'yours';
+                               $employee = 
$GLOBALS['phpgw_info']['user']['account_id'];
+                               $filter_employee = 
$GLOBALS['phpgw_info']['user']['fullname'];
+                       }
+
+                       $GLOBALS['phpgw']->template->set_var('filter_list', 
$filter_employee);
+
                        switch($this->state)
                        {
                                case 'all': $state_sel[0]=' selected';break;
                                case 'open': $state_sel[1]=' selected';break;
                                case 'done': $state_sel[2]=' selected';break;
                                case 'billed': $state_sel[3]=' selected';break;
+                               default: $state_sel[0]=' selected'; 
$this->state = 'all';
                        }

                        $state_list = '<option value="all"' . $state_sel[0] . 
'>' . lang('Show all') . '</option>' . "\n"
-                                               . '<option value="open"' . 
$state_sel[1] . '>' . lang('Open') . '</option>' . "\n"
-                                               . '<option value="done"' . 
$state_sel[2] . '>' . lang('Done') . '</option>' . "\n"
-                                               . '<option value="billed"' . 
$state_sel[3] . '>' . lang('Billed') . '</option>' . "\n";
+                                   . '<option value="open"' . $state_sel[1] . 
'>' . lang('Open') . '</option>' . "\n"
+                                   . '<option value="done"' . $state_sel[2] . 
'>' . lang('Done') . '</option>' . "\n"
+                                   . '<option value="billed"' . $state_sel[3] 
. '>' . lang('Billed') . '</option>' . "\n";

                        
$GLOBALS['phpgw']->template->set_var('state_list',$state_list);
+                       $this->bohours->state = $this->state;

-                       $hours = $this->bohours->list_hours();
+                       $hours = $this->bohours->list_hours($start, $end);

 // --------------------- nextmatch variable template-declarations 
------------------------

@@ -470,6 +453,7 @@
                        
$GLOBALS['phpgw']->template->set_var('sort_end_time',$this->nextmatchs->show_sort_order($this->sort,'end_date',$this->order,'/index.php',lang('End
 time'),$link_data));
                        
$GLOBALS['phpgw']->template->set_var('sort_hours',$this->nextmatchs->show_sort_order($this->sort,'minutes',$this->order,'/index.php',lang('Hours'),$link_data));
                        
$GLOBALS['phpgw']->template->set_var('sort_employee',$this->nextmatchs->show_sort_order($this->sort,'employee',$this->order,'/index.php',lang('Employee'),$link_data));
+                       
$GLOBALS['phpgw']->template->set_var('sort_t_journey',$this->nextmatchs->show_sort_order($this->sort,'t_journey',$this->order,'/index.php',lang('travel
 time'),$link_data));

 // -------------- end header declaration 
---------------------------------------

@@ -485,7 +469,7 @@
                                if ($this->bohours->edit_perms(array('main' => 
$main['project_id'],'main_co' => $main['coordinator'],'status' => 
$hours[$i]['status'],
                                                                                
                        'employee' => $hours[$i]['employee'])))
                                {
-                                       $link_data['menuaction'] = 
'projects.uiprojecthours.edit_hours';
+                                       $link_data['menuaction'] = 
'projects.uiprojecthours.view_hours';
                                        $descr = '<a href="' . 
$GLOBALS['phpgw']->link('/index.php',$link_data) . '">'
                                                                                
                                                . $hours_desr . '</a>';
                                }
@@ -494,19 +478,53 @@
                                        $descr = $hours_desr;
                                }

+                               
if($this->bohours->is_booked($link_data['hours_id']))
+                               {
+                                       $link_data['menuaction'] = 
'projects.uiprojecthours.unbook_hours';
+                                       
if($this->boprojects->isprojectadmin('pad') || 
$this->boprojects->isprojectadmin('pmanager'))
+                                       {
+                                               $link = 
$GLOBALS['phpgw']->link('/index.php',$link_data);
+                                               
$GLOBALS['phpgw']->template->set_var('booked', '<a href="' . $link . '"><img 
src="projects/templates/' . $GLOBALS['phpgw_info']['server']['template_set'] . 
'/images/booked1.png" title="' . lang('booked') . '">&nbsp;</a>');
+                                       }
+                                       else
+                                       {
+                                               
$GLOBALS['phpgw']->template->set_var('booked', '<img src="projects/templates/' 
. $GLOBALS['phpgw_info']['server']['template_set'] . '/images/booked1.png" 
title="' . lang('booked') . '">');
+                                       }
+                               }
+                               else
+                               {
+                                       
$GLOBALS['phpgw']->template->set_var('booked', '');
+                               }
+
+                               if($this->siteconfig['hoursbookingday'] == 
'yes')
+                               {
+                                       $start_date = 
$hours[$i]['sdate_formatted']['date'] . ' - ' . 
$hours[$i]['edate_formatted']['date'];
+                               }
+                               else
+                               {
+                                       $start_date = 
$hours[$i]['sdate_formatted']['date'];
+                               }
+
                                $GLOBALS['phpgw']->template->set_var(array(
-                                                                               
                        'employee'              => $hours[$i]['employeeout'],
-                                                                               
                        'hours_descr'   => $descr,
-                                                                               
                        'status'                => $hours[$i]['statusout'],
-                                                                               
                        'start_date'    => 
$hours[$i]['sdate_formatted']['date'],
-                                                                               
                        'start_time'    => 
$hours[$i]['sdate_formatted']['time'],
-                                                                               
                        'end_time'              => 
$hours[$i]['edate_formatted']['time'],
-                                                                               
                        'wh'                    => $hours[$i]['wh']['whwm']));
+                                                                               
                        'employee'    => $hours[$i]['employeeout'],
+                                                                               
                        'hours_descr' => $descr,
+                                                                               
                        'status'      => $hours[$i]['statusout'],
+                                                                               
                        'start_date'  => $start_date,
+                                                                               
                        'start_time'  => $hours[$i]['sdate_formatted']['time'],
+                                                                               
                        'end_time'    => $hours[$i]['edate_formatted']['time'],
+                                                                               
                        'wh'          => str_replace('.', ':', 
sprintf("%1.02f",$hours[$i]['wh']['whwm'])),
+                                                                               
                        't_journey'   => $hours[$i]['t_journey']));

                                $link_data['menuaction'] = 
'projects.uiprojecthours.view_hours';
                                
$GLOBALS['phpgw']->template->set_var('view_url',$GLOBALS['phpgw']->link('/index.php',$link_data));
                                
$GLOBALS['phpgw']->template->set_var('view_img',$GLOBALS['phpgw']->common->image('phpgwapi','view'));
                                
$GLOBALS['phpgw']->template->set_var('lang_view_hours',lang('view hours'));
+
+                               $link_data['menuaction'] = 
'projects.uiprojecthours.edit_hours';
+                               
$GLOBALS['phpgw']->template->set_var('edit_url',$GLOBALS['phpgw']->link('/index.php',$link_data));
+                               
$GLOBALS['phpgw']->template->set_var('edit_img',$GLOBALS['phpgw']->common->image('phpgwapi','edit'));
+                               
$GLOBALS['phpgw']->template->set_var('lang_edit_hours',lang('edit hours'));
+
                                
$GLOBALS['phpgw']->template->fp('list','hours_list',True);

 // --------------------------- end record declaration 
-----------------------------------
@@ -518,17 +536,22 @@

                        
$GLOBALS['phpgw']->template->set_var('uhours_pro',$this->boprojects->colored($acc['uhours_pro'],$ptime_pro,$acc['uhours_pro_wminutes'],'hours'));
                        
$GLOBALS['phpgw']->template->set_var('uhours_jobs',$this->boprojects->colored($acc['uhours_jobs'],$ptime_pro,$acc['uhours_jobs_wminutes'],'hours'));
-                       
$GLOBALS['phpgw']->template->set_var('ahours_jobs',$acc['ahours_jobs']);
-                       
$GLOBALS['phpgw']->template->set_var('phours',$ptime_pro/60 . '.00');
+                       
$GLOBALS['phpgw']->template->set_var('ahours_jobs',str_replace(".", ":", 
sprintf("%1.02f",$acc['ahours_jobs'])));
+                       
$GLOBALS['phpgw']->template->set_var('phours',intval($ptime_pro/60) . ':00');

                        if ($this->bohours->add_perms(array('main' => 
$main['project_id'],'main_co' => $main['coordinator'])) && $this->project_id > 
0)
                        {
                                $link_data['menuaction'] = 
'projects.uiprojecthours.edit_hours';
                                unset($link_data['hours_id']);
                                
$GLOBALS['phpgw']->template->set_var('action','<form method="POST" action="' . 
$GLOBALS['phpgw']->link('/index.php',$link_data)
-                                                                               
                                                . '"><input type="submit" 
value="' . lang('Add') . '"></form>');
+                                                                               
                                                . '"><input type="submit" 
value="' . lang('add work hours') . '"></form>');
                        }

+                       unset($link_data);
+                       $link_data['menuaction'] = 
'projects.uiprojecthours.controlling_sheet';
+                       
$GLOBALS['phpgw']->template->set_var('view_controlling_sheet','<form 
method="POST" action="' . $GLOBALS['phpgw']->link('/index.php',$link_data)
+                                                                               
                                        . '"><input type="hidden" 
name="datum[start]" value="'.$start.'"><input type="hidden" name="datum[end]" 
value="'.$end.'"><input type="submit" name="view" value="' . lang('View 
controlling sheet') . '"></form>');
+
                        $this->save_sessiondata('hours');
                        
$GLOBALS['phpgw']->template->pfp('out','hours_list_t',True);
                }
@@ -539,14 +562,47 @@
                {
                        //$project_id   = 
get_var('project_id',array('POST','GET'));
                        $sdate  = get_var('sdate',array('POST','GET'));
+                       $edate  = get_var('edate',array('POST','GET'));
+
                        $values = get_var('values',array('POST'));
+                       if(!$values || !isset($values['project_id']))
+                       {
+                               $project_id = 
get_var('project_id',array('POST','GET'));
+                               if($project_id)
+                               {
+                                       $values['project_id'] = $project_id;
+                               }
+                       }
+
+                       $jscal = CreateObject('phpgwapi.jscalendar');
+
+                       if(is_array($edate))
+                       {
+                               $end_array                      = 
$jscal->input2date($edate['str']);
+                               $end_val                        = 
$end_array['raw'];
+                               $values['edate']        = $end_val;
+                       }

+                       if(is_array($sdate))
+                       {
+                               $start_array            = 
$jscal->input2date($sdate['str']);
+                               $start_val                      = 
$start_array['raw'];
+                               $values['sdate']        = $start_val;
+
+                               if($this->siteconfig['hoursbookingday'] == 'no')
+                               {
+                                       $end_val = $start_val; // use the same 
worktime start and end time
+                               }
+                       }
+
+                       $values['t_journey'] = intval($values['t_journey_h']*60 
+ $values['t_journey_m']);
                        //_debug_array($values);

                        $this->project_id = intval($values['project_id']);
                        if($values['start'] || $values['stop'] || 
$values['continue'] || $values['pause'])
                        {
                                $error = 
$this->bohours->check_ttracker($values);
+
                                if (is_array($error))
                                {
                                        
$GLOBALS['phpgw']->template->set_var('message',$GLOBALS['phpgw']->common->error_list($error));
@@ -556,20 +612,15 @@
                                        $this->bohours->ttracker($values);
                                }
                        }
-
-                       $jscal = CreateObject('phpgwapi.jscalendar');
-                       if(is_array($sdate))
-                       {
-                               $start_array    = 
$jscal->input2date($sdate['str']);
-                               $start_val              = $start_array['raw'];
-                       }
-
-                       if($values['apply'])
+                       elseif($values['apply'])
                        {
                                $values['action']       = 'apply';
                                $values['ttracker'] = True;
-                               $values['sdate']        = $start_val;
+                               $values['hours']   = abs($values['hours']);
+                               $values['minutes'] = abs($values['minutes']);
+
                                $error = $this->bohours->check_values($values);
+
                                if (is_array($error))
                                {
                                        
$GLOBALS['phpgw']->template->set_var('message',$GLOBALS['phpgw']->common->error_list($error));
@@ -579,22 +630,19 @@
                                        $this->bohours->save_hours($values);
                                }
                        }
-
-                       if($values['save'])
+                       elseif($values['save'])
                        {
                                $values['action'] = 'save';
                                $this->bohours->ttracker($values);
                        }
-
-                       if($_GET['delete'])
+                       elseif($_GET['delete'])
                        {
                           $this->bohours->delete_hours(array('action' => 
'track','id' => $_GET['track_id']));
                        }

-                       $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . lang('time tracker');
-                       $this->display_app_header();
-
+                       //$GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . lang('time tracker');

+                       $this->ui_base->display_app_header();

                        
$GLOBALS['phpgw']->template->set_file(array('ttracker_t' => 'ttracker.tpl'));
                        
$GLOBALS['phpgw']->template->set_block('ttracker_t','ttracker','track');
@@ -603,13 +651,12 @@
                        
$GLOBALS['phpgw']->template->set_block('ttracker_t','activity','activityhandle');
                        
$GLOBALS['phpgw']->template->set_block('ttracker_t','act_own','actownhandle');

-                       
$GLOBALS['phpgw']->template->set_var('lang_select_project',lang('select 
project'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_start',lang('start'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_stop',lang('stop'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_pause',lang('pause'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_continue',lang('continue'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_comment',lang('comment'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_action',lang('action'));
+                       
$GLOBALS['phpgw']->template->set_block('ttracker_t','booking_date','datehandle');
+                       
$GLOBALS['phpgw']->template->set_block('ttracker_t','booking_time','timehandle');
+
+                       $project_list = '<option value="">' . lang('Select 
project') . '</option>' . "\n"
+                                                       . 
$this->boprojects->select_project_list(array('status' => 'active', 'action' => 
'all', 'selected' => $this->project_id)) . '</select>';
+                       $GLOBALS['phpgw']->template->set_var('select_project', 
$project_list);

                        $curr_date = $this->bohours->format_htime(time());

@@ -625,15 +672,28 @@
                        
$GLOBALS['phpgw']->template->set_var('action_url',$GLOBALS['phpgw']->link('/index.php',$link_data));

                        
$GLOBALS['phpgw']->template->set_var('remark',$values['remark']);
-                       
$GLOBALS['phpgw']->template->set_var('hours',$values['hours']);
-                       
$GLOBALS['phpgw']->template->set_var('minutes',$values['minutes']);
-                       
$GLOBALS['phpgw']->template->set_var('km_distance',$values['km_distance']);
-                       
$GLOBALS['phpgw']->template->set_var('t_journey',$values['t_journey']);
+                       
$GLOBALS['phpgw']->template->set_var('hours',sprintf("%02d",$values['hours']));
+                       
$GLOBALS['phpgw']->template->set_var('minutes',sprintf("%02d",$values['minutes']));
+                       
$GLOBALS['phpgw']->template->set_var('km_distance',sprintf("%01.2f",$values['km_distance']));
+                       
$GLOBALS['phpgw']->template->set_var('t_journey_h',sprintf("%02d", 
floor($values['t_journey']/60)));
+                       
$GLOBALS['phpgw']->template->set_var('t_journey_m',sprintf("%02d", 
intval($values['t_journey']%60)));
                        
$GLOBALS['phpgw']->template->set_var('surcharge_list',$this->boprojects->action_format($values['surcharge'],'charge'));

                        $start = 
$start_val?$start_val:mktime(12,0,0,date('m'),date('d'),date('Y'));
                        
$GLOBALS['phpgw']->template->set_var('start_date_select',$jscal->input('sdate[str]',$start));

+                       if($this->siteconfig['hoursbookingday'] == 'yes')
+                       {
+                               $end = 
$end_val?$end_val:mktime(12,0,0,date('m'),date('d'),date('Y'));
+                               
$GLOBALS['phpgw']->template->set_var('end_date_select',$jscal->input('edate[str]',$end));
+
+                               
$GLOBALS['phpgw']->template->fp('datehandle','booking_date',True);
+                       }
+                       else
+                       {
+                               
$GLOBALS['phpgw']->template->fp('timehandle','booking_time',True);
+                       }
+
                        if($this->siteconfig['accounting'] == 'activity')
                        {
                                
$GLOBALS['phpgw']->template->set_var('activity_list',$this->boprojects->select_hours_activities($this->project_id,$values['activity_id']));
@@ -649,9 +709,15 @@

                        //_debug_array($tracking);

-                       while(is_array($tracking) && list(,$track) = 
each($tracking))
+                       while(is_array($tracking) && (list($no_use,$track) = 
each($tracking)))
                        {
-                               
$GLOBALS['phpgw']->template->set_var('project_title',$track['project_title']);
+                               $level_title = $track['project_title'];
+                               if($track['project_level'] > 0)
+                               {
+                                       $level_title = 
str_repeat('&nbsp;&nbsp;&nbsp;', $track['project_level']).$level_title;
+                               }
+
+                               
$GLOBALS['phpgw']->template->set_var('project_title',$level_title);
                                
$GLOBALS['phpgw']->template->set_var('project_id',$track['project_id']);
                                
$GLOBALS['phpgw']->template->set_var('radio_checked',($track['project_id']==$this->project_id?'
 CHECKED':''));

@@ -685,7 +751,7 @@
                                                                                
                        'start_time'    => 
($track['hours'][$i]['status']!='apply')?$track['hours'][$i]['sdate_formatted']['time']:$track['hours'][$i]['sdate_formatted']['date'],
                                                                                
                        'apply_time'    => $at,
                                                                                
                        'end_time'              => 
($track['hours'][$i]['status']!='apply'?($track['hours'][$i]['edate']>0?$track['hours'][$i]['edate_formatted']['time']:
-                                                                               
                                                                
''):$track['hours'][$i]['sdate_formatted']['date']),
+                                                                               
                                                                
''):$track['hours'][$i]['edate_formatted']['date']),
                                                                                
                        'wh'                    => $wh,
                                                                                
                        'delete_url'    => 
$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojecthours.ttracker&delete=True&track_id='
 . $track['hours'][$i]['track_id']),
                                                                                
                        'edit_url'              => 
$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojecthours.edit_ttracker&track_id='
 . $track['hours'][$i]['track_id']),
@@ -704,26 +770,120 @@

                function edit_ttracker()
                {
+                       $jscal          = CreateObject('phpgwapi.jscalendar');
                        $track_id       = 
get_var('track_id',array('POST','GET'));
                        $values         = $_POST['values'];
+                       $edate          = get_var('edate',array('POST','GET'));
+                       $sdate          = get_var('sdate',array('POST','GET'));
+
+                       if(is_array($edate))
+                       {
+                               $end_array      = 
$jscal->input2date($edate['str']);
+                               $end_val        = $end_array['raw'];
+                       }
+
+                       if(is_array($sdate))
+                       {
+                               $start_array    = 
$jscal->input2date($sdate['str']);
+                               $start_val              = $start_array['raw'];
+
+                               if($this->siteconfig['hoursbookingday'] == 'no')
+                               {
+                                       $end_val = $start_val; // use the same 
worktime start and end time
+                               }
+                       }

                        if($_POST['save'] || $_POST['cancel'])
                        {
                                if($_POST['save'])
                                {
+                                       $values['t_journey'] = 
intval($values['t_journey_h']*60 + $values['t_journey_m']);
+                                       $values['hours']   = 
abs($values['hours']);
+                                       $values['minutes'] = 
abs($values['minutes']);
+
+                                       if 
($GLOBALS['phpgw_info']['user']['preferences']['common']['timeformat'] == '12')
+                                       {
+                                               if ($values['shour'] && 
($values['shour'] != 0) && ($values['shour'] != 12))
+                                               {
+                                                       if 
($values['sampm']=='pm')
+                                                       {
+                                                               
$values['shour'] = $values['shour'] + 12;
+                                                       }
+                                               }
+
+                                               if ($values['shour'] && 
($values['shour'] == 12))
+                                               {
+                                                       if 
($values['sampm']=='am')
+                                                       {
+                                                               
$values['shour'] = 0;
+                                                       }
+                                               }
+
+                                               if ($values['ehour'] && 
($values['ehour'] != 0) && ($values['ehour'] != 12))
+                                               {
+                                                       if 
($values['eampm']=='pm')
+                                                       {
+                                                               
$values['ehour'] = $values['ehour'] + 12;
+                                                       }
+                                               }
+
+                                               if ($values['ehour'] && 
($values['ehour'] == 12))
+                                               {
+                                                       if 
($values['eampm']=='am')
+                                                       {
+                                                               
$values['ehour'] = 0;
+                                                       }
+                                               }
+                                       }
+
+                                       if (intval($start_val) > 0)
+                                       {
+                                               $values['smonth']       = 
date('m',$start_val);
+                                               $values['sday']         = 
date('d',$start_val);
+                                               $values['syear']        = 
date('Y',$start_val);
+                                               $values['sdate']        = 
mktime(($values['shour']?$values['shour']:0),($values['smin']?$values['smin']:0),0,$values['smonth'],$values['sday'],$values['syear']);
+                                       }
+
+                                       if (intval($end_val) > 0)
+                                       {
+                                               $values['emonth']       = 
date('m',$end_val);
+                                               $values['eday']         = 
date('d',$end_val);
+                                               $values['eyear']        = 
date('Y',$end_val);
+                                               $values['edate']        = 
mktime(($values['ehour']?$values['ehour']:0),($values['emin']?$values['emin']:0),0,$values['emonth'],$values['eday'],$values['eyear']);
+                                       }
+
+                                       if(($values['hours'] == 0) && 
($values['minutes'] == 0) && ($values['t_journey'] == 0))
+                                       {
+                                               $minutes = 
(intval($values['ehour'])*60 + intval($values['emin'])) - 
(intval($values['shour']*60) + intval($values['smin']));
+                                               if($minutes < 0)
+                                               {
+                                                       $minutes = 0;
+                                               }
+                                               $values['hours']   = 
intval($minutes / 60);
+                                               $values['minutes'] = 
intval($minutes % 60);
+                                       }
+                                       /*else
+                                       {
+                                               $minutes = 
intval($values['hours'])*60 + intval($values['minutes']);
+                                       }*/
+
                                        $values['track_id']     = $track_id;
                                        $this->bohours->save_hours($values);
                                }
                                
$GLOBALS['phpgw']->redirect_link('/index.php','menuaction=projects.uiprojecthours.ttracker');
                        }

-                       $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . lang('edit time tracker entry');
-                       $this->display_app_header();
+                       //$GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . lang('edit time tracker entry');
+
+                       $this->ui_base->display_app_header();

                        
$GLOBALS['phpgw']->template->set_file(array('ttracker_form' => 
'ttracker_form.tpl'));
                        
$GLOBALS['phpgw']->template->set_block('ttracker_form','activity','activityhandle');
                        
$GLOBALS['phpgw']->template->set_block('ttracker_form','act_own','actownhandle');

+                       
$GLOBALS['phpgw']->template->set_block('ttracker_form','booking_date','datehandle');
+                       
$GLOBALS['phpgw']->template->set_block('ttracker_form','booking_time','timehandle');
+
                        $values = $this->bohours->read_single_track($track_id);

                        $link_data = array
@@ -745,9 +905,11 @@
                                
$GLOBALS['phpgw']->template->fp('actownhandle','act_own',True);
                        }

-                       
$GLOBALS['phpgw']->template->set_var('start_date_select',$GLOBALS['phpgw']->common->dateformatorder($this->sbox->getYears('values[syear]',$values['sdate_formatted']['year']),
-                                                                               
                                                                        
$this->sbox->getMonthText('values[smonth]',$values['sdate_formatted']['month']),
-                                                                               
                                                                        
$this->sbox->getDays('values[sday]',$values['sdate_formatted']['day'])));
+                       $start  = 
$start_val?$start_val:($values['sdate']?mktime(12,0,0,date('m',$values['sdate']),date('d',$values['sdate']),date('Y',$values['sdate'])):mktime(12,0,0,date('m'),date('d'),date('Y')));
+                       $shour  = 
$values['sdate']?date('H',$values['sdate']):date('H',time());
+                       $smin   = 
$values['sdate']?date('i',$values['sdate']):date('i',time());
+
+                       
$GLOBALS['phpgw']->template->set_var('start_date_select',$jscal->input('sdate[str]',$start));

                        $amsel = ' checked';
                        $pmsel = '';
@@ -778,28 +940,27 @@
                                
$GLOBALS['phpgw']->template->set_var('sradio','');
                        }

-                       
$GLOBALS['phpgw']->template->set_var('shour',$values['sdate_formatted']['hour']);
-                       
$GLOBALS['phpgw']->template->set_var('smin',$values['sdate_formatted']['min']);
+                       $GLOBALS['phpgw']->template->set_var('shour',$shour);
+                       $GLOBALS['phpgw']->template->set_var('smin',$smin);

-                       
$GLOBALS['phpgw']->template->set_var('end_date_select',$GLOBALS['phpgw']->common->dateformatorder($this->sbox->getYears('values[eyear]',$values['edate_formatted']['year']),
-                                                                               
                                                                
$this->sbox->getMonthText('values[emonth]',$values['edate_formatted']['month']),
-                                                                               
                                                                
$this->sbox->getDays('values[eday]',$values['edate_formatted']['day'])));
+                       $ehour  = 
$values['edate']?date('H',$values['edate']):date('H',time());
+                       $emin   = 
$values['edate']?date('i',$values['edate']):date('i',time());

                        if 
($GLOBALS['phpgw_info']['user']['preferences']['common']['timeformat'] == '12')
                        {
-                               if ($values['edate_formatted']['hour'] >= 12)
+                               if ($ehour >= 12)
                                {
                                        $amsel = '';
                                        $pmsel = ' checked';

-                                       if ($values['edate_formatted']['hour'] 
> 12)
+                                       if ($ehour > 12)
                                        {
-                                               
$values['edate_formatted']['hour'] = $values['edate_formatted']['hour'] - 12;
+                                               $ehour = $ehour - 12;
                                        }
                                }
-                               if ($values['edate_formatted']['hour'] == 0)
+                               if ($ehour == 0)
                                {
-                                       $values['edate_formatted']['hour'] = 12;
+                                       $ehour = 12;
                                }

                                $eradio = '<input type="radio" 
name="values[eampm]" value="am"' . $amsel . '>am';
@@ -811,16 +972,33 @@
                                
$GLOBALS['phpgw']->template->set_var('eradio','');
                        }

-                       
$GLOBALS['phpgw']->template->set_var('ehour',$values['edate_formatted']['hour']);
-                       
$GLOBALS['phpgw']->template->set_var('emin',$values['edate_formatted']['min']);
+                       $GLOBALS['phpgw']->template->set_var('ehour',$ehour);
+                       $GLOBALS['phpgw']->template->set_var('emin',$emin);
+
+                       if($this->siteconfig['hoursbookingday'] == 'yes')
+                       {
+                               $end = 
$end_val?$end_val:($values['edate']?mktime(12,0,0,date('m',$values['edate']),date('d',$values['edate']),date('Y',$values['edate'])):mktime(12,0,0,date('m'),date('d'),date('Y')));
+                               
$GLOBALS['phpgw']->template->set_var('end_date_select',$jscal->input('edate[str]',$end));

+                               
$GLOBALS['phpgw']->template->fp('datehandle','booking_date',True);
+                       }
+                       else
+                       {
+                               
$GLOBALS['phpgw']->template->fp('timehandle','booking_time',True);
+                       }

+                       
$GLOBALS['phpgw']->template->set_var('status_list',$this->status_format($values['status']));
                        
$GLOBALS['phpgw']->template->set_var('remark',$values['remark']);
                        
$GLOBALS['phpgw']->template->set_var('hours_descr',$values['hours_descr']);

                        
$GLOBALS['phpgw']->template->set_var('hours',$values['wh']['whours_formatted']);
                        
$GLOBALS['phpgw']->template->set_var('minutes',$values['wh']['wmin_formatted']);

+                       
$GLOBALS['phpgw']->template->set_var('km_distance',sprintf("%01.2f",$values['km_distance']));
+                       
$GLOBALS['phpgw']->template->set_var('t_journey_h',sprintf("%02d", 
floor($values['t_journey']/60)));
+                       
$GLOBALS['phpgw']->template->set_var('t_journey_m',sprintf("%02d", 
intval($values['t_journey']%60)));
+                       
$GLOBALS['phpgw']->template->set_var('surcharge_list',$this->boprojects->action_format($values['surcharge'],'charge'));
+
                        
//$GLOBALS['phpgw']->template->set_var('project_name',$GLOBALS['phpgw']->strip_html($this->boprojects->return_value('pro',$this->project_id)));

                        $GLOBALS['phpgw']->template->pfp('out','ttracker_form');
@@ -841,38 +1019,18 @@
                        return $status_list;
                }

-               function status_format_pro($status = '', $showarchive = True)
-               {
-                       if (!$status)
-                       {
-                               $status = $this->status = 'active';
-                       }
-
-                       switch ($status)
-                       {
-                               case 'active':          $stat_sel[0]=' 
selected'; break;
-                               case 'nonactive':       $stat_sel[1]=' 
selected'; break;
-                               case 'archive':         $stat_sel[2]=' 
selected'; break;
-                       }
-
-                       $status_list = '<option value="active"' . $stat_sel[0] 
. '>' . lang('Active') . '</option>' . "\n"
-                                               . '<option value="nonactive"' . 
$stat_sel[1] . '>' . lang('Nonactive') . '</option>' . "\n";
-
-                       if ($showarchive)
-                       {
-                               $status_list .= '<option value="archive"' . 
$stat_sel[2] . '>' . lang('Archive') . '</option>' . "\n";
-                       }
-                       return $status_list;
-               }
-
-               function employee_format($employee = '')
+               /*function employee_format($employee = '')
                {
                        if (! $employee)
                        {
                                $employee = $this->account;
                        }
-
-                       $employees = $this->boprojects->selected_employees();
+                       $employees = 
$this->boprojects->selected_employees(array('project_id' => 
$this->project_id,'admins_included' = True));
+
+                       if(!is_array($employees))
+                       {
+                               return '';
+                       }

                        while (list($null,$account) = each($employees))
                        {
@@ -883,63 +1041,125 @@
                                                                                
. ' [ ' . $account['account_lid'] . ' ]' . '</option>' . "\n";
                        }
                        return $employee_list;
-               }
+               }*/

                function edit_hours()
                {
-                       $project_id             = 
get_var('project_id',array('POST','GET'));
-                       $pro_main               = 
get_var('pro_main',array('POST','GET'));
-                       $hours_id               = 
get_var('hours_id',array('POST','GET'));
-
-                       $values                 = 
get_var('values',array('POST'));
-                       $referer                = 
get_var('referer',array('GET'));
-
-                       $delivery_id    = 
get_var('delivery_id',array('POST','GET'));
-                       $invoice_id             = 
get_var('invoice_id',array('POST','GET'));
-
-                       $sdate                  = 
get_var('sdate',array('POST','GET'));
-                       $edate                  = 
get_var('edate',array('POST','GET'));
-
-                       if(!$referer)  //$_POST['back'] && !$_POST['done'] && 
!$_POST['edit'])
-                       {
-                               $referer = $_SERVER['HTTP_REFERER'];
-                       }
+                       $values                                 = 
get_var('values',array('POST'));
+                       $values['project_id']   = 
get_var('project_id',array('POST','GET'));
+                       //$pro_main             = 
get_var('pro_main',array('POST','GET'));
+
+                       $hours_id                               = 
get_var('hours_id',array('POST','GET'));
+                       $delivery_id                    = 
get_var('delivery_id',array('POST','GET'));
+                       $invoice_id                             = 
get_var('invoice_id',array('POST','GET'));
+                       $edate                                  = 
get_var('edate',array('POST','GET'));
+                       $sdate                                  = 
get_var('sdate',array('POST','GET'));

-                       /*if (! $_POST['save'])
-                       {
-                               $referer = 
$GLOBALS['HTTP_SERVER_VARS']['HTTP_REFERER'] ? 
$GLOBALS['HTTP_SERVER_VARS']['HTTP_REFERER'] : $GLOBALS['HTTP_REFERER'];
-                       }*/
+                       $pro_main                               = 
$this->boprojects->return_value('main',$values['project_id']);
+                       $jscal                                  = 
CreateObject('phpgwapi.jscalendar');

                        $link_data = array
                        (
-                               'menuaction'    => 
'projects.uiprojecthours.edit_hours',
+                               'menuaction'    => 
'projects.uiprojecthours.list_hours',
                                'hours_id'              => $hours_id,
-                               'project_id'    => $this->project_id,
+                               'project_id'    => $values['project_id'],
                                'pro_main'              => $pro_main,
                                'delivery_id'   => $delivery_id,
-                               'invoice_id'    => $invoice_id,
-                               'referer'               => $referer
+                               'invoice_id'    => $invoice_id
                        );

-                       $jscal = CreateObject('phpgwapi.jscalendar');
+                       if(is_array($edate))
+                       {
+                               $end_array      = 
$jscal->input2date($edate['str']);
+                               $end_val        = $end_array['raw'];
+                       }
+
                        if(is_array($sdate))
                        {
                                $start_array    = 
$jscal->input2date($sdate['str']);
                                $start_val              = $start_array['raw'];
-                       }

-                       if(is_array($edate))
-                       {
-                               $end_array      = 
$jscal->input2date($edate['str']);
-                               $end_val        = $end_array['raw'];
+                               if($this->siteconfig['hoursbookingday'] == 'no')
+                               {
+                                       $end_val = $start_val; // use the same 
worktime start and end time
+                               }
                        }

                        if ($_POST['save'])
-                       {
-                               $values['sdate']        = $start_val;
-                               $values['edate']        = $end_val;
+                       {
+                               $values['t_journey'] = 
intval($values['t_journey_h']*60 + $values['t_journey_m']);
+                               $values['hours']   = abs($values['hours']);
+                               $values['minutes'] = abs($values['minutes']);
+
+                               if 
($GLOBALS['phpgw_info']['user']['preferences']['common']['timeformat'] == '12')
+                               {
+                                       if ($values['shour'] && 
($values['shour'] != 0) && ($values['shour'] != 12))
+                                       {
+                                               if ($values['sampm']=='pm')
+                                               {
+                                                       $values['shour'] = 
$values['shour'] + 12;
+                                               }
+                                       }
+
+                                       if ($values['shour'] && 
($values['shour'] == 12))
+                                       {
+                                               if ($values['sampm']=='am')
+                                               {
+                                                       $values['shour'] = 0;
+                                               }
+                                       }
+
+                                       if ($values['ehour'] && 
($values['ehour'] != 0) && ($values['ehour'] != 12))
+                                       {
+                                               if ($values['eampm']=='pm')
+                                               {
+                                                       $values['ehour'] = 
$values['ehour'] + 12;
+                                               }
+                                       }
+
+                                       if ($values['ehour'] && 
($values['ehour'] == 12))
+                                       {
+                                               if ($values['eampm']=='am')
+                                               {
+                                                       $values['ehour'] = 0;
+                                               }
+                                       }
+                               }
+
+                               if (intval($start_val) > 0)
+                               {
+                                       $values['smonth']       = 
date('m',$start_val);
+                                       $values['sday']         = 
date('d',$start_val);
+                                       $values['syear']        = 
date('Y',$start_val);
+                                       $values['sdate']        = 
mktime(($values['shour']?$values['shour']:0),($values['smin']?$values['smin']:0),0,$values['smonth'],$values['sday'],$values['syear']);
+                               }
+
+                               if (intval($end_val) > 0)
+                               {
+                                       $values['emonth']       = 
date('m',$end_val);
+                                       $values['eday']         = 
date('d',$end_val);
+                                       $values['eyear']        = 
date('Y',$end_val);
+                                       $values['edate']        = 
mktime(($values['ehour']?$values['ehour']:0),($values['emin']?$values['emin']:0),0,$values['emonth'],$values['eday'],$values['eyear']);
+                               }
+
+                               if(($values['hours'] == 0) && 
($values['minutes'] == 0) && ($values['t_journey'] == 0))
+                               {
+                                       $minutes = (intval($values['ehour'])*60 
+ intval($values['emin'])) - (intval($values['shour']*60) + 
intval($values['smin']));
+                                       if($minutes < 0)
+                                       {
+                                               $minutes = 0;
+                                       }
+                                       $values['hours']   = intval($minutes / 
60);
+                                       $values['minutes'] = intval($minutes % 
60);
+                               }
+                               else
+                               {
+                                       $minutes = intval($values['hours'])*60 
+ intval($values['minutes']);
+                               }
+
                                $values['pro_main']     = $pro_main;
                                $values['hours_id']     = $hours_id;
+
                                $error = $this->bohours->check_values($values);
                                if (is_array($error))
                                {
@@ -948,33 +1168,44 @@
                                else
                                {
                                        $this->bohours->save_hours($values);
-                                       Header('Location: ' . $referer);
+                                       if($link_data['menuaction'] == 
'projects.uiprojecthours.edit_hours')
+                                       {
+                                               $link_data['menuaction'] = 
'projects.uiprojecthours.list_hours';
+                                       }
+
+                                       
$GLOBALS['phpgw']->redirect_link('/index.php',$link_data);
                                }
                        }
-
-                       if($_POST['cancel'])
+                       elseif($_POST['cancel'])
                        {
-                               $link_data['menuaction'] = 
'projects.uiprojecthours.list_hours';
+                               //$link_data['menuaction'] = 
'projects.uiprojecthours.list_hours';
                                
$GLOBALS['phpgw']->redirect_link('/index.php',$link_data);
                        }
-
-                       if($_POST['delete'])
+                       elseif($_POST['delete'])
                        {
                                $link_data['menuaction'] = 
'projects.uiprojecthours.delete_hours';
                                
$GLOBALS['phpgw']->redirect_link('/index.php',$link_data);
                        }

-                       $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . ($hours_id?lang('edit work hours'):lang('add work 
hours'))
-                                                                               
                                . $this->admin_header_info();
-                       $this->display_app_header();
+                       //$GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . ($hours_id?lang('edit work hours'):lang('add work 
hours'))
+                       //                                                      
                                . $this->admin_header_info();
+
+                       $this->ui_base->display_app_header();

                        
$GLOBALS['phpgw']->template->set_file(array('hours_form' => 
'hours_formhours.tpl'));
                        
$GLOBALS['phpgw']->template->set_block('hours_form','activity','activityhandle');
                        
$GLOBALS['phpgw']->template->set_block('hours_form','activity_own','actownhandle');
+                       
$GLOBALS['phpgw']->template->set_block('hours_form','booking_date','datehandle');
+                       
$GLOBALS['phpgw']->template->set_block('hours_form','booking_time','timehandle');
                        
$GLOBALS['phpgw']->template->set_block('hours_form','main','mainhandle');

+                       $link_data['menuaction'] = 
'projects.uiprojecthours.edit_hours';
                        
$GLOBALS['phpgw']->template->set_var('action_url',$GLOBALS['phpgw']->link('/index.php',$link_data));

+                       $values['billable'] = 
$this->boprojects->soprojects->return_value('billable', $values['project_id']);
+
+                       $pro_main = 
$this->boprojects->soprojects->return_value('main', $values['project_id']);
+
                        if($pro_main)
                        {
                                $main = 
$this->boprojects->read_single_project($pro_main,'hours');
@@ -991,16 +1222,31 @@
                                
$GLOBALS['phpgw']->template->fp('mainhandle','main',True);
                        }

-                       if ($hours_id)
+                       if ($hours_id && !$_POST['save'])
                        {
-                               $values = 
$this->bohours->read_single_hours($hours_id);
-                               $activity_id    = $values['activity_id'];
-                               $pro_parent             = $values['pro_parent'];
+                               $values                         = 
$this->bohours->read_single_hours($hours_id);
+                               $activity_id            = 
$values['activity_id'];
+                               $pro_parent                     = 
$values['pro_parent'];
+                               $values['hours']        = 
$values['wh']['whours_formatted'];
+                               $values['minutes']      = 
$values['wh']['wmin_formatted'];
+                               //_debug_array($values);
                        }

-                       $start = 
$start_val?$start_val:($values['sdate']?mktime(12,0,0,date('m',$values['sdate']),date('d',$values['sdate']),date('Y',$values['sdate'])):mktime(12,0,0,date('m'),date('d'),date('Y')));
-                       $shour  = 
$values['sdate']?date('H',$values['sdate']):date('H',time());
-                       $smin   = 
$values['sdate']?date('i',$values['sdate']):date('i',time());
+                       if($start_val)
+                       {
+                               $start = $start_val;
+                       }
+                       elseif(!$start_val && $_REQUEST['day'])
+                       {
+                               $start = $_REQUEST['day'];
+                       }
+                       else
+                       {
+                               $start = 
($values['sdate']?mktime(0,0,0,date('m',$values['sdate']),date('d',$values['sdate']),date('Y',$values['sdate'])):mktime(0,0,0,date('m'),date('d'),date('Y')));
+                       }
+
+                       $shour = 
$values['sdate']?date('H',$values['sdate']):'08';
+                       $smin  = 
$values['sdate']?date('i',$values['sdate']):'00';

                        
$GLOBALS['phpgw']->template->set_var('start_date_select',$jscal->input('sdate[str]',$start));

@@ -1033,15 +1279,26 @@
                                
$GLOBALS['phpgw']->template->set_var('sradio','');
                        }

-                       $GLOBALS['phpgw']->template->set_var('shour',$shour);
-                       $GLOBALS['phpgw']->template->set_var('smin',$smin);
+                       $GLOBALS['phpgw']->template->set_var('shour', 
sprintf("%02d", $shour));
+                       $GLOBALS['phpgw']->template->set_var('smin', 
sprintf("%02d", $smin));

-                       $end = 
$end_val?$end_val:($values['edate']?mktime(12,0,0,date('m',$values['edate']),date('d',$values['edate']),date('Y',$values['edate'])):mktime(12,0,0,date('m'),date('d'),date('Y')));
-                       $ehour  = 
$values['edate']?date('H',$values['edate']):date('H',time());
-                       $emin   = 
$values['edate']?date('i',$values['edate']):date('i',time());
+                       $end = 
$end_val?$end_val:($values['edate']?mktime(0,0,0,date('m',$values['edate']),date('d',$values['edate']),date('Y',$values['edate'])):mktime(0,0,0,date('m'),date('d'),date('Y')));
+                       if(!intval(date('H',$values['edate'])) && 
!intval(date('i',$values['edate'])) && ($minutes > 0))
+                       {
+                               $s_minutes      = $shour * 60 + $smin;
+                               $e_minutes      = $s_minutes + $minutes;
+                               $ehour          = intval($e_minutes/60);
+                               $emin           = intval($e_minutes%60);
+                       }
+                       else
+                       {
+                               $ehour  = 
$values['edate']?date('H',$values['edate']):'17';
+                               $emin   = 
$values['edate']?date('i',$values['edate']):'00';
+                       }

                        
$GLOBALS['phpgw']->template->set_var('end_date_select',$jscal->input('edate[str]',$end));

+
                        if 
($GLOBALS['phpgw_info']['user']['preferences']['common']['timeformat'] == '12')
                        {
                                if ($ehour >= 12)
@@ -1068,21 +1325,32 @@
                                
$GLOBALS['phpgw']->template->set_var('eradio','');
                        }

-                       $GLOBALS['phpgw']->template->set_var('ehour',$ehour);
-                       $GLOBALS['phpgw']->template->set_var('emin',$emin);
+                       $GLOBALS['phpgw']->template->set_var('ehour', 
sprintf("%02d", $ehour));
+                       $GLOBALS['phpgw']->template->set_var('emin', 
sprintf("%02d", $emin));
+
+                       if($this->siteconfig['hoursbookingday'] == 'yes')
+                       {
+                               
$GLOBALS['phpgw']->template->fp('datehandle','booking_date',True);
+                       }
+                       else
+                       {
+                               
$GLOBALS['phpgw']->template->fp('timehandle','booking_time',True);
+                       }

                        
$GLOBALS['phpgw']->template->set_var('status_list',$this->status_format($values['status']));
                        
$GLOBALS['phpgw']->template->set_var('remark',$values['remark']);
                        
$GLOBALS['phpgw']->template->set_var('hours_descr',$values['hours_descr']);

-                       
$GLOBALS['phpgw']->template->set_var('hours',$values['wh']['whours_formatted']);
-                       
$GLOBALS['phpgw']->template->set_var('minutes',$values['wh']['wmin_formatted']);
+                       $GLOBALS['phpgw']->template->set_var('hours', 
sprintf("%02d",$values['hours']));
+                       $GLOBALS['phpgw']->template->set_var('minutes', 
sprintf("%02d",$values['minutes']));

                        
$GLOBALS['phpgw']->template->set_var('project_name',$GLOBALS['phpgw']->strip_html($this->boprojects->return_value('pro',$this->project_id)));

                        
$GLOBALS['phpgw']->template->set_var('hours_billable_checked',($values['billable']=='N'?'
 CHECKED':''));
-                       
$GLOBALS['phpgw']->template->set_var('km_distance',$values['km_distance']);
-                       
$GLOBALS['phpgw']->template->set_var('t_journey',$values['t_journey']);
+                       
$GLOBALS['phpgw']->template->set_var('km_distance',sprintf("%01.2f",$values['km_distance']));
+
+                       $GLOBALS['phpgw']->template->set_var('t_journey_h', 
sprintf('%02d', floor($values['t_journey']/60)));
+                       $GLOBALS['phpgw']->template->set_var('t_journey_m', 
sprintf('%02d', intval($values['t_journey']%60)));

                        
$GLOBALS['phpgw']->template->set_var('surcharge_list',$this->boprojects->action_format($values['surcharge'],'charge'));

@@ -1104,7 +1372,9 @@

                        if ($this->bohours->edit_perms(array('adminonly' => 
True,'status' => $values['status'],'main_co' => $main['coordinator'])))
                        {
-                               
$GLOBALS['phpgw']->template->set_var('employee','<select 
name="values[employee]">' . $this->employee_format($values['employee'])
+                               
$GLOBALS['phpgw']->template->set_var('employee','<select 
name="values[employee]">' . $this->ui_base->employee_format(array('selected' => 
($values['employee']?$values['employee']:$this->account),
+                                                                               
                                                                                
                                                                                
                                        'admins_included' => True,
+                                                                               
                                                                                
                                                                                
                                        'project_id' => $values['project_id']))
                                                                                
                                                        . '</select>');
                        }
                        else
@@ -1112,12 +1382,23 @@
                                
$GLOBALS['phpgw']->template->set_var('employee',$values['employeeout']?$values['employeeout']:$GLOBALS['phpgw']->common->grab_owner_name($this->account));
                        }

-
-
-                       if ($hours_id && 
$this->bohours->edit_perms(array('action' => 'delete','status' => 
$values['status'],'main_co' => $main['coordinator'])))
+                       if ($hours_id && 
$this->bohours->edit_perms(array('action' => 'delete','status' => 
$values['status'],'main_co' => $main['coordinator'], 'booked' => 
$values['booked'], 'employee' => $values['employee'])))
                        {
                                
$GLOBALS['phpgw']->template->set_var('delete','<input type="submit" 
name="delete" value="' . lang('Delete') .'">');
                        }
+
+                       if ($hours_id && 
$this->bohours->edit_perms(array('action' => 'edit','status' => 
$values['status'],'main_co' => $main['coordinator'], 'booked' => 
$values['booked'], 'employee' => $values['employee'])))
+                       {
+                               
$GLOBALS['phpgw']->template->set_var('save','<input type="submit" name="save" 
value="' . lang('Save') .'">');
+                       }
+                       elseif ($hours_id)
+                       {
+                               
$GLOBALS['phpgw']->template->set_var('booked',lang('Activity already booked!'));
+                       }
+                       else
+                       {
+                               
$GLOBALS['phpgw']->template->set_var('save','<input type="submit" name="save" 
value="' . lang('Save') .'">');
+                       }

                        $this->save_sessiondata('hours');
                        $GLOBALS['phpgw']->template->pfp('out','hours_form');
@@ -1126,24 +1407,29 @@
                function view_hours()
                {
                        $hours_id       = get_var('hours_id',array('GET'));
-                       //$referer      = get_var('referer',array('POST'));
                        $project_id     = get_var('project_id',array('GET'));
                        $pro_main       = get_var('pro_main',array('GET'));
-
-                       $referer = $GLOBALS['HTTP_SERVER_VARS']['HTTP_REFERER'] 
? $GLOBALS['HTTP_SERVER_VARS']['HTTP_REFERER'] : $GLOBALS['HTTP_REFERER'];
-
+
+                       $link_data = array
+                       (
+                               'menuaction' => 
'projects.uiprojecthours.list_hours',
+                               'project_id' => $project_id,
+                               'action'     => 'hours'
+                       );
                        if (!$hours_id)
                        {
-                               $GLOBALS['phpgw']->redirect_link($referer);
+                               $GLOBALS['phpgw']->redirect_link('/index.php', 
$link_data);
                        }

-                       $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . lang('view work hours')
-                                                                               
                                . $this->admin_header_info();
-                       $this->display_app_header();
+                       //$GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . lang('view work hours')
+                       //                                                      
                                . $this->admin_header_info();
+
+                       $this->ui_base->display_app_header();
+

                        
$GLOBALS['phpgw']->template->set_file(array('hours_view' => 'hours_view.tpl'));
-                       
$GLOBALS['phpgw']->template->set_block('hours_view','main','mainhandle');
-                       $GLOBALS['phpgw']->template->set_var('doneurl',$referer 
. '&project_id=' . $project_id);
+                       
$GLOBALS['phpgw']->template->set_block('hours_view','main','mainhandle');
+                       
$GLOBALS['phpgw']->template->set_var('doneurl',$GLOBALS['phpgw']->link('/index.php',
 $link_data));

                        $nopref = $this->boprojects->check_prefs();
                        if ($nopref)
@@ -1156,7 +1442,7 @@
                        }

                        $values = $this->bohours->read_single_hours($hours_id);
-
+/*
                        if($pro_main)
                        {
                                $main = 
$this->boprojects->read_single_project($pro_main,'hours');
@@ -1168,11 +1454,11 @@
                                
$GLOBALS['phpgw']->template->set_var('customer_main',$main['customerout']);
                                
$GLOBALS['phpgw']->template->set_var('url_main',$main['url']);
                                
$GLOBALS['phpgw']->template->set_var('utime_main',$main['uhours_jobs']);
-                               
$GLOBALS['phpgw']->template->set_var('ptime_main',$main['ptime']);
+                               
$GLOBALS['phpgw']->template->set_var('ptime_main',$main['ptime'].':00');
                                
$GLOBALS['phpgw']->template->set_var('atime_main',$main['ahours_jobs']);
                                
$GLOBALS['phpgw']->template->fp('mainhandle','main',True);
                        }
-
+*/
                        
$GLOBALS['phpgw']->template->set_var('status',$values['statusout']);

                        
$GLOBALS['phpgw']->template->set_var('sdate',$values['stime_formatted']['date']);
@@ -1191,7 +1477,7 @@
                        
$GLOBALS['phpgw']->template->set_var('billperae',$values['billperae']);
                        
$GLOBALS['phpgw']->template->set_var('employee',$values['employeeout']);
                        
$GLOBALS['phpgw']->template->set_var('km_distance',$values['km_distance']);
-                       
$GLOBALS['phpgw']->template->set_var('t_journey',$values['t_journey']);
+                       $GLOBALS['phpgw']->template->set_var('t_journey', 
sprintf("%02d:%02d", floor($values['t_journey']/60), 
intval($values['t_journey']%60)));

                        
$GLOBALS['phpgw']->template->set_var('project_name',$GLOBALS['phpgw']->strip_html($this->boprojects->return_value('pro',$values['project_id'])));

@@ -1213,24 +1499,26 @@

                        $link_data = array
                        (
-                               'menuaction'    => 
'projects.uiprojecthours.list_hours',
                                'hours_id'              => $hours_id,
                                'project_id'    => $project_id
                        );

                        if ($_POST['yes'] || $_POST['no'])
                        {
+                               $link_data['menuaction'] = 
'projects.uiprojecthours.list_hours';
                                if($_POST['yes'])
                                {
                                        $this->bohours->delete_hours(array('id' 
=> $hours_id));
+                                       unset($link_data['hours_id']);
                                }
+
                                
$GLOBALS['phpgw']->redirect_link('/index.php',$link_data);
                        }

-                       $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . lang('delete work hours')
-                                                                               
                                . $this->admin_header_info();
+                       //$GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . lang('delete work hours')
+                       //                                                      
                                . $this->admin_header_info();

-                       $this->display_app_header();
+                       $this->ui_base->display_app_header();

                        
$GLOBALS['phpgw']->template->set_file(array('hours_delete' => 'delete.tpl'));

@@ -1245,5 +1533,435 @@

                        $GLOBALS['phpgw']->template->pfp('out','hours_delete');
                }
+
+               function unbook_hours()
+               {
+                       $hours_id       = 
get_var('hours_id',array('POST','GET'));
+                       $project_id     = 
get_var('project_id',array('POST','GET'));
+
+                       $link_data = array
+                       (
+                               'menuaction'    => 
'projects.uiprojecthours.list_hours',
+                               'project_id'    => $project_id
+                       );
+
+                       if ($_POST['yes'] || $_POST['no'])
+                       {
+                               if($_POST['yes'])
+                               {
+                                       $this->sohours->unbook_hours($hours_id);
+                               }
+                               
$GLOBALS['phpgw']->redirect_link('/index.php',$link_data);
+                       }
+
+                       //$GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . lang('edit booked work hours')
+                       //                                                      
                                . $this->admin_header_info();
+
+                       $this->ui_base->display_app_header();
+
+                       
$GLOBALS['phpgw']->template->set_file(array('hours_booked' => 'booked.tpl'));
+
+                       $GLOBALS['phpgw']->template->set_var('unbook',lang('Are 
you sure you want to make this entry editable?'));
+                       
$GLOBALS['phpgw']->template->set_var('lang_no',lang('No'));
+                       
$GLOBALS['phpgw']->template->set_var('lang_yes',lang('Yes'));
+
+                       $link_data = array
+                       (
+                               'menuaction'    => 
'projects.uiprojecthours.unbook_hours',
+                               'hours_id'              => $hours_id
+                       );
+                       
$GLOBALS['phpgw']->template->set_var('actionurl',$GLOBALS['phpgw']->link('/index.php',$link_data));
+
+                       $GLOBALS['phpgw']->template->pfp('out','hours_booked');
+               }
+
+               function controlling_sheet()
+               {
+                       $jscal                  = 
CreateObject('phpgwapi.jscalendar');  // before phpgw_header() !!!
+                       $start_array    = 
$jscal->input2date($_REQUEST['datum']['start']);
+                       $end_array              = 
$jscal->input2date($_REQUEST['datum']['end']);
+
+                       // Workaround for new actions
+                       if(get_var('export', array('POST')))
+                       {
+                               $this->export_controlling_sheet($start_array, 
$end_array);
+                       }
+
+                       if(get_var('import', array('POST')))
+                       {
+                               
$GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/index.php', 
'menuaction=projects.uiprojecthours.import_controlling_sheet'));
+                       }
+
+                       $values = get_var('view', array('POST', 'GET'));
+
+                       //$GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . lang('controlling sheet')
+                       //                                                . 
$this->admin_header_info();
+
+                       $this->ui_base->display_app_header();
+
+
+                       
$GLOBALS['phpgw']->template->set_file(array('controlling' => 
'hours_controlling.tpl'));
+
+                       if ($this->boprojects->isprojectadmin('pad') || 
$this->boprojects->isprojectadmin('pmanager'))
+                       {
+                               $employee       = get_var('employee', 
array('POST','GET'));
+                               if(!$employee)
+                               {
+                                       $employee       = 
$GLOBALS['phpgw_info']['user']['account_id'];
+                               }
+
+                               $format_data = array(
+                                       'selected'     => array($employee)
+                               );
+
+                               $filter_employee  = '<select name="employee">';
+                               $filter_employee .=     
$this->ui_base->employee_format($format_data);
+                               $filter_employee .= '</select>';
+                               
$GLOBALS['phpgw']->template->set_var('l_employee', $filter_employee);
+                       }
+                       else
+                       {
+                               $employee = 
$GLOBALS['phpgw_info']['user']['account_id'];
+                               
$GLOBALS['phpgw']->template->set_var('l_employee', 
$GLOBALS['phpgw_info']['user']['fullname']);
+                       }
+                       $GLOBALS['phpgw']->template->set_var('l_view_sheet', 
lang('View Sheet'));
+                       $GLOBALS['phpgw']->template->set_var('l_export_sheet', 
lang('Export Sheet'));
+                       $GLOBALS['phpgw']->template->set_var('l_import_sheet', 
lang('Import Sheet'));
+
+                       $start = $start_array['raw'] > 1 ? $start_array['raw'] 
: mktime(0,0,0,date('m'),date('d') - (date('w')-1),date('Y'));
+                       $end   = $end_array['raw'] > 1 ?   $end_array['raw']   
: mktime(23,59,59,date('m'),date('d') + (7 - date('w')),date('Y'));
+
+                       
$GLOBALS['phpgw']->template->set_var('sdate_select',$jscal->input('datum[start]',
 $start));
+                       
$GLOBALS['phpgw']->template->set_var('edate_select',$jscal->input('datum[end]', 
$end));
+
+                       $GLOBALS['phpgw']->template->set_var('view_hours_link', 
$GLOBALS['phpgw']->link('/index.php', 
'menuaction=projects.uiprojecthours.edit_hours'));
+                       $calholidays = 
CreateObject('phpgwapi.calendar_holidays');
+
+                       $matrix = 
$this->bohours->build_controlling_matrix($employee, $start, $end);
+                       $prefs = $this->boprojects->read_prefs(True);
+                       $rowtitles = $prefs['cscolumns'];
+
+                       if(count($matrix) > 0)
+                       {
+                               
$GLOBALS['phpgw']->template->set_var('th_bg_theme', 
$GLOBALS['phpgw_info']['theme']['th_bg']);
+                               
$GLOBALS['phpgw']->template->set_block('controlling', 'blk_row_title0', 
'blk_row_titles0_i');
+                               for($i = 0; $i < count($rowtitles); $i++)
+                               {
+                                       
$GLOBALS['phpgw']->template->set_var('l_rowTitles', lang($rowtitles[$i]));
+                                       
$GLOBALS['phpgw']->template->parse('blk_row_titles0_i','blk_row_title0', True);
+                               }
+                               
$GLOBALS['phpgw']->template->parse('blk_row_titles0','blk_row_titles0_i', 
False);
+                               
$GLOBALS['phpgw']->template->set_var('blk_row_titles0_i','');
+
+                               
$GLOBALS['phpgw']->template->set_block('controlling', 'matrix_day', 
'matrix_day_i');
+                               foreach($matrix[0]['days'] as $key => $value)
+                               {
+                                       $holidaystyle = '';
+                                       if(!$calholidays->is_workday($key))
+                                       {
+                                               $daytotal[$key]['should'] = 0;
+                                               $holidaystyle = 
'class="holiday" ';
+                                       }       else
+                                       {
+                                               $daytotal[$key]['should'] = 480;
+                                       }
+                                       
$GLOBALS['phpgw']->template->set_var('holidaystyle', $holidaystyle);
+                                       
$GLOBALS['phpgw']->template->set_var('date', date('d.m', $key));
+                                       
$GLOBALS['phpgw']->template->parse('matrix_day_i','matrix_day', True);
+                               }
+                               
$GLOBALS['phpgw']->template->parse('matrix_days','matrix_day_i', False);
+                               
$GLOBALS['phpgw']->template->set_var('matrix_day_i','');
+
+                               $GLOBALS['phpgw']->template->set_var('l_total', 
lang('Total'));
+
+/************************* Body **********************/
+
+                               
$GLOBALS['phpgw']->template->set_block('controlling', 'body_row', 
'body_rows_i');
+                               
$GLOBALS['phpgw']->template->set_block('controlling', 'row_title', 
'row_titles_i');
+                               
$GLOBALS['phpgw']->template->set_block('controlling', 'content_cell', 
'content_cells_i');
+
+                               for($i = 0; $i < count($matrix); $i++)
+                               {
+                                       if($i%2)
+                                       {
+                                               
$GLOBALS['phpgw']->template->set_var('row_color', 'background-color: #FFFFFF');
+                                       }
+                                       else
+                                       {
+                                               
$GLOBALS['phpgw']->template->set_var('row_color', 'background-color: #EEEEEE');
+                                       }
+                                       for($j = 0; $j < count($rowtitles); 
$j++)
+                                       {
+                                               
$GLOBALS['phpgw']->template->set_var('matrix_link', 
$GLOBALS['phpgw']->link('/index.php', 
'menuaction=projects.uiprojecthours.list_hours&project_id='.$matrix[$i]['id']));
+
+                                               switch($rowtitles[$j])
+                                               {
+                                                       case 'number':
+                                                               
$GLOBALS['phpgw']->template->set_var('pnumber', $matrix[$i]['pnumber']);
+                                                               break;
+
+                                                       case 'edateout':
+                                                               
if($matrix[$i]['enddate'] > 0)
+                                                               {
+                                                                       
$GLOBALS['phpgw']->template->set_var('enddate', 
date($GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'],$matrix[$i]['enddate']));
+                                                               }
+                                                               break;
+
+                                                       default:
+                                                               
$GLOBALS['phpgw']->template->set_var('title', $matrix[$i]['title']);
+                                               }
+
+                                               
$GLOBALS['phpgw']->template->parse('row_titles_i','row_title', True);
+                                       }
+                                       
$GLOBALS['phpgw']->template->parse('row_titles','row_titles_i', False);
+                                       
$GLOBALS['phpgw']->template->set_var('row_titles_i','');
+
+                                       foreach($matrix[$i]['days'] as $key => 
$value)
+                                       {
+                                               $daytotal[$key]['booked'] += 
$value;
+                                               $matrix[$i]['days']['total'] += 
$value;
+
+                                               
$GLOBALS['phpgw']->template->set_var('matrix_value', $matrix[$i]['id'].', 
'.$key);
+                                               
$GLOBALS['phpgw']->template->set_var('content_value', 
$this->bohours->format_minutes($value) != '' ? 
$this->bohours->format_minutes($value) : '&nbsp;');
+                                               
$GLOBALS['phpgw']->template->parse('content_cells_i','content_cell', True);
+                                       }
+                                       
$GLOBALS['phpgw']->template->parse('content_cells','content_cells_i', False);
+                                       
$GLOBALS['phpgw']->template->set_var('content_cells_i','');
+
+                                       
$GLOBALS['phpgw']->template->set_var('row_total_value', 
$this->bohours->format_minutes($matrix[$i]['days']['total']));
+
+                                       
$GLOBALS['phpgw']->template->parse('body_rows_i','body_row', True);
+                               }
+                               
$GLOBALS['phpgw']->template->parse('body_rows','body_rows_i', False);
+                               
$GLOBALS['phpgw']->template->set_var('body_rows_i','');
+
+/******************* foot ************************/
+
+                               
$GLOBALS['phpgw']->template->set_var('theme_th_bg',     
$GLOBALS['phpgw_info']['theme']['th_bg']);
+                               
$GLOBALS['phpgw']->template->set_var('rowtitles', count($rowtitles));
+                               $GLOBALS['phpgw']->template->set_var('l_total', 
lang('Total'));
+
+                               
$GLOBALS['phpgw']->template->set_block('controlling', 'daytotal', 
'daytotals_i');
+                               foreach($daytotal as $key => $value)
+                               {
+                                       $booked_total += $value['booked'];
+
+                                       
$GLOBALS['phpgw']->template->set_var('format_minutes', 
$this->bohours->format_minutes($value['booked']));
+                                       
$GLOBALS['phpgw']->template->parse('daytotals_i','daytotal', True);
+                               }
+                               
$GLOBALS['phpgw']->template->parse('daytotals','daytotals_i', False);
+                               
$GLOBALS['phpgw']->template->set_var('daytotals_i','');
+
+                               
$GLOBALS['phpgw']->template->set_var('booked_total', 
$this->bohours->format_minutes($booked_total));
+                               
$GLOBALS['phpgw']->template->set_var('theme_bg', 
$GLOBALS['phpgw_info']['theme']['th_bg']);
+                               
$GLOBALS['phpgw']->template->set_var('rowtitles', count($rowtitles));
+                               
$GLOBALS['phpgw']->template->set_var('l_overtime', lang('Overtime'));
+
+                               
$GLOBALS['phpgw']->template->set_block('controlling', 'daytotal2', 
'daystotal2_i');
+                               foreach($daytotal as $key => $value)
+                               {
+                                       $should_total += $value['should'];
+
+                                       
$GLOBALS['phpgw']->template->set_var('format_minutes', 
$this->bohours->format_minutes($value['booked'] - $value['should']));
+                                       
$GLOBALS['phpgw']->template->parse('daystotal2_i','daytotal2', True);
+                               }
+                               
$GLOBALS['phpgw']->template->parse('daystotal2','daystotal2_i', False);
+                               
$GLOBALS['phpgw']->template->set_var('daystotal2_i','');
+
+                               
$GLOBALS['phpgw']->template->set_var('booked_total2', 
$this->bohours->format_minutes($booked_total - $should_total));
+                       }
+                       $GLOBALS['phpgw']->template->pfp('out','controlling', 
False);
+               }
+
+               function export_controlling_sheet($start_array, $end_array)
+               {
+                       $export = 
$this->bohours->export_controlling_sheet($start_array['raw'],
+                                                                          
$end_array['raw']
+                                                                         );
+
+                       header('Content-Disposition: attachment; 
filename=controllingsheet_'.$start_array['month'].'_'.$start_array['year'].'.csv');
+                       echo $export;
+                       $GLOBALS['phpgw']->common->phpgw_exit();
+               }
+
+               function import_controlling_sheet()
+               {
+                       //$GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . lang('import controlling sheet')
+                       //                                                . 
$this->admin_header_info();
+
+                       $this->ui_base->display_app_header();
+
+
+                       if(get_var('upload', array('POST', 'GET')))
+                       {
+                               if($_FILES['file']['name'])
+                               {
+                                       if(!$_FILES['file']['error'])
+                                       {
+                                               $handle = fopen 
($_FILES['file']['tmp_name'], 'r');
+                                               $content = fread($handle, 
'100000');
+                                               $content = str_replace('"','', 
$content);
+                                               $lines = explode("\n", 
$content);
+                                               $savematrix = 
$this->bohours->build_import_controlling_sheet($lines, $error);
+                                       }
+                                       else
+                                       {
+                                               $error = lang('error while 
uploading file');
+                                       }
+                               }
+                               else
+                               {
+                                       $error = lang('no file selected');
+                               }
+
+                               
$GLOBALS['phpgw']->template->set_file(array('controlling_import_result' => 
'controlling_import_result.tpl'));
+                               $out = '';
+
+                               if(!strlen($error) && (count($savematrix)>0))
+                               {
+                                       $out .= '<tr>';
+                                       $out .= '<td>&nbsp;</td>';
+                                       $out .= '<td>';
+                                       $out .= lang('project');
+                                       $out .= '</td>';
+                                       $out .= '<td>';
+                                       $out .= lang('project id');
+                                       $out .= '</td>';
+                                       $out .= '<td>';
+                                       $out .= lang('customer');
+                                       $out .= '</td>';
+                                       $out .= '<td>';
+                                       $out .= lang('date');
+                                       $out .= '</td>';
+                                       $out .= '<td>';
+                                       $out .= lang('work time');
+                                       $out .= '</td>';
+                                       $out .= '<td>';
+                                       $out .= lang('time of journey');
+                                       $out .= '</td>';
+                                       $out .= '<td>';
+                                       $out .= lang('description');
+                                       $out .= '</td>';
+                                       $out .= '<td>';
+                                       $out .= lang('result');
+                                       $out .= '</td>';
+                                       $out .= '</tr>';
+
+                                       for($i=0; $i < count($savematrix); $i++)
+                                       {
+                                               
if(!strlen($savematrix[$i]['error']))
+                                               {
+                                                       $hours   = (int) 
($savematrix[$i]['time'] / 60);
+                                                       $minutes = 
$savematrix[$i]['time'] % 60;
+                                                       $j_hours   = (int) 
($savematrix[$i]['journey'] / 60);
+                                                       $j_minutes = 
$savematrix[$i]['journey'] % 60;
+
+                                                       $sum_hm = 
$savematrix[$i]['time'] + $savematrix[$i]['journey'];
+                                                       $sum_h  = (int) 
($sum_hm / 60);
+                                                       $sum_m = $sum_hm % 60;
+
+                                                       $s_h = (int) ((24 - 
$sum_h) / 2);
+                                                       $s_m = 0;
+                                                       $e_h = $s_h + $sum_h;
+                                                       $e_m = $sum_m;
+
+                                                       $cebvalues = 
array('employee'    => $savematrix[$i]['employee'],
+                                                                          
'hours_descr' => $savematrix[$i]['description'],
+                                                                          
'remark'      => lang('imported hours on').' 
'.date($GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'], 
time()),
+                                                                          
'hours'       => $hours,
+                                                                          
'minutes'     => $minutes,
+                                                                          
'shour'       => $s_h,
+                                                                          
'smin'        => $s_m,
+                                                                          
'ehour'       => $e_h,
+                                                                          
'emin'        => $e_m,
+                                                                          
't_journey_h' => $j_hours,
+                                                                          
't_journey_m' => $j_minutes,
+                                                                          
'km_distance' => 0.00,
+                                                                          
'status'      => 'done',
+                                                                          
'surcharge'   => '',
+                                                                          
'project_id'  => $savematrix[$i]['projectid'],
+                                                                          
't_journey'   => $savematrix[$i]['journey'],
+                                                                          
'smonth'      => date('m', $savematrix[$i]['date']),
+                                                                          
'sday'        => date('d', $savematrix[$i]['date']),
+                                                                          
'syear'       => date('Y', $savematrix[$i]['date']),
+                                                                          
'sdate'       => $savematrix[$i]['date'],
+                                                                          
'emonth'      => date('m', $savematrix[$i]['date']),
+                                                                          
'eday'        => date('d', $savematrix[$i]['date']),
+                                                                          
'eyear'       => date('Y', $savematrix[$i]['date']),
+                                                                          
'edate'       => $savematrix[$i]['date']
+                                                                         );
+
+                                                       $checkerrors = 
$this->bohours->check_values($cebvalues);
+                                                       if($checkerrors == True)
+                                                       {
+                                                               
$this->bohours->save_hours($cebvalues);
+                                                               $result = 
lang('imported');
+                                                               $style = 
'passed';
+                                                       }
+                                                       else
+                                                       {
+                                                               $result = 
lang('value check not passed');
+                                                               $style = 
'notpassed';
+                                                       }
+                                               }
+                                               else
+                                               {
+                                                       $result = 
$savematrix[$i]['error'];
+                                                       $style = 'notpassed';
+                                               }
+                                               $out .= '<tr 
class="'.$style.'">';
+                                               $out .= '<td>';
+                                               $out .= sprintf("%d" ,$i);
+                                               $out .= '</td>';
+                                               $out .= '<td>';
+                                               $out .= 
$savematrix[$i]['projecttitle'];
+                                               $out .= '</td>';
+                                               $out .= '<td>';
+                                               $out .= 
$savematrix[$i]['projectnumber'];
+                                               $out .= '</td>';
+                                               $out .= '<td>';
+                                               $out .= 
$savematrix[$i]['customer_org'];
+                                               $out .= '</td>';
+                                               $out .= '<td>';
+                                               $out .= 
date($GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat'], 
$savematrix[$i]['date']);
+                                               $out .= '</td>';
+                                               $out .= '<td align="right">';
+                                               $out .= 
$cebvalues['hours'].':'.sprintf("%02d", $cebvalues['minutes']);
+                                               $out .= '</td>';
+                                               $out .= '<td align="right">';
+                                               $out .= 
$cebvalues['t_journey_h'].':'.sprintf("%02d", $cebvalues['t_journey_m']);
+                                               $out .= '</td>';
+                                               $out .= '<td>';
+                                               $out .= 
$savematrix[$i]['description'];
+                                               $out .= '</td>';
+                                               $out .= '<td>';
+                                               $out .= $result;
+                                               $out .= '</td>';
+                                               $out .= '</tr>';
+                                       }
+                               }
+                               else
+                               { // nothing to import
+                                               $out .= lang('found no data for 
import');
+                               }
+
+                               $GLOBALS['phpgw']->template->set_var('action', 
$GLOBALS['phpgw']->link('/index.php', 
'menuaction=projects.uiprojecthours.controlling_sheet'));
+                               
$GLOBALS['phpgw']->template->set_var('import_result', $out);
+                               
$GLOBALS['phpgw']->template->pfp('out','controlling_import_result', True);
+                               $GLOBALS['phpgw']->common->phpgw_exit();
+
+                       }
+                       
$GLOBALS['phpgw']->template->set_file(array('controlling' => 
'hours_import_controlling.tpl'));
+                       $GLOBALS['phpgw']->template->set_var('l_upload', 
lang('upload'));
+                       $GLOBALS['phpgw']->template->set_var('l_statement', 
lang('Please beware').':<br>'
+                                                                               
 .lang('All correct hours in uploaded CSV file will be added to your 
account').'<br>'
+                                                                               
 .lang('It will NOT check if you already have uploaded hours for a certain day')
+                                                                               
);
+                       $GLOBALS['phpgw']->template->set_var('error', $error);
+                       $GLOBALS['phpgw']->template->set_var('action', 
$GLOBALS['phpgw']->link('/index.php', 
'menuaction=projects.uiprojecthours.import_controlling_sheet'));
+
+                       $GLOBALS['phpgw']->template->pfp('out','controlling', 
True);
+                       $GLOBALS['phpgw']->common->phpgw_exit();
+               }
        }
 ?>

====================================================
Index: projects/inc/class.uiconfig.inc.php
diff -u projects/inc/class.uiconfig.inc.php:1.29 
projects/inc/class.uiconfig.inc.php:1.30
--- projects/inc/class.uiconfig.inc.php:1.29    Sat Jun 19 22:47:31 2004
+++ projects/inc/class.uiconfig.inc.php Mon Mar 14 17:39:39 2005
@@ -37,19 +37,23 @@

                var $public_functions = array
                (
-                       'edit_activity'                 => True,
-                       'list_activities'               => True,
-                       'list_admins'                   => True,
-                       'list_roles'                    => True,
-                       'list_employees'                => True,
-                       'edit_admins'                   => True,
-                       'abook'                                 => True,
-                       'preferences'                   => True,
-                       'delete_pa'                             => True,
-                       'list_employees'                => True,
-                       'list_events'                   => True,
-                       'edit_employee_factor'  => True,
-                       'list_surcharges'               => True
+                       'edit_activity'                                 => True,
+                       'list_activities'                               => True,
+                       'list_admins'                                   => True,
+                       'list_roles'                                    => True,
+                       'list_employees'                                => True,
+                       'edit_admins'                                   => True,
+                       //'abook'                                               
        => True,
+                       'preferences'                                   => True,
+                       'delete_pa'                                             
=> True,
+                       'list_employees'                                => True,
+                       'list_events'                                   => True,
+                       'edit_employee_factor'                  => True,
+                       'list_surcharges'                               => True,
+                       'config_worktime_statusmail'    => True,
+                       'config_workhours_booking'              => True,
+                       'config_worktime_warnmail'              => True,
+                       'config_proid_help_msg'                 => True
                );

                function uiconfig()
@@ -67,6 +71,12 @@
                        $this->cat_id           = $this->boconfig->cat_id;

                        $this->siteconfig       = 
$this->boconfig->boprojects->siteconfig;
+
+                       if(!is_object($GLOBALS['phpgw']->js))
+                       {
+                               $GLOBALS['phpgw']->js = 
createObject('phpgwapi.javascript');
+                       }
+                       $GLOBALS['phpgw']->js->validate_file('common','popup');
                }

                function save_sessiondata($action)
@@ -106,7 +116,6 @@
                        
$GLOBALS['phpgw']->template->set_var('lang_access',lang('access'));

                        
$GLOBALS['phpgw']->template->set_var('lang_projects',lang('Projects'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_jobs',lang('Jobs'));
                        
$GLOBALS['phpgw']->template->set_var('lang_ttracker',lang('time tracker'));
                        
$GLOBALS['phpgw']->template->set_var('lang_archiv',lang('archive'));
                        
$GLOBALS['phpgw']->template->set_var('lang_statistics',lang('Statistics'));
@@ -165,6 +174,10 @@

                        
$GLOBALS['phpgw']->template->set_var('lang_descr',lang('description'));
                        
$GLOBALS['phpgw']->template->set_var('lang_surcharge',lang('surcharge'));
+
+                       
$GLOBALS['phpgw']->template->set_var('opt_off_desc',lang('off'));
+                       
$GLOBALS['phpgw']->template->set_var('opt_weekly_desc',lang('weekly'));
+                       
$GLOBALS['phpgw']->template->set_var('opt_monthly_desc',lang('monthly'));
                }

                function display_app_header()
@@ -175,7 +188,7 @@
                                
$GLOBALS['phpgw']->template->set_block('header','projects_header');
                                
$GLOBALS['phpgw']->template->set_block('header','projects_admin_header');

-                               if 
($this->boconfig->boprojects->isprojectadmin())
+                               if 
($this->boconfig->boprojects->isprojectadmin('pad') || 
$this->boconfig->boprojects->isprojectadmin('pmanager'))
                                {
                                        switch($this->siteconfig['accounting'])
                                        {
@@ -187,11 +200,10 @@
                                                        
$GLOBALS['phpgw']->template->set_var('link_accounting',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiconfig.list_employees&action=accounting'));
                                                        
$GLOBALS['phpgw']->template->set_var('lang_accounting',lang('Accounting'));
                                        }
-                                       
$GLOBALS['phpgw']->template->set_var('link_budget',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojects.list_budget&action=mains'));
-                                       
$GLOBALS['phpgw']->template->set_var('lang_budget',lang('budget'));
                                        
$GLOBALS['phpgw']->template->fp('admin_header','projects_admin_header');
                                }

+                               
$GLOBALS['phpgw']->template->set_var('link_budget',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojects.list_budget&action=mains'));
                                
$GLOBALS['phpgw']->template->set_var('link_jobs',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojects.list_projects&action=subs'));
                                
$GLOBALS['phpgw']->template->set_var('link_hours',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojecthours.list_projects&action=mains'));
                                
$GLOBALS['phpgw']->template->set_var('link_ttracker',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojecthours.ttracker'));
@@ -221,12 +233,12 @@

                        //_debug_array($employees);
                        //_debug_array($selected);
-                       while (is_array($emps) && list($null,$account) = 
each($emps))
+                       while (is_array($emps) && (list($null,$account) = 
each($emps)))
                        {
                                $s .= '<option value="' . 
$account['account_id'] . '"';
                                if($selected == $account['account_id'])
                                {
-                                       $s .= ' SELECTED';
+                                       $s .= ' selected="selected"';
                                }
                                $s .= '>';
                                $s .= 
$GLOBALS['phpgw']->common->display_fullname($account['account_lid'],$account['account_firstname'],$account['account_lastname'])
@@ -250,6 +262,15 @@

                        $jscal = CreateObject('phpgwapi.jscalendar');

+                       if (!is_numeric($values['cost_centre']))
+                       {
+                               $values['cost_centre'] = 0;
+                       }
+                       if (!is_numeric($values['weekly_workhours']))
+                       {
+                               $values['weekly_workhours'] = 40;
+                       }
+
                        if ($values['save'])
                        {
                                //_debug_array($values);
@@ -262,7 +283,7 @@
                                if(is_array($edate))
                                {
                                        $end_array                      = 
$jscal->input2date($edate['str']);
-                                       $values['edate']        = 
$end_array['raw'];
+                                       $values['edate']        = 
intval($end_array['raw']) + 86399; // 23:59:59 for enddate
                                }

                                $error = 
$this->boconfig->check_pa_values($values,'accounting');
@@ -289,10 +310,10 @@

                        
$GLOBALS['phpgw']->template->set_file(array('emp_list_t' => 
'list_employees.tpl'));
                        
$GLOBALS['phpgw']->template->set_block('emp_list_t','emp_list','list');
-                       
//$GLOBALS['phpgw']->template->set_block('emp_list_t','emp_tframe','flist');
+                       
$GLOBALS['phpgw']->template->set_block('emp_list_t','emp_tframe','flist');

-                       
$GLOBALS['phpgw']->template->set_var('search_action',$GLOBALS['phpgw']->link('/index.php',$link_data));
-                       
$GLOBALS['phpgw']->template->set_var('search_list',$this->nextmatchs->search(array('query'
 => $this->query)));
+                       
//$GLOBALS['phpgw']->template->set_var('search_action',$GLOBALS['phpgw']->link('/index.php',$link_data));
+                       
//$GLOBALS['phpgw']->template->set_var('search_list',$this->nextmatchs->search(array('query'
 => $this->query)));
                        
$GLOBALS['phpgw']->template->set_var('action_url',$GLOBALS['phpgw']->link('/index.php',$link_data));

                        $emps = $this->boconfig->read_accounting_factors();
@@ -301,10 +322,10 @@

                        $left = 
$this->nextmatchs->left('/index.php',$this->start,$this->boconfig->total_records,$link_data);
                        $right = 
$this->nextmatchs->right('/index.php',$this->start,$this->boconfig->total_records,$link_data);
-                       $GLOBALS['phpgw']->template->set_var('left',$left);
-                       $GLOBALS['phpgw']->template->set_var('right',$right);
+                       //$GLOBALS['phpgw']->template->set_var('left',$left);
+                       //$GLOBALS['phpgw']->template->set_var('right',$right);

-               
$GLOBALS['phpgw']->template->set_var('lang_showing',$this->nextmatchs->show_hits($this->boconfig->total_records,$this->start));
+       
//$GLOBALS['phpgw']->template->set_var('lang_showing',$this->nextmatchs->show_hits($this->boconfig->total_records,$this->start));

 // ------------------------------ end nextmatch 
------------------------------------------

@@ -315,6 +336,8 @@
                        
$GLOBALS['phpgw']->template->set_var('sort_edate',$this->nextmatchs->show_sort_order($this->sort,'edate',$this->order,'/index.php',lang('end
 date'),$link_data));
                        
$GLOBALS['phpgw']->template->set_var('sort_per_hour',$this->nextmatchs->show_sort_order($this->sort,'accounting',$this->order,'/index.php',lang('per
 hour'),$link_data));
                        
$GLOBALS['phpgw']->template->set_var('sort_per_day',$this->nextmatchs->show_sort_order($this->sort,'d_accounting',$this->order,'/index.php',lang('per
 day'),$link_data));
+                       
$GLOBALS['phpgw']->template->set_var('weekly_workhours',$this->nextmatchs->show_sort_order($this->sort,'weekly_workhours',$this->order,'/index.php',lang('weekly
 workhours'),$link_data));
+                       
$GLOBALS['phpgw']->template->set_var('cost_centre',$this->nextmatchs->show_sort_order($this->sort,'cost_centre',$this->order,'/index.php',lang('cost
 centre'),$link_data));
                        
$GLOBALS['phpgw']->template->set_var('currency',$GLOBALS['phpgw_info']['user']['preferences']['common']['currency']);

                        
$GLOBALS['phpgw']->template->set_var('lang_accounting',lang('accounting'));
@@ -333,6 +356,8 @@
                                                'd_factor'                      
        => $emps[$i]['d_accounting'],
                                                'sdate_formatted'               
=> $emps[$i]['sdate_formatted'],
                                                'edate_formatted'               
=> $emps[$i]['edate_formatted'],
+                                               'weekly_workhours_num'  => 
$emps[$i]['weekly_workhours'],
+                                               'cost_centre_num'               
=> $emps[$i]['cost_centre'],
                                                'delete_emp'                    
=> 
$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiconfig.list_employees&id='
                                                                                
                                                        . $emps[$i]['id'] . 
'&delete=True'),
                                                'delete_img'                    
=> $GLOBALS['phpgw']->common->image('phpgwapi','delete'),
@@ -347,13 +372,18 @@
                        }
                        
$GLOBALS['phpgw']->template->set_var('accounting',$values['accounting']);
                        
$GLOBALS['phpgw']->template->set_var('d_accounting',$values['d_accounting']);
+                       
$GLOBALS['phpgw']->template->set_var('weekly_workhours_num',$values['weekly_workhours']);
+                       
$GLOBALS['phpgw']->template->set_var('cost_centre_num',$values['cost_centre']);
                        
$GLOBALS['phpgw']->template->set_var('lang_add_factor',lang('add factor'));
                        
$GLOBALS['phpgw']->template->set_var('emp_select',$this->employee_format($values['account_id']));

                        
$GLOBALS['phpgw']->template->set_var('sdate_select',$jscal->input('sdate[str]',$values['sdate']));
                        
$GLOBALS['phpgw']->template->set_var('edate_select',$jscal->input('edate[str]',$values['edate']));

+                       // button for showing monthly diamant data
+
                        $this->save_sessiondata('accounting');
+                       $GLOBALS['phpgw']->template->set_var('flist','');
                        
$GLOBALS['phpgw']->template->pfp('out','emp_list_t',True);
                }

@@ -382,7 +412,7 @@
                                if(is_array($edate))
                                {
                                        $end_array                      = 
$jscal->input2date($edate['str']);
-                                       $values['edate']        = 
$end_array['raw'];
+                                       $values['edate']        = 
$end_array['raw'] + 86399; // 23:59:59 for enddate;
                                }
                                $values['id'] = $id;
                                //_debug_array($values);
@@ -414,6 +444,10 @@
                        
$GLOBALS['phpgw']->template->set_var('accounting',$values['accounting']);
                        
$GLOBALS['phpgw']->template->set_var('d_accounting',$values['d_accounting']);
                        
$GLOBALS['phpgw']->template->set_var('lang_save_factor',lang('save factor'));
+                       
$GLOBALS['phpgw']->template->set_var('weekly_workhours',lang('weekly 
workhours'));
+                       
$GLOBALS['phpgw']->template->set_var('cost_centre',lang('cost centre'));
+                       
$GLOBALS['phpgw']->template->set_var('weekly_workhours_num',$values['weekly_workhours']);
+                       
$GLOBALS['phpgw']->template->set_var('cost_centre_num',$values['cost_centre']);
                        
$GLOBALS['phpgw']->template->set_var('emp_select',$this->employee_format($values['account_id']));

                        
$GLOBALS['phpgw']->template->set_var('sdate_select',$jscal->input('sdate[str]',$values['sdate']));
@@ -949,10 +983,10 @@
                                }
                                if($events[$i]['event_type'] == 'percent')
                                {
-                                       $extra = 
$events[$i]['event_extra']==0?100:$events[$i]['event_extra'] . '&nbsp;' . 
lang('% to');
+                                       $extra = 
$events[$i]['event_extra']==0?100:$events[$i]['event_extra'] . '&nbsp;' . 
lang('% from');
                                        $values['percent'] = 
$values['percent']?$values['percent']:$events[$i]['event_extra'];
                                }
-                               
$GLOBALS['phpgw']->template->set_var('event_name',$events[$i]['event_name']);
+                               
$GLOBALS['phpgw']->template->set_var('event_name',lang($events[$i]['event_name']));
                                
$GLOBALS['phpgw']->template->set_var('event_extra',$extra);
                                
$GLOBALS['phpgw']->template->fp('list','event_list',True);
                        }
@@ -981,12 +1015,19 @@

                        if ($_POST['save'])
                        {
-                               if($_POST['new_charge'])
+                               if(strlen(trim($values['charge_name'])) == 0)
                                {
-                                       $values['charge_id'] = 0;
+                                       
$GLOBALS['phpgw']->template->set_var('message', lang('please enter a 
description'));
+                               }
+                               else
+                               {
+                                       if($_POST['new_charge'])
+                                       {
+                                               $values['charge_id'] = 0;
+                                       }
+                                       
$this->boconfig->save_surcharge($values);
+                                       
$GLOBALS['phpgw']->template->set_var('message',lang('surcharge %1 has been 
saved',$values['charge_name']));
                                }
-                               $this->boconfig->save_surcharge($values);
-                               
$GLOBALS['phpgw']->template->set_var('message',lang('surcharge %1 has been 
saved',$values['charge_name']));
                        }

                        if ($_POST['done'])
@@ -1036,6 +1077,8 @@
                                                                                
                                                        . $charge['charge_id'] 
. '&delete=True'),
                                                'edit_url'                      
        => 
$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiconfig.list_surcharges&charge_id='
                                                                                
                                                        . $charge['charge_id'] 
. '&edit=True'),
+                                               'edit_img'                      
=> $GLOBALS['phpgw']->common->image('phpgwapi','edit'),
+                                               'lang_edit_surcharge'   => 
lang('edit surcharge'),
                                                'delete_img'                    
=> $GLOBALS['phpgw']->common->image('phpgwapi','delete'),
                                                'lang_delete_surcharge' => 
lang('delete surcharge')
                                        ));
@@ -1051,7 +1094,37 @@
                        
$GLOBALS['phpgw']->template->pfp('out','charge_list_t',True);
                }

-               function abook()
+               function config_proid_help_msg()
+               {
+                       if($_POST['save'])
+                       {
+                               
$this->boconfig->config_proid_help_msg(array('action' => 
'save','proid_help_msg' => $_POST['proid_help_msg']));
+                       }
+
+                       if($_POST['cancel'])
+                       {
+                               
$GLOBALS['phpgw']->redirect_link('/admin/index.php');
+                       }
+
+                       $link_data = array
+                       (
+                               'menuaction' => 
'projects.uiconfig.config_proid_help_msg'
+                       );
+
+                       $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . lang('edit project id help msg');
+                       $GLOBALS['phpgw']->common->phpgw_header();
+                       echo parse_navbar();
+                       $this->set_app_langs();
+
+                       $GLOBALS['phpgw']->template->set_file(array('proidhelp' 
=> 'config_proid_help.tpl'));
+                       
$GLOBALS['phpgw']->template->set_var('action_url',$GLOBALS['phpgw']->link('/index.php',$link_data));
+                       
$GLOBALS['phpgw']->template->set_var('helpmsg',stripslashes($this->boconfig->config_proid_help_msg(array('action'
 => 'get'))));
+                       
$GLOBALS['phpgw']->template->set_var('help_url',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojects_base.proid_help_popup'));
+                       
$GLOBALS['phpgw']->template->set_var('lang_show',lang('show help msg'));
+                       
$GLOBALS['phpgw']->template->pfp('out','proidhelp',True);
+               }
+
+               /*function abook()
                {
                        $start          = get_var('start',array('POST'));
                        $cat_id         = get_var('cat_id',array('POST'));
@@ -1157,12 +1230,11 @@
                        $GLOBALS['phpgw']->template->p('out');

                        $GLOBALS['phpgw']->common->phpgw_exit();
-               }
+               }*/

                function preferences()
                {
                        //_debug_array($_POST['prefs']);
-
                        
//_debug_array($GLOBALS['phpgw_info']['user']['preferences']);
                        if ($_POST['save'])
                        {
@@ -1191,74 +1263,346 @@
                        
$GLOBALS['phpgw']->template->set_var('action_url',$GLOBALS['phpgw']->link('/index.php',$link_data));

                        $prefs = $this->boconfig->boprojects->read_prefs();
+                       _debug_array($prefs);

-                       //_debug_array($prefs);
+                       $columns = array(
+                                        array('id'   => 'priority',
+                                              'name' => lang('priority')
+                                             ),
+                                        array('id'   => 'number',
+                                              'name' => lang('project id')
+                                             ),
+                                        array('id'   => 'investment_nr',
+                                              'name' => lang('investment nr')
+                                             ),
+                                        array('id'   => 'coordinatorout',
+                                              'name' => lang('coordinator')
+                                             ),
+                                        array('id'   => 'customerout',
+                                              'name' => lang('customer')
+                                             ),
+                                        array('id'   => 'customer_nr',
+                                              'name' => lang('customer nr')
+                                             ),
+                                        array('id'   => 'sdateout',
+                                              'name' => lang('start date')
+                                             ),
+                                        array('id'   => 'edateout',
+                                              'name' => lang('date due')
+                                             ),
+                                        array('id'   => 'psdateout',
+                                              'name' => lang('start date 
planned')
+                                             ),
+                                        array('id'   => 'pedateout',
+                                              'name' => lang('date due 
planned')
+                                             ),
+                                        array('id'   => 'previousout',
+                                              'name' => lang('previous')
+                                             ),
+                                        array('id'   => 'phours',
+                                              'name' => lang('time planned')
+                                             ),
+                                        array('id'   => 'budget',
+                                              'name' => lang('budget')
+                                             ),
+                                        array('id'   => 'e_budget',
+                                              'name' => lang('extra budget')
+                                             ),
+                                        array('id'   => 'url',
+                                              'name' => lang('url')
+                                             ),
+                                        array('id'   => 'reference',
+                                              'name' => lang('reference')
+                                             ),
+                                        array('id'   => 'accountingout',
+                                              'name' => lang('accounting')
+                                             ),
+                                        array('id'   => 
'project_accounting_factor',
+                                              'name' => lang('accounting 
factor').' '.lang('per hour')
+                                             ),
+                                        array('id'   => 
'project_accounting_factor_d',
+                                              'name' => lang('accounting 
factor').' '.lang('per day')
+                                             ),
+                                        array('id'   => 'billableout',
+                                              'name' => lang('billable')
+                                             ),
+                                        array('id'   => 'discountout',
+                                              'name' => lang('discount')
+                                             ),
+                                        array('id'   => 'mstones',
+                                              'name' => lang('milestones')
+                                             )
+                                       );
+
+                       $cscolumns = array(
+                                        array('id'   => 'title',
+                                              'name' => lang('title')
+                                             ),
+                                        array('id'   => 'number',
+                                              'name' => lang('project id')
+                                             ),
+                                        array('id'   => 'edateout',
+                                              'name' => lang('date due')
+                                             )
+                                       );
+                       $mailTypeEntries = array(
+                                    array('id'                 => 'off',
+                                          'name'       => lang('off')
+                                          ),
+                                    array('id'         => 'on',
+                                          'name'       => lang('active')
+                                          )
+                                    );
+
+                       for ($i = 0; $i < count($columns); $i++)
+                       {
+                               $selected = '';
+                               if(is_array($prefs['columns']) && 
in_array($columns[$i]['id'], $prefs['columns']))
+                               {
+                                       $selected = 'selected="selected"';
+                               }
+                               $sel .= '<option value="'.$columns[$i]['id'].'" 
'.$selected.'>'.$columns[$i]['name'].'</option>'."\n";
+                       }
+
+                       for ($i = 0; $i < count($cscolumns); $i++)
+                       {
+                               $selected = '';
+                               if(is_array($prefs['cscolumns']) && 
in_array($cscolumns[$i]['id'], $prefs['cscolumns']))
+                               {
+                                       $selected = 'selected="selected"';
+                               }
+                               $cssel .= '<option 
value="'.$cscolumns[$i]['id'].'" 
'.$selected.'>'.$cscolumns[$i]['name'].'</option>'."\n";
+                       }

-                       $columns = array
-                       (
-                               'priority',
-                               'number',
-                               'investment_nr',
-                               'coordinatorout',
-                               'customerout',
-                               'customer_nr',
-                               'sdateout',
-                               'edateout',
-                               'psdateout',
-                               'pedateout',
-                               'previousout',
-                               'phours',
-                               'budget',
-                               'e_budget',
-                               'url',
-                               'reference',
-                               'accountingout',
-                               'project_accounting_factor',
-                               'project_accounting_factor_d',
-                               'billableout',
-                               'discountout',
-                               'mstones'
-                       );
+                       
$GLOBALS['phpgw']->template->set_var('lang_select_columns',lang('columns to 
show in the projects list'));
+                       
$GLOBALS['phpgw']->template->set_var('column_select',$sel);
+                       
$GLOBALS['phpgw']->template->set_var('lang_select_cs_columns',lang('columns to 
show in the controlling sheet'));
+                       
$GLOBALS['phpgw']->template->set_var('column_cs_select',$cssel);
+                       
$GLOBALS['phpgw']->template->set_var('lang_show_projects_on_mainscreen',lang('show
 projects on mainscreen'));
+                       
$GLOBALS['phpgw']->template->set_var('mainscreen_checked',($prefs['mainscreen_showevents']==True?'
 CHECKED':''));
+                       
$GLOBALS['phpgw']->template->set_var('worktime_statusmail_desc',lang('worktime 
statusmail'));

-                       foreach($columns as $col)
+                       for($i = 0; $i < count($mailTypeEntries); $i++)
                        {
-                               switch($col)
+                               $selected = '';
+
+                               if(is_array($prefs['mailTypeEntries']) && 
in_array($mailTypeEntries[$i]['id'], $prefs['mailTypeEntries']))
                                {
-                                       case 'number':                  $cname 
= lang('project id'); break;
-                                       case 'priority':                $cname 
= lang('priority'); break;
-                                       case 'sdateout':                        
$cname = lang('start date'); break;
-                                       case 'edateout':                        
$cname = lang('date due'); break;
-                                       case 'phours':                  $cname 
= lang('time planned'); break;
-                                       case 'budget':                  $cname 
= lang('budget'); break;
-                                       case 'e_budget':                $cname 
= lang('extra budget'); break;
-                                       case 'coordinatorout':  $cname = 
lang('coordinator'); break;
-                                       case 'customerout':             $cname 
= lang('customer'); break;
-                                       case 'investment_nr':   $cname = 
lang('investment nr'); break;
-                                       case 'previousout':             $cname 
= lang('previous'); break;
-                                       case 'customer_nr':             $cname 
= lang('customer nr'); break;
-                                       case 'url':                             
$cname = lang('url'); break;
-                                       case 'reference':               $cname 
= lang('reference'); break;
-                                       case 'accountingout':           $cname 
= lang('accounting'); break;
-                                       case 'billableout':             $cname 
= lang('billable'); break;
-                                       case 'psdateout':                       
$cname = lang('start date planned'); break;
-                                       case 'pedateout':                       
$cname = lang('date due planned'); break;
-                                       case 'discountout':             $cname 
= lang('discount'); break;
-                                       case 'mstones':                 $cname 
= lang('milestones'); break;
-                                       case 'project_accounting_factor':       
$cname = lang('accounting factor') . ' ' . lang('per hour'); break;
-                                       case 'project_accounting_factor_d':     
$cname = lang('accounting factor') . ' ' . lang('per day'); break;
+                                       $selected = 'selected="selected"';
                                }
+                               $mailTypeSelected .= '<option 
value="'.$mailTypeEntries[$i]['id'].'" '.$selected.' 
/>'.$mailTypeEntries[$i]['name'].'</option>'.'\n';
+                       }
+
+                       
$GLOBALS['phpgw']->template->set_var('mailTypeSelected',$mailTypeSelected);
+                       $GLOBALS['phpgw']->template->pfp('out','prefs');
+               }
+
+               function config_worktime_statusmail()
+               {
+                       $mail_type = get_var('mail_type',array('POST','GET'));
+                       $message = '&nbsp;';
+
+                       $this->set_app_langs();
+
+                       if (isset($_POST['save']))
+                       {
+                               $values = array('action' => 'save', 'mail_type' 
=> $mail_type);
+                               
if($this->boconfig->config_worktime_statusmail($values) == True)
+                                       $message = lang('setting has been 
saved');
+                               else
+                                       $message = lang('setting has not been 
saved');
+                       }

-                               $sel .= '<option value="' . $col . 
(in_array($col,$prefs['columns'])?'" SELECTED':'"') . '>' . "\n"
-                                               . $cname . '</option>' . "\n";
+                       if(isset($_POST['done']))
+                       {
+                               
$GLOBALS['phpgw']->redirect_link('/admin/index.php');
                        }

-                       
$GLOBALS['phpgw']->template->set_var('lang_select_columns',lang('columns to 
show in the projects list'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_show_anonymous_projects_on_mainscreen',lang('show
 anonymous public projects on mainscreen'));
-                       
$GLOBALS['phpgw']->template->set_var('column_select',$sel);
+                       $header_info = lang('config worktime statusmail');
+
+                       $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . $header_info;
+                       $GLOBALS['phpgw']->common->phpgw_header();
+                       echo parse_navbar();
+
+                       $GLOBALS['phpgw']->template->set_file(array('config' => 
'config_worktime_statusmail.tpl'));
+
+                       $link_data['menuaction'] = 
'projects.uiconfig.config_worktime_statusmail';
+                       
$GLOBALS['phpgw']->template->set_var('action_url',$GLOBALS['phpgw']->link('/index.php',$link_data));
+                       
$GLOBALS['phpgw']->template->set_var('worktime_statusmail_desc',lang('worktime 
statusmail'));
+                       
$GLOBALS['phpgw']->template->set_var('opt_off_desc',lang('off'));
+                       
$GLOBALS['phpgw']->template->set_var('opt_weekly_desc',lang('weekly'));
+                       
$GLOBALS['phpgw']->template->set_var('opt_monthly_desc',lang('monthly'));
+                       
$GLOBALS['phpgw']->template->set_var('message',$message);
+
+                       $mail_type_off = '';
+                       $mail_type_weekly = '';
+                       $mail_type_monthly = '';
+
+                       $values = array('action' => 'get');
+                       $mail_type_selected = 
$this->boconfig->config_worktime_statusmail($values);
+
+                       switch($mail_type_selected)
+                       {
+                               case 'off':     $mail_type_off     = ' 
selected'; break;
+                               case 'weekly':  $mail_type_weekly  = ' 
selected'; break;
+                               case 'monthly': $mail_type_monthly = ' 
selected'; break;
+                               default:        $mail_type_off     = ' 
selected'; break;
+                       }
+
+                       $GLOBALS['phpgw']->template->set_var('selected_off',    
 $mail_type_off);
+                       $GLOBALS['phpgw']->template->set_var('selected_weekly', 
 $mail_type_weekly);
+                       
$GLOBALS['phpgw']->template->set_var('selected_monthly', $mail_type_monthly);
+
+                       $GLOBALS['phpgw']->template->pfp('out','config');
+               }

-                       
$GLOBALS['phpgw']->template->set_var('anon_mainscreen_checked',($prefs['mainscreen_showevents']?'
 CHECKED':''));
+               function config_workhours_booking()
+               {
+                       $book_type = get_var('book_type',array('POST','GET'));
+                       $message = '&nbsp;';

-                       $GLOBALS['phpgw']->template->pfp('out','prefs');
+                       $this->set_app_langs();
+
+                       if (isset($_POST['save']))
+                       {
+                               $values = array('action' => 'save', 'book_type' 
=> $book_type);
+                               
if($this->boconfig->config_workhours_booking($values) == True)
+                                       $message = lang('setting has been 
saved');
+                               else
+                                       $message = lang('setting has not been 
saved');
+                       }
+
+                       if(isset($_POST['done']))
+                       {
+                               
$GLOBALS['phpgw']->redirect_link('/admin/index.php');
+                       }
+
+                       $header_info = lang('config workhours booking');
+
+                       $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . $header_info;
+                       $GLOBALS['phpgw']->common->phpgw_header();
+                       echo parse_navbar();
+
+                       $GLOBALS['phpgw']->template->set_file(array('config' => 
'config_workhours_booking.tpl'));
+
+                       $link_data['menuaction'] = 
'projects.uiconfig.config_workhours_booking';
+                       
$GLOBALS['phpgw']->template->set_var('action_url',$GLOBALS['phpgw']->link('/index.php',$link_data));
+                       
$GLOBALS['phpgw']->template->set_var('workhours_booking_desc',lang('booking 
workhours on the specified work day of a month'));
+                       
$GLOBALS['phpgw']->template->set_var('opt_workday_0_desc',lang('off'));
+                       
$GLOBALS['phpgw']->template->set_var('opt_workday_1_desc', 1);
+                       
$GLOBALS['phpgw']->template->set_var('opt_workday_2_desc', 2);
+                       
$GLOBALS['phpgw']->template->set_var('opt_workday_3_desc', 3);
+                       
$GLOBALS['phpgw']->template->set_var('opt_workday_4_desc', 4);
+                       
$GLOBALS['phpgw']->template->set_var('opt_workday_5_desc', 5);
+                       
$GLOBALS['phpgw']->template->set_var('message',$message);
+
+                       $book_type_0 = '';
+                       $book_type_1 = '';
+                       $book_type_2 = '';
+                       $book_type_3 = '';
+                       $book_type_4 = '';
+                       $book_type_5 = '';
+
+                       $values = array('action' => 'get');
+                       $book_type_selected = 
$this->boconfig->config_workhours_booking($values);
+
+                       switch($book_type_selected)
+                       {
+                               case 0:  $book_type_0 = ' selected'; break;
+                               case 1:  $book_type_1 = ' selected'; break;
+                               case 2:  $book_type_2 = ' selected'; break;
+                               case 3:  $book_type_3 = ' selected'; break;
+                               case 4:  $book_type_4 = ' selected'; break;
+                               case 5:  $book_type_5 = ' selected'; break;
+                               default: $book_type_0 = ' selected'; break;
+                       }
+
+                       $GLOBALS['phpgw']->template->set_var('selected_0', 
$book_type_0);
+                       $GLOBALS['phpgw']->template->set_var('selected_1', 
$book_type_1);
+                       $GLOBALS['phpgw']->template->set_var('selected_2', 
$book_type_2);
+                       $GLOBALS['phpgw']->template->set_var('selected_3', 
$book_type_3);
+                       $GLOBALS['phpgw']->template->set_var('selected_4', 
$book_type_4);
+                       $GLOBALS['phpgw']->template->set_var('selected_5', 
$book_type_5);
+                       $GLOBALS['phpgw']->template->pfp('out','config');
+               }
+
+               function config_worktime_warnmail()
+               {
+                       $warnmail_type = 
get_var('warnmail_type',array('POST','GET'));
+                       $message = '&nbsp;';
+
+                       $this->set_app_langs();
+
+                       if (isset($_POST['save']))
+                       {
+                               $values = array('action' => 'save', 
'warnmail_type' => $warnmail_type);
+                               
if($this->boconfig->config_worktime_warnmail($values) == True)
+                                       $message = lang('setting has been 
saved');
+                               else
+                                       $message = lang('setting has not been 
saved');
+                       }
+
+                       if(isset($_POST['done']))
+                       {
+                               
$GLOBALS['phpgw']->redirect_link('/admin/index.php');
+                       }
+
+                       $header_info = lang('config worktime warnmail');
+
+                       $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . $header_info;
+                       $GLOBALS['phpgw']->common->phpgw_header();
+                       echo parse_navbar();
+
+                       $GLOBALS['phpgw']->template->set_file(array('config' => 
'config_worktime_warnmail.tpl'));
+
+                       $link_data['menuaction'] = 
'projects.uiconfig.config_worktime_warnmail';
+                       
$GLOBALS['phpgw']->template->set_var('action_url',$GLOBALS['phpgw']->link('/index.php',$link_data));
+                       
//$GLOBALS['phpgw']->template->set_var('worktime_warnmail_desc',lang('Specify 
how many work days before monthly allowance you would like to send a warning'));
+                       
$GLOBALS['phpgw']->template->set_var('worktime_warnmail_desc',lang('Send a 
warning mail at the end of a month if not enough worktime was captured.'));
+                       
$GLOBALS['phpgw']->template->set_var('message',$message);
+
+                       $values = array('action' => 'get');
+                       $warnmail_type_selected = 
$this->boconfig->config_worktime_warnmail($values);
+
+                       // create option list for selectbox
+                       // first option for disable warnmail
+                       if($warnmail_type_selected == -1)
+                       {
+                               $option_list = '<option value="-1" 
selected>'.lang('off').'</option>';
+                       }
+                       else
+                       {
+                               $option_list = '<option 
value="-1">'.lang('off').'</option>';
+                       }
+
+                       /*
+                       // build other elements of option list
+                       //  0 = last work day of month (day of monthly 
allowance)
+                       //  1 = one work day before monthly allowance
+                       //  2 = two work days before monthly allowance
+                       // ...
+                       for($i=0; $i<=7; ++$i)
+                       {
+                               if($warnmail_type_selected == $i)
+                                       $selected = ' selected';
+                               else
+                                       $selected = '';
+
+                               $option_list .= "<option 
value=\"".$i."\"".$selected.">".$i."</option>\n";
+                       }
+                       */
+                       if($warnmail_type_selected == 1)
+                               $selected = ' selected';
+                       else
+                               $selected = '';
+                       $option_list .= "<option 
value=\"1\"".$selected.">".lang('active')."</option>\n";
+
+                       $selectbox = "<select 
name=\"warnmail_type\">\n".$option_list."</select>";
+                       
$GLOBALS['phpgw']->template->set_var('warnmail_type_selectbox', $selectbox);
+
+                       $GLOBALS['phpgw']->template->pfp('out','config');
                }
+
+
        }
 ?>

====================================================
Index: projects/inc/class.uiprojects.inc.php
diff -u projects/inc/class.uiprojects.inc.php:1.152 
projects/inc/class.uiprojects.inc.php:1.153
--- projects/inc/class.uiprojects.inc.php:1.152 Wed Aug 11 15:05:13 2004
+++ projects/inc/class.uiprojects.inc.php       Mon Mar 14 17:39:39 2005
@@ -36,30 +36,36 @@
                var $order;
                var $cat_id;
                var $status;
+               var $ui_base;

                var $public_functions = array
                (
-                       'list_projects'                 => True,
-                       'list_projects_home'    => True,
-                       'edit_project'                  => True,
-                       'delete_project'                => True,
-                       'view_project'                  => True,
-                       'abook'                                 => True,
-                       'accounts_popup'                => True,
-                       'e_accounts_popup'              => True,
-                       'list_budget'                   => True,
-                       'project_mstones'               => True,
-                       'assign_employee_roles' => True
+                       'list_projects'                         => True,
+                       'list_projects_home'            => True,
+                       'edit_project'                          => True,
+                       'delete_project'                        => True,
+                       'view_project'                          => True,
+                       //'abook'                                               
=> True,
+                       //'accounts_popup'                      => True,
+                       //'e_accounts_popup'                    => True,
+                       'list_budget'                           => True,
+                       'project_mstones'                       => True,
+                       'assign_employee_roles'         => True,
+                       'report'                                        => True,
+                       'export_cost_accounting'        => True,
+                       'view_employee_activity'        => True,
+                       'tree_view_projects'            => True
                );

                function uiprojects()
                {
                        $action = get_var('action',array('GET'));

-                       $this->boprojects                               = 
CreateObject('projects.boprojects',True, $action);
+                       $this->ui_base                                  = 
CreateObject('projects.uiprojects_base');
+                       $this->boprojects                               = 
$this->ui_base->boprojects;
                        $this->nextmatchs                               = 
CreateObject('phpgwapi.nextmatchs');
-                       //$this->sbox                                   = 
CreateObject('phpgwapi.sbox');
-                       $this->attached_files                   = 
CreateObject('projects.attached_files');
+
+                       //$this->attached_files                 = 
CreateObject('projects.attached_files');

                        $this->start                                    = 
$this->boprojects->start;
                        $this->query                                    = 
$this->boprojects->query;
@@ -85,200 +91,6 @@
                        $this->boprojects->save_sessiondata($data, $action);
                }

-               function set_app_langs()
-               {
-                       
$GLOBALS['phpgw']->template->set_var('th_bg',$GLOBALS['phpgw_info']['theme']['th_bg']);
-                       
$GLOBALS['phpgw']->template->set_var('row_on',$GLOBALS['phpgw_info']['theme']['row_on']);
-                       
$GLOBALS['phpgw']->template->set_var('row_off',$GLOBALS['phpgw_info']['theme']['row_off']);
-
-                       
$GLOBALS['phpgw']->template->set_var('lang_category',lang('Category'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_select',lang('Select'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_select_category',lang('Select 
category'));
-
-                       
$GLOBALS['phpgw']->template->set_var('lang_descr',lang('Description'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_title',lang('Title'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_none',lang('None'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_number',lang('Project ID'));
-
-                       
$GLOBALS['phpgw']->template->set_var('lang_start_date',lang('Start Date'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_date_due',lang('Date due'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_cdate',lang('Date created'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_last_update',lang('last update'));
-
-                       
$GLOBALS['phpgw']->template->set_var('lang_start_date_planned',lang('start date 
planned'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_date_due_planned',lang('date due 
planned'));
-
-                       
$GLOBALS['phpgw']->template->set_var('lang_access',lang('access'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_projects',lang('Projects'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_project',lang('Project'));
-
-                       
$GLOBALS['phpgw']->template->set_var('lang_ttracker',lang('time tracker'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_statistics',lang('Statistics'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_roles',lang('roles'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_role',lang('role'));
-
-                       
$GLOBALS['phpgw']->template->set_var('lang_jobs',lang('Jobs'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_act_number',lang('Activity ID'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_title',lang('Title'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_status',lang('Status'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_budget',lang('Budget'));
-
-                       
$GLOBALS['phpgw']->template->set_var('lang_investment_nr',lang('investment 
nr'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_customer',lang('Customer'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_coordinator',lang('Coordinator'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_employees',lang('Employees'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_creator',lang('creator'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_processor',lang('processor'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_previous',lang('previous project'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_bookable_activities',lang('Bookable 
activities'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_billable_activities',lang('Billable 
activities'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_edit',lang('edit'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_view',lang('View'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_hours',lang('Work hours'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_remarkreq',lang('Remark required'));
-
-                       
$GLOBALS['phpgw']->template->set_var('lang_customer_nr',lang('customer nr'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_url',lang('project url'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_reference',lang('external 
reference'));
-
-                       
$GLOBALS['phpgw']->template->set_var('lang_stats',lang('Statistics'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_ptime',lang('time planned'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_utime',lang('time used'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_month',lang('month'));
-
-                       
$GLOBALS['phpgw']->template->set_var('lang_done',lang('done'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_save',lang('save'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_apply',lang('apply'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_cancel',lang('cancel'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_search',lang('search'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_delete',lang('delete'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_back',lang('back'));
-
-                       
$GLOBALS['phpgw']->template->set_var('lang_parent',lang('Parent project'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_main',lang('Main project'));
-
-                       
$GLOBALS['phpgw']->template->set_var('lang_add_milestone',lang('add 
milestone'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_milestones',lang('milestones'));
-
-                       
$GLOBALS['phpgw']->template->set_var('lang_result',lang('result'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_test',lang('test'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_quality',lang('quality check'));
-
-                       
$GLOBALS['phpgw']->template->set_var('lang_accounting',lang('accounting 
system'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_factor_project',lang('factor 
project'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_factor_employee',lang('factor 
employee'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_accounting_factor_for_project',lang('accounting
 factor for project'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_select_factor',lang('select 
factor'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_non_billable',lang('not billable'));
-
-                       
$GLOBALS['phpgw']->template->set_var('lang_pbudget',lang('budget planned'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_ubudget',lang('budget used'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_plus_jobs',lang('+ jobs'));
-
-                       
$GLOBALS['phpgw']->template->set_var('lang_per_hour',lang('per hour'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_per_day',lang('per day'));
-
-                       
$GLOBALS['phpgw']->template->set_var('lang_percent',lang('percent'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_amount',lang('amount'));
-
-                       
$GLOBALS['phpgw']->template->set_var('lang_events',lang('events'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_priority',lang('priority'));
-
-                       
$GLOBALS['phpgw']->template->set_var('lang_available',lang('available'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_used_billable',lang('used 
billable'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_planned',lang('planned'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_used_total',lang('used total'));
-
-                       
$GLOBALS['phpgw']->template->set_var('lang_invoicing_method',lang('invoicing 
method'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_discount',lang('discount'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_extra_budget',lang('extra budget'));
-
-                       
$GLOBALS['phpgw']->template->set_var('lang_billable',lang('billable'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_files',lang('files'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_attach',lang('attach file'));
-               }
-
-               function display_app_header()
-               {
-                       if 
($GLOBALS['phpgw_info']['user']['preferences']['common']['template_set'] != 
'idots')
-                       {
-                               
$GLOBALS['phpgw']->template->set_file(array('header' => 'header.tpl'));
-                               
$GLOBALS['phpgw']->template->set_block('header','projects_header');
-                               
$GLOBALS['phpgw']->template->set_block('header','projects_admin_header');
-
-                               if ($this->boprojects->isprojectadmin('pad') || 
$this->boprojects->isprojectadmin('pmanager'))
-                               {
-                                       
switch($this->boprojects->siteconfig['accounting'])
-                                       {
-                                               case 'activity':
-                                                       
$GLOBALS['phpgw']->template->set_var('link_accounting',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiconfig.list_activities&action=act'));
-                                                       
$GLOBALS['phpgw']->template->set_var('lang_accounting',lang('Activities'));
-                                                       break;
-                                               default:
-                                                       
$GLOBALS['phpgw']->template->set_var('link_accounting',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiconfig.list_employees&action=accounting'));
-                                                       
$GLOBALS['phpgw']->template->set_var('lang_accounting',lang('Accounting'));
-                                       }
-                                       
$GLOBALS['phpgw']->template->set_var('link_budget',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojects.list_budget&action=mains'));
-                                       
$GLOBALS['phpgw']->template->fp('admin_header','projects_admin_header');
-                               }
-
-                               
$GLOBALS['phpgw']->template->set_var('link_jobs',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojects.list_projects&action=subs'));
-                               
$GLOBALS['phpgw']->template->set_var('link_hours',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojecthours.list_projects&action=mains'));
-                               
$GLOBALS['phpgw']->template->set_var('link_ttracker',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojecthours.ttracker'));
-                               
$GLOBALS['phpgw']->template->set_var('link_statistics',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uistatistics.list_projects&action=mains'));
-                               
$GLOBALS['phpgw']->template->set_var('link_projects',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojects.list_projects&action=mains'));
-
-                               
$GLOBALS['phpgw']->template->fp('app_header','projects_header');
-                       }
-                       $GLOBALS['phpgw']->common->phpgw_header();
-                       echo parse_navbar();
-                       $this->set_app_langs();
-               }
-
-               function admin_header_info()
-               {
-                       if ($this->boprojects->isprojectadmin('pad'))
-                       {
-                               $pa = True;
-                       }
-
-                       if ($this->boprojects->isprojectadmin('pmanager'))
-                       {
-                               $pm = True;
-                       }
-
-                       if ($this->boprojects->isprojectadmin('psale'))
-                       {
-                               $ps = True;
-                       }
-                       return ($pa?'&nbsp;&gt;&nbsp;' . 
lang('administrator'):'') . ($pm?'&nbsp;&gt;&nbsp;' . lang('manager'):'')
-                                       . ($ps?'&nbsp;&gt;&nbsp;' . 
lang('salesman'):'');
-               }
-
-               function status_format($status = '', $showarchive = True)
-               {
-                       if (!$status)
-                       {
-                               $status = $this->status = 'active';
-                       }
-
-                       switch ($status)
-                       {
-                               case 'active':          $stat_sel[0]=' 
selected'; break;
-                               case 'nonactive':       $stat_sel[1]=' 
selected'; break;
-                               case 'archive':         $stat_sel[2]=' 
selected'; break;
-                       }
-
-                       $status_list = '<option value="active"' . $stat_sel[0] 
. '>' . lang('Active') . '</option>' . "\n"
-                                               . '<option value="nonactive"' . 
$stat_sel[1] . '>' . lang('Nonactive') . '</option>' . "\n";
-
-                       if ($showarchive)
-                       {
-                               $status_list .= '<option value="archive"' . 
$stat_sel[2] . '>' . lang('Archive') . '</option>' . "\n";
-                       }
-                       return $status_list;
-               }
-
                function priority_list($selected = 0)
                {
                        for($i=1;$i<=10;$i++)
@@ -290,13 +102,10 @@

                function list_projects()
                {
-
                        $action         = get_var('action',array('POST','GET'));
                        $pro_main       = 
get_var('pro_main',array('POST','GET'));
-
-                       //echo 'START: ' . $this->start;
-
-                       if ($_GET['cat_id'])
+
+                       if (isset($_GET['cat_id']))
                        {
                                $this->cat_id = $_GET['cat_id'];
                        }
@@ -306,10 +115,10 @@
                                $action = 'mains';
                        }

-                       $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . ($pro_main?lang('list jobs'):lang('list projects'))
-                                                                               
                                        . $this->admin_header_info();
+                       //$GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . lang('list projects')
+                       //                                                      
                                        . $this->admin_header_info();

-                       $this->display_app_header();
+                       $this->ui_base->display_app_header();

                        
$GLOBALS['phpgw']->template->set_file(array('projects_list_t' => 'list.tpl'));
                        
$GLOBALS['phpgw']->template->set_block('projects_list_t','projects_list','list');
@@ -321,7 +130,8 @@
                        (
                                'menuaction'    => 
'projects.uiprojects.list_projects',
                                'pro_main'              => $pro_main,
-                               'action'                => $action
+                               'action'                => $action,
+                               'status'                => 
$this->boprojects->status
                        );

                        if($pro_main)
@@ -333,9 +143,12 @@
                                
$GLOBALS['phpgw']->template->set_var('coordinator_main',$main['coordinatorout']);
                                
$GLOBALS['phpgw']->template->set_var('number_main',$main['number']);
                                
$GLOBALS['phpgw']->template->set_var('customer_main',$main['customerout']);
+                               
$GLOBALS['phpgw']->template->set_var('customer_org_name',$main['customerorgout']);
                                
$GLOBALS['phpgw']->template->set_var('url_main',$main['url']);
                                
$GLOBALS['phpgw']->template->set_var('attachment',$this->attached_files->get_files($pro_main));
                                
$GLOBALS['phpgw']->template->set_var('lang_files',lang('Files'));
+                               $link = 
$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojects.report&project_id='
 . $pro_main . '&generated=True');
+                               
$GLOBALS['phpgw']->template->set_var('report','<a href="' . $link . '"><img 
src="projects/templates/' . $GLOBALS['phpgw_info']['server']['template_set'] . 
'/images/document.png" title="' . lang('generate activity report') . '">' . 
lang('generate activity report') . '</a>');
                                
$GLOBALS['phpgw']->template->parse('main','project_main',True);
                        }

@@ -367,7 +180,7 @@
                        
$GLOBALS['phpgw']->template->set_var('action_url',$GLOBALS['phpgw']->link('/index.php',$link_data));
                        
$GLOBALS['phpgw']->template->set_var('filter_list',$this->nextmatchs->new_filter($this->filter));
                        
$GLOBALS['phpgw']->template->set_var('search_list',$this->nextmatchs->search(array('query'
 => $this->query)));
-                       
$GLOBALS['phpgw']->template->set_var('status_list',$this->status_format($this->status));
+                       
$GLOBALS['phpgw']->template->set_var('status_list',$this->ui_base->status_format($this->status));

 // ---------------- list header variable template-declarations 
--------------------------

@@ -391,8 +204,8 @@
                                        case 'phours':                  $cname 
= lang('time planned'); $db = 'ptime';  $col_align= 'right';break;
                                        case 'budget':                  $cname 
= $prefs['currency'] . ' ' . lang('budget'); $col_align= 'right'; break;
                                        case 'e_budget':                $cname 
= $prefs['currency'] . ' ' . lang('extra budget'); $col_align= 'right'; break;
-                                       case 'coordinatorout':  $cname = 
($action=='mains'?lang('coordinator'):lang('job manager')); $db = 
'coordinator'; break;
-                                       case 'customerout':             $cname 
= lang('customer'); break; $db = 'customer'; break;
+                                       case 'coordinatorout':  $cname = 
lang('coordinator'); $db = 'coordinator'; break;
+                                       case 'customerout':             $cname 
= lang('customer'); $db = 'customer'; break;
                                        case 'investment_nr':   $cname = 
lang('investment nr'); break;
                                        case 'previousout':             $cname 
= lang('previous'); $db = 'previous'; break;
                                        case 'customer_nr':             $cname 
= lang('customer nr'); break;
@@ -409,8 +222,14 @@
                                        case 'discountout':             $cname 
= lang('discount'); $db = 'discount'; $col_align= 'right'; break;
                                }

-                               ($col=='mstones'?$sort_column = 
lang('milestones'):
-                               $sort_column = 
$this->nextmatchs->show_sort_order($this->sort,($db?$db:$col),$this->order,'/index.php',$cname?$cname:lang($col),$link_data));
+                               if ($col=='mstones')
+                               {
+                                       $sort_column = lang('milestones');
+                               }
+                               else
+                               {
+                                       $sort_column = 
$this->nextmatchs->show_sort_order($this->sort,($db?$db:$col),$this->order,'/index.php',$cname?$cname:lang($col),$link_data);
+                               }
                                
$GLOBALS['phpgw']->template->set_var('col_align',$col_align?$col_align:'left');
                                
$GLOBALS['phpgw']->template->set_var('sort_column',$sort_column);
                                
$GLOBALS['phpgw']->template->fp('sort_cols','pro_sort_cols',True);
@@ -421,23 +240,25 @@
                        if(is_array($pro))
                        {
                                foreach($pro as $p)
-               {
+                               {
                                        
$this->nextmatchs->template_alternate_row_color(&$GLOBALS['phpgw']->template);

 // --------------- template declaration for list records 
-------------------------------------

+                                       $link_data['menuaction'] = 
'projects.uiprojects.tree_view_projects';
                                        $link_data['project_id'] = 
$p['project_id'];
-                                       if ($action == 'mains')
+
+                                       //if ($action == 'mains')
                                        {
-                                               $projects_url = 
$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojects.list_projects&pro_main='
-                                                                       . 
$p['project_id'] . '&action=subs');
+
+                                               $projects_url = 
$GLOBALS['phpgw']->link('/index.php', $link_data);
                                        }
-                                       else
+                                       /*else
                                        {
                                                $projects_url = 
$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojecthours.list_hours&project_id='
                                                                        . 
$p['project_id'] . '&action=hours&pro_main=' . $pro_main);
                                        }
-
+                                       */
                                        
$GLOBALS['phpgw']->template->set_var(array
                                        (
                                                'title'                 => 
$p['title']?$p['title']:lang('browse'),
@@ -491,7 +312,7 @@
                                        {
                                                
$GLOBALS['phpgw']->template->set_var('add_job_url',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojects.edit_project&action=subs&pro_parent='
                                                                                
                                                        . $p['project_id'] . 
'&pro_main=' . ($pro_main?$pro_main:$p['project_id'])));
-                                               
$GLOBALS['phpgw']->template->set_var('add_job_img','<img src="' . 
$GLOBALS['phpgw']->common->image('phpgwapi','new') . '" title="' . lang('add 
job')
+                                               
$GLOBALS['phpgw']->template->set_var('add_job_img','<img src="' . 
$GLOBALS['phpgw']->common->image('phpgwapi','new') . '" title="' . lang('add 
sub project')
                                                                                
                                                                . '" 
border="0">');
                                        }
                                        
$GLOBALS['phpgw']->template->fp('list','projects_list',True);
@@ -499,25 +320,292 @@
                        }
 // ------------------------- end record declaration ------------------------

-// --------------- template declaration for Add Form --------------------------
+// --------------- Button interactions --------------------------
+                       $valid_interactions = 
$this->boprojects->get_interactions(array('pro_main'    => $pro_main,
+                                                                               
        'project_id'  => $p['project_id'],
+                                                                               
        'status'      => $this->status,
+                                                                               
        'action'      => $action,
+                                                                               
        'coordinator' => $main['coordinator']
+                                                                               
       ));
+                       if(in_array('book_hours', $valid_interactions))
+                       {
+                               $link_data['menuaction'] = 
'projects.uiprojecthours.edit_hours';
+                               $link_data['action'] = 'hours';
+                               $link_data['project_id'] = $pro_main;
+                               
$GLOBALS['phpgw']->template->set_var('addhours','<form method="POST" action="' 
. $GLOBALS['phpgw']->link('/index.php',$link_data)
+                                                                               
        . '"><input type="submit" name="addhours" value="' . lang('Add work 
hours to the main project') .'"></form>');
+
+                               $link_data['menuaction'] = 
'projects.uiprojecthours.list_hours';
+                               $link_data['action'] = 'hours';
+                               $link_data['project_id'] = $pro_main;
+                               
$GLOBALS['phpgw']->template->set_var('viewhours','<form method="POST" action="' 
. $GLOBALS['phpgw']->link('/index.php',$link_data)
+                                                                               
        . '"><input type="submit" name="viewhours" value="' . lang('View work 
hours of the main project') .'"></form>');
+                       }
+
+                       unset($link_data['project_id']); // not a good idea
+                       if(in_array('add_project', $valid_interactions))
+                       {
+                               $link_data['menuaction'] = 
'projects.uiprojects.edit_project';
+                               if($action == 'subs')
+                               {
+                                       $link_data['action']     = 'subs';
+                                       $link_data['pro_parent'] = $pro_main;
+                                       $link_data['pro_main']   = $pro_main;
+                                       $add_desc = lang('add sub project');
+                               }
+                               else
+                               {
+                                       $add_desc = lang('Add project');
+                               }

-                       $link_data['menuaction'] = 
'projects.uiprojects.edit_project';
-                       unset($link_data['project_id']);
+                               
$GLOBALS['phpgw']->template->set_var('add','<form method="POST" action="' . 
$GLOBALS['phpgw']->link('/index.php',$link_data)
+                                                                               
        . '"><input type="submit" name="Add" value="' . $add_desc .'"></form>');
+                       }

-                       if($action=='subs' && !$pro_main)
+                       if($pro_main && ((in_array('view_employee_activity', 
$valid_interactions)) || $this->boprojects->isprojectadmin('pad') || 
$this->boprojects->isprojectadmin('pmanager')))
                        {
-                               $GLOBALS['phpgw']->template->set_var('add','');
+                               $link_data['menuaction'] = 
'projects.uiprojects.view_employee_activity';
+                               $link_data['project_id'] = $pro_main;
+                               
$GLOBALS['phpgw']->template->set_var('viewemployeeactivity','<form 
method="POST" action="' . $GLOBALS['phpgw']->link('/index.php',$link_data)
+                                                                               
        . '"><input type="submit" name="addhours" value="' . lang('View project 
activities') .'"></form>');
                        }
-                       else if ($this->boprojects->add_perms(array('action' => 
$action,'main_co' => $main['coordinator'])))
+
+// ---------------------------------------------------
+
+                       $this->save_sessiondata($action);
+                       
$GLOBALS['phpgw']->template->pfp('out','projects_list_t',True);
+               }
+
+               function tree_view_projects()
+               {
+                       $project_id     = get_var('project_id', 
array('POST','GET'));
+                       $pro_main         = get_var('pro_main',   
array('POST','GET'));
+                       $pro_parent     = get_var('pro_parent', 
array('POST','GET'));
+                       $action     = get_var('action',     
array('POST','GET'));
+
+                       $this->ui_base->display_app_header();
+                       if($project_id && !$pro_parent)
                        {
-                               
$GLOBALS['phpgw']->template->set_var('add','<form method="POST" action="' . 
$GLOBALS['phpgw']->link('/index.php',$link_data)
-                                                                               
        . '"><input type="submit" name="Add" value="' . lang('Add') 
.'"></form>');
+                               $pro_parent = $this->ui_base->pro_parent;
+                       }
+                       if($project_id && !$pro_main)
+                       {
+                               $pro_main = $this->ui_base->pro_main;
                        }
+
+                       if(!$action)
+                       {
+                               if($pro_parent > 0)
+                               {
+                                       $action = 'subs';
+                               }
+                               else
+                               {
+                                       $action = 'mains';
+                               }
+                       }
+
+                       
$GLOBALS['phpgw']->template->set_file(array('projects_list_t' => 
'list_tree.tpl'));
+                       
$GLOBALS['phpgw']->template->set_block('projects_list_t','projects_list','list');
+                       
$GLOBALS['phpgw']->template->set_block('projects_list_t','pro_sort_cols','sort_cols');
+                       
$GLOBALS['phpgw']->template->set_block('projects_list_t','pro_cols','cols');
+                       
$GLOBALS['phpgw']->template->set_block('projects_list_t','project_main','main');
+
+                       $link_data = array
+                       (
+                               'status'      => $this->boprojects->status,
+                               'menuaction'    => 
'projects.uiprojects.tree_view_projects',
+                               'project_id'    => $project_id
+                       );
+/*
+                       if($pro_main)
+                       {
+                               $main = 
$this->boprojects->read_single_project($pro_main);
+                               
$GLOBALS['phpgw']->template->set_var('title_main',$main['title']);
+                               
$GLOBALS['phpgw']->template->set_var('main_url',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojects.view_project&action=mains&project_id='
+                                                                               
                                                                                
                . $pro_main));
+                               
$GLOBALS['phpgw']->template->set_var('coordinator_main',$main['coordinatorout']);
+                               
$GLOBALS['phpgw']->template->set_var('number_main',$main['number']);
+                               
$GLOBALS['phpgw']->template->set_var('customer_main',$main['customerout']);
+                               
$GLOBALS['phpgw']->template->set_var('customer_org_name',$main['customerorgout']);
+                               
$GLOBALS['phpgw']->template->set_var('url_main',$main['url']);
+                               
$GLOBALS['phpgw']->template->set_var('attachment',$this->attached_files->get_files($pro_main));
+                               
$GLOBALS['phpgw']->template->set_var('lang_files',lang('Files'));
+                               $link = 
$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojects.report&project_id='
 . $pro_main . '&generated=1');
+                               
$GLOBALS['phpgw']->template->set_var('report','<a href="' . $link . '"><img 
src="projects/templates/' . $GLOBALS['phpgw_info']['server']['template_set'] . 
'/images/document.png" title="' . lang('generate activity report') . '">' . 
lang('generate activity report') . '</a>');
+                               
$GLOBALS['phpgw']->template->parse('main','project_main',True);
+                       }
+*/
+                       $pro = $this->boprojects->list_projects(array('action' 
=> 'mainsubsorted','project_id' => $project_id));
+
+
+// --------------------- nextmatch variable template-declarations 
------------------------
+
+                       $left = 
$this->nextmatchs->left('/index.php',$this->start,$this->boprojects->total_records,$link_data);
+                       $right = 
$this->nextmatchs->right('/index.php',$this->start,$this->boprojects->total_records,$link_data);
+                       $GLOBALS['phpgw']->template->set_var('left',$left);
+                       $GLOBALS['phpgw']->template->set_var('right',$right);
+
+                       
$GLOBALS['phpgw']->template->set_var('lang_showing',$this->nextmatchs->show_hits($this->boprojects->total_records,$this->start));
+
+// ------------------------- end nextmatch template 
--------------------------------------
+
+                       $action_list= '<select name="cat_id" 
onChange="this.form.submit();"><option value="none">' . lang('Select category') 
. '</option>' . "\n"
+                                               . 
$this->boprojects->cats->formatted_list('select','all',$this->cat_id,True) . 
'</select>';
+
+                       
$GLOBALS['phpgw']->template->set_var('action_list',$action_list);
+                       
$GLOBALS['phpgw']->template->set_var('action_url',$GLOBALS['phpgw']->link('/index.php',$link_data));
+                       
$GLOBALS['phpgw']->template->set_var('filter_list',$this->nextmatchs->new_filter($this->filter));
+                       
$GLOBALS['phpgw']->template->set_var('search_list',$this->nextmatchs->search(array('query'
 => $this->query)));
+                       
$GLOBALS['phpgw']->template->set_var('status_list',$this->ui_base->status_format($this->status));
+
+// ---------------- list header variable template-declarations 
--------------------------
+
+                       $nopref = $this->boprojects->check_prefs();
+                       if (is_array($nopref))
+                       {
+                               
$GLOBALS['phpgw']->template->set_var('message',$GLOBALS['phpgw']->common->error_list($nopref));
+                       }
+                       $prefs = $this->boprojects->read_prefs();
+
+                       
$GLOBALS['phpgw']->template->set_var('sort_title',$this->nextmatchs->show_sort_order($this->sort,'title',$this->order,'/index.php',lang('title'),$link_data));
+                       foreach($prefs['columns'] as $col)
+                       {
+                               $col_align = '';
+                               switch($col)
+                               {
+                                       case 'number':                  $cname 
= lang('project id'); $db = 'p_number'; break;
+                                       case 'priority':                $cname 
= lang('priority');  $col_align= 'right';break;
+                                       case 'sdateout':                $cname 
= lang('start date'); $db = 'start_date'; $col_align= 'center'; break;
+                                       case 'edateout':                $cname 
= lang('date due'); $db = 'end_date'; $col_align= 'center'; break;
+                                       case 'phours':                  $cname 
= lang('time planned'); $db = 'ptime';  $col_align= 'right';break;
+                                       case 'budget':                  $cname 
= $prefs['currency'] . ' ' . lang('budget'); $col_align= 'right'; break;
+                                       case 'e_budget':                $cname 
= $prefs['currency'] . ' ' . lang('extra budget'); $col_align= 'right'; break;
+                                       case 'coordinatorout':  $cname = 
lang('coordinator'); $db = 'coordinator'; break;
+                                       case 'customerout':             $cname 
= lang('customer'); break; $db = 'customer'; break;
+                                       case 'investment_nr':   $cname = 
lang('investment nr'); break;
+                                       case 'previousout':             $cname 
= lang('previous'); $db = 'previous'; break;
+                                       case 'customer_nr':             $cname 
= lang('customer nr'); break;
+                                       case 'url':                             
$cname = lang('url'); break;
+                                       case 'reference':               $cname 
= lang('reference'); break;
+                                       case 'accountingout':   $cname = 
lang('accounting'); $db = 'accounting'; break;
+                                       case 'project_accounting_factor':       
        $cname = $prefs['currency'] . ' ' . lang('project') . ' ' . 
lang('accounting factor') . ' '
+                                                                               
                                        . lang('per hour'); $db = 'acc_factor'; 
$col_align = 'right'; break;
+                                       case 'project_accounting_factor_d':     
        $cname = $prefs['currency'] . ' ' . lang('project') . ' ' . 
lang('accounting factor') . ' '
+                                                                               
                                        . lang('per day'); $db = 
'acc_factor_d'; $col_align = 'right'; break;
+                                       case 'billableout':             $cname 
= lang('billable'); $db = 'billable'; $col_align= 'center';break;
+                                       case 'psdateout':               $cname 
= lang('start date planned'); $db = 'psdate'; $col_align= 'center'; break;
+                                       case 'pedateout':               $cname 
= lang('date due planned'); $db = 'pedate'; $col_align= 'center'; break;
+                                       case 'discountout':             $cname 
= lang('discount'); $db = 'discount'; $col_align= 'right'; break;
+                               }
+
+                               if ($col=='mstones')
+                               {
+                                       $sort_column = lang('milestones');
+                               }
+                               else
+                               {
+                                       $sort_column = 
$this->nextmatchs->show_sort_order($this->sort,($db?$db:$col),$this->order,'/index.php',$cname?$cname:lang($col),$link_data);
+                               }
+                               
$GLOBALS['phpgw']->template->set_var('col_align',$col_align?$col_align:'left');
+                               
$GLOBALS['phpgw']->template->set_var('sort_column',$sort_column);
+                               
$GLOBALS['phpgw']->template->fp('sort_cols','pro_sort_cols',True);
+                       }
+
+// -------------- end header declaration 
---------------------------------------
+
+                       if(is_array($pro))
+                       {
+                               foreach($pro as $p)
+                               {
+                                       
$this->nextmatchs->template_alternate_row_color(&$GLOBALS['phpgw']->template);
+
+// --------------- template declaration for list records 
-------------------------------------
+
+                                       $link_data['project_id'] = 
$p['project_id'];
+                                       $link_data['action']     = 
$p['parent']>0?'subs':'mains';
+
+                                       $projects_url = 
$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojecthours.list_hours&project_id='
+                                                                       . 
$p['project_id'] . '&action=hours&pro_main=' . $p['main']);
+
+                                       
$GLOBALS['phpgw']->template->set_var(array
+                                       (
+                                               'title'                 => 
$p['title']?$p['title']:lang('browse'),
+                                               'projects_url'  => $projects_url
+                                       ));
+
+                                       
$GLOBALS['phpgw']->template->set_var('pro_column','');
+                                       foreach($prefs['columns'] as $col)
+                                       {
+                                               switch($col)
+                                               {
+                                                       case 'priority':
+                                                       case 'discountout':
+                                                       case 'e_budget':
+                                                       case 'budget':
+                                                       case 
'project_accounting_factor':
+                                                       case 
'project_accounting_factor_d':
+                                                       case 'phours': 
$col_align = 'right'; break;
+                                                       case 'sdateout':
+                                                       case 'edateout':
+                                                       case 'psdateout':
+                                                       case 'pedateout':
+                                                       case 'billableout': 
$col_align = 'center'; break;
+                                                       default:                
        $col_align = 'left';
+                                               }
+
+                                               
$GLOBALS['phpgw']->template->set_var('col_align',$col_align);
+                                               
$GLOBALS['phpgw']->template->set_var('column',$p[$col]);
+                                               
$GLOBALS['phpgw']->template->fp('pro_column','pro_cols',True);
+                                       }
+                                       
//$GLOBALS['phpgw']->template->set_var('pro_column',$pdata);
+
+
+                                       if($p['parent'] == 0)
+                                       {
+                                               $action='mains';
+                                       }
+                                       else
+                                       {
+                                               $action='subs';
+                                               $pro_main = $p['main'];
+                                       }
+
+                                       $edit = '';
+                                       if 
(!$this->boprojects->edit_perms(array('action' => $action,'coordinator' => 
$p['coordinator'],
+                                                                               
                                'main' => $p['main'], 'parent' => 
$p['parent'])))
+                                       {
+                                               $edit = 'no';
+                                       }
+
+                                       $link_data['action']     = $action;
+                                       $link_data['pro_main']   = $p['main'];
+                                       $link_data['pro_parent'] = $p['parent'];
+
+                                       $link_data['menuaction'] = 
'projects.uiprojects.view_project';
+                                       
$GLOBALS['phpgw']->template->set_var('view_url',$GLOBALS['phpgw']->link('/index.php',$link_data));
+                                       
$GLOBALS['phpgw']->template->set_var('view_img',$GLOBALS['phpgw']->common->image('phpgwapi','view'));

-// ----------------------- end Add form declaration 
----------------------------
+                                       $link_data['menuaction'] = 
'projects.uiprojects.edit_project';
+                                       
$GLOBALS['phpgw']->template->set_var('edit_url',($edit=='no'?'':$GLOBALS['phpgw']->link('/index.php',$link_data)));
+                                       
$GLOBALS['phpgw']->template->set_var('edit_img',($edit=='no'?'':'<img src="' . 
$GLOBALS['phpgw']->common->image('phpgwapi','edit') . '" title="' . lang('edit')
+                                                                               
                                                                                
. '" border="0">'));
+
+                                       if 
($this->boprojects->add_perms(array('action' => $action,'coordinator' => 
$p['coordinator'],
+                                                                               
                                'main_co' => $main['coordinator'],'parent' => 
$p['parent'])))
+                                       {
+                                               
$GLOBALS['phpgw']->template->set_var('add_job_url',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojects.edit_project&action=subs&pro_parent='
+                                                                               
                                                        . $p['project_id'] . 
'&pro_main=' . ($pro_main?$pro_main:$p['project_id'])));
+                                               
$GLOBALS['phpgw']->template->set_var('add_job_img','<img src="' . 
$GLOBALS['phpgw']->common->image('phpgwapi','new') . '" title="' . lang('add 
sub project')
+                                                                               
                                                                . '" 
border="0">');
+                                       }
+                                       
$GLOBALS['phpgw']->template->fp('list','projects_list',True);
+                               }
+                       }
+// ------------------------- end record declaration ------------------------

                        $this->save_sessiondata($action);
-                       
$GLOBALS['phpgw']->template->pfp('out','projects_list_t',True);
+                       
$GLOBALS['phpgw']->template->pfp('out','projects_list_t',True);
                }

                function list_projects_home()
@@ -530,18 +618,7 @@
                                $this->cat_id = $_GET['cat_id'];
                        }

-                       $menuaction     = get_var('menuaction',Array('GET'));
-                       if ($menuaction)
-                       {
-                               $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . ($pro_main?lang('list jobs'):lang('list projects'))
-                                                                               
                                                . $this->admin_header_info();
-                               $GLOBALS['phpgw']->common->phpgw_header();
-                               echo parse_navbar();
-                       }
-                       else
-                       {
-                               $this->boprojects->cats->app_name = 'projects';
-                       }
+                       $this->boprojects->cats->app_name = 'projects';

                        $this->t = 
CreateObject('phpgwapi.Template',$GLOBALS['phpgw']->common->get_tpl_dir('projects'));
                        $this->t->set_file(array('projects_list_t' => 
'home_list.tpl'));
@@ -549,12 +626,16 @@

                        
$this->t->set_var('th_bg',$GLOBALS['phpgw_info']['theme']['th_bg']);

-
                        if (!$action)
                        {
                                $action = 'mains';
                        }

+                       $sdate                          = 
get_var('sdate',array('GET','POST'));
+                       $edate                          = 
get_var('edate',array('GET','POST'));
+                       $psdate                         = 
get_var('psdate',array('GET','POST'));
+                       $pedate                         = 
get_var('pedate',array('GET','POST'));
+
                        $link_data = array
                        (
                                'menuaction'    => 
'projects.uiprojects.list_projects_home',
@@ -563,7 +644,7 @@
                        );

                        $this->status = 'active';
-                       $this->boprojects->filter = 'anonym';
+                       //$this->boprojects->filter = 'anonym';
                        $pro = $this->boprojects->list_projects(array('action' 
=> $action,'parent' => $pro_main));

 // --------------------- nextmatch variable template-declarations 
------------------------
@@ -581,7 +662,7 @@
                        {
                                $action_list= '<select name="cat_id" 
onChange="this.form.submit();"><option value="none">' . lang('Select category') 
. '</option>' . "\n"
                                                        . 
$this->boprojects->cats->formatted_list('select','all',$this->cat_id,True) . 
'</select>';
-                               $this->t->set_var('lang_action',lang('Jobs'));
+                               $this->t->set_var('lang_action',lang('sub 
projects'));
                        }
                        else
                        {
@@ -601,22 +682,18 @@
                        $this->t->set_var('lang_milestones',lang('milestones'));
                        
$this->t->set_var('sort_title',$this->nextmatchs->show_sort_order($this->sort,'title',$this->order,'/index.php',lang('Title'),$link_data));
                        
$this->t->set_var('sort_end_date',$this->nextmatchs->show_sort_order($this->sort,'end_date',$this->order,'/index.php',lang('Date
 due'),$link_data));
-                       
$this->t->set_var('sort_coordinator',$this->nextmatchs->show_sort_order($this->sort,'coordinator',$this->order,'/index.php',($pro_main?lang('job
 manager'):lang('Coordinator')),$link_data));
-
-                       if($action == 'subs')
-                       {
-                               $this->t->set_var('add_job_row','<td>' . 
lang('add job') . '</td>');
-                       }
+                       
$this->t->set_var('sort_coordinator',$this->nextmatchs->show_sort_order($this->sort,'coordinator',$this->order,'/index.php',lang('Coordinator'),$link_data));

 // -------------- end header declaration 
---------------------------------------

-            for ($i=0;$i<count($pro);$i++)
-            {
+                       for ($i=0;$i<count($pro);$i++)
+                       {
                                
$this->nextmatchs->template_alternate_row_color(&$this->t);

                                if ($action == 'mains')
                                {
-                                       $td_action = 
($pro[$i]['customerout']?$pro[$i]['customerout']:'&nbsp;');
+                                       $td_action  = 
($pro[$i]['customerorgout']?$pro[$i]['customerorgout'].'&nbsp;':'');
+                                       $td_action .= 
($pro[$i]['customerout']?$pro[$i]['customerout']:'&nbsp;');
                                }
                                else
                                {
@@ -652,110 +729,99 @@
                                        'coordinator'   => 
$pro[$i]['coordinatorout']
                                ));
                                $link_data['project_id'] = 
$pro[$i]['project_id'];
-                               $link_data['public_view'] = True;
                                $link_data['menuaction'] = 
'projects.uiprojects.view_project';
                                
$this->t->set_var('view',$GLOBALS['phpgw']->link('/index.php',$link_data));
                                
$this->t->set_var('lang_view_entry',lang('View'));
-                               $this->t->fp('list','projects_list',True);
+                               $body .= 
$this->t->fp('list','projects_list',True);
                        }

 // ------------------------- end record declaration ------------------------

                        $this->save_sessiondata($action);

-                       $menuaction     = get_var('menuaction',Array('GET'));
-                       if ($menuaction)
-                       {
-                               list($app,$class,$method) = 
explode('.',$menuaction);
-                               $var['app_tpl'] = $method;
-                               $this->t->pfp('out','projects_list_t',True);
-                       }
-                       else
-                       {
-                               return 
$this->t->fp('out','projects_list_t',True);
-                       }
+                       $body .= $this->t->fp('out','projects_list_t',True);
+                       return $body;
                }

-               function employee_format($data)
+               function edit_project()
                {
-                       $type                           = 
($data['type']?$data['type']:'selectbox');
-                       $selected                       = 
$data['selected']?$data['selected']:$this->boprojects->get_acl_for_project($data['project_id']);
-                       $project_only           = 
$data['project_only']?$data['project_only']:False;
-                       $admins_included        = 
$data['admins_included']?$data['admins_included']:False;
-
-                       if($project_only)
+                       if(!is_object($GLOBALS['phpgw']->js))
                        {
-                               $data['pro_parent']     = $data['project_id'];
-                               $data['action']         = 'subs';
+                               $GLOBALS['phpgw']->js = 
createObject('phpgwapi.javascript');
                        }
+                       $GLOBALS['phpgw']->js->validate_file('api', 'tabs');
+
+                       $jscal = CreateObject('phpgwapi.jscalendar');
+
+                       $action          = 
get_var('action',array('GET','POST'));
+                       $pro_main        = 
get_var('pro_main',array('GET','POST'));
+                       $pro_parent      = 
get_var('pro_parent',array('GET','POST'));
+                       $book_activities = 
get_var('book_activities',array('POST'));
+                       $bill_activities = 
get_var('bill_activities',array('POST'));
+                       $project_id      = 
get_var('project_id',array('GET','POST'));
+                       $name            = get_var('name',array('POST'));
+                       $values          = get_var('values',array('POST'));
+                       $sdate           = get_var('sdate',array('GET','POST'));
+                       $edate           = get_var('edate',array('GET','POST'));
+                       $psdate          = 
get_var('psdate',array('GET','POST'));
+                       $pedate          = 
get_var('pedate',array('GET','POST'));
+                       $budgetradio     = 
get_var('budgetradio',array('GET','POST'));

-                       if (!is_array($selected))
+                       if($pro_parent>0)
                        {
-                               $selected = explode(',',$selected);
+                               $action = 'subs';
                        }
-
-                       switch($type)
+                       else
                        {
-                               case 'selectbox':
-                                       $employees = 
$this->boprojects->selected_employees(array('action' => 
$data['action'],'pro_parent' => $data['pro_parent'],
-                                                                               
                                                                        
'admins_included' => $admins_included));
-                                       break;
-                               case 'popup':
-                                       $employees      = 
$this->boprojects->selected_employees(array('project_id' => 
$data['project_id']));
-                                       break;
+                               $action = 'mains';
                        }

-                       //_debug_array($employees);
-                       //_debug_array($selected);
-                       while (is_array($employees) && list($null,$account) = 
each($employees))
+                       if(!$action && $project_id>0)
                        {
-                               $s .= '<option value="' . 
$account['account_id'] . '"';
-                               if (in_array($account['account_id'],$selected))
+                               $parent = 
$this->boprojects->return_value('parent', $project_id);
+                               if($parent > 0)
+                               {
+                                       $action = 'subs';
+                               }
+                               else
                                {
-                                       $s .= ' SELECTED';
+                                       $action = 'mains';
                                }
-                               $s .= '>';
-                               $s .= $account['account_fullname'] . 
'</option>' . "\n";
                        }
-                       return $s;
-               }
-
-               function accounts_popup()
-               {
-                       $GLOBALS['phpgw']->accounts->accounts_popup('projects');
-               }
-
-               function e_accounts_popup()
-               {
-                       
$GLOBALS['phpgw']->accounts->accounts_popup('e_projects');
-               }
-
-               function edit_project()
-               {
-                       $action                         = 
get_var('action',array('GET','POST'));
-                       $pro_main                       = 
get_var('pro_main',array('GET','POST'));
-                       $pro_parent                     = 
get_var('pro_parent',array('GET','POST'));
-                       $book_activities        = 
get_var('book_activities',array('POST'));
-                       $bill_activities        = 
get_var('bill_activities',array('POST'));
-
-                       $project_id                     = 
get_var('project_id',array('GET','POST'));
-                       $name                           = 
get_var('name',array('POST'));
-                       $values                         = 
get_var('values',array('POST'));
-
-                       $sdate                          = 
get_var('sdate',array('GET','POST'));
-                       $edate                          = 
get_var('edate',array('GET','POST'));
-                       $psdate                         = 
get_var('psdate',array('GET','POST'));
-                       $pedate                         = 
get_var('pedate',array('GET','POST'));

                        $link_data = array
                        (
-                               'menuaction'    => 
'projects.uiprojects.list_projects',
+                               'menuaction'    => 
'projects.uiprojects.tree_view_projects',
                                'pro_main'              => $pro_main,
-                               'action'                => $action,
+                               'action'      => $action,
                                'project_id'    => $project_id,
                                'pro_parent'    => $pro_parent
                        );

+                       if(is_array($sdate))
+                       {
+                               $start_array    = 
$jscal->input2date($sdate['str']);
+                               $start_val              = $start_array['raw'];
+                       }
+
+                       if(is_array($edate))
+                       {
+                               $end_array = $jscal->input2date($edate['str']);
+                               $end_val   = $end_array['raw'];
+                       }
+
+                       if(is_array($psdate))
+                       {
+                               $pstart_array   = 
$jscal->input2date($psdate['str']);
+                               $pstart_val             = $pstart_array['raw'];
+                       }
+
+                       if(is_array($pedate))
+                       {
+                               $pend_array     = 
$jscal->input2date($pedate['str']);
+                               $pend_val       = $pend_array['raw'];
+                       }
+
                        //_debug_array($sdate);

                        $jscal = CreateObject('phpgwapi.jscalendar');
@@ -785,20 +851,53 @@

                        if ($_POST['save'] || $_POST['apply'])
                        {
-                               $this->cat_id = 
($values['cat']?$values['cat']:'');
-                               $values['coordinator']  = $_POST['accountid'];
-                               $values['employees']    = $_POST['employees'];
-
-                               $values['project_id']   = $project_id;
-                               $values['customer']             = 
$_POST['abid'];
+                               $this->cat_id = ($values['cat'] ? 
$values['cat'] : '');

+                               $values['coordinator']  = $_POST['accountid'];
+                               $values['employees']    = 
array_merge($_POST['employees'], array($_POST['accountid']));
+                               $values['project_id']   = $project_id;
+                               $values['customer']     = $_POST['abid'];
+                               $values['customer_org'] = 
$_POST['customer_org'];
                                $values['book_activities'] = $book_activities;
                                $values['bill_activities'] = $bill_activities;
-
-                               $values['sdate'] = $start_val;
-                               $values['edate'] = $end_val;
+                               $values['sdate']  = $start_val;
+                               $values['edate']  = $end_val;
                                $values['psdate'] = $pstart_val;
                                $values['pedate'] = $pend_val;
+
+                               switch($budgetradio)
+                               {
+                                       case 'm': $values['budgetradio'] = 'm'; 
break;
+                                       case 'h': $values['budgetradio'] = 'h'; 
break;
+                                       default : $values['budgetradio'] = 'm'; 
break;
+                               }
+
+                               if($values['radio_acc_factor'] == 'day')
+                               {
+                                       $values['project_accounting_factor'] = 
$values['project_accounting_factor'] / $this->boprojects->siteconfig['hwday'];
+                               }
+
+                               if ($values['accounting'] == 'project')
+                               {
+                                       $values['ptime']  = 
intval($values['ptime']);
+                                       $values['budget'] = 
round($values['budget'], 2);
+                                       if($values['project_accounting_factor'] 
> 0)
+                                       {
+                                               if($values['budgetradio'] == 
'm')
+                                               {
+                                                               
$values['ptime'] = intval($values['budget'] / 
$values['project_accounting_factor']);
+                                               }
+                                               elseif($values['budgetradio'] 
== 'h')
+                                               {
+                                                       $values['budget'] = 
$values['ptime'] * $values['project_accounting_factor'];
+                                               }
+                                               else
+                                               {
+                                                       $values['ptime'] = 0;
+                                                       $values['budget'] = 0.0;
+                                               }
+                                       }
+                               }

                                $error = 
$this->boprojects->check_values($action, $values);
                                if (is_array($error))
@@ -807,8 +906,8 @@
                                }
                                else
                                {
-                                       $project_id = 
$this->boprojects->save_project($action, $values);
-                                       
$this->attached_files->save_file($project_id);
+                                       $project_id = 
$this->boprojects->save_project($action, $values);
+                                       
//$this->attached_files->save_file($project_id);
                                        $link_data['project_id'] = $project_id;
                                        if($_POST['save'])
                                        {
@@ -819,11 +918,17 @@
                                        {
                                                $message = lang('project %1 has 
been saved',$values['title']);
                                        }
+                                       $values = 
$this->boprojects->read_single_project($project_id);
                                }
                        }

                        if($_POST['cancel'])
                        {
+                               if(!$project_id)
+                               {
+                                       $link_data['project_id'] = $pro_parent;
+                               }
+
                                
$GLOBALS['phpgw']->redirect_link('/index.php',$link_data);
                        }

@@ -842,7 +947,7 @@

                        if($_POST['roles'])
                        {
-                               $link_data['menuaction']        = 
'projects.uiprojects.assign_employee_roles';
+                               $link_data['menuaction'] = 
'projects.uiprojects.assign_employee_roles';
                                
$GLOBALS['phpgw']->redirect_link('/index.php',$link_data);
                        }

@@ -858,19 +963,13 @@
                                        
$GLOBALS['phpgw']->redirect_link('/index.php',$link_data);
                                }
                        }
-                               //_debug_array($values);

-                       if ($action == 'mains')
-                       {
-                               $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . ($project_id?lang('edit project'):lang('add project'))
-                                                                               
                                        . $this->admin_header_info();
-                       }
-                       else
-                       {
-                               $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . ($project_id?lang('edit job'):lang('add job'))
+/*
+                       $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . ($project_id?lang('edit project'):lang('add project'))
                                                                                
                                        . $this->admin_header_info();
-                       }
                        $this->display_app_header();
+*/
+                       $this->ui_base->display_app_header();

                        $GLOBALS['phpgw']->template->set_file(array('edit_form' 
=> 'form.tpl'));
                        
$GLOBALS['phpgw']->template->set_block('edit_form','main','mainhandle');
@@ -885,21 +984,29 @@
                        
$GLOBALS['phpgw']->template->set_block('edit_form','accounting_own','accounting_ownhandle');

                        $nopref = $this->boprojects->check_prefs();
-                       if (is_array($nopref))
+                       if (is_array($nopref) && !$_POST['save'] && 
!$_POST['apply'])
                        {
                                $message .= 
$GLOBALS['phpgw']->common->error_list($nopref);
                        }
-
+
                        
$GLOBALS['phpgw']->template->set_var('message',$message);
                        $prefs = $this->boprojects->read_prefs();

-                       
$GLOBALS['phpgw']->template->set_var('addressbook_link',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojects.abook'));
-                       
$GLOBALS['phpgw']->template->set_var('accounts_link',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojects.accounts_popup'));
-                       
$GLOBALS['phpgw']->template->set_var('e_accounts_link',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojects.e_accounts_popup'));
-
-                       
$GLOBALS['phpgw']->template->set_var('lang_open_popup',lang('open popup 
window'));
-                       $link_data['menuaction'] = 
'projects.uiprojects.edit_project';
-                       
$GLOBALS['phpgw']->template->set_var('action_url',$GLOBALS['phpgw']->link('/index.php',$link_data));
+                       
$GLOBALS['phpgw']->template->set_var('addressbook_link',$GLOBALS['phpgw']->link('/index.php',
 array('menuaction' => 'phpgwapi.pbaddbook_projects.show',
+                                                                               
                                            'hidecc' => 1,
+                                                                               
                                            'hidebcc' => 1,
+                                                                               
                                            'targettagto' => 'customer'
+                                                                               
                                           )));
+                       
$GLOBALS['phpgw']->template->set_var('accounts_link',$GLOBALS['phpgw']->link('/index.php',
 array('menuaction' => 'phpgwapi.pbaddbookaccount_projects.show',
+                                                                               
                                         'hidecc' => 1,
+                                                                               
                                         'hidebcc' => 1,
+                                                                               
                                         'targettagto' => 'cordinator'
+                                                                               
                                         )));
+                       
$GLOBALS['phpgw']->template->set_var('e_accounts_link',$GLOBALS['phpgw']->link('/index.php',
 array('menuaction' => 'phpgwapi.pbaddbookaccounts.show',
+                                                                               
                                           'hidecc' => 1,
+                                                                               
                                           'hidebcc' => 1,
+                                                                               
                                           'targettagto' => 'staff'
+                                                                               
                                          )));

                        if($pro_main)
                        {
@@ -916,48 +1023,106 @@
                                $parent = 
$this->boprojects->read_single_project($pro_parent,'planned');
                        }

+                       if(!isset($values['plan_bottom_up']))
+                       {
+                               $values['plan_bottom_up'] = 'N';
+                       }
+
                        if ($project_id)
                        {
+                               $values = 
$this->boprojects->read_single_project($project_id);
+
+                               if(($_POST['save'] || $_POST['apply']) && 
$error)
+                               {
+                                       $values['coordinator']                = 
$_POST['accountid'];
+                                       $values['employees']                  = 
$_POST['employees'];
+                                       $values['customer']                   = 
$_POST['abid'];
+                                       $values['customer_org']               = 
$_POST['customer_org'];
+                                       $values['book_activities']            = 
$book_activities;
+                                       $values['bill_activities']            = 
$bill_activities;
+                                       $values['number']                     = 
$_POST['values']['number'];
+                                       $values['investment_nr']              = 
$_POST['values']['investment_nr'];
+                                       $values['title']                      = 
$_POST['values']['title'];
+                                       $values['descr']                      = 
$_POST['values']['descr'];
+                                       $values['previous']                   = 
$_POST['values']['previous'];
+                                       $values['cat']                        = 
$_POST['values']['cat'];
+                                       $values['status']                     = 
$_POST['values']['status'];
+                                       $values['priority']                   = 
$_POST['values']['priority'];
+                                       $values['url']                        = 
$_POST['values']['url'];
+                                       $values['access']                     = 
$_POST['values']['access'];
+                                       $values['reference']                  = 
$_POST['values']['reference'];
+                                       $values['customer_nr']                = 
$_POST['values']['customer_nr'];
+                                       $values['ptime']                      = 
intval($_POST['values']['ptime']);
+                                       $values['plan_bottom_up']             = 
$_POST['values']['plan_bottom_up'];
+                                       $values['e_budget']                   = 
$_POST['values']['e_budget'];
+                                       $values['project_accounting_factor']  = 
$_POST['values']['project_accounting_factor'];
+                                       $values['direct_work']                = 
$_POST['values']['direct_work'];
+                                       if($_POST['values']['billable'])
+                                       {
+                                               $values['billable'] = 'N';
+                                       }
+                                       $values['inv_method']                 = 
$_POST['values']['inv_method'];
+                                       $values['discount_type']              = 
$_POST['values']['discount_type'];
+                                       $values['discount']                   = 
$_POST['values']['discount'];
+                                       $values['result']                     = 
$_POST['values']['result'];
+                                       $values['test']                       = 
$_POST['values']['test'];
+                                       $values['quality']                    = 
$_POST['values']['quality'];
+                                       $values['attachment']                 = 
$_POST['values']['attachment'];
+                               }
+
                                
$GLOBALS['phpgw']->template->set_var('old_status',$values['status']);
-                               
$GLOBALS['phpgw']->template->set_var('old_parent',$values['parent']);
+                               
//$GLOBALS['phpgw']->template->set_var('old_parent',$values['parent']);
+                               
$GLOBALS['phpgw']->template->set_var('old_parent',$pro_parent);
                                
$GLOBALS['phpgw']->template->set_var('old_edate',$values['edate']);
                                
$GLOBALS['phpgw']->template->set_var('old_coordinator',$values['coordinator']);
                                
$GLOBALS['phpgw']->template->set_var('lang_choose','');
                                
$GLOBALS['phpgw']->template->set_var('choose','');
+                               
$GLOBALS['phpgw']->template->set_var('help_img','');
                                $this->cat_id = $values['cat'];

-                               $start  = 
$start_val?$start_val:$values['sdate'];
-                               $end    = $end_val?$end_val:$values['edate'];
-                               $pstart = 
$pstart_val?$pstart_val:$values['psdate'];
-                               $pend   = $pend_val?$pend_val:$values['pedate'];
+                               $start  = 
$start_val?$start_val:($values['sdate']?$values['sdate']:'');
+                               $end    = 
$end_val?$end_val:($values['edate']?$values['edate']:'');
+                               $pstart = 
$pstart_val?$pstart_val:($values['psdate']?$values['psdate']:'');
+                               $pend   = 
$pend_val?$pend_val:($values['psdate']?$values['pedate']:'');

+                               
$GLOBALS['phpgw']->template->set_var('lang_milestones',lang('milestones').':');
                                
$GLOBALS['phpgw']->template->set_var('edit_mstones_button','<input 
type="submit" name="mstone" value="' . lang('edit milestones') . '">');
                                
$GLOBALS['phpgw']->template->set_var('edit_roles_events_button','<input 
type="submit" name="roles" value="' . lang('edit roles and events') . '">');
                        }
                        else
                        {
-                               
$GLOBALS['phpgw']->template->set_var('choose','<input type="checkbox" 
name="values[choose]" value="True"' . (isset($values['choose'])?' checked':'') 
. '>');
+                               if($this->boprojects->siteconfig['projectnr'] 
== 'generate')
+                               {
+                                       
$GLOBALS['phpgw']->template->set_var('choose','<input type="checkbox" 
name="values[choose]" value="True"' . (isset($values['choose'])?' checked':'') 
. '>');
+                                       
$GLOBALS['phpgw']->template->set_var('lang_choose',lang('generate project id'));
+                               }
+                               else
+                               {
+                                       
$GLOBALS['phpgw']->template->set_var('help_img','<a href="#"><img src="' . 
$GLOBALS['phpgw']->common->image('projects','help') . '" onclick="open_popup(\''
+                                                                               
                        . 
$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojects_base.proid_help_popup')
 . '\');" title="'
+                                                                               
                        . lang('help project nr') . '" alt="Project-Nr." 
/></a>');
+                               }

                                switch($action)
                                {
                                        case 'mains':
-                                               $start  = 
$start_val?$start_val:mktime(12,0,0,date('m'),date('d'),date('Y'));
+                                               $start  = 
$start_val?$start_val:''; //mktime(12,0,0,date('m'),date('d'),date('Y'));
                                                $end    = $end_val?$end_val:'';
-                                               $pstart = 
$pstart_val?$pstart_val:'';
+                                               $pstart = 
$pstart_val?$pstart_val:''; //mktime(12,0,0,date('m'),date('d'),date('Y'));
                                                $pend   = 
$pend_val?$pend_val:'';

                                                $values['access']       = 
isset($values['access'])?$values['access']:'public';
+                                               $values['direct_work']  = 
isset($values['direct_work'])?$values['direct_work']:'Y';
                                                break;
                                        case 'subs':
-
-                                               //_debug_array($parent);
-
                                                if(is_array($parent))
                                                {
-                                                       $start  = 
$start_val?$start_val:($parent['sdate']?mktime(12,0,0,date('m',$parent['sdate']),date('d',$parent['sdate']),date('Y',$parent['sdate'])):mktime(12,0,0,date('m'),date('d'),date('Y')));
+                                                       $start  = 
$start_val?$start_val:($parent['sdate']?mktime(12,0,0,date('m',$parent['sdate']),date('d',$parent['sdate']),date('Y',$parent['sdate'])):'');
 //mktime(12,0,0,date('m'),date('d'),date('Y')));
                                                        $end    = 
$end_val?$end_val:($parent['edate']?mktime(12,0,0,date('m',$parent['edate']),date('d',$parent['edate']),date('Y',$parent['edate'])):'');
                                                        $pstart = 
$pstart_val?$pstart_val:($parent['psdate']?mktime(12,0,0,date('m',$parent['psdate']),date('d',$parent['psdate']),date('Y',$parent['psdate'])):'');
                                                        $pend   = 
$pend_val?$pend_val:($parent['pedate']?mktime(12,0,0,date('m',$parent['pedate']),date('d',$parent['pedate']),date('Y',$parent['pedate'])):'');
+                                                       
$values['plan_bottom_up']       = 
$parent['plan_bottom_up']?$parent['plan_bottom_up']:'N';
+                                                       $values['direct_work'] 
= $parent['direct_work']?$parent['direct_work']:'Y';
                                                }
                                                break;
                                }
@@ -975,76 +1140,108 @@
                                                .       
$this->boprojects->cats->formatted_list('select','all',$this->cat_id,True) . 
'</select>';

                                
$GLOBALS['phpgw']->template->set_var('cat',$cat);
-                               
$GLOBALS['phpgw']->template->set_var('lang_number',lang('Project ID'));
-                               
$GLOBALS['phpgw']->template->set_var('lang_choose',($project_id?'':lang('generate
 project id')));

                                
//$GLOBALS['phpgw']->template->set_var('pcosts','<input type="text" 
name="values[pcosts]" value="' . $values['pcosts'] . '"> [' . 
$prefs['currency'] . $prefs['currency'] . '.cc]');
+
+                               // use input field as checkbox
+                               
$GLOBALS['phpgw']->template->set_var('plan_bottom_up_input_type', 'checkbox');
+                               
$GLOBALS['phpgw']->template->set_var('plan_bottom_up_input_value', 'Y');
+                               
$GLOBALS['phpgw']->template->set_var('plan_bottom_up_input_checked', 
(($values['plan_bottom_up'] == 'Y') ? ' checked' : ''));
+                               
$GLOBALS['phpgw']->template->set_var('plan_bottom_up_text', '');
+
+                               // use input field as checkbox
+                               
$GLOBALS['phpgw']->template->set_var('direct_work_input_type', 'checkbox');
+                               
$GLOBALS['phpgw']->template->set_var('direct_work_input_value', 'Y');
+                               
$GLOBALS['phpgw']->template->set_var('direct_work_input_checked', 
(($values['direct_work'] == 'Y') ? ' checked' : ''));
+                               
$GLOBALS['phpgw']->template->set_var('direct_work_text', '');
+
+                               
$GLOBALS['phpgw']->template->set_var('lang_parent', lang('Main project'));
+                               
$GLOBALS['phpgw']->template->set_var('parent_select', '');
                        }
                        elseif($action == 'subs')
                        {
+/*
                                
$GLOBALS['phpgw']->template->set_var('pro_main',$main['title'] . ' [' . 
$main['number'] . ']');
                                
$GLOBALS['phpgw']->template->set_var('main_url',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojects.view_project&action=mains&project_id='
                                                                                
                                                                                
                . $pro_main));
                                
$GLOBALS['phpgw']->template->set_var('lang_sum_jobs',lang('sum jobs'));
                                
$GLOBALS['phpgw']->template->set_var('lang_available',lang('available'));

-                               
$GLOBALS['phpgw']->template->set_var('ptime_main',$main['ptime']);
-                               
$GLOBALS['phpgw']->template->set_var('ptime_jobs',sprintf("%01.2f",$main['ptime_jobs']));
-                               
$GLOBALS['phpgw']->template->set_var('atime',sprintf("%01.2f",$main['atime']));
+                               
$GLOBALS['phpgw']->template->set_var('ptime_main',intval($main['ptime']).':00');
+                               
$GLOBALS['phpgw']->template->set_var('ptime_jobs',intval($main['ptime_jobs']).':00');
+                               
$GLOBALS['phpgw']->template->set_var('atime',intval($main['atime']).':00');
                                
$GLOBALS['phpgw']->template->set_var('lang_budget_main',lang('budget main 
project') . ':&nbsp;' . $prefs['currency']);
                                
$GLOBALS['phpgw']->template->set_var('budget_main',$main['budget']);
                                
$GLOBALS['phpgw']->template->set_var('pbudget_jobs',sprintf("%01.2f",$main['pbudget_jobs']));
                                
$GLOBALS['phpgw']->template->set_var('apbudget',sprintf("%01.2f",$main['ap_budget_jobs']));

                                
$GLOBALS['phpgw']->template->fp('mainhandle','main',True);
-
+*/
                                $values['coordinator']          = 
isset($values['coordinator'])?$values['coordinator']:$parent['coordinator'];
                                $values['coordinatorout']       = 
isset($values['coordinatorout'])?$values['coordinatorout']:$parent['coordinatorout'];
-                               $values['parent']                       = 
isset($values['parent'])?$values['parent']:$parent['project_id'];
-                               $values['customer']                     = 
isset($values['customer'])?$values['customer']:$parent['customer'];
-                               $values['number']                       = 
isset($values['number'])?$values['number']:$parent['number'];
+                               $values['parent']                               
        = isset($values['parent'])?$values['parent']:$parent['project_id'];
+                               $values['customer']                             
= isset($values['customer'])?$values['customer']:$parent['customer'];
+                               $values['customer_org']         = 
isset($values['customer_org'])?$values['customer_org']:$parent['customer_org'];
+                               $values['number']                               
        = isset($values['number'])?$values['number']:$parent['number'];
                                $values['investment_nr']        = 
isset($values['investment_nr'])?$values['investment_nr']:$parent['investment_nr'];
                                $values['customer_nr']          = 
isset($values['customer_nr'])?$values['customer_nr']:$parent['customer_nr'];
-                               $values['url']                          = 
isset($values['url'])?$values['url']:$parent['url'];
-                               $values['reference']            = 
isset($values['reference'])?$values['reference']:$parent['reference'];
-
-                               $values['budget']                       = 
isset($values['budget'])?$values['budget']:sprintf("%01.2f",$parent['ap_budget_jobs']);
-                               $values['ptime']                        = 
isset($values['ptime'])?$values['ptime']:sprintf("%01.2f",$parent['atime']);
-
-                               $values['e_budget']                     = 
isset($values['e_budget'])?$values['e_budget']:$parent['e_budget'];
-                               $values['access']                       = 
isset($values['access'])?$values['access']:$parent['access'];
-                               $values['priority']                     = 
isset($values['priority'])?$values['priority']:$parent['priority'];
-                               $values['accounting']                           
        = 
isset($values['accounting'])?$values['accounting']:$parent['accounting'];
-                               $values['project_accounting_factor']    = 
isset($values['project_accounting_factor'])?$values['project_accounting_factor']:$parent['project_accounting_factor'];
-                               $values['project_accounting_factor_d']  = 
isset($values['project_accounting_factor_d'])?$values['project_accounting_factor_d']:$parent['project_accounting_factor_d'];
-                               $values['billable']                             
                = 
isset($values['billable'])?$values['billable']:$parent['billable'];
-                               $values['inv_method']                           
        = 
isset($values['inv_method'])?$values['inv_method']:$parent['inv_method'];
-
-                               
$GLOBALS['phpgw']->template->set_var('parent_select','<select 
name="values[parent]">' . $this->boprojects->select_project_list(array('action' 
=> 'mainandsubs',
-                                                                               
                                                                                
                                                                                
                                                'status' => $values['status'],
-                                                                               
                                                                                
                                                                                
                                                'self' => $project_id,
-                                                                               
                                                                                
                                                                                
                                                'selected' => $values['parent'],
-                                                                               
                                                                                
                                                                                
                                                'main' => $pro_main)) . 
'</select>');
+                               $values['url']                                  
        = isset($values['url'])?$values['url']:$parent['url'];
+                               $values['reference']                    = 
isset($values['reference'])?$values['reference']:$parent['reference'];
+                               $values['budget']                               
        = isset($values['budget'])?$values['budget']:$parent['ap_budget_jobs'];
+                               $values['ptime']                                
        = 
isset($values['ptime'])?intval($values['ptime']):intval($parent['atime']);
+                               $values['e_budget']                             
= isset($values['e_budget'])?$values['e_budget']:$parent['e_budget'];
+                               $values['access']                               
        = isset($values['access'])?$values['access']:$parent['access'];
+                               $values['priority']                             
= isset($values['priority'])?$values['priority']:$parent['priority'];
+                               $values['accounting']                  = 
isset($values['accounting'])?$values['accounting']:$parent['accounting'];
+                               $values['project_accounting_factor']   = 
isset($values['project_accounting_factor'])?$values['project_accounting_factor']:$parent['project_accounting_factor'];
+                               $values['billable']                             
= isset($values['billable'])?$values['billable']:$parent['billable'];
+                               $values['inv_method']                   = 
isset($values['inv_method'])?$values['inv_method']:$parent['inv_method'];
+
+                               /* disable because we couldnt update parent 
values
+                               
$GLOBALS['phpgw']->template->set_var('parent_select','<select 
name="values[parent]">' . $this->boprojects->select_project_list(array('action' 
  => 'mainandsubs',
+                                                                               
                                                                                
                                                                                
                                                        'status'        => 
$values['status'],
+                                                                               
                                                                                
                                                                                
                                                        'self'          => 
$project_id,
+                                                                               
                                                                                
                                                                                
                                                        'selected'      => 
$values['parent'],
+                                                                               
                                                                                
                                                                                
                                                        'main'          => 
$pro_main)) . '</select>');
+                               */
+                               
$GLOBALS['phpgw']->template->set_var('parent_select', $parent['title'].'<input 
type="hidden" name="values[parent]" value="'.intval($values['parent']).'">');

-                               
$GLOBALS['phpgw']->template->set_var('lang_choose',($project_id?'':lang('generate
 job id')));
                                
$GLOBALS['phpgw']->template->set_var('cat',$this->boprojects->cats->id2name($main['cat']));
                                $this->cat_id = $main['cat'];

-                               
$GLOBALS['phpgw']->template->set_var('lang_action',lang('Edit job'));
-                               
$GLOBALS['phpgw']->template->set_var('lang_number',lang('Job ID'));
+                               // use input field as hidden field and show 
only a text info
+                               
$GLOBALS['phpgw']->template->set_var('plan_bottom_up_input_type', 'hidden');
+                               
$GLOBALS['phpgw']->template->set_var('plan_bottom_up_input_value', 
(($values['plan_bottom_up'] == 'Y') ? 'Y' : 'N'));
+                               
$GLOBALS['phpgw']->template->set_var('plan_bottom_up_input_checked', '');
+                               
$GLOBALS['phpgw']->template->set_var('plan_bottom_up_text', 
(($values['plan_bottom_up'] == 'Y') ? lang('Yes') : lang('No')));
+
+                               // use input field as hidden field and show 
only a text info
+                               
$GLOBALS['phpgw']->template->set_var('direct_work_input_type', 'hidden');
+                               
$GLOBALS['phpgw']->template->set_var('direct_work_input_value', 
(($values['direct_work'] == 'Y') ? 'Y' : 'N'));
+                               
$GLOBALS['phpgw']->template->set_var('direct_work_input_checked', '');
+                               
$GLOBALS['phpgw']->template->set_var('direct_work_text', 
(($values['direct_work'] == 'Y') ? lang('Yes') : lang('No')));
                        }
-
+
+                       
$GLOBALS['phpgw']->template->set_var('lang_open_popup',lang('open popup 
window'));
+                       $link_data['menuaction'] = 
'projects.uiprojects.edit_project';
+                       
$GLOBALS['phpgw']->template->set_var('action_url',$GLOBALS['phpgw']->link('/index.php',$link_data));
+
+                       $GLOBALS['phpgw']->template->set_var('budget_type', 
($values['ptime'] > 0 && 0 == $values['budget']) ? 'h' : 'm');
+                       
$GLOBALS['phpgw']->template->set_var('lang_budget_type', lang('budget type'));
                        
$GLOBALS['phpgw']->template->set_var('currency',$prefs['currency']);
-
                        $month = $this->boprojects->return_date();
                        
$GLOBALS['phpgw']->template->set_var('month',$month['monthformatted']);

-                       
$GLOBALS['phpgw']->template->set_var('status_list',$this->status_format($values['status'],(($action
 == 'mains')?True:False)));
+                       
$GLOBALS['phpgw']->template->set_var('status_list',$this->ui_base->status_format($values['status'],(($action
 == 'mains')?True:False)));
                        
$GLOBALS['phpgw']->template->set_var('priority_list',$this->priority_list($values['priority']));

-                       $aradio = '<input type="radio" name="values[access]" 
value="private"' . ($values['access'] == 'private'?' checked':'') . '>' . 
lang('private');
-                       $aradio .= '<input type="radio" name="values[access]" 
value="public"' . ($values['access'] == 'public'?' checked':'') . '>' . 
lang('public') . '<br>';
-                       $aradio .= '<input type="radio" name="values[access]" 
value="anonym"' . ($values['access'] == 'anonym'?' checked':'') . '>' . 
lang('anonymous public');
+                       $acces_private = '<option value="private"' . 
($values['access'] == 'private'?' selected="selected"':'') . '>' . 
lang('private') . '</option>';
+                       $acces_public = '<option value="public"' . 
($values['access'] == 'public'?' selected="selected"':'') . '>' . 
lang('public') . '</option>';
+                       $acces_anonym = '<option value="anonym"' . 
($values['access'] == 'anonym'?' selected="selected"':'') . '>' . 
lang('anonymous public') . '</option>';
+
+                       
$GLOBALS['phpgw']->template->set_var('acces_private',$acces_private);
+                       
$GLOBALS['phpgw']->template->set_var('acces_public',$acces_public);
+                       
$GLOBALS['phpgw']->template->set_var('acces_anonym',$acces_anonym);

                        $GLOBALS['phpgw']->template->set_var('access',$aradio);

@@ -1052,16 +1249,16 @@
                                                                                
                                                                                
                                                'status' => $values['status'],
                                                                                
                                                                                
                                                'self' => $project_id,
                                                                                
                                                                                
                                        'selected' => $values['previous'])));
+
+                       
$GLOBALS['phpgw']->template->set_var('help_image',$GLOBALS['phpgw']->common->image('projects','help.png'));
+                       
$GLOBALS['phpgw']->template->set_var('help_project_nr','http://' . 
$_SERVER['HTTP_HOST'] . $GLOBALS['phpgw_info']['server']['webserver_url'] . 
'/projects/templates/default/projects_nr_help.html');

                        if($this->boprojects->siteconfig['accounting'] == 'own')
                        {
-                               
$GLOBALS['phpgw']->template->set_var('acc_employee_selected',($values['accounting']=='employee'?'
 SELECTED':''));
-                               
$GLOBALS['phpgw']->template->set_var('acc_project_selected',($values['accounting']=='project'?'
 SELECTED':''));
-                               
$GLOBALS['phpgw']->template->set_var('project_accounting_factor',$values['project_accounting_factor']);
-                               
$GLOBALS['phpgw']->template->set_var('project_accounting_factor_d',$values['project_accounting_factor_d']);
+                               
$GLOBALS['phpgw']->template->set_var('acc_employee_selected',($values['accounting']=='employee'?'
 selected="selected"':''));
+                               
$GLOBALS['phpgw']->template->set_var('acc_project_selected',($values['accounting']=='project'?'
 selected="selected"':''));
+                               
$GLOBALS['phpgw']->template->set_var('project_accounting_factor',sprintf("%01.2f",$values['project_accounting_factor']));
                                
$GLOBALS['phpgw']->template->set_var('acc_billable_checked',($values['billable']=='N'?'
 checked':''));
-                               
$GLOBALS['phpgw']->template->set_var('acc_factor_hour',$values['radio_acc_factor']=='hour'?'checked':'');
-                               
$GLOBALS['phpgw']->template->set_var('acc_factor_day',$values['radio_acc_factor']=='day'?'checked':'');

                                
$GLOBALS['phpgw']->template->fp('accounting_ownhandle','accounting_own',True);
                        }
@@ -1075,27 +1272,28 @@

 // -------------- activities billable ----------------------

-                               
$GLOBALS['phpgw']->template->set_var('bill_activities_list',$this->boprojects->select_activities_list($project_id,True));
+                       
$GLOBALS['phpgw']->template->set_var('bill_activities_list',$this->boprojects->select_activities_list($project_id,True));
                                        
$GLOBALS['phpgw']->template->fp('accounting_acthandle','accounting_act',True);
                                }
                                else
                                {
                                        
$GLOBALS['phpgw']->template->set_var('book_activities_list',$this->boprojects->select_pro_activities($project_id,
 $pro_main, False));
-                               
$GLOBALS['phpgw']->template->set_var('bill_activities_list',$this->boprojects->select_pro_activities($project_id,
 $pro_main, True));
+                       
$GLOBALS['phpgw']->template->set_var('bill_activities_list',$this->boprojects->select_pro_activities($project_id,
 $pro_main, True));
                                        
$GLOBALS['phpgw']->template->fp('accounting_acthandle','accounting_act',True);
                                }
                        }

                        
$GLOBALS['phpgw']->template->set_var('discount',$values['discount']);
-                       
$GLOBALS['phpgw']->template->set_var('dt_amount',$values['discount_type']=='amount'?'checked':'');
-                       
$GLOBALS['phpgw']->template->set_var('dt_percent',$values['discount_type']=='percent'?'checked':'');
+                       
$GLOBALS['phpgw']->template->set_var('dt_no',$values['discount_type']=='no'?' 
selected="selected"':'');
+                       
$GLOBALS['phpgw']->template->set_var('dt_amount',$values['discount_type']=='amount'?'
 selected="selected"':'');
+                       
$GLOBALS['phpgw']->template->set_var('dt_percent',$values['discount_type']=='percent'?'
 selected="selected"':'');

                        
$GLOBALS['phpgw']->template->set_var('budget',$values['budget']);
                        
$GLOBALS['phpgw']->template->set_var('e_budget',$values['e_budget']);
                        
$GLOBALS['phpgw']->template->set_var('number',$values['number']);
                        
$GLOBALS['phpgw']->template->set_var('title',$values['title']);
                        
$GLOBALS['phpgw']->template->set_var('descr',$values['descr']);
-                       
$GLOBALS['phpgw']->template->set_var('ptime',$values['ptime']);
+                       
$GLOBALS['phpgw']->template->set_var('ptime',(intval($values['ptime'])==0?'':intval($values['ptime'])));
                        
$GLOBALS['phpgw']->template->set_var('investment_nr',$values['investment_nr']);
                        
$GLOBALS['phpgw']->template->set_var('customer_nr',$values['customer_nr']);

@@ -1107,32 +1305,64 @@
                        
$GLOBALS['phpgw']->template->set_var('test',$values['test']);
                        
$GLOBALS['phpgw']->template->set_var('quality',$values['quality']);

-//--------- coordinator -------------
+                       
//$GLOBALS['phpgw']->template->set_var('attachment',$this->attached_files->get_files($project_id,
 True));
+                       
$GLOBALS['phpgw']->template->set_var('lang_files',lang('Files'));
+                       
$GLOBALS['phpgw']->template->set_var('lang_attach',lang('Attach File'));

-                       
$GLOBALS['phpgw']->template->set_var('lang_coordinator',($pro_main?lang('job 
manager'):lang('Coordinator')));
+//--------- coordinator -------------

+                       
$GLOBALS['phpgw']->template->set_var('lang_coordinator',lang('Coordinator'));
                        
switch($GLOBALS['phpgw_info']['user']['preferences']['common']['account_selection'])
                        {
                                case 'popup':
                                        if ($values['coordinator'])
                                        {
                                                
$GLOBALS['phpgw']->template->set_var('accountid',$values['coordinator']);
+                                               if(!$values['coordinatorout'])
+                                               {
+                                                       
$GLOBALS['phpgw']->accounts->get_account_name($values['coordinator'],$lid,$fname,$lname);
+                                                       
$values['coordinatorout'] = 
$GLOBALS['phpgw']->common->display_fullname($lid,$fname,$lname);
+                                               }
+                                               
$GLOBALS['phpgw']->template->set_var('accountname',$values['coordinatorout']);
+                                       }
+                                       else
+                                       {
+                                               $values['coordinator'] = 
$GLOBALS['phpgw_info']['user']['account_id'];
+                                               
$GLOBALS['phpgw']->template->set_var('accountid', $values['coordinator']);
+                                               
$GLOBALS['phpgw']->accounts->get_account_name($values['coordinator'],$lid,$fname,$lname);
+                                               $values['coordinatorout'] = 
$GLOBALS['phpgw']->common->display_fullname($lid,$fname,$lname);
                                                
$GLOBALS['phpgw']->template->set_var('accountname',$values['coordinatorout']);
                                        }
                                        
$GLOBALS['phpgw']->template->set_var('clisthandle','');
                                        
$GLOBALS['phpgw']->template->fp('cfieldhandle','cfield',True);

-                                       
$GLOBALS['phpgw']->template->set_var('employee_list',$this->employee_format(array('type'
 => 'popup','project_id' => ($project_id?$project_id:$parent['project_id']))));
-
+                                       if($project_id || $parent['project_id'])
+                                       {
+                                               
$GLOBALS['phpgw']->template->set_var('employee_list',$this->ui_base->employee_format(array('type'
 => 'popup','project_id' => ($project_id?$project_id:$parent['project_id']))));
+                                       }
+                                       elseif(isset($values['employees']) && 
(count($values['employees']) > 0))
+                                       {
+                                               $employee_list = '';
+                                               for($i=0; 
$i<count($values['employees']); ++$i)
+                                               {
+                                                       $account_id = 
$values['employees'][$i];
+                                                       if(!$account_id)
+                                                               continue;
+                                                       
$GLOBALS['phpgw']->accounts->get_account_name($account_id,$lid,$fname,$lname);
+                                                       $fullname = 
$GLOBALS['phpgw']->common->display_fullname($lid,$fname,$lname);
+                                                       $employee_list .= 
'<option value="'.$account_id.'" SELECTED>'.$fullname.'</option>' . "\n";
+                                               }
+                                               
$GLOBALS['phpgw']->template->set_var('employee_list',$employee_list);
+                                       }
                                        
$GLOBALS['phpgw']->template->set_var('elisthandle','');
                                        
$GLOBALS['phpgw']->template->fp('efieldhandle','efield',True);
                                        break;
                                default:
-                                       
$GLOBALS['phpgw']->template->set_var('coordinator_list',$this->employee_format(array('selected'
 => 
($values['coordinator']?$values['coordinator']:$this->boprojects->account))));
+                                       
$GLOBALS['phpgw']->template->set_var('coordinator_list',$this->ui_base->employee_format(array('selected'
 => 
($values['coordinator']?$values['coordinator']:$this->boprojects->account))));
                                                
$GLOBALS['phpgw']->template->set_var('cfieldhandle','');
                                                
$GLOBALS['phpgw']->template->fp('clisthandle','clist',True);

-                                       
$GLOBALS['phpgw']->template->set_var('employee_list',$this->employee_format(array('project_id'
 => ($project_id?$project_id:$parent['project_id']),'action' => $action,
+                                       
$GLOBALS['phpgw']->template->set_var('employee_list',$this->ui_base->employee_format(array('project_id'
 => ($project_id?$project_id:$parent['project_id']),'action' => $action,
                                                                                
                                                                                
                                        'pro_parent' => 
$parent['project_id'],'selected' => $values['employees'])));
                                                
$GLOBALS['phpgw']->template->set_var('efieldhandle','');
                                                
$GLOBALS['phpgw']->template->fp('elisthandle','elist',True);
@@ -1141,13 +1371,17 @@

                        $abid = $values['customer'];
                        $customer = 
$this->boprojects->read_single_contact($abid);
-                       if ($customer[0]['org_name'] == '') { $name = 
$customer[0]['per_first_name'] . ' ' . $customer[0]['per_last_name']; }
-            else { $name = $customer[0]['org_name'] . ' [ ' . 
$customer[0]['per_first_name'] . ' ' . $customer[0]['per_last_name'] . ' ]'; }
-
+                       $name = $customer[0] ? $customer[0]['per_first_name'] . 
' ' . $customer[0]['per_last_name'] : '';
                        $GLOBALS['phpgw']->template->set_var('name',$name);
                        $GLOBALS['phpgw']->template->set_var('abid',$abid);

-                       
$GLOBALS['phpgw']->template->set_var('attachment',$this->attached_files->get_files($project_id,True));
+                       $customer_org_id = $values['customer_org'];
+                       $customer_org = 
$this->boprojects->read_single_contact_org($customer_org_id);
+                       $customer_org_name = $customer_org[0] ? 
$customer[0]['org_name'] : '';
+                       
$GLOBALS['phpgw']->template->set_var('customer_org_name', $customer_org_name);
+                       $GLOBALS['phpgw']->template->set_var('customer_org', 
$customer_org_id);
+
+                       
//$GLOBALS['phpgw']->template->set_var('attachment',$this->attached_files->get_files($project_id,True));

                        if ($project_id && 
$this->boprojects->edit_perms(array('action' => $action,'coordinator' => 
$values['coordinator'],'main_co' => $main['coordinator'],
                                                                                
                        'parent_co' => $parent['coordinator'],'type' => 
'delete')))
@@ -1161,33 +1395,41 @@

                function view_project()
                {
-                       $action                 = $_GET['action'];
-                       $pro_main               = $_GET['pro_main'];
-                       $project_id             = $_GET['project_id'];
-                       $public_view    = $_GET['public_view'];
-                       $referer                = $_GET['referer'];
+                       //$action                 = get_var('action',    
array('POST','GET'));
+                       //$pro_main       = get_var('pro_main',  
array('POST','GET'));
+                       $project_id     = 
get_var('project_id',array('POST','GET'));

-                       if(!$referer)  //$_POST['back'] && !$_POST['done'] && 
!$_POST['edit'])
+                       if($project_id)
                        {
-                               $referer = $_SERVER['HTTP_REFERER'];
+                               $values = 
$this->boprojects->read_single_project($project_id);
+                               $pro_main = $values['main'];
+                               if($values['parent'] > 0)
+                               {
+                                       $action = 'subs';
+                               }
+                               else
+                               {
+                                       $action = 'mains';
+                               }
                        }

-                       //echo 'REFERER: ' . $referer;
-
                        $link_data = array
-                       (
-                               'menuaction'    => 
'projects.uiprojects.view_project',
-                               'pro_main'              => $pro_main,
-                               'action'                => $action,
-                               'project_id'    => $project_id,
-                               'referer'               => $referer,
-                               'public_view'   => $public_view
+                       (
+                               'menuaction'  => 
'projects.uiprojects.view_project',
+                               'pro_main'    => $pro_main,
+                               'action'      => $action,
+                               'project_id'  => $project_id,
+                               'public_view' => $public_view
                        );

                        if($_POST['back'])
                        {
-                               Header('Location: ' . $referer);
-                               //$GLOBALS['phpgw']->redirect_link($referer);
+                               $clickhistory = 
$GLOBALS['phpgw']->session->get_click_path_entry();
+                               $link_data['menuaction'] = 
$clickhistory['menuaction'];
+                               $link_data['project_id'] = 
$clickhistory['get']['project_id'];
+                               $link_data['action'] = 
$clickhistory['get']['action'];
+                               $link_data['pro_main'] = 
$clickhistory['get']['pro_main'];
+                               
$GLOBALS['phpgw']->redirect_link('/index.php',$link_data);
                        }

                        if($_POST['edit'])
@@ -1195,7 +1437,6 @@
                                $link_data['menuaction'] = 
'projects.uiprojects.edit_project';
                                
$GLOBALS['phpgw']->redirect_link('/index.php',$link_data);
                        }
-
                        if($_POST['mstone'])
                        {
                                $link_data['menuaction'] = 
'projects.uiprojects.project_mstones';
@@ -1222,18 +1463,18 @@
                                
$GLOBALS['phpgw']->redirect_link('/index.php',$link_data);
                        }

-                       $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . ($pro_main?lang('view job'):lang('view project'))
-                                                                               
                                        . $this->admin_header_info();
-
                        if (isset($public_view))
                        {
+                               $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . lang('view project')
+                                                                               
                                                . $this->admin_header_info();
                                $GLOBALS['phpgw']->common->phpgw_header();
                                echo parse_navbar();
                                $this->set_app_langs();
                        }
                        else
                        {
-                               $this->display_app_header();
+                               //$this->display_app_header();
+                               $this->ui_base->display_app_header();
                        }

                        $GLOBALS['phpgw']->template->set_file(array('view' => 
'view.tpl'));
@@ -1259,7 +1500,10 @@
                                $prefs = $this->boprojects->read_prefs();
                        }

-                       $values = 
$this->boprojects->read_single_project($project_id);
+                       if(!isset($values))
+                       {
+                               $values = 
$this->boprojects->read_single_project($project_id);
+                       }

                        //_debug_array($values);

@@ -1268,16 +1512,16 @@
                                
$GLOBALS['phpgw']->template->set_var('cat',$this->boprojects->cats->id2name($values['cat']));
                                
$GLOBALS['phpgw']->template->set_var('pcosts',$values['pcosts']);
                        }
+/*
                        else if($pro_main && $action == 'subs')
                        {
                                $main = 
$this->boprojects->read_single_project($pro_main);

                                
$GLOBALS['phpgw']->template->set_var('cat',$this->boprojects->cats->id2name($main['cat']));
                                
$GLOBALS['phpgw']->template->set_var('pcosts',$main['pcosts']);
-                               
$GLOBALS['phpgw']->template->set_var('lang_number',lang('Job ID'));

                                $link_data['project_id'] = $values['parent'];
-                               
$GLOBALS['phpgw']->template->set_var('pro_parent',$this->boprojects->return_value('pro',$values['parent']));
+                               
$GLOBALS['phpgw']->template->set_var('pro_parent',$this->boprojects->return_value('pro',$values['parent']));
                                
$GLOBALS['phpgw']->template->set_var('parent_url',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojects.view_project&action='
                                                                                
                                                                                
                        . ($values['main']==$values['parent']?'mains':'subs') . 
'&project_id='
                                                                                
                                                                                
                . $values['parent'] . '&pro_main=' . $values['main']));
@@ -1288,7 +1532,7 @@
                                
$GLOBALS['phpgw']->template->set_var('previous',$this->boprojects->return_value('pro',$values['previous']));
                                
$GLOBALS['phpgw']->template->fp('subhandle','sub',True);
                        }
-
+*/
                        
$GLOBALS['phpgw']->template->set_var('investment_nr',($values['investment_nr']?$values['investment_nr']:$main['investment_nr']));


@@ -1298,8 +1542,16 @@
                        
$GLOBALS['phpgw']->template->set_var('status',lang($values['status']));
                        
$GLOBALS['phpgw']->template->set_var('access',lang($values['access']));

-                       
$GLOBALS['phpgw']->template->set_var('budget',$values['budget']);
-                       
$GLOBALS['phpgw']->template->set_var('ebudget',$values['e_budget']);
+                       
$GLOBALS['phpgw']->template->set_var('plan_bottom_up_text', 
(($values['plan_bottom_up'] == 'Y') ? lang('Yes') : lang('No')));
+                       
$GLOBALS['phpgw']->template->set_var('direct_work_text', 
(($values['direct_work'] == 'Y') ? lang('Yes') : lang('No')));
+
+                       
$GLOBALS['phpgw']->template->set_var('budget_item',sprintf("%01.2f",$values['budget']-$values['pbudget_jobs']));
+                       
$GLOBALS['phpgw']->template->set_var('budget_jobs',sprintf("%01.2f",$values['pbudget_jobs']));
+                       $GLOBALS['phpgw']->template->set_var('budget_sum', 
sprintf("%01.2f",$values['budget']));
+
+                       
$GLOBALS['phpgw']->template->set_var('ebudget_item',sprintf("%01.2f",$values['e_budget']-$values['e_budget_chields']));
+                       
$GLOBALS['phpgw']->template->set_var('ebudget_jobs',sprintf("%01.2f",$values['e_budget_chields']));
+                       $GLOBALS['phpgw']->template->set_var('ebudget_sum', 
sprintf("%01.2f",$values['e_budget']));

                        
$GLOBALS['phpgw']->template->set_var('discount',$values['discount']);
                        
$GLOBALS['phpgw']->template->set_var('discount_type',$values['discount_type']=='amount'?$prefs['currency']:'%');
@@ -1319,7 +1571,9 @@
                        $month = $this->boprojects->return_date();
                        
$GLOBALS['phpgw']->template->set_var('month',$month['monthformatted']);

-                       
$GLOBALS['phpgw']->template->set_var('ptime',$values['ptime']);
+                       
$GLOBALS['phpgw']->template->set_var('ptime_item',intval($values['ptime']-$values['ptime_jobs']));
+                       
$GLOBALS['phpgw']->template->set_var('ptime_jobs',intval($values['ptime_jobs']));
+                       $GLOBALS['phpgw']->template->set_var('ptime_sum', 
intval($values['ptime']));

                        
$GLOBALS['phpgw']->template->set_var('uhours_jobs',$values['uhours_jobs_all']);

@@ -1334,7 +1588,7 @@

 //--------- coordinator -------------

-                       
$GLOBALS['phpgw']->template->set_var('lang_coordinator',($pro_main?lang('job 
manager'):lang('Coordinator')));
+                       
$GLOBALS['phpgw']->template->set_var('lang_coordinator',lang('Coordinator'));
                        
$GLOBALS['phpgw']->template->set_var('coordinator',$values['coordinatorout']);
                        
$GLOBALS['phpgw']->template->set_var('owner',$GLOBALS['phpgw']->common->grab_owner_name($values['owner']));
                        
$GLOBALS['phpgw']->template->set_var('processor',$GLOBALS['phpgw']->common->grab_owner_name($values['processor']));
@@ -1342,14 +1596,16 @@
 // ----------------------------------- customer ------

                        
$GLOBALS['phpgw']->template->set_var('customer',$values['customerout']);
+                       
$GLOBALS['phpgw']->template->set_var('customerorg',$values['customerorgout']);
                        
$GLOBALS['phpgw']->template->set_var('customer_nr',$values['customer_nr']);

 // --------- milestones ------------------------------

+                       
$GLOBALS['phpgw']->template->set_var('lang_milestones',lang('milestones').':');
                        $mstones = $this->boprojects->get_mstones($project_id);
                        //$link_data['menuaction'] = 
'projects.uiprojects.edit_mstone';

-                       while (is_array($mstones) && list(,$ms) = 
each($mstones))
+                       while (is_array($mstones) && (list($no_use,$ms) = 
each($mstones)))
                        {
                                //$link_data['s_id'] = $ms['s_id'];
                                
$GLOBALS['phpgw']->template->set_var('s_title',$ms['title']);
@@ -1362,7 +1618,7 @@

                        $emps = 
$this->boprojects->get_employee_roles(array('project_id' => 
$project_id,'formatted' => True));

-                       while (is_array($emps) && list(,$emp) = each($emps))
+                       while (is_array($emps) && (list($no_use,$emp) = 
each($emps)))
                        {
                                
$GLOBALS['phpgw']->template->set_var('emp_name',$emp['emp_name']);
                                
$GLOBALS['phpgw']->template->set_var('events',$emp['events']);
@@ -1375,8 +1631,8 @@
                                if($this->boprojects->siteconfig['accounting'] 
== 'own')
                                {
                                        
$GLOBALS['phpgw']->template->set_var('accounting_factor',($values['accounting']=='employee'?lang('factor
 employee'):lang('factor project')));
-                                       
$GLOBALS['phpgw']->template->set_var('project_accounting_factor',$values['project_accounting_factor']);
-                                       
$GLOBALS['phpgw']->template->set_var('project_accounting_factor_d',$values['project_accounting_factor_d']);
+                                       
$GLOBALS['phpgw']->template->set_var('project_accounting_factor',sprintf("%01.2f",$values['project_accounting_factor']));
+                                       
$GLOBALS['phpgw']->template->set_var('project_accounting_factor_d',sprintf("%01.2f",$values['project_accounting_factor_d']));
                                        
$GLOBALS['phpgw']->template->set_var('billable',($values['billable']=='Y'?lang('yes'):lang('no')));

                                        
$GLOBALS['phpgw']->template->fp('accounting_settings','accounting_own',True);
@@ -1424,7 +1680,7 @@
                                }
                        }

-                       
$GLOBALS['phpgw']->template->set_var('attachment',$this->attached_files->get_files($project_id));
+                       
//$GLOBALS['phpgw']->template->set_var('attachment',$this->attached_files->get_files($project_id));

                        $GLOBALS['phpgw']->template->set_var('ownhandle','');
                        $GLOBALS['phpgw']->template->set_var('acthandle','');
@@ -1437,15 +1693,15 @@
                        $action         = get_var('action',array('POST','GET'));
                        $pro_main       = 
intval(get_var('pro_main',array('POST','GET')));

-                       $subs           = get_var('subs',array('POST'));
-                       $pa_id          = 
intval(get_var('pa_id',array('POST','GET')));
+                       $subs    = get_var('subs',array('POST'));
+                       $pa_id = intval(get_var('pa_id',array('POST','GET')));

                        $link_data = array
                        (
-                               'menuaction'    => 
'projects.uiprojects.list_projects',
-                               'pro_main'              => $pro_main,
-                               'pa_id'                 => $pa_id,
-                               'action'                => $action
+                               'menuaction' => 
'projects.uiprojects.tree_view_projects',
+                               'pro_main'   => $pro_main,
+                               'pa_id'      => $pa_id,
+                               'action'     => $action
                        );

                        if($pa_id==0 || 
!($this->boprojects->edit_perms(array('type' => 'delete','project_id' => 
$pa_id,'action' => $action,'main' => $pro_main))))
@@ -1456,44 +1712,38 @@
                        if ($_POST['yes'])
                        {
                                $this->attached_files->delete_file($pa_id);
-                               
$this->boprojects->delete_project($pa_id,(isset($_POST['subs'])?True:False));
+                               $this->boprojects->delete_project($pa_id,$subs);
+                               $link_data['project_id'] = $pro_main;
                                
$GLOBALS['phpgw']->redirect_link('/index.php',$link_data);
                        }

                        if ($_POST['no'])
                        {
+                               $link_data['menuaction'] = 
'projects.uiprojects.edit_project';
+                               $link_data['project_id'] = $pa_id;
                                
$GLOBALS['phpgw']->redirect_link('/index.php',$link_data);
                        }

-                       switch($action)
-                       {
-                               case 'mains':   $deleteheader = lang('are you 
sure you want to delete this project');
-                                                               $header = 
lang('delete project');
-                                                               break;
-                               case 'subs':    $deleteheader = lang('are you 
sure you want to delete this job');
-                                                               $header = 
lang('delete job');
-                                                               break;
-                       }
+                       //$GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . $header
+                       //                                                      
                                        . $this->admin_header_info();

-                       $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . $header
-                                                                               
                                        . $this->admin_header_info();
+                       $this->ui_base->display_app_header();

-                       $this->display_app_header();
                        $GLOBALS['phpgw']->template->set_file(array('pa_delete' 
=> 'delete.tpl'));

-                       $GLOBALS['phpgw']->template->set_var('lang_subs','');
+                       //$GLOBALS['phpgw']->template->set_var('lang_subs','');
                        $GLOBALS['phpgw']->template->set_var('subs', '');

-                       
$GLOBALS['phpgw']->template->set_var('deleteheader',$deleteheader);
+                       
$GLOBALS['phpgw']->template->set_var('deleteheader',lang('are you sure you want 
to delete this project'));
                        
$GLOBALS['phpgw']->template->set_var('lang_no',lang('No'));
                        
$GLOBALS['phpgw']->template->set_var('lang_yes',lang('Yes'));

-                       $exists = $this->boprojects->exists('mains', 'par', 
$num ='', $pa_id);
+                       $exists = $this->boprojects->exists(array('check' => 
'parent','project_id' => $pa_id));

                        if ($exists)
                        {
-                               
$GLOBALS['phpgw']->template->set_var('lang_subs',lang('Do you also want to 
delete all sub projects ?'));
-                               
$GLOBALS['phpgw']->template->set_var('subs','<input type="checkbox" name="subs" 
value="True">');
+                               
//$GLOBALS['phpgw']->template->set_var('lang_subs',lang('Do you also want to 
delete all sub projects ?'));
+                               
$GLOBALS['phpgw']->template->set_var('subs','<input type="hidden" name="subs" 
value="True">');
                        }

                        $link_data['menuaction'] = 
'projects.uiprojects.delete_project';
@@ -1502,123 +1752,17 @@
                        $GLOBALS['phpgw']->template->pfp('out','pa_delete');
                }

-               function abook()
-               {
-                       $start          = get_var('start',array('POST'));
-                       $cat_id         = get_var('cat_id',array('POST'));
-                       $sort           = get_var('sort',array('POST'));
-                       $order          = get_var('order',array('POST'));
-                       $filter         = get_var('filter',array('POST'));
-                       $qfilter        = get_var('qfilter',array('POST'));
-                       $query          = get_var('query',array('POST'));
-
-                       
$GLOBALS['phpgw']->template->set_file(array('abook_list_t' => 
'addressbook.tpl'));
-                       
$GLOBALS['phpgw']->template->set_block('abook_list_t','abook_list','list');
-
-                       $this->boprojects->cats->app_name = 'addressbook';
-
-                       $this->set_app_langs();
-
-                       
$GLOBALS['phpgw']->template->set_var('title',$GLOBALS['phpgw_info']['site_title']);
-                       
$GLOBALS['phpgw']->template->set_var('lang_action',lang('Address book'));
-                       
$GLOBALS['phpgw']->template->set_var('charset',$GLOBALS['phpgw']->translation->translate('charset'));
-                       
$GLOBALS['phpgw']->template->set_var('font',$GLOBALS['phpgw_info']['theme']['font']);
-
-                       $link_data = array
-                       (
-                               'menuaction'    => 'projects.uiprojects.abook',
-                               'start'                 => $start,
-                               'sort'                  => $sort,
-                               'order'                 => $order,
-                               'cat_id'                => $cat_id,
-                               'filter'                => $filter,
-                               'query'                 => $query
-                       );
-
-                       if (! $start) { $start = 0; }
-
-                       if (!$filter) { $filter = 'none'; }
-
-                       $qfilter = 'tid=n';
-
-                       switch ($filter)
-                       {
-                               case 'none': break;
-                               case 'private': $qfilter .= ',access=private'; 
break;
-                               case 'yours': $qfilter .= ',owner=' . 
$this->boprojects->account; break;
-                       }
-
-                       if ($cat_id)
-                       {
-                               $qfilter .= ',cat_id=' . $cat_id;
-                       }
-
-                       $entries = $this->boprojects->read_abook($start, 
$query, $qfilter, $sort, $order);
-
-// --------------------------------- nextmatch ---------------------------
-
-                       $left = 
$this->nextmatchs->left('/index.php',$start,$this->boprojects->total_records,$link_data);
-                       $right = 
$this->nextmatchs->right('/index.php',$start,$this->boprojects->total_records,$link_data);
-                       $GLOBALS['phpgw']->template->set_var('left',$left);
-                       $GLOBALS['phpgw']->template->set_var('right',$right);
-
-                       
$GLOBALS['phpgw']->template->set_var('lang_showing',$this->nextmatchs->show_hits($this->boprojects->total_records,$start));
-
-// -------------------------- end nextmatch 
------------------------------------
-
-                       
$GLOBALS['phpgw']->template->set_var('cats_action',$GLOBALS['phpgw']->link('/index.php',$link_data));
-                       
$GLOBALS['phpgw']->template->set_var('cats_list',$this->boprojects->cats->formatted_list('select','all',$cat_id,True));
-                       
$GLOBALS['phpgw']->template->set_var('filter_action',$GLOBALS['phpgw']->link('/index.php',$link_data));
-                       
$GLOBALS['phpgw']->template->set_var('filter_list',$this->nextmatchs->new_filter($filter));
-                       
$GLOBALS['phpgw']->template->set_var('search_action',$GLOBALS['phpgw']->link('/index.php',$link_data));
-                       
$GLOBALS['phpgw']->template->set_var('search_list',$this->nextmatchs->search(array('query'
 => $query)));
-
-// ---------------- list header variable template-declarations 
--------------------------
-
-// -------------- list header variable template-declaration 
------------------------
-
-                       
$GLOBALS['phpgw']->template->set_var('sort_company',$this->nextmatchs->show_sort_order($sort,'org_name',$order,'/index.php',lang('Company'),$link_data));
-                       
$GLOBALS['phpgw']->template->set_var('sort_firstname',$this->nextmatchs->show_sort_order($sort,'per_first_name',$order,'/index.php',lang('Firstname'),$link_data));
-                       
$GLOBALS['phpgw']->template->set_var('sort_lastname',$this->nextmatchs->show_sort_order($sort,'per_last_name',$order,'/index.php',lang('Lastname'),$link_data));
-                       
$GLOBALS['phpgw']->template->set_var('lang_select',lang('Select'));
-
-// ------------------------- end header declaration 
--------------------------------
-
-                       for ($i=0;$i<count($entries);$i++)
-                       {
-                               
$GLOBALS['phpgw']->template->set_var('tr_color',$this->nextmatchs->alternate_row_color($tr_color));
-                               $firstname = $entries[$i]['per_first_name'];
-                               if (!$firstname) { $firstname = '&nbsp;'; }
-                               $lastname = $entries[$i]['per_last_name'];
-                               if (!$lastname) { $lastname = '&nbsp;'; }
-                               $company = $entries[$i]['org_name'];
-                               if (!$company) { $company = '&nbsp;'; }
-
-// ---------------- template declaration for list records 
--------------------------
-
-                               
$GLOBALS['phpgw']->template->set_var(array('company'    => $company,
-                                                                       
'firstname'     => $firstname,
-                                                                       
'lastname'              => $lastname,
-                                                                       'abid'  
                => $entries[$i]['contact_id']));
-
-                               
$GLOBALS['phpgw']->template->parse('list','abook_list',True);
-                       }
-
-                       
$GLOBALS['phpgw']->template->parse('out','abook_list_t',True);
-                       $GLOBALS['phpgw']->template->p('out');
-
-                       $GLOBALS['phpgw']->common->phpgw_exit();
-               }
-
                function list_budget()
                {
                        $action         = get_var('action',array('POST','GET'));
                        $pro_main       = 
get_var('pro_main',array('POST','GET'));
+                       $project_id     = 
get_var('project_id',array('POST','GET'));

+                       /*
                        $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . ($pro_parent?lang('list budget'):lang('list budget'))
                                                                                
                                . $this->admin_header_info();
-
-                       $this->display_app_header();
+                       */
+                       $this->ui_base->display_app_header();

                        
$GLOBALS['phpgw']->template->set_file(array('projects_list_t' => 
'list_budget.tpl'));
                        
$GLOBALS['phpgw']->template->set_block('projects_list_t','projects_list','list');
@@ -1638,7 +1782,15 @@

                        if (!$action)
                        {
-                               $action = 'mains';
+                               if (strlen($project_id))
+                               {
+                                       $action = 'mainsubsorted';
+                                       $pro_main = $project_id;
+                               }
+                               else
+                               {
+                                       $action = 'mains';
+                               }
                        }

                        $link_data = array
@@ -1657,10 +1809,11 @@
                                
$GLOBALS['phpgw']->template->set_var('coordinator_main',$main['coordinatorout']);
                                
$GLOBALS['phpgw']->template->set_var('number_main',$main['number']);
                                
$GLOBALS['phpgw']->template->set_var('customer_main',$main['customerout']);
+                               
$GLOBALS['phpgw']->template->set_var('customerorg_main',$main['customerorgout']);
                                
$GLOBALS['phpgw']->template->set_var('url_main',$main['url']);

-                               
$GLOBALS['phpgw']->template->set_var('ubudget_main',$main['u_budget_jobs']);    
//sprintf("%01.2f",$main['u_budget_jobs']));
-                               
$GLOBALS['phpgw']->template->set_var('abudget_main',sprintf("%01.2f",$main['a_budget_jobs']));
+                               
$GLOBALS['phpgw']->template->set_var('ubudget_main',sprintf("%01.2f",$main['u_budget_jobs']));
+                               
$GLOBALS['phpgw']->template->set_var('abudget_main',trim(sprintf("%01.2f",$main['a_budget_jobs'])));

                                
$GLOBALS['phpgw']->template->set_var('pbudget_main',$main['budget']);
                                
$GLOBALS['phpgw']->template->parse('main','project_main',True);
@@ -1668,6 +1821,16 @@

                        $pro = $this->boprojects->list_projects(array('action' 
=> $action,'parent' => $pro_main,'page' => 'budget'));

+
+                       if ($action == 'mainsubsorted')
+                       {
+                               $pro = 
$this->boprojects->list_projects(array('action' => $action,'project_id' => 
$pro_main,'page' => 'budget'));
+                       }
+                       else
+                       {
+                               $pro = 
$this->boprojects->list_projects(array('action' => $action,'parent' => 
$pro_main,'page' => 'budget'));
+                       }
+
 // --------------------- nextmatch variable template-declarations 
------------------------

                        $left = 
$this->nextmatchs->left('/index.php',$this->start,$this->boprojects->total_records,$link_data);
@@ -1679,39 +1842,41 @@

 // ------------------------- end nextmatch template 
--------------------------------------

-                       if ($action == 'mains')
-                       {
+                       //if ($action == 'mains')
+                       //{
                                $action_list= '<select name="cat_id" 
onChange="this.form.submit();"><option value="none">' . lang('Select category') 
. '</option>' . "\n"
                                                        . 
$this->boprojects->cats->formatted_list('select','all',$this->cat_id,True) . 
'</select>';
-                               
$GLOBALS['phpgw']->template->set_var('lang_action',lang('Jobs'));
-                       }
-                       else
-                       {
-                               $action_list= '<select name="pro_main" 
onChange="this.form.submit();"><option value="">' . lang('Select main project') 
. '</option>' . "\n"
-                                                       . 
$this->boprojects->select_project_list(array('status' => $this->status, 
'selected' => $pro_main)) . '</select>';
-                               
$GLOBALS['phpgw']->template->set_var('lang_action',lang('Work hours'));
-                       }
+                               
$GLOBALS['phpgw']->template->set_var('lang_action',lang('sub projects'));
+                       //}
+                       //else
+                       //{
+                       //      $action_list= '<select name="pro_main" 
onChange="this.form.submit();"><option value="">' . lang('Select main project') 
. '</option>' . "\n"
+                       //                              . 
$this->boprojects->select_project_list(array('status' => $this->status, 
'selected' => $pro_main)) . '</select>';
+                       //      
$GLOBALS['phpgw']->template->set_var('lang_action',lang('Work hours'));
+                       //}

                        
$GLOBALS['phpgw']->template->set_var('action_list',$action_list);
                        
$GLOBALS['phpgw']->template->set_var('action_url',$GLOBALS['phpgw']->link('/index.php',$link_data));
                        
$GLOBALS['phpgw']->template->set_var('filter_list',$this->nextmatchs->new_filter($this->filter));
                        
$GLOBALS['phpgw']->template->set_var('search_list',$this->nextmatchs->search(array('query'
 => $this->query)));
-                       
$GLOBALS['phpgw']->template->set_var('status_list',$this->status_format($this->status));
+                       
$GLOBALS['phpgw']->template->set_var('status_list',$this->ui_base->status_format($this->status));

 // ---------------- list header variable template-declarations 
--------------------------

-                       
$GLOBALS['phpgw']->template->set_var('sort_number',$this->nextmatchs->show_sort_order($this->sort,'p_number',$this->order,'/index.php',($pro_main?lang('job
 id'):lang('Project ID')),$link_data));
+                       
$GLOBALS['phpgw']->template->set_var('sort_number',$this->nextmatchs->show_sort_order($this->sort,'p_number',$this->order,'/index.php',lang('Project
 ID'),$link_data));
                        
$GLOBALS['phpgw']->template->set_var('sort_title',$this->nextmatchs->show_sort_order($this->sort,'title',$this->order,'/index.php',lang('Title'),$link_data));

                        
$GLOBALS['phpgw']->template->set_var('sort_planned',$this->nextmatchs->show_sort_order($this->sort,'budget',$this->order,'/index.php',lang('planned'),$link_data));
-                       
$GLOBALS['phpgw']->template->set_var('sort_used',lang('used'));
-                       
$GLOBALS['phpgw']->template->set_var('sort_used_jobs',lang('used - jobs 
included'));
-                       
$GLOBALS['phpgw']->template->set_var('sort_available_budget',lang('budget 
available'));

 // -------------- end header declaration 
---------------------------------------

-            for ($i=0;$i<count($pro);$i++)
-            {
+                       for ($i=0;$i<count($pro);$i++)
+                       {
+                               if ($i==0)
+                               {
+                                       $upmost_level = $pro[$i]['level'];
+                               }
+
                                
$this->nextmatchs->template_alternate_row_color(&$GLOBALS['phpgw']->template);

 // --------------- template declaration for list records 
-------------------------------------
@@ -1729,25 +1894,41 @@

                                $GLOBALS['phpgw']->template->set_var(array
                                (
-                                       'number'                => 
$pro[$i]['number'],
-                                       'sub_url'               => 
$projects_url,
-                                       'title'                 => 
$pro[$i]['title']?$pro[$i]['title']:lang('browse'),
-                                       'p_budget'              => 
($pro[$i]['budget']?$pro[$i]['budget']:'&nbsp;'),
-                                       'u_budget'              => 
$pro[$i]['u_budget'],
-                                       'u_budget_jobs' => 
$pro[$i]['u_budget_jobs'],
-                                       'b_budget'              => 
sprintf("%01.2f",$pro[$i]['b_budget']),
-                                       'b_budget_jobs' => 
sprintf("%01.2f",$pro[$i]['b_budget_jobs']),
-                                       'a_budget'              => 
sprintf("%01.2f",$pro[$i]['a_budget']),
-                                       'a_budget_jobs' => 
sprintf("%01.2f",$pro[$i]['a_budget_jobs']),
+                                       'number'        => $pro[$i]['number'],
+                                       'sub_url'       => $projects_url,
+                                       'title'         => 
$pro[$i]['title']?$pro[$i]['title']:lang('browse'),
+
+                                       'p_budget'      => sprintf('%01.2f', 
$pro[$i]['item_planned_budget']),
+                                       'p_budget_jobs' => sprintf('%01.2f', 
$pro[$i]['sum_planned_budget']),
+                                       'u_budget'      => sprintf('%01.2f', 
$pro[$i]['item_used_budget']),
+                                       'u_budget_jobs' => sprintf('%01.2f', 
$pro[$i]['sum_used_budget']),
+                                       'b_budget'      => sprintf('%01.2f', 
$pro[$i]['item_bill_budget']),
+                                       'b_budget_jobs' => sprintf('%01.2f', 
$pro[$i]['sum_bill_budget']),
+                                       'n_budget'      => sprintf('%01.2f', 
$pro[$i]['item_nobill_budget']),
+                                       'n_budget_jobs' => sprintf('%01.2f', 
$pro[$i]['sum_nobill_budget']),
+                                       'a_budget'      => sprintf('%01.2f', 
$pro[$i]['item_avail_budget']),
+                                       'a_budget_jobs' => sprintf('%01.2f', 
$pro[$i]['sum_avail_budget']),
+
+                                       'list_class_sum'                => 
$pro[$i]['is_leaf']?'leaf_sum':'node_sum',
+                                       'list_class_item'               => 
$pro[$i]['is_leaf']?'leaf_item':'node_item',
+                                       'value_class_sum'               => 
'value_'.$pro[$i]['sum_budget_status'],
+                                       'value_class_item'              => 
'value_'.$pro[$i]['item_budget_status']
                                ));
                                
$GLOBALS['phpgw']->template->parse('list','projects_list',True);

-                               $sum_a_budget_jobs += $pro[$i]['a_budget_jobs'];
-                               $sum_a_budget += $pro[$i]['a_budget'];
-                               $sum_u_budget += $pro[$i]['u_budget'];
-                               $sum_b_budget += $pro[$i]['b_budget'];
-                               $sum_u_budget_jobs += $pro[$i]['u_budget_jobs'];
-                               $sum_b_budget_jobs += $pro[$i]['b_budget_jobs'];
+                               if ($pro[$i]['level'] == $upmost_level)
+                               {
+                                       $sum_p_budget += 
$pro[$i]['item_planned_budget'];
+                                       $sum_a_budget += 
$pro[$i]['item_avail_budget'];
+                                       $sum_u_budget += 
$pro[$i]['item_used_budget'];
+                                       $sum_b_budget += 
$pro[$i]['item_bill_budget'];
+                                       $sum_n_budget += 
$pro[$i]['item_nobill_budget'];
+                                       $sum_p_budget_jobs += 
$pro[$i]['sum_planned_budget'];
+                                       $sum_a_budget_jobs += 
$pro[$i]['sum_avail_budget'];
+                                       $sum_u_budget_jobs += 
$pro[$i]['sum_used_budget'];
+                                       $sum_b_budget_jobs += 
$pro[$i]['sum_bill_budget'];
+                                       $sum_n_budget_jobs += 
$pro[$i]['sum_nobill_budget'];
+                               }
                        }

 // ------------------------- end record declaration ------------------------
@@ -1755,17 +1936,20 @@
 // --------------- template declaration for sum  --------------------------

                        
$GLOBALS['phpgw']->template->set_var('lang_sum_budget',lang('sum budget'));
-                       
$GLOBALS['phpgw']->template->set_var('sum_budget',$this->boprojects->sum_budget(array('action'
 => $action,'parent' => $pro_main)));
+                       
$GLOBALS['phpgw']->template->set_var('sum_budget_jobs',sprintf("%01.2f",$sum_p_budget_jobs));
+                       
$GLOBALS['phpgw']->template->set_var('sum_budget',$action=='mains'?sprintf("%01.2f",$sum_p_budget):'');

-                       
$GLOBALS['phpgw']->template->set_var('sum_budget_used',$action=='subs'?sprintf("%01.2f",$sum_u_budget):'');
-                       
$GLOBALS['phpgw']->template->set_var('sum_a_budget',$action=='subs'?sprintf("%01.2f",$sum_a_budget):'');
-                       
$GLOBALS['phpgw']->template->set_var('sum_b_budget',$action=='subs'?sprintf("%01.2f",$sum_b_budget):'');
+                       
$GLOBALS['phpgw']->template->set_var('sum_u_budget_jobs',sprintf("%01.2f",$sum_u_budget_jobs));
+                       
$GLOBALS['phpgw']->template->set_var('sum_u_budget',$action=='mains'?sprintf("%01.2f",$sum_u_budget):'');

-                       
$GLOBALS['phpgw']->template->set_var('sum_budget_jobs',$action == 
'mains'?sprintf("%01.2f",$sum_u_budget_jobs):'');
+                       
$GLOBALS['phpgw']->template->set_var('sum_b_budget_jobs',sprintf("%01.2f",$sum_b_budget_jobs));
+                       
$GLOBALS['phpgw']->template->set_var('sum_b_budget',$action=='mains'?sprintf("%01.2f",$sum_b_budget):'');

-                       
$GLOBALS['phpgw']->template->set_var('sum_b_budget_jobs',$action == 
'mains'?sprintf("%01.2f",$sum_b_budget_jobs):'');
+                       
$GLOBALS['phpgw']->template->set_var('sum_n_budget_jobs',sprintf("%01.2f",$sum_n_budget_jobs));
+                       
$GLOBALS['phpgw']->template->set_var('sum_n_budget',$action=='mains'?sprintf("%01.2f",$sum_n_budget):'');

-                       
$GLOBALS['phpgw']->template->set_var('sum_a_budget_jobs',$action == 
'mains'?sprintf("%01.2f",$sum_a_budget_jobs):'');
+                       
$GLOBALS['phpgw']->template->set_var('sum_a_budget_jobs',sprintf("%01.2f",$sum_a_budget_jobs));
+                       
$GLOBALS['phpgw']->template->set_var('sum_a_budget',$action=='mains'?sprintf("%01.2f",$sum_a_budget):'');

 // ----------------------- end sum declaration ----------------------------

@@ -1835,7 +2019,14 @@
                        if ($_POST['done'])
                        {
                                unset($jscal);
-                               Header('Location: ' . $referer);
+                               $link = array
+                               (
+                                       'menuaction'    => 
'projects.uiprojects.edit_project',
+                                       'action'                => 'mains',
+                                       'project_id'    => $project_id
+                               );
+                               
$GLOBALS['phpgw']->redirect_link('/index.php',$link);
+                               //Header('Location: ' . $referer);
                        }

                        if ($_GET['delete'])
@@ -1850,7 +2041,9 @@
                        }

                        $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . lang('edit milestones') . $this->admin_header_info();
-                       $this->display_app_header();
+                       //$this->display_app_header();
+                       $this->ui_base->display_app_header();
+                       $this->set_app_langs();

                        
$GLOBALS['phpgw']->template->set_file(array('mstone_list_t' => 
'list_mstones.tpl'));
                        
$GLOBALS['phpgw']->template->set_block('mstone_list_t','mstone_list','list');
@@ -1863,7 +2056,12 @@
                        
$GLOBALS['phpgw']->template->set_var('coordinator_pro',$pro['coordinatorout']);
                        
$GLOBALS['phpgw']->template->set_var('number_pro',$pro['number']);
                        
$GLOBALS['phpgw']->template->set_var('customer_pro',$pro['customerout']);
+                       
$GLOBALS['phpgw']->template->set_var('customerorg_pro',$pro['customerorgout']);
                        
$GLOBALS['phpgw']->template->set_var('url_pro',$pro['url']);
+                       
$GLOBALS['phpgw']->template->set_var('sdate',$pro['sdate_formatted']);
+                       
$GLOBALS['phpgw']->template->set_var('edate',$pro['edate_formatted']);
+
+
                        
$GLOBALS['phpgw']->template->parse('pro','project_data',True);

                        
$GLOBALS['phpgw']->template->set_var('message',$message);
@@ -1886,6 +2084,8 @@
                                                'edit_url'      => 
$GLOBALS['phpgw']->link('/index.php',$link_data),
                                                'title'         => 
$mstones[$i]['title']
                                        ));
+                                       
$GLOBALS['phpgw']->template->set_var('edit_img','<img src="' . 
$GLOBALS['phpgw']->common->image('phpgwapi','edit')
+                                                                               
                                                        . '" border="0" 
title="' . lang('edit') . '">');
                                        unset($link_data['edit']);

                                        if 
($this->boprojects->edit_perms(array('action' => $action,'main' => 
$pro['main'],'parent' => $pro['parent'],'type' => 'delete',
@@ -1954,7 +2154,14 @@

                        if ($_POST['done'])
                        {
-                               Header('Location: ' . $referer);
+                               $link = array
+                               (
+                                       'menuaction'    => 
'projects.uiprojects.edit_project',
+                                       'action'                => 'mains',
+                                       'project_id'    => $project_id
+                               );
+                               
$GLOBALS['phpgw']->redirect_link('/index.php',$link);
+                               //Header('Location: ' . $referer);
                        }

                        if ($_GET['delete'])
@@ -1968,9 +2175,10 @@
                                list($values) = 
$this->boprojects->get_employee_roles(array('project_id' => 
$project_id,'account_id' => $_GET['account_id']));
                        }

-                       $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . lang('assign roles and events')
-                                                                               
                                . $this->admin_header_info();
-                       $this->display_app_header();
+                       //$GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . lang('assign roles and events')
+                       //                                                      
                                . $this->admin_header_info();
+
+                       $this->ui_base->display_app_header();

                        
$GLOBALS['phpgw']->template->set_file(array('role_list_t' => 
'form_emp_roles.tpl'));
                        
$GLOBALS['phpgw']->template->set_block('role_list_t','role_list','list');
@@ -1983,6 +2191,7 @@
                        
$GLOBALS['phpgw']->template->set_var('coordinator_pro',$pro['coordinatorout']);
                        
$GLOBALS['phpgw']->template->set_var('number_pro',$pro['number']);
                        
$GLOBALS['phpgw']->template->set_var('customer_pro',$pro['customerout']);
+                       
$GLOBALS['phpgw']->template->set_var('customerorg_pro',$pro['customerorgout']);
                        
$GLOBALS['phpgw']->template->set_var('url_pro',$pro['url']);
                        
$GLOBALS['phpgw']->template->parse('pro','project_data',True);

@@ -2003,7 +2212,7 @@
                        $co             = 
$this->boprojects->return_value('co',$project_id);

                        if (is_array($roles))
-            {
+                       {
                                foreach($roles as $role)
                                {
                                        
$this->nextmatchs->template_alternate_row_color(&$GLOBALS['phpgw']->template);
@@ -2018,6 +2227,8 @@
                                                        $link_data['edit']      
                = True;
                                                        
$GLOBALS['phpgw']->template->set_var('edit_link','<a href="' . 
$GLOBALS['phpgw']->link('/index.php',$link_data) . '">');
                                                        
$GLOBALS['phpgw']->template->set_var('end_link','</a>');
+                                                       
$GLOBALS['phpgw']->template->set_var('edit_img','<img src="' . 
$GLOBALS['phpgw']->common->image('phpgwapi','edit')
+                                                                               
                                                        . '" . border="0" 
title="' . lang('edit') . '"></a>');
                                                        $link_data['edit']      
                = False;

                                                        $link_data['r_id'] = 
$role['r_id'];
@@ -2029,6 +2240,8 @@
                                                }
                                        }
                                        
$GLOBALS['phpgw']->template->set_var('role_name',$role['role_name']);
+
+
                                        
$GLOBALS['phpgw']->template->set_var('events',$role['events']);
                                        
$GLOBALS['phpgw']->template->parse('list','role_list',True);
                                }
@@ -2037,11 +2250,471 @@
                        
$GLOBALS['phpgw']->template->set_var('action_url',$GLOBALS['phpgw']->link('/index.php',$link_data));
                        
$GLOBALS['phpgw']->template->set_var('role_select',$this->boprojects->action_format($values['role_id']));
                        
$GLOBALS['phpgw']->template->set_var('event_select',$this->boprojects->action_format($values['events'],'event'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_select_role',('select role'));
-                       
$GLOBALS['phpgw']->template->set_var('emp_select',$this->employee_format(array('type'
 => 'selectbox','project_id' => $project_id,'selected' => $values['account_id']
+                       
$GLOBALS['phpgw']->template->set_var('lang_select_role',lang('select role'));
+                       
$GLOBALS['phpgw']->template->set_var('emp_select',$this->ui_base->employee_format(array('type'
 => 'selectbox','project_id' => $project_id,'selected' => $values['account_id']
                                                                                
                                                                                
                        ,'project_only' => True,'admins_included' => True)));
                        
$GLOBALS['phpgw']->template->set_var('lang_assign',lang('assign'));
                        
$GLOBALS['phpgw']->template->pfp('out','role_list_t',True);
                }
+
+               function report()
+               {
+                       $project_id     = 
get_var('project_id',array('POST','GET'));
+                       $generated      = 
get_var('generated',array('POST','GET'));
+                       $sdate          = get_var('sdate',array('POST','GET'));
+                       $edate          = get_var('edate',array('POST','GET'));
+                       $employee       = 
get_var('employee',array('POST','GET'));
+
+                       $this->reportOOo = CreateObject('projects.reportOOo');
+
+                       $jscal = CreateObject('phpgwapi.jscalendar');
+
+                       if($_POST['yes'] || $_POST['no'])
+                       {
+                               if($_POST['yes'])
+                               {
+                                       if($sdate)
+                                       {
+                                               $start_array = 
$jscal->input2date($sdate);
+                                               $start_val   = 
mktime(0,0,0,$start_array['month'],$start_array['day'],$start_array['year']);
+                                       }
+
+                                       if($edate)
+                                       {
+                                               $end_array = 
$jscal->input2date($edate);
+                                               $end_val   = 
mktime(23,59,59,$end_array['month'],$end_array['day'],$end_array['year']);
+                                       }
+
+                                       $link_data = array(
+                                               'menuaction'    => 
'projects.uiprojects.report',
+                                               'project_id'  => $project_id,
+                                               'sdate'             => 
$start_val,
+                                               'edate'             => $end_val
+                                       );
+
+                                       $generated = 
$this->reportOOo->generate($project_id, $start_val, $end_val, $employee);
+                                       if(!$generated)
+                                       {
+                                               $link_data['generated'] = 0;
+                                       }
+                                       else
+                                       {
+                                               $link_data['generated'] = 1;
+                                       }
+                                       
$GLOBALS['phpgw']->redirect_link('/index.php', $link_data);
+                               }
+
+                               
$GLOBALS['phpgw']->redirect_link('/index.php',$link_data);
+                       }
+
+                       //$GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . lang('generate activity report')
+                       //                                                      
                                . $this->admin_header_info();
+
+                       $this->ui_base->display_app_header();
+
+                       $GLOBALS['phpgw']->template->set_file(array('report' => 
'report.tpl'));
+
+                       if($generated === '0')
+                       {
+                               
$GLOBALS['phpgw']->template->set_var('error',lang('no activities in this 
period!'));
+                       }
+                       elseif($generated === '1')
+                       {
+                               
$GLOBALS['phpgw']->template->set_var('error',lang('activity report generated'));
+                       }
+                       else
+                       {
+                               
$GLOBALS['phpgw']->template->set_var('error','');
+                       }
+
+                       $pro = 
$this->boprojects->read_single_project($project_id);
+
+                       $start = 
$sdate?$sdate:mktime(0,0,0,date('m'),1,date('Y'));
+                       $end = 
$edate?$edate:mktime(23,59,59,date('m')+1,0,date('Y'));
+
+                       
$GLOBALS['phpgw']->template->set_var('period',lang('please choose the 
period:'));
+                       
$GLOBALS['phpgw']->template->set_var('lang_no',lang('Cancel'));
+                       
$GLOBALS['phpgw']->template->set_var('lang_yes',lang('generate activity 
report'));
+                       
$GLOBALS['phpgw']->template->set_var('start_date_select',$jscal->input('sdate',$start));
+                       
$GLOBALS['phpgw']->template->set_var('end_date_select',$jscal->input('edate',$end));
+                       
$GLOBALS['phpgw']->template->set_var('lang_employee',lang('Employee'));
+
+                       if($this->boprojects->edit_perms(array('coordinator' => 
$pro['coordinator'])))
+                       {
+                               if(!$employee)
+                               {
+                                       $employee = 
$GLOBALS['phpgw_info']['user']['account_id'];
+                               }
+
+                               
$GLOBALS['phpgw']->template->set_var('employee','<select name="employee">' . 
$this->ui_base->employee_format(array('project_only'               => True,
+                                                                               
                                                                                
                                                                                
                        'admins_included'       => True,
+                                                                               
                                                                                
                                                                                
                        'project_id'            => $project_id,
+                                                                               
                                                                                
                                                                                
                        'selected'                      => 
$employee?$employee:$this->account
+                                                                               
                                                   ))
+                                                                               
                                                . '</select>');
+                       }
+                       else
+                       {
+                               
$GLOBALS['phpgw']->template->set_var('employee','<input type="hidden" 
name="employee" value="' . $this->account . '">' . 
$GLOBALS['phpgw_info']['user']['fullname']);
+                       }
+
+                       
$GLOBALS['phpgw']->template->set_var('attachment',$this->attached_files->get_files($project_id));
+                       
$GLOBALS['phpgw']->template->set_var('lang_activity_reports',lang('Activity 
reports'));
+
+                       $link_data = array
+                       (
+                               'menuaction'    => 'projects.uiprojects.report',
+                               'project_id'    => $project_id
+                       );
+                       
$GLOBALS['phpgw']->template->set_var('actionurl',$GLOBALS['phpgw']->link('/index.php',$link_data));
+
+                       $GLOBALS['phpgw']->template->pfp('out','report');
+
+               }
+
+               function export_cost_accounting()
+               {
+                       $action = get_var('action',array('POST','GET'));
+                       if (!$action)
+                       {
+                               $action = 'select';
+                       }
+
+                       if ($action == 'export')
+                       {
+                               $month = get_var('month',array('POST','GET'));
+                               $year = get_var('year',array('POST','GET'));
+                               if($month && $year)
+                               {
+                                       $data = 
$this->boprojects->get_cost_accounting_diamant($month, $year);
+                                       header("Content-Type: text/plain");
+                                       echo $data;
+                                       $GLOBALS['phpgw']->common->phpgw_exit();
+                               }
+                       }
+
+                       //$GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . ($pro_parent?lang('list budget'):lang('export diamant 
accounting'))
+                       //                                                      
                                . $this->admin_header_info();
+
+                       $this->ui_base->display_app_header();
+
+                       
$GLOBALS['phpgw']->template->set_file(array('export_diamant_t' => 
'export_diamant.tpl'));
+
+                       $link_data = array
+                       (
+                               'menuaction' => 
'projects.uiprojects.export_cost_accounting',
+                               'action'     => 'export'
+                       );
+                       
$GLOBALS['phpgw']->template->set_var('action_url',$GLOBALS['phpgw']->link('/index.php',$link_data));
+
+                       
$GLOBALS['phpgw']->template->set_var('text',lang('Select month and year'));
+
+                       $current_m = date('m', time());
+                       $current_y = date('Y', time());
+
+                       if($current_m == 1)
+                       {
+                               $select_m = 12;
+                               $select_y = $current_y-1;
+                       }
+                       else
+                       {
+                               $select_m = $current_m-1;
+                               $select_y = $current_y;
+                       }
+
+                       $optionlist_m = '';
+                       for($m=1; $m<=12; ++$m)
+                       {
+                               if($m == $select_m)
+                                       $optionlist_m .= '<option 
value="'.$m.'" selected>'.$m.'</option>'."\n";
+                               else
+                                       $optionlist_m .= '<option 
value="'.$m.'"/>'.$m.'</option>'."\n";
+                       }
+
+                       $optionlist_y = '';
+                       for($y=2004; $y<=2010; ++$y)
+                       {
+                               if($y == $select_y)
+                                       $optionlist_y .= '<option 
value="'.$y.'" selected>'.$y.'</option>'."\n";
+                               else
+                                       $optionlist_y .= '<option 
value="'.$y.'"/>'.$y.'</option>'."\n";
+                       }
+
+                       $selectbox_m = '<select 
name="month">'.$optionlist_m.'</select>';
+                       $selectbox_y = '<select 
name="year">'.$optionlist_y.'</select>';
+
+                       
$GLOBALS['phpgw']->template->set_var('selectbox_m',$selectbox_m);
+                       
$GLOBALS['phpgw']->template->set_var('selectbox_y',$selectbox_y);
+                       $GLOBALS['phpgw']->template->set_var('button','<input 
type="submit" name="export" value="' . lang('Submit') . '">');
+                       
$GLOBALS['phpgw']->template->pfp('out','export_diamant_t',True);
+               }
+
+               function view_employee_activity()
+               {
+                       $budget_modus = get_var('budgetmodus', array('POST', 
'GET')) ? get_var('budgetmodus', array('POST', 'GET')) : 'h';
+
+                       
$GLOBALS['phpgw']->template->set_file(array('controlling' => 
'project_activity.tpl'));
+
+                       $jscal = CreateObject('phpgwapi.jscalendar');   // 
before phpgw_header() !!!
+                       $start_array    = 
$jscal->input2date($_REQUEST['datum']['start']);
+                       $end_array        = 
$jscal->input2date($_REQUEST['datum']['end']);
+
+                       $GLOBALS['phpgw']->js->validate_file('api', 
'wz_tooltip');
+
+                       //$values       = get_var('view', array('POST', 'GET'));
+                       $GLOBALS['phpgw']->template->set_var('l_update_view', 
lang('Update'));
+
+                       $start = $start_array['raw'] > 1 ? $start_array['raw'] 
: mktime(0,0,0,7,1,date('Y'));
+                       $end   = $end_array['raw'] > 1 ?   $end_array['raw']   
: mktime(23,59,59,6,30,date('Y')+1);
+
+                       
$GLOBALS['phpgw']->template->set_var('sdate_select',$jscal->input('datum[start]',
 $start));
+                       
$GLOBALS['phpgw']->template->set_var('edate_select',$jscal->input('datum[end]', 
$end));
+
+                       $projectID = get_var('project_id', array('POST','GET'));
+
+                       $this->bohours = 
CreateObject('projects.boprojecthours');
+                       $matrix = 
$this->bohours->build_acitivity_matrix($projectID, $start, $end);
+
+                       for($i=0; $i < count($matrix); $i++)
+                       {
+                               if($i == 0) // head
+                               {
+                                       $output .= '<thead>';
+                                       $output .= '<tr>';
+                                       $output .= '<td style="padding-left: 
5px; background-color: #d3dce3; border-bottom: 2px solid #808080">';
+                                       $output .= lang('Projects');
+                                       $output .= '</td>';
+                                       foreach($matrix[0]['employee'] as $key 
=> $value)
+                                       {
+                                               $allemployees[] = $key;
+                                               $output .= '<td 
style="background-color: #d3dce3; font-weight: bold; height: 30px; 
padding-left: 5px; padding-right: 5px; border-bottom: 2px solid #808080; 
vertical-align: bottom">';
+                                               
$GLOBALS['phpgw']->accounts->get_account_name($key, $lid,$fname,$lname);
+                                               $output .= 
$GLOBALS['phpgw']->common->display_fullname($lid, $fname, $lname);
+                                               $output .= '</td>';
+                                       }
+                                       $output .= '<td style="font-weight: 
bold; background-color: #d3dce3; border-bottom: 2px solid #808080">';
+                                       $output .= lang('Total');
+                                       $output .= '</td>';
+                                       $output .= '</tr>';
+                                       $output .= '</thead>';
+                               }
+
+                               $output .= '<tbody>';
+                               $output .= '<tr>';
+                               $output .= '<td style="font-weight: bold; 
white-space: nowrap; background-color: #d3dce3; vertical-align: top; 
border-bottom: 1px solid #808080; padding-left: 5px; padding-right: 5px">';
+                               $output .= $matrix[$i]['project']['title'];
+                               $output .= '</td>';
+                               for($j=0; $j < count($allemployees); $j++)
+                               {
+                                       $colstyle = $j % 2 ? 'background-color: 
#eeeeee' : 'background-color: #FFFFFF';
+                                       $output .= '<td style="'.$colstyle.'; 
vertical-align: bottom; border-bottom: 1px solid #808080">';
+                                       foreach($matrix[$i]['employee'] as 
$xkey => $xvalue)
+                                       {
+                                               if($allemployees[$j] == $xkey)
+                                               {
+                                                       $output .= '<table 
align="right" cellspacing="0" cellpadding="0" style="font-size: 10px">';
+                                                       $totalminutes = 0;
+                                                       for($k=0; $k < 
count($xvalue); $k++)
+                                                       {
+                                                               $tooltiptitle = 
$xvalue[$k]['description'];
+
+                                                               $tooltip  = 
'<table width=100%>';
+                                                               $tooltip .= 
'<tr>';
+                                                               $tooltip .= 
'<td>';
+                                                               $tooltip .= 
lang('Date').':';
+                                                               $tooltip .= 
'</td>';
+                                                               $tooltip .= 
'<td align=right>';
+                                                               $tooltip .= 
$xvalue[$k]['date'];
+                                                               $tooltip .= 
'</td>';
+                                                               $tooltip .= 
'</tr>';
+                                                               $tooltip .= 
'<tr>';
+                                                               $tooltip .= 
'<td>';
+                                                               $tooltip .= 
lang('Begin').':';
+                                                               $tooltip .= 
'</td>';
+                                                               $tooltip .= 
'<td align=right>';
+                                                               $tooltip .= 
$xvalue[$k]['start'];
+                                                               $tooltip .= 
'</td>';
+                                                               $tooltip .= 
'</tr>';
+                                                               $tooltip .= 
'<tr>';
+                                                               $tooltip .= 
'<td>';
+                                                               $tooltip .= 
lang('End').':';
+                                                               $tooltip .= 
'</td>';
+                                                               $tooltip .= 
'<td align=right>';
+                                                               $tooltip .= 
$xvalue[$k]['end'];
+                                                               $tooltip .= 
'</td>';
+                                                               $tooltip .= 
'</tr>';
+                                                               $tooltip .= 
'<tr>';
+                                                               $tooltip .= 
'<td>';
+                                                               $tooltip .= 
lang('Hours').':';
+                                                               $tooltip .= 
'</td>';
+                                                               $tooltip .= 
'<td align=right>';
+                                                               $tooltip .= 
$xvalue[$k]['minutesout'];
+                                                               $tooltip .= 
'</td>';
+                                                               $tooltip .= 
'</tr>';
+                                                               $tooltip .= 
'<tr>';
+                                                               $tooltip .= 
'<td>';
+                                                               $tooltip .= 
lang('Status').':';
+                                                               $tooltip .= 
'</td>';
+                                                               $tooltip .= 
'<td align=right>';
+                                                               $tooltip .= 
$xvalue[$k]['statusout'];
+                                                               $tooltip .= 
'</td>';
+                                                               $tooltip .= 
'</tr>';
+                                                               $tooltip .= 
'</table>';
+
+                                                               $output .= 
'<tr>';
+                                                               $output .= 
'<td>';
+                                                               $output .= 
"<div style=\"text-align: right;\" onMouseover=\"this.T_TITLE='$tooltiptitle'; 
this.T_WIDTH=250; return escape('$tooltip'); \" >";
+                                                               
if($budget_modus == 'h')
+                                                               {
+                                                                       $output 
.= $this->bohours->format_minutes($xvalue[$k]['minutes']).'<br>';
+                                                               }
+                                                               else
+                                                               {
+                                                                       $output 
.= number_format($xvalue[$k]['minutes'] / 60 * 
$matrix[$i]['project']['budget_factor'], 0, ',', '.'). ' &euro;';
+                                                               }
+                                                               $totalminutes 
+= $xvalue[$k]['minutes'];
+                                                               $output .= 
'</div>';
+                                                               $output .= 
'</td>';
+                                                               $output .= 
'</tr>';
+                                                       }
+                                                       if($totalminutes > 0)
+                                                       {
+                                                               
$matrix[0]['employee'][$xkey]['totalhours'] += $totalminutes;
+                                                               
$matrix[0]['employee'][$xkey]['totalcosts'] += $totalminutes / 60 * 
$matrix[$i]['project']['budget_factor'];
+                                                               
$matrix[$i]['project']['totalhours'] += $totalminutes;
+                                                               $output .= 
'<tr>';
+                                                               $output .= '<td 
style="font-weight: bold; border-top: 1px solid #000000">';
+                                                               
if($budget_modus == 'h')
+                                                               {
+                                                                       $output 
.= $this->bohours->format_minutes($totalminutes);
+                                                               }
+                                                               else
+                                                               {
+                                                                       $output 
.= number_format($totalminutes / 60 * $matrix[$i]['project']['budget_factor'], 
0, ',', '.'). ' &euro;';
+                                                               }
+                                                               $output .= 
'</td>';
+                                                               $output .= 
'</tr>';
+                                                       }
+                                                       $output .= '</table>';
+                                               }
+                                       }
+                                       $output .= '</td>';
+                               }
+                               $output .= '<td style="font-weight: bold; 
background-color: #d3dce3; vertical-align:bottom; text-align: right; 
border-bottom: 1px solid #808080">';
+
+                               $tooltiptitle = lang('Budget');
+                               $tooltip  = '<table width=100%>';
+                               $tooltip .= '<tr>';
+                               $tooltip .= '<td>';
+                               $tooltip .= lang('Debit').':';
+                               $tooltip .= '</td>';
+                               $tooltip .= '<td align=right>';
+                               if($budget_modus == 'h')
+                               {
+                                       
if($matrix[$i]['project']['budget_factor'] > 0)
+                                       {
+                                               $tooltip .= 
$this->bohours->format_minutes($matrix[$i]['project']['budget'] / 
$matrix[$i]['project']['budget_factor'] * 60);
+                                       }
+                                       else
+                                       {
+                                               $tooltip .= '-';
+                                       }
+                               }
+                               else
+                               {
+                                       $tooltip .= 
number_format($matrix[$i]['project']['budget'], 0, ',', '.'). ' &euro;';
+                               }
+                               $tooltip .= '</td>';
+                               $tooltip .= '</tr>';
+                               $tooltip .= '<tr>';
+                               $tooltip .= '<td>';
+                               $tooltip .= lang('Actual').':';
+                               $tooltip .= '</td>';
+                               $tooltip .= '<td align=right>';
+                               if($budget_modus == 'h')
+                               {
+                                       $tooltip .= 
$this->bohours->format_minutes($matrix[$i]['project']['totalhours']);
+                               }
+                               else
+                               {
+                                       $tooltip .= 
number_format($matrix[$i]['project']['totalhours'] / 60 * 
$matrix[$i]['project']['budget_factor'], 0, ',', '.'). ' &euro;';
+                               }
+                               $tooltip .= '</td>';
+                               $tooltip .= '</tr>';
+                               $tooltip .= '<tr>';
+                               $tooltip .= '<td>';
+                               $tooltip .= lang('Variance').':';
+                               $tooltip .= '</td>';
+                               $tooltip .= '<td align=right>';
+                               if($budget_modus == 'h')
+                               {
+                                       
if($matrix[$i]['project']['budget_factor'] > 0)
+                                       {
+                                               $tooltip .= 
$this->bohours->format_minutes($matrix[$i]['project']['budget'] / 
$matrix[$i]['project']['budget_factor'] * 60 - 
$matrix[$i]['project']['totalhours']);
+                                       }
+                                       else
+                                       {
+                                               $tooltip .= '-';
+                                       }
+                               }
+                               else
+                               {
+                                       $tooltip .= 
number_format($matrix[$i]['project']['budget'] - 
$matrix[$i]['project']['totalhours'] / 60 * 
$matrix[$i]['project']['budget_factor'], 0, ',', '.'). ' &euro;';
+                               }
+                               $tooltip .= '</td>';
+                               $tooltip .= '</tr>';
+                               $tooltip .= '</table>';
+
+                               $output .= "<div style=\"text-align: right;\" 
onMouseover=\"this.T_TITLE='$tooltiptitle'; this.T_WIDTH=250; return 
escape('$tooltip'); \" >";
+                               if($budget_modus == 'h')
+                               {
+                                       $output .= 
$this->bohours->format_minutes($matrix[$i]['project']['totalhours']);
+                               }
+                               else
+                               {
+                                       $output .= 
number_format($matrix[$i]['project']['totalhours'] / 60 * 
$matrix[$i]['project']['budget_factor'], 0, ',', '.'). ' &euro;';
+                               }
+                               $output .= '</div>';
+                               $output .= '</td>';
+                               $output .= '</tr>';
+                       }
+
+                       $GLOBALS['phpgw']->template->set_var('tableContent', 
$output);
+                       $GLOBALS['phpgw']->template->set_var('l_total', 
lang('Total'));
+
+                       for($i = 0; $i < count($allemployees); $i++)
+                       {
+                               $output2 .= '<td style="font-weight: bold; 
text-align: right">';
+                               if($budget_modus == 'h')
+                               {
+                                       $output2 .= 
$this->bohours->format_minutes($matrix[0]['employee'][$allemployees[$i]]['totalhours']);
+                               }
+                               else
+                               {
+                                       $output2 .= 
number_format($matrix[0]['employee'][$allemployees[$i]]['totalcosts'], 0, ',', 
'.'). ' &euro;';
+                               }
+                               $output2 .= '</td>';
+                       }
+
+                       $GLOBALS['phpgw']->template->set_var('tableContent2', 
$output2);
+/*
+                       $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . lang('view project activities')
+                                                                       . 
$this->admin_header_info();
+                       $this->display_app_header();
+*/
+                       $this->ui_base->display_app_header();
+
+                       if($budget_modus == 'm')
+                       {
+                               
$GLOBALS['phpgw']->template->set_var('selected', 'selected');
+                       }
+                       $GLOBALS['phpgw']->template->set_var('l_hour', 
lang('timed'));
+                       $GLOBALS['phpgw']->template->set_var('l_monetary', 
lang('monetary'));
+                       $GLOBALS['phpgw']->template->set_var('l_project', 
$matrix[0]['project']['title']);
+
+                       $GLOBALS['phpgw']->template->pfp('out','controlling', 
True);
+               }
+
        }
 ?>

====================================================
Index: projects/inc/class.uistatistics.inc.php
diff -u projects/inc/class.uistatistics.inc.php:1.55 
projects/inc/class.uistatistics.inc.php:1.56
--- projects/inc/class.uistatistics.inc.php:1.55        Sun Jun 20 23:02:43 2004
+++ projects/inc/class.uistatistics.inc.php     Mon Mar 14 17:39:39 2005
@@ -35,23 +35,29 @@
                var $sort;
                var $order;
                var $cat_id;
+               var $ui_base;

                var $public_functions = array
                (
-                       'list_projects'         => True,
-                       'list_users'            => True,
-                       'user_stat'                     => True,
-                       'project_gantt'         => True,
-                       'show_stat'                     => True,
-                       'get_screen_size'       => True
+                       'list_projects'                         => True,
+                       'list_users'                            => True,
+                       'list_users_worktimes'          => True,
+                       'user_stat'                                     => True,
+                       'project_gantt'                         => True,
+                       'show_stat'                                     => True,
+                       'get_screen_size'                       => True,
+                       'list_project_employees'        => true
                );

                function uistatistics()
                {
                        $action = get_var('action',array('POST','GET'));

+                       $this->ui_base                  = 
CreateObject('projects.uiprojects_base');
+                       $this->boprojects                               = 
$this->ui_base->boprojects;
+
                        $this->bostatistics                             = 
CreateObject('projects.bostatistics');
-                       $this->boprojects                               = 
$this->bostatistics->boprojects;
+
                        $this->nextmatchs                               = 
CreateObject('phpgwapi.nextmatchs');
                        $this->sbox                                             
= CreateObject('phpgwapi.sbox');
                        $this->cats                                             
= CreateObject('phpgwapi.categories');
@@ -85,139 +91,6 @@
                        $this->boprojects->save_sessiondata($data, $action);
                }

-               function set_app_langs()
-               {
-                       
$GLOBALS['phpgw']->template->set_var('th_bg',$GLOBALS['phpgw_info']['theme']['th_bg']);
-                       
$GLOBALS['phpgw']->template->set_var('row_on',$GLOBALS['phpgw_info']['theme']['row_on']);
-                       
$GLOBALS['phpgw']->template->set_var('row_off',$GLOBALS['phpgw_info']['theme']['row_off']);
-
-                       
$GLOBALS['phpgw']->template->set_var('lang_archiv',lang('archive'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_statistics',lang('Statistics'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_projects',lang('Projects'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_ttracker',lang('time tracker'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_roles',lang('roles'));
-
-                       
$GLOBALS['phpgw']->template->set_var('lang_category',lang('Category'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_calculate',lang('Calculate'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_descr',lang('Description'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_title',lang('Title'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_none',lang('None'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_start_date',lang('Start Date'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_end_date',lang('End Date'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_date_due',lang('Date due'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_project',lang('Project'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_hours',lang('Hours'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_jobs',lang('Jobs'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_activity',lang('Activity'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_title',lang('Title'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_status',lang('Status'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_budget',lang('Budget'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_customer',lang('Customer'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_coordinator',lang('Coordinator'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_done',lang('Done'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_firstname',lang('Firstname'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_lastname',lang('Lastname'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_employee',lang('Employee'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_employees',lang('Employees'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_billedonly',lang('Billed only'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_hours',lang('Work hours'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_minperae',lang('Minutes per 
workunit'));
-               
$GLOBALS['phpgw']->template->set_var('lang_billperae',lang('Bill per 
workunit'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_stat',lang('Statistic'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_userstats',lang('User statistics'));
-
-                       
$GLOBALS['phpgw']->template->set_var('lang_view_projects',lang('view 
projects'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_gantt_chart',lang('gantt chart'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_show_chart',lang('show gantt 
chart'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_view_employees',lang('view 
employees'));
-
-                       
$GLOBALS['phpgw']->template->set_var('lang_main',lang('Main project'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_number',lang('Project ID'));
-                       
$GLOBALS['phpgw']->template->set_var('lang_url',lang('project url'));
-               }
-
-               function display_app_header()
-               {
-                       if 
($GLOBALS['phpgw_info']['user']['preferences']['common']['template_set'] != 
'idots')
-                       {
-                               
$GLOBALS['phpgw']->template->set_file(array('header' => 'header.tpl'));
-                               
$GLOBALS['phpgw']->template->set_block('header','projects_header');
-                               
$GLOBALS['phpgw']->template->set_block('header','projects_admin_header');
-
-                               if ($this->boprojects->isprojectadmin('pad') || 
$this->boprojects->isprojectadmin('pmanager'))
-                               {
-                                       switch($this->siteconfig['accounting'])
-                                       {
-                                               case 'activity':
-                                                       
$GLOBALS['phpgw']->template->set_var('link_accounting',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiconfig.list_activities&action=act'));
-                                                       
$GLOBALS['phpgw']->template->set_var('lang_accounting',lang('Activities'));
-                                                       break;
-                                               default:
-                                                       
$GLOBALS['phpgw']->template->set_var('link_accounting',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiconfig.list_employees&action=accounting'));
-                                                       
$GLOBALS['phpgw']->template->set_var('lang_accounting',lang('Accounting'));
-                                       }
-                                       
$GLOBALS['phpgw']->template->set_var('link_budget',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojects.list_budget&action=mains'));
-                                       
$GLOBALS['phpgw']->template->set_var('lang_budget',lang('budget'));
-                                       
$GLOBALS['phpgw']->template->fp('admin_header','projects_admin_header');
-                               }
-
-                               
$GLOBALS['phpgw']->template->set_var('link_jobs',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojects.list_projects&action=subs'));
-                               
$GLOBALS['phpgw']->template->set_var('link_hours',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojecthours.list_projects&action=mains'));
-                               
$GLOBALS['phpgw']->template->set_var('link_ttracker',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojecthours.ttracker'));
-                               
$GLOBALS['phpgw']->template->set_var('link_statistics',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uistatistics.list_projects&action=mains'));
-                               
$GLOBALS['phpgw']->template->set_var('link_projects',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojects.list_projects&action=mains'));
-
-                               
$GLOBALS['phpgw']->template->fp('app_header','projects_header');
-                       }
-                       $GLOBALS['phpgw']->common->phpgw_header();
-                       echo parse_navbar();
-                       $this->set_app_langs();
-               }
-
-               function admin_header_info()
-               {
-                       if ($this->boprojects->isprojectadmin('pad'))
-                       {
-                               $pa = True;
-                       }
-
-                       if ($this->boprojects->isprojectadmin('pmanager'))
-                       {
-                               $pm = True;
-                       }
-
-                       if ($this->boprojects->isprojectadmin('psale'))
-                       {
-                               $ps = True;
-                       }
-                       return ($pa?'&nbsp;&gt;&nbsp;' . 
lang('administrator'):'') . ($pm?'&nbsp;&gt;&nbsp;' . lang('manager'):'')
-                                       . ($ps?'&nbsp;&gt;&nbsp;' . 
lang('salesman'):'');
-               }
-
-               function status_format($status = '', $showarchive = True)
-               {
-                       if (!$status)
-                       {
-                               $status = $this->status = 'active';
-                       }
-
-                       switch ($status)
-                       {
-                               case 'active':          $stat_sel[0]=' 
selected'; break;
-                               case 'nonactive':       $stat_sel[1]=' 
selected'; break;
-                               case 'archive':         $stat_sel[2]=' 
selected'; break;
-                       }
-
-                       $status_list = '<option value="active"' . $stat_sel[0] 
. '>' . lang('Active') . '</option>' . "\n"
-                                               . '<option value="nonactive"' . 
$stat_sel[1] . '>' . lang('Nonactive') . '</option>' . "\n";
-
-                       if ($showarchive)
-                       {
-                               $status_list .= '<option value="archive"' . 
$stat_sel[2] . '>' . lang('Archive') . '</option>' . "\n";
-                       }
-                       return $status_list;
-               }
-
                function list_projects()
                {
                        $action         = get_var('action',array('POST','GET'));
@@ -230,6 +103,11 @@
                                
$GLOBALS['phpgw']->redirect_link('/index.php','menuaction=projects.uistatistics.list_users');
                        }

+                       if($_POST['worktimestats'])
+                       {
+                               
$GLOBALS['phpgw']->redirect_link('/index.php','menuaction=projects.uistatistics.list_users_worktimes');
+                       }
+
                        $pro_user = array();
                        if($_POST['viewuser'])
                        {
@@ -267,9 +145,12 @@
                                }
                        }

-                       $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . ($pro_main?lang('list jobs'):lang('list projects'))
+/*
+                       $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . lang('list projects')
                                                                                
                                        . $this->admin_header_info();
                        $this->display_app_header();
+*/
+                       $this->ui_base->display_app_header();

                        
$GLOBALS['phpgw']->template->set_file(array('projects_list_t' => 
'stats_projectlist.tpl'));
                        
$GLOBALS['phpgw']->template->set_block('projects_list_t','projects_list','list');
@@ -337,17 +218,17 @@
                        
$GLOBALS['phpgw']->template->set_var('action_list',$action_list);
                        
$GLOBALS['phpgw']->template->set_var('filter_list',$this->nextmatchs->new_filter($this->filter));
                        
$GLOBALS['phpgw']->template->set_var('search_list',$this->nextmatchs->search(array('query'
 => $this->query)));
-                       
$GLOBALS['phpgw']->template->set_var('status_list',$this->status_format($this->status));
+                       
$GLOBALS['phpgw']->template->set_var('status_list',$this->ui_base->status_format($this->status));

                        
$GLOBALS['phpgw']->template->set_var('action_url',$GLOBALS['phpgw']->link('/index.php',$link_data));

 // ---------------- list header variable template-declarations 
--------------------------

-                       
$GLOBALS['phpgw']->template->set_var('sort_number',$this->nextmatchs->show_sort_order($this->sort,'num',$this->order,'/index.php',$action=='mains'?lang('Project
 ID'):lang('job id'),$link_data));
+                       
$GLOBALS['phpgw']->template->set_var('sort_number',$this->nextmatchs->show_sort_order($this->sort,'num',$this->order,'/index.php',lang('Project
 ID'),$link_data));
                        
$GLOBALS['phpgw']->template->set_var('sort_title',$this->nextmatchs->show_sort_order($this->sort,'title',$this->order,'/index.php',lang('Title'),$link_data));
                        
$GLOBALS['phpgw']->template->set_var('sort_sdate',$this->nextmatchs->show_sort_order($this->sort,'start_date',$this->order,'/index.php',lang('Start
 date'),$link_data));
                        
$GLOBALS['phpgw']->template->set_var('sort_edate',$this->nextmatchs->show_sort_order($this->sort,'end_date',$this->order,'/index.php',lang('Date
 due'),$link_data));
-                       
$GLOBALS['phpgw']->template->set_var('sort_coordinator',$this->nextmatchs->show_sort_order($this->sort,'coordinator',$this->order,'/index.php',$action=='mains'?lang('Coordinator'):lang('job
 manager'),$link_data));
+                       
$GLOBALS['phpgw']->template->set_var('sort_coordinator',$this->nextmatchs->show_sort_order($this->sort,'coordinator',$this->order,'/index.php',lang('Coordinator'),$link_data));
                        
$GLOBALS['phpgw']->template->set_var('user_img',$GLOBALS['phpgw']->common->image('phpgwapi','users'));
                        
$GLOBALS['phpgw']->template->set_var('user_url',$GLOBALS['phpgw']->link('/index.php',$link_data));

@@ -430,6 +311,181 @@
                        
$GLOBALS['phpgw']->template->pfp('out','projects_list_t',True);
                }

+
+               function list_project_employees()
+               {
+                       $project_id             = 
get_var('project_id',array('POST','GET'));
+
+                       //$GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . lang('list project employees')
+                       //                                                      
                                        . $this->admin_header_info();
+
+                       $this->ui_base->display_app_header();
+
+
+                       
$GLOBALS['phpgw']->template->set_file(array('projects_list_t' => 
'stats_project_employees.tpl'));
+                       
$GLOBALS['phpgw']->template->set_block('projects_list_t','projects_list','list');
+                       
$GLOBALS['phpgw']->template->set_block('projects_list_t','user_list','users');
+                       
$GLOBALS['phpgw']->template->set_block('projects_list_t','user_cols','cols');
+                       
$GLOBALS['phpgw']->template->set_block('projects_list_t','project_main','main');
+
+                       $GLOBALS['phpgw']->template->set_var('msg',$msg);
+
+                       if($pro_main)
+                       {
+                               $main = 
$this->boprojects->read_single_project($pro_main);
+                               
$GLOBALS['phpgw']->template->set_var('title_main',$main['title']);
+                               
$GLOBALS['phpgw']->template->set_var('main_url',$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojects.view_project&action=mains&project_id='
+                                                                               
                                                                                
                . $pro_main));
+                               
$GLOBALS['phpgw']->template->set_var('coordinator_main',$main['coordinatorout']);
+                               
$GLOBALS['phpgw']->template->set_var('number_main',$main['number']);
+                               
$GLOBALS['phpgw']->template->set_var('customer_main',$main['customerout']);
+                               
$GLOBALS['phpgw']->template->set_var('url_main',$main['url']);
+                               
$GLOBALS['phpgw']->template->parse('main','project_main',True);
+                       }
+
+                       $link_data = array
+                       (
+                               'menuaction'    => 
'projects.uistatistics.list_project_employees',
+                               'project_id'    => $project_id,
+                               'cat_id'                => $this->cat_id
+                       );
+
+                       if (!$this->start)
+                       {
+                               $this->start = 0;
+                       }
+
+                       $this->boprojects->limit = false;
+                       $this->boprojects->status = $this->status;
+                       $pro = $this->boprojects->list_projects(array('action' 
=> 'mainsubsorted','project_id' => $project_id));
+
+// --------------------- nextmatch variable template-declarations 
------------------------
+
+                       $left = 
$this->nextmatchs->left('/index.php',$this->start,$this->boprojects->total_records,$link_data);
+                       $right = 
$this->nextmatchs->right('/index.php',$this->start,$this->boprojects->total_records,$link_data);
+                       $GLOBALS['phpgw']->template->set_var('left',$left);
+                       $GLOBALS['phpgw']->template->set_var('right',$right);
+
+                       
$GLOBALS['phpgw']->template->set_var('lang_showing',$this->nextmatchs->show_hits($this->boprojects->total_records,$this->start));
+
+// ------------------------- end nextmatch template 
--------------------------------------
+
+                       //if ($action == 'mains')
+                       //{
+                               $action_list = '<select name="cat_id" 
onChange="this.form.submit();"><option value="none">' . lang('Select category') 
. '</option>' . "\n"
+                                                       . 
$this->boprojects->cats->formatted_list('select','all',$this->cat_id,True) . 
'</select>';
+                       //}
+                       //else
+                       //{
+                       //      $action_list= '<select name="pro_main" 
onChange="this.form.submit();"><option value="">' . lang('Select main project') 
. '</option>' . "\n"
+                       //                              . 
$this->boprojects->select_project_list(array('status' => $status, 'selected' => 
$project_id)) . '</select>';
+                       //}
+
+                       
$GLOBALS['phpgw']->template->set_var('action_list',$action_list);
+                       
$GLOBALS['phpgw']->template->set_var('filter_list',$this->nextmatchs->new_filter($this->filter));
+                       
$GLOBALS['phpgw']->template->set_var('search_list',$this->nextmatchs->search(array('query'
 => $this->query)));
+                       
$GLOBALS['phpgw']->template->set_var('status_list',$this->ui_base->status_format($this->status));
+
+                       
$GLOBALS['phpgw']->template->set_var('action_url',$GLOBALS['phpgw']->link('/index.php',$link_data));
+
+// ---------------- list header variable template-declarations 
--------------------------
+
+                       
$GLOBALS['phpgw']->template->set_var('sort_number',$this->nextmatchs->show_sort_order($this->sort,'p_number',$this->order,'/index.php',lang('project
 id'),$link_data));
+                       
$GLOBALS['phpgw']->template->set_var('sort_title',$this->nextmatchs->show_sort_order($this->sort,'title',$this->order,'/index.php',lang('Title'),$link_data));
+                       
$GLOBALS['phpgw']->template->set_var('sort_sdate',$this->nextmatchs->show_sort_order($this->sort,'start_date',$this->order,'/index.php',lang('Start
 date'),$link_data));
+                       
$GLOBALS['phpgw']->template->set_var('sort_edate',$this->nextmatchs->show_sort_order($this->sort,'end_date',$this->order,'/index.php',lang('Date
 due'),$link_data));
+                       
$GLOBALS['phpgw']->template->set_var('sort_coordinator',$this->nextmatchs->show_sort_order($this->sort,'coordinator',$this->order,'/index.php',lang('Coordinator'),$link_data));
+                       
$GLOBALS['phpgw']->template->set_var('user_img',$GLOBALS['phpgw']->common->image('phpgwapi','users'));
+                       
$GLOBALS['phpgw']->template->set_var('user_url',$GLOBALS['phpgw']->link('/index.php',$link_data));
+
+// -------------- end header declaration 
---------------------------------------
+
+                       for ($i=0;$i<count($pro);$i++)
+            {
+                               $emps[$pro[$i]['project_id']] = 
$this->boprojects->selected_employees(array('project_id' => 
$pro[$i]['project_id'],'roles_included' => True,
+                                                                               
                                                                                
                                'admins_included' => True));
+
+                               
$this->nextmatchs->template_alternate_row_color(&$GLOBALS['phpgw']->template);
+
+// --------------- template declaration for list records 
-------------------------------------
+
+                               /*$projects_url = 
$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uistatistics.list_project_employees&project_id='
+                                                                       . 
$pro[$i]['project_id']);
+                               */
+                               $projects_url = 
$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojecthours.list_hours&project_id='
+                                                                       . 
$pro[$i]['project_id'] . '&action=hours&pro_main=' . $pro[$i]['main']);
+
+                               if($pro[$i]['project_id']==$project_id)
+                               {
+                                       $node_style = "block";
+                               }
+                               else
+                               {
+                                       $node_style = "none";
+                               }
+
+                               $style = '<style 
type="text/css">div.node_view_' . $i . ' { display:' . $node_style . 
';}</style>';
+
+                               $GLOBALS['phpgw']->template->set_var(array
+                               (
+                                       'number'                => 
$pro[$i]['number'],
+                                       'title'                 => 
($pro[$i]['title']?$pro[$i]['title']:lang('browse')),
+                                       'projects_url'  => $projects_url,
+                                       'sdate'                 => 
$pro[$i]['sdateout'],
+                                       'edate'                 => 
$pro[$i]['edateout'],
+                                       'coordinator'   => 
$pro[$i]['coordinatorout'],
+                                       'view_img'              => 
$GLOBALS['phpgw']->common->image('project','users'),
+                                       'radio_user_checked'    => 
$_POST['viewuser']?(in_array($pro[$i]['project_id'],$pro_user)?' 
checked':''):'',
+                                       'project_id'    => 
$pro[$i]['project_id'],
+                                       'node_style'    => $node_style,
+                                       'node_nr'               => $i
+                               ));
+
+
+                               $link_data['project_id'] = 
$pro[$i]['project_id'];
+                               $link_data['pro_users'] = 
$pro[$i]['project_id'];
+                               $link_data['menuaction'] = 
'projects.uistatistics.list_project_employees';
+                               
$GLOBALS['phpgw']->template->set_var('user_url',$GLOBALS['phpgw']->link('/index.php',$link_data));
+
+                               $link_data['menuaction'] = 
'projects.uiprojects.view_project';
+                               
$GLOBALS['phpgw']->template->set_var('view_url',$GLOBALS['phpgw']->link('/index.php',$link_data));
+
+                               $link_data['menuaction'] = 
'projects.uistatistics.project_stat';
+                               
$GLOBALS['phpgw']->template->set_var('stat',$GLOBALS['phpgw']->link('/index.php',$link_data));
+                               
$GLOBALS['phpgw']->template->set_var('lang_gantt_entry',lang('gantt chart'));
+                               
$GLOBALS['phpgw']->template->set_var('lang_project_employees',lang('project 
employees'));
+                               
$GLOBALS['phpgw']->template->set_var('lang_view_employees',lang('view 
employees'));
+
+                               
$GLOBALS['phpgw']->template->set_var('employee_list','');
+                               
$GLOBALS['phpgw']->template->set_var('users','');
+                               if(is_array($emps[$pro[$i]['project_id']]))
+                               {
+                                       foreach($emps[$pro[$i]['project_id']] 
as $e)
+                                       {
+                                               //_debug_array($e);
+                                               
$GLOBALS['phpgw']->template->set_var('emp_name',$e['account_fullname']);
+                                               
$GLOBALS['phpgw']->template->set_var('emp_role',$e['role_name']);
+                                               
$GLOBALS['phpgw']->template->fp('users','user_list',True);
+                                       }
+                                       
$GLOBALS['phpgw']->template->set_var('lang_name',lang('name'));
+                                       
$GLOBALS['phpgw']->template->set_var('lang_role',lang('role'));
+                                       
$GLOBALS['phpgw']->template->fp('employee_list','user_cols',True);
+                               }
+                               
$GLOBALS['phpgw']->template->fp('list','projects_list',True);
+                       }
+
+// ------------------------- end record declaration ------------------------
+
+                       
$GLOBALS['phpgw']->template->set_var('lang_view_gantt',lang('view gantt 
chart'));
+                       
$GLOBALS['phpgw']->template->set_var('lang_view_users',lang('view users'));
+
+                       $this->save_sessiondata('pstat');
+                       $GLOBALS['phpgw']->template->set_var('cols','');
+                       
$GLOBALS['phpgw']->template->pfp('out','projects_list_t',True);
+               }
+
+
+
                function coordinator_format($employee = '')
                {
                        if (! $employee)
@@ -465,9 +521,10 @@
                                }
                        }

-                       $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . lang('User statistics')
-                                                                               
                                        . $this->admin_header_info();
-                       $this->display_app_header();
+                       //$GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . lang('User statistics')
+                       //                                                      
                                        . $this->admin_header_info();
+                       //$this->display_app_header();
+                       $this->ui_base->display_app_header();

                        
$GLOBALS['phpgw']->template->set_file(array('user_list_t' => 
'stats_userlist.tpl'));
                        
$GLOBALS['phpgw']->template->set_block('user_list_t','user_list','list');
@@ -571,9 +628,10 @@
                                
$phpgw->redirect_link('/index.php','menuaction=projects.uistatistics.list_users&action=ustat');
                        }

-                       $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . lang('User statistics')
-                                                                               
                                . $this->admin_header_info();
-                       $this->display_app_header();
+                       //$GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . lang('User statistics')
+                       //                                                      
                                . $this->admin_header_info();
+                       //$this->display_app_header();
+                       $this->ui_base->display_app_header();

                        
$GLOBALS['phpgw']->template->set_file(array('user_stat_t' => 
'stats_userstat.tpl'));
                        
$GLOBALS['phpgw']->template->set_block('user_stat_t','user_stat','stat');
@@ -650,7 +708,7 @@
                                                        
$GLOBALS['phpgw']->template->set_var('e_activity',$GLOBALS['phpgw']->strip_html($hours[$i]['descr'])
 . ' ['
                                                                                
                        . $GLOBALS['phpgw']->strip_html($hours[$i]['num']) . 
']');
                                                        $summin += 
$hours[$i]['min'];
-                                                       $hrs = 
floor($hours[$i]['min']/60) . ':' . sprintf 
("%02d",(int)($hours[$i]['min']-floor($hours[$i]['min']/60)*60));
+                                                       $hrs = 
intval($hours[$i]['min']/60) . ':' . sprintf 
("%02d",(int)($hours[$i]['min']-intval($hours[$i]['min']/60)*60));
                                                        
$GLOBALS['phpgw']->template->set_var('e_hours',$hrs);
                                                        
$GLOBALS['phpgw']->template->fp('stat','user_stat',True);
                                                }
@@ -658,7 +716,7 @@

                                        
$GLOBALS['phpgw']->template->set_var('e_project','&nbsp;');
                                        
$GLOBALS['phpgw']->template->set_var('e_activity','&nbsp;');
-                                       $hrs = floor($summin/60) . ':' . 
sprintf ("%02d",(int)($summin-floor($summin/60)*60));
+                                       $hrs = intval($summin/60) . ':' . 
sprintf ("%02d",(int)($summin-intval($summin/60)*60));
                                        
$GLOBALS['phpgw']->template->set_var('e_hours',$hrs);
                                        
$GLOBALS['phpgw']->template->fp('stat','user_stat',True);
                                }
@@ -681,7 +739,7 @@
                                        
$GLOBALS['phpgw']->template->set_var('e_activity',$GLOBALS['phpgw']->strip_html($userall['descr'])
 . ' ['
                                                                                
                        . $GLOBALS['phpgw']->strip_html($userall['num']) . ']');
                                        $summin += $userall['min'];
-                                       $hrs = floor($userall['min']/60) . ':' 
. sprintf ("%02d",(int)($userall['min']-floor($userall['min']/60)*60));
+                                       $hrs = intval($userall['min']/60) . ':' 
. sprintf ("%02d",(int)($userall['min']-intval($userall['min']/60)*60));
                                        
$GLOBALS['phpgw']->template->set_var('e_hours',$hrs);
                                        
$GLOBALS['phpgw']->template->fp('stat','user_stat',True);
                                }
@@ -690,7 +748,7 @@
                        
$this->nextmatchs->template_alternate_row_color(&$GLOBALS['phpgw']->template);
                        $GLOBALS['phpgw']->template->set_var('e_project','<b>' 
. lang('Sum') . '</b>');
                        
$GLOBALS['phpgw']->template->set_var('e_activity','&nbsp;');
-                       $hrs = floor($summin/60) . ':' . sprintf 
("%02d",(int)($summin-floor($summin/60)*60));
+                       $hrs = intval($summin/60) . ':' . sprintf 
("%02d",(int)($summin-intval($summin/60)*60));
                        $GLOBALS['phpgw']->template->set_var('e_hours',$hrs);
                        
$GLOBALS['phpgw']->template->fp('stat','user_stat',True);
                        
$GLOBALS['phpgw']->template->pfp('out','user_stat_t',True);
@@ -767,7 +825,7 @@

                        //_debug_array($parent_array);

-                       $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . lang('gantt chart') . $this->admin_header_info();
+                       // $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . lang('gantt chart') . $this->admin_header_info();

                        $jscal = CreateObject('phpgwapi.jscalendar');   // 
before phpgw_header() !!!

@@ -776,7 +834,9 @@
                                
$GLOBALS['phpgw']->template->set_file(array('project_stat' => 
'stats_gant_popup.tpl'));
                                
$GLOBALS['phpgw']->template->set_block('project_stat','map','list');

-                               $this->set_app_langs();
+                               
$GLOBALS['phpgw']->template->set_var('lang_show_chart',lang('show gantt 
chart'));
+                               
$GLOBALS['phpgw']->template->set_var('lang_start_date',lang('Start Date'));
+                               
$GLOBALS['phpgw']->template->set_var('lang_end_date',lang('End Date'));
                                $gantt_popup = True;

                                
$GLOBALS['phpgw']->template->set_var('jscal_setup_src',$GLOBALS['phpgw']->link('/phpgwapi/js/jscalendar/jscalendar-setup.php'));
@@ -784,7 +844,7 @@
                        }
                        else
                        {
-                               $this->display_app_header();
+                               $this->ui_base->display_app_header();
                                
$GLOBALS['phpgw']->template->set_file(array('project_stat' => 
'stats_gant.tpl'));
                                
$GLOBALS['phpgw']->template->set_block('project_stat','map','list');

@@ -1025,7 +1085,7 @@
                                                        
$GLOBALS['phpgw']->template->set_var('e_account','&nbsp;');
                                                        
$GLOBALS['phpgw']->template->set_var('e_activity',$GLOBALS['phpgw']->strip_html($hours[$i]['descr'])
 . ' ['
                                                                                
                                . 
$GLOBALS['phpgw']->strip_html($hours[$i]['num']) . ']');
-                                                       $hrs = 
floor($hours[$i]['min']/60). ':' . sprintf 
("%02d",(int)($hours[$i]['min']-floor($hours[$i]['min']/60)*60));
+                                                       $hrs = 
intval($hours[$i]['min']/60). ':' . sprintf 
("%02d",(int)($hours[$i]['min']-intval($hours[$i]['min']/60)*60));
                                                        
$GLOBALS['phpgw']->template->set_var('e_hours',$hrs);
                                                        $summin += 
$hours[$i]['min'];
                                                        
$GLOBALS['phpgw']->template->fp('list','stat_list',True);
@@ -1034,7 +1094,7 @@

                                        
$GLOBALS['phpgw']->template->set_var('e_account','&nbsp;');
                                        
$GLOBALS['phpgw']->template->set_var('e_activity','&nbsp;');
-                                       $sumhours = floor($summin/60). ':' . 
sprintf ("%02d",(int)($summin-floor($summin/60)*60));
+                                       $sumhours = intval($summin/60). ':' . 
sprintf ("%02d",(int)($summin-intval($summin/60)*60));
                                        
$GLOBALS['phpgw']->template->set_var('e_hours',$sumhours);
                                        
$GLOBALS['phpgw']->template->fp('list','stat_list',True);
                                }
@@ -1058,7 +1118,7 @@
                                        
$GLOBALS['phpgw']->template->set_var('e_activity',$GLOBALS['phpgw']->strip_html($proall['descr'])
 . ' ['
                                                                                
                . $GLOBALS['phpgw']->strip_html($proall['num']) . ']');
                                        $summin += $proall['min'];
-                                       $hrs = floor($proall['min']/60). ':' . 
sprintf ("%02d",(int)($proall['min']-floor($proall['min']/60)*60));
+                                       $hrs = intval($proall['min']/60). ':' . 
sprintf ("%02d",(int)($proall['min']-intval($proall['min']/60)*60));
                                        
$GLOBALS['phpgw']->template->set_var('e_hours',$hrs);

                                        
$GLOBALS['phpgw']->template->fp('list','stat_list',True);
@@ -1067,11 +1127,231 @@
                        
$this->nextmatchs->template_alternate_row_color(&$GLOBALS['phpgw']->template);
                        $GLOBALS['phpgw']->template->set_var('e_account','<b>' 
. lang('sum') . '</b>');
                        
$GLOBALS['phpgw']->template->set_var('e_activity','&nbsp;');
-                       $hrs = floor($summin/60). ':' . sprintf 
("%02d",(int)($summin-floor($summin/60)*60));
+                       $hrs = intval($summin/60). ':' . sprintf 
("%02d",(int)($summin-intval($summin/60)*60));
                        $GLOBALS['phpgw']->template->set_var('e_hours',$hrs);

                        
$GLOBALS['phpgw']->template->fp('list','stat_list',True);
                        $GLOBALS['phpgw']->template->pfp('out','project_stat');
                }*/
+
+               function list_users_worktimes()
+               {
+                       $jscal = CreateObject('phpgwapi.jscalendar');   // 
before phpgw_header() !!!
+
+                       $values = $_POST['values'];
+
+                       //$GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('projects') . ': ' . lang('User statistics')
+                       //                                                      
                                        . $this->admin_header_info();
+                       //$this->display_app_header();
+                       $this->ui_base->display_app_header();
+
+                       
$GLOBALS['phpgw']->template->set_file(array('user_list_worktimes_t' => 
'stats_userlist_worktimes.tpl'));
+                       
$GLOBALS['phpgw']->template->set_block('user_list_worktimes_t','pro_list','pro');
+                       
$GLOBALS['phpgw']->template->set_block('user_list_worktimes_t','worktime_list','work');
+
+                       $link_data = array
+                       (
+                               'menuaction' => 
'projects.uistatistics.list_users_worktimes',
+                               'action'     => 'ustat'
+                       );
+
+                       
$GLOBALS['phpgw']->template->set_var('action_url',$GLOBALS['phpgw']->link('/index.php',$link_data));
+                       
$GLOBALS['phpgw']->template->set_var('lang_workhours',lang('work hours'));
+                       
$GLOBALS['phpgw']->template->set_var('lang_workhours_project', lang('Project'));
+                       
$GLOBALS['phpgw']->template->set_var('lang_workhours_journey', lang('time of 
journey'));
+                       
$GLOBALS['phpgw']->template->set_var('lang_workhours_sum', lang('Sum'));
+
+                       if(!isset($values['employee']))
+                       {
+                               $values['employee'] = 
$GLOBALS['phpgw_info']['user']['account_id'];
+                       }
+
+// ---------- employee selectbox variable template-declarations 
---------------------
+
+                       if ($this->boprojects->isprojectadmin('pad') || 
$this->boprojects->isprojectadmin('pmanager'))
+                       {
+                               $employees = 
$this->boprojects->read_projects_acl();
+                               $employees_list = array();
+
+                               while (is_array($employees) && 
(list($no_use,$account_id) = each($employees)))
+                               {
+                                       
$GLOBALS['phpgw']->accounts->get_account_name($account_id,$lid,$fname,$lname);
+                                       if(!$fname && !$lname)
+                                               continue;
+                                       $employees_list[$account_id] = 
$GLOBALS['phpgw']->common->display_fullname($lid,$fname,$lname);
+                               }
+
+                               if(count($employees_list))
+                               {
+                                       asort($employees_list);
+                                       reset($employees_list);
+                               }
+
+                               $select_employee_list = "<select 
name=\"values[employee]\" size=\"1\">\n";
+                               while (list($account_id,$account_name) = 
each($employees_list))
+                               {
+                                       $select_employee_list .= '<option 
value="' . $account_id . '"';
+                                       if ($values['employee'] == $account_id)
+                                       {
+                                               $select_employee_list .= ' 
selected';
+                                       }
+                                       $select_employee_list .= 
'>'.$account_name."</option>\n";
+                               }
+                               $select_employee_list .= '</select>';
+                       }
+                       else
+                       {
+                               // show only current user
+                               $account_id = 
$GLOBALS['phpgw_info']['user']['account_id'];
+                               
$GLOBALS['phpgw']->accounts->get_account_name($account_id,$lid,$fname,$lname);
+                               $select_employee_list = '<input type="hidden" 
name="values[employee]" value="'.$account_id.'">'. 
$GLOBALS['phpgw']->common->display_fullname($lid,$fname,$lname);
+                       }
+
+                       
$GLOBALS['phpgw']->template->set_var('select_employee_list', 
$select_employee_list);
+
+// --------------- end employee selectbox template 
---------------------------------
+
+// ------------ action selectbox variable template-declarations 
---------------------
+
+                       $select_action_list = "<select 
name=\"values[stat_action]\" size=\"1\">\n";
+
+                       $actions = array(
+                               'pro_all'      => lang('all'),
+                               'pro_direct'   => lang('direct work'),
+                               'pro_indirect' => lang('indirect work')
+                       );
+
+                       while(list($stat, $lang_stat) = each($actions))
+                       {
+                               $select_action_list .= '<option 
value="'.$stat.'"';
+                               if($values['stat_action'] == $stat)
+                               {
+                                       $select_action_list .= ' selected';
+                               }
+                               $select_action_list .= 
'>'.$lang_stat."</option>\n";
+                       }
+                       $select_action_list .= '</select>';
+
+                       
$GLOBALS['phpgw']->template->set_var('select_action_list', $select_action_list);
+
+// --------------------- end action selectbox template 
------------------------------
+
+// ------------- jscal variable template-declarations 
-------------------------------
+
+                       $start_val = false;
+                       if($values['sdate'])
+                       {
+                               $start_array = 
$jscal->input2date($values['sdate']);
+                               //$start_val   = $start_array['raw'];
+                               $start_val   = 
mktime(0,0,0,$start_array['month'],$start_array['day'],$start_array['year']);
+                       }
+
+                       $end_val = false;
+                       if($values['edate'])
+                       {
+                               $end_array = 
$jscal->input2date($values['edate']);
+                               //$end_val   = $end_array['raw'];
+                               $end_val   = 
mktime(23,59,59,$end_array['month'],$end_array['day'],$end_array['year']);
+                       }
+
+                       $start = 
$start_val?$start_val:mktime(0,0,0,date('m'),1,date('Y'));
+                       $end   = 
$end_val?$end_val:mktime(23,59,59,date('m')+1,0,date('Y'));
+
+                       
$GLOBALS['phpgw']->template->set_var('sdate_select',$jscal->input('values[sdate]',$start));
+                       
$GLOBALS['phpgw']->template->set_var('edate_select',$jscal->input('values[edate]',$end));
+
+// ------------------------ end jscal template 
--------------------------------------
+
+                       if(isset($values['employee']) && 
($values['employee']>0))
+                       {
+                               $worktimes = 
$this->boprojects->list_emp_worktimes($values['employee'], $start, $end);
+
+                               // filter
+                               $project_list = array();
+                               for($i=0; $i<count($worktimes['projects']); 
++$i)
+                               {
+                                       $project_id = 
$worktimes['projects'][$i];
+                                       $project = 
$worktimes[$project_id]['project_data'];
+
+                                       switch($values['stat_action'])
+                                       {
+                                               case 'pro_direct':
+                                                       
if($project['project_direct'] != 'Y')
+                                                       {
+                                                               continue 2;
+                                                       }
+                                               break;
+                                               case 'pro_indirect':
+                                                       
if($project['project_direct'] != 'N')
+                                                       {
+                                                               continue 2;
+                                                       }
+                                               break;
+                                               case 'pro_all': // fall down
+                                               default:
+                                               break;
+                                       }
+
+                                       $main_project_id = 
$project['project_main'];
+                                       
if(!isset($project_list[$main_project_id]))
+                                       {
+                                               $main = 
$this->boprojects->read_single_project($main_project_id);
+                                               if(!$main)
+                                               {
+                                                       continue;
+                                               }
+
+                                               $project_list[$main_project_id] 
= array();
+                                               
$project_list[$main_project_id]['project_title']        = $main['title'];
+                                               
$project_list[$main_project_id]['sum_minutes_worktime'] = 0;
+                                               
$project_list[$main_project_id]['sum_minutes_journey']  = 0;
+                                               
$project_list[$main_project_id]['sum_minutes_all']      = 0;
+                                       }
+
+                                       
$project_list[$main_project_id]['sum_minutes_worktime'] += 
$project['sum_minutes_worktime'];
+                                       
$project_list[$main_project_id]['sum_minutes_journey']  += 
$project['sum_minutes_journey'];
+                                       
$project_list[$main_project_id]['sum_minutes_all']      += 
$project['sum_minutes_all'];
+                               }
+
+                               $summary_sum_minutes_worktime = 0;
+                               $summary_sum_minutes_journey  = 0;
+                               $summary_sum_minutes_all      = 0;
+
+                               reset($project_list);
+                               while(list($project_id, $project) = 
each($project_list))
+                               {
+                                       $summary_sum_minutes_worktime += 
$project['sum_minutes_worktime'];
+                                       $summary_sum_minutes_journey  += 
$project['sum_minutes_journey'];
+                                       $summary_sum_minutes_all      += 
$project['sum_minutes_all'];
+
+                                       $project_hw  = 
$this->boprojects->format_minutes($project['sum_minutes_worktime']);
+                                       $project_hj = 
$this->boprojects->format_minutes($project['sum_minutes_journey']);
+                                       $project_hs = 
$this->boprojects->format_minutes($project['sum_minutes_all']);
+
+                                       
$GLOBALS['phpgw']->template->set_var('pro_name', $project['project_title']);
+                                       
$GLOBALS['phpgw']->template->set_var('pro_hours', $project_hw);
+                                       
$GLOBALS['phpgw']->template->set_var('pro_hours_journey', $project_hj);
+                                       
$GLOBALS['phpgw']->template->set_var('pro_hours_sum', $project_hs);
+
+                                       
$GLOBALS['phpgw']->template->fp('pro','pro_list', true);
+                               }
+
+                               if(count($project_list) > 0)
+                               {
+                                       
$GLOBALS['phpgw']->template->fp('project_list','pro', true);
+                                       
$GLOBALS['phpgw']->template->set_var('pro', '');
+
+                                       
$GLOBALS['phpgw']->template->set_var('lang_summery', lang('Summary'));
+                                       
$GLOBALS['phpgw']->template->set_var('lang_summery_workhours_project', 
$this->boprojects->format_minutes($summary_sum_minutes_worktime));
+                                       
$GLOBALS['phpgw']->template->set_var('lang_summery_workhours_journey', 
$this->boprojects->format_minutes($summary_sum_minutes_journey));
+                                       
$GLOBALS['phpgw']->template->set_var('lang_summery_workhours_sum', 
$this->boprojects->format_minutes($summary_sum_minutes_all));
+                               }
+
+                               
$GLOBALS['phpgw']->template->fp('work','worktime_list', true);
+
+                       }
+
+                       
$GLOBALS['phpgw']->template->pfp('out','user_list_worktimes_t',True);
+               }
        }
 ?>

====================================================
Index: projects/inc/hook_home.inc.php
diff -u projects/inc/hook_home.inc.php:1.3 projects/inc/hook_home.inc.php:1.4
--- projects/inc/hook_home.inc.php:1.3  Mon Apr 26 15:35:57 2004
+++ projects/inc/hook_home.inc.php      Mon Mar 14 17:39:39 2005
@@ -1,27 +1,29 @@
 <?php
-       
/**************************************************************************\
-       * phpGroupWare - home                                                   
   *
-       * http://www.phpgroupware.org                                           
   *
-       * --------------------------------------------                          
   *
-       *  This program is free software; you can redistribute it and/or modify 
it *
-       *  under the terms of the GNU General Public License as published by 
the   *
-       *  Free Software Foundation; either version 2 of the License, or (at 
your  *
-       *  option) any later version.                                           
   *
-       
\**************************************************************************/
+  /**************************************************************************\
+  * phpGroupWare - E-Mail                                                    *
+  * http://www.phpgroupware.org                                              *
+  * --------------------------------------------                             *
+  *  This program is free software; you can redistribute it and/or modify it *
+  *  under the terms of the GNU General Public License as published by the   *
+  *  Free Software Foundation; either version 2 of the License, or (at your  *
+  *  option) any later version.                                              *
+  \**************************************************************************/
+
        /* $Id$ */

        $d1 = strtolower(substr(PHPGW_APP_INC,0,3));
        if($d1 == 'htt' || $d1 == 'ftp' )
        {
-               echo "Failed attempt to break in via an old Security 
Hole!<br>\n";
+               echo "Failed attempt to break in via an old Security Hole!<br 
/>\n";
                $GLOBALS['phpgw']->common->phpgw_exit();
        }
        unset($d1);

-       if 
($GLOBALS['phpgw_info']['user']['preferences']['projects']['mainscreen_showevents'])
+       if 
($GLOBALS['phpgw_info']['user']['preferences']['projects']['mainscreen_showevents']
 == True)
        {
-               $pro = CreateObject('projects.uiprojects');
-               $extra_data = 
'<td>'."\n".$pro->list_projects_home().'</td>'."\n";
+
+               $projects = CreateObject('projects.uiprojects');
+               $extra_data = 
'<td>'."\n".$projects->list_projects_home().'</td>'."\n";

                $portalbox = CreateObject('phpgwapi.listbox',
                        Array(

====================================================
Index: projects/inc/hook_admin.inc.php
diff -u projects/inc/hook_admin.inc.php:1.20 
projects/inc/hook_admin.inc.php:1.21
--- projects/inc/hook_admin.inc.php:1.20        Mon Jan 12 17:25:27 2004
+++ projects/inc/hook_admin.inc.php     Mon Mar 14 17:39:39 2005
@@ -15,10 +15,14 @@
                $file = Array
                (
                        'Site Configuration'            => 
$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiconfig.index&appname=' 
. $appname),
+                       'Worktime statusmail'           => 
$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiconfig.config_worktime_statusmail'),
+                       'Worktime warnmail'                     => 
$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiconfig.config_worktime_warnmail'),
+                       'Workhours booking'                     => 
$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiconfig.config_workhours_booking'),
                        'managing committee'            => 
$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiconfig.list_admins&action=pmanager'),
                        'project administrators'        => 
$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiconfig.list_admins&action=pad'),
                        'sales department'                      => 
$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiconfig.list_admins&action=psale'),
-                       'Global Categories'                     => 
$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uicategories.index&appname='
 . $appname)
+                       'Global Categories'                     => 
$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uicategories.index&appname='
 . $appname),
+                       'edit project id help msg'      => 
$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiconfig.config_proid_help_msg')
                );
 //Do not modify below this line
                display_section($appname,$appname,$file);

====================================================
Index: projects/inc/class.soprojects.inc.php
diff -u projects/inc/class.soprojects.inc.php:1.106 
projects/inc/class.soprojects.inc.php:1.107
--- projects/inc/class.soprojects.inc.php:1.106 Fri Nov 12 15:51:47 2004
+++ projects/inc/class.soprojects.inc.php       Mon Mar 14 17:39:39 2005
@@ -42,7 +42,7 @@
                        $this->year                     = 
$GLOBALS['phpgw']->common->show_date(time(),'Y');
                        $this->member           = $this->get_acl_projects();
                        $this->soconfig         = 
CreateObject('projects.soconfig');
-                       $this->siteconfig       = $this->get_site_config();
+                       $this->siteconfig       = 
$this->soconfig->get_site_config();
                        $this->column_array = array();
                }

@@ -75,45 +75,51 @@
                                {
                                        $projects[] = array
                                        (
-                                               'project_id'                    
                => $this->db->f('project_id'),
+                                               'project_id'                    
        => $this->db->f('project_id'),
                                                'parent'                        
                        => $this->db->f('parent'),
                                                'number'                        
                        => $this->db->f('p_number'),
                                                'access'                        
                        => $this->db->f('access'),
-                                               'cat'                           
                        => $this->db->f('category'),
+                                               'cat'                           
                                => $this->db->f('category'),
                                                'sdate'                         
                        => $this->db->f('start_date'),
                                                'edate'                         
                        => $this->db->f('end_date'),
-                                               'coordinator'                   
                => $this->db->f('coordinator'),
-                                               'customer'                      
                        => $this->db->f('customer'),
+                                               'coordinator'                   
        => $this->db->f('coordinator'),
+                                               'customer'                      
                => $this->db->f('customer'),
+                                               'customer_org'                  
=> $this->db->f('customer_org'),
                                                'status'                        
                        => $this->db->f('status'),
                                                'descr'                         
                        => $this->db->f('descr'),
                                                'title'                         
                        => $this->db->f('title'),
                                                'budget'                        
                        => $this->db->f('budget'),
-                                               'e_budget'                      
                        => $this->db->f('e_budget'),
+                                               'budget_childs'     => 
$this->db->f('budget_childs'),
+                                               'e_budget'                      
                => $this->db->f('e_budget'),
+                                               'e_budget_childs'   => 
$this->db->f('e_budget_childs'),
                                                'ptime'                         
                        => $this->db->f('time_planned'),
+                                               'ptime_childs'      => 
$this->db->f('time_planned_childs'),
                                                'owner'                         
                        => $this->db->f('owner'),
                                                'cdate'                         
                        => $this->db->f('date_created'),
-                                               'processor'                     
                        => $this->db->f('processor'),
+                                               'processor'                     
                => $this->db->f('processor'),
                                                'udate'                         
                        => $this->db->f('entry_date'),
-                                               'investment_nr'                 
                => $this->db->f('investment_nr'),
+                                               'investment_nr'                 
=> $this->db->f('investment_nr'),
                                                'main'                          
                        => $this->db->f('main'),
                                                'level'                         
                        => $this->db->f('level'),
-                                               'previous'                      
                        => $this->db->f('previous'),
-                                               'customer_nr'                   
                => $this->db->f('customer_nr'),
-                                               'url'                           
                        => $this->db->f('url'),
-                                               'reference'                     
                        => $this->db->f('reference'),
+                                               'previous'                      
                => $this->db->f('previous'),
+                                               'customer_nr'                   
        => $this->db->f('customer_nr'),
+                                               'url'                           
                                => $this->db->f('url'),
+                                               'reference'                     
                => $this->db->f('reference'),
                                                'result'                        
                        => $this->db->f('result'),
                                                'test'                          
                        => $this->db->f('test'),
                                                'quality'                       
                        => $this->db->f('quality'),
-                                               'accounting'                    
                => $this->db->f('accounting'),
+                                               'accounting'                    
        => $this->db->f('accounting'),
                                                'project_accounting_factor'     
        => $this->db->f('acc_factor'),
                                                'project_accounting_factor_d'   
=> $this->db->f('acc_factor_d'),
-                                               'billable'                      
                        => $this->db->f('billable'),
+                                               'billable'                      
                => $this->db->f('billable'),
                                                'psdate'                        
                        => $this->db->f('psdate'),
                                                'pedate'                        
                        => $this->db->f('pedate'),
-                                               'priority'                      
                        => $this->db->f('priority'),
-                                               'discount'                      
                        => $this->db->f('discount'),
-                                               'discount_type'                 
                => $this->db->f('discount_type'),
-                                               'inv_method'                    
                => $this->db->f('inv_method')
+                                               'priority'                      
                => $this->db->f('priority'),
+                                               'discount'                      
                => $this->db->f('discount'),
+                                               'discount_type'                 
=> $this->db->f('discount_type'),
+                                               'inv_method'                    
        => $this->db->f('inv_method'),
+                                               'plan_bottom_up'                
=> $this->db->f('plan_bottom_up'),
+                                               'direct_work'                   
        => $this->db->f('direct_work')
                                        );
                                }
                        }
@@ -123,7 +129,7 @@
                function read_projects($values)
                {
                        $start          = intval($values['start']);
-                       $limit          = 
(isset($values['limit'])?$values['limit']:True);
+                       $limit          = 
(isset($values['limit'])?$values['limit']:true);
                        $filter         = 
(isset($values['filter'])?$values['filter']:'none');
                        $sort           = $values['sort']?$values['sort']:'ASC';
                        $order          = 
$values['order']?$values['order']:'p_number,title,start_date';
@@ -135,6 +141,7 @@
                        $parent         = intval($values['parent']);
                        $project_id     = intval($values['project_id']);
                        $column         = 
(isset($values['column'])?$values['column']:False);
+                       $employee       = $values['employee'];

                        $query  = $this->db->db_addslashes($values['query']);

@@ -184,6 +191,10 @@
                        {
                                $filtermethod = " access = 'anonym' ";
                        }
+                       elseif ($filter == 'employee')
+                       {
+                               $filtermethod = ' employee =' . $employee;
+                       }
                        else
                        {
                                $filtermethod = ' coordinator=' . 
$this->account . " AND access='private'";
@@ -212,6 +223,7 @@
                        $this->column_array = explode(',',$column);

                        $sql = "SELECT $column_select from phpgw_p_projects 
WHERE $filtermethod $statussort $querymethod";
+                       //wenn accounts in db: $sql = "SELECT $column_select 
from phpgw_p_projects , phpgw_accounts WHERE $filtermethod $statussort 
$querymethod AND coordinator=account_id";

                        if ($limit && $action == 'mains')
                        {
@@ -354,7 +366,7 @@

                        $pro = $this->read_projects(array
                                                (
-                                                       'limit'         => 
False,
+                                                       'limit'         => 
false,
                                                        'status'        => 
$values['status'],
                                                        'action'        => 
(isset($values['action'])?$values['action']:'mains'),
                                                        'main'          => 
$values['main'],
@@ -362,6 +374,11 @@
                                                        'column'        => 
'project_id,p_number,level,title'
                                                ));

+                       if(is_array($pro) && isset($values['action']) && 
(($values['action'] == 'mains') || ($values['action'] == 'mainandsubs')))
+                       {
+                               usort($pro, array("soprojects", "cmp_pro"));
+                       }
+
                        if($values['self'])
                        {
                                for ($i=0;$i<count($pro);$i++)
@@ -397,6 +414,11 @@
                        return $formatted?$s:$pro;
                }

+               function cmp_pro ($a, $b)
+               {
+       return strcasecmp($a['level'].$a['title'], $b['level'].$b['title']);
+               }
+
                function add_project($values)
                {
                        $values['descr']                        = 
$this->db->db_addslashes($values['descr']);
@@ -412,7 +434,9 @@
                        $values['reference']            = 
$this->db->db_addslashes($values['reference']);

                        $values['budget']                       = 
$values['budget'] + 0.0;
+                       $values['budget_childs']               = 
$values['budget_childs'] + 0.0;
                        $values['e_budget']                     = 
$values['e_budget'] + 0.0;
+                       $values['e_budget_childs']             = 
$values['e_budget_childs'] + 0.0;
                        $values['discount']                     = 
$values['discount'] + 0.0;
                        $values['project_accounting_factor'] = 
$values['project_accounting_factor'] + 0.0;
                        $values['project_accounting_factor_d'] = 
$values['project_accounting_factor_d'] + 0.0;
@@ -428,19 +452,19 @@
                        $this->db->lock($table);

                        $this->db->query('INSERT into phpgw_p_projects 
(owner,access,category,entry_date,start_date,end_date,coordinator,customer,status,'
-                                                       . 
'descr,title,budget,p_number,parent,time_planned,date_created,processor,investment_nr,main,level,previous,'
-                                                       . 
'customer_nr,url,reference,result,test,quality,accounting,acc_factor,acc_factor_d,billable,inv_method,psdate,pedate,priority,e_budget,
-                                                       discount,discount_type) 
VALUES ('
+                                                       . 
'descr,title,budget,budget_childs,p_number,parent,time_planned,time_planned_childs,date_created,processor,investment_nr,main,level,previous,'
+                                                       . 
'customer_nr,url,reference,result,test,quality,accounting,acc_factor,acc_factor_d,billable,inv_method,psdate,pedate,priority,e_budget,e_budget_childs,
+                                                       
discount,discount_type,plan_bottom_up,customer_org,direct_work) VALUES ('
                                                        . $this->account . ",'" 
. (isset($values['access'])?$values['access']:'public') . "'," . 
intval($values['cat']) . ',' . time() . ','
                                                        . 
intval($values['sdate']) . ',' . intval($values['edate']) . ',' . 
intval($values['coordinator']) . ',' . intval($values['customer']) . ",'"
-                                                       . $values['status'] . 
"','" . $values['descr'] . "','" . $values['title'] . "'," . $values['budget'] 
. ",'" . $values['number'] . "',"
-                                                       . $values['parent'] . 
',' . intval($values['ptime']) . ',' . time() . ',' . $this->account . ",'" . 
$values['investment_nr']
+                                                       . $values['status'] . 
"','" . $values['descr'] . "','" . $values['title'] . "'," . $values['budget'] 
. "," . $values['budget_childs'] . ",'" . $values['number'] . "',"
+                                                       . $values['parent'] . 
',' . intval($values['ptime']) . ',' . intval($values['ptime_childs']) . ',' . 
time() . ',' . $this->account . ",'" . $values['investment_nr']
                                                        . "'," . 
intval($values['main']) . ',' . intval($values['level']) . ',' . 
intval($values['previous']) . ",'"
                                                        . 
$values['customer_nr'] . "','" . $values['url'] . "','" . $values['reference'] 
. "','" . $values['result'] . "','"
                                                        . $values['test'] . 
"','" . $values['quality'] . "','" . $values['accounting'] . "'," . 
$values['project_accounting_factor']
                                                        . ',' . 
$values['project_accounting_factor_d'] . ",'". ($values['billable']?'N':'Y') . 
"','" . $values['inv_method'] . "',"
-                                                       . 
intval($values['psdate']) . ',' . intval($values['pedate']) . ',' . 
intval($values['priority']) . ',' . $values['e_budget'] . ','
-                                                       . $values['discount'] . 
",'" . $values['discount_type'] . "')",__LINE__,__FILE__);
+                                                       . 
intval($values['psdate']) . ',' . intval($values['pedate']) . ',' . 
intval($values['priority']) . ',' . $values['e_budget'] . ',' . 
$values['e_budget_childs'] . ','
+                                                       . $values['discount'] . 
",'" . $values['discount_type'] . "', '".$values['plan_bottom_up']."', 
".intval($values['customer_org']).", 
'".$values['direct_work']."')",__LINE__,__FILE__);

                        $p_id = 
$this->db->get_last_insert_id($table,'project_id');
                        $this->db->unlock();
@@ -581,10 +605,20 @@
                        $values['edate']                        = 
intval($values['edate']);

                        $values['budget']                       = 
$values['budget'] + 0.0;
+                       $values['budget_childs']               = 
$values['budget_childs'] + 0.0;
                        $values['e_budget']                     = 
$values['e_budget'] + 0.0;
+                       $values['e_budget_childs']             = 
$values['e_budget_childs'] + 0.0;
                        $values['discount']                     = 
$values['discount'] + 0.0;
                        $values['project_accounting_factor'] = 
$values['project_accounting_factor'] + 0.0;
                        $values['project_accounting_factor_d'] = 
$values['project_accounting_factor_d'] + 0.0;
+                       if($values['billable'] == 'N')
+                       {
+                               $values['billable'] = false;
+                       }
+                       elseif($values['billable'] == 'Y')
+                       {
+                               $values['billable'] = true;
+                       }

                        if (isset($values['old_parent']) && 
$values['old_parent'] != $values['parent'])
                        {
@@ -606,16 +640,16 @@
                        $this->db->query("UPDATE phpgw_p_projects set access='" 
. (isset($values['access'])?$values['access']:'public') . "', category=" . 
intval($values['cat']) . ", entry_date="
                                                        . time() . ", 
start_date=" . intval($values['sdate']) . ", end_date=" . $values['edate'] . ", 
coordinator="
                                                        . 
intval($values['coordinator']) . ", customer=" . intval($values['customer']) . 
", status='" . $values['status'] . "', descr='"
-                                                       . $values['descr'] . 
"', title='" . $values['title'] . "', budget=" . $values['budget'] . ", 
p_number='"
-                                                       . $values['number'] . 
"', time_planned=" . intval($values['ptime']) . ', processor=' . $this->account 
. ", investment_nr='"
+                                                       . $values['descr'] . 
"', title='" . $values['title'] . "', budget=" . $values['budget'] . ", 
budget_childs=" . $values['budget_childs'] . ", p_number='"
+                                                       . $values['number'] . 
"', time_planned=" . intval($values['ptime']) . ", time_planned_childs=" . 
intval($values['ptime_childs']) . ', processor=' . $this->account . ", 
investment_nr='"
                                                        . 
$values['investment_nr'] . "', inv_method='" . $values['inv_method'] . "', 
parent=" . $values['parent'] . ', main=' . intval($values['main'])
                                                        . ', level=' . 
intval($values['level']) . ', previous=' . intval($values['previous']) . ", 
customer_nr='" . $values['customer_nr']
                                                        . "', url='" . 
$values['url'] . "', reference='" . $values['reference'] . "', result='" . 
$values['result'] . "', test='"
                                                        . $values['test'] . "', 
quality='" . $values['quality'] . "', accounting='" . $values['accounting'] . 
"', acc_factor="
                                                        . 
$values['project_accounting_factor'] . ', acc_factor_d=' . 
$values['project_accounting_factor_d'] . ",billable='" . 
($values['billable']?'N':'Y')
                                                        . "', discount_type='" 
. $values['discount_type'] . "',psdate=" . intval($values['psdate']) . ', 
pedate=' . intval($values['pedate']) . ', priority='
-                                                       . 
intval($values['priority']) . ', e_budget=' . $values['e_budget'] . ', 
discount=' . $values['discount'] . ' where project_id='
-                                                       . 
$values['project_id'],__LINE__,__FILE__);
+                                                       . 
intval($values['priority']) . ", e_budget=" . $values['e_budget'] . ", 
e_budget_childs=" . $values['e_budget_childs'] . ", discount=" . 
$values['discount'] .", plan_bottom_up='" . $values['plan_bottom_up']
+                                                       . "', 
customer_org=".intval($values['customer_org']). ", direct_work='" . 
$values['direct_work'] . "' where project_id=" . 
$values['project_id'],__LINE__,__FILE__);

                        if ($values['status'] == 'archive')
                        {
@@ -736,6 +770,14 @@
                                        $bla = $this->db->f('charge_percent');
                                }
                        }
+                       else if($action == 'charge')
+                       {
+                               $this->db->query('SELECT charge_percent from 
phpgw_p_surcharges where charge_id=' . $pro_id,__LINE__,__FILE__);
+                               if($this->db->next_record())
+                               {
+                                       $bla = $this->db->f('charge_percent');
+                               }
+                       }
                        else
                        {
                                switch ($action)
@@ -749,13 +791,20 @@
                                        case 'sdate':           $column = 
'start_date'; break;
                                        case 'pedate':          $column = 
'pedate'; break;
                                        case 'psdate':          $column = 
'psdate'; break;
-                                       case 'phours':
+                                       case 'phours':          // fall thru to 
ptime
                                        case 'ptime':           $column = 
'time_planned'; break;
+                                       case 'ptime_childs':    $column = 
'time_planned_childs'; break;
                                        case 'invest':          $column = 
'investment_nr'; break;
                                        case 'budget':          $column = 
'budget'; break;
+                                       case 'budget_childs':   $column = 
'budget_childs'; break;
                                        case 'e_budget':        $column = 
'e_budget'; break;
+                                       case 'e_budget_childs': $column = 
'e_budget_childs'; break;
                                        case 'previous':        $column = 
'previous'; break;
                                        case 'billable':        $column = 
'billable'; break;
+                                       case 'plan_bottom_up':  $column = 
'plan_bottom_up'; break;
+                                       case 'direct_work':     $column = 
'direct_work'; break;
+                                       case 'title':   $column = 'title'; 
break;
+                                       case 'coordinator': $column = 
'coordinator'; break;
                                }

                                $this->db->query('SELECT ' . $column . ' from 
phpgw_p_projects where project_id=' . $pro_id,__LINE__,__FILE__);
@@ -778,26 +827,28 @@
                        return $bla;
                }

-               function exists($action, $check = 'number', $num = '', 
$project_id = '')
+               function exists($params)
                {
-                       $project_id = intval($project_id);
-                       $p_table = ' phpgw_p_projects';
+                       $project_id     = intval($params['project_id']);
+                       $column_val     = 
$params['column_val']?$params['column_val']:$project_id;
+                       $check          = 
$params['check']?$params['check']:'project_id';

                        switch($check)
                        {
                                case 'number':
-                                       $column = ' p_number';
+                                       $column = "'p_number'";
                                        if ($project_id > 0)
                                        {
                                                $editexists = ' and project_id 
!=' . $project_id;
                                        }
                                        break;
-                               case 'par':
-                                       $column = ' parent';
-                                       $num    = $project_id;
+                               case 'parent':
+                                       $column         = "'parent'";
                                        break;
+                               default:
+                                       $column = 'project_id';
                        }
-                       $this->db->query("select count(*) from $p_table where 
$column='$num'" . $editexists,__LINE__,__FILE__);
+                       $this->db->query('SELECT count(*) from phpgw_p_projects 
where ' . $column . '=' . $column_val . $editexists,__LINE__,__FILE__);
                        $this->db->next_record();

                        if ($this->db->f(0))
@@ -810,6 +861,7 @@
                        }
                }

+
 // returns project-,invoice- and delivery-ID

                function add_leading_zero($num)
@@ -903,13 +955,13 @@
                        return $prefix . $max;
                }

-               function delete_project($project_id, $subs = False)
+               function delete_project($project_id, $subs = false)
                {
                        $project_id = intval($project_id);

-                       if ($subs)
+                       if($subs)
                        {
-                               $subpro = $this->read_projects(array('column' 
=> 'project_id,level','limit' => False,'action' => 'subs','parent' => 
$project_id));
+                               $subpro = $this->read_projects(array('column' 
=> 'project_id,level','limit' => false,'action' => 'subs','parent' => 
$project_id));

                                if(is_array($subpro))
                                {
@@ -921,28 +973,34 @@
                                        }
                                }

+                               $id_list = '';
                                if(is_array($s))
                                {
                                        $sub_acl_delete = ' OR acl_location 
in(' . implode(',',$s) . ')';
-                                       $sub_pro_delete = ' OR project_id in(' 
. implode(',',$s) . ')';
+                                       $id_list = ','.implode(',',$s);
                                }
                        }

-                       $this->db->query("DELETE from phpgw_acl where 
acl_appname='projects' and acl_rights=7 and (acl_location=" . $project_id . 
$sub_acl_delete
+                       $this->db->query("DELETE from phpgw_acl where 
acl_appname='project_members' and acl_rights=7 and (acl_location=" . 
$project_id . $sub_acl_delete
                                                        . 
')',__LINE__,__FILE__);

-                       $this->db->query('DELETE from phpgw_p_projects where 
project_id=' . $project_id . $sub_pro_delete,__LINE__,__FILE__);
-
-                       $this->db->query('DELETE from phpgw_p_hours where 
project_id=' . $project_id . $sub_pro_delete,__LINE__,__FILE__);
-
-
-                       $this->db->query('SELECT id from phpgw_p_delivery where 
project_id=' . $project_id . $sub_pro_delete,__LINE__,__FILE__);
+                       if($subs)
+                       {
+                               $this->db->query('DELETE from phpgw_p_projects 
where project_id in('.$project_id.$id_list.')',__LINE__,__FILE__);
+                               $this->db->query('DELETE from phpgw_p_hours 
where project_id in('.$project_id.$id_list.')',__LINE__,__FILE__);
+                       }
+                       else
+                       {
+                               $this->db->query('DELETE from phpgw_p_projects 
where project_id=' . $project_id,__LINE__,__FILE__);
+                               $this->db->query('DELETE from phpgw_p_hours 
where project_id=' . $project_id,__LINE__,__FILE__);
+                       }

+                       $this->db->query('select id from phpgw_p_delivery where 
project_id=' . $project_id,__LINE__,__FILE__);
                        while ($this->db->next_record())
                        {
                                $del[] = array
                                (
-                                       'id' => $this->db->f('id')
+                                       'id'    => $this->db->f('id')
                                );
                        }

@@ -952,16 +1010,16 @@
                                {
                                        $this->db->query('Delete from 
phpgw_p_deliverypos where delivery_id=' . 
intval($del[$i]['id']),__LINE__,__FILE__);
                                }
-                               $this->db->query('DELETE from phpgw_p_delivery 
where project_id=' . $project_id . $sub_pro_delete,__LINE__,__FILE__);
+                               $this->db->query('DELETE from phpgw_p_delivery 
where project_id=' . $project_id,__LINE__,__FILE__);
                        }

-                       $this->db->query('SELECT id from phpgw_p_invoice where 
project_id=' . $project_id . $sub_pro_delete,__LINE__,__FILE__);
+                       $this->db->query('select id from phpgw_p_invoice where 
project_id=' . $project_id,__LINE__,__FILE__);

                        while ($this->db->next_record())
                        {
                                $inv[] = array
                                (
-                                       'id' => $this->db->f('id')
+                                       'id'    => $this->db->f('id')
                                );
                        }

@@ -971,7 +1029,7 @@
                                {
                                        $this->db->query('Delete from 
phpgw_p_invoicepos where invoice_id=' . 
intval($inv[$i]['id']),__LINE__,__FILE__);
                                }
-                               $this->db->query('DELETE from phpgw_p_invoice 
where project_id=' . $project_id . $sub_pro_delete,__LINE__,__FILE__);
+                               $this->db->query('DELETE from phpgw_p_invoice 
where project_id=' . $project_id,__LINE__,__FILE__);
                        }
                }

@@ -982,11 +1040,11 @@
                        {
                                $this->db->query('delete from phpgw_categories 
where cat_owner=' . $account_id . " AND 
cat_appname='projects'",__LINE__,__FILE__);
                                $this->db->query('delete from phpgw_p_hours 
where employee=' . $account_id,__LINE__,__FILE__);
-                               $this->db->query('select id from 
phpgw_p_projects where coordinator=' . $account_id,__LINE__,__FILE__);
+                               $this->db->query('select project_id from 
phpgw_p_projects where coordinator=' . $account_id,__LINE__,__FILE__);

                                while ($this->db->next_record())
                                {
-                                       $drop_list[] = $this->db->f('id');
+                                       $drop_list[] = 
$this->db->f('project_id');
                                }

                                if (is_array($drop_list))
@@ -997,7 +1055,7 @@

                                        $subdelete = ' OR parent in (' . 
implode(',',$drop_list) . ')';

-                                       $this->db->query('DELETE from 
phpgw_p_projects where id project_in (' . implode(',',$drop_list) . ')'
+                                       $this->db->query('DELETE from 
phpgw_p_projects where project_id in (' . implode(',',$drop_list) . ')'
                                                                        . 
$subdelete,__LINE__,__FILE__);

                                        $this->db->query('select id from 
phpgw_p_delivery where project_id in (' . implode(',',$drop_list) . 
')',__LINE__,__FILE__);
@@ -1225,13 +1283,13 @@

                function delete_acl($project_id)
                {
-                       $this->db->query("DELETE from phpgw_acl where 
acl_appname='projects' AND acl_location=" . $project_id
+                       $this->db->query("DELETE from phpgw_acl where 
acl_appname='project_members' AND acl_location=" . $project_id
                                                        . ' AND 
acl_rights=7',__LINE__,__FILE__);
                }

                function get_acl_projects()
                {
-                       $this->db->query("SELECT acl_location from phpgw_acl 
where acl_appname = 'projects' and acl_rights=7 and acl_account="
+                       $this->db->query("SELECT acl_location from phpgw_acl 
where acl_appname = 'project_members' and acl_rights=7 and acl_account="
                                                                . 
$this->account,__LINE__,__FILE__);

                        while($this->db->next_record())
@@ -1289,7 +1347,7 @@

                function member($project_id)
                {
-                       $this->db->query("SELECT acl_account from phpgw_acl 
where acl_appname = 'projects' and acl_rights=7 and acl_location="
+                       $this->db->query("SELECT acl_account from phpgw_acl 
where acl_appname = 'project_members' and acl_rights=7 and acl_location="
                                                                . 
intval($project_id),__LINE__,__FILE__);

                        while($this->db->next_record())
@@ -1334,7 +1392,7 @@
                                                'r_id'                  => 
$this->db->f('id'),
                                                'account_id'    => 
$this->db->f('account_id'),
                                                'role_id'               => 
$this->db->f('role_id'),
-                                               'events'                => 
explode(',',$this->db->f('events'))
+                                               'events'                => 
$this->db->f('events')?explode(',',$this->db->f('events')):array()
                                        );
                                }
                        }
@@ -1469,24 +1527,179 @@
                        return False;
                }

-               function get_site_config($default = True)
+               function plan_bottom_up_set_job_setting($main_project_id, 
$plan_bottom_up)
                {
-                       $this->config = 
CreateObject('phpgwapi.config','projects');
-                       $this->config->read_repository();
+                       $this->db->query('UPDATE phpgw_p_projects SET 
plan_bottom_up="' . $plan_bottom_up . '" WHERE main=' . $main_project_id, 
__LINE__,__FILE__);
+               }
+
+               function direct_work_set_job_setting($main_project_id, 
$direct_work)
+               {
+                       $this->db->query('UPDATE phpgw_p_projects SET 
direct_work="' . $direct_work . '" WHERE main=' . $main_project_id, 
__LINE__,__FILE__);
+               }

-                       if ($this->config->config_data)
+               function get_projects_tree($mainProject = null, $fields = 
array('project_id', 'parent', 'title', 'p_number', 'direct_work', 'p_number', 
'end_date', 'customer_org'), $employee=-1)
+               {
+                       if($employee == -1)
                        {
-                               $items = $this->config->config_data;
+                               $employee = 
$GLOBALS['phpgw_info']['user']['account_id'];
+                       }
+
+                       $projectstree = array();
+                       //if($this->soconfig->isprojectadmin('pad') || 
$this->soconfig->isprojectadmin('pmanager'))
+                       //{
+                       //      $this->db->query('SELECT '.implode($fields, 
',').' FROM phpgw_p_projects '.
+                       //                       'WHERE status = "active"');
+                       //}
+                       //elseif($this->member)
+                       if($this->member)
+                       {
+                               $this->db->query('SELECT '.implode($fields, 
',').' FROM phpgw_p_projects '.
+                                                'WHERE status = "active" AND 
('.
+                                                       'coordinator = 
'.$employee.' OR '.
+                                                       '(access != "private" 
AND project_id in(' . implode(',',$this->member) . '))) ');
+                       }
+                       else
+                       {
+                               return $projectstree;
                        }

-                       if($default)
+                       $i = 0;
+                       while($this->db->next_record())
                        {
-                               $items['hwday']                 = 
isset($items['hwday'])?$items['hwday']:8;
-                               $items['accounting']    = 
isset($items['accounting'])?$items['accounting']:'own';
-                               $items['activity_bill'] = 
isset($items['activity_bill'])?$items['activity_bill']:'h';
-                               $items['dateprevious']  = 
isset($items['dateprevious'])?$items['dateprevious']:'no';
+                               $projects[$i]['id']            = 
$this->db->f(0);
+                               $projects[$i]['parent']        = 
$this->db->f(1);
+                               $projects[$i]['title']         = 
$this->db->f(2);
+                               $projects[$i]['direct']        = 
$this->db->f(4);
+                               $projects[$i]['pnumber']       = 
$this->db->f(5);
+                               $projects[$i]['enddate']       = 
$this->db->f(6);
+                               $projects[$i]['customer_org']  = 
$this->db->f('customer_org');
+
+                               if($this->db->f(9) > 0)
+                               {
+                                       $projects[$i]['budget_factor'] = 
$this->db->f(9);
+                               }
+                               else
+                               {
+                                       $projects[$i]['budget_factor'] = 
$this->db->f(10) / 8;
+                               }
+                               if($this->db->f(7) > 0)
+                               {
+                                       $projects[$i]['budget'] = 
$this->db->f(7) * $projects[$i]['budget_factor'] / 60;
+                               }
+                               else
+                               {
+                                       $projects[$i]['budget'] = 
$this->db->f(8);
+                               }
+                               ++$i;
+                       }
+
+                       $this->tmp = $projects;
+                       for($i = 0; $i < count($projects); ++$i)
+                       {
+                               $presort = $projects[$i]['direct'] == 'Y' ? '1' 
: '2';
+                               //echo 
$presort.'.'.$this->get_tree_index($projects[$i]['id'], 
$projects[$i]['parent'])."<br>";
+                               $index = 
$this->get_tree_index($projects[$i]['id'], $projects[$i]['parent']);
+                               $indexparts = explode('.', $index);
+
+                               if(!$mainProject || array_search((int) 
$mainProject, $indexparts) !== FALSE)
+                               {
+                                       $projectstree[$presort.'.'.$index] = 
$projects[$i];
+                               }
+                       }
+                       ksort($projectstree);
+                       return $projectstree;
+               }
+
+               function get_tree_index($id, $parent)
+               {
+                       if($parent)
+                       {
+                               for($i = 0; $i < count($this->tmp); ++$i)
+                               {
+                                       if($this->tmp[$i]['id'] == $parent)
+                                       {
+                                               $parentparent = 
$this->tmp[$i]['parent'];
+                                               $i = count($this->tmp);
+                                       }
+                               }
+                               $id = $this->get_tree_index($parent, 
$parentparent).'.'.$id;
+                       }
+                       return $id;
+               }
+
+               /**
+               * Get cost unit numbers for active projects in given month
+               *
+               * @param integer $month Month for which to get the projects
+               * @param integer $year Year for which to get the projects
+               * @return array List of active projects
+               */
+               function get_active_projects($month,$year)
+               {
+                       $this->db->query('select distinct p_number from 
phpgw_p_projects,phpgw_p_hours where phpgw_p_projects.project_id = 
phpgw_p_hours.pro_main and phpgw_p_hours.start_date >= ' . 
mktime(0,0,0,$month,1,$year) . ' and phpgw_p_hours.start_date <= ' . 
mktime(23,59,59,$month,cal_days_in_month(CAL_GREGORIAN,$month,$year),$year) . ' 
order by p_number asc', __LINE__,__FILE__);
+                       $result = array();
+                       while ($this->db->next_record())
+                       {
+                               $result[] = $this->db->f('p_number');
+                       }
+                       return($result);
+               }
+
+               /**
+               * Get hours for a given project in a specified month
+               *
+               * @param integer $month Month for which to get the project hours
+               * @param integer $year Year for which to get the project hours
+               * @return array Project hours for different "credit cost 
centres"
+               * divided inot project hours and travel hours. 
$result[$cost_centre]['project'];
+               * $result[$cost_centre]['travel']
+               */
+               function get_project_hours($month,$year)
+               {
+                       $this->db->query("select 
p_number,employee,cost_centre,sum(minutes),sum(t_journey) from phpgw_p_projects 
join phpgw_p_hours on phpgw_p_projects.project_id = phpgw_p_hours.pro_main join 
(select distinct account_id,cost_centre from phpgw_p_projectmembers where 
type='accounting' and ((sdate = 0) or (sdate <= " . 
mktime(0,0,0,$month,1,$year) . ")) and ((edate = 0) or (edate >= " . 
mktime(23,59,59,$month,cal_days_in_month(CAL_GREGORIAN,$month,$year),$year) . 
"))) as pmembers on phpgw_p_hours.employee = pmembers.account_id where 
phpgw_p_hours.start_date >= " . mktime(0,0,0,$month,1,$year) . " and  
phpgw_p_hours.start_date <= " . 
mktime(23,59,59,$month,cal_days_in_month(CAL_GREGORIAN,$month,$year),$year) . " 
group by employee,cost_centre,p_number order by p_number,employee,cost_centre", 
__LINE__,__FILE__);
+                       $result = array();
+                       $i = 0;
+                       while ($this->db->next_record())
+                       {
+                               $result[$i]['p_number'] = 
$this->db->f('p_number');
+                               
$GLOBALS['phpgw']->accounts->get_account_name($this->db->f('employee'),$lid,$fname,$lname);
+                               $result[$i]['employee'] = 
$GLOBALS['phpgw']->common->display_fullname($lid,$fname,$lname);
+                               $result[$i]['cost_centre'] = 
$this->db->f('cost_centre');
+                               $result[$i]['minutes'] = 
$this->db->f('sum(minutes)') / 60;
+                               $result[$i]['journey'] = 
$this->db->f('sum(t_journey)') / 60;
+                               ++$i;
                        }
-                       return $items;
+                       return($result);
+               }
+
+               function get_acl_project_members($project_id = false)
+               {
+                       $sql  = 'SELECT * FROM phpgw_acl ';
+                       $sql .= 'WHERE acl_appname LIKE \'project_members\' ';
+
+                       if($project_id)
+                       { // project members of a project
+                               $sql .= 'AND acl_location = 
'.intval($project_id).' ';
+                       }
+
+                       $sql .= 'ORDER BY acl_account';
+
+                       $this->db->query($sql ,__LINE__,__FILE__);
+
+                       if ($this->db->num_rows() == 0)
+                       {
+                               return false;
+                       }
+
+                       $members = array();
+                       while ($this->db->next_record())
+                       {
+                               $account_id = $this->db->f('acl_account');
+                               $members[$account_id][] = 
$this->db->f('acl_location');
+                       }
+
+                       return $members;
                }
+
        }
 ?>

====================================================
Index: projects/inc/class.soprojecthours.inc.php
diff -u projects/inc/class.soprojecthours.inc.php:1.38 
projects/inc/class.soprojecthours.inc.php:1.39
--- projects/inc/class.soprojecthours.inc.php:1.38      Sun Jun 27 20:06:30 2004
+++ projects/inc/class.soprojecthours.inc.php   Mon Mar 14 17:39:39 2005
@@ -29,19 +29,21 @@
        class soprojecthours
        {
                var $db;
-               var $grants;
+               var $db2;
+               var $account;

                function soprojecthours()
                {
-                       $this->db               = $GLOBALS['phpgw']->db;
-                       $this->db2              = $this->db;
-                       $this->account  = 
$GLOBALS['phpgw_info']['user']['account_id'];
+                       $this->db                       = $GLOBALS['phpgw']->db;
+                       $this->db2                      = $this->db;
+                       $this->account          = 
$GLOBALS['phpgw_info']['user']['account_id'];
                        $this->column_array = array();
                }

                function db2hours($column = False)
                {
                        $i = 0;
+                       $hours = array();
                        while ($this->db->next_record())
                        {
                                if($column)
@@ -72,6 +74,7 @@
                                                'billable'              => 
$this->db->f('billable'),
                                                'km_distance'   => 
$this->db->f('km_distance'),
                                                't_journey'             => 
$this->db->f('t_journey'),
+                                               'booked'                => 
$this->db->f('booked'),
                                                'surcharge'             => 
$this->db->f('surcharge')
                                        );
                                }
@@ -80,17 +83,32 @@
                }

                function read_hours($values)
-               {
-                       $start                  = intval($values['start']);
-                       $limit                  = $values['limit']?True:False;
-                       $filter                 = 
$values['filter']?$values['filter']:'none';
-                       $sort                   = 
$values['sort']?$values['sort']:'ASC';
-                       $order                  = 
$values['order']?$values['order']:'start_date';
-                       $status                 = 
$values['status']?$values['status']:'all';
-                       $project_id             = intval($values['project_id']);
-                       $query                  = 
$this->db->db_addslashes($values['query']);
-                       $column                 = 
(isset($values['column'])?$values['column']:False);
-                       $parent_select  = 
isset($values['parent_select'])?True:False;
+               {
+                       $start         = intval($values['start']);
+                       $limit         = 
$values['limit']?$values['limit']:false;
+                       $filter        = 
$values['filter']?$values['filter']:'none';
+                       $sort          = $values['sort']?$values['sort']:'ASC';
+                       $order         = 
$values['order']?$values['order']:'start_date';
+                       $status        = 
$values['status']?$values['status']:'all';
+                       $project_id        = intval($values['project_id']);
+                       $query         = 
$this->db->db_addslashes($values['query']);
+                       $column        = 
(isset($values['column'])?$values['column'] : false);
+                       $parent_select = isset($values['parent_select']) ? true 
: false;
+                       $period_start  = isset($values['period_start']) ? 
intval($values['period_start']) : 0;
+                       $period_end    = isset($values['period_end']) ? 
intval($values['period_end']) : 0;
+
+                       if(isset($values['employee']))
+                       {
+                               $employee = $values['employee'];
+                       }
+                       elseif(isset($this->employee))
+                       {
+                               $employee = $this->employee;
+                       }
+                       else
+                       {
+                               $employee = $this->account;
+                       }

                        //_debug_array($values);

@@ -103,20 +121,38 @@
                                $filtermethod .= " AND status='$status'";
                        }

-                       if ($filter == 'yours')
+                       switch ($filter)
                        {
-                               $filtermethod .= ' AND employee=' . 
$this->account;
+                               case 'yours':
+                                       $filtermethod .= ' AND employee=' . 
$this->account;
+                               break;
+                               case 'employee':
+                                       $filtermethod .= ' AND employee=' . 
$employee; //dirty hack - filter should be more flexible: filter[field] and 
filter[value]
+                               break;
                        }

                        if ($query)
                        {
                                $querymethod = " AND (remark like '%$query%' OR 
minutes like '%$query%' OR hours_descr like '%$query%')";
                        }
+                       else
+                       {
+                               $querymethod = "";
+                       }
+
+                       if($period_end - $period_start > 0 )
+                       {
+                               $sqlperiod = " AND start_date < $period_end AND 
start_date > $period_start ";
+                       }
+                       else
+                       {
+                               $sqlperiod = "";
+                       }

                        $column_select = ((is_string($column) && $column != 
'')?$column:'*');
                        $this->column_array = explode(',',$column);

-                       $sql = "SELECT $column_select FROM phpgw_p_hours WHERE 
$filtermethod $querymethod";
+                       $sql = "SELECT $column_select FROM phpgw_p_hours WHERE 
$filtermethod $querymethod $sqlperiod";

                        if($limit)
                        {
@@ -128,7 +164,7 @@
                        {
                                $this->db->query($sql . 
$ordermethod,__LINE__,__FILE__);
                        }
-                       //echo $sql;
+                       //echo '<pre>'.$sql.$ordermethod.'</pre>';
                        return $this->db2hours();
                }

@@ -145,14 +181,14 @@
                        $values['hours_descr']  = 
$this->db->db_addslashes($values['hours_descr']);
                        $values['remark']               = 
$this->db->db_addslashes($values['remark']);
                        $values['km_distance']  = $values['km_distance'] + 0.0;
-                       $values['t_journey']    = $values['t_journey'] + 0.0;
+                       $values['t_journey']    = intval($values['t_journey']);

                        $this->db->query('INSERT into phpgw_p_hours 
(project_id,activity_id,entry_date,start_date,end_date,hours_descr,remark,billable,minutes,'
-                                                       . 
'status,employee,pro_parent,pro_main,km_distance,t_journey,surcharge) VALUES (' 
. intval($values['project_id']) . ','
+                                                       . 
'status,employee,pro_parent,pro_main,km_distance,t_journey,surcharge,booked) 
VALUES (' . intval($values['project_id']) . ','
                                                        . 
intval($values['activity_id']) . ',' . time() . ',' . intval($values['sdate']) 
. ',' . intval($values['edate']) . ",'"
                                                        . 
$values['hours_descr'] . "','" . $values['remark'] . "','" . 
(isset($values['billable'])?'N':'Y') . "'," . intval($values['w_minutes'])
                                                        . ",'" . 
$values['status'] . "'," . intval($values['employee']) . ',' . 
intval($values['pro_parent']) . ',' . intval($values['pro_main'])
-                                                       . ',' . 
$values['km_distance'] . ',' . $values['t_journey'] . ',' . 
intval($values['surcharge']) . ')',__LINE__,__FILE__);
+                                                       . ',' . 
$values['km_distance'] . ',' . $values['t_journey'] . ',' . 
intval($values['surcharge']) . ',"N")',__LINE__,__FILE__);
                }

                function edit_hours($values)
@@ -207,13 +243,17 @@
                        {
                                $wh = array
                                (
-                                       'whours_formatted'      => 
floor($minutes/60),
-                                       'wmin_formatted'        => 
($minutes-(floor($minutes/60)*60)),
+                                       'whours_formatted'      => 
intval($minutes/60),
+                                       'wmin_formatted'        => abs( 
$minutes- ( (int)($minutes / 60) *60 ) ),
                                        'wminutes'                      => 
$minutes
-                                       //'whwm'                                
=> floor($minutes/60) . ':' . ($minutes-(floor($minutes/60)*60))
                                );
-                               $wh['wmin_formatted'] = 
$wh['wmin_formatted']<=9?'0' . $wh['wmin_formatted']:$wh['wmin_formatted'];
-                               $wh['whwm']     = $wh['whours_formatted'] . '.' 
. (($wh['wmin_formatted']==0)?'00':$wh['wmin_formatted']);
+
+                               if((0 < abs($wh['wmin_formatted'])) && 
(abs($wh['wmin_formatted']) <= 9))
+                               {
+                                       $wh['wmin_formatted']   = '0' . 
abs($wh['wmin_formatted']);
+                               }
+
+                               $wh['whwm']     = $wh['whours_formatted'] . '.' 
. $wh['wmin_formatted'];
                        }
                        else
                        {
@@ -222,11 +262,17 @@
                                        'whours_formatted'      => 0,
                                        'wmin_formatted'        => 0,
                                        'wminutes'                      => 0,
-                                       'whwm'                          => 0
+                                       'whwm'                          => 0.0
                                );
                        }
                        return $wh;
                }
+
+               function min2time($string)
+               {
+                       $time = ((int)($string / 60)) . ':' . (($string % 60) 
== '0' ? '00' : sprintf("%02d",($string % 60)));
+                       return $time;
+               }

                function calculate_activity_budget($params = 0)
                {
@@ -343,10 +389,10 @@
                        $hours                  = 
isset($params['hours'])?$params['hours']:True;
                        $action                 = 
$params['action']?$params['action']:'subs';

-                       $columns = 'id,minutes,billable,surcharge,employee';
+                       $columns = 
'id,minutes,t_journey,billable,surcharge,employee';
                        $this->column_array = explode(',',$columns);

-                       $sql = 'SELECT id,minutes,billable,surcharge,employee 
from phpgw_p_hours where ' . "status='done' and";
+                       $sql = 'SELECT 
id,minutes,t_journey,billable,surcharge,employee from phpgw_p_hours where ' . 
"status='done' and";

                        switch($action)
                        {
@@ -469,7 +515,8 @@
                                        'remark'                => 
$this->db->f('remark'),
                                        'km_distance'   => 
$this->db->f('km_distance'),
                                        't_journey'             => 
$this->db->f('t_journey'),
-                                       'surcharge'             => 
$this->db->f('surcharge')
+                                       'surcharge'             => 
$this->db->f('surcharge'),
+                                       'billable'              => 
$this->db->f('billable')
                                );
                        }
                        return $track;
@@ -494,9 +541,9 @@
                function format_ttime($diff)
                {
                        $tdiff = array();
-                       $tdiff['days'] = floor($diff/60/60/24);
+                       $tdiff['days'] = intval($diff/60/60/24);
                        $diff -= $tdiff['days']*60*60*24;
-                       $tdiff['hrs'] = floor($diff/60/60);
+                       $tdiff['hrs'] = intval($diff/60/60);
                        $diff -= $tdiff['hrs']*60*60;
                        $tdiff['mins'] = round($diff/60);
                        //$diff -= $minsDiff*60;
@@ -517,15 +564,17 @@
                        return $this->db->f('max');
                }

-               function check_ttracker($project_id = '',$status='active')
+               function check_ttracker($params)
                {
-                       $track_id = $this->get_max_track($project_id);
+                       $project_id     = intval($params['project_id']);
+                       $track_id       = $this->get_max_track($project_id);
+                       $status         = 
$params['status']?$params['status']:'active';
                        //echo 'MAX: ' . $track_id;

                        switch($status)
                        {
                                case 'active':          $status_select = " and 
(status='start' or status='continue') and end_date = 0"; break;
-                               case 'inactive':        $status_select = " and 
status='stop'"; break;
+                               case 'inactive':        $status_select = " and 
(status='stop' or status='pause')"; break;
                        }
                        $this->db->query('SELECT minutes from phpgw_p_ttracker 
where track_id=' . intval($track_id) . $status_select,__LINE__,__FILE__);
                        if($this->db->next_record())
@@ -536,20 +585,30 @@
                }

                function ttracker($values)
-               {
+               {
                        $values['hours_descr']  = 
$this->db->db_addslashes($values['hours_descr']);
                        $values['remark']               = 
$this->db->db_addslashes($values['remark']);
                        $values['km_distance']  = $values['km_distance'] + 0.0;
-                       $values['t_journey']    = $values['t_journey'] + 0.0;
+                       $values['t_journey']    = intval($values['t_journey']);
+                       $values['surcharge']    = intval($values['surcharge']);
                        $project_id                             = 
intval($values['project_id']);

+                       if(!isset($values['billable']))
+                       {
+                               $values['billable'] = 
$this->return_value('billable', $project_id);
+                       }
+                       elseif(($values['billable'] != 'N') && 
($values['billable'] != 'Y'))
+                       {
+                               $values['billable'] = 'Y';
+                       }
+
                        //_debug_array($values);

                        switch($values['action'])
                        {
                                case 'start':
                                case 'continue':
-                                       $this->db2->query('SELECT 
track_id,start_date,project_id from phpgw_p_ttracker where employee=' . 
$this->account . ' and project_id !=' . $project_id
+                               $this->db2->query('SELECT 
track_id,start_date,project_id,hours_descr from phpgw_p_ttracker where 
employee=' . $this->account . ' and project_id !=' . $project_id
                                                                        . " and 
(status='start' or status='continue') and minutes=0",__LINE__,__FILE__);
                                        while($this->db2->next_record())
                                        {
@@ -558,11 +617,10 @@
                                                $this->db->query('UPDATE 
phpgw_p_ttracker set end_date=' . time() . ',minutes=' . $work_time . ' where 
track_id='
                                                                                
. $this->db2->f('track_id'),__LINE__,__FILE__);

-
-                                               $this->db->query('INSERT into 
phpgw_p_ttracker 
(project_id,activity_id,start_date,end_date,employee,status,hours_descr,remark) 
'
-                                                                               
.' values(' . $this->db2->f('project_id') . ',0,' . time() . ',0,' . 
$this->account
-                                                                               
. ",'pause','pause','')",__LINE__,__FILE__);
-                                       };
+                                               $this->db->query('INSERT into 
phpgw_p_ttracker 
(project_id,activity_id,start_date,end_date,employee,status,hours_descr,remark,billable)
 '
+                                                                               
.' values(' . $this->db2->f('project_id') . ',0,' . time() . ',0,' . 
$this->account . ",'pause','"
+                                                                               
. $this->db2->f('hours_descr') . "','','" . $values['billable'] . "')", 
__LINE__,__FILE__);
+                                       }
                                        break;
                        }

@@ -575,18 +633,22 @@
                                        $max = 
intval($this->get_max_track($project_id));
                                        $this->db->query('UPDATE 
phpgw_p_ttracker set end_date=' . time() . ' where track_id=' . 
$max,__LINE__,__FILE__);

-                                       $this->db->query('SELECT 
start_date,end_date from phpgw_p_ttracker where track_id=' . 
$max,__LINE__,__FILE__);
+                                       $this->db->query('SELECT 
start_date,end_date,hours_descr from phpgw_p_ttracker where track_id=' . 
$max,__LINE__,__FILE__);
                                        $this->db->next_record();
                                        $sdate = $this->db->f('start_date');
                                        $edate = $this->db->f('end_date');
-                                       $wtime = $this->format_ttime($edate - 
$sdate);
-                                       $work_time = 
($wtime['hrs']*60)+$wtime['mins'];
+
+                                       $wtime          = 
$this->format_ttime($edate - $sdate);
+                                       $work_time      = 
($wtime['hrs']*60)+$wtime['mins'];
+
+                                       $descr                  = 
$this->db->f('hours_descr');
+                                       $hours_descr    = 
$descr?$descr:$values['hours_descr'];

                                        $this->db->query('UPDATE 
phpgw_p_ttracker set minutes=' . $work_time . ' where track_id=' . 
$max,__LINE__,__FILE__);

-                                       $this->db->query('INSERT into 
phpgw_p_ttracker 
(project_id,activity_id,start_date,end_date,employee,status,hours_descr,remark) 
'
+                                       $this->db->query('INSERT into 
phpgw_p_ttracker 
(project_id,activity_id,start_date,end_date,employee,status,hours_descr,remark,billable)
 '
                                                                                
.' values(' . $project_id . ',' . intval($values['activity_id']) . ',' . time() 
. ',0,' . $this->account . ",'" . $values['action']
-                                                                               
. "','" . ($values['hours_descr']?$values['hours_descr']:$values['action']) . 
"','" . $values['remark'] . "')",__LINE__,__FILE__);
+                                                                               
. "','" . $hours_descr . "','" . $values['remark'] . "','" . 
$values['billable'] ."')",__LINE__,__FILE__);

                                        if($values['action'] == 'stop')
                                        {
@@ -596,44 +658,42 @@
                                case 'edit':
                                        $this->db->query('UPDATE 
phpgw_p_ttracker set activity_id=' . intval($values['activity_id']) . 
',start_date=' . intval($values['sdate']) . ',end_date='
                                                                        . 
intval($values['edate']) . ',minutes=' . intval($values['w_minutes']) . ", 
hours_descr='" . $values['hours_descr'] . "',remark='"
-                                                                       . 
$values['remark'] . "' where track_id=" . 
intval($values['track_id']),__LINE__,__FILE__);
+                                                                       . 
$values['remark'] . "', t_journey=" . $values['t_journey'] . ', km_distance=' . 
$values['km_distance'] . ', surcharge='
+                                                                       . 
$values['surcharge'] . ' where track_id=' . 
intval($values['track_id']),__LINE__,__FILE__);
                                        break;
                        }

-                       switch($values['action'])
+                       if($values['action'] == 'apply')
                        {
-                               //case 'start':
-                               case 'apply':
                                        $this->db->query('INSERT into 
phpgw_p_ttracker 
(project_id,activity_id,employee,start_date,end_date,minutes,hours_descr,status,'
-                                                                       
.'remark,t_journey,km_distance,stopped,surcharge) values(' . $project_id . ',' 
. intval($values['activity_id'])
-                                                                       . ',' . 
$this->account . ',' . intval($values['sdate']) . ',' . 
intval($values['sdate']) . ','
+                                                                       
.'remark,t_journey,km_distance,stopped,surcharge,billable) values(' . 
$project_id . ',' . intval($values['activity_id'])
+                                                                       . ',' . 
$this->account . ',' . intval($values['sdate']) . ',' . 
intval($values['edate']) . ','
                                                                        . 
intval($values['w_minutes']) . ",'" . $values['hours_descr'] . "','" . 
$values['action'] . "','" . $values['remark']
-                                                                       . "'," 
. $values['t_journey'] . ',' . $values['km_distance'] . ",'Y'," . 
intval($values['surcharge']) . ')',__LINE__,__FILE__);
+                                                                       . "'," 
. $values['t_journey'] . ',' . $values['km_distance'] . ",'Y'," . 
$values['surcharge'] . ",'" . $values['billable'] . "')", __LINE__,__FILE__);

                                        //return 
$this->db->get_last_insert_id('phpgw_p_ttracker','track_id');
-                                       break;
                        }
                }

                function save_ttracker()
                {
-                       $this->db->query("SELECT * from phpgw_p_ttracker where 
status !='pause' and status != 'stop' and end_date > 0 and minutes > 0 and 
stopped='Y' and employee="
+                       $this->db->query("SELECT * from phpgw_p_ttracker where 
status != 'pause' and status != 'stop' and end_date > 0 and minutes > 0 and 
stopped='Y' and employee="
                                                        . 
$this->account,__LINE__,__FILE__);
                        $hours = $this->db2track();

-                       while(is_array($hours) && list(,$hour) = each($hours))
+                       while(is_array($hours) && (list($no_use,$hour) = 
each($hours)))
                        {
-                               $hour['pro_parent']             = 
$this->return_value('pro_parent',$hour['project_id']);
-                               $hour['pro_main']               = 
$this->return_value('pro_main',$hour['project_id']);
-                               $hour['km_distance']    = $hour['km_distance'] 
+ 0.0;
-                               $hour['t_journey']              = 
$hour['t_journey'] + 0.0;
+                               $hour['pro_parent']  = 
$this->return_value('pro_parent',$hour['project_id']);
+                               $hour['pro_main']          = 
$this->return_value('pro_main',$hour['project_id']);
+                               $hour['km_distance'] = $hour['km_distance'] + 
0.0;
+                               $hour['t_journey']   = 
intval($hour['t_journey']);

                                $this->db->query('INSERT into phpgw_p_hours 
(project_id,activity_id,entry_date,start_date,end_date,hours_descr,remark,minutes,'
-                                                       . 
'status,employee,pro_parent,pro_main,billable,t_journey,km_distance,surcharge) 
VALUES (' . intval($hour['project_id']) . ','
+                                                       . 
'status,employee,pro_parent,pro_main,billable,t_journey,km_distance,surcharge,booked)
 VALUES (' . intval($hour['project_id']) . ','
                                                        . 
intval($hour['activity_id']) . ',' . time() . ',' . intval($hour['sdate']) . 
',' . intval($hour['edate']) . ",'"
                                                        . $hour['hours_descr'] 
. "','" . $hour['remark'] . "'," . intval($hour['minutes']) . ",'done'," . 
intval($hour['employee'])
-                                                       . ',' . 
intval($hour['pro_parent']) . ',' . intval($hour['pro_main']) . ",'Y'," . 
$hour['t_journey'] . ','
-                                                       . $hour['km_distance'] 
. ',' . intval($values['surcharge']) . ')',__LINE__,__FILE__);
+                                                       . ',' . 
intval($hour['pro_parent']) . ',' . intval($hour['pro_main']) . 
",'".$hour['billable']."'," . $hour['t_journey'] . ','
+                                                       . $hour['km_distance'] 
. ',' . intval($hour['surcharge']) .',"N"' . ')',__LINE__,__FILE__);

                                $this->db->query('DELETE from phpgw_p_ttracker 
where track_id=' . intval($hour['track_id']),__LINE__,__FILE__);
                        }
@@ -646,6 +706,7 @@
                        {
                                case 'pro_main':        $column = 'main'; break;
                                case 'pro_parent':      $column = 'parent'; 
break;
+                               case 'billable':        $column = 'billable'; 
break;
                        }

                        $this->db->query("SELECT $column from phpgw_p_projects 
where project_id=$pro_id",__LINE__,__FILE__);
@@ -654,5 +715,63 @@
                                return 
$GLOBALS['phpgw']->strip_html($this->db->f($column));
                        }
                }
+
+               function unbook_hours()
+               {
+                       $hours_id       = 
get_var('hours_id',array('POST','GET'));
+                       $this->db->query("UPDATE phpgw_p_hours SET booked='N' 
where id='$hours_id'",__LINE__,__FILE__);
+               }
+
+               function set_booked($values)
+               {
+                       $this->db->query('UPDATE phpgw_p_hours SET booked="Y" 
where (start_date <= ' . $values['edate'] . ')',__LINE__,__FILE__);
+               }
+
+               function get_dayhours($employee, $start_date, $end_date)
+               {
+                       // Nice SQL-Statement Kai
+                       $sql  = 'SELECT 
UNIX_TIMESTAMP(FROM_UNIXTIME(start_date,"%Y%m%d")) as day, project_id, 
sum(minutes) + sum(t_journey) ';
+                       $sql .= 'FROM phpgw_p_hours ';
+                       $sql .= 'WHERE employee='.(int)$employee.' AND 
start_date >= '.(int)$start_date.' AND start_date <= '.((int)$end_date + 
86400).' ';
+                       $sql .= 'GROUP BY project_id, day ';
+                       $sql .= 'ORDER BY day, project_id';
+                       //echo $sql;
+                       $this->db->query($sql);
+                       return $this->db;
+               }
+
+               function get_emp_worktimes($employee, $start_date=0, 
$end_date=0)
+               {
+                       $sql  = 'SELECT phpgw_p_hours.project_id AS project_id, 
';
+                       $sql .= '       SUM(minutes) AS sum_minutes_worktime, ';
+                       $sql .= '       SUM(t_journey) AS sum_minutes_journey, 
';
+                       $sql .= '       SUM(minutes+t_journey) AS 
sum_minutes_all ';
+                       $sql .= 'FROM phpgw_p_hours, phpgw_p_projects ';
+                       $sql .= 'WHERE phpgw_p_hours.start_date >= 
'.(int)$start_date.' AND phpgw_p_hours.start_date <= '.((int)$end_date + 
86400).' ';
+                       $sql .= 'AND employee='.(int)$employee.' ';
+                       $sql .= 'AND phpgw_p_hours.project_id = 
phpgw_p_projects.project_id ';
+                       $sql .= 'GROUP BY phpgw_p_hours.project_id ';
+
+                       //echo $sql;
+                       $this->db->query($sql);
+                       return $this->db;
+               }
+
+               function min2str($min)
+               {
+                       return sprintf('%s%d:%02d', $min<0?'-':'', 
abs($min)/60, abs($min)%60);
+               }
+
+               function str2min($s)
+               {
+                       if (ereg('(-?)([0-9]+):([0-9][0-9])', $s, $h))
+                       {
+                               return $h[1].($h[2]*60+$h[3]);
+                       }
+                       else
+                       {
+                               return(0);
+                       }
+               }
        }
 ?>

====================================================
Index: projects/inc/class.attached_files.inc.php
diff -u projects/inc/class.attached_files.inc.php:1.1 
projects/inc/class.attached_files.inc.php:1.2
--- projects/inc/class.attached_files.inc.php:1.1       Wed Aug 11 15:05:13 2004
+++ projects/inc/class.attached_files.inc.php   Mon Mar 14 17:39:39 2005
@@ -42,8 +42,9 @@
                function attached_files()
                {
                        $this->file                     = $_REQUEST['file'];
-                       $this->project_id       = $_REQUEST['project_id'];
-                       $this->vfs                      = 
CreateObject('phpgwapi.vfs');
+                       $this->project_id       = $_REQUEST['project_id'];
+                       $this->vfs                      = 
CreateObject('phpgwapi.vfs');
+                       $this->vfs->override_acl = True;
                }

                function show_file()
@@ -62,7 +63,7 @@
                        }
                        elseif ($GLOBALS['settings']['viewtextplain'])
                        {
-                               $mime_type = 'text/plain';
+                               $mime_type = 'application/octet-stream;';
                        }
                        $filename = basename($this->file);
                        header('Content-type: ' . $mime_type);
@@ -160,7 +161,7 @@
                                ++$x;
                        }

-                       for($i=0;$i <= $x-1;$i++)
+                       for($i=0; $i<=$x-1; $i++)
                        {
                                $file = 
$GLOBALS['phpgw']->link('/index.php',array
                                                                                
                                        (
@@ -182,5 +183,10 @@
                        }
                        return ($attLink);
                }
+
+               function file_exists($data)
+               {
+                       return $this->vfs->file_exists($data);
+               }
        }
 ?>

====================================================
Index: projects/inc/class.boconfig.inc.php
diff -u projects/inc/class.boconfig.inc.php:1.20 
projects/inc/class.boconfig.inc.php:1.21
--- projects/inc/class.boconfig.inc.php:1.20    Wed Aug 11 15:05:13 2004
+++ projects/inc/class.boconfig.inc.php Mon Mar 14 17:39:39 2005
@@ -38,10 +38,10 @@

                var $public_functions = array
                (
-                       'save_prefs'                            => True,
-                       'selected_employees'            => True,
-                       'read_accounting_factors'       => True,
-                       'save_accounting_factor'        => True,
+                       'save_prefs'              => True,
+                       'selected_employees'      => True,
+                       'read_accounting_factors' => True,
+                       'save_accounting_factor'  => True,
                        'read_admins'                           => True,
                        'list_admins'                           => True,
                        'selected_admins'                       => True,
@@ -59,28 +59,41 @@

                function boconfig()
                {
-                       $action                         = 
get_var('action',array('GET'));
-                       $this->debug            = False;
+                       $action           = get_var('action',array('GET'));
+                       $this->debug      = false;
                        $this->boprojects       = 
CreateObject('projects.boprojects',True,$action);
-                       $this->soconfig         = $this->boprojects->soconfig;
-                       $this->start            = $this->boprojects->start;
-                       $this->query            = $this->boprojects->query;
-                       $this->filter           = $this->boprojects->filter;
-                       $this->order            = $this->boprojects->order;
-                       $this->sort                     = 
$this->boprojects->sort;
-                       $this->cat_id           = $this->boprojects->cat_id;
+                       $this->soconfig   = $this->boprojects->soconfig;
+                       $this->start      = $this->boprojects->start;
+                       $this->query      = $this->boprojects->query;
+                       $this->filter     = $this->boprojects->filter;
+                       $this->order      = $this->boprojects->order;
+                       $this->sort       = $this->boprojects->sort;
+                       $this->cat_id     = $this->boprojects->cat_id;
                }

                function save_prefs($prefs)
                {
                        $GLOBALS['phpgw']->preferences->read_repository();

-                       if (is_array($prefs))
+                       if(!is_array($prefs['cols']))
                        {
-                               
$GLOBALS['phpgw']->preferences->change('projects','columns',implode(',',$prefs['cols']));
-                               
$GLOBALS['phpgw']->preferences->change('projects','mainscreen_showevents',$prefs['mainscreen_showevents']);
-                               
$GLOBALS['phpgw']->preferences->save_repository(True);
+                               $prefs['cols'] = array();
                        }
+                       if(!is_array($prefs['cscols']))
+                       {
+                               $prefs['cscols'] = array();
+                       }
+                       if(!is_array($prefs['mail_type']))
+                       {
+                               $prefs['mail_type'] = array();
+                       }
+
+                       
$GLOBALS['phpgw']->preferences->change('projects','columns',implode(',',$prefs['cols']));
+                       
$GLOBALS['phpgw']->preferences->change('projects','cscolumns',implode(',',$prefs['cscols']));
+                       
$GLOBALS['phpgw']->preferences->change('projects','mailTypeEntries',implode(',',$prefs['mail_type']));
+                       
$GLOBALS['phpgw']->preferences->change('projects','mainscreen_showevents',$prefs['mainscreen_showevents']);
+
+                       $GLOBALS['phpgw']->preferences->save_repository(True);
                }

                function selected_employees()
@@ -127,17 +140,35 @@
                                                'account_name'          => 
$GLOBALS['phpgw']->common->grab_owner_name($emp['account_id']),
                                                'accounting'            => 
$emp['accounting'],
                                                'd_accounting'          => 
$emp['d_accounting'],
+                                               'weekly_workhours'      => 
$emp['weekly_workhours'],
+                                               'cost_centre'           => 
$emp['cost_centre'],
                                                'sdate'                         
=> $emp['sdate'],
                                                'edate'                         
=> $emp['edate'],
                                                'sdate_formatted'       => 
$sdate['date_formatted'],
                                                'edate_formatted'       => 
$edate['date_formatted']
                                        );
                                }
-                               asort($emps);
-                               reset($emps);
+
+                               if(!$this->order || $this->order == 
'account_id')
+                               {
+                                       if(is_array($emps))
+                                       {
+                                               usort($emps, array("boconfig", 
"cmp_account_name"));
+                                               if($this->sort == 'DESC')
+                                               {
+                                                       $emps = 
array_reverse($emps);
+                                               }
+                                       }
+                               }
+
                                return $emps;
                        }
-                       return False;
+                       return false;
+               }
+
+               function cmp_account_name($a, $b)
+               {
+                       return strcasecmp($a['account_name'], 
$b['account_name']);
                }

                function save_accounting_factor($values)
@@ -303,6 +334,14 @@
                                                        }
                                                }
                                        }
+                                       if 
(!is_numeric($values['weekly_workhours']))
+                                       {
+                                               $error[] = lang('please set the 
weekly workhours');
+                                       }
+                                       if (!is_numeric($values['cost_centre']))
+                                       {
+                                               $error[] = lang('please set the 
cost centre');
+                                       }
                                        break;
                                default:
                                        if (strlen($values['descr']) > 250)
@@ -413,5 +452,293 @@
                {
                        $this->soconfig->save_surcharge($values);
                }
+
+               function config_proid_help_msg($params)
+               {
+                       switch($params['action'])
+                       {
+                               case 'get':
+                                       $config = 
$this->soconfig->get_site_config(array('helpmsg' => True,'default' => False));
+                                       return $config['proid_help_msg'];
+                                       break;
+                               case 'save':
+                                       $config = 
CreateObject('phpgwapi.config','projects');
+                                       $config->read_repository();
+                                       
$config->value('proid_help_msg',$params['proid_help_msg']);
+                                       $config->save_repository();
+                                       break;
+                       }
+               }
+
+               /**
+               * Configure the worktime statusmail. The method can used for 
get and set the configuration (mail_type => (off | weekly | monthly).
+               * @param array $values contains the action (get or set) and the 
value set by the user
+               * @return mixed array when get the configuration; boolean if 
set the configuration: True if config was saved, otherwise false
+               */
+               function config_worktime_statusmail($values)
+               {
+                       if(!isset($values['action']))
+                       {
+                               return False;
+                       }
+
+                       $config = CreateObject('phpgwapi.config','projects');
+                       $config->read_repository();
+
+                       switch($values['action'])
+                       {
+                               case 'get':
+                                       
if(isset($config->config_data['worktime_statusmail']))
+                                               $mail_type = 
$config->config_data['worktime_statusmail'];
+                                       else
+                                               $mail_type = 'off';
+
+                                       return $mail_type;
+                               break;
+                               case 'save':
+                                       if(!isset($values['mail_type']))
+                                               return false;
+
+                                       switch($values['mail_type'])
+                                       {
+                                               case 'off':
+                                                       $mail_type = 'off';
+                                                       $start     = 0;
+                                               break;
+                                               case 'weekly':
+                                                       $mail_type = 'weekly';
+                                                       $dow_1 = date('d') - 
date('w') + 1;
+                                                       if (date('w') == 0)
+                                                               $dow_1 = $dow_1 
- 7;
+                                                       $start = 
mktime(0,0,0,date('m'),$dow_1,date('Y'));
+                                               break;
+                                               case 'monthly':
+                                                       $mail_type = 'monthly';
+                                                       $start = 
mktime(0,0,0,date('m'),1,date('Y'));
+                                               break;
+                                               default:
+                                                       return false;
+                                               break;
+                                       }
+
+                                       $config->value('worktime_statusmail', 
$mail_type);
+                                       $config->save_repository();
+
+                                       // set async service
+                                       
$this->boprojects->update_async($mail_type, $start);
+
+                                       return True;
+                               break;
+                               default:
+                                       return false;
+                               break;
+                       }
+               }
+
+               /**
+               * Configure the worktime warnmail. The method can used for get 
and set the configuration (mail_type => (off | 0 | 1 | ... ).
+               * @param array $values contains the action (get or set) and the 
value set by the user
+               * @return mixed array when get the configuration; boolean if 
set the configuration: True if config was saved, otherwise false
+               */
+               function config_worktime_warnmail($values)
+               {
+                       if(!isset($values['action']))
+                               return false;
+
+                       $config = CreateObject('phpgwapi.config','projects');
+                       $config->read_repository();
+
+                       switch($values['action'])
+                       {
+                               case 'get':
+                                       
if(isset($config->config_data['worktime_warnmail']))
+                                               $warnmail_type = 
$config->config_data['worktime_warnmail'];
+                                       else
+                                               $warnmail_type = -1;
+                                       return $warnmail_type;
+                               break;
+                               case 'save':
+                                       if(!isset($values['warnmail_type']))
+                                               return false;
+
+                                       $warnmail_type = 
intval($values['warnmail_type']);
+                                       $config->value('worktime_warnmail', 
$warnmail_type);
+                                       $config->save_repository();
+
+                                       // set async service
+                                       $async = 
CreateObject('phpgwapi.asyncservice');
+                                       $aid = 'projects-worktime-warnmail-';
+
+                                       // set async service
+                                       if($warnmail_type == -1)
+                                       { // remove async
+                                               $jobs = $async->read($aid.'%');
+                                               if(is_array($jobs))
+                                               {
+                                                       foreach($jobs as $job)
+                                                       {
+                                                               
$async->delete($job['id']);
+                                                       }
+                                               }
+                                               return True;
+                                       }
+                                       else
+                                       { // update async setting
+                                               $jobs = $async->read($aid.'%');
+                                               if($jobs)
+                                               {
+                                                       foreach($jobs as $job)
+                                                       {
+                                                               
$async->delete($job['id']);
+                                                       }
+                                               }
+
+                                               $warnmail_month = date('n', 
time());
+                                               $warnmail_year  = date('Y', 
time());
+
+                                               
if($this->boprojects->update_async_warnmail($warnmail_month, $warnmail_year, 
$warnmail_type))
+                                                       return True;
+                                               else
+                                                       return false;
+                                       }
+                               break;
+                               default:
+                                       return false;
+                               break;
+                       }
+               }
+
+
+               /**
+               * Configure the workhours booking setting. The method can used 
for get and set the configuration (book_type => (0, 1 .. 5).
+               * @param array $values contains the action (get or set) and the 
value set by the user
+               * @return mixed array when get the configuration; boolean if 
set the configuration: True if config was saved, otherwise false
+               */
+               function config_workhours_booking($values)
+               {
+                       if(!isset($values['action']))
+                               return false;
+
+                       $config = CreateObject('phpgwapi.config','projects');
+                       $config->read_repository();
+
+                       switch($values['action'])
+                       {
+                               case 'get':
+                                       
if(isset($config->config_data['workhours_booking']))
+                                               $book_type = 
$config->config_data['workhours_booking'];
+                                       else
+                                               $book_type = 0;
+
+                                       return $book_type;
+                               break;
+                               case 'save':
+                                       if(!isset($values['book_type']))
+                                               return false;
+
+                                       $book_type = 
intval($values['book_type']);
+                                       if(($book_type < 0) || ($book_type > 5))
+                                               return false;
+
+                                       $config->value('workhours_booking', 
$book_type);
+                                       $config->save_repository();
+
+                                       $async = 
CreateObject('phpgwapi.asyncservice');
+                                       $aid = 'projects-workhours-booking-';
+
+                                       // set async service
+                                       if($book_type == 0)
+                                       { // remove async
+                                               $jobs = $async->read($aid.'%');
+                                               if(is_array($jobs))
+                                               {
+                                                       foreach($jobs as $job)
+                                                       {
+                                                               
$async->delete($job['id']);
+                                                       }
+                                               }
+                                       }
+                                       else
+                                       { // update async setting
+                                               $jobs = $async->read($aid.'%');
+                                               if($jobs)
+                                               {
+                                                       foreach($jobs as $job)
+                                                       {
+                                                               
$async->delete($job['id']);
+                                                       }
+                                               }
+
+                                               $holidays = 
CreateObject('phpgwapi.calendar_holidays');
+                                               $sbox = 
createobject('phpgwapi.sbox');
+                                               $country = 
ucfirst($GLOBALS['phpgw']->translation->retranslate($sbox->country_array[$GLOBALS['phpgw']->preferences->data['common']['country']]));
+                                               $federal_state = 
$holidays->federal_states[$country][$GLOBALS['phpgw']->preferences->data['common']['federalstate']];
 // Achtung: bisher existiert nur germany!
+                                               $religion = 
$holidays->religions[$GLOBALS['phpgw']->preferences->data['common']['religion']];
+
+                                               $ts_now = time();
+                                               $now_d = date('d', $ts_now);
+                                               $now_m = date('n', $ts_now);
+                                               $now_y = date('Y', $ts_now);
+
+                                               $workdays = $book_type;
+
+                                               // time of booking in this month
+                                               
$holidays->add_number_of_workdays(1,$now_m,$now_y,$workdays,$country,$federal_state,$religion,&$new_d,&$new_m,&$new_y);
+                                               $ts_book = 
mktime(0,0,0,$new_m,$new_d,$new_y)-1;
+
+                                               if($ts_book < $ts_now)
+                                               {
+                                                       // book is in past -> 
book next month
+                                                       if($now_m == 12)
+                                                       {
+                                                               $next_y = 
$now_y + 1;
+                                                               $next_m = 1;
+                                                       }
+                                                       else
+                                                       {
+                                                               $next_y = 
$now_y;
+                                                               $next_m = 
$now_m + 1;
+                                                       }
+
+                                                       
$holidays->add_number_of_workdays(1,$next_m,$next_y,$workdays,$country,$federal_state,$religion,&$new_d,&$new_m,&$new_y);
+                                                       $ts_book = 
mktime(0,0,0,$new_m,$new_d,$new_y)-1;
+                                               }
+
+                                               // calc book month
+                                               $book_run_m = date('n', 
$ts_book);
+                                               $book_run_y = date('Y', 
$ts_book);
+                                               if($book_run_m == 1)
+                                               {
+                                                       // book december last 
year
+                                                       $book_for_month = 12;
+                                                       $book_for_year  = 
$book_run_y - 1;
+                                               }
+                                               else
+                                               {
+                                                       $book_for_month = 
$book_run_m - 1;
+                                                       $book_for_year  = 
$book_run_y;
+                                               }
+
+                                               $async_data = array(
+                                                       'id' => 
$aid.$book_for_year.'-'.$book_for_month,
+                                                       'next' => $ts_book,
+                                                       'times' => $ts_book,
+                                                       'account_id' => 
$GLOBALS['phpgw_info']['user']['account_id'],
+                                                       'method' => 
'projects.boprojects.async_workhours_booking',
+                                                       'data' => array(
+                                                               'book_type'  => 
$book_type,
+                                                               'book_year'  => 
$book_for_year,
+                                                               'book_month' => 
$book_for_month
+                                                       )
+                                               );
+                                               $async->write($async_data);
+                                       }
+                                       return True;
+                               break;
+                               default:
+                                       return false;
+                               break;
+                       }
+               }
        }
 ?>

====================================================
Index: projects/inc/class.boprojecthours.inc.php
diff -u projects/inc/class.boprojecthours.inc.php:1.34 
projects/inc/class.boprojecthours.inc.php:1.35
--- projects/inc/class.boprojecthours.inc.php:1.34      Sun Jun 27 20:06:28 2004
+++ projects/inc/class.boprojecthours.inc.php   Mon Mar 14 17:39:39 2005
@@ -51,6 +51,7 @@

                        $this->boprojects       = 
CreateObject('projects.boprojects',True,$action);
                        $this->sohours          = $this->boprojects->sohours;
+
                        $this->account          = $this->boprojects->account;
                        $this->grants           = $this->boprojects->grants;

@@ -63,6 +64,7 @@
                        $this->project_id       = $this->boprojects->project_id;
                        $this->cat_id           = $this->boprojects->cat_id;
                        $this->limit            = True;
+
                        $this->siteconfig       = $this->boprojects->siteconfig;
                }

@@ -108,7 +110,7 @@
                                default:                $acl = PHPGW_ACL_EDIT; 
break;
                        }

-                       if (($pro['status'] != 'billed') && ($pro['status'] != 
'closed'))
+                       if (($pro['status'] != 'billed') && ($pro['status'] != 
'closed') && ($pro['booked'] != 'Y'))
                        {
                                if ($pro['employee'] == $this->account && 
!$pro['adminonly'])
                                {
@@ -161,6 +163,18 @@
                        return $htime;
                }

+               function format_minutes($min = '') // should be in a common 
class - needed almost everywhere
+               {
+                       if($min != 0)
+                       {
+                               return sprintf('%s%d:%02d', $min < 0 ? '-' : 
'', abs($min)/60, abs($min)%60);
+                       }
+                       else
+                       {
+                               return '';
+                       }
+               }
+
                function hdate_format($hdate = '')
                {
                        if (!$hdate)
@@ -182,13 +196,23 @@
                        return $dateval;
                }

-               function list_hours()
+               function list_hours($start = 0, $end = 0)
                {
-                       $hours_list = $this->sohours->read_hours(array('start' 
=> $this->start,'limit' => $this->limit,'query' => $this->query,'filter' => 
$this->filter,
-                                                                               
                                                        'sort' => 
$this->sort,'order' => $this->order,'status' => $this->state,'project_id' => 
$this->project_id));
+                       $filter = $this->filter;
+                       $hours_list = $this->sohours->read_hours(array('start' 
=> $this->start,
+                                                                      'limit' 
=> $this->limit,
+                                                                      'query' 
=> $this->query,
+                                                                      'filter' 
=> $filter,
+                                                                      'sort' 
=> $this->sort,
+                                                                      'order' 
=> $this->order,
+                                                                      'status' 
=> $this->state,
+                                                                      
'project_id' => $this->project_id,
+                                                                      
'period_start' => intval($start),
+                                                                      
'period_end' => intval($end)
+                                                                     ));
                        $this->total_records = $this->sohours->total_records;

-                       while(is_array($hours_list) && list(,$hour) = 
each($hours_list))
+                       while(is_array($hours_list) && (list($no_use,$hour) = 
each($hours_list)))
                        {
                                $hours[] = array
                                (
@@ -202,6 +226,8 @@
                                        'edate'                         => 
$hour['end_date'],
                                        'minutes'                       => 
$hour['minutes'],
                                        'wh'                            => 
$this->sohours->format_wh($hour['minutes']),
+                                       't_journey'                     => 
$this->sohours->min2time($hour['t_journey']),
+                                       'wh_all'                        => 
$this->sohours->format_wh($hour['minutes']+$hour['t_journey']),
                                        'employee'                      => 
$hour['employee'],
                                        'employeeout'           => 
$GLOBALS['phpgw']->common->grab_owner_name($hour['employee']),
                                        'sdate_formatted'       => 
$this->format_htime($hour['sdate']),
@@ -240,6 +266,7 @@
                                'billable'                      => 
$hours['billable'],
                                'km_distance'           => 
$hours['km_distance'],
                                't_journey'                     => 
$hours['t_journey'],
+                               'booked'                        => 
$hours['booked'],
                                'surcharge'                     => 
$hours['surcharge']
                        );
                        return $hour;
@@ -252,58 +279,88 @@

                function check_values($values)
                {
-                       if (strlen($values['hours_descr']) > 250)
+                       if(!$values['project_id'])
                        {
-                               $error[] = lang('Description can not exceed 250 
characters in length');
+                               $error[] = lang('please select a project for 
time tracking');
                        }

-                       if (strlen($values['remark']) > 8000)
+                       if($this->siteconfig['accounting'] != 'activity' && 
strlen(trim($values['hours_descr']))==0)
                        {
-                               $error[] = lang('Remark can not exceed 8000 
characters in length !');
+                               $error[] = lang('Description was not set');
                        }
-
-                       /*if ($values['shour'] && ($values['shour'] != 0) && 
($values['shour'] != 12))
+                       elseif($this->siteconfig['accounting'] == 'activity')
                        {
-                               if ($values['sampm']=='pm')
+                               $activity = 
$this->boprojects->read_single_activity($values['activity_id']);
+
+                               if (! is_array($activity))
                                {
-                                       $values['shour'] = $values['shour'] + 
12;
+                                       $error[] = lang('please select an 
activity');
+                               }
+                               elseif ($activity['remarkreq']=='Y' && 
(!$values['remark']))
+                               {
+                                       $error[] = lang('Please enter a 
remark');
                                }
                        }

-                       if ($values['shour'] && ($values['shour'] == 12))
+                       if (strlen($values['hours_descr']) > 250)
                        {
-                               if ($values['sampm']=='am')
-                               {
-                                       $values['shour'] = 0;
-                               }
+                               $error[] = lang('Description can not exceed 250 
characters in length');
                        }

-                       if ($values['ehour'] && ($values['ehour'] != 0) && 
($values['ehour'] != 12))
+                       if (strlen($values['remark']) > 8000)
                        {
-                               if ($values['eampm']=='pm')
+                               $error[] = lang('Remark can not exceed 8000 
characters in length !');
+                       }
+
+                       if($this->siteconfig['hoursbookingnull'] == 'no')
+                       {
+                               if(intval($values['hours']) == 0 && 
intval($values['minutes']) == 0)
                                {
-                                       $values['ehour'] = $values['ehour'] + 
12;
+                                       $error[] = lang('please enter the work 
time');
                                }
                        }

-                       if ($values['ehour'] && ($values['ehour'] == 12))
+                       if($this->siteconfig['hoursbookingday'] == 'no')
                        {
-                               if ($values['eampm']=='am')
+                               if(isset($values['shour']) && 
isset($values['smin']) && isset($values['ehour']) && isset($values['emin']))
                                {
-                                       $values['ehour'] = 0;
+                                       if(isset($values['hours']) && 
isset($values['minutes']))
+                                       {
+                                               $time_s  = 
$values['shour']*60+$values['smin'];
+                                               $time_e  = 
$values['ehour']*60+$values['emin'];
+                                               $time_w  = 
$values['hours']*60+$values['minutes'];
+
+                                               $time_se = $time_e - $time_s;
+
+                                               if(($time_se > 0) && ($time_w > 
$time_se))
+                                               {
+                                                       $error[] = lang('work 
time can not be bigger then time between start time and end time');
+                                               }
+                                       }
+
+                                       
if(mktime(intval($values['shour']),intval($values['smin']),0,1,1,2000) > 
mktime(intval($values['ehour']),intval($values['emin']),0,1,1,2000))
+                                       {
+                                               $error[] = lang('end time can 
not be before start time');
+                                       }
                                }
-                       }*/

-                       if(intval($values['hours']) == 0 && 
intval($values['minutes']) == 0)
-                       {
-                               $error[] = lang('please enter the work hours');
+                               if(isset($values['hours']) && 
isset($values['minutes']))
+                               {
+                                       $minutes = intval($values['hours'])*60 
+ intval($values['minutes']);
+                                       if($minutes < 0 || $minutes > 1440)
+                                       {
+                                               $error[] = lang('You have 
entered an invalid work time');
+                                       }
+                               }
                        }
-
-                       if($values['sdate'] > 0 && $values['edate'] > 0)
+                       else
                        {
-                               if($values['edate'] < $values['sdate'])
+                               if($values['sdate'] > 0 && $values['edate'] > 0)
                                {
-                                       $error[] = lang('end date can not be 
before start date');
+                                       if($values['edate'] < $values['sdate'])
+                                       {
+                                               $error[] = lang('end date can 
not be before start date');
+                                       }
                                }
                        }

@@ -313,14 +370,37 @@

                                if (! is_array($activity))
                                {
-                                       $error[] = lang('You have selected an 
invalid activity');
+                                       $error[] = lang('Please select an 
activity');
                                }
-                               else
+                               elseif ($activity['remarkreq']=='Y' && 
(!$values['remark']))
+                               {
+                                       $error[] = lang('Please enter a 
remark');
+                               }
+                       }
+
+                       $async = CreateObject('phpgwapi.asyncservice');
+                       $aid = 'projects-workhours-booking-';
+                       $data = $async->read($aid . '%');
+
+                       $month = 1;
+                       $year  = 1970;
+                       if(is_array($data))
+                       {
+                               foreach($data as $job)
                                {
-                                       if ($activity['remarkreq']=='Y' && 
(!$values['remark']))
+                                       $asyncdata = $job['data'];
+                                       if(!isset($asyncdata['book_year']) || 
!isset($asyncdata['book_month']))
                                        {
-                                               $error[] = lang('Please enter a 
remark');
+                                               continue;
                                        }
+
+                                       $month = $asyncdata['book_month'];
+                                       $year = $asyncdata['book_year'];
+                               }
+
+                               if($values['sdate'] < 
mktime(0,0,0,$month,1,$year))
+                               {
+                                       $error[] = lang('You entered a worktime 
for a month that was already booked! Booking is not possible any more.').' 
('.date("d.m.Y", $values['sdate']).' < 1.'.$month.'.'.$year.')';
                                }
                        }

@@ -328,6 +408,10 @@
                        {
                                return $error;
                        }
+                       else
+                       {
+                               return True;
+                       }
                }

                function check_ttracker($values)
@@ -337,20 +421,57 @@
                                $error[] = lang('please select a project for 
time tracking');
                        }

+                       if (strlen($values['remark']) > 8000)
+                       {
+                               $error[] = lang('Remark can not exceed 8000 
characters in length !');
+                       }
+
+                       if(strlen($values['hours_descr']) > 250)
+                       {
+                               $error[] = lang('Description can not exceed 250 
characters in length');
+                       }
+
+                       if(is_array($error))
+                       {
+                               return $error;
+                       }
+
                        if($values['start'] || $values['continue'])
                        {
-                               $is_active = 
$this->sohours->check_ttracker($values['project_id'],'active');
+                               $is_active = 
$this->sohours->check_ttracker(array('project_id' => 
$values['project_id'],'status' => 'active'));
                                if($is_active)
                                {
                                        $error[] = lang('time tracking for this 
project is already active');
                                }
+
+                               if($values['start'])
+                               {
+                                       if($this->siteconfig['accounting'] != 
'activity' && strlen(trim($values['hours_descr']))==0)
+                                       {
+                                               $error[] = lang('Description 
was not set');
+
+                                       }
+                                       elseif($this->siteconfig['accounting'] 
== 'activity')
+                                       {
+                                               $activity = 
$this->boprojects->read_single_activity($values['activity_id']);
+
+                                               if (! is_array($activity))
+                                               {
+                                                       $error[] = lang('please 
select an activity');
+                                               }
+                                               elseif 
($activity['remarkreq']=='Y' && (!$values['remark']))
+                                               {
+                                                       $error[] = lang('Please 
enter a remark');
+                                               }
+                                       }
+                               }
                        }
-                       else if($values['stop'] || $values['pause'])
+                       elseif($values['stop'] || $values['pause'])
                        {
-                               $is_active = 
$this->sohours->check_ttracker($values['project_id'],'inactive');
-                               if($is_active)
+                               $is_active = 
$this->sohours->check_ttracker(array('project_id' => 
$values['project_id'],'status' => 'active'));
+                               if(!$is_active)
                                {
-                                       $error[] = lang('time tracking for this 
project has been stopped already');
+                                       $error[] = lang('time tracking for this 
project is not active');
                                }
                        }
                        return $error;
@@ -358,7 +479,7 @@

                function save_hours($values)
                {
-                       if ($values['shour'] && ($values['shour'] != 0) && 
($values['shour'] != 12))
+                       /*if ($values['shour'] && ($values['shour'] != 0) && 
($values['shour'] != 12))
                        {
                                if ($values['sampm']=='pm')
                                {
@@ -388,27 +509,38 @@
                                {
                                        $values['ehour'] = 0;
                                }
-                       }
+                       }*/

                        if (!$values['sdate'])
-            {
-                $values['sdate'] = time();
-            }
+                       {
+                               $values['sdate'] = time();
+                       }

                        $values['smonth']       = date('m',$values['sdate']);
                        $values['sday']         = date('d',$values['sdate']);
                        $values['syear']        = date('Y',$values['sdate']);
-                       $values['sdate']        = 
mktime(($values['shour']?$values['shour']:12),($values['smin']?$values['smin']:0),0,$values['smonth'],$values['sday'],$values['syear']);
+                       $values['sdate']        = 
mktime(($values['shour']?$values['shour']:0),($values['smin']?$values['smin']:0),0,$values['smonth'],$values['sday'],$values['syear']);

                        if (intval($values['edate']) > 0)
                        {
                                $values['emonth']       = 
date('m',$values['edate']);
                                $values['eday']         = 
date('d',$values['edate']);
                                $values['eyear']        = 
date('Y',$values['edate']);
-                               $values['edate']        = 
mktime(($values['ehour']?$values['ehour']:12),($values['emin']?$values['emin']:0),0,$values['emonth'],$values['eday'],$values['eyear']);
+                               $values['edate']        = 
mktime(($values['ehour']?$values['ehour']:0),($values['emin']?$values['emin']:0),0,$values['emonth'],$values['eday'],$values['eyear']);
+                       }
+                       else
+                       {
+                               $values['edate']        = 
mktime(($values['ehour']?$values['ehour']:0),($values['emin']?$values['emin']:0),0,$values['smonth'],$values['sday'],$values['syear']);
                        }

-                       $values['w_minutes'] = 
$values['hours']*60+$values['minutes'];
+                       if(!$values['t_journey'] && !$values['hours'] && 
!$values['minutes'])
+                       {
+                               $values['w_minutes'] = 
(($values['ehour']*60+$values['emin']) - ($values['shour']*60+$values['smin']));
+                       }
+                       else
+                       {
+                               $values['w_minutes'] = 
$values['hours']*60+$values['minutes'];
+                       }

                        if($values['track_id'] || $values['action'] == 'apply')
                        {
@@ -421,9 +553,17 @@
                                        $values['employee'] = 
$this->sohours->account;
                                }

-                               $values['project_id']   = $this->project_id;
-                               $values['pro_parent']   = 
$this->boprojects->return_value('parent',$this->project_id);
-                               $values['pro_main']             = 
$values['pro_main']?$values['pro_main']:$this->project_id;
+                               $values['project_id']   = 
$values['project_id']?$values['project_id']:$this->project_id;
+                               $values['pro_parent']   = 
$this->boprojects->return_value('parent',$values['project_id']);
+
+                               if(!$values['pro_main'])
+                               {
+                                       $values['pro_main'] = 
$this->boprojects->return_value('main',$values['project_id']);
+                                       if(!$values['pro_main'])
+                                       {
+                                               $values['pro_main']     = 
$values['project_id'];
+                                       }
+                               }

                                if (intval($values['hours_id']) > 0)
                                {
@@ -521,7 +661,9 @@
                                        $hours[$key] = array
                                        (
                                                'project_title' => 
$GLOBALS['phpgw']->strip_html($pro['title']) . ' [' . 
$GLOBALS['phpgw']->strip_html($pro['p_number']) . ']',
-                                               'project_id'    => 
$pro['project_id']
+                                               'project_id'    => 
$pro['project_id'],
+                                               'project_level' => $pro['level']
+
                                        );

                                        if(is_array($tracking))
@@ -561,7 +703,7 @@
                        switch($values['action'])
                        {
                                case 'save':    
$this->sohours->save_ttracker(); break;
-                               default:                
$this->sohours->ttracker($values); break;
+                               default:                
$this->sohours->ttracker($values);break;
                        }
                }

@@ -587,5 +729,303 @@
                        );
                        return $hour;
                }
+
+               function is_booked($hours_id)
+               {
+                       $hours = $this->read_single_hours($hours_id);
+                       if ($hours['booked'] == 'Y')
+                       {
+                               return True;
+                       }
+                       else
+                       {
+                               return False;
+                       }
+               }
+
+               function set_booked($values)
+               {
+                       $this->sohours->set_booked($values);
+               }
+
+               function build_controlling_matrix($account_id, $start_date, 
$end_date)
+               {
+                       if($account_id != 
$GLOBALS['phpgw_info']['user']['account_id'])
+                       { // read projects for account_id
+                               $this->boprojects->soprojects->account = 
$account_id;
+                               $this->boprojects->soprojects->member = 
$this->boprojects->soprojects->get_acl_projects();
+                       }
+
+                       $projects    = 
$this->boprojects->soprojects->get_projects_tree();
+                       $hoursResult = 
$this->sohours->get_dayhours($account_id, $start_date, $end_date);
+
+                       $days = array();
+                       $start_date = mktime(0, 0, 0, date("m", $start_date), 
date("d", $start_date), date("Y", $start_date));
+                       foreach($projects as $key => $value)
+                       {
+                               $j = $start_date;
+                               while($j <= $end_date)
+                               {
+                                       $days[$j] = 0;
+                                       // use +1day instead of +86400s because 
we could have daylight saving time
+                                       $j = mktime(0, 0, 0, date("m", $j), 
date("d", $j)+1, date("Y", $j));
+                               }
+
+                               $matrix[] = array('id'      => $value['id'],
+                                                 'title'   => 
str_repeat('&nbsp;&nbsp;&nbsp;', (substr_count($key, '.') - 1)).$value['title'],
+                                                 'pnumber' => 
$value['pnumber'],
+                                                 'enddate' => 
$value['enddate'],
+                                                 'days'    => $days
+                                                );
+
+                       }
+                       while($hoursResult->next_record())
+                       {
+                               for($i = 0; $i < count($matrix); $i++)
+                               {
+                                       if($matrix[$i]['id'] == 
$hoursResult->f(1))
+                                       {
+                                               
$matrix[$i]['days'][$hoursResult->f(0)] = $hoursResult->f(2);
+                                               break;
+                                       }
+                               }
+                       }
+
+                       if($account_id != 
$GLOBALS['phpgw_info']['user']['account_id'])
+                       { // restore projects for current user
+                               $this->boprojects->soprojects->account = 
$GLOBALS['phpgw_info']['user']['account_id'];
+                               $this->boprojects->soprojects->member = 
$this->boprojects->soprojects->get_acl_projects();
+                       }
+
+                       return $matrix;
+               }
+
+               function export_controlling_sheet($start, $end)
+               {
+                       $projects = 
$this->boprojects->soprojects->get_projects_tree();
+                       $export  = 
lang('User').":\t".$GLOBALS['phpgw_info']['user']['account_lid']."\t".$GLOBALS['phpgw_info']['user']['account_id']."\n\n\n";
+                       $export .= "\t".lang('Project')."\t".lang('job 
id')."\t".lang('Customer')."\t";
+                       for($j = $start; $j <= $end; $j += 86400)
+                       {
+                               $export .= "\t".date('d.m.Y', $j);
+                       }
+                       $export .= "\n";
+
+                       foreach($projects as $key => $value)
+                       {
+                               $org = '';
+                               if($value['customer_org'] != 0)
+                               {
+                                       $org_data = 
$this->boprojects->read_single_contact_org($value['customer_org']);
+                                       if($org_data && isset($org_data[0]))
+                                       {
+                                               $org = $org_data[0]['org_name'];
+                                       }
+                               }
+
+                               $export .= $value['id']."\t".str_repeat('   ', 
(substr_count($key, '.') - 1)).$value['title']."\t";
+                               $export .= 
$value['pnumber']."\t".$org."\t".lang('work time');
+                               $export .= "\n";
+                               $export .= "\t\t\t\t".lang('time of journey');
+                               $export .= "\n";
+                               $export .= "\t\t\t\t".lang('description');
+                               $export .= "\n";
+                       }
+
+                       return $export;
+               }
+
+               function _time2minutes($time_str)
+               {
+                       if(!$time_str)
+                       {
+                               return 0;
+                       }
+
+                       if(strpos($time_str, ','))
+                       {
+                               $timeparts = explode(',', $time_str);
+                               $minfactor = 0.6;
+                       }
+                       elseif(strpos($time_str, '.'))
+                       {
+                               $timeparts = explode('.', $time_str);
+                               $minfactor = 0.6;
+                       }
+                       elseif(strpos($time_str, ':'))
+                       {
+                               $timeparts = explode(':', $time_str);
+                               $minfactor = 1;
+                       }
+                       else
+                       { // full hours
+                               return 60*intval($time_str);
+                       }
+
+                       if(!is_array($timeparts) || (count($timeparts)<2))
+                       {
+                               return false;
+                       }
+
+                       if(($minfactor != 1) && ($timeparts[1]<10))
+                       { // for inputs like ,1 ... ,9  examble 0,5 h
+                               $timeparts[1] = $timeparts[1] * 10;
+                       }
+
+                       return intval($timeparts[0])*60 + intval($timeparts[1]) 
* $minfactor;
+               }
+
+               function build_import_controlling_sheet($lines, &$error)
+               {
+                       for($i=0; $i < count($lines); $i++)
+                       {
+                               //echo $i."->".$lines[$i]."<br>";
+                               if($i == 0) //get account_id
+                               {
+                                       $accountinfo = explode("\t", 
$lines[$i]);
+
+                                       
if(!$this->boprojects->isprojectadmin('pad') && 
!$this->boprojects->isprojectadmin('pmanager'))
+                                       {
+                                               
if($GLOBALS['phpgw_info']['user']['account_id'] != (int) $accountinfo[2] )
+                                               {
+                                                       $error = lang('could 
not verify account id');
+                                                       break;
+                                               }
+                                       }
+                               }
+                               if($i == 3) //days
+                               {
+                                       $days = explode("\t", $lines[$i]);
+                                       for($j=5; $j < count($days); $j++)
+                                       {
+                                               $dateparts = explode('.', 
$days[$j]);
+                                               $days[$j] = mktime(0,0,0, 
$dateparts[1], $dateparts[0], $dateparts[2]);
+                                       }
+                               }
+
+                               if($i > 3) //here we go
+                               {
+                                       // get 3 lines for one project 
(worktime, journey, description)
+                                       $project = explode("\t", $lines[$i]);   
++$i;
+                                       $journey = explode("\t", $lines[$i]); 
++$i;
+                                       $descrip = explode("\t", $lines[$i]);
+
+                                       $validprojectid = 
$this->boprojects->soprojects->exists(array('project_id' => $project[0]));
+                                       $employees = 
$this->boprojects->get_acl_for_project($project[0]);
+                                       if(is_array($employees))
+                                       {
+                                               
if($this->boprojects->isprojectadmin('pad') || 
$this->boprojects->isprojectadmin('pmanager'))
+                                               {
+                                                       $validemployee = 
in_array($accountinfo[2], $employees);
+                                               }
+                                               else
+                                               {
+                                                       $validemployee = 
in_array($this->account,$employees);
+                                               }
+                                       }
+                                       for($j=5; $j < count($project); $j++)
+                                       {
+                                               $entryerror = '';
+
+                                               if(isset($project[$j]))
+                                               {
+                                                       $project[$j] = 
$this->_time2minutes($project[$j]);
+                                               }
+                                               else
+                                               {
+                                                       $project[$j] = 0;
+                                               }
+                                               if(isset($journey[$j]))
+                                               {
+                                                       $journey[$j] = 
$this->_time2minutes($journey[$j]);
+                                               }
+                                               else
+                                               {
+                                                       $journey[$j] = 0;
+                                               }
+
+                                               if(!$validprojectid)
+                                               {
+                                                       $entryerror = 
lang('invalid project id');
+                                               }
+                                               if(!$days[$j])
+                                               {
+                                                       $entryerror = 
lang('invalid date');
+                                               }
+                                               if(!$validemployee)
+                                               {
+                                                       $entryerror = 
lang('employee not on this project');
+                                               }
+                                               if($journey[$j]+$project[$j] >= 
24*60)
+                                               {
+                                                       $entryerror = lang('too 
many hours for this day');
+                                               }
+                                               if(($project[$j] > 0) || 
($journey[$j] > 0))
+                                               {
+                                                       if(isset($descrip[$j]) 
&& ($descrip[$j]!=''))
+                                                       {
+                                                               $description = 
$descrip[$j];
+                                                       }
+                                                       else
+                                                       {
+                                                               $description = 
lang('imported hours');
+                                                       }
+
+                                                       $savematrix[] = 
array('employee'     => $accountinfo[2],
+                                                                             
'projectid'    => $project[0],
+                                                                             
'projecttitle' => $project[1],
+                                                                             
'projectnumber'=> $project[2],
+                                                                             
'customer_org' => $project[3],
+                                                                             
'date'         => $days[$j],
+                                                                             
'time'         => $project[$j],
+                                                                             
'journey'      => $journey[$j],
+                                                                             
'description'  => $description,
+                                                                             
'error'        => $entryerror
+                                                                            );
+                                               }
+                                       }
+                               }
+                       }
+                       return $savematrix;
+               }
+
+               function build_acitivity_matrix($projectID, $start = 0, $end = 
0)
+               {
+                       $projects = 
$this->boprojects->soprojects->get_projects_tree($projectID, 
array('project_id', 'parent', 'title', 'p_number', 'direct_work', 'p_number', 
'end_date', 'time_planned', 'e_budget', 'acc_factor', 'acc_factor_d'));
+                       $this->filter = 'employee';
+                       $i=0;
+                       foreach($projects as $key => $value)
+                       {
+                               $matrix[$i]['project']  = $value;
+                               $matrix[$i]['project']['title'] = 
str_repeat('&nbsp;&nbsp;&nbsp;', (substr_count($key, '.') - 1)).$value['title'];
+                               $employees = 
$this->boprojects->get_acl_for_project($value['id']);
+                               $this->project_id = $value['id'];
+
+                               for($j=0; $j < count($employees); $j++)
+                               {
+                                       $matrix[$i]['employee'][$employees[$j]] 
= array();
+                                       $this->sohours->employee = 
$employees[$j]; // dirty hack - list_hours not flexible engough
+                                       $employee_hours = 
$this->list_hours($start, $end);
+
+                                       if(is_array($employee_hours))
+                                       {
+                                               for($k=0; $k < 
count($employee_hours); $k++)
+                                               {
+                                                       
$matrix[$i]['employee'][$employees[$j]][] = array('id'          => 
$employee_hours[$k]['hours_id'],
+                                                                               
                          'description' => $employee_hours[$k]['hours_descr'],
+                                                                               
                          'statusout'   => $employee_hours[$k]['status'],
+                                                                               
                          'minutes'     => $employee_hours[$k]['minutes'],
+                                                                               
                          'minutesout'  => 
$employee_hours[$k]['wh']['whours_formatted'].':'.$employee_hours[$k]['wh']['wmin_formatted'],
+                                                                               
                          'date'        => 
$employee_hours[$k]['sdate_formatted']['date'],
+                                                                               
                          'start'       => 
$employee_hours[$k]['sdate_formatted']['time'],
+                                                                               
                          'end'         => 
$employee_hours[$k]['edate_formatted']['time']
+                                                                               
                         );
+                                               }
+                                       }
+                               }
+                               $i++;
+                       }
+                       return $matrix;
+               }
        }
 ?>

====================================================
Index: projects/inc/class.soconfig.inc.php
diff -u projects/inc/class.soconfig.inc.php:1.17 
projects/inc/class.soconfig.inc.php:1.18
--- projects/inc/class.soconfig.inc.php:1.17    Sat Jun 19 22:47:31 2004
+++ projects/inc/class.soconfig.inc.php Mon Mar 14 17:39:39 2005
@@ -40,16 +40,32 @@
                        $this->account  = 
$GLOBALS['phpgw_info']['user']['account_id'];
                }

-               function get_site_config()
+               function get_site_config($params = 0)
                {
+                       $default = $params['default']?$params['default']:True;
+                       $helpmsg = $params['helpmsg']?$params['helpmsg']:False;
+
                        $this->config = 
CreateObject('phpgwapi.config','projects');
                        $this->config->read_repository();

                        if ($this->config->config_data)
                        {
                                $items = $this->config->config_data;
+
+                               if($default)
+                               {
+                                       $items['hwday']                         
= isset($items['hwday'])?$items['hwday']:8;
+                                       $items['accounting']            = 
isset($items['accounting'])?$items['accounting']:'own';
+                                       $items['activity_bill']         = 
isset($items['activity_bill'])?$items['activity_bill']:'h';
+                                       $items['dateprevious']          = 
isset($items['dateprevious'])?$items['dateprevious']:'no';
+                                       $items['hoursbookingday']       = 
isset($items['hoursbookingday'])?$items['hoursbookingday']:'no';
+                                       $items['hoursbookingnull']      = 
isset($items['hoursbookingnull'])?$items['hoursbookingnull']:'no';
+                                       $items['projectnr']                     
= isset($items['projectnr'])?$items['projectnr']:'generate';
+                               }
+                               $items['proid_help_msg'] = 
($helpmsg==True?$items['proid_help_msg']:'');
+                               return $items;
                        }
-                       return $items;
+                       return False;
                }

                function bill_lang()
@@ -345,7 +361,7 @@

                                if ($admins[$i]['type'] == $type_a && 
$admins[$i]['account_id'] == $this->account)
                                {
-                                       return True;
+                                       return true;
                                }
                                elseif ($admins[$i]['type'] == $type_g)
                                {
@@ -354,13 +370,13 @@
                                                for 
($j=0;$j<count($admin_groups);$j++)
                                                {
                                                        if 
($admin_groups[$j]['account_id'] == $admins[$i]['account_id'])
-                                                       return True;
+                                                               return true;
                                                }
                                        }
                                }
                                else
                                {
-                                       return False;
+                                       return false;
                                }
                        }
                }
@@ -537,7 +553,9 @@
                                        'accounting'    => 
$this->db->f('accounting'),
                                        'd_accounting'  => 
$this->db->f('d_accounting'),
                                        'sdate'                 => 
$this->db->f('sdate'),
-                                       'edate'                 => 
$this->db->f('edate')
+                                       'edate'                 => 
$this->db->f('edate'),
+                                       'weekly_workhours'      => 
$this->db->f('weekly_workhours'),
+                                       'cost_centre'   => 
$this->db->f('cost_centre')
                                );
                        }
                        return $emps;
@@ -546,12 +564,13 @@
                function read_employees($values)
                {
                        $start          = intval($values['start']);
-                       $limit          = 
(isset($values['limit'])?$values['limit']:True);
+                       $limit          = 
(isset($values['limit'])?$values['limit']:false);
                        $sort           = 
(isset($values['sort'])?$values['sort']:'ASC');
                        $order          = 
(isset($values['order'])?$values['order']:'sdate');
                        $query          = 
$this->db->db_addslashes($values['query']);
                        $account_id     = intval($values['account_id']);
                        $id                     = intval($values['id']);
+                       $date     = intval($values['date']);

                        $ordermethod = ' order by ' . 
($order!='account_id'?'account_id,' . $order:$order) . ' ' . $sort;

@@ -565,7 +584,12 @@
                                $id_select = ' and id !=' . $id;
                        }

-                       $sql = "SELECT * from phpgw_p_projectmembers WHERE 
type='accounting'" . $id_select;
+                       if ($date)
+                       {
+                               $date_select = " and sdate <= ".$date." and 
edate >= ".$date;
+                       }
+
+                       $sql = "SELECT * from phpgw_p_projectmembers WHERE 
type='accounting'" . $id_select . $date_select . $querymethod;

                        if($limit)
                        {
@@ -590,14 +614,17 @@
                        if($values['id'] > 0)
                        {
                                $this->db->query('UPDATE phpgw_p_projectmembers 
set accounting=' . $values['accounting'] . ', d_accounting=' . 
$values['d_accounting']. ', sdate='
-                                                               . 
intval($values['sdate']) . ', edate=' . intval($values['edate']) . ' where 
account_id=' . intval($values['account_id'])
+                                                               . 
intval($values['sdate']) . ', edate=' . intval($values['edate'])
+                                                               . ', 
weekly_workhours=' . $values['weekly_workhours'] . ', cost_centre=' . 
$values['cost_centre']
+                                                               . ' where 
account_id=' . intval($values['account_id'])
                                                                . " and 
type='accounting' and id=" . $values['id'],__LINE__,__FILE__);
                        }
                        else
                        {
-                               $this->db->query('INSERT into 
phpgw_p_projectmembers (account_id,type,accounting,d_accounting,sdate,edate) 
values(' . intval($values['account_id'])
+                               $this->db->query('INSERT into 
phpgw_p_projectmembers 
(account_id,type,accounting,d_accounting,sdate,edate,weekly_workhours,cost_centre)
 values(' . intval($values['account_id'])
                                                                . 
",'accounting'," . $values['accounting'] . ',' . $values['d_accounting'] . ',' 
. intval($values['sdate']) . ','
-                                                               . 
intval($values['edate']) . ')',__LINE__,__FILE__);
+                                                               . 
intval($values['edate'])  . ',' . $values['weekly_workhours'] . ',' . 
$values['cost_centre']
+                                                               . 
')',__LINE__,__FILE__);
                        }
                }


====================================================
Index: projects/inc/class.boprojects.inc.php
diff -u projects/inc/class.boprojects.inc.php:1.150 
projects/inc/class.boprojects.inc.php:1.151
--- projects/inc/class.boprojects.inc.php:1.150 Wed Aug 11 15:05:13 2004
+++ projects/inc/class.boprojects.inc.php       Mon Mar 14 17:39:39 2005
@@ -37,34 +37,45 @@
                var $cat_id;
                var $status;
                var $html_output;
+               var $bohours;

                var $public_functions = array
                (
-                       'save_sessiondata'                      => True,
-                       'cached_accounts'                       => True,
-                       'list_projects'                         => True,
-                       'check_perms'                           => True,
-                       'check_values'                          => True,
-                       'select_project_list'           => True,
-                       'save_project'                          => True,
-                       'read_single_project'           => True,
-                       'delete_pa'                                     => True,
-                       'exists'                                        => True,
-                       'employee_list'                         => True,
-                       'read_abook'                            => True,
-                       'read_single_contact'           => True,
-                       'return_value'                          => True,
-                       'change_owner'                          => True
+                       'save_sessiondata'                                      
=> True,
+                       'cached_accounts'                                       
=> True,
+                       'list_projects'                                         
=> True,
+                       'check_perms'                                           
=> True,
+                       'check_values'                                          
=> True,
+                       'select_project_list'                           => True,
+                       'save_project'                                          
=> True,
+                       'read_single_project'                           => True,
+                       'delete_pa'                                             
        => True,
+                       'exists'                                                
        => True,
+                       'employee_list'                                         
=> True,
+                       //'read_abook'                                          
=> True,
+                       'read_single_contact'                           => True,
+                       'read_single_contact_org'                       => True,
+                       'return_value'                                          
=> True,
+                       'change_owner'                                          
=> True,
+                       'async_worktime_statusmail'                     => True,
+                       'async_worktime_warnmail'                       => True,
+                       'async_workhours_booking'                       => True,
+                       'test_async_worktime_statusmail'        => True,
+                       'test_async_worktime_warnmail'          => True
                );

                function boprojects($is_active=False, $action = '')
                {
                        $this->soprojects       = 
CreateObject('projects.soprojects');
+
                        $this->sohours          = 
CreateObject('projects.soprojecthours');
                        $this->soconfig         = $this->soprojects->soconfig;
+
                        $this->contacts         = 
CreateObject('phpgwapi.contacts');
                        $this->cats                     = 
CreateObject('phpgwapi.categories');
+
                        $this->debug            = False;
+
                        $this->siteconfig       = $this->soprojects->siteconfig;

                        $this->account                                  = 
$GLOBALS['phpgw_info']['user']['account_id'];
@@ -278,7 +289,7 @@
                {
                        if($this->status == 'archive')
                        {
-                               return False;
+                               return false;
                        }
                        switch($pro['action'])
                        {
@@ -362,7 +373,7 @@
                        return $date;
                }

-               function read_abook($start, $query, $filter, $sort, $order)
+               /*function read_abook($start, $query, $filter, $sort, $order)
                {
                        $cols = array('contact_id', 
'per_first_name','per_last_name','org_name','people');
                        //$criteria = array('my_preferred' => 'Y');
@@ -371,7 +382,7 @@

                        $this->total_records = $this->contacts->total_records;
                        return $entries;
-               }
+               }*/

                function read_single_contact($abid)
                {
@@ -382,13 +393,21 @@
                        //_debug_array($co);
                }

+               function read_single_contact_org($customer_org)
+               {
+                       $cols = array('contact_id', 'org_name');
+                       $criteria = array('contact_id' => 
intval($customer_org));
+
+                       return $this->contacts->get_orgs($cols, 
$limit='',$start = '',$order='', $sort='', $criteria);
+               }
+
                function return_value($action,$item)
                {
                        return $this->soprojects->return_value($action,$item);
                }

                function read_projects_acl($useronly = True)
-               {
+               {
                        $aclusers       = 
$GLOBALS['phpgw']->acl->get_ids_for_location('run',1,'projects');
                        $acl_users      = 
$GLOBALS['phpgw']->accounts->return_members($aclusers);

@@ -403,13 +422,31 @@
                        }
                }

+               function read_projectsmembers_acl($project_id = false)
+               {
+                       $members = 
$this->soprojects->get_acl_project_members($project_id);
+                       return $members;
+               }
+
+               // a lot of work-arounds added - fips
                function get_acl_for_project($project_id = 0)
                {
-                       if(intval($project_id) > 0)
+                       while(!count($empl) && $project_id)
+                       {
+                               $myproject = 
$this->soprojects->read_single_project($project_id);
+
+                               $empl = 
$GLOBALS['phpgw']->acl->get_ids_for_location($project_id, 7, 'project_members');
+                               if(!count($empl) || $empl[0] == '')
+                               {
+                                       $empl = null;
+                                       $project_id = $myproject['parent'];
+                               }
+                       }
+                       if(count($empl))
                        {
-                               return 
$GLOBALS['phpgw']->acl->get_ids_for_location($project_id, 7);
+                               return $empl;
                        }
-                       return False;
+                       return false;
                }

                function get_employee_projects($account_id = 0)
@@ -426,7 +463,11 @@
                        $project_id = intval($data['project_id']);
                        $pro_parent = intval($data['pro_parent']);

-                       if(intval($project_id) > 0)
+                       if($data['action'] == 'mains')
+                       {
+                               $emps = $this->read_projects_acl();
+                       }
+                       elseif(intval($project_id) > 0)
                        {
                                $emps = $this->get_acl_for_project($project_id);
                        }
@@ -473,33 +514,39 @@
                                        $emps[0] = $co;
                                }
                        }
-
                        //_debug_array($emps);

                        for($i=0;$i<count($emps);$i++)
                        {
-                               $this->accounts = 
CreateObject('phpgwapi.accounts',$emps[$i]);
-                               $this->accounts->read_repository();
+                               if(!$emps[$i])
+                                       continue;
+
+                               //$this->accounts = 
CreateObject('phpgwapi.accounts',$emps[$i]);
+                               //$this->accounts->read_repository();

                                if($data['roles_included'] == True)
                                {
                                        $role_name = 
$this->soprojects->return_value('role',$project_id,$emps[$i]);
                                }

+                               
$GLOBALS['phpgw']->accounts->get_account_name($emps[$i],$lid,$fname,$lname);
                                $empl[] = array
                                (
-                                       'account_id'            => 
$this->accounts->data['account_id'],
-                                       'account_lid'           => 
$this->accounts->data['account_lid'],
-                                       'account_firstname'     => 
$this->accounts->data['firstname'],
-                                       'account_lastname'      => 
$this->accounts->data['lastname'],
-                                       'account_fullname'      => 
$GLOBALS['phpgw']->common->display_fullname($this->accounts->data['account_lid'],$this->accounts->data['firstname'],
-                                                                               
                                                                                
                $this->accounts->data['lastname']),
-                                       'role_name'                     => 
$role_name
-                                       //'role_name'                   => 
$co==$emps[$i]?($action=='mains'?lang('coordinator'):lang('job manager')) . 
"\n" . $role_name:$role_name
+                                       'account_id'            => $emps[$i],
+                                       'account_lid'           => $lid,
+                                       'account_firstname'     => $fname,
+                                       'account_lastname'      => $lname,
+                                       'account_fullname'      => 
$GLOBALS['phpgw']->common->display_fullname($lid,$fname,$lname),
+                                       'role_name'                     => 
isset($role_name)?$role_name:''
                                );
                        }
-                       asort($empl);
-                       reset($empl);
+
+                       if(count($empl))
+                       {
+                               asort($empl);
+                               reset($empl);
+                       }
+                       //_debug_array($empl);
                        return $empl;
                }

@@ -517,8 +564,6 @@

                function calculate_budget($data = 0)
                {
-                       //_debug_array($data);
-
                        if($this->siteconfig['accounting'] == 'activity')
                        {
                                $budget = 
$this->sohours->calculate_activity_budget(array('project_id' => 
$data['project_id'],'project_array' => $data['project_array']));
@@ -529,17 +574,10 @@
                                $factor_per_minute = $data['factor']/60;

                                $surcharge = 
$data['surcharge']>0?$this->return_value('charge',$data['surcharge']):0;
-
-                               //echo 'boprojects->calculate_budget: 
SURCHARGE: ' . $surcharge . '<br>';
-
                                $budget = 
round($factor_per_minute*$data['minutes'],2);
-
-                               //echo 'BUDGET: ' . $budget . '<br>';
                                if($surcharge>0)
                                {
                                        $add_surcharge = 
($budget*$surcharge)/100;
-                                       //echo 'ADD SURCHARGE: ' . 
$add_surcharge . '<br>';
-
                                        return $budget + $add_surcharge;
                                }
                                else
@@ -556,13 +594,11 @@
                        $subs = $this->get_sub_projects($params);
                        if(is_array($subs))
                        {
-                               //_debug_array($subs);
-
                                $i = 0;
                                foreach($subs as $sub)
                                {
                                        $sub_pro[$i] = $sub['project_id'];
-                                       ++$i;
+                                       $i++;
                                        if($sub['parent'] == 
$params['project_id'])
                                        {
                                                $sum_budget += $sub['budget'];
@@ -639,9 +675,14 @@

                                $subs = $this->get_sub_projects($params);

+                               $acc = array();
+
+                               $acc['is_leaf'] = True;
                                if(is_array($subs))
                                {
                                        $i = 0;
+                                       $sum_budget = 0;
+                                       $sum_ptime = 0;
                                        foreach($subs as $sub)
                                        {
                                                switch($sub['billable'])
@@ -654,14 +695,14 @@
                                                ++$i;
                                                if($sub['parent'] == 
$params['project_id'])
                                                {
-                                                       $sum_budget += 
$sub['budget'];
-                                                       $sum_ptime += 
$sub['time_planned'];
+                                                       $sum_budget += 
$sub['budget']+$sub['budget_childs'];
+                                                       $sum_ptime += 
$sub['time_planned']+$sub['time_planned_childs'];
                                                }
                                        }
+
+                                       $acc['is_leaf'] = ($i==1);
                                }

-                               $acc = array();
-
                                if($params['page'] == 'planned')
                                {
                                        $acc['pbudget_jobs']    = $sum_budget;
@@ -670,11 +711,15 @@
                                        $acc['ptime_jobs_min']  = $sum_ptime;
                                        return $acc;
                                }
-
+
+                               $acc['pbudget_jobs']    = $sum_budget;
+                               $ptimejobs                              = 
$this->sohours->format_wh($sum_ptime);
+                               $acc['ptime_jobs']              = 
$ptimejobs['whwm'];
+                               $acc['ptime_jobs_min']  = $sum_ptime;
+
                                // ------ project only -------

                                $h_pro = 
$this->sohours->get_time_used(array('project_id' => $params['project_id']));
-
                                //echo 'boprojects->get_budget: time used 
project only:';
                                //_debug_array($h_pro);

@@ -709,14 +754,20 @@
                                $formatted_uhours_pro_bill              = 
$this->sohours->format_wh($uhours_pro_bill);
                                $formatted_uhours_pro_nobill    = 
$this->sohours->format_wh($uhours_pro_nobill);

-                               $acc['uhours_pro']                      = 
$formatted_uhours_pro['whwm'];
-                               $acc['uhours_pro_nobill']       = 
$formatted_uhours_pro_nobill['whwm'];
-                               $acc['uhours_pro_bill']         = 
$formatted_uhours_pro_bill['whwm'];
+                               $acc['uhours_pro']                      = 
$this->sohours->min2str($uhours_pro);
+                               $acc['uhours_pro_nobill']       = 
$this->sohours->min2str($uhours_pro_nobill);
+                               $acc['uhours_pro_bill']         = 
$this->sohours->min2str($uhours_pro_bill);
                                $acc['uhours_pro_wminutes']     = $uhours_pro;
+
+                               $acc['utime_item']                      = 
$uhours_pro;
+                               $acc['utime_item_nobill']       = 
$uhours_pro_nobill;
+                               $acc['utime_item_bill']         = 
$uhours_pro_bill;

                                $formatted_ahours_pro           = 
$this->sohours->format_wh($params['ptime'] - $uhours_pro);
                                $acc['ahours_pro']                      = 
$formatted_ahours_pro['whwm'];

+                               $acc['atime_item']                      = 
$params['ptime'] - $acc['ptime_jobs_min']- $uhours_pro;
+
                                //echo 'uhours_pro:' . $uhours_pro;
                                //_debug_array($acc);

@@ -764,8 +815,18 @@
                                $acc['uhours_jobs_bill']                = 
$formatted_uhours_jobs_bill['whwm'];
                                $acc['uhours_jobs_wminutes']    = $uhours_jobs;

+                               $acc['utime_sum']                               
= $uhours_jobs;
+                               $acc['utime_sum_nobill']                = 
$uhours_jobs_nobill;
+                               $acc['utime_sum_bill']                  = 
$uhours_jobs_bill;
+
                                $formatted_ahours_jobs          = 
$this->sohours->format_wh($params['ptime'] - $uhours_jobs);
                                $acc['ahours_jobs']                     = 
$formatted_ahours_jobs['whwm'];
+
+                               $acc['atime_sum']                       = 
$params['ptime'] - $uhours_jobs;
+
+                               $acc['b_budget'] = 0;
+                               $acc['nb_budget'] = 0;
+                               $acc['u_budget'] = 0;

                                if($params['page'] == 'budget')
                                {
@@ -848,8 +909,6 @@
                                                        case 'project':
                                                                $h_sub = 
$this->sohours->get_time_used(array('project_id' => $subs[$i]['project_id']));

-                                                               
//_debug_array($h_sub);
-
                                                                
if(is_array($h_sub))
                                                                {
                                                                        
foreach($h_sub as $hs)
@@ -858,7 +917,6 @@
                                                                                
{
                                                                                
        $sub_b_budget += $this->calculate_budget(array('factor' => 
$subs[$i]['acc_factor'],'minutes' => $hs['minutes'],
                                                                                
                                                                                
                        'surcharge' => $hs['surcharge']));
-                                                                               
        //echo 'sub_b_budget: ' . $sub_b_budget;
                                                                                
}
                                                                                
else
                                                                                
{
@@ -911,12 +969,11 @@
                                                }
                                                $nb_budget_jobs += 
$sub_nb_budget;
                                                $acc['b_budget_jobs'] += 
$sub_b_budget;
-
-                                               //echo 'nb_budget_jobs: ' . 
$nb_budget_jobs;
-                                               //echo 'b_budget_jobs: ' . 
$b_budget_jobs;
                                        }
                                        $acc['u_budget_jobs'] = 
$acc['b_budget_jobs'] + $nb_budget_jobs;
+                                       $acc['nb_budget_jobs'] = 
$nb_budget_jobs;
                                }
+
                                //_debug_array($acc);
                                return $acc;
                        }
@@ -928,7 +985,8 @@
                        {
                                case 'planned':                 $column = 
'project_id,parent,level,budget,time_planned'; break;
                                case 'hours':
-                               case 'budget':                  $column = 
'project_id,accounting,acc_factor,billable,level'; break;
+//                             case 'budget':                  $column = 
'project_id,accounting,acc_factor,billable,level'; break;
+                               case 'budget':                  $column = 
'project_id,parent,accounting,acc_factor,billable,level,budget,time_planned'; 
break;
                        }
                        $subs = $this->soprojects->read_projects(array('column' 
=> $column,'limit' => False,'action' => 'subs','parent' => 
$params['project_id']));

@@ -952,12 +1010,33 @@
                        //echo 'percent: ' . $used_percent . '<br>';

                        //echo 'used: ' . $used . '<br>';
+                       if($this->html_output && ($action == 'hours'))
+                       {
+                               $val = explode(".", $value);
+                               if(isset($val[1]) && $val[1] < 10)
+                               {
+                                       $value = $val[0].'.0'.$val[1];
+                               }
+
+                               $value = str_replace(".", ":", $value);
+                       }
+
+
                        if($this->html_output && ($used > $used_percent))
                        {
                        //echo 'used > $used_percent: ' . $used . '>' . 
$used_percent . '<br><br>';
-                               return '<font color="CC0000"><b>' . 
sprintf("%01.2f",$value) . '</b></font>';
+                               //return '<font color="CC0000"><b>' . 
sprintf("%01.2f",$value) . '</b></font>';
+                               return '<font color="CC0000"><b>' . $value . 
'</b></font>';
                        }
-                       return sprintf("%01.2f",$value);
+                       return $value;
+               }
+
+               function is_red($limit = 0, $used = 0, $action = 'budget')
+               {
+                       $event_extra = 
$this->soconfig->get_event_extra($action=='budget'?'budget limit':'hours 
limit');
+
+                       $used_percent = ($limit*intval($event_extra))/100;
+                       return ($used > $used_percent);
                }

                function formatted_priority($pri = 0)
@@ -979,6 +1058,10 @@
                        }
                        else
                        {
+                               if($this->order == 'coordinator' || 
$this->order == 'customer')
+                               {
+                                       $this->limit = false;
+                               }
                                $pro_list = 
$this->soprojects->read_projects(array
                                                                        (
                                                                                
'start'                 => $this->start,
@@ -1010,8 +1093,20 @@
                                        if ($pro['customer'])
                                        {
                                                $customer = 
$this->read_single_contact($pro['customer']);
-                               if ($customer[0]['org_name'] == '') { 
$customerout = $customer[0]['per_first_name'] . ' ' . 
$customer[0]['per_last_name']; }
-                               else { $customerout = $customer[0]['org_name'] 
. ' [ ' . $customer[0]['per_first_name'] . ' ' . $customer[0]['per_last_name'] 
. ' ]'; }
+                                               if($customer[0])
+                                               {
+                                                       $customerout = 
$customer[0]['per_first_name'] . ' ' . $customer[0]['per_last_name'];
+                                               }
+                                       }
+
+                                       $customerorgout = '';
+                                       if ($pro['customer_org'])
+                                       {
+                                               $customer_org = 
$this->read_single_contact_org($pro['customer_org']);
+                                               if ($customer_org[0])
+                                               {
+                                                       $customerorgout = 
$customer[0]['org_name'];
+                                               }
                                        }

                                        $mstones = 
$this->get_mstones($pro['project_id']);
@@ -1040,11 +1135,15 @@
                                                $acc = 
$this->get_budget($params);
                                        }

-                                       $uhours_pro             = 
$this->colored($acc['uhours_pro'],$pro['ptime'],$acc['uhours_pro_wminutes'],'hours');
-                                       $uhours_jobs    = 
$this->colored($acc['uhours_jobs'],$pro['ptime'],$acc['uhours_jobs_wminutes'],'hours');
+                                       $ptime_pro = $pro['ptime'] - 
$acc['ptime_jobs_min'];
+                                       $phours_pro = 
$this->colored($this->sohours->min2str($ptime_pro), $ptime_pro, 
$acc['uhours_pro_wminutes'], 'hours');
+
+                                       $uhours_pro             = 
$this->colored($this->sohours->min2str($acc['uhours_pro_wminutes']), 
$ptime_pro, $acc['uhours_pro_wminutes'], 'hours');

-                                       $ubudget_pro    = 
$this->colored($acc['u_budget'],$pro['budget'],$acc['u_budget']);
-                                       $ubudget_jobs   = 
$this->colored($acc['u_budget_jobs'],$pro['budget'],$acc['u_budget_jobs']);
+                                       $uhours_jobs    = 
$this->colored(str_replace(".", 
":",sprintf("%01.2f",$acc['uhours_jobs'])),$pro['ptime'],$acc['uhours_jobs_wminutes'],'hours');
+
+                                       $ubudget_pro    = $acc['u_budget'];
+                                       $ubudget_jobs   = $acc['u_budget_jobs'];

                                        $space = '';
                                        if ($pro['level'] > 0 && 
!isset($params['no_formatted_level']))
@@ -1062,6 +1161,7 @@
                                                'investment_nr'         => 
$GLOBALS['phpgw']->strip_html($pro['investment_nr']),
                                                'coordinatorout'        => 
$GLOBALS['phpgw']->common->grab_owner_name($pro['coordinator']),
                                                'customerout'           => 
$customerout,
+                                               'customerorgout'                
=> $customerorgout,
                                                'customer_nr'           => 
$GLOBALS['phpgw']->strip_html($pro['customer_nr']),
                                                'sdateout'                      
=> $this->formatted_edate($pro['sdate'],False),
                                                'edateout'                      
=> $this->formatted_edate($pro['edate']),
@@ -1070,9 +1170,12 @@
                                                'psdateout'                     
=> $this->formatted_edate($pro['psdate'],False),
                                                'pedateout'                     
=> $this->formatted_edate($pro['pedate'],False),
                                                'previousout'           => 
$this->return_value('pro',$pro['previous']),
-                                               'phours'                        
=> ($pro['ptime']/60) . '.00',
+//                                             'phours'                        
=> intval($pro['ptime']/60) . ':00',
+                                               'phours_childs'                 
=> intval($pro['ptime_childs']/60) . ':00',
                                                'budget'                        
=> $pro['budget'],
+                                               'budget_childs'                 
=> $pro['budget_childs'],
                                                'e_budget'                      
=> $pro['e_budget'],
+                                               'e_budget_childs'               
        => $pro['e_budget_childs'],
                                                'url'                           
=> $GLOBALS['phpgw']->strip_html($pro['url']),
                                                'reference'                     
=> $GLOBALS['phpgw']->strip_html($pro['reference']),
                                                'accountingout'         => 
lang('per') . ' ' . lang($pro['accounting']),
@@ -1088,25 +1191,88 @@
                                                'previous'                      
=> $pro['previous'],
                                                'status'                        
=> $pro['status'],
                                                'level'                         
=> $pro['level'],
-                                               'uhours_pro'            => 
$uhours_pro,      //$acc['uhours_pro']?$acc['uhours_pro']:'0.00',
-                                               'uhours_pro_nobill'     => 
$acc['uhours_pro_nobill']?$acc['uhours_pro_nobill']:'0.00',
-                                               'uhours_pro_bill'       => 
$acc['uhours_pro_bill']?$acc['uhours_pro_bill']:'0.00',
-                                               'uhours_jobs'           => 
$uhours_jobs,     //$acc['uhours_jobs']?$acc['uhours_jobs']:'0.00',
-                                               'uhours_jobs_nobill'=> 
$acc['uhours_jobs_nobill']?$acc['uhours_jobs_nobill']:'0.00',
-                                               'uhours_jobs_bill'      => 
$acc['uhours_jobs_bill']?$acc['uhours_jobs_bill']:'0.00',
-                                               'ahours_pro'            => 
$acc['ahours_pro']?$acc['ahours_pro']:'0.00',
-                                               'ahours_jobs'           => 
$acc['ahours_jobs']?$acc['ahours_jobs']:'0.00',
+                                               'uhours_pro'            => 
$uhours_pro,      //$acc['uhours_pro']?$acc['uhours_pro']:'0:00',
+                                               'uhours_pro_nobill'     => 
$acc['uhours_pro_nobill']?$acc['uhours_pro_nobill']:'0:00',
+                                               'uhours_pro_bill'       => 
$acc['uhours_pro_bill']?$acc['uhours_pro_bill']:'0:00',
+                                               'uhours_jobs'           => 
$uhours_jobs,     //$acc['uhours_jobs']?$acc['uhours_jobs']:'0:00',
+                                               'uhours_jobs_nobill'=> 
$acc['uhours_jobs_nobill']?str_replace(".", 
":",sprintf("%01.2f",$acc['uhours_jobs_nobill'])):'0:00',
+                                               'uhours_jobs_bill'      => 
$acc['uhours_jobs_bill']?str_replace(".", 
":",sprintf("%01.2f",$acc['uhours_jobs_bill'])):'0:00',
+                                               'ahours_pro'            => 
$ahours_pro,
+                                               'ahours_jobs'           => 
$ahours_jobs,
                                                'u_budget'                      
=> $ubudget_pro,     //$acc['u_budget']?$acc['u_budget']:'0.00',
                                                'u_budget_jobs'         => 
$ubudget_jobs,    //$acc['u_budget_jobs']?$acc['u_budget_jobs']:'0.00',
                                                'a_budget'                      
=> $pro['budget']-$acc['u_budget'],
                                                'a_budget_jobs'         => 
$pro['budget']-$acc['u_budget_jobs'],
                                                'b_budget'                      
=> $acc['b_budget']?$acc['b_budget']:'0.00',
                                                'b_budget_jobs'         => 
$acc['b_budget_jobs']?$acc['b_budget_jobs']:'0.00',
+
+                                               /* AS: new version values with 
a stricter naming scheme (others should be deprecated but may still be in use 
somewhere) */
+                                               'item_planned_time'     => 
$pro['ptime'] - $acc['ptime_jobs_min'],
+                                               'item_used_time'        => 
$acc['utime_item'],
+                                               'item_bill_time'        => 
$acc['utime_item_bill'],
+                                               'item_nobill_time'      => 
$acc['utime_item_nobill'],
+                                               'item_avail_time'       => 
$acc['atime_item'],
+                                               'sum_planned_time'      => 
$pro['ptime'],
+                                               'sum_used_time'         => 
$acc['utime_sum'],
+                                               'sum_bill_time'         => 
$acc['utime_sum_bill'],
+                                               'sum_nobill_time'       => 
$acc['utime_sum_nobill'],
+                                               'sum_avail_time'        => 
$acc['atime_sum'],
+                                               'is_leaf'                       
=> $acc['is_leaf'],
+
+                                               'item_planned_budget' => 
$pro['budget']-$acc['pbudget_jobs'],
+                                               'item_used_budget'    => 
$ubudget_pro,
+                                               'item_bill_budget'    => 
$acc['b_budget']?$acc['b_budget']:'0.00',
+                                               'item_nobill_budget'    => 
$acc['nb_budget']?$acc['nb_budget']:'0.00',
+                                               'item_avail_budget'   => 
$pro['budget']-$acc['pbudget_jobs']-$acc['u_budget'],
+                                               'sum_planned_budget'  => 
$pro['budget'],
+                                               'sum_used_budget'    => 
$ubudget_jobs,
+                                               'sum_bill_budget'    => 
$acc['b_budget_jobs']?$acc['b_budget_jobs']:'0.00',
+                                               'sum_nobill_budget'    => 
$acc['nb_budget_jobs']?$acc['nb_budget_jobs']:'0.00',
+                                               'sum_avail_budget'   => 
$pro['budget']-$acc['u_budget_jobs'],
+
+/*
+planned_subs=planned_sum-planned_item
+used_subs=used_sum-used_item
+*/
+                                               'sum_time_status'       => 
$this->is_red($pro['ptime'], $acc['utime_sum'], 'time') ? 'red' : 
($this->is_red($acc['ptime_jobs_min'], $acc['utime_sum']-$acc['utime_item'], 
'time') ? 'yellow':'green'),
+                                               'item_time_status'      => 
$this->is_red($pro['ptime'] - $acc['ptime_jobs_min'], $acc['utime_item'], 
'time') ? 'red' : ($this->is_red($acc['ptime_jobs_min'], 
$acc['utime_sum']-$acc['utime_item'], 'time') ? 'yellow':'green'),
+
+                                               'sum_budget_status'     => 
$this->is_red($pro['budget'], $ubudget_jobs, 'budget') ? 'red' : 
($this->is_red($acc['pbudget_jobs'], $ubudget_jobs-$ubudget_pro, 'budget') ? 
'yellow':'green'),
+                                               'item_budget_status'=> 
$this->is_red($pro['budget']-$acc['pbudget_jobs'], $ubudget_pro, 'budget') ? 
'red' : ($this->is_red($acc['pbudget_jobs'], $ubudget_jobs-$ubudget_pro, 
'budget') ? 'yellow':'green')
                                        );
                                }
                        }
+
+                       switch($this->order)
+                       {
+                               case 'coordinator':
+                                       usort($projects, array('boprojects', 
'cmp_projects_coordinator'));
+                                       if($this->sort == 'DESC')
+                                       {
+                                               $projects = 
array_reverse($projects);
+                                       }
+                               break;
+                               case 'customer':
+                                       usort($projects, array('boprojects', 
'cmp_projects_customer'));
+                                       if($this->sort == 'DESC')
+                                       {
+                                               $projects = 
array_reverse($projects);
+                                       }
+                               break;
+                       }
+
                        return $projects;
                }
+
+               function cmp_projects_coordinator($a, $b)
+               {
+                       return strcasecmp($a['coordinatorout'], 
$b['coordinatorout']);
+               }
+
+               function cmp_projects_customer($a, $b)
+               {
+                       return strcasecmp($a['coordinatorout'], 
$b['coordinatorout']);
+               }

                function format_date($date = 0)
                {
@@ -1155,9 +1321,15 @@
                }

                function read_single_project($project_id,$page = 'bla',$action 
= 'subs')
-               {
+               {
                        $pro = 
$this->soprojects->read_single_project($project_id);

+                       if (!is_array($pro))
+                       {
+                               return False;
+                       }
+
+/* fix empty field in view project
                        $check_pro = array
                        (
                                'coordinator'   => $pro['coordinator'],
@@ -1165,13 +1337,12 @@
                                'parent'                => $pro['parent'],
                                'action'                => 
($pro['parent']>0?'subs':'mains')
                        );
-
                        $perms = $this->edit_perms($check_pro);
-
-                       if (!$perms || !is_array($pro))
+                       if (!$perms)
                        {
                                return False;
                        }
+*/

                        if($page == 'budget' || $page == 'hours' || $page = 
'planned')
                        {
@@ -1185,11 +1356,15 @@

                        $ubudget_pro    = 
$this->colored($acc['u_budget'],$pro['budget'],$acc['u_budget']);
                        $ubudget_jobs   = 
$this->colored($acc['u_budget_jobs'],$pro['budget'],$acc['u_budget_jobs']);
+                       $ubudget_pro    = $acc['u_budget'];
+                       $ubudget_jobs   = $acc['u_budget_jobs'];

                        $project = array
                        (
-                               'ptime'                         => 
($pro['ptime']/60) . '.00',
+                               'ptime'                         => 
intval($pro['ptime']/60),
+                               'ptime_childs'  => 
intval($pro['ptime_childs']/60),
                                'ptime_min'                     => 
$pro['ptime'],
+                               'ptime_min_childs'      => $pro['ptime_childs'],
                                'ptime_jobs'            => $acc['ptime_jobs'],
                                'atime'                         => 
$atime['whwm'],
                                'title'                         => 
$GLOBALS['phpgw']->strip_html($pro['title']),
@@ -1197,6 +1372,9 @@
                                'investment_nr'         => 
$GLOBALS['phpgw']->strip_html($pro['investment_nr']),
                                'descr'                         => 
$GLOBALS['phpgw']->strip_html($pro['descr']),
                                'budget'                        => 
$pro['budget'],
+                               'budget_childs'         => 
$pro['budget_childs'],
+                               'e_budget'                      => 
$pro['e_budget'],
+                               'e_budget_childs'               => 
$pro['e_budget_childs'],
                                'pbudget_jobs'          => 
$acc['pbudget_jobs']?$acc['pbudget_jobs']:'0.00',
                                'ap_budget_jobs'        => 
$pro['budget']-$acc['pbudget_jobs'],
                                'a_budget'                      => 
$pro['budget']-$acc['u_budget'],
@@ -1211,6 +1389,7 @@
                                'coordinator'           => $pro['coordinator'],
                                'coordinatorout'        => 
$GLOBALS['phpgw']->common->grab_owner_name($pro['coordinator']),
                                'customer'                      => 
$pro['customer'],
+                               'customer_org'                  => 
$pro['customer_org'],
                                'status'                        => 
$pro['status'],
                                'owner'                         => 
$pro['owner'],
                                'processor'                     => 
$pro['processor'],
@@ -1225,15 +1404,17 @@
                                'project_accounting_factor'     => 
$pro['project_accounting_factor'],
                                'project_accounting_factor_d'   => 
$pro['project_accounting_factor_d'],
                                'billable'                      => 
$pro['billable'],
-                               'uhours_pro'            => $uhours_pro,         
 //$acc['uhours_pro']?$acc['uhours_pro']:'0.00',
-                               'uhours_pro_nobill'     => 
$acc['uhours_pro_nobill']?$acc['uhours_pro_nobill']:'0.00',
-                               'uhours_pro_bill'       => 
$acc['uhours_pro_bill']?$acc['uhours_pro_bill']:'0.00',
-                               'uhours_jobs'           => $uhours_jobs,        
  //$acc['uhours_jobs']?$acc['uhours_jobs']:'0.00',
-                               'uhours_jobs_nobill'=> 
$acc['uhours_jobs_nobill']?$acc['uhours_jobs_nobill']:'0.00',
-                               'uhours_jobs_bill'      => 
$acc['uhours_jobs_bill']?$acc['uhours_jobs_bill']:'0.00',
+                               'plan_bottom_up' => (($pro['plan_bottom_up'] == 
'Y')?'Y':'N'),
+                               'direct_work'           =>  
(($pro['direct_work'] == 'Y')?'Y':'N'),
+                               'uhours_pro'            => $uhours_pro,         
 //$acc['uhours_pro']?$acc['uhours_pro']:'0:00',
+                               'uhours_pro_nobill'     => 
$acc['uhours_pro_nobill']?$acc['uhours_pro_nobill']:'0:00',
+                               'uhours_pro_bill'       => 
$acc['uhours_pro_bill']?$acc['uhours_pro_bill']:'0:00',
+                               'uhours_jobs'           => $uhours_jobs,        
  //$acc['uhours_jobs']?$acc['uhours_jobs']:'0:00',
+                               'uhours_jobs_nobill'=> 
$acc['uhours_jobs_nobill']?$acc['uhours_jobs_nobill']:'0:00',
+                               'uhours_jobs_bill'      => 
$acc['uhours_jobs_bill']?$acc['uhours_jobs_bill']:'0:00',
                                'uhours_jobs_wminutes'  => 
$acc['uhours_jobs_wminutes']?$acc['uhours_jobs_wminutes']:0,
-                               'ahours_pro'            => 
$acc['ahours_pro']?$acc['ahours_pro']:'0.00',
-                               'ahours_jobs'           => 
$acc['ahours_jobs']?$acc['ahours_jobs']:'0.00',
+                               'ahours_pro'            => 
$acc['ahours_pro']?$acc['ahours_pro']:'0:00',
+                               'ahours_jobs'           => 
$acc['ahours_jobs']?$acc['ahours_jobs']:'0:00',
                                'priority'                      => 
$pro['priority'],
                                'inv_method'            => 
$GLOBALS['phpgw']->strip_html($pro['inv_method']),
                                'discount'                      => 
$pro['discount'],
@@ -1264,13 +1445,27 @@
                        $project['psdate']                              = 
$date['date'];
                        $project['psdate_formatted']    = 
$date['date_formatted'];

-                       if ($pro['customer'] > 0)
+                       $customerout = '';
+                       if ($pro['customer'] > 0)
                        {
                                $customer = 
$this->read_single_contact($pro['customer']);
-               if ($customer[0]['org_name'] == '') { $project['customerout'] = 
$customer[0]['per_first_name'] . ' ' . $customer[0]['per_last_name']; }
-               else { $project['customerout'] = $customer[0]['org_name'] . ' [ 
' . $customer[0]['per_first_name'] . ' ' . $customer[0]['per_last_name'] . ' 
]'; }
+                               if($customer[0])
+                               {
+                                       $customerout = 
$customer[0]['per_first_name'] . ' ' . $customer[0]['per_last_name'];
+                               }
+                       }
+                       $project['customerout'] = $customerout;
+
+                       $customerorgout = '';
+                       if ($pro['customer_org'] > 0)
+                       {
+                               $customer_org = 
$this->read_single_contact_org($pro['customer_org']);
+                               if ($customer_org[0])
+                               {
+                                       $customerorgout = 
$customer[0]['org_name'];
+                               }
                        }
-                       else { $project['customerout'] = '&nbsp;'; }
+                       $project['customerorgout'] = $customerorgout;

                        //_debug_array($project);
                        return $project;
@@ -1295,9 +1490,9 @@
                                                                        ));
                }

-               function exists($action, $check, $num, $pa_id)
+               function exists($params)
                {
-                       return $this->soprojects->exists($action, $check , 
$num, $pa_id);
+                       return $this->soprojects->exists($params);
                }

                function check_values($action, $values)
@@ -1312,9 +1507,9 @@
                                $error[] = lang('please choose a project 
coordinator');
                        }

-                       if(strlen($values['title']) == 0)
+                       if (strlen(trim($values['title'])) == 0)
                        {
-                               $error[] = lang('please enter a title');
+                               $error[] = lang('Please enter a title');
                        }
                        else if(strlen($values['title']) > 250)
                        {
@@ -1325,7 +1520,7 @@
                        {
                                if (! $values['number'])
                                {
-                                       $error[] = lang('Please enter an ID');
+                                       $error[] = lang('Please enter the 
project id');
                                }
                                else
                                {
@@ -1343,7 +1538,8 @@
                                        $error[] = lang('please choose 
activities for the project');
                                }
                        }
-                       else if(!$values['billable'])
+                       //else if(!$values['billable'])
+                       else
                        {
                                if(!$values['accounting'])
                                {
@@ -1351,13 +1547,31 @@
                                }
                                else
                                {
-                                       if($values['accounting'] == 'project' 
&& !$values['project_accounting_factor'] && 
!$values['project_accounting_factor_d'])
+                                       if($values['accounting'] == 'project' 
&& ($values['project_accounting_factor'] == 0) && 
($values['project_accounting_factor_d'] == 0))
                                        {
                                                $error[] = lang('please set the 
accounting factor for the project');
                                        }
                                }
                        }

+                       if(isset($values['project_id']) && 
($values['project_id']>0))
+                       {
+                               $project = 
$this->read_single_project($values['project_id']);
+                       }
+                       else
+                       {
+                               $project = false;
+                       }
+
+                       if(isset($values['parent']) && ($values['parent']>0))
+                       {
+                               $parent = 
$this->read_single_project($values['parent']);
+                       }
+                       else
+                       {
+                               $parent = false;
+                       }
+
                        $values['discount'] = 
($values['discount']=='0.00')?0:$values['discount'];
                        if($values['discount'] > 0 && !$values['discount_type'])
                        {
@@ -1374,9 +1588,9 @@
                                }
                        }

-                       if ($action == 'subs')
+                       if (($action == 'subs') && ($values['plan_bottom_up'] 
== 'N') && $parent)
                        {
-                               $main_edate = 
$this->return_value('edate',$values['parent']);
+                               $main_edate = $parent['edate']; 
//$this->return_value('edate',$values['parent']);

                                if ($main_edate > 0)
                                {
@@ -1386,7 +1600,7 @@
                                        }
                                }

-                               $main_sdate = 
$this->return_value('sdate',$values['parent']);
+                               $main_sdate = $parent['sdate']; 
//$this->return_value('sdate',$values['parent']);

                                if ($main_sdate > 0 && $values['sdate'] > 0)
                                {
@@ -1396,7 +1610,7 @@
                                        }
                                }

-                               $main_pedate = 
$this->return_value('pedate',$values['parent']);
+                               $main_pedate = $parent['pedate']; 
//$this->return_value('pedate',$values['parent']);

                                if ($main_pedate > 0)
                                {
@@ -1406,7 +1620,7 @@
                                        }
                                }

-                               $main_psdate = 
$this->return_value('psdate',$values['parent']);
+                               $main_psdate = $parent['psdate']; 
//$this->return_value('psdate',$values['parent']);

                                if ($main_psdate > 0 && $values['psdate'] > 0)
                                {
@@ -1432,25 +1646,33 @@
                                        }
                                }

-                               $ptime_parent   = 
$this->soprojects->return_value('ptime',$values['parent']);
-                               $sum_ptime              = 
$this->soprojects->get_planned_value(array('action' => 'tparent','parent_id' => 
$values['parent']
-                                                                               
                                                        ,'project_id' => 
$values['project_id']));
-                               $pminutes = intval($values['ptime'])*60;
+                               $ptime_parent = $parent['ptime_min'];  
//$this->soprojects->return_value('ptime',$values['parent']);
+                               if($values['project_id'])
+                               {
+                                       $sum_ptime = 
$this->soprojects->get_planned_value(array('action' => 'tparent','parent_id' => 
$values['parent']
+                                                                               
                                ,'project_id' => $values['project_id']));

+                               }
+                               else
+                               {
+                                       $sum_ptime = 0;
+                               }
+
+                               $pminutes = intval($values['ptime'])*60;
                                if (($pminutes+$sum_ptime) > $ptime_parent)
                                {
                                        $error[] = lang('planned time sum of 
all sub projects is bigger than the planned time of the main project');
                                }

-                               $budget_parent  = 
$this->soprojects->return_value('budget',$values['parent']);
-                               $sum_budget             = 
$this->soprojects->get_planned_value(array('action' => 'bparent','parent_id' => 
$values['parent']
+                               $budget_parent = $parent['budget'];  
//$this->soprojects->return_value('budget',$values['parent']);
+                               $sum_budget    = 
$this->soprojects->get_planned_value(array('action' => 'bparent','parent_id' => 
$values['parent']
                                                                                
                                                        ,'project_id' => 
$values['project_id']));
                                if (($values['budget']+$sum_budget) > 
$budget_parent)
                                {
                                        $error[] = lang('budget sum of all sub 
projects is bigger than the budget of the main project');
                                }

-                               $ebudget_parent = 
$this->soprojects->return_value('e_budget',$values['parent']);
+                               $ebudget_parent = $parent['e_budget'];  
//$this->soprojects->return_value('e_budget',$values['parent']);
                                $sum_ebudget    = 
$this->soprojects->get_planned_value(array('action' => 'ebparent','parent_id' 
=> $values['parent']
                                                                                
                                                        ,'project_id' => 
$values['project_id']));
                                if (($values['e_budget']+$sum_ebudget) > 
$ebudget_parent)
@@ -1459,6 +1681,101 @@
                                }
                        }

+                       if($values['sdate'] > 0 && $values['edate'] > 0)
+                       {
+                               if($values['edate'] < $values['sdate'])
+                               {
+                                       $error[] = lang('end date can not be 
before start date');
+                               }
+                       }
+
+                       if($values['psdate'] > 0 && $values['pedate'] > 0)
+                       {
+                               if($values['pedate'] < $values['psdate'])
+                               {
+                                       $error[] = lang('end date planned can 
not be before start date planned');
+                               }
+                       }
+
+                       // check values against sub project data
+                       $sdate    = $values['sdate'];  // start date
+                       $psdate   = $values['psdate']; // planed start date
+                       $edate    = $values['edate'];  // end date
+                       $pedate   = $values['pedate']; // planed end date
+                       $ptime    = 0.0;    // planed time
+                       $budget   = 0.0;    // budget
+                       $e_budget = 0.0;    // extra budget
+
+                       // get sub jobs
+                       $subs = $this->get_sub_projects(array('project_id' => 
$values['project_id']));
+
+                       // for each sub project
+                       while($values['project_id'] && (list($subNum, $subData) 
= each($subs)))
+                       {
+                               // get planned dates (earliest start and latest 
end date) and workhours and budget
+                               if(isset($subData['sdate']) && 
($subData['sdate'] < $sdate))
+                                       $sdate = $subData['sdate'];
+                               if(isset($subData['psdate']) && 
($subData['psdate'] < $psdate))
+                                       $psdate = $subData['psdate'];
+                               if(isset($subData['edate']) && 
($subData['edate'] > $edate))
+                                       $edate = $subData['edate'];
+                               if(isset($subData['pedate']) && 
($subData['pedate'] > $pedate))
+                                       $pedate = $subData['pedate'];
+                               $ptime    += $subData['ptime'];
+                               $budget   += $subData['budget'];
+                               $e_budget += $subData['e_budget'];
+                       }
+
+                       if($values['smonth'] || $values['sday'] || 
$values['syear'])
+                       {
+                               if($sdate < 
mktime(12,0,0,$values['smonth'],$values['sday'],$values['syear']))
+                               {
+                                       $error[] = lang('start date can not be 
after sub projects start date');
+                               }
+                       }
+
+                       if($values['psmonth'] || $values['psday'] || 
$values['psyear'])
+                       {
+                               if($psdate < 
mktime(12,0,0,$values['psmonth'],$values['psday'],$values['psyear']))
+                               {
+                                       $error[] = lang('planned start date can 
not be after sub projects planned start date');
+                               }
+                       }
+
+                       if($values['emonth'] || $values['eday'] || 
$values['eyear'])
+                       {
+                               if($edate > 
mktime(12,0,0,$values['emonth'],$values['eday'],$values['eyear']))
+                               {
+                                       $error[] = lang('end date can not be 
before sub projects end date');
+                               }
+                       }
+
+                       if($values['pemonth'] || $values['peday'] || 
$values['peyear'])
+                       {
+                               if($pedate > 
mktime(12,0,0,$values['pemonth'],$values['peday'],$values['peyear']))
+                               {
+                                       $error[] = lang('planned end date can 
not be before sub projects planned end date');
+                               }
+                       }
+
+                       if($values['plan_bottom_up'] == 'N')
+                       {
+                               if($ptime > (intval($values['ptime'])*60))
+                               {
+                                       $error[] = lang('planned time can not 
be lesser then planned time sum of all sub projects');
+                               }
+
+                               if($budget > $values['budget'])
+                               {
+                                       $error[] = lang('budget can not be 
lesser then budget sum of all sub projects');
+                               }
+
+                               if($e_budget > $values['e_budget'])
+                               {
+                                       $error[] = lang('extra budget can not 
be lesser then extra budget sum of all sub projects');
+                               }
+                       }
+
                        if (is_array($error))
                        {
                                return $error;
@@ -1478,13 +1795,14 @@
                                }
                        }

-                       $values['ptime'] = intval($values['ptime'])*60;
-
-            if (!$values['sdate'])
-            {
-                $values['sdate'] = time();
-            }
+                       /*
+                       if (!$values['sdate'])
+                       {
+                           $values['sdate'] = time();
+                       }
+                       */

+                       $values['sdate'] = intval($values['sdate']);
                        $values['edate'] = intval($values['edate']);

                        if (!$values['previous'] && $values['parent'])
@@ -1492,23 +1810,82 @@
                                $values['previous'] = 
$this->return_value('previous',$values['parent']);
                        }

-                       if ($values['project_accounting_factor'] || 
$values['project_accounting_factor_d'])
+                       $values['ptime']  = intval($values['ptime']);
+                       $values['budget'] = round($values['budget'], 2);
+
+                       if ($values['accounting'] == 'project')
                        {
-                               switch($values['radio_acc_factor'])
+                               if ($values['project_accounting_factor'] || 
$values['project_accounting_factor_d'])
                                {
-                                       case 'day':             
$values['project_accounting_factor']    = 
$values['project_accounting_factor_d']/$this->siteconfig['hwday']; break;
-                                       default:                
$values['project_accounting_factor_d']  = 
$values['project_accounting_factor']*$this->siteconfig['hwday']; break;
+                                       switch($values['radio_acc_factor'])
+                                       {
+                                               case 'day':             
$values['project_accounting_factor']    = 
$values['project_accounting_factor_d']/$this->siteconfig['hwday']; break;
+                                               default:                
$values['project_accounting_factor_d']  = 
$values['project_accounting_factor']*$this->siteconfig['hwday']; break;
+                                       }
+
+                                       if(($values['budgetradio'] == 'm') && 
($values['project_accounting_factor'] > 0))
+                                       {
+                                                       $values['ptime'] = 
intval($values['budget'] / $values['project_accounting_factor']);
+                                       }
+                                       elseif($values['budgetradio'] == 'h')
+                                       {
+                                               $values['budget'] = 
$values['ptime'] * $values['project_accounting_factor'];
+                                       }
+                                       else
+                                       {
+                                               $values['ptime'] = 0;
+                                               $values['budget'] = 0.0;
+                                       }
                                }
                        }

+                       $values['ptime'] = $values['ptime'] * 60;
+
                        //echo 'start boprojects: save_project ->';
                        //_debug_array($values);
                        //echo 'end boprojects: save_project';

+                       if(isset($values['plan_bottom_up']) && 
($values['plan_bottom_up'] == 'Y'))
+                       {
+                               $values['plan_bottom_up'] = 'Y';
+                       }
+                       else
+                       {
+                               $values['plan_bottom_up'] = 'N';
+                       }
+
+                       if(isset($values['direct_work']) && 
($values['direct_work'] == 'Y'))
+                       {
+                               $values['direct_work'] = 'Y';
+                       }
+                       else
+                       {
+                               $values['direct_work'] = 'N';
+                       }
+
+                       if (isset($values['discount_type']) && 
($values['discount_type'] == 'no'))
+                       {
+                               $values['discount'] = 0.0;
+                       }
+
                        $values['project_name'] = $values['title'] . ' [' . 
$values['number'] . ']';
                        if (intval($values['project_id']) > 0)
                        {
+                               // get old project values for later calculation
+                               $old_pro = 
$this->soprojects->read_single_project($values['project_id']);
+                               $values['ptime_childs']    = 
$old_pro['ptime_childs'];
+                               $values['budget_childs']   = 
$old_pro['budget_childs'];
+                               $values['e_budget_childs'] = 
$old_pro['e_budget_childs'];
+
+                               // calc new_value - old_value
+                               $changed_values = array(
+                                       'ptime'    => $values['ptime']    - 
$old_pro['ptime'],
+                                       'budget'   => $values['budget']   - 
$old_pro['budget'],
+                                       'e_budget' => $values['e_budget'] - 
$old_pro['e_budget']
+                               );
+
                                $following = 
$this->soprojects->edit_project($values);
+                               $this->update_parent($old_pro['parent'], 
$changed_values);

                                if(is_array($following))
                                {
@@ -1539,7 +1916,25 @@
                        }
                        else
                        {
+                               // new project -> no old project values 
available
+
+                               $values['ptime_childs']    = 0;
+                               $values['budget_childs']   = 0;
+                               $values['e_budget_childs'] = 0;
+
                                $values['project_id'] = 
$this->soprojects->add_project($values);
+
+                               // if parent isset we its a new sub project 
else its a new main project
+                               if(isset($values['parent']) && 
($values['parent']>0))
+                               { // for a new subproject update the parent 
project
+                                       // calc new_value - old_value (old 
values doesnt exists!)
+                                       $changed_values = array(
+                                               'ptime'    => $values['ptime'],
+                                               'budget'   => $values['budget'],
+                                               'e_budget' => 
$values['e_budget']
+                                       );
+                                       $this->update_parent($values['parent'], 
$changed_values);
+                               }
                        }

                        $values['project_id'] = intval($values['project_id']);
@@ -1570,15 +1965,26 @@
                        }
                        unset($async);

-                       //_debug_array($values['employees']);
                        if (is_array($values['employees']))
                        {
+                               $tmp = $values['employees'];
+                               $values['employees'] = array_unique($tmp);
                                
$this->soprojects->delete_acl($values['project_id']);
                                for($i=0;$i<count($values['employees']);$i++)
                                {
-                                       
$GLOBALS['phpgw']->acl->add_repository('projects',$values['project_id'],$values['employees'][$i],7);
+                                       
$GLOBALS['phpgw']->acl->add_repository('project_members',$values['project_id'],$values['employees'][$i],7);
                                }
                        }
+
+                       if($action == 'mains')
+                       {
+                               // update plan bottom up setting for all jobs 
of this project
+                               
$this->plan_bottom_up_set_job_setting($values['project_id'], 
$values['plan_bottom_up']);
+
+                               // update direct work setting for all jobs of 
this project
+                               
$this->direct_work_set_job_setting($values['project_id'], 
$values['direct_work']);
+                       }
+
                        return $values['project_id'];
                }

@@ -1589,6 +1995,8 @@

                function delete_project($pa_id, $subs, $action = 'pro')
                {
+                       $project = $this->read_single_project($pa_id);
+
                        if ($action == 'account')
                        {
                                
$this->soprojects->delete_account_project_data($pa_id);
@@ -1597,6 +2005,18 @@
                        {
                                $this->soprojects->delete_project($pa_id, 
$subs);
                        }
+
+                       // update parent
+                       if(isset($project['parent']) && ($project['parent']>0))
+                       { // update the parent project
+                               // calc new_value - old_value (when deleting 
the project the new values are zero)
+                               $changed_values = array(
+                                       'ptime'    => 0 - 60*($project['ptime'] 
   + $project['ptime_childs']   ),
+                                       'budget'   => 0 - ($project['budget']   
+ $project['budget_childs']  ),
+                                       'e_budget' => 0 - ($project['e_budget'] 
+ $project['e_budget_childs'])
+                               );
+                               $this->update_parent($project['parent'], 
$changed_values);
+                       }
                }

                function change_owner($old, $new)
@@ -1631,34 +2051,48 @@

                function check_mstone($values)
                {
-
-                       if (strlen($values['title']) == 0)
+                       if (strlen(trim($values['title'])) == 0)
                        {
                                $error[] = lang('please enter a title');
                        }
-                       else if (strlen($values['title']) > 250)
+
+                       if (strlen($values['title']) > 250)
                        {
                                $error[] = lang('title can not exceed 250 
characters in length');
                        }
+
                        if (intval($values['edate']) == 0)
                        {
                                $error[] = lang('please specify the date due');
                        }
                        else
                        {
+                               $pro_sdate = 
$this->return_value('sdate',$values['project_id']);
                                $pro_edate = 
$this->return_value('edate',$values['project_id']);
                                if ($pro_edate > 0)
                                {
                                        if ($values['edate'] > $pro_edate)
                                        {
-                                               $error[] = lang('end date can 
not be after projects date due');
+                                               $error[] = lang('milestone date 
can not be after projects date due');
+                                       }
+                               }
+                               if ($pro_sdate > 0)
+                               {
+                                       if ($values['edate'] < $pro_sdate)
+                                       {
+                                               $error[] = lang('milestone date 
can not be before projects date due');
                                        }
                                }
                        }
+
                        if(is_array($error))
                        {
                                return $error;
                        }
+                       else
+                       {
+                               return True;
+                       }
                }

                function save_mstone($values)
@@ -1890,7 +2324,7 @@
                                        );

                                        $param_list = '';
-                                       $is_first_param = true;
+                                       $is_first_param = True;

                                        foreach($link_data as $param_name => 
$param_val)
                                        {
@@ -1900,7 +2334,8 @@
                                                $is_first_param = false;
                                        }

-                                       $msg .= "\n\n" . 'http://' . 
$_SERVER['SERVER_NAME'] . $GLOBALS['phpgw_info']['server']['webserver_url'] . 
'/login.php' . $param_list;
+                                       $_SERVER['HTTP_HOST'] = 
'projektmanagement.hannover';
+                                       $msg .= "\n\n" . 'http://' . 
$_SERVER['HTTP_HOST'] . $GLOBALS['phpgw_info']['server']['webserver_url'] . 
'/login.php' . $param_list;
                                        //$msg .= "\n\n" . 
$GLOBALS['phpgw']->link('/index.php',$link_data);

                                        if($send_alarm)
@@ -1920,7 +2355,7 @@
                                                        $GLOBALS['phpgw']->send 
= CreateObject('phpgwapi.send');
                                                }

-                                               
print_debug('UserID',$emp['account_id']);
+                                               
//print_debug('UserID',$emp['account_id']);

                                                $to = 
$prefs->email_address($emp_events[$k]['account_id']);

@@ -1981,9 +2416,6 @@

                function read_prefs($default = True)
                {
-                       //$GLOBALS['phpgw']->preferences->read_repository();
-
-                       $prefs = array();
                        if 
(isset($GLOBALS['phpgw_info']['user']['preferences']['projects']['columns']))
                        {
                                $cols = 
$GLOBALS['phpgw_info']['user']['preferences']['projects']['columns'];
@@ -1993,6 +2425,25 @@
                        {
                                $prefs['columns'] = 
array('priority','number','customerout','coordinatorout','edateout');
                        }
+
+                       if 
(isset($GLOBALS['phpgw_info']['user']['preferences']['projects']['cscolumns']))
+                       {
+                               $prefs['cscolumns'] = 
explode(',',$GLOBALS['phpgw_info']['user']['preferences']['projects']['cscolumns']);
+                       }
+                       else if($default)
+                       {
+                               $prefs['cscolumns'] = array('title');
+                       }
+
+                       if 
(isset($GLOBALS['phpgw_info']['user']['preferences']['projects']['mailTypeEntries']))
+                       {
+                               $prefs['mailTypeEntries'] = 
explode(',',$GLOBALS['phpgw_info']['user']['preferences']['projects']['mailTypeEntries']);
+                       }
+                       else if($default)
+                       {
+                               $prefs['mailTypeEntries'] = array('');
+                       }
+
                        $prefs['currency'] = 
$GLOBALS['phpgw_info']['user']['preferences']['common']['currency'];
                        $prefs['mainscreen_showevents'] = 
$GLOBALS['phpgw_info']['user']['preferences']['projects']['mainscreen_showevents'];

@@ -2013,9 +2464,9 @@
                                $error[] = lang('please choose the columns to 
list in the projects preferences section');
                        }

-                       $config = $this->soprojects->get_site_config(False);
+                       $config = 
$this->soprojects->soconfig->get_site_config(array('default' => False));

-                       if (! isset($config['accounting']))
+                       if (!isset($config['accounting']))
                        {
                                $error[] = lang('if you are an administrator, 
please edit the site configuration for projects in the admin section');
                                $error[] = lang('if you are not an 
administrator, please inform the administrator to configure projects');
@@ -2047,7 +2498,7 @@
                                                for 
($i=0;$i<count($emp['events']);$i++)
                                                {
                                                        $e = 
$this->soprojects->id2item(array('action' => 'event','item_id' => 
$emp['events'][$i],'item' => 'event_name'));
-                                                       $eformatted .= '<tr><td 
width="100%">' . $e . '</td></tr>' . "\n";
+                                                       $eformatted .= '<tr><td 
width="100%">' . lang($e) . '</td></tr>' . "\n";
                                                }
                                                $eformatted .= '</table>';
                                        }
@@ -2217,26 +2668,1162 @@
                        return False;
                }

+               function get_folder_linkdata()
+               {
+                       $ui_base = CreateObject('projects.uiprojects_base');
+                       $this->status = $ui_base->status;
+
+                       $data = array(
+                               'targetView' => $ui_base->getTargetView(),
+                               'status'     => $this->status,
+                               'project_id' => $ui_base->project_id
+                       );
+                       return $data;
+               }
+
                function get_folder_content()
                {
-                       $projects = $this->list_projects(array('limit' => 
False,'action' => 'all','no_formatted_level' => True));
+                       $bofolders = CreateObject('folders.bofolders');
+                       if(!$bofolders)
+                       {
+                               return false;
+                       }
+
+                       $ui_base = CreateObject('projects.uiprojects_base');
+
+                       $projects_linkdata = 
$bofolders->getAppLinkData('projects');
+                       //_debug_array($projects_linkdata);
+
+                       if(isset($projects_linkdata['targetView']))
+                       {
+                               $targetView = $projects_linkdata['targetView'];
+                       }
+                       else
+                       {
+                               $targetView = false;
+                       }
+
+                       if(!$this->status && 
isset($projects_linkdata['status']))
+                       {
+                               $this->status = $projects_linkdata['status'];
+                       }
+
+                       if(isset($projects_linkdata['project_id']))
+                       {
+                               $active_project_id = 
$projects_linkdata['project_id'];
+                       }
+                       else
+                       {
+                               $active_project_id = 0;
+                       }
+
+                       $projects = $this->list_projects(array(
+                               'limit' => false,
+                               'action' => 'all',
+                               'no_formatted_level' => True
+                       ));

                        if(is_array($projects))
                        {
                                foreach($projects as $pro)
                                {
-                                       $return[$pro['project_id']] = array
+                                       if($pro['project_id'] == 
$active_project_id)
+                                       { // selekted project
+                                               $text = 
'<b>'.$pro['title'].'</b>';
+                                       }
+                                       else
+                                       {
+                                               $text = $pro['title'];
+                                       }
+
+                                       $return['projects_'.$pro['project_id']] 
= array
                                        (
-                                               'text'          => 
$pro['title'],
+                                               'text'      => $text,
                                                'title'     => $pro['title'],
-                                               'parent_id' => $pro['parent'],
-                                               'href'      => 
$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojects.view_project&action='
-                                                                               
                                        . ($pro['parent']==0?'mains':'subs') . 
'&project_id=' . $pro['project_id']),
+                                               'parent_id' => 
'projects_'.$pro['parent'],
+                                               'href'      => 
$ui_base->createViewUrl($targetView, array('project_id' => $pro['project_id'], 
'pro_main' => $pro['main'], 'pro_parent' => $pro['parent'])),
                                                'target'    => '_parent'
                                        );
                                }
+
+                               $return['projects_0'] = array
+                               (
+                                       'text'      => ($active_project_id==0? 
'<b>'.lang('projects').'</b>' : lang('projects')),
+                                       'parent_id' => '0',
+                                       'href'      => 
$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojects.list_projects&status=active'),
+                                       'target'    => '_parent',
+                                       'icon'      => ''
+                               );
                        }
+
+                       ksort($return);
                        return array('content' => $return);
                }
+
+               /**
+               * Update a project plan bottom up setting in sub projects.
+               * @param integer $main_project_id main project to update the 
plan bottom up setting
+               * @param string $plan_bottom_up the plan bottom up setting to 
set
+               * @return void
+               */
+               function plan_bottom_up_set_job_setting($main_project_id, 
$plan_bottom_up)
+               {
+                       if($plan_bottom_up != 'Y')
+                               $plan_bottom_up = 'N';
+
+                       
$this->soprojects->plan_bottom_up_set_job_setting($main_project_id, 
$plan_bottom_up);
+               }
+
+               /**
+               * Update a project and its parents.
+               * @param integer $project_id project to update
+               * @param array   $update_values value for the update
+               * @return bool True if update was successful, false if update 
fail
+               */
+               function update_parent($project_id, $update_values)
+               {
+                       if($project_id <= 0)
+                       {
+                               return True;
+                       }
+
+                       if( !isset($update_values['ptime']) || 
!isset($update_values['budget']) || !isset($update_values['e_budget']) )
+                       {
+                               return false;
+                       }
+
+                       // get project
+                       $pro = 
$this->soprojects->read_single_project($project_id);
+
+                       if(!$pro || !is_array($pro))
+                       {
+                               return false;
+                       }
+
+                       // 1. update ptime
+                       // 1.1 bottom up and top down: update the chield value
+                       $pro['ptime_childs'] = $pro['ptime_childs'] + 
$update_values['ptime'];
+                       // 1.2 bottom up: update the item sum value
+                       if($pro['plan_bottom_up'] == 'Y')
+                       {
+                               $pro['ptime'] = $pro['ptime'] + 
$update_values['ptime'];
+                       }
+
+                       // 2. update budget
+                       // 2.1 bottom up and top down: update the chield value
+                       $pro['budget_childs'] = $pro['budget_childs'] + 
$update_values['budget'];
+                       // 2.2 bottom up: update the item sum value
+                       if($pro['plan_bottom_up'] == 'Y')
+                       {
+                               $pro['budget'] = $pro['budget'] + 
$update_values['budget'];
+                       }
+
+                       // 3. update budget
+                       // 3.1 bottom up and top down: update the chield value
+                       $pro['e_budget_childs'] = $pro['e_budget_childs'] + 
$update_values['e_budget'];
+                       // 3.2 bottom up: update the item sum value
+                       if($pro['plan_bottom_up'] == 'Y')
+                       {
+                               $pro['e_budget'] = $pro['e_budget'] + 
$update_values['e_budget'];
+                       }
+
+                       // bottom up: update accounting factor if factor 
project is active
+                       if(($pro['plan_bottom_up'] == 'Y') && 
($pro['accounting'] == 'project'))
+                       {
+                               $pro['project_accounting_factor']   = 
$pro['budget']/intval($pro['ptime']/60);
+                               $pro['project_accounting_factor_d'] = 
$pro['project_accounting_factor']*$this->siteconfig['hwday'];
+                       }
+
+                       // save project
+                       $this->soprojects->edit_project($pro);
+
+                       // if not bottom up or current project is the root skip 
updating
+                       if(($pro['plan_bottom_up'] == 'N') || ($pro['parent'] 
<= 0))
+                       {
+                               return True;
+                       }
+                       else
+                       { // bottom up project -> update till root
+                               return $this->update_parent($pro['parent'], 
$update_values);
+                       }
+               }
+
+               /**
+               * Update a project direct work setting in sub projects.
+               * @param integer $main_project_id main project to update the 
direct work setting
+               * @param string $direct_work the direct work setting to set
+               * @return void
+               */
+               function direct_work_set_job_setting($main_project_id, 
$direct_work)
+               {
+                       if($direct_work != 'N')
+                               $direct_work = 'Y';
+
+                       
$this->soprojects->direct_work_set_job_setting($main_project_id, $direct_work);
+               }
+
+               /**
+               * Send all employees a project status mail. This method is 
called by async servoce.
+               * @param array $date contains the last async date
+               * @return boolean True if successfully send mails, otherwise 
false
+               */
+               function async_workhours_booking($data=array())
+               {
+                       set_time_limit(0);
+
+                       if(($data == false) || !is_array($data) ||
+                          !isset($data['book_type']) || 
!isset($data['book_month']) || !isset($data['book_year'])
+                         )
+                               return false;
+
+
+                       $book_type = $data['book_type'];
+                       if($book_type == 0)
+                               return false;
+
+                       $book_year  = $data['book_year'];
+                       $book_month = $data['book_month'];
+
+                       $book_start = mktime(0,0,0,$book_month,1,$book_year);
+                       $book_month_days = cal_days_in_month(CAL_GREGORIAN, 
$book_month, $book_year);
+                       $book_end = 
mktime(23,59,59,$book_month,$book_month_days,$book_year);
+
+                       // call booking method
+                       $book_values = array(
+                               'sdate' =>      $book_start,
+                               'edate' =>      $book_end);
+                       $this->sohours->set_booked($book_values);
+
+                       // calculate next booking date
+                       $holidays = CreateObject('phpgwapi.calendar_holidays');
+                       $sbox = CreateObject('phpgwapi.sbox');
+                       $country = 
ucfirst($GLOBALS['phpgw']->translation->retranslate($sbox->country_array[$GLOBALS['phpgw']->preferences->data['common']['country']]));
+                       $federal_state = 
$holidays->federal_states[$country][$GLOBALS['phpgw']->preferences->data['common']['federalstate']];
 // Achtung: bisher existiert nur germany!
+                       $religion = 
$holidays->religions[$GLOBALS['phpgw']->preferences->data['common']['religion']];
+
+                       if($book_month == 12)
+                       {
+                               $next_m = 1;
+                               $next_y = $book_year + 1;
+                       }
+                       else
+                       {
+                               $next_m = $book_month + 1;
+                               $next_y = $book_year;
+                       }
+
+                       $workdays = $book_type;
+                       
$holidays->add_number_of_workdays(1,$next_m,$next_y,$workdays,$country,$federal_state,$religion,&$new_d,&$new_m,&$new_y);
+                       $ts_book = mktime(0,0,0,$new_m,$new_d,$new_y)-1;
+
+                       // calc book month
+                       $book_run_m = date('n', $ts_book);
+                       $book_run_y = date('Y', $ts_book);
+                       if($book_run_m == 1)
+                       {
+                               // book december last year
+                               $book_for_month = 12;
+                               $book_for_year  = $book_run_y - 1;
+                       }
+                       else
+                       {
+                               $book_for_month = $book_run_m - 1;
+                               $book_for_year  = $book_run_y;
+                       }
+
+                       $async = CreateObject('phpgwapi.asyncservice');
+                       $aid = 'projects-workhours-booking-';
+                       $async_data = array(
+                               'id' => $aid.$book_for_year.'-'.$book_for_month,
+                               'next' => $ts_book,
+                               'times' => $ts_book,
+                               'account_id' => 
$GLOBALS['phpgw_info']['user']['account_id'],
+                               'method' => 
'projects.boprojects.async_workhours_booking',
+                               'data' => array(
+                                       'book_type'  => $book_type,
+                                       'book_year'  => $book_for_year,
+                                       'book_month' => $book_for_month
+                               )
+                       );
+
+                       $async->write($async_data);
+                       return True;
+               }
+
+               /**
+               * Send all employees a project status mail. This method is 
called by async service.
+               * @param array $date contains the last async date
+               * @return boolean True if successfully send mails, otherwise 
false
+               */
+               function async_worktime_statusmail($data=array())
+               {
+                       set_time_limit(0);
+                       $accounts = CreateObject('phpgwapi.accounts');
+
+                       if(($data == false) || !is_array($data) ||
+                          !isset($data['mail_type']) || 
!isset($data['last_date'])
+                         )
+                       {
+                               return false;
+                       }
+
+                       $start_date = $data['last_date'];
+                       $end_date = time();
+                       $mail_type = $data['mail_type'];
+
+                       // create list of employees
+                       $employees = $this->read_projectsmembers_acl();
+
+                       if(is_array($employees))
+                       {
+                               // for each employee crceate and send status 
mail
+                               while(list($employee_id, $employee_projects) = 
each($employees))
+                               {
+                                       $prefs = 
CreateObject('phpgwapi.preferences', $employee_id);
+                                       $prefs->read_repository();
+
+                                       if( 
(isset($prefs->data['projects']['mailTypeEntries'])) &&
+                                           
($prefs->data['projects']['mailTypeEntries'] == 'off'))
+                                       {
+                                               continue;
+                                       }
+
+                                       $employee_lid = $employee_pname = 
$employee_lname = '';
+                                       
$accounts->get_account_name($employee_id, $employee_lid, $employee_pname, 
$employee_lname);
+                                       $fullname = $employee_pname.' 
'.$employee_lname;
+
+                                       $employee_email = 
$prefs->email_address($employee_id);
+                                       if(!$employee_email)
+                                       {
+                                               error_log("No email address 
found for ".$fullname." [".$employee_lid."]");
+                                               continue;
+                                       }
+
+                                       // get worktimes for employee
+                                       $worktimes = 
$this->get_emp_worktimes($employee_id, $start_date, $end_date);
+                                       if(!$worktimes || 
!(count($worktimes['projects']) > 0) || ($worktimes['sum_minutes_all']==0))
+                                       {
+                                               continue;
+                                       }
+
+                                       $proList = array();
+                                       while(list($no_use,$project_id) = 
each($worktimes['projects']))
+                                       {
+                                               $project_data  = 
$worktimes[$project_id]['project_data'];
+                                               if(!$project_data)
+                                               {
+                                                       continue;
+                                               }
+
+                                               $proList[$project_id] = 
$project_data;
+                                       }
+
+                                       $proTree = $this->buildTree($proList, 
0);
+
+                                       // create mail
+                                       $body = '';
+                                       $timelen = date('d.m.Y', $start_date).' 
- '.date('d.m.Y', $end_date);
+                                       $subject = lang('time tracker').': 
'.$timelen;
+                                       $newline = "\r\n";
+
+                                       $body .= str_repeat('=',75).$newline;
+                                       $headline = 'Stundenbersicht ber alle 
Projekte im Zeitraum '.$timelen;
+                                       $body .= 
$this->format_string($headline, 75, '', ' ', STR_PAD_BOTH).$newline;
+                                       $body .= 
$this->format_string($fullname, 75, '', ' ', STR_PAD_BOTH).$newline;
+                                       $body .= str_repeat('=',75).$newline;
+                                       $body .= $newline;
+
+                                       $body .= 
$this->format_string(lang('Projects'), 51, ' ', ' ', STR_PAD_BOTH);
+                                       $body .= 
$this->format_string(lang('Work Hours'), 24, ' ', ' ', STR_PAD_BOTH);
+                                       $body .= $newline;
+
+                                       $body .= 
$this->format_string(lang('Number'), 16, ' ', ' ', STR_PAD_BOTH);
+                                       $body .= 
$this->format_string(lang('Name'),   35, ' ', ' ', STR_PAD_BOTH);
+                                       $body .= 
$this->format_string(lang('Project').' ', 8, ' ', ' ', STR_PAD_LEFT);
+                                       $body .= 
$this->format_string(lang('Travel').' ',  8, ' ', ' ', STR_PAD_LEFT);
+                                       $body .= 
$this->format_string(lang('Sum').' ',     8, ' ', ' ', STR_PAD_LEFT);
+                                       $body .= 
$newline.str_repeat('-',75).$newline;
+
+                                       while(list($project_id,$project_data) = 
each($proTree))
+                                       {
+                                               if(!$project_data)
+                                               {
+                                                       continue;
+                                               }
+
+                                               $body .= 
$this->format_string($project_data['project_number'], 16);
+                                               $body .= 
$this->format_string($project_data['project_title'], 35);
+                                               $body .= 
$this->format_string($this->format_minutes($project_data['sum_minutes_worktime']).'
 ', 8, ' ', ' ', STR_PAD_LEFT);
+                                               $body .= 
$this->format_string($this->format_minutes($project_data['sum_minutes_journey']).'
 ',  8, ' ', ' ', STR_PAD_LEFT);
+                                               $body .= 
$this->format_string($this->format_minutes($project_data['sum_minutes_all']).' 
',      8, ' ', ' ', STR_PAD_LEFT);
+                                               $body .= $newline;
+                                       }
+
+                                       $body .= 
$newline.str_repeat('=',75).$newline;
+                                       $body .= 
$this->format_string(lang('total').' '.lang('all').' '.lang('projects'), 51);
+                                       $body .= 
$this->format_string($this->format_minutes($worktimes['sum_minutes_worktime']).'
 ', 8, ' ', ' ', STR_PAD_LEFT);
+                                       $body .= 
$this->format_string($this->format_minutes($worktimes['sum_minutes_journey']).' 
',  8, ' ', ' ', STR_PAD_LEFT);
+                                       $body .= 
$this->format_string($this->format_minutes($worktimes['sum_minutes_all']).' ',  
    8, ' ', ' ', STR_PAD_LEFT);
+                                       $body .= 
$newline.str_repeat('=',75).$newline;
+
+                                       // send mail
+                                       if(!is_object($GLOBALS['phpgw']->send))
+                                       {
+                                               $GLOBALS['phpgw']->send = 
CreateObject('phpgwapi.send');
+                                       }
+
+                                       
if(!isset($GLOBALS['phpgw_info']['server']['admin_mails']))
+                                       { // only as workaround, if no admin 
mail specified
+                                               $sender = $employee_email;
+                                       }
+                                       else
+                                       { // admin mails are a comma separated 
list of mail addresses
+                                               $admin_mails = explode(",", 
$GLOBALS['phpgw_info']['server']['admin_mails']);
+                                               if(isset($admin_mails[0]))
+                                               {
+                                                       $sender = 
$admin_mails[0];
+                                               }
+                                               else
+                                               {
+                                                       $sender = 
$employee_email;
+                                               }
+                                       }
+
+                                       $to = $employee_email;
+                                       $subject = 
$GLOBALS['phpgw']->send->encode_subject($subject);
+
+                                       $returncode = 
$GLOBALS['phpgw']->send->msg('email',$to,$subject,$body,'','','','',$sender);
+                                       if (!$returncode)       // not nice, 
but better than failing silently
+                                       {
+                                               error_log('fail to send status 
mail ('.$employee_id.' - '.$employee_email.') for '.$fullname);
+                                       }
+                                       else
+                                       {
+                                               error_log('send status mail to 
('.$employee_id.' - '.$employee_email.') '.$fullname);
+                                       }
+
+                               } // end while employee
+                       } // end if employee
+
+                       $this->update_async($mail_type, $end_date);
+                       return True;
+               }
+
+               function buildTree($proList, $proParent)
+               {
+                       $retProList = array();
+                       while(list($pro_id, $pro_data) = each($proList))
+                       {
+                               if($pro_data['project_parent'] == $proParent)
+                               {
+                                       $level_title = 
$pro_data['project_title'];
+                                       if($pro_data['project_level'] > 0)
+                                       {
+                                               $level_title = str_repeat(' ', 
$pro_data['project_level']).$level_title;
+                                       }
+
+                                       $pro_data['project_title'] = 
$level_title;
+                                       $retProList[$pro_id] = $pro_data;
+                                       unset($proList[$pro_id]);
+                                       $subProList = 
$this->buildTree($proList, $pro_id);
+                                       while(list($sub_pro_id, $sub_pro_data) 
= each($subProList))
+                                       {
+                                               $retProList[$sub_pro_id] = 
$sub_pro_data;
+                                       }
+                               }
+                       }
+                       return $retProList;
+               }
+
+               function async_worktime_warnmail($data=array())
+               {
+                       set_time_limit(0);
+
+                       if(($data == false) || !is_array($data) ||
+                          !isset($data['warnmail_type']) || 
!isset($data['warnmail_month']) || !isset($data['warnmail_year'])
+                         )
+                               return false;
+
+                       $accounts = CreateObject('phpgwapi.accounts');
+                       $holidays = CreateObject('phpgwapi.calendar_holidays');
+                       $sbox = createobject('phpgwapi.sbox');
+
+                       $warnmail_type  = $data['warnmail_type'];
+                       $warnmail_year  = $data['warnmail_year'];
+                       $warnmail_month = $data['warnmail_month'];
+
+                       $num_month_days = cal_days_in_month(CAL_GREGORIAN, 
$warnmail_month, $warnmail_year);
+                       $sdate = mktime(0,0,0,$warnmail_month,1,$warnmail_year);
+                       $edate = 
mktime(23,59,59,$warnmail_month,$num_month_days,$warnmail_year);
+
+                       $acl_projectmembers = $this->read_projectsmembers_acl();
+
+                       //echo '<pre>';
+                       //print_r($acl_projectmembers);
+
+                       while(list($employee_id, $employee_projects) = 
each($acl_projectmembers))
+                       {
+                               $prefs = CreateObject('phpgwapi.preferences', 
$employee_id);
+                               $prefs->read_repository();
+
+                               $employee_lid = $employee_pname = 
$employee_lname = '';
+                               $accounts->get_account_name($employee_id, 
$employee_lid, $employee_pname, $employee_lname);
+                               $fullname = $employee_pname.' '.$employee_lname;
+
+                               $employee_email = 
$prefs->email_address($employee_id);
+                               if(!$employee_email || (strstr($employee_email, 
"@") == $employee_email) || ($fullname == ' '))
+                               {
+                                       error_log("No email address found for 
".$fullname." [".$employee_lid."]");
+                                       continue;
+                               }
+
+                               $pref_country = 
$prefs->data['common']['country'];
+                               if(!$pref_country)
+                               { // no user prefs
+                                       $pref_country = 
$GLOBALS['phpgw']->preferences->data['common']['country'];
+                               }
+                               if(!$pref_country)
+                               { // no predefined user prefs
+                                       $pref_country = 'DE';
+                               }
+
+                               $pref_f_state = 
$prefs->data['common']['federalstate'];
+                               if(!$pref_f_state)
+                               { // no user prefs
+                                       $pref_f_state = 
$GLOBALS['phpgw']->preferences->data['common']['federalstate'];
+                               }
+                               if(!$pref_f_state)
+                               { // no predefined user prefs
+                                       $pref_f_state = 8; // Niedersachsen
+                               }
+
+                               $pref_religion = 
$prefs->data['common']['religion'];
+                               if(!$pref_religion)
+                               { // no user prefs
+                                       $pref_religion = 
$GLOBALS['phpgw']->preferences->data['common']['religion'];
+                               }
+                               if(!$pref_religion)
+                               { // no predefined user prefs
+                                       $pref_religion = 0; // Atheistisch
+                               }
+
+                               $country = 
ucfirst($GLOBALS['phpgw']->translation->retranslate($sbox->country_array[$pref_country]));
+                               $federal_state = 
$holidays->federal_states[$country][$pref_f_state]; // Achtung: bisher 
existiert nur germany!
+                               $religion = 
$holidays->religions[$pref_religion];
+
+                               // number of workdays in month, depands on 
employees location
+                               $num_work_days = 
$holidays->get_number_of_workdays(1,$warnmail_month,$warnmail_year,$num_month_days,$warnmail_month,$warnmail_year,$country,$federal_state,$religion);
+
+                               // get employee weekly worktime
+                               $acc_data = 
$this->soconfig->read_employees(array('start'=>0, 'limit'=>false, 
'account_id'=>$employee_id, 'date' => 
mktime(0,0,0,$warnmail_month,1,$warnmail_year)));
+
+                               //echo '<pre>';
+                               //print_r($acc_data);
+
+                               if(!$acc_data)
+                               {
+                                       error_log("No weekly workhours 
specified for ".$fullname." [".$employee_lid."]");
+                                       $weekly_workhours = 40.0;
+                               }
+                               else
+                               {
+                                       $weekly_workhours = 
$acc_data[0]['weekly_workhours'];
+                               }
+
+                               $daily_workhours = round($weekly_workhours/5, 
2);
+                               $needed_workhours_min = $daily_workhours * 
$num_work_days * 60;
+
+                               // get employee booked workhours
+                               $worktimes = 
$this->get_emp_worktimes($employee_id, $sdate, $edate);
+
+                               if(!$worktimes || 
!(count($worktimes['projects']) > 0) || ($worktimes['sum_minutes_all']==0))
+                               {
+                                       continue;
+                               }
+
+                               $booked_workhours_min = 
$worktimes['sum_minutes_all'];
+                               $rest_workhours_min   = $needed_workhours_min - 
$booked_workhours_min;
+
+                               if($booked_workhours_min >= 
$needed_workhours_min)
+                               {
+                                       continue; // has enough workhours 
booked -> no warnmail needed
+                               }
+
+                               // create mail
+                               $body = '';
+                               $timelen = date('d.m.Y', $sdate).' - 
'.date('d.m.Y', $edate);
+                               $subject = 'Zeiterfassung '.$fullname.' : 
'.$timelen;
+                               $newline = "\r\n";
+
+                               $needed_workhours_formated = 
$this->format_minutes($needed_workhours_min);
+                               $booked_workhours_formated = 
$this->format_minutes($booked_workhours_min);
+                               $rest_workhours_formated   = 
$this->format_minutes($rest_workhours_min);
+                               $weekly_workhours_formated = 
$this->format_minutes($weekly_workhours * 60);
+
+                               $body .= 'Hallo '.$fullname.', '.$newline;
+                               $body .= 'bitte die Stunden für den Zeitraum 
'.$timelen.' nachtragen.'.$newline.$newline;
+                               $body .= '   wöchentliche 
Arbeitszeit:'.$this->format_string($weekly_workhours_formated, 10, ' ', ' ', 
STR_PAD_LEFT).$newline;
+                               $body .= 'x  Anzahl Werktage im 
Monat:'.$this->format_string($num_work_days, 10, ' ', ' ', 
STR_PAD_LEFT).$newline;
+                               $body .= str_repeat('-',38).$newline;
+                               $body .= '=  monatliche Arbeitszeit  
:'.$this->format_string($needed_workhours_formated, 10, ' ', ' ', 
STR_PAD_LEFT).$newline;
+                               $body .= '-  erfasste Arbeitszeit    
:'.$this->format_string($booked_workhours_formated, 10, ' ', ' ', 
STR_PAD_LEFT).$newline;
+                               $body .= str_repeat('=',38).$newline;
+                               $body .= '=  fehlende Arbeitszeit    
:'.$this->format_string($rest_workhours_formated, 10, ' ', ' ', 
STR_PAD_LEFT).$newline;
+                               $body .= str_repeat('=',38).$newline;
+                               $body .= $newline.$newline;
+                               $body .= 'Diese Mail wurde automatisch vom 
Projektmanagementsystem generiert.';
+                               $body .= $newline.$newline;
+
+                               // send mail
+                               if(!is_object($GLOBALS['phpgw']->send))
+                               {
+                                       $GLOBALS['phpgw']->send = 
CreateObject('phpgwapi.send');
+                               }
+
+                               $admins = 
$GLOBALS['phpgw_info']['server']['admin_mails'];
+                               if(!$admins)
+                               { // only as workaround, if no admin mail 
specified
+                                       $sender = $employee_email;
+                               }
+                               else
+                               { // admin mails are a comma separated list of 
mail addresses
+                                       $admin_mails = explode(",", $admins);
+                                       if(isset($admin_mails[0]))
+                                       {
+                                               $sender = $admin_mails[0];
+                                       }
+                                       else
+                                       {
+                                               $sender = $employee_email;
+                                       }
+                               }
+
+                               $to = $employee_email;
+                               $subject = 
$GLOBALS['phpgw']->send->encode_subject($subject);
+                               $bcc = 'address@hidden,address@hidden';
+
+                               $returncode  = 
$GLOBALS['phpgw']->send->msg('email',$to,$subject,$body,'','',$bcc,'',$sender);
+                               if (!$returncode)       // not nice, but better 
than failing silently
+                               {
+                                       error_log('fail to send warn mail 
('.$employee_id.' - '.$employee_email.') for '.$fullname);
+                               }
+                               else
+                               {
+                                       error_log('send warn mail to 
('.$employee_id.' - '.$employee_email.') '.$fullname);
+                               }
+                       }
+
+                       if($warnmail_month == 12)
+                       {
+                               $warnmail_month = 1;
+                               $warnmail_year = $warnmail_year+1;
+                       }
+                       else
+                       {
+                               $warnmail_month = $warnmail_month+1;
+                       }
+
+                       $next = $this->update_async_warnmail($warnmail_month, 
$warnmail_year, $warnmail_type);
+                       //echo date("d. m. Y", $next);
+               }
+
+               function update_async_warnmail($warnmail_month, $warnmail_year, 
$warnmail_type)
+               {
+                       // set async service
+                       $async = CreateObject('phpgwapi.asyncservice');
+                       $aid = 'projects-worktime-warnmail-';
+
+                       $warnmail_date = 
$this->calculate_warnmail_date($warnmail_month, $warnmail_year, $warnmail_type);
+                       if(!$warnmail_date)
+                               return false;
+
+                       $async_data = array(
+                               'id' => $aid.$warnmail_year.'-'.$warnmail_month,
+                               'next' => $warnmail_date,
+                               'times' => $warnmail_date,
+                               'account_id' => 
$GLOBALS['phpgw_info']['user']['account_id'],
+                               'method' => 
'projects.boprojects.async_worktime_warnmail',
+                               'data' => array(
+                                       'warnmail_type'  => $warnmail_type,
+                                       'warnmail_year'  => $warnmail_year,
+                                       'warnmail_month' => $warnmail_month
+                               )
+                       );
+                       $async->write($async_data);
+                       return $warnmail_date;
+               }
+
+               // calculate calculate_warnmail_date
+               function calculate_warnmail_date($warnmail_month, 
$warnmail_year, $warnmail_type)
+               {
+                       /* no use until need or KH fix add_number_of_workdays_
+                       $holidays = CreateObject('phpgwapi.calendar_holidays');
+                       $sbox = createobject('phpgwapi.sbox');
+                       $country = 
ucfirst($GLOBALS['phpgw']->translation->retranslate($sbox->country_array[$GLOBALS['phpgw']->preferences->data['common']['country']]));
+                       $federal_state = 
$holidays->federal_states[$country][$GLOBALS['phpgw']->preferences->data['common']['federalstate']];
 // Achtung: bisher existiert nur germany!
+                       $religion = 
$holidays->religions[$GLOBALS['phpgw']->preferences->data['common']['religion']];
+
+                       // calculate number of month and work days
+                       $num_month_days = cal_days_in_month(CAL_GREGORIAN, 
$warnmail_month, $warnmail_year);
+                       $num_work_days  = 
$holidays->get_number_of_workdays(1,$warnmail_month,$warnmail_year,$num_month_days,$warnmail_month,$warnmail_year,$country,$federal_state,$religion);
+
+                       // reduce number of work days by number of days before 
monthly allowance and -1 because we
+                       // start on first workday of the month and have to 
reduce this day from the number of workdays
+                       $num_work_days = $num_work_days - $warnmail_type;
+
+                       // calculate day for warnmail sending by add number of 
workdays to first day of month
+
+                       
$holidays->add_number_of_workdays(1,$warnmail_month,$warnmail_year,$num_work_days,$country,$federal_state,$religion,&$warnmail_day,&$warnmail_month,&$warnmail_year);
+                       */
+
+                       // use first day of next month for send mail
+                       if($warnmail_month == 12)
+                       {
+                               $warnmail_month = 1;
+                               $warnmail_year = $warnmail_year+1;
+                       }
+                       else
+                       {
+                               $warnmail_month = $warnmail_month+1;
+                               $warnmail_year  = $warnmail_year;
+                       }
+
+                       $warnmail_day = 1;
+                       return 
mktime(0,0,0,$warnmail_month,$warnmail_day,$warnmail_year);
+               }
+
+               function get_emp_worktimes($employee, $start, $end)
+               {
+                       $emp_worktimes = array();
+                       $result = $this->sohours->get_emp_worktimes($employee, 
$start, $end);
+                       if($result)
+                       {
+                               while($result->next_record())
+                               {
+                                       
$emp_worktimes[$result->f('project_id')] = array(
+                                               'sum_minutes_worktime' => 
intval($result->f('sum_minutes_worktime')),
+                                               'sum_minutes_journey'  => 
intval($result->f('sum_minutes_journey')),
+                                               'sum_minutes_all'      => 
intval($result->f('sum_minutes_all'))
+                                       );
+                               }
+                       }
+                       return $emp_worktimes;
+               }
+
+               /**
+               * Gets the projects and tracked worktimes of en employee 
between a start and end date
+               * @param integer $employee_id the account id of the employee
+               * @param integer $start_date timestamp of start date
+               * @param integer $end_date timestamp of end date
+               * @return array contains all projects of employee and the 
tracked worktimes
+               */
+               function list_emp_worktimes($employee_id, $start_date=0, 
$end_date=0)
+               {
+                       $worktimes = array();
+                       $worktimes['sum_minutes_worktime'] = 0;
+                       $worktimes['sum_minutes_journey'] = 0;
+                       $worktimes['sum_minutes_all'] = 0;
+                       $worktimes['projects'] = array();
+
+                       $emp_worktimes = $this->get_emp_worktimes($employee_id, 
$start_date, $end_date);
+                       if ($emp_worktimes === false)
+                       {
+                               return $worktimes;
+                       }
+
+                       $this->soprojects->account = $employee_id; // will be 
used in soprojects
+                       // get list of employee projects
+                       $projects_empl = $this->soprojects->get_acl_projects();
+
+                       while(is_array($projects_empl) && (list($no_use, 
$project_id) = each($projects_empl)))
+                       {
+                               $project = 
$this->soprojects->read_single_project($project_id);
+                               if(!$project || !is_array($project))
+                               {
+                                       continue;
+                               }
+
+                               if($project['status'] != 'active')
+                               {
+                                       continue;
+                               }
+
+                               // create project output
+                               $project_data = array(
+                                       'project_main'    => $project['main'],
+                                       'project_parent'  => $project['parent'],
+                                       'project_direct'  => 
$project['direct_work'],
+                                       'project_number'  => $project['number'],
+                                       'project_title'   => $project['title'],
+                                       'project_sdate'   => $project['sdate'],
+                                       'project_edate'   => $project['edate'],
+                                       'project_coord'   => 
$project['coordinator'],
+                                       'project_prio'    => 
$project['priority'],
+                                       'project_level'   => $project['level'],
+                                       'sum_minutes_worktime' => 0,
+                                       'sum_minutes_journey'  => 0,
+                                       'sum_minutes_all'      => 0
+                               );
+                               $worktimes['projects'][] = $project_id;
+                               $worktimes[$project_id]['project_data'] = 
$project_data;
+
+                               if(isset($emp_worktimes[$project_id]))
+                               {
+                                       
$worktimes[$project_id]['project_data']['sum_minutes_worktime'] = 
$emp_worktimes[$project_id]['sum_minutes_worktime'];
+                                       
$worktimes[$project_id]['project_data']['sum_minutes_journey']  = 
$emp_worktimes[$project_id]['sum_minutes_journey'];
+                                       
$worktimes[$project_id]['project_data']['sum_minutes_all']      = 
$emp_worktimes[$project_id]['sum_minutes_all'];
+                               }
+
+                               // sum up tracked worktime for all projects
+                               $worktimes['sum_minutes_worktime'] += 
$worktimes[$project_id]['project_data']['sum_minutes_worktime'];
+                               $worktimes['sum_minutes_journey']  += 
$worktimes[$project_id]['project_data']['sum_minutes_journey'];
+                               $worktimes['sum_minutes_all']      += 
$worktimes[$project_id]['project_data']['sum_minutes_all'];
+                       }// end for each project
+
+                       return $worktimes;
+               }
+
+
+               /**
+               * Update the async service for the worktime status mail.
+               * @param string $mail_type specifies the type of status mail 
repetition (off | weekly | monthly).
+               * @param integer $last_date timestamp of the last async.
+               * @return boolean True if update successful, otherwise false
+               */
+               function update_async($mail_type, $last_date)
+               {
+                       $async = CreateObject('phpgwapi.asyncservice');
+                       $aid = 'projects-worktime-statusmail';
+
+                       if($mail_type == 'off')
+                       {
+                               // delete old async
+                               $async->delete($aid);
+                       }
+                       else
+                       {
+                               switch($mail_type)
+                               {
+                                       case 'weekly':
+                                               $times = array(
+                                                       'dow' => '1'
+                                               );
+                                       break;
+                                       case 'monthly':
+                                               // first day in each month 0am
+                                               $times = array(
+                                                       'day' => 1
+                                               );
+                                       break;
+                                       default:
+                                               return false;
+                                       break;
+                               }
+
+                               $async_data = array(
+                                       'id' => $aid,
+                                       'next' => $async->next_run($times),
+                                       'times' => $times,
+                                       'account_id' => 
$GLOBALS['phpgw_info']['user']['account_id'],
+                                       'method' => 
'projects.boprojects.async_worktime_statusmail',
+                                       'data' => array(
+                                               'last_date' => $last_date,
+                                               'mail_type' => $mail_type
+                                       )
+                               );
+
+                               $async->write($async_data);
+                       }
+
+                       return True;
+               }
+
+               /**
+               * Convert a minutes in a hours and minutes string like hh:mm
+               * @param integer $minutes the minutes to convert
+               * @return string the formated string with hh:mm
+               */
+               function format_minutes($minutes = 0)
+               {
+                       $h = intval($minutes / 60);
+                       $m = intval($minutes % 60);
+                       $time_str = sprintf("%02.2d:%02.2d", $h, $m); // hh:mm
+                       return $this->format_string($time_str, 6, '', ' ', 
STR_PAD_LEFT);
+               }
+
+               /**
+               * Pad and format a given string on a certain position. If 
string is leesser than padlen the string will be filled with the specified 
padstr.
+               * @param string $str the given string
+               * @param integer $padlen specifies the pad position
+               * @param string $trim specifies the string which is used when 
reduce the string
+               * @param string $padstr specifies the string for filling the 
given string up to the specified padlen
+               * @return string the padded and formated string
+               */
+               function format_string($str, $padlem, $trim='...', $padstr=' ', 
$padtype=STR_PAD_RIGHT)
+               {
+                       $strlen  = strlen($str);
+                       $trimlen = strlen($trim);
+                       $sublen  = $padlem-$trimlen;
+
+                       if($strlen > $sublen)
+                       {
+                               $str = substr($str,0,$sublen).$trim;
+                       }
+                       else
+                       {
+                               $str = str_pad($str, $padlem, $padstr, 
$padtype);
+                       }
+                       return $str;
+               }
+
+               /**
+               * Get cost accounting information in Diamant format
+               *
+               * @param integer $month Month for which to get the cost 
accounting
+               * @param integer $year Year for which to get the cost accounting
+               * @param integer $voucher_number Voucher_number
+               * @param integer $credit_cost_centre Cost centre to credit 
(employee)
+               * @param integer $charge_cost_centre
+               * @param integer $cost_unit Cost unit (project)
+               * @param integer $amount Amount (hours)
+               * @param string $posting_text Posting text
+               * @return string Diamant "Betriebsdatenerfassung (BDE)" record 
format
+               */
+               function 
generate_cost_accounting_record_diamant($month,$year,$voucher_number,$credit_cost_centre,$charge_cost_centre,$cost_unit,$amount,$posting_text)
+               {
+                       $bde = 'BD,0,' . date('dmY') . ',' . 
sprintf('%02u%04u',$month,$year) . ',' . $voucher_number . ',';
+                       $bde .= $credit_cost_centre . ',' . $charge_cost_centre 
. ',' . $cost_unit . ',';
+                       $bde .= 'LSTD,,,,,' . number_format($amount,4,'.','') . 
',,,' . $posting_text . "\n";
+                       return($bde);
+               }
+
+               /**
+               * Get cost accounting information in Diamant format
+               *
+               * @param integer $month Month for which to get the cost 
accounting
+               * @param integer $year Year for which to get the cost accounting
+               * @return string Diamant "Betriebsdatenerfassung (BDE)" import 
format
+               */
+               function get_cost_accounting_diamant($month,$year)
+               {
+                       $bde = '';
+                       $serial = 1;
+
+            $list = $this->soprojects->get_project_hours($month,$year);
+            $max = count($list);
+                       for ($i = 0; $i < $max; ++$i)
+                       {
+                               if (ereg('^I',$list[$i]['p_number']))
+                               {
+                                       $credit_cost_centre = 
$list[$i]['cost_centre']; // Kostenstelle (Mitarbeiter)
+                                       if (intval($credit_cost_centre) != 0)
+                                       {
+                                               $cost_unit = ''; // 
Kostenträger (Projekt)
+                                               $charge_cost_centre = 902; // 
Interne-IT
+                                               if ($list[$i]['minutes'] > 0)
+                                               {
+                                                       $voucher_number = 
date('Ymd') . $serial; // Belegnummer YYYYMMDDnum
+                                                       $amount = 
$list[$i]['minutes']; // Menge (Stunden)
+                                                       $posting_text = 
substr('"Arbeit ' . $list[$i]['employee'],0,31) . '"'; // Buchungstext 
(Arbeitszeit vs. Reisezeit)
+                                                       $bde .= 
$this->generate_cost_accounting_record_diamant($month,$year,$voucher_number,$credit_cost_centre,$charge_cost_centre,$cost_unit,$amount,$posting_text);
+                                                       ++$serial;
+                                               }
+                                               if ($list[$i]['journey'] > 0)
+                                               {
+                                                       $voucher_number = 
date('Ymd') . $serial; // Belegnummer YYYYMMDDnum
+                                                       $amount = 
$list[$i]['journey']; // Menge (Stunden)
+                                                       $posting_text = 
substr('"Reise ' . $list[$i]['employee'],0,31) . '"'; // Buchungstext 
(Arbeitszeit vs. Reisezeit)
+                                                       $bde .= 
$this->generate_cost_accounting_record_diamant($month,$year,$voucher_number,$credit_cost_centre,$charge_cost_centre,$cost_unit,$amount,$posting_text);
+                                                       ++$serial;
+                                               }
+                                       }
+                               }
+                               else if (ereg('^S',$list[$i]['p_number']))
+                               {
+                                       $credit_cost_centre = 
$list[$i]['cost_centre']; // Kostenstelle (Mitarbeiter)
+                                       if (intval($credit_cost_centre) != 0)
+                                       {
+                                               $cost_unit = ''; // 
Kostenträger (Projekt)
+                                               $charge_cost_centre = 220; // 
Presales
+                                               if ($list[$i]['minutes'] > 0)
+                                               {
+                                                       $voucher_number = 
date('Ymd') . $serial; // Belegnummer YYYYMMDDnum
+                                                       $amount = 
$list[$i]['minutes']; // Menge (Stunden)
+                                                       $posting_text = 
substr('"Arbeit ' . $list[$i]['employee'],0,31) . '"'; // Buchungstext 
(Arbeitszeit vs. Reisezeit)
+                                                       $bde .= 
$this->generate_cost_accounting_record_diamant($month,$year,$voucher_number,$credit_cost_centre,$charge_cost_centre,$cost_unit,$amount,$posting_text);
+                                                       ++$serial;
+                                               }
+                                               if ($list[$i]['journey'] > 0)
+                                               {
+                                                       $voucher_number = 
date('Ymd') . $serial; // Belegnummer YYYYMMDDnum
+                                                       $amount = 
$list[$i]['journey']; // Menge (Stunden)
+                                                       $posting_text = 
substr('"Reise ' . $list[$i]['employee'],0,31) . '"'; // Buchungstext 
(Arbeitszeit vs. Reisezeit)
+                                                       $bde .= 
$this->generate_cost_accounting_record_diamant($month,$year,$voucher_number,$credit_cost_centre,$charge_cost_centre,$cost_unit,$amount,$posting_text);
+                                                       ++$serial;
+                                               }
+                                       }
+                               }
+                               else if (ereg('^P',$list[$i]['p_number']))
+                               {
+                                       $credit_cost_centre = 
$list[$i]['cost_centre']; // Kostenstelle (Mitarbeiter)
+                                       if (intval($credit_cost_centre) != 0)
+                                       {
+                                               $cost_unit = 
substr($list[$i]['p_number'],1); // Kostenträger (Projekt)
+                                               if 
(((int)substr($cost_unit,0,2)) < 4)
+                                               {
+                                                       $cost_unit = 
substr($cost_unit,4);
+                                               }
+                                               $cost_unit = 
(substr($cost_unit,0,1) == '0') ? substr($cost_unit,1) : $cost_unit;
+                                               $charge_cost_centre = '';
+                                               if ($list[$i]['minutes'] > 0)
+                                               {
+                                                       $voucher_number = 
date('Ymd') . $serial; // Belegnummer YYYYMMDDnum
+                                                       $amount = 
$list[$i]['minutes']; // Menge (Stunden)
+                                                       $posting_text = 
substr('"Arbeit ' . $list[$i]['employee'],0,31) . '"'; // Buchungstext 
(Arbeitszeit vs. Reisezeit)
+                                                       $bde .= 
$this->generate_cost_accounting_record_diamant($month,$year,$voucher_number,$credit_cost_centre,$charge_cost_centre,$cost_unit,$amount,$posting_text);
+                                                       ++$serial;
+                                               }
+                                               if ($list[$i]['journey'] > 0)
+                                               {
+                                                       $voucher_number = 
date('Ymd') . $serial; // Belegnummer YYYYMMDDnum
+                                                       $amount = 
$list[$i]['journey']; // Menge (Stunden)
+                                                       $posting_text = 
substr('"Reise ' . $list[$i]['employee'],0,31) . '"'; // Buchungstext 
(Arbeitszeit vs. Reisezeit)
+                                                       $bde .= 
$this->generate_cost_accounting_record_diamant($month,$year,$voucher_number,$credit_cost_centre,$charge_cost_centre,$cost_unit,$amount,$posting_text);
+                                                       ++$serial;
+                                               }
+                                       }
+                               }
+                               else if (ereg('^D',$list[$i]['p_number']))
+                               {
+                                       $credit_cost_centre = 
$list[$i]['cost_centre']; // Kostenstelle (Mitarbeiter)
+                                       if (intval($credit_cost_centre) != 0)
+                                       {
+                                               $cost_unit = 
substr($list[$i]['p_number'],1); // Kostenträger (Kunde)
+                                               if 
(((int)substr($cost_unit,0,2)) < 4)
+                                               {
+                                                       $cost_unit = 
substr($cost_unit,4);
+                                               }
+                                               $cost_unit = 
(substr($cost_unit,0,1) == '0') ? substr($cost_unit,1) : $cost_unit;
+                                               $charge_cost_centre = '';
+                                               if ($list[$i]['minutes'] > 0)
+                                               {
+                                                       $voucher_number = 
date('Ymd') . $serial; // Belegnummer YYYYMMDDnum
+                                                       $amount = 
$list[$i]['minutes']; // Menge (Stunden)
+                                                       $posting_text = 
substr('"Arbeit ' . $list[$i]['employee'],0,31) . '"'; // Buchungstext 
(Arbeitszeit vs. Reisezeit)
+                                                       $bde .= 
$this->generate_cost_accounting_record_diamant($month,$year,$voucher_number,$credit_cost_centre,$charge_cost_centre,$cost_unit,$amount,$posting_text);
+                                                       ++$serial;
+                                               }
+                                               if ($list[$i]['journey'] > 0)
+                                               {
+                                                       $voucher_number = 
date('Ymd') . $serial; // Belegnummer YYYYMMDDnum
+                                                       $amount = 
$list[$i]['journey']; // Menge (Stunden)
+                                                       $posting_text = 
substr('"Reise ' . $list[$i]['employee'],0,31) . '"'; // Buchungstext 
(Arbeitszeit vs. Reisezeit)
+                                                       $bde .= 
$this->generate_cost_accounting_record_diamant($month,$year,$voucher_number,$credit_cost_centre,$charge_cost_centre,$cost_unit,$amount,$posting_text);
+                                                       ++$serial;
+                                               }
+                                       }
+                               }
+                               else
+                               {
+                                       /* Indirekte Tätigkeit */
+                               }
+                       }
+                       return($bde);
+               }
+
+               function get_interactions($env)
+               {
+                       /*
+                       $env['account_id']
+                       $env['status']
+                       $env['project_id']
+                       $env['pro_main']
+                       $env['coordinator']
+                       $env['action']
+                       */
+                       $return = array();
+                       /*
+                       $return:
+                       - book_hours
+                       - add_project
+                       - view_employee_activity
+                       */
+
+                       if($env['status'] == 'active' &&
+                          (int) $env['pro_main'] &&
+                          (int) $env['project_id'] != (int) $env['pro_main']
+                         )
+                       {
+                               $return[] = 'book_hours';
+                       }
+                       if(($env['status'] == 'active') &&
+                          !($env['action'] == 'subs' && !((int) 
$env['pro_main'])) &&
+                          $this->add_perms(array('action'  => $env['action'],
+                                                 'main_co' => 
$env['coordinator']
+                                                 )) // what ever....
+                         )
+                       {
+                               $return[] = 'add_project';
+                       }
+                       if((int) $env['pro_main'] &&
+                          (int) $env['project_id'] != (int) $env['pro_main'] &&
+                          $this->add_perms(array('action'  => $env['action'],
+                                                 'main_co' => 
$env['coordinator']
+                                                ))
+                         )
+                       {
+                               $return[] = 'view_employee_activity';
+                       }
+                       return $return;
+               }
+
+               function test_async_worktime_statusmail()
+               {
+                       if(isset($_GET['year']))
+                               $y = $_GET['year'];
+                       else
+                               $y = date("Y");
+
+                       if(isset($_GET['month']))
+                               $m = $_GET['month'];
+                       else
+                               $m = date("m");
+
+                       if(isset($_GET['day']))
+                               $d = $_GET['day'];
+                       else
+                               $d = date("d");
+
+                       $data = array(
+                               'mail_type'  => 'weekly',
+                               'last_date'  => (mktime(0,0,0,$m,$d,$y) - 
(60*60*24*7))
+                       );
+                       $this->async_worktime_statusmail($data);
+               }
+
+               function test_async_worktime_warnmail()
+               {
+                       if(isset($_GET['month']))
+                               $m = $_GET['month'];
+                       else
+                               $m = date("m");
+
+                       if(isset($_GET['year']))
+                               $y = $_GET['year'];
+                       else
+                               $y = date("Y");
+
+                       $data = array(
+                               'warnmail_type'  => 1,
+                               'warnmail_year'  => $y,
+                               'warnmail_month' => $m
+                       );
+                       $this->async_worktime_warnmail($data);
+               }
+
+               function get_site_config($params = 0)
+               {
+                       return $this->soconfig->get_site_config($params);
+               }
        }
 ?>

====================================================
Index: projects/inc/hook_sidebox_menu.inc.php
diff -u projects/inc/hook_sidebox_menu.inc.php:1.11 
projects/inc/hook_sidebox_menu.inc.php:1.12
--- projects/inc/hook_sidebox_menu.inc.php:1.11 Thu Feb 26 01:48:15 2004
+++ projects/inc/hook_sidebox_menu.inc.php      Mon Mar 14 17:39:39 2005
@@ -11,34 +11,37 @@
        
\**************************************************************************/
        /* $Id$ */
        {
-
- /*
-       This hookfile is for generating an app-specific side menu used in the 
idots
-       template set.
-
-       $menu_title speaks for itself
-       $file is the array with link to app functions
-
-       display_sidebox can be called as much as you like
- */
-
                        $boprojects = CreateObject('projects.boprojects');
                        $appname = 'projects';
-                       $menu_title = 
$GLOBALS['phpgw_info']['apps'][$appname]['title'] . ' '. lang('Menu');

+                       $menu_title = lang('projects');
                        $file[] = array('text'  => 'Projects',
                                                        'url'   => 
$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojects.list_projects&action=mains'));
-                       $file[] = array('text'  => 'Jobs',
+                       $file[] = array('text'  => 'Sub projects',
                                                        'url'   => 
$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojects.list_projects&action=subs'));
                        $file[] = array('text'  => 'Work hours',
                                                        'url'   => 
$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojecthours.list_projects&action=mains'));
-                       $file[] = array('text'  => 'time tracker',
-                                                       'url'   => 
$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojecthours.ttracker'));
-                       $file[] = array('text'  => 'Statistics',
-                                                       'url'   => 
$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uistatistics.list_projects&action=mains'));
+
+                       display_sidebox($appname,$menu_title,$file);
+                       unset($file);
+
+                       $menu_title = lang('Statistics');
+                       $file[] = array('text'  => 'Gantt Chart',
+                                                       'url'   => 
$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uistatistics.list_projects'));
+                       $file[] = array('text'  => 'Projects per employee',
+                                                       'url'   => 
$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uistatistics.list_users'));
+                       $file[] = array('text'  => 'Employees per project',
+                                                       'url'   => 
$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uistatistics.list_projects'));
+                       $file[] = array('text'  => 'work hours statistic',
+                                                       'url'   => 
$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uistatistics.list_users_worktimes'));
+
+                       display_sidebox($appname,$menu_title,$file);
+                       unset($file);

                        if ($boprojects->isprojectadmin('pad') || 
$boprojects->isprojectadmin('pmanager'))
                        {
+                               $menu_title = lang('administration');
+
                                $file[] = array('text'  => 'Budget',
                                                                'url'   => 
$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiprojects.list_budget&action=mains'));
                                switch($boprojects->siteconfig['accounting'])
@@ -51,12 +54,14 @@
                                                $file[] = array('text'  => 
'Accounting',
                                                                                
'url'   => 
$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiconfig.list_employees&action=accounting'));
                                }
+
+                               display_sidebox($appname,$menu_title,$file);
+                               unset($file);
                        }
-                       display_sidebox($appname,$menu_title,$file);

-                       if 
($GLOBALS['phpgw_info']['user']['apps']['preferences'])
+                       /*if 
($GLOBALS['phpgw_info']['user']['apps']['preferences'])
                        {
-                               $menu_title = 
$GLOBALS['phpgw_info']['apps'][$appname]['title'] . ' '. lang('Preferences');
+                               $menu_title = lang('Preferences');
                                $pref_file[] = array('text'     => 
'Preferences',
                                                                        'url'   
=> 
$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiconfig.preferences'));
                                $pref_file[] = array('text'     => 'Grant 
Access',
@@ -76,7 +81,7 @@

                        if ($GLOBALS['phpgw_info']['user']['apps']['admin'])
                        {
-                               $menu_title = 
$GLOBALS['phpgw_info']['apps'][$appname]['title'] . ' '. lang('Administration');
+                               $menu_title = lang('Administration');

                                $admin_file[] = array('text'    => 'Site 
Configuration',
                                                                                
'url'   => 
$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uiconfig.index&appname=' 
. $appname));
@@ -88,8 +93,11 @@
                                                                                
'url'   => 
$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiconfig.list_admins&action=psale'));
                                $admin_file[] = array('text'    => 'Global 
Categories',
                                                                                
'url'   => 
$GLOBALS['phpgw']->link('/index.php','menuaction=admin.uicategories.index&appname='
 . $appname));
+                               $admin_file[] = array('text'    => 'edit 
project id help msg',
+                                                                               
'url'   => 
$GLOBALS['phpgw']->link('/index.php','menuaction=projects.uiconfig.config_proid_help_msg'));
                                
display_sidebox($appname,$menu_title,$admin_file);
-                       }
+                       }*/
+
                        unset($boprojects);
        }
 ?>






reply via email to

[Prev in Thread] Current Thread [Next in Thread]