[fix] the compatibility system of domaines_types was not working. Fixing that (null in SQL is awefully weird)

This commit is contained in:
Benjamin Sonntag 2017-10-07 17:27:03 +02:00
parent 1c6191eabc
commit 80ec8fc748
4 changed files with 18 additions and 11 deletions

View File

@ -32,7 +32,7 @@ $dom->unlock();
<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_domain_id" value="<?php ehe($sub_domain_id); ?>" /> <input type="hidden" name="sub_domain_id" value="<?php echo intval($sub_domain_id); ?>" />
<input type="hidden" name="action" value="add" /> <input type="hidden" name="action" value="add" />
<?php <?php
if ($isedit) { if ($isedit) {

View File

@ -33,7 +33,7 @@ $fields = array (
"domain" => array ("post", "string", ""), "domain" => array ("post", "string", ""),
"sub" => array ("post", "string", ""), "sub" => array ("post", "string", ""),
"type" => array ("post", "string", $dom->type_local), "type" => array ("post", "string", $dom->type_local),
"sub_domain_id" => array ("post", "integer", ""), "sub_domain_id" => array ("post", "integer", 0),
); );
getFields($fields); getFields($fields);
@ -61,9 +61,14 @@ $r=$dom->set_sub_domain($domain,$sub,$type,$value, $sub_domain_id);
$dom->unlock(); $dom->unlock();
if (!$r) { if (!$r) {
$noread=true; if ($sub_domain_id!=0) {
include("dom_subedit.php"); $noread=true;
exit(); include("dom_subedit.php");
} else {
// it was a creation, not an edit
include("dom_edit.php");
}
exit();
} else { } else {
$t = time(); $t = time();
// XXX: we assume the cron job is at every 5 minutes // XXX: we assume the cron job is at every 5 minutes

View File

@ -32,7 +32,7 @@ include_once("head.php");
$fields = array ( $fields = array (
"sub_domain_id" => array ("request", "integer", ""), "sub_domain_id" => array ("request", "integer", 0),
); );
getFields($fields); getFields($fields);

View File

@ -1339,9 +1339,11 @@ 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, $sub_domain_id = 'null') { function can_create_subdomain($dom, $sub, $type, $sub_domain_id = 0) {
global $db, $msg; global $db, $msg;
$msg->log("dom", "can_create_subdomain", $dom . "/" . $sub);
$sub_domain_id=intval($sub_domain_id);
$msg->log("dom", "can_create_subdomain", $dom . "/" . $sub . "/" .$type . "/" . $sub_domain_id);
// Get the compatibility list for this domain type // Get the compatibility list for this domain type
$db->query("select upper(compatibility) as compatibility from domaines_type where upper(name)=upper(?);", array($type)); $db->query("select upper(compatibility) as compatibility from domaines_type where upper(name)=upper(?);", array($type));
@ -1382,7 +1384,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, $sub_domain_id = null) { function set_sub_domain($dom, $sub, $type, $dest, $sub_domain_id = 0) {
global $db, $msg, $cuid, $bro; global $db, $msg, $cuid, $bro;
$msg->log("dom", "set_sub_domain", $dom . "/" . $sub . "/" . $type . "/" . $dest); $msg->log("dom", "set_sub_domain", $dom . "/" . $sub . "/" . $type . "/" . $dest);
// Locked ? // Locked ?
@ -1420,12 +1422,12 @@ class m_dom {
return false; return false;
} }
if (!is_null($sub_domain_id) && !empty($sub_domain_id)) { // It's not a creation, it's an edit. Delete the old one if ($sub_domain_id!=0) { // It's not a creation, it's an edit. Delete the old one
$this->del_sub_domain($sub_domain_id); $this->del_sub_domain($sub_domain_id);
} }
// Re-create the one we want // Re-create the one we want
if (!$db->query("replace into sub_domaines (compte,domaine,sub,valeur,type,web_action) values (?, ?, ?, ?, ?, 'UPDATE');", array( $cuid , $dom , $sub , $dest , $type ))) { if (!$db->query("INSERT INTO sub_domaines (compte,domaine,sub,valeur,type,web_action) VALUES (?, ?, ?, ?, ?, 'UPDATE');", array( $cuid , $dom , $sub , $dest , $type ))) {
echo "query failed: " . $db->Error; echo "query failed: " . $db->Error;
return false; return false;
} }