True,
'add_sector' => True,
'validate_data_sectors_add' => True,
'edit_sector' => True,
'validate_data_sectors_edit' => True,
'delete_sector' => True,
'css' => True
);
var $bo;
var $nextmatchs;
var $functions;
function uisectors()
{
$this->bo = CreateObject('expressoAdmin1_2.bosectors');
$this->so = $this->bo->so;
$this->functions = $this->bo->functions;
$this->nextmatchs = createobject('phpgwapi.nextmatchs');
}
function list_sectors()
{
$manager_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
$acl = $this->functions->read_acl($manager_lid);
$contexts = $acl['contexts'];
foreach ($acl['contexts_display'] as $index=>$tmp_context)
{
$context_display .= '
'.$tmp_context;
}
// Verifica se o administrador tem acesso.
if (!$this->functions->check_acl($manager_lid,'list_sectors'))
{
$GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php'));
}
unset($GLOBALS['phpgw_info']['flags']['noheader']);
unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
$GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Sectors');
$GLOBALS['phpgw']->common->phpgw_header();
$p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
$p->set_file(array('sectors' => 'sectors.tpl'));
$p->set_block('sectors','list','list');
$p->set_block('sectors','row','row');
$p->set_block('sectors','row_empty','row_empty');
$sectors_info = $this->functions->get_sectors_list($contexts);
$var = Array(
'th_bg' => $GLOBALS['phpgw_info']['theme']['th_bg'],
'back_url' => $GLOBALS['phpgw']->link('/expressoAdmin1_2/index.php'),
'context_display' => $context_display,
'lang_inactives' => lang('list inactives')
);
$p->set_var($var);
$p->set_var($this->functions->make_dinamic_lang($p, 'list'));
if (!count($sectors_info))
{
$p->set_var('message',lang('No matches found'));
$p->parse('rows','row_empty',True);
}
else
{
if ($this->functions->check_acl($manager_lid,'edit_sectors'))
{
$can_edit = True;
}
if ($this->functions->check_acl($manager_lid,'delete_sectors'))
{
$can_delete = True;
}
foreach($sectors_info as $context=>$sector)
{
$tr_color = $this->nextmatchs->alternate_row_color($tr_color);
$var = Array(
'tr_color' => $tr_color,
'sector_name' => $sector,
'add_link' => $this->row_action('add','sector',$context)
);
if(isset($GLOBALS['phpgw_info']['server']['time_to_account_expires']))
$var['inactives_link'] = $this->row_action('list_inactive','users',$context,'uiaccounts');
else
$var['inactives_link'] = lang('disabled');
$p->set_var($var);
if ($can_edit)
{
$p->set_var('edit_link',$this->row_action('edit','sector',$context));
}
else
{
$p->set_var('edit_link',' ');
}
if ($can_delete)
{
$p->set_var('delete_link',$this->row_action('delete','sector',$context));
}
else
{
$p->set_var('delete_link',' ');
}
$p->fp('rows','row',True);
}
}
$var = Array(
'action' => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uisectors.add_sector')
);
$p->set_var($var);
$p->set_var('input_add','');
$p->parse('rows','row_empty',True);
$p->pfp('out','list');
}
function add_sector($context='')
{
$manager_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
$acl = $this->functions->read_acl($manager_lid);
$manager_contexts = $acl['contexts'];
$combo_manager_org = '';
if ( array_key_exists( 'context', $_GET ) )
{
$context = $_GET['context'];
$combo_manager_org = $this->functions->get_organizations( $context, '', true, true, true );
}
else
{
foreach ($manager_contexts as $index=>$context)
$combo_manager_org .= $this->functions->get_organizations( $context );
}
// Verifica se tem acesso a este modulo
if (!$this->functions->check_acl($manager_lid,'create_sectors'))
{
$GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php'));
}
unset($GLOBALS['phpgw_info']['flags']['noheader']);
unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
$GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Create Sector');
$GLOBALS['phpgw']->common->phpgw_header();
// Set o template
$p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
$p->set_file(Array('create_sector' => 'sectors_form.tpl'));
$p->set_block('create_sector','list','list');
// Seta variaveis utilizadas pelo tpl.
$var = Array(
'action' => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uisectors.validate_data_sectors_add'),
'back_url' => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uisectors.list_sectors'),
'th_bg' => $GLOBALS['phpgw_info']['theme']['th_bg'],
'context' => $context == '' ? $GLOBALS['phpgw_info']['server']['ldap_context'] : $context,
'sector' => $_POST['sector'],
'manager_org' => $combo_manager_org,
'sector_visible_checked'=> $_POST['sector_visible'] ? 'checked' : '',
'error_messages' => $_POST['error_messages'] == '' ? '' : "",
);
$p->set_var($var);
$p->set_var($this->functions->make_dinamic_lang($p, 'list'));
$p->pfp('out','create_sector');
}
function edit_sector()
{
$account_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
$acl = $this->functions->read_acl($account_lid);
$manager_context = $acl[0]['context'];
$context = $_GET['context'];
$combo_manager_org = $this->functions->get_organizations($_GET['context'], '', true, true, true);
$combo_manager_org = substr( $combo_manager_org, 0, ( strpos($combo_manager_org, '') + 9 ) );
$a_tmp = explode(",", ldap_dn2ufn($context));
$sector_name = $a_tmp[0];
// Verifica se tem acesso a este modulo
if (!$this->functions->check_acl($account_lid,'edit_sectors'))
{
$GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php'));
}
unset($GLOBALS['phpgw_info']['flags']['noheader']);
unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
$GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Edit Sector');
$GLOBALS['phpgw']->common->phpgw_header();
// Set o template
$p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
$p->set_file(Array('edit_sector' => 'sectors_form.tpl'));
$p->set_block('edit_sector','list','list');
if (!$_POST)
{
$sector_info = $this->so->get_info($context);
$_POST['sector_visible'] = $sector_info[0]['phpgwaccountvisible'][0];
}
// Seta variaveis utilizadas pelo tpl.
$var = Array(
'action' => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.bosectors.save_sector'),
'back_url' => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uisectors.list_sectors'),
'th_bg' => $GLOBALS['phpgw_info']['theme']['th_bg'],
'context' => $context == '' ? $manager_context : $context,
'sector' => $_POST['sector'] == '' ? $sector_name : $_POST['sector'],
'manager_org' => $combo_manager_org,
'sector_visible_checked'=> $_POST['sector_visible'] ? 'checked' : '',
'lang_add' => lang('Add'),
'disable' => 'disabled',
'error_messages' => $_POST['error_messages'] == '' ? '' : "",
);
$p->set_var($var);
$p->set_var($this->functions->make_dinamic_lang($p, 'list'));
$p->pfp('out','edit_sector');
}
function validate_data_sectors_add()
{
$sector_name = $_POST['sector'];
$context = $_POST['context'];
// Verifica se o nome do sector nao esta vazio.
if ($sector_name == '')
{
$_POST['error_messages'] = lang('Sector name is empty.');
ExecMethod('expressoAdmin1_2.uisectors.add_sector');
return;
}
// Verifica se o nome do setor existe no contexto atual.
if ($this->so->exist_sector_name($sector_name, $context))
{
$_POST['error_messages'] = lang('Sector name already exist.');
ExecMethod('expressoAdmin1_2.uisectors.add_sector');
return;
}
ExecMethod('expressoAdmin1_2.bosectors.create_sector');
}
function delete_sector()
{
$account_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
$acl = $this->functions->read_acl($account_lid);
$manager_context = $acl[0]['context'];
// Verifica se tem acesso a este modulo
if (!$this->functions->check_acl($account_lid,'delete_sectors'))
{
$GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php'));
}
unset($GLOBALS['phpgw_info']['flags']['noheader']);
unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
$GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Delete Sectors');
$GLOBALS['phpgw']->common->phpgw_header();
// Set o template
$p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
$p->set_file(Array('delete_sector' => 'sectors_delete.tpl'));
$p->set_block('delete_sector','list','list');
$tmp_sector_name = $_GET['context'];
$tmp_sector_name = explode(",",$tmp_sector_name);
$tmp_sector_name = $tmp_sector_name[0];
$tmp_sector_name = explode("=", $tmp_sector_name);
$sector_name = $tmp_sector_name[1];
// Get users of sector
$sector_users = $this->so->get_sector_users($_GET['context']);
$sector_groups = $this->so->get_sector_groups($_GET['context']);
$sector_subsectors = $this->so->get_sector_subsectors($_GET['context']);
$users_list = '';
foreach ($sector_users as $user)
{
$users_list .= $user['cn'][0] . '
';
}
$groups_list = '';
foreach ($sector_groups as $group)
{
$groups_list .= $group['cn'][0] . '
';
}
$subsectors_list = '';
foreach ($sector_subsectors as $subsector)
{
if ($subsector['dn'] != $_GET['context'])
$subsectors_list .= $subsector['ou'][0] . '
';
}
// Seta variaveis utilizadas pelo tpl.
$var = Array(
'color_bg1' => "#E8F0F0",
'manager_context' => $manager_context,
'dn' => $_GET['context'],
'back_url' => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uisectors.list_sectors'),
'action' => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.bosectors.delete_sector'),
'sector_name' => $sector_name,
'users_list' => $users_list,
'groups_list' => $groups_list,
'sectors_list' => $subsectors_list
);
$p->set_var($var);
$p->set_var($this->functions->make_dinamic_lang($p, 'list'));
$p->pfp('out','delete_sector');
}
function row_action($action,$type,$context,$class='uisectors')
{
return ' '.lang($action).' ';
}
function css()
{
$appCSS = '';
return $appCSS;
}
}
?>