['status'] = True ou False, ['msg'] = Mensagem de erro;
*/
function createLimitRecipientsByGroup($params)
{
if(!$params['selectGroupsInRule'])
return array('status' => false , 'msg' => 'no user selected');
if(!$params['inputTextMaximumRecipientsGroupModal'])
$params['inputTextMaximumRecipientsGroupModal'] = 0 ;
foreach ($params[selectGroupsInRule] as $groupInRule)
{
//Verifica se este usuario Já tem uma regra
$groupInRuleDB = $this->soConfiguration->getRuleInDb('where configuration_type = \'LimitRecipient\' AND email_user = \''.$groupInRule.'\' AND email_user_type = \'G\' ');
if(count($groupInRuleDB) > 0)
{
$fields = array(
'email_user' => $groupInRule,
'configuration_type' => 'LimitRecipient',
'email_max_recipient' => $params['inputTextMaximumRecipientsGroupModal'],
'email_user_type' => 'G'
);
if(!$this->soConfiguration->updatetRuleInDb($groupInRuleDB[0]['id'],$fields))
return array('status' => false , 'msg' => 'Error on Updating');
else
$this->dbFunctions->write_log ('Update Limit Recipients By Group', $groupInRule);
}
else
{
$fields = array(
'email_user' => $groupInRule,
'configuration_type' => 'LimitRecipient',
'email_max_recipient' => $params['inputTextMaximumRecipientsGroupModal'],
'email_user_type' => 'G'
);
if(!$this->soConfiguration->insertRuleInDb($fields))
return array('status' => false , 'msg' => 'Error on insert');
else
$this->dbFunctions->write_log ('Create Limit Recipients By Group', $groupInRule);
}
}
return array('status' => true);
}
/**
* Busca todas as regras LimitRecipientsByUser para a tabela
* @return string Linhas e celulas de tabela
*/
function getTableRulesLimitRecipientsByUser($edit = false)
{
$filter = 'WHERE configuration_type = \'LimitRecipient\' AND email_user_type = \'U\' ORDER BY email_user';
$fields = array('id','email_user','email_max_recipient');
$rules = $this->soConfiguration->getRuleInDb($filter, $fields);
$return = '';
$zebra = 1;
foreach ($rules as $rule)
{
//Resgata informaçoes do usuario do ldap
if($zebra == 0)
{
$return.= '';
$zebra = 1;
}
else
{
$return.= '
';
$zebra = 0;
}
$return.= ''.utf8_encode($this->ldapFunctions->get_user_cn_by_uid($rule['email_user'])).' | ';
if($rule['email_max_recipient'] > 0)
$return.= ''.$rule['email_max_recipient'].' | ';
else
$return.= ''.$this->functions->make_lang('lang_no_limit').' | ';
if($edit == true)
{
$return.= ''.$this->functions->make_lang('lang_edit').' | ';
$return.= ''.$this->functions->make_lang('lang_remove').' | ';
}
else
{
$return.= ''.$this->functions->make_lang('lang_edit').' | ';
$return.= ''.$this->functions->make_lang('lang_remove').' | ';
}
$return.= '
';
}
return utf8_decode($return);
}
/**
* Busca todas as regras LimitRecipientsByGroup para a tabela
* @return string tabela
*/
function getTableRulesLimitRecipientsByGroup($edit = false)
{
$filter = 'WHERE configuration_type = \'LimitRecipient\' AND email_user_type = \'G\' ORDER BY email_user';
$fields = array('id','email_user','email_max_recipient');
$rules = $this->soConfiguration->getRuleInDb($filter, $fields);
$return = '';
$zebra = 1;
foreach ($rules as $rule)
{
//Resgata informaçoes do usuario do ldap
if($zebra == 0)
{
$return.= '';
$zebra = 1;
}
else
{
$return.= '
';
$zebra = 0;
}
$return.= ''.utf8_encode($this->ldapFunctions->get_group_cn_by_gidnumber($rule['email_user'])).' | ';
if($rule['email_max_recipient'] > 0)
$return.= ''.$rule['email_max_recipient'].' | ';
else
$return.= ''.$this->functions->make_lang('lang_no_limit').' | ';
if($edit == true)
{
$return.= ''.$this->functions->make_lang('lang_edit').' | ';
$return.= ''.$this->functions->make_lang('lang_remove').' | ';
}
else
{
$return.= ''.$this->functions->make_lang('lang_edit').' | ';
$return.= ''.$this->functions->make_lang('lang_remove').' | ';
}
$return.= '
';
}
return utf8_decode($return);
}
/**
* Remove regra
* @param array $params [id]
* @return array [status] = true or false,[msg] = mensagem de erro
*/
function removeLimitRecipientsByUser($params)
{
$rule = $this->soConfiguration->getRuleInDb('Where id = \''.$params['id'].'\'');
if($this->soConfiguration->removeRuleInDb($params['id']))
{
$this->dbFunctions->write_log ('Removed Limit Recipients By User', $rule['0']['email_user']);
return array('status' => true);
}
else
return array('status' => false , 'msg' => 'Error on remove');
}
/**
* Remove regra
* @param array $params [id]
* @return array [status] = true or false,[msg] = mensagem de erro
*/
function removeLimitRecipientsByGroup($params)
{
$rule = $this->soConfiguration->getRuleInDb('Where id = \''.$params['id'].'\'');
if($this->soConfiguration->removeRuleInDb($params['id']))
{
$this->dbFunctions->write_log ('Removed Limit Recipients By Group', $rule['0']['email_user']);
return array('status' => true);
}
else
return array('status' => false , 'msg' => 'Error on remove');
}
/**
* Remove regra
* @param array $params [id]
* @return array [status] = true or false,[msg] = mensagem de erro
*/
function removeBlockEmailForInstitutionalAcounteExeption($params)
{
$recipient = explode(',', $params['recipient']);
if($params['recipient'] == '*')
$recipient['1'] = 'A';
$filter = 'WHERE configuration_type = \'InstitutionalAccountException\' AND email_user = \''.$recipient['0'].'\' AND email_user_type = \''.$recipient['1'].'\' ';
$fields = array('id','email_user');
$rules = $this->soConfiguration->getRuleInDb($filter, $fields);
foreach ($rules as $rule)
{
if(!$this->soConfiguration->removeRuleInDb($rule['id']))
return array('status' => false , 'msg' => 'Error on remove');
else
$this->dbFunctions->write_log ('Removed BlockEmail For Institutional AcounteExeption', $rule['email_user']);
}
return array('status' => true);
}
/**
* Carrega as informaçoes da regra para ser editada
* @param array $params [id] = Id da regra
* @return array retorna a rule em um array
*/
function editLimitRecipientesByUser($params)
{
$filter = 'WHERE id = \''.$params['id'].'\'';
$rules = $this->soConfiguration->getRuleInDb($filter);
if($rules)
{
//Resgata informaçoes do usuario do ldap
$rules[0]['userCn'] = $this->ldapFunctions->get_user_cn_by_uid($rules[0]['email_user']);
$rules[0]['status'] = true;
return $rules[0];
}
else
return array('status' => false , 'msg' => 'Error on read rule');
}
/**
* Carrega as informaçoes da regra para ser editada
* @param array $params [id] = Id da regra
* @return array retorna a rule em um array
*/
function editLimitRecipientesByGroup($params)
{
$filter = 'WHERE id = \''.$params['id'].'\'';
$rules = $this->soConfiguration->getRuleInDb($filter);
if($rules)
{
//Resgata informaçoes do usuario do ldap
$rules[0]['groupCn'] = $this->ldapFunctions->get_group_cn_by_gidnumber($rules[0]['email_user']);
$rules[0]['status'] = true;
return $rules[0];
}
else
return array('status' => false , 'msg' => 'Error on read rule');
}
/**
* Cria ou sobrescreve resgras de Institutional Account Exception
* @param array $params
* @return array [status] = true or false,[msg] = mensagem de erro
*/
function createBlockEmailForInstitutionalAcounteExeption($params)
{
if(!$params['selectUsersOrGroupsInRule'] && !$params['inputCheckAllRecipientsInstitutionalAccountRule'])
return array('status' => false , 'msg' => 'no recipients selecteds');
if(!$params['selecSendersInRule'] && !$params['inputCheckAllSendersInstitutionalAccountRule'])
return array('status' => false , 'msg' => 'no senders selecteds');
if($params['inputCheckAllRecipientsInstitutionalAccountRule'] && $params['inputCheckAllSendersInstitutionalAccountRule'])
return array('status' => false , 'msg' => 'all senders and all recipients selecteds');
if($params['inputCheckAllRecipientsInstitutionalAccountRule'])
{
//resgata todas as regras de all Recipients
$condition = 'WHERE configuration_type = \'InstitutionalAccountException\' AND email_user_type = \'A\' ';
$fields = array('id');
$rules = $this->soConfiguration->getRuleInDb($condition,$fields);
//Remove todas as regras de all Recipients
foreach ($rules as $rule)
$this->soConfiguration->removeRuleInDb($rule['id']);
//Insere as novas Regras
foreach($params['selecSendersInRule'] as $senderInRule)
{
$fields = array(
'email_user' => '*',
'email_recipient' => $senderInRule,
'configuration_type' => 'InstitutionalAccountException',
'email_user_type' => 'A'
);
if(!$this->soConfiguration->insertRuleInDb($fields))
return array('status' => false , 'msg' => 'Error on insert');
else
$this->dbFunctions->write_log ('Create BlockEmail For Institutional AcounteExeption', 'All');
}
}
else
{
//intera todos os usuarios ou grupos selecionados
foreach($params['selectUsersOrGroupsInRule'] as $userOrGroupT)
{
$userOrGroupA = explode(',', $userOrGroupT);
$userOrGroup = $userOrGroupA['0'];
if($userOrGroupA['1'] == 'G')
{
//Caso seja um grupo
//resgata todas as regras
$condition = 'WHERE configuration_type = \'InstitutionalAccountException\' AND email_user_type = \'G\' AND email_user = \''.$userOrGroup.'\' ';
$fields = array('id');
$rules = $this->soConfiguration->getRuleInDb($condition,$fields);
//Remove todas as regras
foreach ($rules as $rule)
$this->soConfiguration->removeRuleInDb($rule['id']);
//Se todos os senders estiverem selecionados
if($params['inputCheckAllSendersInstitutionalAccountRule'])
{
$fields = array(
'email_user' => $userOrGroup,
'email_recipient' => '*',
'configuration_type' => 'InstitutionalAccountException',
'email_user_type' => 'G'
);
if(!$this->soConfiguration->insertRuleInDb($fields))
return array('status' => false , 'msg' => 'Error on insert');
}
else
{
//Insere as novas Regras
foreach($params['selecSendersInRule'] as $senderInRule)
{
$fields = array(
'email_user' => $userOrGroup,
'email_recipient' => $senderInRule,
'configuration_type' => 'InstitutionalAccountException',
'email_user_type' => 'G'
);
if(!$this->soConfiguration->insertRuleInDb($fields))
return array('status' => false , 'msg' => 'Error on insert');
}
}
}
else
{
//Caso seja um usuario
//resgata todas as regras
$condition = 'WHERE configuration_type = \'InstitutionalAccountException\' AND email_user_type = \'U\' AND email_user = \''.$userOrGroup.'\' ';
$fields = array('id');
$rules = $this->soConfiguration->getRuleInDb($condition,$fields);
//Remove todas as regras
foreach ($rules as $rule)
$this->soConfiguration->removeRuleInDb($rule['id']);
//Se todos os senders estiverem selecionados
if($params['inputCheckAllSendersInstitutionalAccountRule'])
{
$fields = array(
'email_user' => $userOrGroup,
'email_recipient' => '*',
'configuration_type' => 'InstitutionalAccountException',
'email_user_type' => 'U'
);
if(!$this->soConfiguration->insertRuleInDb($fields))
return array('status' => false , 'msg' => 'Error on insert');
}
else
{
//Insere as novas Regras
foreach($params['selecSendersInRule'] as $senderInRule)
{
$fields = array(
'email_user' => $userOrGroup,
'email_recipient' => $senderInRule,
'configuration_type' => 'InstitutionalAccountException',
'email_user_type' => 'U'
);
if(!$this->soConfiguration->insertRuleInDb($fields))
return array('status' => false , 'msg' => 'Error on insert');
}
}
}
$this->dbFunctions->write_log ('Create BlockEmail For Institutional AcounteExeption', $userOrGroup);
}
}
return array('status' => true);
}
/**
* Retorna todas as regras BlockEmailForInstitutionalAcounteExeption
* @return string
*/
function getOptionsBlockEmailForInstitutionalAcounteExeption()
{
$filter = 'WHERE configuration_type = \'InstitutionalAccountException\' AND email_user_type = \'U\' GROUP BY email_user ORDER BY email_user ';
$fields = array('email_user');
$rulesUsers = $this->soConfiguration->getRuleInDb($filter, $fields);
$filter = 'WHERE configuration_type = \'InstitutionalAccountException\' AND email_user_type = \'G\' GROUP BY email_user ORDER BY email_user ';
$fields = array('email_user');
$rulesGroups = $this->soConfiguration->getRuleInDb($filter, $fields);
$filter = 'WHERE configuration_type = \'InstitutionalAccountException\' AND email_user_type = \'A\' GROUP BY email_user ORDER BY email_user ';
$fields = array('email_user');
$rulesAll = $this->soConfiguration->getRuleInDb($filter, $fields);
$return = '';
if(count($rulesAll) > 0)
{
$return .= '';
foreach ($rulesAll as $all)
$return .= '';
}
if(count($rulesUsers) > 0)
{
$return .= '';
foreach ($rulesUsers as $user)
$return .= '';
}
if(count($rulesGroups) > 0)
{
$return .= '';
foreach ($rulesGroups as $group)
$return .= '';
}
return $return;
}
/**
* Retorna todos os destinatarios da regra BlockInstitutionalAcounteExeptio
* @param $params
* @return string
*/
function getOptionsSenderInstitutionalAcounteExeption($params)
{
$recipient = explode(',', $params['recipient']);
$filter = 'WHERE configuration_type = \'InstitutionalAccountException\' AND email_user = \''.$recipient['0'].'\' ORDER BY email_recipient ';
$fields = array('email_recipient');
$rules = $this->soConfiguration->getRuleInDb($filter, $fields);
$return = '';
if(count($rules) > 0)
{
foreach ($rules as $rule)
{
$return .= '';
}
}
return $return;
}
/**
* Busca os destinatarios das regras de excessao block institutional account
* @param $params
* @return
*/
function getRecipientsInstitutionalAcounteExeption($params)
{
$recipient = explode(',', $params['recipient']);
$filter = 'WHERE configuration_type = \'InstitutionalAccountException\' AND email_user = \''.$recipient['0'].'\' ORDER BY email_recipient ';
$rules = $this->soConfiguration->getRuleInDb($filter);
$return = '';
$allSenders = false;
$optionRecipient = '';
if(count($rules) > 0)
{
foreach ($rules as $rule)
{
if($rule['email_recipient'] == '*')
{
$allSenders = true;
}
$return .= '';
}
}
return array('status' => true, 'options' => $return, 'allSender' => $allSenders );
}
/**
* Cria ou atualiza regras globais de bloqueios
* @param array $params
* @return array [status] = true or false,[msg] = mensagem de erro
*/
function saveGlobalConfiguration($params)
{
//Valida se maximum sender é do tipo numero
if(!is_numeric($params['maximumRecipient']) && $params['maximumRecipient'])
return array('status' => false , 'msg' => 'maximumRecipient not number');
//Atualiza Regra Bloquei de comunicação de contas institucionais ou compartilhadas
$filter = 'WHERE config_app = \'expressoMail1_2\' AND config_name = \'expressoMail_block_institutional_comunication\'';
$fields = array('oid','config_value');
$rules = $this->soConfiguration->getRuleGlobalInDb($filter, $fields);
$params['blockComunication'] = (string)$params['blockComunication'];
//Verifica se ouve alteração
if($rules[0]['config_value'] != $params['blockComunication'])
{
if(count($rules) > 0)
{
//Update
$fields = array(
'config_app' => 'expressoMail1_2',
'config_name' => 'expressoMail_block_institutional_comunication',
'config_value' => $params['blockComunication'],
);
if(!$this->soConfiguration->updatetRuleGlobalInDb($rules['0']['oid'], $fields))
return array('status' => false , 'msg' => 'Error on update block comunication ');
else
$this->dbFunctions->write_log ('Block Institutional Comunication Global Update', 'All');
}
else
{
//Insert
$fields = array(
'config_app' => 'expressoMail1_2',
'config_name' => 'expressoMail_block_institutional_comunication',
'config_value' => $params['blockComunication'],
);
if(!$this->soConfiguration->insertRuleGlobalInDb($fields))
return array('status' => false , 'msg' => 'Error on insert block comunication ');
else
$this->dbFunctions->write_log ('Block Institutional Comunication Global Update', 'All');
}
}
//Atualiza Regra Maximo Destinatarios
$filter = 'WHERE config_app = \'expressoMail1_2\' AND config_name = \'expressoAdmin_maximum_recipients\'';
$fields = array('oid','config_value');
$rules = $this->soConfiguration->getRuleGlobalInDb($filter, $fields);
if($params['maximumRecipient'] < 1)
$params['maximumRecipient'] = '0';
//Verifica se ouve alteração
if($rules[0]['config_value'] != $params['maximumRecipient'])
{
if(count($rules) > 0)
{
//Update
$fields = array(
'config_app' => 'expressoMail1_2',
'config_name' => 'expressoAdmin_maximum_recipients',
'config_value' => $params['maximumRecipient'],
);
if(!$this->soConfiguration->updatetRuleGlobalInDb($rules['0']['oid'], $fields))
return array('status' => false , 'msg' => 'Error on update maximum Recipient ');
else
$this->dbFunctions->write_log ('Maximum RecipientsGlobal Update', 'All');
}
else
{
//Insert
$fields = array(
'config_app' => 'expressoMail1_2',
'config_name' => 'expressoAdmin_maximum_recipients',
'config_value' => $params['maximumRecipient'],
);
if(!$this->soConfiguration->insertRuleGlobalInDb($fields))
return array('status' => false , 'msg' => 'Error on insert maximum Recipient ');
else
$this->dbFunctions->write_log ('Maximum RecipientsGlobal Update', 'All');
}
}
return array('status' => true );
}
/**
* Retorna Todas as regras do modulo expressoAdmin
* @return array
*/
function getGlobalConfiguratons()
{
$filter = 'WHERE config_app = \'expressoMail1_2\' ';
$fields = array('config_name','config_value');
$rules = $this->soConfiguration->getRuleGlobalInDb($filter, $fields);
$config = array();
foreach ($rules as $rule)
{
$config[$rule['config_name']] = $rule['config_value'] ;
}
return $config;
}
}
?>