Manipulation des sub_domains via leur id et non plus via le couple sub/type/value

Corrige le bug de suppression de deux sub_domains ayant des valeurs identiques
This commit is contained in:
Alan Garcia 2013-03-01 12:56:19 +00:00
parent 52cda8789e
commit 769d090705
7 changed files with 49 additions and 68 deletions

View File

@ -6,7 +6,7 @@ include_once("head.php");
# Function to create/edit subdomain # Function to create/edit subdomain
# Take the values of the subdomain in arguments # Take the values of the subdomain in arguments
function sub_domains_edit($domain, $sub=false,$type=false,$value=false) { function sub_domains_edit($domain, $sub_domain_id=false) {
global $admin, $err, $oldid, $isedit; global $admin, $err, $oldid, $isedit;
$dom=new m_dom(); $dom=new m_dom();
@ -21,7 +21,10 @@ if (! empty($sub)) {
} }
} }
*/ */
$sd=$dom->get_sub_domain_all($domain,$sub,$type,$value); $sd=$dom->get_sub_domain_all($sub_domain_id);
$type=$sd['type'];
$sub=$sd['name'];
$dom->unlock(); $dom->unlock();
?> ?>
@ -30,10 +33,8 @@ $dom->unlock();
<table border="0"> <table border="0">
<tr> <tr>
<td> <td>
<input type="hidden" name="domain" value="<?php ehe($domain); ?>" /> <input type="hidden" name="domain" value="<?php ehe($domain) ?>" />
<input type="hidden" name="sub_old" value="<?php ehe($sub); ?>" /> <input type="hidden" name="sub_domain_id" value="<?php echo $sub_domain_id ?>" />
<input type="hidden" name="type_old" value="<?php ehe($type); ?>" />
<input type="hidden" name="value_old" value="<?php ehe($value); ?>" />
<input type="hidden" name="action" value="add" /> <input type="hidden" name="action" value="add" />
<?php <?php
if ($isedit) { if ($isedit) {

View File

@ -122,13 +122,13 @@ for($i=0;$i<$r["nsub"];$i++) {
<?php if ( $r['sub'][$i]['web_action'] =='DELETE') { echo "<td colspan=2 />"; } else { ?> <?php if ( $r['sub'][$i]['web_action'] =='DELETE') { echo "<td colspan=2 />"; } else { ?>
<td class="center"> <td class="center">
<?php if (!(!$isinvited && $dt[strtolower($r["sub"][$i]["type"])]["enable"] != "ALL" )) { ?> <?php if (!(!$isinvited && $dt[strtolower($r["sub"][$i]["type"])]["enable"] != "ALL" )) { ?>
<div class="ina"><a href="dom_subedit.php?domain=<?php echo urlencode($r["name"]) ?>&amp;sub=<?php echo urlencode($r["sub"][$i]["name"]) ?>&amp;type=<?php echo urlencode($r["sub"][$i]["type"]) ?>&amp;value=<?php echo urlencode($r["sub"][$i]['dest'])?>"><img src="images/edit.png" alt="<?php __("Edit"); ?>" /><?php __("Edit"); ?></a></div> <div class="ina"><a href="dom_subedit.php?sub_domain_id=<?php echo urlencode($r["sub"][$i]["id"]) ?>"><img src="images/edit.png" alt="<?php __("Edit"); ?>" /><?php __("Edit"); ?></a></div>
<?php } ?> <?php } ?>
</td><td class="center"> </td><td class="center">
<?php if (!(!$isinvited && $dt[strtolower($r["sub"][$i]["type"])]["enable"] != "ALL" )) { ?> <?php if (!(!$isinvited && $dt[strtolower($r["sub"][$i]["type"])]["enable"] != "ALL" )) { ?>
<div class="ina"><a href="dom_subdel.php?domain=<?php echo urlencode($r["name"]) ?>&amp;sub=<?php echo urlencode($r["sub"][$i]["name"]) ?>&amp;type=<?php echo urlencode($r["sub"][$i]["type"]) ?>&amp;value=<?php echo urlencode($r["sub"][$i]['dest'])?>"><img src="images/delete.png" alt="<?php __("Delete"); ?>" /><?php __("Delete"); ?></a></div> <div class="ina"><a href="dom_subdel.php?sub_domain_id=<?php echo urlencode($r["sub"][$i]["id"]) ?>"><img src="images/delete.png" alt="<?php __("Delete"); ?>" /><?php __("Delete"); ?></a></div>
<?php } ?> <?php } ?>
</td> </td>
<?php } // end IF ==DELETE ?> <?php } // end IF ==DELETE ?>

View File

@ -31,10 +31,7 @@ require_once("../class/config.php");
include_once("head.php"); include_once("head.php");
$fields = array ( $fields = array (
"domain" => array ("request", "string", ""), "sub_domain_id" => array ("request", "integer", ""),
"sub" => array ("request", "string", ""),
"type" => array ("request", "string", ""),
"value" => array ("request", "string", ""),
); );
getFields($fields); getFields($fields);
@ -46,15 +43,13 @@ if (!$isinvited && $dt[strtolower($type)]["enable"] != "ALL" ) {
$dom->lock(); $dom->lock();
if (!$r=$dom->get_sub_domain_all($domain,$sub,$type)) { if (!$r=$dom->get_sub_domain_all($sub_domain_id)) {
$error=$err->errstr(); $error=$err->errstr();
} }
$dom->unlock(); $dom->unlock();
?> ?>
<h3><?php printf(_("Deleting subdomain %s"),"http://".ife($sub,$sub.".").$domain); ?> : </h3> <h3><?php printf(_("Deleting subdomain %s"),"http://".ife($r['name'],$r['name'].".").$r['domain']); ?> : </h3>
<?php <?php
if (isset($error) && $error) { if (isset($error) && $error) {
echo "<p class=\"error\">$error</p>"; echo "<p class=\"error\">$error</p>";
@ -69,12 +64,9 @@ $dom->unlock();
--> -->
<form action="dom_subdodel.php" method="post"> <form action="dom_subdodel.php" method="post">
<p class="error"> <p class="error">
<input type="hidden" name="domain" value="<?php echo $domain ?>" /> <input type="hidden" name="sub_domain_id" value="<?php echo $sub_domain_id ?>" />
<input type="hidden" name="sub" value="<?php echo $sub ?>" />
<input type="hidden" name="type" value="<?php echo $type ?>" />
<input type="hidden" name="value" value="<?php echo $value ?>" />
<?php __("WARNING : Confirm the deletion of the subdomain"); ?> : </p> <?php __("WARNING : Confirm the deletion of the subdomain"); ?> : </p>
<p><?php ecif($sub,$sub."."); echo $domain; ?></p> <p><?php ecif($r['name'],$r['name']."."); echo $r['domain']; ?></p>
<blockquote> <blockquote>
<input type="submit" class="inb" name="confirm" value="<?php __("Yes"); ?>" />&nbsp;&nbsp; <input type="submit" class="inb" name="confirm" value="<?php __("Yes"); ?>" />&nbsp;&nbsp;
<input type="button" class="inb" name="cancel" value="<?php __("No"); ?>" onclick="history.back();" /> <input type="button" class="inb" name="cancel" value="<?php __("No"); ?>" onclick="history.back();" />

View File

@ -31,10 +31,7 @@ require_once("../class/config.php");
include_once("head.php"); include_once("head.php");
$fields = array ( $fields = array (
"domain" => array ("request", "string", ""), "sub_domain_id" => array ("request", "integer", ""),
"sub" => array ("request", "string", ""),
"type" => array ("request", "string", ""),
"value" => array ("request", "string", ""),
); );
getFields($fields); getFields($fields);
@ -46,15 +43,18 @@ if (!$isinvited && $dt[strtolower($type)]["enable"] != "ALL" ) {
$dom->lock(); $dom->lock();
if (!$r=$dom->get_sub_domain_all($sub_domain_id)) {
$error=$err->errstr();
}
if (!$dom->del_sub_domain($domain,$sub,$type,$value)) { if (!$dom->del_sub_domain($sub_domain_id)) {
$error=$err->errstr(); $error=$err->errstr();
} }
$dom->unlock(); $dom->unlock();
?> ?>
<h3><?php echo sprintf(_("Deleting the subdomain %s:"),"http://".(($sub)?$sub.".":$sub).$domain); ?></h3> <h3><?php echo sprintf(_("Deleting the subdomain %s:"),"http://".(($r['name'])?$r['name'].".":$r['name']).$r['domain']); ?></h3>
<hr id="topbar"/> <hr id="topbar"/>
<br /> <br />
<?php <?php
@ -69,5 +69,5 @@ $dom->unlock();
echo "<p class=\"error\">".$error."</p>"; echo "<p class=\"error\">".$error."</p>";
} }
?> ?>
<p><span class="ina"><a href="dom_edit.php?domain=<?php echo urlencode($domain) ?>"><?php __("Click here to continue"); ?></a></span></p> <p><span class="ina"><a href="dom_edit.php?domain=<?php echo urlencode($r['domain']) ?>"><?php __("Click here to continue"); ?></a></span></p>
<?php include_once("foot.php"); ?> <?php include_once("foot.php"); ?>

View File

@ -32,10 +32,8 @@ require_once("../class/config.php");
$fields = array ( $fields = array (
"domain" => array ("request", "string", ""), "domain" => array ("request", "string", ""),
"sub" => array ("request", "string", ""), "sub" => array ("request", "string", ""),
"sub_old" => array ("request", "string", ""),
"type" => array ("request", "string", $dom->type_local), "type" => array ("request", "string", $dom->type_local),
"type_old" => array ("request", "string", ""), "sub_domain_id" => array ("request", "integer", ""),
"value_old" => array ("request", "string", ""),
); );
getFields($fields); getFields($fields);
@ -58,7 +56,7 @@ if ( (!isset($isinvited) || !$isinvited) && $dt[strtolower($type)]["enable"] !=
$r=$dom->set_sub_domain($domain,$sub,$type,$value, $type_old, $sub_old, $value_old); $r=$dom->set_sub_domain($domain,$sub,$type,$value, $sub_domain_id);
$dom->unlock(); $dom->unlock();

View File

@ -32,15 +32,11 @@ include_once("head.php");
$fields = array ( $fields = array (
"domain" => array ("request", "string", ""), "sub_domain_id" => array ("request", "integer", ""),
"sub" => array ("request", "string", ""),
"type" => array ("request", "string", $dom->type_local),
"value" => array ("request", "string", ""),
); );
getFields($fields); getFields($fields);
$dom->lock(); $dom->lock();
$domroot=$dom->get_domain_all($domain);
$dt=$dom->domains_type_lst(); $dt=$dom->domains_type_lst();
if (!$isinvited && $dt[strtolower($type)]["enable"] != "ALL" ) { if (!$isinvited && $dt[strtolower($type)]["enable"] != "ALL" ) {
@ -48,16 +44,17 @@ if (!$isinvited && $dt[strtolower($type)]["enable"] != "ALL" ) {
exit(); exit();
} }
if (!isset($noread) || !$noread) { if (!isset($noread) || !$noread) {
if (!$r=$dom->get_sub_domain_all($domain,$sub,$type,$value)) { if (!$r=$dom->get_sub_domain_all($sub_domain_id)) {
$error=$err->errstr(); $error=$err->errstr();
} }
} }
$domroot=$dom->get_domain_all($r['domain']);
echo "<h3>"; echo "<h3>";
__("Editing subdomain"); __("Editing subdomain");
echo " http://"; ecif($sub,$sub."."); echo $domain."</h3>"; echo " http://"; ecif($r['name'],$r['name']."."); echo $r['domain']."</h3>";
if (isset($error) && $error) { if (isset($error) && $error) {
echo "<p class=\"error\">$error</p>"; echo "<p class=\"error\">$error</p>";
include_once("foot.php"); include_once("foot.php");
@ -71,7 +68,8 @@ $dom->unlock();
<?php <?php
$isedit=true; $isedit=true;
require_once('dom_edit.inc.php'); require_once('dom_edit.inc.php');
sub_domains_edit($domain,$sub,$type,$value); printvar($r);
sub_domains_edit($r['domain'],$sub_domain_id);
include_once("foot.php"); include_once("foot.php");
?> ?>

View File

@ -768,6 +768,7 @@ class m_dom {
for($i=0;$i<$r["nsub"];$i++) { for($i=0;$i<$r["nsub"];$i++) {
$db->next_record(); $db->next_record();
$r["sub"][$i]=array(); $r["sub"][$i]=array();
$r["sub"][$i]["id"]=$db->Record["id"];
$r["sub"][$i]["name"]=$db->Record["sub"]; $r["sub"][$i]["name"]=$db->Record["sub"];
$r["sub"][$i]["dest"]=$db->Record["valeur"]; $r["sub"][$i]["dest"]=$db->Record["valeur"];
$r["sub"][$i]["type"]=$db->Record["type"]; $r["sub"][$i]["type"]=$db->Record["type"];
@ -785,8 +786,7 @@ class m_dom {
/** /**
* Retourne TOUTES les infos d'un sous domaine du compte courant. * Retourne TOUTES les infos d'un sous domaine du compte courant.
* *
* @param string $dom Domaine fqdn concerné * @param integer sub_domain_id id du subdomain
* @param string $sub Sous-domaine dont on souhaite les informations
* @return arrray Retourne un tableau associatif contenant les * @return arrray Retourne un tableau associatif contenant les
* informations du sous-domaine demandé.<pre> * informations du sous-domaine demandé.<pre>
* $r["name"]= nom du sous-domaine (NON-complet) * $r["name"]= nom du sous-domaine (NON-complet)
@ -795,29 +795,27 @@ class m_dom {
* $r["type"]= Type (0-n) de la redirection. * $r["type"]= Type (0-n) de la redirection.
* Retourne FALSE si une erreur s'est produite. * Retourne FALSE si une erreur s'est produite.
*/ */
function get_sub_domain_all($dom,$sub, $type="", $value='') { function get_sub_domain_all($sub_domain_id) {
global $db,$err,$cuid; global $db,$err,$cuid;
$err->log("dom","get_sub_domain_all",$dom."/".$sub); $err->log("dom","get_sub_domain_all",$sub_domain_id);
// Locked ? // Locked ?
if (!$this->islocked) { if (!$this->islocked) {
$err->raise("dom",_("--- Program error --- No lock on the domains!")); $err->raise("dom",_("--- Program error --- No lock on the domains!"));
return false; return false;
} }
$t=checkfqdn($dom); $db->query("select sd.*, dt.description as type_desc, dt.only_dns from sub_domaines sd, domaines_type dt where compte='$cuid' and sd.id='$sub_domain_id' and upper(dt.name)=upper(sd.type);");
if ($t) {
$err->raise("dom",_("The domain name is syntaxically incorrect"));
return false;
}
$db->query("select sd.*, dt.description as type_desc, dt.only_dns from sub_domaines sd, domaines_type dt where compte='$cuid' and domaine='$dom' and sub='$sub' and ( length('$type')=0 or type='$type') and (length('$value')=0 or '$value'=valeur) and upper(dt.name)=upper(sd.type);");
if ($db->num_rows()==0) { if ($db->num_rows()==0) {
$err->raise("dom",_("The sub-domain does not exist")); $err->raise("dom",_("The sub-domain does not exist"));
return false; return false;
} }
$db->next_record(); $db->next_record();
$r=array(); $r=array();
$r["id"]=$db->Record["id"];
$r["name"]=$db->Record["sub"]; $r["name"]=$db->Record["sub"];
$r["domain"]=$db->Record["domaine"];
$r["dest"]=$db->Record["valeur"]; $r["dest"]=$db->Record["valeur"];
$r["enable"]=$db->Record["enable"]; $r["enable"]=$db->Record["enable"];
$r["type"]=$db->Record["type"];
$r["type_desc"]=$db->Record["type_desc"]; $r["type_desc"]=$db->Record["type_desc"];
$r["only_dns"]=$db->Record["only_dns"]; $r["only_dns"]=$db->Record["only_dns"];
$r["web_action"]=$db->Record["web_action"]; $r["web_action"]=$db->Record["web_action"];
@ -825,7 +823,6 @@ class m_dom {
return $r; return $r;
} // get_sub_domain_all } // get_sub_domain_all
function check_type_value($type, $value) { function check_type_value($type, $value) {
global $db,$err,$cuid; global $db,$err,$cuid;
@ -904,7 +901,7 @@ class m_dom {
* @param string $sub SUBdomain * @param string $sub SUBdomain
* @return boolean tell you if the subdomain can be installed there * @return boolean tell you if the subdomain can be installed there
*/ */
function can_create_subdomain($dom,$sub,$type,$type_old='', $value_old='') { function can_create_subdomain($dom,$sub,$type,$sub_domain_id='null') {
global $db,$err,$cuid; global $db,$err,$cuid;
$err->log("dom","can_create_subdomain",$dom."/".$sub); $err->log("dom","can_create_subdomain",$dom."/".$sub);
@ -914,7 +911,7 @@ class m_dom {
$compatibility_lst = explode(",",$db->f('compatibility')); $compatibility_lst = explode(",",$db->f('compatibility'));
// Get the list of type of subdomains already here who have the same name // Get the list of type of subdomains already here who have the same name
$db->query("select * from sub_domaines where sub='$sub' and domaine='$dom' and not (type='$type_old' and valeur='$value_old') and web_action != 'DELETE'"); $db->query("select * from sub_domaines where sub='$sub' and domaine='$dom' and not id = $sub_domain_id and web_action != 'DELETE'");
#$db->query("select * from sub_domaines where sub='$sub' and domaine='$dom';"); #$db->query("select * from sub_domaines where sub='$sub' and domaine='$dom';");
while ($db->next_record()) { while ($db->next_record()) {
// And if there is a domain with a incompatible type, return false // And if there is a domain with a incompatible type, return false
@ -941,7 +938,7 @@ class m_dom {
* de $type (url, ip, dossier...) * de $type (url, ip, dossier...)
* @return boolean Retourne FALSE si une erreur s'est produite, TRUE sinon. * @return boolean Retourne FALSE si une erreur s'est produite, TRUE sinon.
*/ */
function set_sub_domain($dom,$sub,$type,$dest, $type_old=null,$sub_old=null,$value_old=null) { function set_sub_domain($dom,$sub,$type,$dest, $sub_domain_id=null) {
global $db,$err,$cuid,$bro; global $db,$err,$cuid,$bro;
$err->log("dom","set_sub_domain",$dom."/".$sub."/".$type."/".$dest); $err->log("dom","set_sub_domain",$dom."/".$sub."/".$type."/".$dest);
// Locked ? // Locked ?
@ -974,13 +971,13 @@ class m_dom {
return false; return false;
} }
if (! $this->can_create_subdomain($dom,$sub,$type,$type_old,$value_old)) { if (! $this->can_create_subdomain($dom,$sub,$type,$sub_domain_id)) {
$err->raise("dom", _("The parameters for this subdomain and domain type are invalid. Please check for subdomain entries incompatibility")); $err->raise("dom", _("The parameters for this subdomain and domain type are invalid. Please check for subdomain entries incompatibility"));
return false; return false;
} }
if (! is_null($type_old )) { // It's not a creation, it's an edit. Delete the old one if (! is_null($sub_domain_id )) { // It's not a creation, it's an edit. Delete the old one
$db->query("update sub_domaines set web_action='DELETE' where domaine='$dom' and sub='$sub_old' and upper(type)=upper('$type_old') and valeur='$value_old';"); $this->del_sub_domain($sub_domain_id);
} }
// Re-create the one we want // Re-create the one we want
@ -1030,25 +1027,20 @@ class m_dom {
* @return boolean Retourne FALSE si une erreur s'est produite, TRUE sinon. * @return boolean Retourne FALSE si une erreur s'est produite, TRUE sinon.
* *
*/ */
function del_sub_domain($dom,$sub,$type,$value='') { function del_sub_domain($sub_domain_id) {
global $db,$err,$cuid; global $db,$err,$cuid;
$err->log("dom","del_sub_domain",$dom."/".$sub); $err->log("dom","del_sub_domain",$sub_domain_id);
// Locked ? // Locked ?
if (!$this->islocked) { if (!$this->islocked) {
$err->raise("dom",_("--- Program error --- No lock on the domains!")); $err->raise("dom",_("--- Program error --- No lock on the domains!"));
return false; return false;
} }
$t=checkfqdn($dom); if (!$r=$this->get_sub_domain_all($sub_domain_id)) {
if ($t) {
$err->raise("dom",_("The domain name is syntaxically incorrect"));
return false;
}
if (!$r=$this->get_sub_domain_all($dom,$sub,$type)) {
$err->raise("dom",_("The sub-domain does not exist")); $err->raise("dom",_("The sub-domain does not exist"));
return false; return false;
} else { } else {
$db->query("update sub_domaines set web_action='DELETE' where domaine='$dom' and sub='$sub' and type='$type' and ( length('$value')=0 or valeur='$value') "); $db->query("update sub_domaines set web_action='DELETE' where id='$sub_domain_id'; ");
$db->query("update domaines set dns_action='UPDATE' where domaine='$dom';"); $db->query("update domaines set dns_action='UPDATE' where domaine='".$r['domain']."';");
} }
return true; return true;
} // del_sub_domain } // del_sub_domain