[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpgroupware-cvs] hr/inc class.hr_acl_so.inc.php, 1.1 class.hr_acl_bo.i
From: |
skwashd |
Subject: |
[Phpgroupware-cvs] hr/inc class.hr_acl_so.inc.php, 1.1 class.hr_acl_bo.inc.php, 1.1 class.hr_acl_ui.inc.php, 1.1 class.hr_bo.inc.php, 1.1 class.hr_ui.inc.php, 1.1 class.hr_so.inc.php, 1.1 hook_admin.inc.php, 1.1 |
Date: |
Tue, 15 Nov 2005 15:09:00 +0100 |
Update of hr/inc
Added Files:
Branch: MAIN
class.hr_acl_so.inc.php
class.hr_acl_bo.inc.php
class.hr_acl_ui.inc.php
class.hr_bo.inc.php
class.hr_ui.inc.php
class.hr_so.inc.php
hook_admin.inc.php
Log Message:
new version of hr - now it is actually useful
====================================================
Index: class.hr_acl_so.inc.php
<?php
/**************************************************************************\
* phpGroupWare - HR
*
* http://www.phpgroupware.org
*
* Written by Dave Hall skwashd at phpgroupware org
*
* Portions Copyright (c) 2005 Free Software Foundation, Inc
*
* --------------------------------------------
*
* Parts taken from news_admin ACL - written by Michael Totshnig
*
* --------------------------------------------
*
* This program is free software; you can redistribute it and/or modify
it *
* under the terms of the GNU General Public License as published by
the *
* Free Software Foundation; either version 2 of the License, or (at
your *
* option) any later version.
*
\**************************************************************************/
/* $Id: class.hr_acl_so.inc.php,v 1.1 2005/11/15 14:09:42 skwashd Exp $
*/
class hr_acl_so
{
var $db;
function hr_acl_so()
{
$this->db =& $GLOBALS['phpgw']->db;
}
function get_permissions($user, $inc_groups)
{
$groups =
$GLOBALS['phpgw']->acl->get_location_list_for_id('phpgw_group', 1, $user);
$result = array();
$sql = 'SELECT acl_location, acl_rights FROM phpgw_acl
';
$sql .= "WHERE acl_appname = 'hr' ";
if($inc_groups)
{
$sql .= 'AND acl_account IN('. intval($user);
$sql .= (is_array($groups) ? ',' . implode(',',
$groups) : ''); //-1 is self
$sql .= ')';
}
else
{
$sql .= 'AND acl_account ='. intval($user);
}
$this->db->query($sql,__LINE__,__FILE__);
while ($this->db->next_record())
{
$result[$this->db->f('acl_location')] |=
$this->db->f('acl_rights');
}
return $result;
}
function get_rights($location)
{
$result = array();
$sql = "SELECT acl_account, acl_rights from phpgw_acl
WHERE acl_appname = 'hr' and acl_location = '" .
$this->db->db_addslashes($location) . "'";
$this->db->query($sql, __LINE__,__FILE__);
while ($this->db->next_record())
{
$result[$this->db->f('acl_account')] =
$this->db->f('acl_rights');
}
return $result;
}
function remove_location($location)
{
$sql = "DELETE FROM phpgw_acl where acl_appname='hr'
and acl_location='" . $this->db->db_addslashes($location) . "'";
$this->db->query($sql,__LINE__,__FILE__);
}
}
?>
====================================================
Index: class.hr_acl_bo.inc.php
<?php
/**************************************************************************\
* phpGroupWare - HR
*
* http://www.phpgroupware.org
*
* Written by Dave Hall skwashd at phpgroupware org
*
* Portions Copyright (c) 2005 Free Software Foundation, Inc
*
* --------------------------------------------
*
* Parts taken from news_admin ACL - written by Michael Totshnig
*
* --------------------------------------------
*
* This program is free software; you can redistribute it and/or modify
it *
* under the terms of the GNU General Public License as published by
the *
* Free Software Foundation; either version 2 of the License, or (at
your *
* option) any later version.
*
\**************************************************************************/
/* $Id: class.hr_acl_bo.inc.php,v 1.1 2005/11/15 14:09:42 skwashd Exp $
*/
class hr_acl_bo
{
var $acl;
var $start = 0;
var $query = '';
var $sort = '';
var $total = 0;
var $accounts;
var $cats = array();
var $debug;
var $use_session = False;
function hr_acl_bo($session=False)
{
$this->so = CreateObject('hr.hr_acl_so');
$this->accounts =
$GLOBALS['phpgw']->accounts->get_list();
$this->debug = False;
//all this is only needed when called from uiacl. not
from ui,
if($session)
{
$this->read_sessiondata();
$this->use_session = True;
foreach(array('start','query','sort','order')
as $var)
{
if (isset($_REQUEST[$var]))
{
$this->$var = $_REQUEST[$var];
}
}
$this->save_sessiondata();
}
$this->catbo = createobject('phpgwapi.categories');
$this->_set_cats();
$this->permissions = $this->get_permissions(True);
}
function save_sessiondata()
{
$data = array
(
'start' => $this->start,
'query' => $this->query,
'sort' => $this->sort,
'order' => $this->order,
'limit' => $this->limit,
);
if($this->debug) { echo '<br>Read:';
_debug_array($data); }
$GLOBALS['phpgw']->session->appsession('session_data','hr_acl',$data);
}
function read_sessiondata()
{
$data =
$GLOBALS['phpgw']->session->appsession('session_data','news_admin_acl');
if($this->debug) { echo '<br>Read:';
_debug_array($data); }
$this->start = $data['start'];
$this->query = $data['query'];
$this->sort = $data['sort'];
$this->order = $data['order'];
$this->limit = $data['limit'];
}
function get_rights($cat_id)
{
return $this->so->get_rights("C{$cat_id}");
}
function is_permitted($cat_id,$right)
{
return $this->permissions["C{$cat_id}"] & $right;
}
function is_readable($cat_id)
{
return $this->is_permitted($cat_id,PHPGW_ACL_READ);
}
function is_writeable($cat_id)
{
return $this->is_permitted($cat_id,PHPGW_ACL_ADD);
}
function set_rights($cat_id, $read, $write)
{
$readcat = $read ? $read : array();
$writecat = $write ? $write : array();
$this->so->remove_location('L' . $cat_id);
foreach($this->accounts as $ign => $account)
{
$account_id = $account['account_id'];
//write implies read
$rights = in_array($account_id, $writecat)
? (PHPGW_ACL_READ |
PHPGW_ACL_ADD)
:
(in_array($account_id,$readcat) ? PHPGW_ACL_READ : 0 );
if ($rights)
{
$GLOBALS['phpgw']->acl->add_repository('hr', "C{$cat_id}", $account_id, $rights
);
}
}
}
//access permissions for current user
function get_permissions($inc_groups = False)
{
return
$this->so->get_permissions($GLOBALS['phpgw_info']['user']['account_id'],
$inc_groups);
}
/**
* Set the list of cats
*
* @access private
*/
function _set_cats()
{
$cats[-1] = array
(
'id' => -1,
'owner' => -1,
'access' => 'public',
'app_name' => 'hr',
'main' => -1,
'level' => 0,
'parent' => 0,
'name' =>
lang('contact_information'),
'description' => lang('read
user\'s contact information')
);
$cats[-2] = array
(
'id' => -2,
'owner' => -1,
'access' => 'public',
'app_name' => 'hr',
'main' => -2,
'level' => 0,
'parent' => 0,
'name' =>
lang('photo'),
'description' =>
lang('user\'s image')
);
$cats += $this->catbo->return_array('all',
$this->start, True, $this->query, $this->sort, 'cat_name', True);
foreach ( $cats as $cat )
{
$this->cats[$cat['id']] = $cat;
$this->cats[$cat['id']]['rights'] =
$this->get_rights($cat['id']);
}
}
}
?>
====================================================
Index: class.hr_acl_ui.inc.php
<?php
/**************************************************************************\
* phpGroupWare - HR
*
* http://www.phpgroupware.org
*
* Written by Dave Hall skwashd at phpgroupware org
*
* Portions Copyright (c) 2005 Free Software Foundation, Inc
*
* --------------------------------------------
*
* Parts taken from news_admin ACL - written by Michael Totshnig
*
* --------------------------------------------
*
* This program is free software; you can redistribute it and/or modify
it *
* under the terms of the GNU General Public License as published by
the *
* Free Software Foundation; either version 2 of the License, or (at
your *
* option) any later version.
*
\**************************************************************************/
/* $Id: class.hr_acl_ui.inc.php,v 1.1 2005/11/15 14:09:42 skwashd Exp $
*/
class hr_acl_ui
{
var $start = 0;
var $query = '';
var $sort = '';
var $order = '';
var $bo;
var $accounts;
var $nextmatchs = '';
var $rights;
var $public_functions = array
(
'acllist' => True,
);
function hr_acl_ui()
{
$this->bo = createobject('hr.hr_acl_bo',True);
$this->accounts =
$GLOBALS['phpgw']->accounts->get_list();
$this->nextmatchs = createobject('phpgwapi.nextmatchs');
$this->start = $this->bo->start;
$this->query = $this->bo->query;
$this->order = $this->bo->order;
$this->sort = $this->bo->sort;
$this->cat_id = $this->bo->cat_id;
}
function acllist()
{
if (!$GLOBALS['phpgw']->acl->check('run',1,'admin'))
{
$this->deny();
}
if ( isset($_POST['close']) && $_POST['close'] )
{
$GLOBALS['phpgw']->redirect_link('/admin/index.php');
}
$GLOBALS['phpgw']->common->phpgw_header();
echo parse_navbar();
if ( isset($_POST['save']) && $_POST['save'] )
{
foreach($_POST['catids'] as $cat_id)
{
$this->bo->set_rights($cat_id,$_POST['inputread'][$cat_id],$_POST['inputwrite'][$cat_id]);
}
}
$GLOBALS['phpgw']->template->set_file('acl', 'acl.tpl');
$GLOBALS['phpgw']->template->set_block('acl','cat_list','Cblock');
$GLOBALS['phpgw']->template->set_var(array
(
'title' => lang('configure
access permissions - hr'),
'lang_close' => lang('close'),
'lang_implies' => lang('implies read
permission'),
'lang_read' => lang('read
permissions'),
'lang_save' => lang('save'),
'lang_search' => lang('search'),
'lang_write' => lang('write
permissions'),
));
$GLOBALS['phpgw']->template->set_var(array
(
'left' =>
$this->nextmatchs->left('/index.php',$this->start,$this->bo->catbo->total_records,'menuaction=hr.uihracl.acllist'),
'right' =>
$this->nextmatchs->right('/index.php',$this->start,$this->bo->catbo->total_records,'menuaction=hr.uihracl.acllist'),
'lang_showing' =>
$this->nextmatchs->show_hits($this->bo->catbo->total_records,$this->start),
'th_bg' =>
$GLOBALS['phpgw_info']['theme']['th_bg'],
'sort_cat' =>
$this->nextmatchs->show_sort_order($this->sort,'cat_name','cat_name','/index.php',lang('Category'),'&menuaction=hr.uihracl.acllist'
),
'query' => $this->query,
));
if ( is_array($this->bo->cats) &&
count($this->bo->cats) )
{
$i = 0;
foreach ( $this->bo->cats as $cat )
{
$this->rights =
$this->bo->get_rights($cat['id']);
$row_class = 'row_' . ( $i % 2 ? 'on' :
'off' );
$GLOBALS['phpgw']->template->set_var(array
(
'catid' =>
$cat['id'],
'catname' =>
$cat['name'],
'read' =>
$this->selectlist(PHPGW_ACL_READ),
'row_class' =>
$row_class,
'write' =>
$this->selectlist(PHPGW_ACL_ADD)
));
$GLOBALS['phpgw']->template->parse('Cblock','cat_list',True);
++$i;
}
}
$GLOBALS['phpgw']->template->pfp('out','acl',True);
}
function selectlist($right)
{
if ( is_array($this->bo->accounts) &&
count($this->bo->accounts) )
{
foreach ( $this->bo->accounts as $account )
{
$selectlist .= '<option value="' .
$account['account_id'] . '"';
if($this->rights[$account['account_id']] & $right)
{
$selectlist .= '
selected="selected"';
}
$selectlist .= '>' .
$account['account_firstname'] . ' ' . $account['account_lastname']
. ' [ ' . $account['account_lid'] . ' ]' . '</option>' . "\n";
}
}
return $selectlist;
}
function deny()
{
echo '<p class="msg">><strong>'.lang('Access not
permitted').'</strong></p>';
$GLOBALS['phpgw']->common->phpgw_exit(True);
}
}
?>
====================================================
Index: class.hr_bo.inc.php
<?php
/**************************************************************************\
* phpGroupWare - Human Resources
*
* Written by Dave Hall skwashd phpgroupware org
*
* Copyright 2005 Free Software Foundation, Inc
*
* http://www.phpgroupware.org
*
* --------------------------------------------
*
* This program is free software; you can redistribute it and/or modify
it *
* under the terms of the GNU General Public License as published by
the *
* Free Software Foundation; either version 2 of the License, or (at
your *
* option) any later version.
*
\**************************************************************************/
/* $Id: class.hr_bo.inc.php,v 1.1 2005/11/15 14:09:42 skwashd Exp $ */
class hr_bo
{
/**
* @var object $so hr storage object
*/
var $so;
function hr_bo()
{
$this->so = createObject('hr.hr_so');
}
/**
* Add an entry
*
* @param int $user_id the user to add the entry to
* @param int $cat the category the record belongs to
* @param string $content the content for the record
*/
function add_entry($user_id, $cat, $content)
{
return $this->so->add_entry($user_id, $cat, $content);
}
/**
* Can a user edit an entry?
*
* @param int $user_id user account id
* @returns bool does the user have the rights?
*/
function can_edit()
{
$acls = createObject('hr.hr_acl_bo');
$rights = $acls->permissions;
if ( is_array($rights) && count($rights) )
{
foreach ( $rights as $cat => $right )
{
if ( $right & PHPGW_ACL_ADD )
{
return true;
}
}
}
return false;
}
/**
* Get a list of categories avaulable to the user permissions
*/
function get_cats()
{
$acls = createObject('hr.hr_acl_bo');
return $acls->cats;
}
/**
* Get group listing
*
* @param int $group_id id of account
* @returns array account and contact information
*/
function get_group($group_id)
{
return $this->so->get_group($group_id);
}
/**
* Get a list of groups
*
* @param string $filter to filter group names by
* @returns array list of groups
*/
function get_groups($filter = '' )
{
return $this->so->get_groups($filter);
}
/**
* Get all records for a user
*
* @param int $user_id user id
* @param int $mode access type required
* @returns array records for user id => info
*/
function get_records($user_id, $mode = PHPGW_ACL_READ)
{
$cats = array();
$cats[] = 0;
$acls = createObject('hr.hr_acl_bo');
$rights = $acls->permissions;
if ( is_array($rights) && count($rights) )
{
foreach ( $rights as $cat => $right )
{
if ( $right | $mode )
{
if ( $cat == 'run' || ($mode ==
PHPGW_ACL_ADD && $cat < 0) )
{
continue;
}
$cats[] = substr($cat, 1);
}
}
}
return $this->so->get_records($user_id, $cats);
}
/**
* Get user listing
*
* @param int $acct_id id of account
* @returns array account and contact information
*/
function get_user($user_id)
{
$cats = array();
$cats[0] = 0;
$full_cats = $this->get_cats();
if ( is_array($full_cats) && count($full_cats) )
{
foreach ( $full_cats as $cat_id => $crap )
{
$cats[$cat_id] = $cat_id;
}
}
unset($full_cats);
return $this->so->get_user($user_id, $cats);
}
/**
* Get a list of users
*
* @param string $filter to filter account names by
* @returns array list of accounts
*/
function get_users($filter = '' )
{
return $this->so->get_users($filter);
}
/**
* Update an entry
*
* @param int $user_id the user to update the entry for
* @param int $cat the category the record belongs to
* @param string $content the content for the record
*/
function update_entry($user_id, $cat, $content)
{
return $this->so->update_entry($user_id, $cat,
$content);
}
}
?>
====================================================
Index: class.hr_ui.inc.php
<?php
/**************************************************************************\
* phpGroupWare - Human Resources
*
* Written by Dave Hall skwashd phpgroupware org
*
* Copyright 2005 Free Software Foundation, Inc
*
* Development Sponsored by JimsBookkeeping.com.au
*
* http://www.phpgroupware.org
*
* --------------------------------------------
*
* This program is free software; you can redistribute it and/or modify
it *
* under the terms of the GNU General Public License as published by
the *
* Free Software Foundation; either version 2 of the License, or (at
your *
* option) any later version.
*
\**************************************************************************/
/* $Id: class.hr_ui.inc.php,v 1.1 2005/11/15 14:09:42 skwashd Exp $ */
class hr_ui
{
/**
* @var object $bo hr logic object
*/
var $bo;
/**
* @var array $public_functions the methods of the class that
can be called publicly
*/
var $public_functions = array
(
'edit_user' => True,
'index' => True,
'view' => True
);
/**
* @var object $t reference to phpgw global template object
*/
var $t;
function hr_ui()
{
if ( !isset($GLOBALS['phpgw_info']['flags']['css']) )
{
$GLOBALS['phpgw_info']['flags']['css'] = '';
}
$GLOBALS['phpgw_info']['flags']['css'] .= "@import
url('{$GLOBALS['phpgw_info']['server']['webserver_url']}/hr/css/base.css');\n";
if (
!isset($GLOBALS['phpgw_info']['flags']['java_script']) )
{
$GLOBALS['phpgw_info']['flags']['java_script']
= '';
}
if ( !isset($GLOBALS['phpgw']->js) ||
!is_object($GLOBALS['phpgw']->js) )
{
$GLOBALS['phpgw']->js =&
createObject('phpgwapi.javascript');
}
$GLOBALS['phpgw']->js->validate_file('tabs', 'tabs',
'communik8r');
$this->_set_tabs_js();
$this->bo = createObject('hr.hr_bo');
$this->t =& $GLOBALS['phpgw']->template;
}
/**
* Edit the information about the user
*/
function edit_user()
{
if ( !isset($_REQUEST['user_id']) ||
!is_numeric($_REQUEST['user_id']) || !$this->bo->can_edit() )
{
die('invalid request');
$GLOBALS['phpgw']->redirect_link('/index.php');
//go to start - do not collect $200 :P
exit;
}
if ( isset($_POST['close']) )
{
$GLOBALS['phpgw']->redirect_link('/index.php',
array
(
'menuaction' => 'hr.hr_ui.view',
'user_id' => $_REQUEST['user_id']
));
exit;
}
if ( isset($_POST['save']) )
{
if ( isset($_FILES['photo']) &&
$_FILES['photo']['size'] && is_uploaded_file($_FILES['photo']['tmp_name']) )
{
$this->bo->add_entry($_POST['user_id'],
-2, '');
$content =
file_get_contents($_FILES['photo']['tmp_name']);
$this->bo->update_entry($_POST['user_id'], -2, $content);
}
if ( is_array($_POST['field']) &&
count($_POST['field']) )
{
foreach ( $_POST['field'] as $cat =>
$content )
{
$this->bo->update_entry($_POST['user_id'], $cat, $content);
}
}
}
$cats = $this->bo->get_cats();
if ( isset($_POST['add']) && isset($_POST['cat']) &&
$_POST['cat']
&&
isset($cats[$_POST['cat']]['rights'][$GLOBALS['phpgw_info']['user']['account_id']])
&&
$cats[$_POST['cat']]['rights'][$GLOBALS['phpgw_info']['user']['account_id']] |
PHPGW_ACL_ADD )
{
$this->bo->add_entry($_POST['user_id'],
$_POST['cat'], '');
$cats = $this->bo->get_cats(); //refresh the
cats
}
unset($cats[-1]);//can't edit contact here!
$GLOBALS['phpgw']->common->phpgw_header();
echo parse_navbar();
$this->t->set_file('hr_edit', 'edit_user.tpl');
$this->t->set_block('hr_edit', 'edit_block',
'edit_blocks');
$this->t->set_block('hr_edit', 'update_photo',
'update_photos');
$this->t->set_block('hr_edit', 'add_option',
'add_options');
$this->t->set_block('hr_edit', 'add_form', 'add_forms');
$account =
$GLOBALS['phpgw']->accounts->get_account_name($_REQUEST['user_id'], $lid,
$fname, $lname);
$this->t->set_var(array
(
'lang_add' => lang('add'),
'lang_add_label' => lang('add
information:'),
'lang_close' =>
lang('close'),
'lang_please_select' => lang('please
select'),
'lang_save' => lang('save'),
'lang_undo' => lang('undo'),
'lang_upload_photo' => lang('upload
photo'),
'title' => lang('edit
%1', "$fname $lname"),
'url_action' =>
$GLOBALS['phpgw']->link('/index.php',array
(
'menuaction' => 'hr.hr_ui.edit_user'
)),
'user_id' =>
$_REQUEST['user_id']
));
$records = $this->bo->get_records($_REQUEST['user_id'],
PHPGW_ACL_ADD);
if ( count($records) )
{
foreach ( $records as $rec_id => $record )
{
if ( $rec_id < 0 )
{
continue;
}
$this->t->set_var(array
(
'label' =>
$cats[$rec_id]['name'],
'id' =>
$rec_id,
'field_val' =>
nl2br(htmlspecialchars($record))
));
$this->t->parse('edit_blocks',
'edit_block', true);
unset($cats[$rec_id]);
}
}
else
{
$this->t->set_var('edit_blocks', '');
}
if ( isset($cats[-2]) &&
isset($cats[-2]['rights'][$GLOBALS['phpgw_info']['user']['account_id']])
&&
$cats[-2]['rights'][$GLOBALS['phpgw_info']['user']['account_id']] |
PHPGW_ACL_ADD )
{
$this->t->parse('update_photos',
'update_photo');
}
else
{
$this->t->set_var('update_photos', '');
}
unset($cats[-2]);
if ( count($cats) )
{
foreach ( $cats as $cat )
{
$this->t->set_var(array
(
'cat_id'
=> $cat['id'],
'cat_name'
=> $cat['name']
));
$this->t->parse('add_options',
'add_option', true);
}
$this->t->parse('add_forms', 'add_form');
}
else
{
$this->t->set_var('add_forms', '');
}
$this->t->pparse('out', 'hr_edit');
$GLOBALS['phpgw']->common->phpgw_footer();
}
function index()
{
$GLOBALS['phpgw']->common->phpgw_header();
echo parse_navbar();
$this->_render_list();
unset($GLOBALS['phpgw_info']['flags']['nofooter']);//we
should now get a footer
$GLOBALS['phpgw']->common->phpgw_footer();
}
function view()
{
if ( isset($_GET['user_id']) && $_GET['user_id'] )
{
$this->_view_user($_GET['user_id']);
exit;
}
elseif ( isset($_GET['group_id']) && $_GET['group_id'] )
{
$this->_view_group($_GET['group_id']);
}
//Invalid request throw them back to index
$this->index();
}
/**
* @access private
*/
function _render_list($output = true)
{
$this->t->set_file('index', 'index.tpl');
$this->t->set_block('index', 'user', 'users');
$this->t->set_block('index', 'group', 'groups');
$this->t->set_var(
array
(
'lang_users' =>
lang('users'),
'lang_groups' =>
lang('groups')
)
);
$base_href = $GLOBALS['phpgw']->link('/index.php',
array
(
'menuaction' => 'hr.hr_ui.view',
));
$users = $this->bo->get_users();
foreach ( $users as $user )
{
$this->t->set_var(
array
(
'user_href' =>
$base_href . '&user_id=' . $user['account_id'],
'user_fullname' =>
"{$user['account_firstname']} {$user['account_lastname']}"
)
);
$this->t->parse('users', 'user', True);
}
unset($users);
$groups = $this->bo->get_groups();
foreach ( $groups as $group )
{
$this->t->set_var(
array
(
'group_href' =>
$base_href . '&group_id=' . $group['account_id'],
'group_name' =>
$GLOBALS['phpgw']->common->display_fullname($group['account_lid'],
$group['firstname'], $group['lastname'])
)
);
$this->t->parse('groups', 'group', True);
}
unset($groups);
if ( $output )
{
$this->t->pparse('out', 'index');
}
else
{
return $this->t->fp('out', 'index');
}
}
function _set_tabs_js()
{
$GLOBALS['phpgw_info']['flags']['java_script'] .=
"<script type=\"text/javascript\">\n\n"
. "window.onload = function()\n"
. "{\nvar oTabs = new Tabs(2, 'tab_active',
'tab_inactive', 'hr_selector', 'hr_list');\n"
. "oTabs.init();\n"
. (isset($_GET['group_id']) &&
$_GET['group_id'] ? "oTabs.display(2);\n" : '')
. "}\n</script>\n";
}
function _view_group($group_id)
{
$GLOBALS['phpgw']->common->phpgw_header();
echo parse_navbar();
$this->t->set_file('group_profile', 'group.tpl');
$this->t->set_block('group_profile', 'member',
'members');
$group = $this->bo->get_group($group_id);
$this->t->set_var(
array
(
'nav_list' =>
$this->_render_list(false),
'lang_members' =>
lang('members'),
'group_name' =>
$group['fullname']
));
if ( isset($group['members'])
&& is_array($group['members'])
&& count($group['members']) )
{
$base_href =
$GLOBALS['phpgw']->link('/index.php',
array
(
'menuaction' => 'hr.hr_ui.view',
));
foreach ( $group['members'] as $mid => $member )
{
$this->t->set_var(
array
(
'href_member'
=> "{$base_href}&user_id={$member['account_id']}",
'member_name'
=> $GLOBALS['phpgw']->common->grab_owner_name($member['account_id']),
'class_row'
=> ($mid % 2) ? 'on' : 'off'
));
$this->t->parse('members', 'member',
true);
}
}
else
{
$this->t->set_var('members', lang('this group
has no members'));
}
$this->t->pparse('out', 'group_profile');
$GLOBALS['phpgw']->common->phpgw_footer();
$GLOBALS['phpgw']->common->phpgw_exit();
}
function _view_user($user_id)
{
$user = $this->bo->get_user($user_id);
if ( !is_array($user) || !count($user) )
{
$this->index();
exit;
}
$GLOBALS['phpgw']->common->phpgw_header();
echo parse_navbar();
$this->t->set_file('user_profile', 'user.tpl');
$this->t->set_block('user_profile', 'user_image',
'user_images');
$this->t->set_block('user_profile', 'comm', 'comms');
$this->t->set_block('user_profile', 'addr', 'addrs');
$this->t->set_block('user_profile', 'contact',
'contacts');
$this->t->set_block('user_profile', 'note', 'notes');
$this->t->set_block('user_profile', 'can_edit', 'edit');
$this->t->set_var(
array
(
'nav_list' =>
$this->_render_list(false),
'lang_addresses' =>
lang('addresses'),
'lang_communication' =>
lang('communication'),
) + $user['account']) ;
unset($user['account']);
if ( isset($user[-2]) )
{
$mime = createObject('phpgwapi.mime_magic');
$this->t->set_var('img_src', 'data:' .
$mime->analyze_data($user[-2]) . ';base64,' . base64_encode($user[-2]) );
unset($mime);//remove the unneeded memory hog
$this->t->parse('user_images', 'user_image');
unset($user[-2]);
}
else
{
$this->set_var('user_images', '');
}
if ( isset($user['contact']) && count($user['contact'])
)
{
if ( isset($user['contact']['comm_media'])
&&
is_array($user['contact']['comm_media'])
&&
count($user['contact']['comm_media']) )
{
foreach (
$user['contact']['comm_media'] as $comm_type => $comm_val )
{
$this->t->set_var(
array
(
'lang_comm_field' => lang($comm_type),
'val_comm_field' => $comm_val
));
$this->t->parse('comms',
'comm', true);
}
}
else
{
$this->t->set_var('comms', lang('no
communication information available'));
}
if ( isset($user['contact']['locations'])
&&
is_array($user['contact']['locations'])
&& count($user['contact']['locations'])
)
{
foreach ( $user['contact']['locations']
as $location )
{
$address = ''
.
(isset($location['add1']) && $location['add1'] ? $location['add1'] . "\n" : '')
.
(isset($location['add2']) && $location['add2'] ? $location['add2'] . "\n" : '')
.
(isset($location['add3']) && $location['add3'] ? $location['add3'] . "\n" : '')
.
(isset($location['city']) && $location['city'] ? "{$location['city'] }" : '')
.
(isset($location['state']) && $location['state'] ? " {$location['state']} " :
'')
.
(isset($location['postal_code']) && $location['postal_code'] ? "
{$location['postal_code']}" : '');
$address .= (strlen($address) ?
"\n" : '') . (isset($location['country']) && $location['country'] ?
strtoupper($location['country']) : '');
$this->t->set_var(
array
(
'addr_type' => lang($location['type']),
'address' => nl2br(trim($address)),
));
$this->t->parse('addrs',
'addr', true);
}
}
else
{
$this->t->set_var('addrs', lang('no
address information available'));
}
$this->t->parse('contacts', 'contact');
unset($user['contact']);
}
else
{
$this->t->set_var('contacts', '');
}
if ( count($user) )
{
$cats = $this->bo->get_cats();
foreach ( $user as $note_id => $note )
{
$this->t->set_var(array
(
'note_type'
=> $cats[$note_id]['name'],
'note_contents'
=> nl2br(htmlspecialchars($note))
));
$this->t->parse('notes', 'note', true);
}
}
else
{
$this->t->set_var('notes', '');
}
if ( $this->bo->can_edit() )
{
$this->t->set_var(array
(
'url_edit' =>
$GLOBALS['phpgw']->link('/index.php', array
(
'menuaction' => 'hr.hr_ui.edit_user',
'user_id' => $user_id
)),
'lang_edit_info'
=> lang('edit information')
));
$this->t->parse('edit', 'can_edit');
}
else
{
$this->t->parse('can_edit', '');
}
$this->t->pparse('out', 'user_profile');
$GLOBALS['phpgw']->common->phpgw_footer();
$GLOBALS['phpgw']->common->phpgw_exit();
}
}
?>
====================================================
Index: class.hr_so.inc.php
<?php
/**************************************************************************\
* phpGroupWare - Human Resources
*
* Written by Dave Hall skwashd phpgroupware org
*
* Copyright 2005 Free Software Foundation, Inc
*
* Development Sponsored by JimsBookkeeping.com.au
*
* http://www.phpgroupware.org
*
* --------------------------------------------
*
* This program is free software; you can redistribute it and/or modify
it *
* under the terms of the GNU General Public License as published by
the *
* Free Software Foundation; either version 2 of the License, or (at
your *
* option) any later version.
*
\**************************************************************************/
/* $Id: class.hr_so.inc.php,v 1.1 2005/11/15 14:09:42 skwashd Exp $ */
class hr_so
{
/**
* @var object $accounts reference to phpgw global account object
*/
var $accounts;
/**
* @var object $contacts api contacts object
*/
var $contacts;
/**
* @var object $db reference to phpgw global database object
*/
var $db;
function hr_so()
{
$this->accounts =& $GLOBALS['phpgw']->accounts;
$this->contacts = createObject('phpgwapi.contacts');
$this->db =& $GLOBALS['phpgw']->db;
}
/**
* Add an entry
*
* @param int $user_id the user to add the entry to
* @param int $cat the category the record belongs to
* @param string $content the content for the record
*/
function add_entry($user_id, $cat, $content)
{
$user_id = intval($user_id);
$cat = intval($cat);
$this->db->query('SELECT hr_note_id FROM phpgw_hr_notes'
. " WHERE user_id = {$user_id} AND
cat_id = {$cat}", __LINE__, __FILE__);
if ( !$this->db->next_record() )
{
$sql = 'INSERT INTO phpgw_hr_notes(user_id,
cat_id, hr_note, lastmod_ts)'
. " VALUES({$user_id}, {$cat}, '" .
$this->db->db_addslashes($content) . "'," . time() . ')';
$this->db->query($sql, __LINE__, __FILE__);
return
$this->db->get_last_insert_id('phpgw_hr_notes', 'hr_note_id');
}
else
{
return $this->db->f('hr_note_id');
}
}
/**
* Get group listing
*
* @param int $group_id id of account
* @returns array account and contact information
*/
function get_group($group_id)
{
// We have to do it this way cos the accounts class is
all arse about
$this->accounts->account_id = $group_id;
$group = $this->accounts->read_repository();
$this->accounts->account_id =
$GLOBALS['phpgw_info']['user']['account_id'];
$group['members'] = $this->accounts->member($group_id);
return $group;
}
/**
* Get a list of groups
*
* @param string $filter to filter group names by
* @returns array list of groups
*/
function get_groups($filter = '' )
{
return $this->_get_acct_list('groups', $filter);
}
/**
* Get a list of records
*
* @param int $user_id the user information is sought for
* @param array $cats the categories sought
* @return array records
*/
function get_records($user_id, $cats)
{
$record = array();
$sql = 'SELECT cat_id, hr_note FROM phpgw_hr_notes'
. ' WHERE user_id = ' . intval($user_id)
. ' AND cat_id IN(' . implode(',',
$cats) . ')';
$this->db->query($sql, __LINE__, __FILE__);
while ( $this->db->next_record() )
{
$record[$this->db->f('cat_id')] =
$this->db->f('hr_note', true);
}
return $record;
}
/**
* Get user listing
*
* @param int $user_id id of user account
* #param array $cats permitted categories
* @returns array account and contact information
*/
function get_user($user_id, $cats)
{
$user = array();
// We have to do it this way cos the accounts class is
all arse about
$this->accounts->account_id = $user_id;
$user['account'] = $this->accounts->read_repository();
$this->accounts->account_id =
$GLOBALS['phpgw_info']['user']['account_id'];
if ( !is_array($user['account']) ||
!count($user['account']) )
{
return $user;
}
$sql = 'SELECT cat_id, hr_note FROM phpgw_hr_notes'
. ' WHERE user_id = ' . intval($user_id)
. ' AND cat_id IN(' . implode(',',
$cats) . ')';
$this->db->query($sql, __LINE__, __FILE__);
while ( $this->db->next_record() )
{
$user[$this->db->f('cat_id')] =
$this->db->f('hr_note');
}
if ( isset($cats[-1]) )
{
$user['contact'] = array();
if ( isset($user['account']['person_id']) &&
intval($user['account']['person_id']) )
{
$user['contact'] =
$this->contacts->person_complete_data($user['person_id']);
}
}
return $user;
}
/**
* Get a list of users
*
* @param string $filter to filter account names by
* @returns array list of accounts
*/
function get_users($filter = '' )
{
return $this->_get_acct_list('accounts', $filter);
}
/**
* Add an entry
*
* @param int $user_id the user to add the entry to
* @param int $cat the category the record belongs to
* @param string $content the content for the record
*/
function update_entry($user_id, $cat, $content)
{
$sql = 'UPDATE phpgw_hr_notes'
. " SET hr_note = '" .
$this->db->db_addslashes($content) . "',"
. ' lastmod_ts = ' . time()
. ' WHERE cat_id = ' . intval($cat)
. ' AND user_id = ' . intval($user_id);
$this->db->query($sql, __LINE__, __FILE__);
}
/**
* @access private
*/
function _get_acct_list($acct_type, $filter)
{
if ( !$filter )
{
return $this->accounts->get_list($acct_type);
}
//process filter here
}
}
?>
====================================================
Index: hook_admin.inc.php
<?php
/**************************************************************************\
* phpGroupWare *
* http://www.phpgroupware.org *
* Written by Dave Hall *
* -------------------------------------------- *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU General Public License as published by the *
* Free Software Foundation; either version 2 of the License, or (at your *
* option) any later version. *
\**************************************************************************/
/* $Id: hook_admin.inc.php,v 1.1 2005/11/15 14:09:42 skwashd Exp $ */
{
$file = array
(
/*
'Site Configuration' =>
$GLOBALS['phpgw']->link('/index.php',
array
(
'menuaction' => 'admin.uiconfig.index',
'appname' => 'hr'
) ),
*/
'Global Categories' =>
$GLOBALS['phpgw']->link('/index.php',
array
(
'menuaction' => 'admin.uicategories.index',
'appname' => 'hr'
) ),
'Configure Access Permissions' =>
$GLOBALS['phpgw']->link('/index.php',
array
(
'menuaction' => 'hr.hr_acl_ui.acllist'
) ),
);
display_section($appname,$appname,$file);
}
?>
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Phpgroupware-cvs] hr/inc class.hr_acl_so.inc.php, 1.1 class.hr_acl_bo.inc.php, 1.1 class.hr_acl_ui.inc.php, 1.1 class.hr_bo.inc.php, 1.1 class.hr_ui.inc.php, 1.1 class.hr_so.inc.php, 1.1 hook_admin.inc.php, 1.1,
skwashd <=
- Prev by Date:
[Phpgroupware-cvs] hr/setup phpgw_it.lang, 1.3 phpgw_hu.lang, 1.2 phpgw_nl.lang, 1.2 phpgw_sv.lang, 1.3 phpgw_tr.lang, 1.3 phpgw_fr.lang, 1.5 phpgw_ja.lang, 1.2 phpgw_fi.lang, 1.2 phpgw_cs.lang, 1.2 phpgw_da.lang, 1.2 phpgw_de.lang, 1.5 phpgw_es.lang, 1.2 phpgw_en.lang, 1.5
- Next by Date:
[Phpgroupware-cvs] 宜しいですか?
- Previous by thread:
[Phpgroupware-cvs] hr/setup phpgw_it.lang, 1.3 phpgw_hu.lang, 1.2 phpgw_nl.lang, 1.2 phpgw_sv.lang, 1.3 phpgw_tr.lang, 1.3 phpgw_fr.lang, 1.5 phpgw_ja.lang, 1.2 phpgw_fi.lang, 1.2 phpgw_cs.lang, 1.2 phpgw_da.lang, 1.2 phpgw_de.lang, 1.5 phpgw_es.lang, 1.2 phpgw_en.lang, 1.5
- Next by thread:
[Phpgroupware-cvs] 宜しいですか?
- Index(es):