Index: branches/2.4/expressoAdmin1_2/setup/phpgw_pt-br.lang
===================================================================
--- branches/2.4/expressoAdmin1_2/setup/phpgw_pt-br.lang (revision 5870)
+++ branches/2.4/expressoAdmin1_2/setup/phpgw_pt-br.lang (revision 6660)
@@ -458,4 +458,11 @@
user login expressoAdmin1_2 pt-br Login do usuário
last login expressoAdmin1_2 pt-br Último acesso
+user number cota expressoAdmin1_2 pt-br Cota de usuários
+disk usage cota expressoAdmin1_2 pt-br Cota de disco
+user number expressoAdmin1_2 pt-br Nº de usuários
+disk usage expressoAdmin1_2 pt-br Espaço utilizado
+view cota expressoAdmin1_2 pt-br Cotas
+users quota expressoAdmin1_2 pt-br Cota de Usuários
+disk quota expressoAdmin1_2 pt-br Cota em Disco
shared accounts expressoAdmin1_2 pt-br Contas compartilhadas
create shared account expressoAdmin1_2 pt-br Criar conta compartilhada
Index: branches/2.4/expressoAdmin1_2/inc/class.db_functions.inc.php
===================================================================
--- branches/2.4/expressoAdmin1_2/inc/class.db_functions.inc.php (revision 6585)
+++ branches/2.4/expressoAdmin1_2/inc/class.db_functions.inc.php (revision 6660)
@@ -65,4 +65,14 @@
return $acls;
}
+
+ //returns true if cotas control property is set.
+ function use_cota_control() {
+ $query = "select * from phpgw_config where config_name='expressoAdmin_cotasOu' and config_value='true'";
+ $this->db->query($query);
+ if($this->db->next_record())
+ return true;
+ return false;
+ }
+
/*
* Reativa os usuários desabilitados por tempo inativo modificando o seu ultimo acesso para o dia atual.
Index: branches/2.4/expressoAdmin1_2/inc/class.user.inc.php
===================================================================
--- branches/2.4/expressoAdmin1_2/inc/class.user.inc.php (revision 6186)
+++ branches/2.4/expressoAdmin1_2/inc/class.user.inc.php (revision 6660)
@@ -36,4 +36,19 @@
$return['status'] = true;
+ if($this->db_functions->use_cota_control()) {
+ //Verifica quota de usuários e disco
+ $setor = $this->functions->get_info($params['context']);
+ if (!$this->functions->existe_quota_usuario($setor[0])) {
+ $return['status'] = false;
+ $return['msg'] = $this->functions->lang("user cota exceeded");//TODO colocar valor de acordo com tabela de traduções.
+ return $return;
+ }
+ if (!$this->functions->existe_quota_disco($setor[0],$params['mailquota'])) {
+ $return['status'] = false;
+ $return['msg'] = $this->functions->lang("disk cota exceeded");//TODO colocar valor de acordo com tabela de traduções.
+ return $return;
+ }
+ }
+
// Verifica o acesso do gerente
if ($this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'add_users'))
@@ -303,4 +318,14 @@
*/
+ //Verifica quota de disco, como estou alterando, não preciso checar quota de usuários.
+ if($this->db_functions->use_cota_control()) {
+ $setor = $this->functions->get_info($new_values['context']);
+ if (!$this->functions->existe_quota_disco($setor[0],$new_values['mailquota'])) {
+ $return['status'] = false;
+ $return['msg'] = "Quota em disco excedida...";//TODO colocar valor de acordo com tabela de traduções.
+ return $return;
+ }
+ }
+
$manager_account_lid = $_SESSION['phpgw_session']['session_lid'];
if ((!$this->functions->check_acl($manager_account_lid,'edit_users')) &&
Index: branches/2.4/expressoAdmin1_2/inc/class.bosectors.inc.php
===================================================================
--- branches/2.4/expressoAdmin1_2/inc/class.bosectors.inc.php (revision 5133)
+++ branches/2.4/expressoAdmin1_2/inc/class.bosectors.inc.php (revision 6660)
@@ -47,4 +47,11 @@
$sector_info['objectClass'][0] = 'top';
$sector_info['objectClass'][1] = 'organizationalUnit';
+
+ /*Insere as informações sobre quota total por usuários e por gigabytes de espaço em disco
+ Se não vierem os dados, ele coloca 0 (Caso não exista controle de cota).
+ */
+ $sector_info['diskQuota'] = isset($_POST['disk_quota']) ? $_POST['disk_quota'] : "0";
+ $sector_info['usersQuota'] = isset($_POST['users_quota']) ? $_POST['users_quota'] : "0";
+
$systemName = $GLOBALS['phpgw_info']['server']['system_name'];
@@ -98,9 +105,17 @@
$this->so->add_attribute($sector_info[0]['dn'], $ldap_mod_add);
}
- else
+ elseif($sector_info['phpgwaccountvisible'] == '-1')
{
$ldap_mod_del['objectClass'] = 'phpgwAccount';
$ldap_mod_del['phpgwaccountvisible'] = array();
$this->so->remove_attribute($sector_info[0]['dn'], $ldap_mod_del);
+ }
+
+ //Modifica o conteúdo das cotas.
+ if( (isset($_POST['disk_quota']) ) && (isset($_POST['users_quota']) ) ) { //se for passado alguma coisa, lógico
+ $ldap_mod_replace = array();
+ $ldap_mod_replace['diskQuota'] = $_POST['disk_quota'];
+ $ldap_mod_replace['usersQuota'] = $_POST['users_quota'];
+ $this->so->replace_attribute($sector_info[0]['dn'], $ldap_mod_replace);
}
Index: branches/2.4/expressoAdmin1_2/inc/class.uisectors.inc.php
===================================================================
--- branches/2.4/expressoAdmin1_2/inc/class.uisectors.inc.php (revision 5133)
+++ branches/2.4/expressoAdmin1_2/inc/class.uisectors.inc.php (revision 6660)
@@ -20,5 +20,6 @@
'validate_data_sectors_edit' => True,
'delete_sector' => True,
- 'css' => True
+ 'css' => True,
+ 'view_cota' => True
);
@@ -63,5 +64,6 @@
$p->set_block('sectors','row_empty','row_empty');
- $sectors_info = $this->functions->get_sectors_list($contexts);
+ //$sectors_info = $this->functions->get_sectors_list($contexts);
+ $sectors_info = $this->functions->get_organizations2($contexts);
$var = Array(
@@ -69,5 +71,6 @@
'back_url' => $GLOBALS['phpgw']->link('/expressoAdmin1_2/index.php'),
'context_display' => $context_display,
- 'lang_inactives' => lang('list inactives')
+ 'lang_inactives' => lang('list inactives'),
+ 'lang_ver_cota' => lang('view cota')
);
@@ -95,9 +98,9 @@
{
$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)
+ 'sector_name' => $sector['display'],
+ 'cota_link' => $this->row_action('view','cota',$sector['dn']),
+ 'add_link' => $this->row_action('add','sector',$sector['dn'])
);
@@ -106,5 +109,5 @@
if(isset($GLOBALS['phpgw_info']['server']['time_to_account_expires']))
- $var['inactives_link'] = $this->row_action('list_inactive','users',$context,'uiaccounts');
+ $var['inactives_link'] = $this->row_action('list_inactive','users',$sector['dn'],'uiaccounts');
else
$var['inactives_link'] = lang('disabled');
@@ -114,5 +117,5 @@
if ($can_edit)
{
- $p->set_var('edit_link',$this->row_action('edit','sector',utf8_decode($context)));
+ $p->set_var('edit_link',$this->row_action('edit','sector',$sector['dn']));
}
else
@@ -123,5 +126,5 @@
if ($can_delete)
{
- $p->set_var('delete_link',$this->row_action('delete','sector',utf8_decode($context)));
+ $p->set_var('delete_link',$this->row_action('delete','sector',$sector['dn']));
}
else
@@ -189,9 +192,20 @@
'context' => $context == '' ? $GLOBALS['phpgw_info']['server']['ldap_context'] : $context,
'sector' => $_POST['sector'],
+ 'disk_quota' => $_POST['disk_quota'],
+ 'users_quota' => $_POST['users_quota'],
'manager_org' => $combo_manager_org,
'sector_visible_checked'=> $_POST['sector_visible'] ? 'checked' : '',
'error_messages' => $_POST['error_messages'] == '' ? '' : "",
);
-
+
+ if($this->functions->db_functions->use_cota_control()) {
+ $var["open_comment_cotas"] = "";
+ $var["close_comment_cotas"] ="";
+ }
+ else {
+ $var["open_comment_cotas"] = "";
+ }
+
$var['sector'] = preg_replace("/\\\([0-9A-Fa-f]{2})/e", "''.chr(hexdec('\\1')).''",$var['sector']);
$var['sector'] = utf8_decode($var['sector']);
@@ -242,4 +256,6 @@
{
$sector_info = $this->so->get_info($context);
+ $sector_disk_quota = $sector_info[0]['diskquota'][0];
+ $sector_users_quota = $sector_info[0]['usersquota'][0];
$_POST['sector_visible'] = $sector_info[0]['phpgwaccountvisible'][0];
}
@@ -254,9 +270,21 @@
'manager_org' => $combo_manager_org,
'sector_visible_checked'=> $_POST['sector_visible'] ? 'checked' : '',
+ 'disk_quota' => $_POST['disk_quota'] == '' ? $sector_disk_quota : $_POST['disk_quota'],
+ 'users_quota' => $_POST['users_quota'] == '' ? $sector_users_quota : $_POST['users_quota'],
'lang_add' => lang('Add'),
'disable' => 'disabled',
'error_messages' => $_POST['error_messages'] == '' ? '' : "",
- );
+ 'lang_disk_quota' => lang('disk quota'),
+ 'lang_users_quota' => lang('users quota')
+ );
+ if($this->functions->db_functions->use_cota_control()) {
+ $var["open_comment_cotas"] = "";
+ $var["close_comment_cotas"] ="";
+ }
+ else {
+ $var["open_comment_cotas"] = "";
+ }
$var['sector'] = preg_replace("/\\\([0-9A-Fa-f]{2})/e", "''.chr(hexdec('\\1')).''",$var['sector']);
@@ -267,5 +295,57 @@
$p->pfp('out','edit_sector');
- }
+ }
+
+ function view_cota()
+ {
+ $context = $_GET['context'];
+ $a_tmp = explode(",", ldap_dn2ufn($context));
+
+ $sector_name = $a_tmp[0];
+ if($this->functions->db_functions->use_cota_control()) {
+ $sector_info = $this->so->get_info($context);
+ $sector_disk_cota = $sector_info[0]['diskquota'][0];
+ $sector_users_cota = $sector_info[0]['usersquota'][0];
+ }
+ else {
+ $sector_disk_cota = lang('cotas control disabled');
+ $sector_users_cota = lang('cotas control disabled');
+ }
+
+
+ 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('ver_cota' => 'sectors_cota.tpl'));
+
+
+ // Seta variaveis utilizadas pelo tpl.
+ $var = Array(
+ 'back_url' => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uisectors.list_sectors'),
+ 'th_bg' => $GLOBALS['phpgw_info']['theme']['th_bg'],
+ 'context' => $context,
+ 'sector' => $sector_name,
+ 'disk_cota' => $sector_disk_cota,
+ 'users_cota' => $sector_users_cota,
+ 'actual_users' => $this->functions->get_num_users($context),
+ 'actual_disk' => round($this->functions->get_actual_disk_usage($context),2),
+
+ 'lang_back' => lang('Back'),
+ 'lang_context' => lang('Context'),
+ 'lang_sector_name' => lang('Sector name'),
+ 'lang_disk_cota' => lang('disk usage cota'),
+ 'lang_users_cota' => lang('user number cota'),
+ 'lang_user_number' => lang('user number'),
+ 'lang_disk_used' => lang('disk usage'),
+ 'error_messages' => $_POST['error_messages'] == '' ? '' : "",
+ );
+ $p->set_var($var);
+
+ $p->pfp('out','ver_cota');
+ }
function validate_data_sectors_add()
Index: branches/2.4/expressoAdmin1_2/inc/class.sosectors.inc.php
===================================================================
--- branches/2.4/expressoAdmin1_2/inc/class.sosectors.inc.php (revision 5133)
+++ branches/2.4/expressoAdmin1_2/inc/class.sosectors.inc.php (revision 6660)
@@ -133,4 +133,21 @@
}
+ function replace_attribute($dn, $info)
+ {
+ $connection = $GLOBALS['phpgw']->common->ldapConnect();
+
+ if (ldap_mod_replace($connection, $dn, $info))
+ {
+ ldap_close($connection);
+ return true;
+ }
+ else
+ {
+ echo 'Erro na escrita no LDAP, funcao replace_attribute: ' . ldap_error($connection);
+ ldap_close($connection);
+ return false;
+ }
+ }
+
function remove_attribute($dn, $info)
{
Index: branches/2.4/expressoAdmin1_2/inc/class.functions.inc.php
===================================================================
--- branches/2.4/expressoAdmin1_2/inc/class.functions.inc.php (revision 5934)
+++ branches/2.4/expressoAdmin1_2/inc/class.functions.inc.php (revision 6660)
@@ -464,6 +464,176 @@
$sectors_info = $s->get_organizations($context, $selected, $referral, $show_invisible_ou, $master);
return $sectors_info;
- }
-
+ }
+
+ /*
+ Funciona de maneira similar ao get_sectors_list, porém retorna a propria OU do contexto
+ e monta o array de retorno de forma diferente, necessário para algumas mudanças implementadas
+ no método admin.uisectors.list_sectors.
+ */
+ function get_organizations2($contexts, $selected='', $referral=false, $show_invisible_ou=true) {
+
+ $dn = $GLOBALS['phpgw_info']['server']['ldap_root_dn'];
+ $passwd = $GLOBALS['phpgw_info']['server']['ldap_root_pw'];
+ $ldap_conn = ldap_connect($GLOBALS['phpgw_info']['server']['ldap_host']);
+
+ ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3);
+
+ if ($referral)
+ ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 1);
+ else
+ ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 0);
+
+ ldap_bind($ldap_conn,$dn,$passwd);
+
+ $justthese = array("dn","diskQuota","usersQuota","actualDiskQuota");
+ $filter = "(ou=*)";
+ foreach ($contexts as $context) {
+ $search=ldap_search($ldap_conn, $context, $filter, $justthese);
+
+ ldap_sort($ldap_conn, $search, "ou");
+ $info = ldap_get_entries($ldap_conn, $search);
+ ldap_close($ldap_conn);
+
+ // Retiro o count do array info e inverto o array para ordenaçãoo.
+ for ($i=0; $i<$info["count"]; $i++)
+ {
+ $dn = $info[$i]["dn"];
+
+ // Necessário, pq em uma busca com ldapsearch ou=*, traz tb o próprio ou.
+ //if (strtolower($dn) == $context)
+ //continue;
+
+ $array_dn = ldap_explode_dn ( $dn, 1 );
+
+ $array_dn_reverse = array_reverse ( $array_dn, true );
+
+ // Retirar o indice count do array.
+ array_pop ( $array_dn_reverse );
+
+ $inverted_dn[implode ( "#", $array_dn_reverse )] = $info[$i];
+ }
+ }
+ // Ordenação por chave
+ ksort($inverted_dn);
+
+ // Construção do select
+ $level = 0;
+ $options = array();
+ foreach ($inverted_dn as $dn=>$info_ou)
+ {
+ $display = '';
+ $info_retorno = array();
+ $array_dn_reverse = explode ( "#", $dn );
+ $array_dn = array_reverse ( $array_dn_reverse, true );
+
+ $level = count( $array_dn ) - (int)(count(explode(",", $GLOBALS['phpgw_info']['server']['ldap_context'])) + 1);
+
+ if ($level == 0)
+ $display .= '+';
+ else
+ {
+ for ($i=0; $i<$level; $i++)
+ $display .= '---';
+ }
+
+ reset ( $array_dn );
+ $display .= ' ' . (current ( $array_dn ) );
+
+ $info_retorno['display'] = $display;
+ $info_retorno['dn'] = $info_ou['dn'];
+ $info_retorno['diskquota'] = $info_ou['diskquota'][0];
+ $info_retorno['usersquota'] = $info_ou['usersquota'][0];
+// $info_retorno['actualdiskquota'] = round($this->get_actual_disk_usage($info_ou['dn']),2);//$info_ou['actualdiskquota'][0];
+// $info_retorno['actualnumusers'] = $this->get_num_users($info_ou['dn']);
+
+ array_push($options,$info_retorno);
+
+ }
+ return $options;
+ }
+
+ function get_info($context, $referral = false) {
+ $dn = $GLOBALS['phpgw_info']['server']['ldap_root_dn'];
+ $passwd = $GLOBALS['phpgw_info']['server']['ldap_root_pw'];
+ $ldap_conn = ldap_connect($GLOBALS['phpgw_info']['server']['ldap_host']);
+
+ ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3);
+
+ if ($referral)
+ ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 1);
+ else
+ ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 0);
+
+ ldap_bind($ldap_conn,$dn,$passwd);
+
+ $filter="(objectClass=organizationalUnit)";
+ $search=ldap_search($ldap_conn, $context, $filter);
+ $result = ldap_get_entries($ldap_conn, $search);
+ return $result;
+
+ }
+
+ function get_num_users($context,$selected='', $referral=false, $show_invisible_ou=true) {
+ $dn = $GLOBALS['phpgw_info']['server']['ldap_root_dn'];
+ $passwd = $GLOBALS['phpgw_info']['server']['ldap_root_pw'];
+ $ldap_conn = ldap_connect($GLOBALS['phpgw_info']['server']['ldap_host']);
+
+ ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3);
+
+ if ($referral)
+ ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 1);
+ else
+ ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 0);
+
+ ldap_bind($ldap_conn,$dn,$passwd);
+
+ $justthese = array("dn");
+ $filter = "(objectClass=inetOrgPerson)";
+ $search=ldap_search($ldap_conn, $context, $filter, $justthese);
+
+ $retorno = ldap_count_entries($ldap_conn, $search);
+ ldap_close($ldap_conn);
+
+ return $retorno;
+ }
+
+ //Checa se existe quota para mais um usuï¿Årio no setor... se existir retorna true, senï¿Åo false.
+ function existe_quota_usuario($setor) {
+ $num_users = $this->get_num_users($setor['dn']);
+ //return $num_users . " --- " . $setor['usersquota'][0]
+ if(($num_users>=$setor['usersquota'][0]) && ($setor['usersquota'][0]!=-1)) {
+ return false;
+ }
+ return true;
+ }
+
+ //Checa se existe quota em disco para mais um usuï¿Årio no setor... se existir retorna true, senï¿Åo false.
+ function existe_quota_disco($setor,$quota_novo_usuario) {
+ settype($quota_novo_usuario,"float");
+ $quota_novo_usuario /= 1024; //A quota vï¿Åm da interface em megabytes, deve se tornar gigabyte.
+
+ $nova_quota = $this->get_actual_disk_usage($setor['dn']) + $quota_novo_usuario;
+ if(( $nova_quota >= $setor['diskquota'][0] ) && ($setor['diskquota'][0] != -1)) {
+ return false;
+ }
+ return true;
+ }
+
+ // Soma as quotas de todos os usuï¿Årios daquele contexto.
+ function get_actual_disk_usage($context) {
+ $quota_usada=0;
+ $contexts = array($context);
+ $usuarios = $this->get_list('accounts', '', $contexts);
+
+ $imap_functions = new imap_functions();
+ foreach($usuarios as $usuario) {
+ $temp = $imap_functions->get_user_info($usuario['account_lid']);
+ if($temp['mailquota'] != -1) //Usuï¿Årio sem cota nï¿Åo conta...
+ $quota_usada += ($temp['mailquota'] / 1024);
+ }
+ return $quota_usada;
+ }
+
+
function get_sectors($selected='', $referral=false, $show_invisible_ou=true)
{
Index: branches/2.4/expressoAdmin1_2/templates/default/sectors_form.tpl
===================================================================
--- branches/2.4/expressoAdmin1_2/templates/default/sectors_form.tpl (revision 6159)
+++ branches/2.4/expressoAdmin1_2/templates/default/sectors_form.tpl (revision 6660)
@@ -23,4 +23,23 @@
+ {open_comment_cotas}
+
+
+ {lang_users_quota}:
+ |
+
+
+ |
+
+
+
+
+ {lang_disk_quota}:
+ |
+
+
+ |
+
+ {close_comment_cotas}
Index: branches/2.4/expressoAdmin1_2/templates/default/sectors.tpl
===================================================================
--- branches/2.4/expressoAdmin1_2/templates/default/sectors.tpl (revision 5133)
+++ branches/2.4/expressoAdmin1_2/templates/default/sectors.tpl (revision 6660)
@@ -17,8 +17,9 @@
-
+
{lang_name} |
{lang_inactives} |
+ {lang_ver_cota} |
{lang_add_sub_sectors} |
{lang_edit} |
@@ -32,6 +33,7 @@
{sector_name} |
- {inactives_link} |
- {add_link} |
+ {inactives_link} |
+ {cota_link} |
+ {add_link} |
{edit_link} |
{delete_link} |
Index: branches/2.4/expressoAdmin1_2/templates/default/sectors_cota.tpl
===================================================================
--- branches/2.4/expressoAdmin1_2/templates/default/sectors_cota.tpl (revision 6660)
+++ branches/2.4/expressoAdmin1_2/templates/default/sectors_cota.tpl (revision 6660)
@@ -0,0 +1,59 @@
+
+
+
+
+ {lang_context}: {context} |
+
+
+
+
+
Index: branches/2.4/expressoAdmin1_2/templates/default/config.tpl
===================================================================
--- branches/2.4/expressoAdmin1_2/templates/default/config.tpl (revision 5133)
+++ branches/2.4/expressoAdmin1_2/templates/default/config.tpl (revision 6660)
@@ -166,4 +166,13 @@
{lang_Result}: |
+
+ {lang_use_quotas_control_for_ou} |
+
+
+ |
+
{lang_use_login_generator} |
|