From f2384f6ba8408c52a1573b450ecc19f6ac871ef4 Mon Sep 17 00:00:00 2001 From: David Ramos Date: Wed, 3 Jan 2018 13:26:30 +0100 Subject: [PATCH] =?UTF-8?q?Versi=C3=B3n=20v2.0.=20Control=20total=20de=20l?= =?UTF-8?q?as=20limitaciones=20para=20usuarios=20y=20revendedores.=20Solo?= =?UTF-8?q?=20para=20admin.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- clases/limites.inc.php | 118 ++++++++++++++++++++++++++++++----------- 1 file changed, 88 insertions(+), 30 deletions(-) diff --git a/clases/limites.inc.php b/clases/limites.inc.php index 5828709..634cbf4 100644 --- a/clases/limites.inc.php +++ b/clases/limites.inc.php @@ -22,10 +22,10 @@ class limites { public function __construct($cliente_group_id){ global $app, $conf; $this->cliente = $client = $app->db->queryOneRecord( - "SELECT limit_dns_zone, limit_web_domain, limit_database, parent_client_id - FROM sys_group, client - WHERE sys_group.client_id = client.client_id - and sys_group.groupid = ?", $cliente_group_id); + "SELECT limit_dns_zone, limit_web_domain, limit_database, parent_client_id, client.client_id, client.contact_name + FROM sys_group, client + WHERE sys_group.client_id = client.client_id + AND sys_group.groupid = ?", $cliente_group_id); $this->cliente_grupo_id = $cliente_group_id; } @@ -44,7 +44,31 @@ class limites { $this->revendedor = $tmpReseller['userid']; $this->revendedor_grupos = $tmpReseller['groups']; - $this->revendedor_grupo_def = $tmpReseller['default_group']; + $this->revendedor_grupo_def = $tmpReseller['default_group']; + } + + public $esReventa; + public $todosLosGrupos; + //public $gruposDelReventa; + + public function esRevendedor(){ + global $app, $conf; + //PARA SABER QUIEN ES UN RESELLER + //SELECT client_id, company_name, limit_client FROM client WHERE limit_client > 0 OR limit_client = -1 + $this->esReventa = $app->db->queryOneRecord( + "SELECT client_id, limit_client, contact_name + FROM client + WHERE limit_client > 0 OR limit_client = -1 AND client_id = ?", $this->cliente['client_id']); + + //El campo contact_name es obligatorio. Si viene vacĂ­o no es reventa. + if($this->esReventa['contact_name'] != ''){ + //Capturo los grupos que tiene este reventa + $gruposDelReventa = $app->db->queryOneRecord( + "SELECT client_id, groups FROM sys_user WHERE client_id = ?", $this->cliente['client_id']); + + $this->todosLosGrupos = explode(',', $gruposDelReventa['groups']); + + } } public function limClienteDns(){ @@ -55,11 +79,13 @@ class limites { if($this->cliente["limit_dns_zone"] >= 0) { $tmp = $app->db->queryOneRecord( "SELECT count(id) as number FROM dns_soa WHERE sys_groupid = ?", $this->cliente_grupo_id); + if($tmp["number"] >= $this->cliente["limit_dns_zone"]) { $app->error($app->tform->wordbook["limit_dns_zone_txt"]); return true; } } + //* If the client belongs to a reseller, we will check against the reseller Limit too if($this->cliente['parent_client_id'] != 0) { //* first we need to know the groups of this reseller @@ -67,7 +93,7 @@ class limites { //echo(' Valores '.$this->revendedor . ' otro ' . $this->revendedor_grupos . ' y otro ' .$this->revendedor_grupo_def); //echo(' El cliente es ' . $this->cliente['parent_client_id']); $reseller = $app->db->queryOneRecord( - "SELECT limit_dns_zone as number, contact_firstname FROM client WHERE client_id = ?", $this->cliente['parent_client_id']); + "SELECT limit_dns_zone as number, contact_name FROM client WHERE client_id = ?", $this->cliente['parent_client_id']); //echo(' Cliente Reventa limites DNS ' . $reseller['number']); // Check if the user may add another item if($reseller['number'] >= 0) { @@ -78,31 +104,29 @@ class limites { "SELECT count(id) as number FROM dns_soa WHERE sys_groupid = ?", $this->revendedor_grupo_def); $totalCreado = $tmpCliente['number'] + $tmpReventa['number']; - //echo(' Total creado ' . $totalCreado . ' el array ' . print_r($reseller). ' Y ' . $reseller['number']); + if($totalCreado >= $reseller['number']) { - $app->error($reseller['contact_firstname'] . '. ' . $app->tform->wordbook["limit_dns_zone_txt"]); + $app->error($reseller['contact_name'] . '. ' . $app->tform->wordbook["limit_dns_zone_txt"]); return true; } - /* $tmp = $app->db->queryOneRecord( - "SELECT count(id) as number FROM dns_soa WHERE sys_groupid = ?", explode(',', $this->revendedor_grupos)); - echo(' El temp registros en dns_soa usando grupo reseller ' .$tmp['number']);*/ - /* $sumaTotal = 0; - $todosLosGrupos = explode(',', $this->revendedor_grupos); - foreach($todosLosGrupos as $grupos) { - $tmpReventaALL = $app->db->queryOneRecord( - "SELECT count(id) as number FROM dns_soa WHERE sys_groupid = ?", $grupos); - $sql = "SELECT count(id) as number FROM dns_soa WHERE sys_groupid = ". $grupos; - echo(' Valores ' . $tmpReventaALL['number']); - $sumaTotal =+ $tmpReventaALL['number']; - echo($sumaTotal); - - }*/ - /*if($tmp['number'] >= $reseller['number']) { - $app->error($app->tform->wordbook["limit_dns_zone_txt"]); - return true; - }*/ } } + + $this->esRevendedor(); + + $sumaTotal = 0; + foreach($this->todosLosGrupos as $grupos) { + $tmpReventaALL = $app->db->queryOneRecord( + "SELECT count(id) as number FROM dns_soa WHERE sys_groupid = ?", $grupos); + + $sumaTotal += $tmpReventaALL['number']; + } + + if($sumaTotal >= $this->cliente["limit_dns_zone"]) { + $app->error($this->esReventa['contact_name'] . '. ' . $app->tform->wordbook["limit_dns_zone_txt"]); + return true; + } + return false; } } @@ -127,7 +151,7 @@ class limites { $this->getRevendedor(); $reseller = $app->db->queryOneRecord( - "SELECT limit_web_domain as number, contact_firstname FROM client WHERE client_id = ?", $this->cliente['parent_client_id']); + "SELECT limit_web_domain as number, contact_name FROM client WHERE client_id = ?", $this->cliente['parent_client_id']); //echo(' Cliente Reventa limites DNS ' . $reseller['number']); // Check if the user may add another item if($reseller['number'] >= 0) { @@ -142,11 +166,28 @@ class limites { $totalCreado = $tmpCliente['number'] + $tmpReventa['number']; if($totalCreado >= $reseller['number']) { - $app->error($reseller['contact_firstname'] . '. ' . $app->tform->wordbook["limit_web_domain_txt"]); + $app->error($reseller['contact_name'] . '. ' . $app->tform->wordbook["limit_web_domain_txt"]); return true; } } } + + $this->esRevendedor(); + + $sumaTotal = 0; + foreach($this->todosLosGrupos as $grupos) { + $tmpReventaALL = $app->db->queryOneRecord( + "SELECT count(domain_id) as number FROM web_domain + WHERE sys_groupid = ? and type = 'vhost'", $grupos); + + $sumaTotal += $tmpReventaALL['number']; + } + + if($sumaTotal >= $this->cliente["limit_web_domain"]) { + $app->error($this->esReventa['contact_name'] . '. ' . $app->tform->wordbook["limit_web_domain_txt"]); + return true; + } + return false; } } @@ -171,7 +212,7 @@ class limites { $this->getRevendedor(); $reseller = $app->db->queryOneRecord( - "SELECT limit_database as number, contact_firstname FROM client WHERE client_id = ?", $this->cliente['parent_client_id']); + "SELECT limit_database as number, contact_name FROM client WHERE client_id = ?", $this->cliente['parent_client_id']); //echo(' Cliente Reventa limites DNS ' . $reseller['number']); // Check if the user may add another item if($reseller['number'] >= 0) { @@ -186,11 +227,28 @@ class limites { $totalCreado = $tmpCliente['number'] + $tmpReventa['number']; if($totalCreado >= $reseller['number']) { - $app->error($reseller['contact_firstname'] . '. ' . $app->tform->wordbook["limit_database_txt"]); + $app->error($reseller['contact_name'] . '. ' . $app->tform->wordbook["limit_database_txt"]); return true; } } } + + $this->esRevendedor(); + + $sumaTotal = 0; + foreach($this->todosLosGrupos as $grupos) { + $tmpReventaALL = $app->db->queryOneRecord( + "SELECT count(database_id) as number + FROM web_database WHERE sys_groupid = ?", $grupos); + + $sumaTotal += $tmpReventaALL['number']; + } + + if($sumaTotal >= $this->cliente["limit_database"]) { + $app->error($this->esReventa['contact_name'] . '. ' . $app->tform->wordbook["limit_database_txt"]); + return true; + } + return false; } }