phpgroupware-cvs
[Top][All Lists]
Advanced

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

[Phpgroupware-cvs] projects/inc class.uiprojects.inc.php, 1.152.2.1 clas


From: ceb
Subject: [Phpgroupware-cvs] projects/inc class.uiprojects.inc.php, 1.152.2.1 class.boprojects.inc.php, 1.150.2.1 class.uiprojecthours.inc.php, 1.81.2.1
Date: Tue, 17 May 2005 15:23:00 +0200

Update of projects/inc

Modified Files:
     Branch: old_0_9_17_HEAD
            class.uiprojects.inc.php lines: +3 -3
            class.boprojects.inc.php lines: +24 -7
            class.uiprojecthours.inc.php lines: +2 -2

Log Message:
fixes

====================================================
Index: projects/inc/class.uiprojects.inc.php
diff -u projects/inc/class.uiprojects.inc.php:1.152 
projects/inc/class.uiprojects.inc.php:1.152.2.1
--- projects/inc/class.uiprojects.inc.php:1.152 Wed Aug 11 15:05:13 2004
+++ projects/inc/class.uiprojects.inc.php       Tue May 17 13:23:58 2005
@@ -486,7 +486,7 @@
                                        
$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'],
+                                       if 
($this->boprojects->add_perms(array('action' => $action,'coordinator' => 
$p['coordinator'],'cat' => $p['cat'],
                                                                                
                                '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='
@@ -1259,7 +1259,7 @@
                                $prefs = $this->boprojects->read_prefs();
                        }

-                       $values = 
$this->boprojects->read_single_project($project_id);
+                       $values = 
$this->boprojects->read_single_project($project_id,'hours',True);

                        //_debug_array($values);


====================================================
Index: projects/inc/class.boprojects.inc.php
diff -u projects/inc/class.boprojects.inc.php:1.15 
projects/inc/class.boprojects.inc.php:1.150.2.1
--- projects/inc/class.boprojects.inc.php:1.15  Wed Nov 14 23:19:32 2001
+++ projects/inc/class.boprojects.inc.php       Tue May 17 13:23:58 2005
@@ -2,11 +2,12 @@
        /*******************************************************************\
        * phpGroupWare - Projects                                           *
        * http://www.phpgroupware.org                                       *
+       * This program is part of the GNU project, see http://www.gnu.org/      
*
        *                                                                   *
        * Project Manager                                                   *
        * Written by Bettina Gille address@hidden                   *
        * -----------------------------------------------                   *
-       * Copyright (C) 2000, 2001 Bettina Gille                            *
+       * Copyright 2000 - 2004 Free Software Foundation, Inc.              *
        *                                                                   *
        * This program is free software; you can redistribute it and/or     *
        * modify it under the terms of the GNU General Public License as    *
@@ -23,6 +24,7 @@
        * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.         *
        \*******************************************************************/
        /* $Id$ */
+       // $Source$

        class boprojects
        {
@@ -33,442 +35,2225 @@
                var $order;
                var $sort;
                var $cat_id;
+               var $status;
+               var $html_output;

                var $public_functions = array
                (
-                       'cached_accounts'               => True,
-                       'list_projects'                 => True,
-                       'check_perms'                   => True,
-                       'check_values'                  => True,
-                       'select_project_list'   => True,
-                       'check_act_values'              => True,
-                       'save_project'                  => True,
-                       'read_single_project'   => True,
-                       'delete_pa'                             => True,
-                       'exists'                                => True,
-                       'read_customer_data'    => True,
-                       'isprojectadmin'                => True,
-                       'select_activity_list'  => True,
-                       'coordinator_list'              => True,
-                       'check_prefs'                   => True,
-                       'get_prefs'                             => True,
-                       'list_activities'               => True,
-                       'read_single_activity'  => True,
-                       'save_activity'                 => 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,
+                       'return_value'                          => True,
+                       'change_owner'                          => True
                );

-               function boprojects($session=False, $action = '')
+               function boprojects($is_active=False, $action = '')
                {
-                       global $phpgw;
+                       $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'];
+                       $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->html_output      = True;
+
+                       if ($is_active)
+                       {
+                               $this->read_sessiondata($action);
+                               $this->use_session = True;
+
+                               $_start                 = 
get_var('start',array('POST','GET'));
+                               $_query                 = 
get_var('query',array('POST','GET'));
+                               $_sort                  = 
get_var('sort',array('POST','GET'));
+                               $_order                 = 
get_var('order',array('POST','GET'));
+                               $_cat_id                = 
get_var('cat_id',array('POST','GET'));
+                               $_filter                = 
get_var('filter',array('POST','GET'));
+                               $_status                = 
get_var('status',array('POST','GET'));
+                               $_state                 = 
get_var('state',array('POST','GET'));
+                               $_project_id    = 
get_var('project_id',array('POST','GET'));
+
+                               if(!empty($_start) || ($_start == '0') || 
($_start == 0))
+                               {
+                                       if($this->debug) { echo '<br>overriding 
$start: "' . $this->start . '" now "' . $_start . '"'; }
+                                       $this->start = $_start;
+                               }
+
+                               if((empty($_query) && !empty($this->query)) || 
!empty($_query))
+                               {
+                                       $this->query  = $_query;
+                               }
+
+                               if(isset($_status) && !empty($_status))
+                               {
+                                       $this->status = $_status;
+                               }
+
+                               if(isset($_status) && !empty($_status))
+                               {
+                                       $this->status = $_status;
+                               }
+
+                               if(isset($_state) && !empty($_state))
+                               {
+                                       $this->state = $_state;
+                               }
+
+                               if(isset($_cat_id) && !empty($_cat_id))
+                               {
+                                       $this->cat_id = $_cat_id;
+                               }
+
+                               if(isset($_project_id) && !empty($_project_id))
+                               {
+                                       $this->project_id = $_project_id;
+                               }
+                               else
+                               {
+                                       unset($this->project_id);
+                               }
+
+                               /*if($_project_id)
+                               {
+                                       $this->project_id = $_project_id;
+                               }*/
+
+                               if(isset($_sort) && !empty($_sort))
+                               {
+                                       if($this->debug)
+                                       {
+                                               echo '<br>overriding $sort: "' 
. $this->sort . '" now "' . $_sort . '"';
+                                       }
+                                       $this->sort   = $_sort;
+                               }
+
+                               if(isset($_order) && !empty($_order))
+                               {
+                                       if($this->debug)
+                                       {
+                                               echo '<br>overriding $order: "' 
. $this->order . '" now "' . $_order . '"';
+                                       }
+                                       $this->order  = $_order;
+                               }
+
+                               if(isset($_filter) && !empty($_filter))
+                               {
+                                       if($this->debug) { echo '<br>overriding 
$filter: "' . $this->filter . '" now "' . $_filter . '"'; }
+                                       $this->filter = $_filter;
+                               }
+                               $this->limit = True;
+                       }
+               }
+
+               function type($action)
+               {
+                       switch ($action)
+                       {
+                               case 'mains'            : $column = 
'projects_mains'; break;
+                               case 'subs'                     : $column = 
'projects_subs'; break;
+                               case 'pad'                      : $column = 
'projects_pad'; break;
+                               case 'amains'           : $column = 
'projects_amains'; break;
+                               case 'asubs'            : $column = 
'projects_asubs'; break;
+                               case 'ustat'            : $column = 
'projects_ustat'; break;
+                               case 'pstat'            : $column = 
'projects_pstat'; break;
+                               case 'act'                      : $column = 
'projects_act'; break;
+                               case 'pad'                      : $column = 
'projects_pad'; break;
+                               case 'role'                     : $column = 
'projects_role'; break;
+                               case 'accounting'       : $column = 
'projects_accounting'; break;
+                               case 'hours'            : $column = 
'projects_hours'; break;
+                       }
+                       return $column;
+               }
+
+               function save_sessiondata($data, $action)
+               {
+                       if ($this->use_session)
+                       {
+                               $column = $this->type($action);
+                               
$GLOBALS['phpgw']->session->appsession('session_data',$column, $data);
+                       }
+               }
+
+               function read_sessiondata($action)
+               {
+                       $column = $this->type($action);
+                       $data = 
$GLOBALS['phpgw']->session->appsession('session_data',$column);
+
+                       $this->start            = $data['start'];
+                       $this->query            = $data['query'];
+                       $this->filter           = $data['filter'];
+                       $this->order            = $data['order'];
+                       $this->sort                     = $data['sort'];
+                       $this->cat_id           = $data['cat_id'];
+                       $this->status           = $data['status'];
+                       $this->state            = $data['state'];
+                       $this->project_id       = $data['project_id'];
+               }
+
+               function check_perms($has, $needed)
+               {
+                       return (!!($has & $needed) == True);
+               }
+
+               function edit_perms($pro)
+               {
+                       $type = isset($pro['type'])?$pro['type']:'edit';
+
+                       switch($type)
+                       {
+                               case 'delete':  $acl = PHPGW_ACL_DELETE;
+                               default:                $acl = PHPGW_ACL_EDIT;
+                       }
+
+                       if($pro['project_id'] && !$pro['coordinator'])
+                       {
+                               $pro['coordinator']     = 
$this->soprojects->return_value('co',$pro['project_id']);
+                       }
+
+                       
if($this->check_perms($this->grants[$pro['coordinator']],$acl) || 
$pro['coordinator'] == $this->account)
+                       {
+                               return True;
+                       }
+                       if($this->isprojectadmin('pad') || 
$this->isprojectadmin('pmanager'))
+                       {
+                               return True;
+                       }
+
+                       switch($pro['action'])
+                       {
+                               case 'subs':
+                                       if($pro['main_co'])
+                                       {
+                                               $main_co = $pro['main_co'];
+                                       }
+                                       else
+                                       {
+                                               if($pro['project_id'] && 
!$pro['main'])
+                                               {
+                                                       $pro['main'] = 
$this->soprojects->return_value('main',$pro['project_id']);
+                                               }
+                                               $main_co = 
$this->soprojects->return_value('co',$pro['main']);
+                                       }
+                                       
if($this->check_perms($this->grants[$main_co],$acl) || $main_co == 
$this->account)
+                                       {
+                                               return True;
+                                       }
+                                       if($pro['parent_co'])
+                                       {
+                                               $parent_co = $pro['parent_co'];
+                                       }
+                                       else
+                                       {
+                                               if($pro['project_id'] && 
!$pro['parent'])
+                                               {
+                                                       $pro['parent'] = 
$this->soprojects->return_value('parent',$pro['project_id']);
+                                               }
+                                               $parent_co = 
$this->soprojects->return_value('co',$pro['parent']);
+                                       }
+                                       
if($this->check_perms($this->grants[$parent_co],$acl) || $parent_co == 
$this->account)
+                                       {
+                                               return True;
+                                       }
+                                       break;
+                       }
+                       return False;
+               }
+
+               function add_perms($pro)
+               {
+                       if($this->status == 'archive')
+                       {
+                               return False;
+                       }
+                       switch($pro['action'])
+                       {
+                               case 'mains':
+                                       if (intval($this->cat_id) > 0)
+                                       {
+                                               $cat = 
$this->cats->return_single($this->cat_id);
+
+                                               if ($cat[0]['app_name'] == 
'phpgw' || $cat[0]['owner'] == -1)
+                                               {
+                                                       return True;
+                                               }
+                                               else if 
($this->check_perms($this->grants[$cat[0]['owner']],PHPGW_ACL_ADD) || 
$cat[0]['owner'] == $this->account)
+                                               {
+                                                       return True;
+                                               }
+                                       }
+                                       elseif(intval($this->cat_id) == 0 && 
intval($pro['cat']) == 0)
+                                       {
+                                               return True;
+                                       }
+                                       elseif(intval($pro['cat']) > 0)
+                                       {
+                                               $cat = 
$this->cats->return_single(intval($pro['cat']));
+
+                                               if ($cat[0]['app_name'] == 
'phpgw' || $cat[0]['owner'] == -1)
+                                               {
+                                                       return True;
+                                               }
+                                               else if 
($this->check_perms($this->grants[$cat[0]['owner']],PHPGW_ACL_ADD) || 
$cat[0]['owner'] == $this->account)
+                                               {
+                                                       return True;
+                                               }
+                                       }
+                                       else 
if($this->check_perms($this->grants[$pro['coordinator']],PHPGW_ACL_ADD) || 
$pro['coordinator'] == $this->account && !is_array($cat))
+                                       {
+                                               return True;
+                                       }
+                                       else if($this->isprojectadmin('pad') || 
$this->isprojectadmin('pmanager') && !is_array($cat))
+                                       {
+                                               return True;
+                                       }
+                                       break;
+                               case 'subs':
+                                       
if($this->check_perms($this->grants[$pro['coordinator']],PHPGW_ACL_ADD) || 
$pro['coordinator'] == $this->account)
+                                       {
+                                               return True;
+                                       }
+                                       //$main_co = 
$this->soprojects->return_value('co',$pro['main']);
+                                       
if($this->check_perms($this->grants[$pro['main_co']],PHPGW_ACL_ADD) || 
$pro['main_co'] == $this->account)
+                                       {
+                                               return True;
+                                       }
+                                       $parent_co = 
$this->soprojects->return_value('co',$pro['parent']);
+                                       
if($this->check_perms($this->grants[$parent_co],PHPGW_ACL_ADD) || $parent_co == 
$this->account)
+                                       {
+                                               return True;
+                                       }
+                                       if($this->isprojectadmin('pad') || 
$this->isprojectadmin('pmanager'))
+                                       {
+                                               return True;
+                                       }
+                                       break;
+                       }
+                       return False;
+               }
+
+               function cached_accounts($account_id)
+               {
+                       $this->accounts = 
CreateObject('phpgwapi.accounts',$account_id);
+
+                       $this->accounts->read_repository();
+
+                       
$cached_data[$this->accounts->data['account_id']]['account_id']         = 
$this->accounts->data['account_id'];
+                       
$cached_data[$this->accounts->data['account_id']]['account_lid']        = 
$this->accounts->data['account_lid'];
+                       
$cached_data[$this->accounts->data['account_id']]['firstname']          = 
$this->accounts->data['firstname'];
+                       
$cached_data[$this->accounts->data['account_id']]['lastname']           = 
$this->accounts->data['lastname'];
+
+                       return $cached_data;
+               }
+
+               function return_date()
+               {
+                       $date = array
+                       (
+                               'month'         => 
$GLOBALS['phpgw']->common->show_date(time(),'n'),
+                               'day'           => 
$GLOBALS['phpgw']->common->show_date(time(),'d'),
+                               'year'          => 
$GLOBALS['phpgw']->common->show_date(time(),'Y')
+                       );
+
+                       $date['daydate']                = 
mktime(12,0,0,$date['month'],$date['day'],$date['year']);
+                       $date['monthdate']              = 
mktime(12,0,0,$date['month']+2,0,$date['year']);
+                       $date['monthformatted'] = 
$GLOBALS['phpgw']->common->show_date($date['monthdate'],'n/Y');
+                       return $date;
+               }
+
+               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');
+
+                       $entries = $this->contacts->get_persons($cols, 
$GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'], $start, 
$order, $sort);//, $criteria);
+
+                       $this->total_records = $this->contacts->total_records;
+                       return $entries;
+               }
+
+               function read_single_contact($abid)
+               {
+                       $cols = array('contact_id', 
'per_first_name','per_last_name','org_name','people');
+                       $criteria = array('contact_id' => intval($abid));//, 
'my_preferred' => 'Y');
+
+                       return $this->contacts->get_persons($cols, 
$limit='',$start = '',$order='', $sort='',$criteria);
+                       //_debug_array($co);
+               }
+
+               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);
+
+                       if($useronly)
+                       {
+                               $employees      = $acl_users['users'];
+                               return $employees;
+                       }
+                       else
+                       {
+                               return $acl_users;
+                       }
+               }
+
+               function get_acl_for_project($project_id = 0)
+               {
+                       if(intval($project_id) > 0)
+                       {
+                               return 
$GLOBALS['phpgw']->acl->get_ids_for_location($project_id, 7);
+                       }
+                       return False;
+               }
+
+               function get_employee_projects($account_id = 0)
+               {
+                       if(intval($account_id) > 0)
+                       {
+                               return 
$this->soprojects->get_employee_projects($account_id);
+                       }
+                       return False;
+               }
+
+               function selected_employees($data = 0)
+               {
+                       $project_id = intval($data['project_id']);
+                       $pro_parent = intval($data['pro_parent']);
+
+                       if(intval($project_id) > 0)
+                       {
+                               $emps = $this->get_acl_for_project($project_id);
+                       }
+                       else
+                       {
+                               $emps = $this->read_projects_acl();
+                       }
+
+                       if(isset($data['action']) && $data['action'] == 'subs')
+                       {
+                               $parent_select = 
$this->get_acl_for_project($pro_parent);
+
+                               $k = 0;
+                               if(is_array($parent_select))
+                               {
+                                       for($i=0;$i<count($emps);$i++)
+                                       {
+                                               
if(in_array($emps[$i],$parent_select))
+                                               {
+                                                       $emp[$k] = $emps[$i];
+                                                       $k++;
+                                               }
+                                       }
+                               }
+                               if(is_array($emp))
+                               {
+                                       $emps = array();
+                                       $emps = $emp;
+                               }
+                       }
+
+                       if($data['admins_included'] == True)
+                       {
+                               $co = 
$this->soprojects->return_value('co',$project_id?$project_id:$pro_parent);
+
+                               //echo 'CO:' . $co;
+                               if(is_array($emps) && !in_array($co,$emps))
+                               {
+                                       $i = count($emps);
+                                       $emps[$i] = $co;
+                               }
+                               else
+                               {
+                                       $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($data['roles_included'] == True)
+                               {
+                                       $role_name = 
$this->soprojects->return_value('role',$project_id,$emps[$i]);
+                               }
+
+                               $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
+                               );
+                       }
+                       asort($empl);
+                       reset($empl);
+                       return $empl;
+               }
+
+               function get_time_used($data)
+               {
+                       if($this->siteconfig['accounting'] == 'activity')
+                       {
+                               return 
$this->sohours->get_activity_time_used($data);
+                       }
+                       else
+                       {
+                               return $this->sohours->get_time_used($data);
+                       }
+               }
+
+               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']));
+                               return 
$data['is_billable']?$budget['bbudget']:$budget['budget'];
+                       }
+                       else
+                       {
+                               $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
+                               {
+                                       return $budget;
+                               }
+                       }
+               }
+
+// BUDGET FOR ACTIVIES
+
+               function get_activity_budget($params)
+               {
+                       $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;
+                                       if($sub['parent'] == 
$params['project_id'])
+                                       {
+                                               $sum_budget += $sub['budget'];
+                                               $sum_ptime += 
$sub['time_planned'];
+                                       }
+                               }
+
+                               $acc = array();
+
+                               if($params['page'] == 'planned')
+                               {
+                                       $acc['pbudget_jobs']    = $sum_budget;
+                                       $ptimejobs                              
= $this->sohours->format_wh($sum_ptime);
+                                       $acc['ptime_jobs']              = 
$ptimejobs['whwm'];
+                                       $acc['ptime_jobs_min']  = $sum_ptime;
+                                       return $acc;
+                               }
+                       }
+                       $uhours_pro                     = 
$this->sohours->get_activity_time_used(array('project_id' => 
$params['project_id']));
+                       $uhours_pro_nobill      = 
$this->sohours->get_activity_time_used(array('project_id' => 
$params['project_id'],'no_billable' => True));
+                       $uhours_pro_bill        = $uhours_pro - 
$uhours_pro_nobill;
+
+                       $formatted_uhours_pro                   = 
$this->sohours->format_wh($uhours_pro);
+                       $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_wminutes']             = $uhours_pro;
+
+                       $formatted_ahours_pro                   = 
$this->sohours->format_wh($params['ptime'] - $uhours_pro);
+                       $acc['ahours_pro']                              = 
$formatted_ahours_pro['whwm'];
+
+                       $uhours_jobs            = 
$this->sohours->get_activity_time_used(array('project_array' => $sub_pro));
+                       $uhours_jobs_nobill     = 
$this->sohours->get_activity_time_used(array('project_array' => 
$sub_pro,'no_billable' => True));
+                       $uhours_jobs_bill       = $uhours_jobs - 
$uhours_jobs_nobill;
+
+                       $formatted_uhours_jobs                  = 
$this->sohours->format_wh($uhours_jobs);
+                       $formatted_uhours_jobs_bill             = 
$this->sohours->format_wh($uhours_jobs_bill);
+                       $formatted_uhours_jobs_nobill   = 
$this->sohours->format_wh($uhours_jobs_nobill);
+
+                       $acc['uhours_jobs']                             = 
$formatted_uhours_jobs['whwm'];
+                       $acc['uhours_jobs_nobill']              = 
$formatted_uhours_jobs_nobill['whwm'];
+                       $acc['uhours_jobs_bill']                = 
$formatted_uhours_jobs_bill['whwm'];
+                       $acc['uhours_jobs_wminutes']    = $uhours_jobs;
+
+                       $formatted_ahours_jobs                  = 
$this->sohours->format_wh($params['ptime'] - $uhours_jobs);
+                       $acc['ahours_jobs']                             = 
$formatted_ahours_jobs['whwm'];
+
+                       if($params['page'] == 'budget')
+                       {
+                               $acc['u_budget'] = 
$this->calculate_budget(array('project_id' => $params['project_id']));
+                               $acc['b_budget'] = 
$this->calculate_budget(array('project_id' => 
$params['project_id'],'is_billable' => True));
+
+                               $acc['u_budget_jobs'] = 
$this->calculate_budget(array('project_array' => $sub_pro));
+                               $acc['b_budget_jobs'] = 
$this->calculate_budget(array('project_array' => $sub_pro,'is_billable' => 
True));
+                       }
+                       return $acc;
+               }
+
+               function get_budget($params)
+               {
+                       if($this->siteconfig['accounting'] == 'activity')
+                       {
+                               return $this->get_activity_budget($params);
+                       }
+                       else
+                       {
+                               if(!$params['billable'])
+                               {
+                                       $params['billable'] = 
$this->return_value('billable',$params['project_id']);
+                               }
+
+                               $subs = $this->get_sub_projects($params);
+
+                               if(is_array($subs))
+                               {
+                                       $i = 0;
+                                       foreach($subs as $sub)
+                                       {
+                                               switch($sub['billable'])
+                                               {
+                                                       case 'N': 
$sub_pro_nobill[$i]   = $sub['project_id']; break;
+                                                       case 'Y': 
$sub_pro_bill[$i]             = $sub['project_id']; break;
+                                               }
+
+                                               $sub_pro[$i] = 
$sub['project_id'];
+                                               ++$i;
+                                               if($sub['parent'] == 
$params['project_id'])
+                                               {
+                                                       $sum_budget += 
$sub['budget'];
+                                                       $sum_ptime += 
$sub['time_planned'];
+                                               }
+                                       }
+                               }
+
+                               $acc = array();
+
+                               if($params['page'] == 'planned')
+                               {
+                                       $acc['pbudget_jobs']    = $sum_budget;
+                                       $ptimejobs                              
= $this->sohours->format_wh($sum_ptime);
+                                       $acc['ptime_jobs']              = 
$ptimejobs['whwm'];
+                                       $acc['ptime_jobs_min']  = $sum_ptime;
+                                       return $acc;
+                               }
+
+                               // ------ 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);
+
+                               $uhours_pro_bill = $uhours_pro_nobill = 
$uhours_pro = 0;
+                               if(is_array($h_pro))
+                               {
+                                       foreach($h_pro as $hp)
+                                       {
+                                               if($hp['billable'] == 'Y')
+                                               {
+                                                       $uhours_pro_bill += 
$hp['minutes'];
+                                               }
+                                               elseif($hp['billable'] == 'N')
+                                               {
+                                                       $uhours_pro_nobill += 
$hp['minutes'];
+                                               }
+                                       }
+                                       $uhours_pro = $uhours_pro_bill + 
$uhours_pro_nobill;
+                               }
+                               else
+                               {
+                                       $uhours_pro_bill = $uhours_pro_nobill = 
$uhours_pro = 0;
+                               }
+
+                               if($params['billable'] == 'N')
+                               {
+                                       $uhours_pro_nobill      = $uhours_pro;
+                                       $uhours_pro_bill        = 0;
+                               }
+
+                               $formatted_uhours_pro                   = 
$this->sohours->format_wh($uhours_pro);
+                               $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_wminutes']     = $uhours_pro;
+
+                               $formatted_ahours_pro           = 
$this->sohours->format_wh($params['ptime'] - $uhours_pro);
+                               $acc['ahours_pro']                      = 
$formatted_ahours_pro['whwm'];
+
+                               //echo 'uhours_pro:' . $uhours_pro;
+                               //_debug_array($acc);
+
+                               // ------ jobs included ------
+
+                               $h_jobs_bill = 
$this->sohours->get_time_used(array('project_array' => $sub_pro_bill)); // 
project is billable
+
+                               if(is_array($h_jobs_bill))
+                               {
+                                       foreach($h_jobs_bill as $hjb)
+                                       {
+                                               if($hjb['billable'] == 'Y')
+                                               {
+                                                       $uhours_jobs_bill += 
$hjb['minutes'];
+                                               }
+                                               elseif($hjb['billable'] == 'N')
+                                               {
+                                                       $uhours_jobs_nobill += 
$hjb['minutes'];
+                                               }
+                                       }
+                               }
+                               else
+                               {
+                                       $uhours_jobs_bill = $uhours_jobs_nobill 
= 0;
+                               }
+
+                               $h_jobs_nobill = 
$this->sohours->get_time_used(array('project_array' => $sub_pro_nobill)); // 
project is not billable
+
+                               if(is_array($h_jobs_nobill))
+                               {
+                                       foreach($h_jobs_nobill as $hjnb)
+                                       {
+                                               $uhours_jobs_nobill += 
$hjnb['minutes'];
+                                       }
+                               }
+
+                               $uhours_jobs = $uhours_jobs_bill + 
$uhours_jobs_nobill;
+
+                               $formatted_uhours_jobs                  = 
$this->sohours->format_wh($uhours_jobs);
+                               $formatted_uhours_jobs_bill             = 
$this->sohours->format_wh($uhours_jobs_bill);
+                               $formatted_uhours_jobs_nobill   = 
$this->sohours->format_wh($uhours_jobs_nobill);
+
+                               $acc['uhours_jobs']                             
= $formatted_uhours_jobs['whwm'];
+                               $acc['uhours_jobs_nobill']              = 
$formatted_uhours_jobs_nobill['whwm'];
+                               $acc['uhours_jobs_bill']                = 
$formatted_uhours_jobs_bill['whwm'];
+                               $acc['uhours_jobs_wminutes']    = $uhours_jobs;
+
+                               $formatted_ahours_jobs          = 
$this->sohours->format_wh($params['ptime'] - $uhours_jobs);
+                               $acc['ahours_jobs']                     = 
$formatted_ahours_jobs['whwm'];
+
+                               if($params['page'] == 'budget')
+                               {
+                                       switch($params['accounting'])
+                                       {
+                                               case 'project':
+                                                       if(is_array($h_pro))
+                                                       {
+                                                               foreach($h_pro 
as $hp)
+                                                               {
+                                                                       
if($params['billable'] == 'Y' && $hp['billable'] == 'Y')
+                                                                       {
+                                                                               
$acc['b_budget'] += $this->calculate_budget(array('factor' => 
$params['project_accounting_factor'],'minutes' => $hp['minutes'],
+                                                                               
                                                                                
                        'surcharge' => $hp['surcharge']));
+                                                                       }
+                                                                       else
+                                                                       {
+                                                                               
$acc['nb_budget'] += $this->calculate_budget(array('factor' => 
$params['project_accounting_factor'],'minutes' => $hp['minutes'],
+                                                                               
                                                                                
                        'surcharge' => $hp['surcharge']));
+                                                                       }
+                                                               }
+                                                               
$acc['u_budget'] = $acc['nb_budget'] + $acc['b_budget'];
+                                                       }
+                                                       break;
+                                               case 'employee':
+                                                       $emps_pro = 
$this->sohours->get_employee_time_used(array('project_id' => 
$params['project_id']));
+                                                       
//_debug_array($emps_pro);
+
+                                                       
for($i=0;$i<count($emps_pro);$i++)
+                                                       {
+                                                               $factor = 
$this->soconfig->return_value('acc',$emps_pro[$i]['employee']);
+                                                               
//_debug_array($factor);
+                                                               
if(is_array($emps_pro[$i]['hours']))
+                                                               {
+                                                                       
foreach($emps_pro[$i]['hours'] as $wh)
+                                                                       {
+                                                                               
$wh['factor'] = 0;
+                                                                               
if(is_array($factor))
+                                                                               
{
+                                                                               
        for($j=0;$j<count($factor);++$j)
+                                                                               
        {
+                                                                               
                if($wh['sdate']>=$factor[$j]['sdate'] && 
$wh['edate']<=$factor[$j]['edate'])
+                                                                               
                {
+                                                                               
                        $wh['factor'] = $factor[$j]['factor'];
+                                                                               
                }
+                                                                               
                else if($factor[$j]['sdate']==0)
+                                                                               
                {
+                                                                               
                        $wh['factor'] = $factor[$j]['factor'];
+                                                                               
                }
+                                                                               
        }
+                                                                               
}
+                                                                               
$bill = $this->calculate_budget(array('factor' => $wh['factor'],'minutes' => 
$wh['minutes'],'surcharge' => $wh['surcharge']));
+
+                                                                               
if($wh['billable'] == 'Y')
+                                                                               
{
+                                                                               
        $acc['b_budget'] += $bill;
+                                                                               
}
+                                                                               
else
+                                                                               
{
+                                                                               
        $acc['nb_budget'] += $bill;
+                                                                               
}
+                                                                       }
+                                                               }
+                                                       }
+
+                                                       $acc['u_budget'] = 
$acc['b_budget'] + $acc['nb_budget'];
+                                                       if($params['billable'] 
== 'N')
+                                                       {
+                                                               
$acc['b_budget'] = 0;
+                                                       }
+                                                       
//_debug_array($emps_pro);
+                                                       break;
+                                       }
+
+                                       for($i=0;$i<count($subs);$i++)
+                                       {
+                                               $sub_b_budget = $sub_nb_budget 
= 0;
+                                               switch($subs[$i]['accounting'])
+                                               {
+                                                       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)
+                                                                       {
+                                                                               
if($subs[$i]['billable'] == 'Y' && $hs['billable'] == 'Y')
+                                                                               
{
+                                                                               
        $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
+                                                                               
{
+                                                                               
        $sub_nb_budget += $this->calculate_budget(array('factor' => 
$subs[$i]['acc_factor'],'minutes' => $hs['minutes'],
+                                                                               
                                                                                
                        'surcharge' => $hs['surcharge']));
+                                                                               
}
+                                                                       }
+                                                               }
+                                                               break;
+                                                       case 'employee':
+                                                               $emps_sub = 
$this->sohours->get_employee_time_used(array('project_id' => 
$subs[$i]['project_id']));
+
+                                                               
for($k=0;$k<count($emps_sub);$k++)
+                                                               {
+                                                                       $factor 
= $this->soconfig->return_value('acc',$emps_sub[$k]['employee']);
+                                                                       
if(is_array($emps_sub[$k]['hours']))
+                                                                       {
+                                                                               
foreach($emps_sub[$k]['hours'] as $wh)
+                                                                               
{
+                                                                               
        $wh['factor'] = 0;
+                                                                               
        if(is_array($factor))
+                                                                               
        {
+                                                                               
                for($j=0;$j<count($factor);++$j)
+                                                                               
                {
+                                                                               
                        if($wh['sdate']>=$factor[$j]['sdate'] && 
$wh['edate']<=$factor[$j]['edate'])
+                                                                               
                        {
+                                                                               
                                $wh['factor'] = $factor[$j]['factor'];
+                                                                               
                        }
+                                                                               
                        else if($factor[$j]['sdate']==0)
+                                                                               
                        {
+                                                                               
                                $wh['factor'] = $factor[$j]['factor'];
+                                                                               
                        }
+                                                                               
                }
+                                                                               
        }
+
+                                                                               
        if($subs[$i]['billable'] == 'Y' && $wh['billable'] == 'Y')
+                                                                               
        {
+                                                                               
                $sub_b_budget += $this->calculate_budget(array('factor' => 
$wh['factor'],'minutes' => $wh['minutes'],
+                                                                               
                                                                                
                                'surcharge' => $wh['surcharge']));
+                                                                               
        }
+                                                                               
        else
+                                                                               
        {
+                                                                               
                $sub_nb_budget += $this->calculate_budget(array('factor' => 
$wh['factor'],'minutes' => $wh['minutes'],
+                                                                               
                                                                                
                                'surcharge' => $wh['surcharge']));
+                                                                               
        }
+                                                                               
}
+                                                                       }
+                                                               }
+                                                               break;
+                                               }
+                                               $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;
+                               }
+                               //_debug_array($acc);
+                               return $acc;
+                       }
+               }
+
+               function get_sub_projects($params)
+               {
+                       switch($params['page'])
+                       {
+                               case 'planned':                 $column = 
'project_id,parent,level,budget,time_planned'; break;
+                               case 'hours':
+                               case 'budget':                  $column = 
'project_id,accounting,acc_factor,billable,level'; break;
+                       }
+                       $subs = $this->soprojects->read_projects(array('column' 
=> $column,'limit' => False,'action' => 'subs','parent' => 
$params['project_id']));
+
+                       $i = count($subs);
+                       $subs[$i]['project_id'] = $params['project_id'];
+                       $subs[$i]['accounting'] = $params['accounting'];
+                       $subs[$i]['billable'] = $params['billable'];
+                       $subs[$i]['acc_factor'] = 
$params['project_accounting_factor'];
+
+                       //_debug_array($subs);
+                       return $subs;
+               }
+
+               function colored($value, $limit = 0,$used = 0,$action = 
'budget')
+               {
+                       $event_extra = 
$this->soconfig->get_event_extra($action=='budget'?'budget limit':'hours 
limit');
+
+                       //echo 'EXTRA: ' . $event_extra . '<br>';
+                       //echo 'limit: ' . $limit . '<br>';
+                       $used_percent = ($limit*intval($event_extra))/100;
+                       //echo 'percent: ' . $used_percent . '<br>';
+
+                       //echo 'used: ' . $used . '<br>';
+                       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 sprintf("%01.2f",$value);
+               }
+
+               function formatted_priority($pri = 0)
+               {
+                       $green  = $pri <= 3?True:False;
+                       $yel    = ($pri > 3 && $pri <= 7)?True:False;
+                       $red    = $pri > 7?True:False;
+
+                       $color = ($green?'38BB00':($yel?'ECC200':'CC0000'));
+
+                       return '<font color="' . $color . '">' . $pri . 
'</font>';
+               }
+
+               function list_projects($params)
+               {
+                       if($params['function'] == 'gantt')
+                       {
+                               $pro_list = 
$this->soprojects->read_gantt_projects(array('project_id' => 
$params['project_id'],'parent_array' => $params['parent_array']));
+                       }
+                       else
+                       {
+                               $pro_list = 
$this->soprojects->read_projects(array
+                                                                       (
+                                                                               
'start'                 => $this->start,
+                                                                               
'limit'                 => $this->limit,
+                                                                               
'query'                 => $this->query,
+                                                                               
'filter'                => $this->filter,
+                                                                               
'sort'                  => $this->sort,
+                                                                               
'order'                 => $this->order,
+                                                                               
'status'                => $this->status,
+                                                                               
'cat_id'                => ($params['action'] == 'mains'?$this->cat_id:0),
+                                                                               
'action'                => $params['action'],
+                                                                               
'parent'                => $params['parent'],
+                                                                               
'main'                  => $params['main'],
+                                                                               
'project_id'    => $params['project_id']
+                                                                       ));
+                       }
+
+                       $this->total_records = $this->soprojects->total_records;
+                       if(is_array($pro_list))
+                       {
+                               foreach($pro_list as $pro)
+                               {
+                                       /*$cached_data = 
$this->cached_accounts($pro['coordinator']);
+                                       $coordinatorout = 
$GLOBALS['phpgw']->common($cached_data[$pro['coordinator']]['account_lid']
+                                        . ' [' . 
$cached_data[$pro['coordinator']]['firstname'] . ' '
+                                        . 
$cached_data[$pro['coordinator']]['lastname'] . ' ]');*/
+
+                                       $customerout = '';
+                                       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'] 
. ' ]'; }
+                                       }
+
+                                       $mstones = 
$this->get_mstones($pro['project_id']);
+
+                                       if (!isset($params['mstones_stat']))
+                                       {
+                                               $mlist = '';
+                                               if (is_array($mstones))
+                                               {
+                                                       $mlist = '<table 
width="100%" border="0" cellpadding="0" cellspacing="0">' . "\n";
+                                                       for 
($i=0;$i<count($mstones);$i++)
+                                                       {
+                                                               $mlist .= 
'<tr><td width="50%">' . $mstones[$i]['title'] . '</td><td width="50%" 
align="right">' . $this->formatted_edate($mstones[$i]['edate']) . '</td></tr>' 
. "\n";
+                                                       }
+                                                       $mlist .= '</table>';
+                                               }
+                                       }
+
+                                       if($params['page'] == 'budget' || 
$params['page'] == 'hours')
+                                       {
+                                               $params['project_id']           
                        = $pro['project_id'];
+                                               $params['accounting']           
                        = $pro['accounting'];
+                                               
$params['project_accounting_factor']    = $pro['project_accounting_factor'];
+                                               $params['billable']             
                                = $pro['billable'];
+                                               $params['ptime']                
                                = $pro['ptime'];
+                                               $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');
+
+                                       $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']);
+
+                                       $space = '';
+                                       if ($pro['level'] > 0 && 
!isset($params['no_formatted_level']))
+                                       {
+                                               $space = 
($this->html_output?'&nbsp;.&nbsp;':'.');
+                                               $spaceset = 
str_repeat($space,$pro['level']);
+                                       }
+
+                                       $projects[] = array
+                                       (
+                                               'project_id'            => 
$pro['project_id'],
+                                               'priority'                      
=> $this->formatted_priority($pro['priority']),
+                                               'title'                         
=> $spaceset . $GLOBALS['phpgw']->strip_html($pro['title']),
+                                               'number'                        
=> $GLOBALS['phpgw']->strip_html($pro['number']),
+                                               'investment_nr'         => 
$GLOBALS['phpgw']->strip_html($pro['investment_nr']),
+                                               'coordinatorout'        => 
$GLOBALS['phpgw']->common->grab_owner_name($pro['coordinator']),
+                                               'customerout'           => 
$customerout,
+                                               'customer_nr'           => 
$GLOBALS['phpgw']->strip_html($pro['customer_nr']),
+                                               'cat'                           
=> $pro['cat'],
+                                               'sdateout'                      
=> $this->formatted_edate($pro['sdate'],False),
+                                               'edateout'                      
=> $this->formatted_edate($pro['edate']),
+                                               'sdate'                         
=> $pro['sdate'],
+                                               'edate'                         
=> $pro['edate'],
+                                               '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',
+                                               'budget'                        
=> $pro['budget'],
+                                               'e_budget'                      
=> $pro['e_budget'],
+                                               'url'                           
=> $GLOBALS['phpgw']->strip_html($pro['url']),
+                                               'reference'                     
=> $GLOBALS['phpgw']->strip_html($pro['reference']),
+                                               'accountingout'         => 
lang('per') . ' ' . lang($pro['accounting']),
+                                               'project_accounting_factor'     
=> $pro['project_accounting_factor'],
+                                               'project_accounting_factor_d'   
=> $pro['project_accounting_factor_d'],
+                                               'billableout'           => 
$pro['billable']=='Y'?lang('yes'):lang('no'),
+                                               'discountout'           => 
$pro['discount_type']=='percent'?'%':$GLOBALS['phpgw_info']['user']['preferences']['common']['currency']
+                                                                               
                 . ' ' . $pro['discount'],
+                                               'mstones'                       
=> (isset($params['mstones_stat'])?$mstones:$mlist),
+                                               'main'                          
=> $pro['main'],
+                                               'parent'                        
=> $pro['parent'],
+                                               'coordinator'           => 
$pro['coordinator'],
+                                               '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',
+                                               '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',
+                                       );
+                               }
+                       }
+                       return $projects;
+               }
+
+               function format_date($date = 0)
+               {
+                       $d = array();
+                       if($date > 0)
+                       {
+                               $d['date'] = $date + (60*60) * 
$GLOBALS['phpgw_info']['user']['preferences']['common']['tz_offset'];
+                               $d['date_formatted'] = 
$GLOBALS['phpgw']->common->show_date($date,$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
+                       }
+                       return $d;
+               }
+
+               function formatted_edate($edate = 0,$colored = True,$type = 
'project')
+               {
+                       $edate = intval($edate);
+
+                       $month  = 
$GLOBALS['phpgw']->common->show_date(time(),'n');
+                       $day    = 
$GLOBALS['phpgw']->common->show_date(time(),'d');
+                       $year   = 
$GLOBALS['phpgw']->common->show_date(time(),'Y');
+
+                       if ($edate > 0)
+                       {
+                               $edate = $edate + (60*60) * 
$GLOBALS['phpgw_info']['user']['preferences']['common']['tz_offset'];
+                               $edateout = 
$GLOBALS['phpgw']->common->show_date($edate,$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
+                       }
+                       if($this->html_output && $colored)
+                       {
+                               switch($type)
+                               {
+                                       case 'ms':      $event = 'milestone 
date due'; break;
+                                       default:        $event = 'project date 
due'; break;
+                               }
+
+                               $event_extra = 
$this->soconfig->get_event_extra($event);
+
+                               /*if 
(mktime(2,0,0,$month,$day+($event_extra*2),$year) >= $edate)
+                               {
+                                       $edateout = '<font color="ECC200"><b>' 
. $edateout . '</b></font>';
+                               }*/
+                               if 
(mktime(12,0,0,$month,$day+$event_extra,$year) >= $edate)
+                               {
+                                       $edateout = '<font color="CC0000"><b>' 
. $edateout . '</b></font>';
+                               }
+                       }
+                       return $edateout;
+               }
+
+               function read_single_project($project_id,$page = 'bla',$view = 
False)
+               {
+                       $pro = 
$this->soprojects->read_single_project($project_id);
+
+                       $check_pro = array
+                       (
+                               'coordinator'   => $pro['coordinator'],
+                               'main'                  => $pro['main'],
+                               'parent'                => $pro['parent'],
+                               'action'                => 
($pro['parent']>0?'subs':'mains')
+                       );
+
+                       if(!$view)
+                       {
+                               $perms = $this->edit_perms($check_pro);
+
+                               if (!$perms || !is_array($pro))
+                               {
+                                       return False;
+                               }
+                       }
+
+                       if($page == 'budget' || $page == 'hours' || $page = 
'planned')
+                       {
+                               $acc = 
$this->get_budget(array('project_accounting_factor' => 
$pro['project_accounting_factor'],'accounting' => $pro['accounting'],
+                                                                               
        'project_id' => $project_id,'page' => $page,'action' => $action,'ptime' 
=> $pro['ptime']));
+                               $atime = 
$this->sohours->format_wh($pro['ptime']-$acc['ptime_jobs_min']);
+                       }
+
+                       $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');
+
+                       $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']);
+
+                       $project = array
+                       (
+                               'ptime'                         => 
($pro['ptime']/60) . '.00',
+                               'ptime_min'                     => 
$pro['ptime'],
+                               'ptime_jobs'            => $acc['ptime_jobs'],
+                               'atime'                         => 
$atime['whwm'],
+                               'title'                         => 
$GLOBALS['phpgw']->strip_html($pro['title']),
+                               'number'                        => 
$GLOBALS['phpgw']->strip_html($pro['number']),
+                               'investment_nr'         => 
$GLOBALS['phpgw']->strip_html($pro['investment_nr']),
+                               'descr'                         => 
$GLOBALS['phpgw']->strip_html($pro['descr']),
+                               'budget'                        => 
$pro['budget'],
+                               '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'],
+                               'a_budget_jobs'         => 
$pro['budget']-$acc['u_budget_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',
+                               'project_id'            => $pro['project_id'],
+                               'parent'                        => 
$pro['parent'],
+                               'main'                          => $pro['main'],
+                               'cat'                           => $pro['cat'],
+                               'access'                        => 
$pro['access'],
+                               'coordinator'           => $pro['coordinator'],
+                               'coordinatorout'        => 
$GLOBALS['phpgw']->common->grab_owner_name($pro['coordinator']),
+                               'customer'                      => 
$pro['customer'],
+                               'status'                        => 
$pro['status'],
+                               'owner'                         => 
$pro['owner'],
+                               'processor'                     => 
$pro['processor'],
+                               'previous'                      => 
$pro['previous'],
+                               'url'                           => 
$GLOBALS['phpgw']->strip_html($pro['url']),
+                               'reference'                     => 
$GLOBALS['phpgw']->strip_html($pro['reference']),
+                               'customer_nr'           => 
$GLOBALS['phpgw']->strip_html($pro['customer_nr']),
+                               'test'                          => 
$GLOBALS['phpgw']->strip_html($pro['test']),
+                               'quality'                       => 
$GLOBALS['phpgw']->strip_html($pro['quality']),
+                               'result'                        => 
$GLOBALS['phpgw']->strip_html($pro['result']),
+                               'accounting'            => $pro['accounting'],
+                               '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',
+                               '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',
+                               'priority'                      => 
$pro['priority'],
+                               'inv_method'            => 
$GLOBALS['phpgw']->strip_html($pro['inv_method']),
+                               'discount'                      => 
$pro['discount'],
+                               'discount_type'         => $pro['discount_type']
+                       );
+
+                       $date = $this->format_date($pro['edate']);
+                       $project['edate']                       = $date['date'];
+                       $project['edate_formatted'] = $date['date_formatted'];
+
+                       $date = $this->format_date($pro['sdate']);
+                       $project['sdate']                       = $date['date'];
+                       $project['sdate_formatted'] = $date['date_formatted'];
+
+                       $date = $this->format_date($pro['udate']);
+                       $project['udate']                       = $date['date'];
+                       $project['udate_formatted'] = $date['date_formatted'];
+
+                       $date = $this->format_date($pro['cdate'] == 
0?$pro['sdate']:$pro['cdate']);
+                       $project['cdate']                       = $date['date'];
+                       $project['cdate_formatted'] = $date['date_formatted'];
+
+                       $date = $this->format_date($pro['pedate']);
+                       $project['pedate']                              = 
$date['date'];
+                       $project['pedate_formatted']    = 
$date['date_formatted'];
+
+                       $date = $this->format_date($pro['psdate']);
+                       $project['psdate']                              = 
$date['date'];
+                       $project['psdate_formatted']    = 
$date['date_formatted'];
+
+                       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'] . ' 
]'; }
+                       }
+                       else { $project['customerout'] = '&nbsp;'; }
+
+                       //_debug_array($project);
+                       return $project;
+               }
+
+               function sum_budget($values)
+               {
+                       return $this->soprojects->sum_budget(array
+                                                                       (
+                                                                               
'start'         => $this->start,
+                                                                               
'limit'         => False,
+                                                                               
'query'         => $this->query,
+                                                                               
'filter'        => $this->filter,
+                                                                               
'sort'          => $this->sort,
+                                                                               
'order'         => $this->order,
+                                                                               
'status'        => $this->status,
+                                                                               
'cat_id'        => ($values['action'] == 'mains'?$this->cat_id:0),
+                                                                               
'action'        => $values['action'],
+                                                                               
'parent'        => $values['parent'],
+                                                                               
'main'          => $values['main'],
+                                                                               
'bcolumn'       => $values['bcolumn']
+                                                                       ));
+               }
+
+               function exists($action, $check, $num, $pa_id)
+               {
+                       return $this->soprojects->exists($action, $check , 
$num, $pa_id);
+               }
+
+               function check_values($action, $values)
+               {
+                       if (strlen($values['descr']) > 8000)
+                       {
+                               $error[] = lang('Description can not exceed 
8000 characters in length');
+                       }
+
+                       if (!$values['coordinator'])
+                       {
+                               $error[] = lang('please choose a project 
coordinator');
+                       }
+
+                       if(strlen($values['title']) == 0)
+                       {
+                               $error[] = lang('please enter a title');
+                       }
+                       else if(strlen($values['title']) > 250)
+                       {
+                               $error[] = lang('title can not exceed 250 
characters in length');
+                       }
+
+                       if (!$values['choose'])
+                       {
+                               if (! $values['number'])
+                               {
+                                       $error[] = lang('Please enter an ID');
+                               }
+                               else
+                               {
+                                       if (strlen($values['number']) > 250)
+                                       {
+                                               $error[] = lang('id can not 
exceed 250 characters in length');
+                                       }
+                               }
+                       }
+
+                       if($this->siteconfig['accounting'] == 'activity')
+                       {
+                               if ((!$values['book_activities']) && 
(!$values['bill_activities']))
+                               {
+                                       $error[] = lang('please choose 
activities for the project');
+                               }
+                       }
+                       else if(!$values['billable'])
+                       {
+                               if(!$values['accounting'])
+                               {
+                                       $error[] = lang('please choose the 
accounting system for the project');
+                               }
+                               else
+                               {
+                                       if($values['accounting'] == 'project' 
&& !$values['project_accounting_factor'] && 
!$values['project_accounting_factor_d'])
+                                       {
+                                               $error[] = lang('please set the 
accounting factor for the project');
+                                       }
+                               }
+                       }
+
+                       $values['discount'] = 
($values['discount']=='0.00')?0:$values['discount'];
+                       if($values['discount'] > 0 && !$values['discount_type'])
+                       {
+                               $error[] = lang('please choose the discount 
type');
+                       }
+
+                       if ($values['previous'])
+                       {
+                               $edate = 
$this->return_value('edate',$values['previous']);
+
+                               if (intval($edate) == 0)
+                               {
+                                       $error[] = lang('the choosen previous 
project does not have an end date specified');
+                               }
+                       }
+
+                       if ($action == 'subs')
+                       {
+                               $main_edate = 
$this->return_value('edate',$values['parent']);
+
+                               if ($main_edate > 0)
+                               {
+                                       if ($values['edate'] > $main_edate)
+                                       {
+                                               $error[] = lang('end date can 
not be after parent projects date due');
+                                       }
+                               }
+
+                               $main_sdate = 
$this->return_value('sdate',$values['parent']);
+
+                               if ($main_sdate > 0 && $values['sdate'] > 0)
+                               {
+                                       if ($values['sdate'] < $main_sdate)
+                                       {
+                                               $error[] = lang('start date can 
not be before parent projects start date');
+                                       }
+                               }
+
+                               $main_pedate = 
$this->return_value('pedate',$values['parent']);
+
+                               if ($main_pedate > 0)
+                               {
+                                       if ($values['pedate'] > $main_pedate)
+                                       {
+                                               $error[] = lang('end date 
planned can not be after parent projects end date planned');
+                                       }
+                               }
+
+                               $main_psdate = 
$this->return_value('psdate',$values['parent']);
+
+                               if ($main_psdate > 0 && $values['psdate'] > 0)
+                               {
+                                       if ($values['psdate'] < $main_psdate)
+                                       {
+                                               $error[] = lang('start date 
planned can not be before parent projects start date planned');
+                                       }
+                               }
+
+                               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');
+                                       }
+                               }
+
+                               $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;
+
+                               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']
+                                                                               
                                                        ,'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']);
+                               $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)
+                               {
+                                       $error[] = lang('extra budget sum of 
all sub projects is bigger than the extra budget of the main project');
+                               }
+                       }
+
+                       if (is_array($error))
+                       {
+                               return $error;
+                       }
+               }
+
+               function save_project($action, $values)
+               {
+                       if ($values['choose'])
+                       {
+                               switch($action)
+                               {
+                                       case 'mains':
+                                               $values['number'] = 
$this->soprojects->create_projectid(); break;
+                                       default:
+                                               $values['number'] = 
$this->soprojects->create_jobid($values['parent']); break;
+                               }
+                       }
+
+                       $values['ptime'] = intval($values['ptime'])*60;
+
+            if (!$values['sdate'])
+            {
+                $values['sdate'] = time();
+            }
+
+                       $values['edate'] = intval($values['edate']);
+
+                       if (!$values['previous'] && $values['parent'])
+                       {
+                               $values['previous'] = 
$this->return_value('previous',$values['parent']);
+                       }
+
+                       if ($values['project_accounting_factor'] || 
$values['project_accounting_factor_d'])
+                       {
+                               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;
+                               }
+                       }
+
+                       //echo 'start boprojects: save_project ->';
+                       //_debug_array($values);
+                       //echo 'end boprojects: save_project';
+
+                       $values['project_name'] = $values['title'] . ' [' . 
$values['number'] . ']';
+                       if (intval($values['project_id']) > 0)
+                       {
+                               $following = 
$this->soprojects->edit_project($values);
+
+                               if(is_array($following))
+                               {
+                                       $return = 
$this->send_alarm(array('project_name' => $values['project_name'],'event_type' 
=> 'project dependencies','project_id' => $values['project_id'],
+                                                                               
        'following' => $following,'edate' => $values['edate'],'old_edate' => 
$values['old_edate'],'is_previous' => True));
+
+                                       if($return)
+                                       {
+                                               foreach($following as $fol)
+                                               {
+                                                       $fol['previous_name']   
        = $values['project_name'];
+                                                       $fol['previous_edate']  
        = $values['edate'];
+                                                       
$fol['previous_old_edate']      = $values['old_edate'];
+                                                       $fol['project_name']    
        = $fol['title'] . ' [' . $fol['number'] . ']';
+                                                       $fol['event_type']      
                = 'project dependencies';
+                                                       $this->send_alarm($fol);
+                                               }
+                                       }
+                               }

-                       $this->soprojects       = 
CreateObject('projects.soprojects');
+                               $this->send_alarm(array('project_name' => 
$values['project_name'],'event_type' => 'changes of project data','project_id' 
=> $values['project_id']));

-                       if ($session)
+                               if($values['coordinator'] != 
$values['old_coordinator'])
+                               {
+                                       $this->send_alarm(array('account_id' => 
$values['coordinator'],'events' => array($event_id),'project_name' => 
$values['project_name'],
+                                                                               
        'event_type' => 'assignment to role','project_id' => 
$values['project_id']));
+                               }
+                       }
+                       else
                        {
-                               $this->read_sessiondata($action);
-                               $this->use_session = True;
+                               $values['project_id'] = 
$this->soprojects->add_project($values);
                        }

-                       global $start, $query, $filter, $order, $sort, $cat_id;
+                       $values['project_id'] = intval($values['project_id']);

-                       if(isset($start)) { $this->start = $start; }
-                       if(isset($query)) { $this->query = $query; }
-                       if(!empty($filter)) { $this->filter = $filter; }
-                       if(isset($sort)) { $this->sort = $sort; }
-                       if(isset($order)) { $this->order = $order; }
-                       if(isset($cat_id)) { $this->cat_id = $cat_id; }
-               }
+                       $values['old_edate'] = intval($values['old_edate']);
+                       $async = CreateObject('phpgwapi.asyncservice');
+                       if($values['edate'] > 0 && $values['old_edate'] != 
$values['edate'])
+                       {
+                               $event_extra = 
$this->soconfig->get_event_extra('project date due');
+                               $next = 
mktime(date('H',time()),date('i',time())+5,0,$values['emonth'],$values['eday']-$event_extra,$values['eyear']);

-               function type($action)
-               {
-                       switch ($action)
+                               $edate = $this->format_date($values['edate']);
+                               $async->write(array('id' => 'projects-' . 
$values['project_id'], 'next' => $next,'times' => array('year' => 
date('Y',$next),
+                                                                       'month' 
=> date('m',$next),'day' => date('d',$next),'hour' => date('H',$next),'min' => 
date('i',$next))
+                                                                       
,'account_id' => $values['coordinator'],'method' => 
'projects.boprojects.send_alarm',
+                                                                       'data' 
=> array('project_id' => $values['project_id'],'event_type' => 'project date 
due',
+                                                                       'edate' 
=> $edate['date_formatted'],'project_name' => $values['project_name'])));
+
+                               /*$async->write(array('id' => 'projects-' . 
$values['project_id'], 'next' => 0,'times' => array('min' => '5')
+                                                                       
,'account_id' => $values['coordinator'],'method' => 
'projects.boprojects.send_alarm',
+                                                                       'data' 
=> array('project_id' => $values['project_id'],'action' => 'prodatedue')));*/
+                       }
+
+                       if($values['edate'] == 0)
                        {
-                               case 'mains'    : $column = 'projects_mains'; 
break;
-                               case 'subs'             : $column = 
'projects_subs'; break;
-                               case 'act'              : $column = 
'projects_act'; break;
+                               $aid = 'projects-' . $values['project_id'];
+                               $async->delete($aid);
                        }
-                       return $column;
+                       unset($async);
+
+                       //_debug_array($values['employees']);
+                       if (is_array($values['employees']))
+                       {
+                               
$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);
+                               }
+                       }
+                       return $values['project_id'];
                }

-               function save_sessiondata($data, $action)
+               function select_project_list($values)
                {
-                       global $phpgw;
+                       return $this->soprojects->select_project_list($values);
+               }

-                       if ($this->use_session)
+               function delete_project($pa_id, $subs, $action = 'pro')
+               {
+                       if ($action == 'account')
                        {
-                               $column = $this->type($action);
-                               
$phpgw->session->appsession('session_data',$column, $data);
+                               
$this->soprojects->delete_account_project_data($pa_id);
+                       }
+                       else
+                       {
+                               $this->soprojects->delete_project($pa_id, 
$subs);
                        }
                }

-               function read_sessiondata($action)
+               function change_owner($old, $new)
                {
-                       global $phpgw;
+                       $this->soprojects->change_owner($old, $new);
+               }

-                       $column = $this->type($action);
-                       $data = 
$phpgw->session->appsession('session_data',$column);
+               function get_mstones($project_id)
+               {
+                       $mstones = $this->soprojects->get_mstones($project_id);

-                       $this->start    = $data['start'];
-                       $this->query    = $data['query'];
-                       $this->filter   = $data['filter'];
-                       $this->order    = $data['order'];
-                       $this->sort             = $data['sort'];
-                       $this->cat_id   = $data['cat_id'];
+                       if(is_array($mstones))
+                       {
+                               foreach($mstones as $ms)
+                               {
+                                       $stones[] = array
+                                       (
+                                               'title'         => 
$GLOBALS['phpgw']->strip_html($ms['title']),
+                                               'edate'         => $ms['edate'],
+                                               's_id'          => $ms['s_id']
+                                       );
+                               }
+                               return $stones;
+                       }
+                       return False;
                }

-               function check_perms($has, $needed)
+               function get_single_mstone($s_id)
                {
-                       return (!!($has & $needed) == True);
+                       return $this->soprojects->get_single_mstone($s_id);
                }

-               function cached_accounts($account_id)
+               function check_mstone($values)
                {
-                       global $phpgw;
-
-                       $this->accounts = 
CreateObject('phpgwapi.accounts',$account_id);
-
-                       $this->accounts->read_repository();

-                       
$cached_data[$this->accounts->data['account_id']]['account_lid'] = 
$this->accounts->data['account_lid'];
-                       
$cached_data[$this->accounts->data['account_id']]['firstname']   = 
$this->accounts->data['firstname'];
-                       
$cached_data[$this->accounts->data['account_id']]['lastname']    = 
$this->accounts->data['lastname'];
-
-                       return $cached_data;
+                       if (strlen($values['title']) == 0)
+                       {
+                               $error[] = lang('please enter a title');
+                       }
+                       else 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_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');
+                                       }
+                               }
+                       }
+                       if(is_array($error))
+                       {
+                               return $error;
+                       }
                }

-               function check_prefs()
+               function save_mstone($values)
                {
-                       global $phpgw_info;
+                       if ($values['emonth'] || $values['eday'] || 
$values['eyear'])
+                       {
+                               $values['edate'] = 
mktime(12,0,0,$values['emonth'],$values['eday'],$values['eyear']);
+                       }
+                       $values['edate'] = intval($values['edate']);

-                       if (! 
isset($phpgw_info['user']['preferences']['common']['currency']))
+                       if (intval($values['s_id']) > 0)
                        {
-                               return True;
+                               $this->soprojects->edit_mstone($values);
                        }
                        else
                        {
-                               return False;
+                               $values['s_id'] = 
$this->soprojects->add_mstone($values);
                        }
-               }
-

-               function get_prefs()
-               {
-                       global $phpgw_info;
+                       $values['old_edate'] = intval($values['old_edate']);
+                       $async = CreateObject('phpgwapi.asyncservice');
+                       if($values['edate'] > 0 && $values['old_edate'] != 
$values['edate'])
+                       {
+                               $co = 
$this->soprojects->return_value('co',$values['project_id']);
+                               $event_extra = 
$this->soconfig->get_event_extra('milestone date due');
+                               $next = 
mktime(date('H',time()),date('i',time())+5,0,$values['emonth'],$values['eday']-$event_extra,$values['eyear']);

-                       if 
(isset($phpgw_info['user']['preferences']['common']['currency']))
+                               $edate = $this->format_date($values['edate']);
+                               $async->write(array('id' => 'ms-' . 
$values['s_id'] . '-project-' . $values['project_id'], 'next' => $next,'times' 
=> array('year' => date('Y',$next),
+                                                                       'month' 
=> date('m',$next),'day' => date('d',$next),'hour' => date('H',$next),'min' => 
date('i',$next))
+                                                                       
,'account_id' => $co,'method' => 'projects.boprojects.send_alarm',
+                                                                       'data' 
=> array('project_id' => $values['project_id'],'event_type' => 'milestone date 
due',
+                                                                       'edate' 
=> $edate['date_formatted'],'ms_title' => $values['title'])));
+                       }
+                       if($values['edate'] == 0)
                        {
-                               $currency = 
$phpgw_info['user']['preferences']['common']['currency'];
+                               $aid = 'ms-' . $values['s_id'] . '-project-' . 
$values['project_id'];
+                               $async->delete($aid);
                        }
-                       return $currency;
-               }
+                       unset($async);

+                       return $values['s_id'];
+               }

-               function read_customer_data($ab_id)
+               function delete_item($values)
                {
-                       $this->contacts = CreateObject('phpgwapi.contacts');
-
-                       $cols = array('n_given'=> 'n_given',
-                                               'n_family' => 'n_family',
-                                               'org_name' => 'org_name');
+                       switch($values['action'])
+                       {
+                               case 'emp_role':        
$this->soprojects->soconfig->delete_pa($values['action'],$values['id']); break;
+                               default:                        
$this->soprojects->delete_mstone($values['id']);
+                       }
+               }

-                       $customer = 
$this->contacts->read_single_entry($ab_id,$cols);
-                       return $customer;
+               function member($project_id = '')
+               {
+                       return $this->soprojects->member($project_id);
                }


-               function coordinator_list()
+// ------------ ALARM ----------------
+
+               function send_alarm($values)
                {
-                       global $phpgw;
+                       $event_type             = 
isset($values['event_type'])?$values['event_type']:'assignment to role';
+                       $project_name   = 
isset($values['project_name'])?$values['project_name']:$this->soprojects->return_value('pro',$values['project_id']);

-                       $employees = $phpgw->accounts->get_list('accounts');
-                       return $employees;
-               }
+                       switch($event_type)
+                       {
+                               case 'assignrolepro':
+                                       $values['event_type'] = 'assignment to 
project,assignment to role';
+                                       $emp_events     = 
$this->soprojects->read_employee_roles($values);
+                                       break;
+                               default:
+                                       $emp_events = 
$this->soprojects->read_employee_roles($values);
+                                       break;
+                       }

-               function isprojectadmin()
-               {
-                       global $phpgw, $phpgw_info;
+                       //echo 'BOPROJECTS->alarm EVENTS: ';
+                       //_debug_array($emp_events);

-                       $admin_groups = 
$phpgw->accounts->membership($phpgw_info['user']['account_id']);
-                       $admins = $this->soprojects->return_admins();
+                       $notify_hours   = 
$this->soprojects->check_alarm($values['project_id'],'hours');
+                       $notify_budget  = 
$this->soprojects->check_alarm($values['project_id'],'budget');

-                       for ($i=0;$i<count($admins);$i++)
+                       for($k=0;$k<count($emp_events);$k++)
                        {
-                               if ($admins[$i]['type']=='aa')
-                               {
-                                       if ($admins[$i]['account_id'] == 
$phpgw_info['user']['account_id'])
-                                       return True;
-                               }
-                               elseif ($admins[$i]['type']=='ag')
+                               
for($i=0;$i<count($emp_events[$k]['events']);$i++)
                                {
-                                       if (is_array($admin_groups))
+                                       $event          = 
$this->soprojects->id2item(array('action' => 'event','item_id' => 
$emp_events[$k]['events'][$i],'item' => 'event_name'));
+                                       $co                     = 
$this->soprojects->return_value('co',$values['project_id']);
+                                       $subject        = lang('project') .  ': 
' . $project_name . ': ' . lang($event) . ' ';
+
+                                       switch($event_type)
+                                       {
+                                               case 'project date due':
+                                               case 'milestone date due':
+                                               case 'budget limit':
+                                               case 'hours limit': $subject .= 
lang('has reached'); break;
+                                               case 'project dependencies': 
$subject .=  ', ' . ($values['is_previous']?lang('end date has 
changed'):lang('previous projects end date has changed')); break;
+                                       }
+
+                                       switch($event)
                                        {
-                                               for 
($j=0;$j<count($admin_groups);$j++)
+                                               case 'changes of project data':
+                                                       $send_alarm = True;
+                                                       $msg = $subject;
+                                                       break;
+                                               case 'assignment to role':
+                                                       $send_alarm = True;
+                                                       if($co == 
$emp_events[$k]['account_id'])
+                                                       {
+                                                               $role_name = 
lang('coordinator');
+                                                       }
+                                                       else
+                                                       {
+                                                               $role_name = 
$this->soprojects->id2item(array('action' => 'role','item_id' => 
$emp_events[$k]['role_id'],'item' => 'role_name'));
+                                                       }
+                                                       $msg = lang($event) . 
': ' . $role_name;
+                                                       break;
+                                               case 'project dependencies':
+                                                       $send_alarm = True;
+                                                       $changedate = 
$this->siteconfig['dateprevious'] == 'yes'?True:False;
+                                                       
if($values['is_previous'])
+                                                       {
+                                                               $edate = 
$this->format_date($values['edate']);
+                                                               $oedate = 
$this->format_date($values['old_edate']);
+                                                               $msg = 
lang('previous project') . ': ' . $project_name . "\n"
+                                                                       . 
lang('old end date') . ': ' . $oedate['date_formatted'] . "\n"
+                                                                       . 
lang('new end date') . ': ' . $edate['date_formatted'] . "\n\n"
+                                                                       . 
lang('projects, which are assigned as sequencing') . ':' . "\n"
+                                                                       . 
($changedate?lang('changed start date and end date of projects bellow'):'') . 
"\n\n";
+
+                                                               
if(is_array($values['following']))
+                                                               {
+                                                                       
foreach($values['following'] as $fol)
+                                                                       {
+                                                                               
$sdate  = $this->format_date($fol['sdate']);
+                                                                               
$nsdate = ($changedate?$this->format_date($fol['nsdate']):'');
+                                                                               
$edate  = $this->format_date($fol['edate']);
+                                                                               
$nedate = ($changedate?$this->format_date($fol['nedate']):'');
+                                                                               
$msg .= $fol['title'] . ' [' . $fol['number'] . '] ' . "\n"
+                                                                               
        . ($changedate?lang('old start date'):lang('start date')) . ': ' . 
$sdate['date_formatted'] . ' '
+                                                                               
        . ($changedate?lang('new start date') . ': ' . 
$nsdate['date_formatted']:'') . "\n"
+                                                                               
        . ($changedate?lang('old end date'):lang('end date')) . ': ' . 
$edate['date_formatted'] . ' '
+                                                                               
        . ($changedate?lang('new end date') . ': ' . 
$nedate['date_formatted']:'') . "\n";
+
+                                                                               
if(is_array($fol['mstones']))
+                                                                               
{
+                                                                               
        foreach($fol['mstones'] as $stone)
+                                                                               
        {
+                                                                               
                $sedate = $this->format_date($stone['edate']);
+                                                                               
                $snedate        = 
($changedate?$this->format_date($stone['snedate']):'');
+                                                                               
                $msg .= lang('milestone') . ' ' . $stone['title'] . "\n"
+                                                                               
                                . ($changedate?lang('old end date'):lang('end 
date')) . ': ' . $sedate['date_formatted'] . ' '
+                                                                               
                                . ($changedate?lang('new end date') . ': ' . 
$snedate['date_formatted']:'') . "\n";
+                                                                               
        }
+                                                                               
}
+                                                                               
$msg .= "\n";
+                                                                       }
+                                                               }
+                                                       }
+                                                       else
+                                                       {
+                                                               $previous_edate 
= $this->format_date($values['previous_edate']);
+                                                               
$previous_oedate = $this->format_date($values['previous_old_edate']);
+
+                                                               $sdate  = 
$this->format_date($values['sdate']);
+                                                               $nsdate = 
($changedate?$this->format_date($values['nsdate']):'');
+                                                               $edate  = 
$this->format_date($values['edate']);
+                                                               $nedate = 
($changedate?$this->format_date($values['nedate']):'');
+
+                                                               $msg = 
lang('previous project') . ': ' . $values['previous_name'] . "\n"
+                                                                               
. lang('old end date') . ': ' . $previous_oedate['date_formatted'] . "\n"
+                                                                               
. lang('new end date') . ': ' . $previous_edate['date_formatted'] . "\n\n"
+
+                                                                               
. lang('sequencing project') . ': ' . $project_name . "\n"
+                                                                               
. ($changedate?lang('changed start date and end date'):'') . "\n"
+                                                                               
. ($changedate?lang('old start date'):lang('start date')) . ': ' . 
$sdate['date_formatted'] . ' '
+                                                                               
. ($changedate?lang('new start date') . ': ' . $nsdate['date_formatted']:'') . 
"\n"
+                                                                               
. ($changedate?lang('old end date'):lang('end date')) . ': ' . 
$edate['date_formatted'] . ' '
+                                                                               
. ($changedate?lang('new end date') . ': ' . $nedate['date_formatted']:'') . 
"\n";
+
+                                                               
if(is_array($values['mstones']))
+                                                               {
+                                                                       
foreach($values['mstones'] as $stone)
+                                                                       {
+                                                                               
$sedate = $this->format_date($stone['edate']);
+                                                                               
$snedate        = ($changedate?$this->format_date($stone['snedate']):'');
+                                                                               
$msg .= lang('milestone') . ' ' . $stone['title'] . "\n"
+                                                                               
                . ($changedate?lang('old end date'):lang('end date')) . ': ' . 
$sedate['date_formatted'] . ' '
+                                                                               
                . ($changedate?lang('new end date') . ': ' . 
$snedate['date_formatted']:'') . "\n";
+                                                                       }
+                                                               }
+                                                       }
+                                                       break;
+                                               case 'hours limit':
+                                                       $send_alarm = 
$notify_hours?True:False;
+                                                       $msg = lang($event) . 
': ' . $values['ptime'] . "\n"
+                                                                       . 
lang('hours used total') . ': ' . $values['uhours_jobs_all'];
+                                                       break;
+                                               case 'budget limit':
+                                                       $send_alarm = 
$notify_budget?True:False;
+                                                       $msg = lang($event) . 
': ' . $values['budget'] . "\n"
+                                                                       . 
lang('budget used total') . ': ' . 
$GLOBALS['phpgw_info']['user']['preferences']['common']['currency']
+                                                                       . ' ' . 
$values['u_budget_jobs'];
+                                                       break;
+                                               case 'assignment to project':
+                                                       $send_alarm = True;
+                                                       $msg = lang($event) . 
': ' . $project_name;
+                                                       break;
+                                               case 'project date due':
+                                                       $send_alarm = 
$event_type=='project date due'?True:False;
+                                                       $msg = lang($event) . 
': ' . $values['edate'];
+                                                       break;
+                                               case 'milestone date due':
+                                                       $send_alarm = 
$event_type=='milestone date due'?True:False;
+                                                       $msg = lang($event) . 
': ' . $values['edate'] . "\n";
+                                                       $msg .= 
lang('milestone') . ': ' . $values['ms_title'] . "\n";
+                                                       $msg .= lang('project') 
. ':' . $values['project_name'];
+                                                       break;
+                                       }
+
+                                       //create the url for automatic login
+                                       $link_data = array
+                                       (
+                                               'phpgw_forward'         => 
'/index.php',
+                                               'phpgw_menuaction'      => 
'projects.uiprojects.view_project',
+                                               'phpgw_project_id'      => 
$values['project_id'],
+                                               'phpgw_action'          => 
$values['action']
+                                       );
+
+                                       $param_list = '';
+                                       $is_first_param = true;
+
+                                       foreach($link_data as $param_name => 
$param_val)
+                                       {
+                                               $param_val = 
urlencode($param_val);
+
+                                               $param_list .= 
($is_first_param?'?':'&') . $param_name . '=' . $param_val;
+                                               $is_first_param = false;
+                                       }
+
+                                       $msg .= "\n\n" . 'http://' . 
$_SERVER['SERVER_NAME'] . $GLOBALS['phpgw_info']['server']['webserver_url'] . 
'/login.php' . $param_list;
+                                       //$msg .= "\n\n" . 
$GLOBALS['phpgw']->link('/index.php',$link_data);
+
+                                       if($send_alarm)
+                                       {
+                                               $prefs_co = 
CreateObject('phpgwapi.preferences',$co);
+                                               $prefs_co->read_repository();
+                                               $sender = 
$prefs_co->email_address($co);
+                                               unset($prefs_co);
+
+                                               $prefs = 
CreateObject('phpgwapi.preferences',$emp_events[$k]['account_id']);
+                                               $prefs->read_repository();
+
+                                               $msgtype = '"projects";';
+
+                                               
if(!is_object($GLOBALS['phpgw']->send))
                                                {
-                                                       if 
($admin_groups[$j]['account_id'] == $admins[$i]['account_id'])
-                                                       return True;
+                                                       $GLOBALS['phpgw']->send 
= CreateObject('phpgwapi.send');
+                                               }
+
+                                               
print_debug('UserID',$emp['account_id']);
+
+                                               $to = 
$prefs->email_address($emp_events[$k]['account_id']);
+
+                                               /*if (empty($to) || $to[0] == 
'@' || $to[0] == '$')     // we have no valid email-address
+                                               {
+                                                       //echo 
"<p>boprojects::send_update: Empty email adress for user 
'".$emp_events[$k]['emp_name']."' ==> ignored !!!</p>\n";
+                                                       continue;
+                                               }*/
+                                               //echo 'Email being sent to ' . 
$to;
+
+                                               $subject = 
$GLOBALS['phpgw']->send->encode_subject($subject);
+
+                                               $returncode = 
$GLOBALS['phpgw']->send->msg('email',$to,$subject,$msg,''/*$msgtype*/,'','','',$sender);
+                                               //echo "<p>send(to='$to', 
sender='$sender'<br>subject='$subject') 
returncode=$returncode<br>".nl2br($body)."</p>\n";
+
+                                               if (!$returncode)       // not 
nice, but better than failing silently
+                                               {
+                                                       echo 
'<p><b>boprojects::send_alarm</b>: '.lang("Failed sending message to '%1' #%2 
subject='%3', sender='%4' 
!!!",$to,$emp['account_id'],htmlspecialchars($subject), $sender)."<br>\n";
+                                                       echo 
'<i>'.$GLOBALS['phpgw']->send->err['desc']."</i><br>\n";
+                                                       echo lang('This is 
mostly caused by a not or wrongly configured SMTP server. Notify your 
administrator.')."</p>\n";
+                                                       echo '<p>'.lang('Click 
%1here%2 to return to projects.','<a 
href="'.$GLOBALS['phpgw']->link('/projects/').'">','</a>')."</p>\n";
                                                }
+                                               unset($prefs);
                                        }
                                }
-                               else
-                               {
-                                       return False;
-                               }
                        }
+                       return $returncode;
                }

-               function list_projects($start, $limit, $query, $filter, $sort, 
$order, $status, $cat_id, $type, $pro_parent)
+               function activities_list($project_id, $billable)
                {
-                       $pro_list = $this->soprojects->read_projects($start, 
$limit, $query, $filter, $sort, $order, $status, $cat_id, $type, $pro_parent);
-                       $this->total_records = $this->soprojects->total_records;
-                       return $pro_list;
+                       $activities_list = 
$this->soprojects->soconfig->activities_list($project_id, $billable);
+                       return $activities_list;
+               }
+
+               function select_activities_list($project_id, $billable)
+               {
+                       $activities_list = 
$this->soprojects->soconfig->select_activities_list($project_id, $billable);
+                       return $activities_list;
+               }
+
+               function select_pro_activities($project_id, $pro_parent, 
$billable)
+               {
+                       $activities_list = 
$this->soprojects->soconfig->select_pro_activities($project_id, $pro_parent, 
$billable);
+                       return $activities_list;
                }

-               function read_single_project($project_id)
+               function select_hours_activities($project_id, $act)
                {
-                       $single_pro = 
$this->soprojects->read_single_project($project_id);
-                       return $single_pro;
+                       $activities_list = 
$this->soprojects->soconfig->select_hours_activities($project_id, $act);
+                       return $activities_list;
                }

-               function read_single_activity($activity_id)
+               function isprojectadmin($action = 'pad')
                {
-                       $single_act = 
$this->soprojects->read_single_activity($activity_id);
-                       return $single_act;
+                       return 
$this->soprojects->soconfig->isprojectadmin($action);
                }

-               function exists($action, $check, $num, $pa_id)
+               function read_prefs($default = True)
                {
-                       $exists = $this->soprojects->exists($action, $check , 
$num, $pa_id);
-                       if ($exists)
+                       //$GLOBALS['phpgw']->preferences->read_repository();
+
+                       $prefs = array();
+                       if 
(isset($GLOBALS['phpgw_info']['user']['preferences']['projects']['columns']))
                        {
-                               return True;
+                               $cols = 
$GLOBALS['phpgw_info']['user']['preferences']['projects']['columns'];
+                               $prefs['columns'] = explode(',',$cols);
                        }
-                       else
+                       else if($default)
                        {
-                               return False;
+                               $prefs['columns'] = 
array('priority','number','customerout','coordinatorout','edateout');
                        }
-               }
+                       $prefs['currency'] = 
$GLOBALS['phpgw_info']['user']['preferences']['common']['currency'];
+                       $prefs['mainscreen_showevents'] = 
$GLOBALS['phpgw_info']['user']['preferences']['projects']['mainscreen_showevents'];

-               function list_activities($start, $limit, $query, $sort, $order, 
$cat_id)
-               {
-                       $act_list = $this->soprojects->read_activities($start, 
$limit, $query, $sort, $order, $cat_id);
-                       $this->total_records = $this->soprojects->total_records;
-                       return $act_list;
+                       return $prefs;
                }

-               function select_activities_list($project_id, $billable)
+               function check_prefs()
                {
-                       $activities_list = 
$this->soprojects->select_activities_list($project_id, $billable);
-                       return $activities_list;
+                       $prefs = $this->read_prefs(False);
+
+                       if (! isset($prefs['currency']))
+                       {
+                               $error[] = lang('please specify the currency in 
the global preferences section');
+                       }
+
+                       if(! isset($prefs['columns']))
+                       {
+                               $error[] = lang('please choose the columns to 
list in the projects preferences section');
+                       }
+
+                       $config = $this->soprojects->get_site_config(False);
+
+                       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');
+                       }
+                       return $error;
                }

-               function select_pro_activities($project_id, $billable)
+               function get_prefs()
                {
-                       $activities_list = 
$this->soprojects->select_pro_activities($project_id, $billable);
-                       return $activities_list;
+                       return $this->read_prefs();
                }

-               function check_values($action, $values, $book_activities, 
$bill_activities)
+               function get_employee_roles($data)
                {
-                       global $phpgw;
+                       $formatted = 
isset($data['formatted'])?$data['formatted']:False;

-                       if (strlen($values['descr']) >= 8000)
-                       {
-                               $error[] = lang('Description can not exceed 
8000 characters in length !');
-                       }
+                       $emp_roles = 
$this->soprojects->read_employee_roles($data);

-                       if (strlen($values['title']) >= 255)
-                       {
-                               $error[] = lang('Title can not exceed 255 
characters in length !');
-                       }
+                       //_debug_array($emp_roles);

-                       if (! $values['choose'])
+                       if(is_array($emp_roles))
                        {
-                               if (! $values['number'])
-                               {
-                                       $error[] = lang('Please enter an ID !');
-                               }
-                               else
+                               foreach($emp_roles as $emp)
                                {
-                                       $exists = $this->exists($action, 
'number', $values['number'], $values['project_id']);
-
-                                       if ($exists)
+                                       if (is_array($emp['events']) && 
$formatted)
                                        {
-                                               $error[] = lang('That ID has 
been used already !');
+                                               $eformatted = '';
+                                               $eformatted = '<table 
width="100%" border="0" cellpadding="0" cellspacing="0">' . "\n";
+                                               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 .= '</table>';
                                        }

-                                       if (strlen($values['number']) > 19)
-                                       {
-                                               $error[] = lang('ID can not 
exceed 19 characters in length !');
-                                       }
+                                       $user[] = array
+                                       (
+                                               'r_id'                  => 
$emp['r_id'],
+                                               'account_id'    => 
$emp['account_id'],
+                                               'emp_name'              => 
$GLOBALS['phpgw']->common->grab_owner_name($emp['account_id']),
+                                               'role_id'               => 
$emp['role_id'],
+                                               'role_name'             => 
$GLOBALS['phpgw']->strip_html($this->soprojects->id2item(array('item_id' => 
$emp['role_id'],'item' => 'role_name','action' => 'role'))),
+                                               'events'                => 
$formatted?$eformatted:$emp['events']
+                                       );
                                }
+                               return $user;
                        }
+                       return False;
+               }

-                       if ($action == 'mains')
+               function save_employee_role($values)
+               {
+                       $old_roles = 
$this->soprojects->read_employee_roles(array('project_id' => 
$values['project_id'],'account_id' => $values['account_id']));
+
+                       if(is_array($old_roles))
                        {
-                               if ((! $book_activities) && (! 
$bill_activities))
-                               {
-                                       $error[] = lang('Please choose 
activities for that project first !');
-                               }
+                               list($old_roles) = $old_roles;
+                               $values['r_id'] = $old_roles['r_id'];
                        }

-                       if ($values['smonth'] || $values['sday'] || 
$values['syear'])
+                       
$this->soprojects->save_employee_role($values,(is_array($old_roles)?True:False));
+
+                       if(is_array($old_roles['events']) && 
is_array($values['events']))
                        {
-                               if (! 
checkdate($values['smonth'],$values['sday'],$values['syear']))
+                               $event_role_id = 
$this->soprojects->item2id(array('item' => 'assignment to role'));
+                               $values['role_id'] = intval($values['role_id']);
+
+                               
if(!in_array($event_role_id,$old_roles['events']) && 
in_array($event_role_id,$values['events']) && $values['role_id'] > 0)
                                {
-                                       $error[] = lang('You have entered an 
starting invalid date');
+                                       $send_role = True;
+                               }
+                               if(in_array($event_role_id,$values['events']) 
&& intval($old_roles['role_id']) != $values['role_id'] && $values['role_id'] > 
0)
+                               {
+                                       $send_role = True;
                                }
-                       }

-                       if ($values['emonth'] || $values['eday'] || 
$values['eyear'])
-                       {
-                               if (! 
checkdate($values['emonth'],$values['eday'],$values['eyear']))
+                               if($send_role)
                                {
-                                       $error[] = lang('You have entered an 
ending invalid date');
+                                       $values['event_type'] = 'assignment to 
role';
+                                       $this->send_alarm($values);
                                }
-                       }

-/*                     if ($values['edate'] < $values['sdate'] && 
$values['edate'] && $values['sdate'])
-                       {
-                               $error[] = lang('Ending date can not be before 
start date');
-                       } */
+                               $event_assignpro_id = 
$this->soprojects->item2id(array('item' => 'assignment to project'));

-                       if (is_array($error))
+                               
if(!in_array($event_assignpro_id,$old_roles['events']) && 
in_array($event_assignpro_id,$values['events']))
+                               {
+                                       $values['event_type'] = 'assignment to 
project';
+                                       $this->send_alarm($values);
+                               }
+                       }
+
+                       if(!is_array($old_roles['events']) && 
is_array($values['events']))
                        {
-                               return $error;
+                               $values['event_type'] = 'assignrolepro';
+                               $this->send_alarm($values);
                        }
                }

-               function check_pa_values($values)
+               function list_roles()
                {
-                       global $phpgw;
+                       $roles = 
$this->soprojects->soconfig->list_roles(array('start' => $this->start,'sort' => 
$this->sort,'order' => $this->order,
+                                                                               
                                'query' => $this->query,'limit' => 
$this->limit));
+                       $this->total_records = 
$this->soprojects->soconfig->total_records;

-                       if (strlen($values['descr']) >= 255)
+                       if(is_array($roles))
                        {
-                               $error[] = lang('Description can not exceed 255 
characters in length !');
+                               foreach($roles as $role)
+                               {
+                                       $emp_roles[] = array
+                                       (
+                                               'role_id'       => 
$role['role_id'],
+                                               'role_name'     => 
$GLOBALS['phpgw']->strip_html($role['role_name'])
+                                       );
+                               }
+                               return $emp_roles;
                        }
+                       return False;
+               }
+
+               function get_granted_roles($project_id)
+               {
+                       $emps = $this->selected_employees($project_id);
+                       $roles  = $this->get_employee_roles($project_id);

-                       if (! $values['choose'])
+                       if(is_array($emps))
                        {
-                               if (! $values['number'])
-                               {
-                                       $error[] = lang('Please enter an ID !');
-                               }
-                               else
+                               foreach($emps as $emp)
                                {
-                                       $exists = $this->exists('act', 
'number', $values['number'], $values['activity_id']);
-
-                                       if ($exists)
+                                       $assigned_role = '';
+                                       for($i=0;$i<count($roles);$i++)
                                        {
-                                               $error[] = lang('That ID has 
been used already !');
+                                               if($roles[$i]['account_id'] == 
$emp['account_id'])
+                                               {
+                                                       $assigned_role = 
$roles[$i]['role_name'];
+                                               }
                                        }

-                                       if (strlen($values['number']) >= 20)
-                                       {
-                                               $error[] = lang('ID can not 
exceed 19 characters in length !');
-                                       }
+                                       $assigned[] = array
+                                       (
+                                               'emp_name'      => 
$GLOBALS['phpgw']->common->display_fullname($emp['account_lid'],$emp['account_firstname'],$emp['account_lastname']),
+                                               'role_name'     => 
$assigned_role
+                                       );
                                }
+                               return $assigned;
                        }
+                       return False;
+               }

-                       if ((! $values['billperae']) || ($values['billperae'] 
== 0))
-                       {
-                               $error[] = lang('Please enter the bill per 
workunit !');
-                       }
-
-                       if ((! $values['minperae']) || ($values['minperae'] == 
0))
-                       {
-                               $error[] = lang('Please enter the minutes per 
workunit !');
-                       }
+               function list_events($type = '')
+               {
+                       return $this->soprojects->soconfig->list_events($type);
+               }

-                       if (is_array($error))
-                       {
-                               return $error;
-                       }
+               function list_surcharges($charge_id = 0)
+               {
+                       return 
$this->soprojects->soconfig->list_surcharges($charge_id);
                }

-               function save_project($action, $values, $book_activities, 
$bill_activities)
+               function get_event_extra($type = '')
                {
-                       global $phpgw;
+                       return $this->soprojects->get_event_extra($type);
+               }

-                       if ($values['choose'])
-                       {
-                               if ($action == 'mains')
-                               {
-                                       $values['number'] = 
$this->soprojects->create_projectid();
-                               }
-                               else
-                               {
-                                       $values['number'] = 
$this->soprojects->create_jobid($values['parent']);
-                               }
-                       }
+               function action_format($selected = 0,$action = 'role',$type = 
'')
+               {
+                       $this->limit = False;

-                       if ($values['access'])
+                       switch($action)
                        {
-                               $values['access'] = 'private';
-                       }
-                       else
-                       {
-                               $values['access'] = 'public';
+                               case 'event':   $list = 
$this->list_events($type); break;
+                               case 'charge':  $list = 
$this->list_surcharges(); break;
+                               default:                $list = 
$this->list_roles(); break;
                        }

-                       if ($values['smonth'] || $values['sday'] || 
$values['syear'])
+                       if(!is_array($selected))
                        {
-                               $values['sdate'] = 
mktime(0,0,0,$values['smonth'], $values['sday'], $values['syear']);
+                               $selected = explode(',',$selected);
                        }

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

-                       if ($values['emonth'] || $values['eday'] || 
$values['eyear'])
-                       {
-                               $values['edate'] = 
mktime(0,0,0,$values['emonth'],$values['eday'],$values['eyear']);
-                       }
+                       $id             = $action . '_id';
+                       $name   = $action . '_name';

-                       if ($values['project_id'])
+                       if(is_array($list))
                        {
-                               if ($values['project_id'] != 0)
+                               foreach($list as $li)
                                {
-                                       
$this->soprojects->edit_project($action, $values, $book_activities, 
$bill_activities);
+                                       $list_list .= '<option value="' . 
$li[$id] . '"';
+                                       if(in_array($li[$id],$selected))
+                                       {
+                                               $list_list .= ' selected';
+                                       }
+                                       $list_list .= '>' . 
($action=='event'?lang($li[$name]):$li[$name]) . '</option>' . "\n";
                                }
+                               return $list_list;
                        }
-                       else
-                       {
-                               $this->soprojects->add_project($action, 
$values, $book_activities, $bill_activities);
-                       }
+                       return False;
                }

-               function save_activity($values)
+               function get_folder_content()
                {
-                       global $phpgw;
-
-                       if ($values['choose'])
-                       {
-                               $values['number'] = 
$this->soprojects->create_activityid();
-                       }
+                       $projects = $this->list_projects(array('limit' => 
False,'action' => 'all','no_formatted_level' => True));

-                       if ($values['activity_id'])
+                       if(is_array($projects))
                        {
-                               if ($values['activity_id'] != 0)
+                               foreach($projects as $pro)
                                {
-                                       
$this->soprojects->edit_activity($values);
+                                       $return[$pro['project_id']] = array
+                                       (
+                                               'text'          => 
$pro['title'],
+                                               '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']),
+                                               'target'    => '_parent'
+                                       );
                                }
                        }
-                       else
-                       {
-                               $this->soprojects->add_activity($values);
-                       }
-               }
-
-               function select_project_list($type, $project_id)
-               {
-                       $list = 
$this->soprojects->select_project_list($type,$project_id);
-                       return $list;
-               }
-
-               function delete_pa($action, $pa_id, $subs)
-               {
-                       $this->soprojects->delete_pa($action, $pa_id, $subs);
+                       return array('content' => $return);
                }
        }
 ?>

====================================================
Index: projects/inc/class.uiprojecthours.inc.php
diff -u projects/inc/class.uiprojecthours.inc.php:1.81 
projects/inc/class.uiprojecthours.inc.php:1.81.2.1
--- projects/inc/class.uiprojecthours.inc.php:1.81      Wed Aug 11 15:05:13 2004
+++ projects/inc/class.uiprojecthours.inc.php   Tue May 17 13:23:58 2005
@@ -53,7 +53,7 @@
                        $this->bohours                                  = 
CreateObject('projects.boprojecthours');
                        $this->boprojects                               = 
$this->bohours->boprojects;
                        $this->nextmatchs                               = 
CreateObject('phpgwapi.nextmatchs');
-                       //$this->sbox                                           
= CreateObject('phpgwapi.sbox');
+                       $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;






reply via email to

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