2011-01-28 15:55:26 +00:00
< ? php
2017-10-11 09:58:04 +00:00
/*
----------------------------------------------------------------------
LICENSE
This program is free software ; you can redistribute it and / or
modify it under the terms of the GNU General Public License ( GPL )
as published by the Free Software Foundation ; either version 2
of the License , or ( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
To read the license please visit http :// www . gnu . org / copyleft / gpl . html
----------------------------------------------------------------------
*/
/**
* Form to edit / add subdomains ,
* using domaine_type table to show a synamic form .
*
* @ copyright AlternC - Team 2000 - 2017 https :// alternc . com /
*/
2011-01-28 15:55:26 +00:00
require_once ( " ../class/config.php " );
include_once ( " head.php " );
2013-03-01 12:56:19 +00:00
function sub_domains_edit ( $domain , $sub_domain_id = false ) {
2017-08-16 00:23:22 +00:00
global $admin , $msg , $oldid , $isedit ;
2011-01-28 15:55:26 +00:00
$dom = new m_dom ();
$dom -> lock ();
2017-08-16 00:23:22 +00:00
$r = $dom -> get_domain_all ( $domain );
2011-01-28 15:55:26 +00:00
/*
if ( ! empty ( $sub )) {
2017-08-16 00:23:22 +00:00
$sd = $dom -> get_sub_domain_all ( $domain , $sub , $type , $value );
2011-01-28 15:55:26 +00:00
}
*/
2013-03-01 12:56:19 +00:00
$sd = $dom -> get_sub_domain_all ( $sub_domain_id );
$type = $sd [ 'type' ];
$sub = $sd [ 'name' ];
2011-01-28 15:55:26 +00:00
$dom -> unlock ();
2017-08-16 00:23:22 +00:00
2011-01-28 15:55:26 +00:00
?>
< form action = " dom_subdoedit.php " method = " post " name = " main " id = " main " >
2016-05-20 12:21:47 +00:00
< ? php csrf_get (); ?>
2018-06-22 14:31:23 +00:00
< table class = " dom-edit-table " >
2014-03-26 15:40:43 +00:00
< tr >
< td >
< input type = " hidden " name = " domain " value = " <?php ehe( $domain ) ?> " />
2017-10-07 15:27:03 +00:00
< input type = " hidden " name = " sub_domain_id " value = " <?php echo intval( $sub_domain_id ); ?> " />
2014-03-26 15:40:43 +00:00
< input type = " hidden " name = " action " value = " add " />
2011-03-27 13:21:09 +00:00
< ? php
if ( $isedit ) {
__ ( " Edit a subdomain: " );
2011-03-27 13:29:44 +00:00
} else {
__ ( " Create a subdomain: " );
2011-03-27 13:21:09 +00:00
}
?> </td><td>
2016-05-22 18:14:26 +00:00
< input type = " text " class = " int " name = " sub " style = " text-align:right " value = " <?php ehe( $sub ); ?> " size = " 22 " id = " sub " />< span class = " int " id = " newsubname " >.< ? php ehe ( $domain ); ?> </span></td>
2018-06-22 14:31:23 +00:00
< td ></ td >
2014-03-26 15:40:43 +00:00
</ tr >
2011-03-06 15:03:51 +00:00
< ? php
$first_advanced = true ;
2014-03-26 11:01:02 +00:00
$lst_advanced = array ();
2011-03-06 15:03:51 +00:00
foreach ( $dom -> domains_type_lst () as $dt ) {
// If this type is disabled AND it's not the type in use here, continue
if ( $dt [ 'enable' ] == 'NONE' && strtoupper ( $type ) != strtoupper ( $dt [ 'name' ])) continue ;
// If this type is only for ADMIN and i'm not an admin, continue (oldid is to check if we are an admin who take user identity)
if (( $dt [ 'enable' ] == 'ADMIN' ) && ( ! $admin -> enabled and ! intval ( $oldid ))) continue ;
2011-01-28 15:55:26 +00:00
if ( ( ! $r [ 'dns' ] ) and ( $dt [ 'need_dns' ]) ) continue ;
$targval = ( strtoupper ( $type ) == strtoupper ( $dt [ 'name' ])) ? $sd [ 'dest' ] : '' ;
2011-03-06 15:03:51 +00:00
if ( $dt [ 'advanced' ]) {
$lst_advanced [] = $dt [ 'name' ];
if ( $first_advanced ) {
$first_advanced = false ;
2013-04-19 07:18:25 +00:00
echo " <tr id='domtype_show' onClick= \" domtype_advanced_show(); \" ><td colspan='2'><a href= \" javascript:domtype_advanced_show(); \" ><b>+ " ; __ ( " Show advanced options " ); echo " </b></a></td></tr> " ;
echo " <tr id='domtype_hide' onClick= \" domtype_advanced_hide(); \" style='display:none'><td colspan='2'><a href= \" javascript:domtype_advanced_hide(); \" ><b>- " ; __ ( " Hide advanced options " ); echo " </b></a></td></tr> " ;
2011-03-06 15:03:51 +00:00
}
}
2011-01-28 15:55:26 +00:00
?>
2011-03-06 15:03:51 +00:00
< tr id = " tr_<?php echo $dt['name'] ; ?> " >
2011-01-28 15:55:26 +00:00
< td >
2016-05-22 18:14:26 +00:00
< input type = " radio " id = " r_<?php ehe( $dt['name'] ); ?> " class = " inc " name = " type " value = " <?php ehe( $dt['name'] ); ?> " < ? php cbox ( strtoupper ( $type ) == strtoupper ( $dt [ 'name' ])); ?> OnClick="getElementById('t_<?php ehe($dt['name']); ?>').focus();"/>
< label for = " r_<?php ehe( $dt['name'] ); ?> " >< ? php __ ( $dt [ 'description' ]); ?> </label>
2011-01-28 15:55:26 +00:00
</ td >
< td >
< ? php
switch ( $dt [ 'target' ]) {
case " DIRECTORY " : ?>
2016-05-22 18:14:26 +00:00
< input type = " text " class = " int " name = " t_<?php ehe( $dt['name'] ); ?> " id = " t_<?php ehe( $dt['name'] ); ?> " value = " <?php ehe( $targval ); ?> " size = " 28 " onKeyPress = " getElementById('r_<?php ehe( $dt['name'] ); ?>').checked=true; " />
2015-05-12 14:07:39 +00:00
< ? php display_browser ( $targval , " t_ " . $dt [ 'name' ] );
2011-01-28 15:55:26 +00:00
break ;
case " URL " : ?>
2016-05-22 18:14:26 +00:00
< input type = " text " class = " int " name = " t_<?php ehe( $dt['name'] ); ?> " id = " t_<?php ehe( $dt['name'] ); ?> " value = " <?php ehe( (empty( $targval )?'http://': $targval ) ); ?> " size = " 50 " onKeyPress = " getElementById('r_<?php ehe( $dt['name'] ); ?>').checked=true; " />
2011-01-28 15:55:26 +00:00
< small >< ? php __ ( " (enter an URL here) " ); ?> </small><?php
break ;;
case 'IP' : ?>
2016-05-22 18:14:26 +00:00
< input type = " text " class = " int " name = " t_<?php ehe( $dt['name'] ); ?> " id = " t_<?php ehe( $dt['name'] ); ?> " value = " <?php ehe( $targval ); ?> " size = " 16 " onKeyPress = " getElementById('r_<?php ehe( $dt['name'] ); ?>').checked=true; " />
2011-01-28 15:55:26 +00:00
< small >< ? php __ ( " (enter an IPv4 address, for example 192.168.1.2) " ); ?> </small><?php
break ;
case 'IPV6' : ?>
2016-05-22 18:14:26 +00:00
< input type = " text " class = " int " name = " t_<?php ehe( $dt['name'] ); ?> " id = " t_<?php ehe( $dt['name'] ); ?> " value = " <?php ehe( $targval ); ?> " size = " 32 " onKeyPress = " getElementById('r_<?php ehe( $dt['name'] ); ?>').checked=true; " />
2011-01-28 15:55:26 +00:00
< small >< ? php __ ( " (enter an IPv6 address, for example 2001:0910::0) " ); ?> </small><?php
break ;
case 'TXT' : ?>
2016-05-22 18:14:26 +00:00
< input type = " text " class = " int " name = " t_<?php ehe( $dt['name'] ); ?> " id = " t_<?php ehe( $dt['name'] ); ?> " value = " <?php ehe( $targval );?> " size = " 32 " onKeyPress = " getElementById('r_<?php ehe( $dt['name'] ); ?>').checked=true; " />
2013-10-17 16:18:32 +00:00
< small >< ? php __ ( " (enter a TXT content for this domain) " ); ?> </small><?php
2011-01-28 15:55:26 +00:00
break ;
case 'DOMAIN' : ?>
2016-05-22 18:14:26 +00:00
< input type = " text " class = " int " name = " t_<?php ehe( $dt['name'] ); ?> " id = " t_<?php ehe( $dt['name'] ); ?> " value = " <?php ehe( $targval );?> " size = " 32 " onKeyPress = " getElementById('r_<?php ehe( $dt['name'] ); ?>').checked=true; " />
2011-02-08 08:41:08 +00:00
< small >< ? php __ ( " (enter a domain name or subdomain) " ); ?> </small><?php
2011-01-28 15:55:26 +00:00
break ;
2014-03-26 15:40:43 +00:00
case " NONE " :
default :
break ;
2011-01-28 15:55:26 +00:00
} // switch ?>
</ td >
2018-06-22 14:31:23 +00:00
< td >
< ? php if ( $dt [ 'has_https_option' ]) { ?>
< select class = " inl " name = " https_<?php ehe( $dt['name'] ); ?> " id = " https_<?php ehe( $dt['name'] ); ?> " >
< option value = " http " < ? php selected (( strtoupper ( $type ) == strtoupper ( $dt [ 'name' ]) && $sd [ " https " ] == " http " ) || false ); ?> ><?php __("HTTP Only (redirect HTTPS to HTTP)"); ?></option>
2018-07-17 16:29:57 +00:00
< option value = " https " < ? php selected (( strtoupper ( $type ) == strtoupper ( $dt [ 'name' ]) && $sd [ " https " ] == " https " ) || true ); ?> ><?php __("HTTPS Only (redirect HTTP to HTTPS)"); ?></option>
< option value = " both " < ? php selected (( strtoupper ( $type ) == strtoupper ( $dt [ 'name' ]) && $sd [ " https " ] == " both " ) || false ); ?> ><?php __("Both HTTP and HTTPS hosted at the same place"); ?></option>
2018-06-22 14:31:23 +00:00
</ select >
< ? php } ?>
</ td >
2011-01-28 15:55:26 +00:00
</ tr >
< ? php } // foreach ?>
2014-03-26 15:40:43 +00:00
< tr class = " trbtn " >
2018-06-22 15:13:43 +00:00
< td colspan = " 2 " >< button type = " submit " class = " inb ok " name = " add " onclick = 'return check_type_selected();' >< ? php
2011-03-27 15:03:42 +00:00
if ( $isedit ) {
__ ( " Edit this subdomain " );
} else {
__ ( " Add this subdomain " );
}
2018-06-22 15:13:43 +00:00
?> </button>
2018-06-21 17:15:18 +00:00
< ? php if ( $isedit ) { ?>
2018-07-17 16:20:06 +00:00
< button class = " inb cancel " type = " button " name = " cancel " onclick = " document.location = 'dom_edit.php?domain=<?php echo $domain ; ?>' " >< ? php __ ( " Cancel " ); ?> </button>
2018-06-21 17:15:18 +00:00
< ? php } ?>
</ td >
2014-03-26 15:40:43 +00:00
</ tr >
</ table >
2011-01-28 15:55:26 +00:00
</ form >
2011-03-06 15:03:51 +00:00
< script type = " text/javascript " >
2013-01-25 15:58:56 +00:00
function check_type_selected () {
if ( $ ( 'input[name=type]:radio:checked' ) . val () ) {
// there is a value
2013-03-01 14:47:55 +00:00
var ll = $ ( 'input[name=type]:radio:checked' ) . val ();
var tt = $ ( '#t_' + ll );
if ( tt . length == 0 ) {
// this element do not exist, so OK
return true ;
}
if ( tt . val () == '' ) {
alert ( " <?php __( " Missing value for this sub - domain " ); ?> " );
return false ;
}
2013-01-25 15:58:56 +00:00
return true ;
}
alert ( " <?php __( " Please select a type for this sub - domain " ); ?> " );
return false ;
}
2011-03-06 15:03:51 +00:00
function domtype_advanced_hide () {
< ? php foreach ( $lst_advanced as $adv ) echo " $ ( \" #tr_ $adv\ " ) . hide (); \n " ?>
$ ( " #domtype_show " ) . show ();
$ ( " #domtype_hide " ) . hide ();
}
function domtype_advanced_show () {
< ? php foreach ( $lst_advanced as $adv ) echo " $ ( \" #tr_ $adv\ " ) . show (); \n " ?>
$ ( " #domtype_show " ) . hide ();
$ ( " #domtype_hide " ) . show ();
}
2013-02-06 09:53:39 +00:00
< ? php if ( isset ( $type ) && in_array ( $type , $lst_advanced ) ) { // if it's an edit of an advanced option, we need to show the advanced options ?>
domtype_advanced_show ();
< ? php } else { ?>
domtype_advanced_hide ();
< ? php } // if advanced ?>
2011-03-06 15:03:51 +00:00
</ script >
2011-01-28 15:55:26 +00:00
< ? php
} // sub_domains_edit
?>