2012-06-04 16:58:40 +02:00
< ? php
/*
FusionPBX
Version : MPL 1.1
The contents of this file are subject to the Mozilla Public License Version
1.1 ( the " License " ); you may not use this file except in compliance with
the License . You may obtain a copy of the License at
http :// www . mozilla . org / MPL /
Software distributed under the License is distributed on an " AS IS " basis ,
WITHOUT WARRANTY OF ANY KIND , either express or implied . See the License
for the specific language governing rights and limitations under the
License .
The Original Code is FusionPBX
The Initial Developer of the Original Code is
Mark J Crane < markjcrane @ fusionpbx . com >
2015-07-24 01:51:39 +02:00
Portions created by the Initial Developer are Copyright ( C ) 2008 - 2015
2012-06-04 16:58:40 +02:00
the Initial Developer . All Rights Reserved .
Contributor ( s ) :
Mark J Crane < markjcrane @ fusionpbx . com >
*/
require_once " root.php " ;
2013-07-06 08:03:27 +02:00
require_once " resources/require.php " ;
2013-07-06 07:50:55 +02:00
require_once " resources/check_auth.php " ;
2012-09-27 02:34:10 +02:00
if ( permission_exists ( 'domain_view' )) {
2012-06-04 16:58:40 +02:00
//access granted
}
else {
echo " access denied " ;
exit ;
}
2013-05-14 07:34:04 +02:00
//add multi-lingual support
2015-01-18 10:22:07 +01:00
$language = new text ;
$text = $language -> get ();
2013-05-14 07:34:04 +02:00
2012-09-27 02:34:10 +02:00
//change the domain
if ( strlen ( check_str ( $_GET [ " domain_uuid " ])) > 0 && check_str ( $_GET [ " domain_change " ]) == " true " ) {
if ( permission_exists ( 'domain_select' )) {
//get the domain_uuid
$sql = " select * from v_domains " ;
$sql .= " order by domain_name asc " ;
$prep_statement = $db -> prepare ( $sql );
$prep_statement -> execute ();
$result = $prep_statement -> fetchAll ( PDO :: FETCH_NAMED );
foreach ( $result as $row ) {
if ( count ( $result ) == 0 ) {
2012-06-04 16:58:40 +02:00
$_SESSION [ " domain_uuid " ] = $row [ " domain_uuid " ];
$_SESSION [ " domain_name " ] = $row [ 'domain_name' ];
}
2012-09-27 02:34:10 +02:00
else {
if ( $row [ 'domain_name' ] == $domain_array [ 0 ] || $row [ 'domain_name' ] == 'www.' . $domain_array [ 0 ]) {
$_SESSION [ " domain_uuid " ] = $row [ " domain_uuid " ];
$_SESSION [ " domain_name " ] = $row [ 'domain_name' ];
}
}
2012-06-04 16:58:40 +02:00
}
2012-09-27 02:34:10 +02:00
unset ( $result , $prep_statement );
//update the domain session variables
$domain_uuid = check_str ( $_GET [ " domain_uuid " ]);
$_SESSION [ 'domain_uuid' ] = $domain_uuid ;
$_SESSION [ " domain_name " ] = $_SESSION [ 'domains' ][ $domain_uuid ][ 'domain_name' ];
$_SESSION [ 'domain' ][ 'template' ][ 'name' ] = $_SESSION [ 'domains' ][ $domain_uuid ][ 'template_name' ];
2014-06-10 22:04:14 +02:00
2012-09-27 02:34:10 +02:00
//clear the extension array so that it is regenerated for the selected domain
unset ( $_SESSION [ 'extension_array' ]);
2014-06-10 22:04:14 +02:00
2012-10-16 20:08:24 +02:00
//set the setting arrays
$domain = new domains ();
$domain -> db = $db ;
$domain -> set ();
2014-02-25 07:41:42 +01:00
// on domain change, redirect user
2014-06-10 22:04:14 +02:00
if ( $_SESSION [ " login " ][ " destination " ] != '' ) {
// to default, or domain specific, login destination
header ( " Location: " . PROJECT_PATH . $_SESSION [ " login " ][ " destination " ][ " url " ]);
}
else {
header ( " Location: " . PROJECT_PATH . " /core/user_settings/user_dashboard.php " );
}
return ;
2012-09-27 02:34:10 +02:00
}
2012-06-04 16:58:40 +02:00
}
//includes
2013-07-06 08:29:50 +02:00
require_once " resources/header.php " ;
2014-07-10 02:32:50 +02:00
$document [ 'title' ] = $text [ 'title-domains' ];
2013-05-14 07:34:04 +02:00
2013-07-06 08:29:50 +02:00
require_once " resources/paging.php " ;
2012-06-04 16:58:40 +02:00
2014-07-23 06:24:57 +02:00
//get the http values and set them as variables
$search = check_str ( $_GET [ " search " ]);
if ( isset ( $_GET [ " order_by " ])) {
$order_by = check_str ( $_GET [ " order_by " ]);
$order = check_str ( $_GET [ " order " ]);
}
2012-06-04 16:58:40 +02:00
2014-07-23 06:24:57 +02:00
//show the header and the search
2015-02-06 02:26:06 +01:00
echo " <table width='100%' cellpadding='0' cellspacing='0' border='0'> \n " ;
2012-06-04 16:58:40 +02:00
echo " <tr> \n " ;
2015-02-06 02:26:06 +01:00
echo " <td width='50%' align='left' valign='top' nowrap='nowrap'><b> " . $text [ 'header-domains' ] . " </b></td> \n " ;
echo " <td width='50%' align='right' valign='top'> \n " ;
echo " <form method='get' action=''> \n " ;
2014-07-23 06:24:57 +02:00
echo " <input type='text' class='txt' style='width: 150px' name='search' value=' $search '> " ;
echo " <input type='submit' class='btn' name='submit' value=' " . $text [ 'button-search' ] . " '> " ;
2015-02-06 02:26:06 +01:00
echo " </form> \n " ;
2014-07-23 06:24:57 +02:00
echo " </td> \n " ;
2012-06-04 16:58:40 +02:00
echo " </tr> \n " ;
echo " <tr> \n " ;
2015-02-06 02:26:06 +01:00
echo " <td align='left' valign='top' colspan='2'> \n " ;
2013-05-14 07:34:04 +02:00
echo " " . $text [ 'description-domains' ] . " <br /><br /> \n " ;
2012-06-04 16:58:40 +02:00
echo " </td> \n " ;
echo " </tr> \n " ;
echo " </table> \n " ;
2014-07-23 06:24:57 +02:00
//prepare to page the results
$sql = " select count(*) as num_rows from v_domains " ;
2014-07-23 06:30:10 +02:00
if ( strlen ( $search ) > 0 ) {
$sql .= " where ( " ;
$sql .= " domain_name like '% " . $search . " %' " ;
$sql .= " or domain_description like '% " . $search . " %' " ;
$sql .= " ) " ;
}
2014-07-23 06:24:57 +02:00
$prep_statement = $db -> prepare ( $sql );
if ( $prep_statement ) {
$prep_statement -> execute ();
$row = $prep_statement -> fetch ( PDO :: FETCH_ASSOC );
if ( $row [ 'num_rows' ] > 0 ) {
$num_rows = $row [ 'num_rows' ];
2012-09-03 19:05:03 +02:00
}
else {
2014-07-23 06:24:57 +02:00
$num_rows = '0' ;
2012-09-03 19:05:03 +02:00
}
2014-07-23 06:24:57 +02:00
}
//prepare to page the results
$rows_per_page = 100 ;
$param = " " ;
$page = $_GET [ 'page' ];
if ( strlen ( $page ) == 0 ) { $page = 0 ; $_GET [ 'page' ] = 0 ; }
list ( $paging_controls , $rows_per_page , $var3 ) = paging ( $num_rows , $param , $rows_per_page );
$offset = $rows_per_page * $page ;
//get the list
$sql = " select * from v_domains " ;
if ( strlen ( $search ) > 0 ) {
$sql .= " where ( " ;
$sql .= " domain_name like '% " . $search . " %' " ;
$sql .= " or domain_description like '% " . $search . " %' " ;
$sql .= " ) " ;
}
if ( strlen ( $order_by ) == 0 ) {
$sql .= " order by domain_name asc " ;
}
else {
2015-02-06 02:26:06 +01:00
$sql .= " order by " . $order_by . " " . $order . " " ;
2014-07-23 06:24:57 +02:00
}
2015-02-06 02:26:06 +01:00
$sql .= " limit " . $rows_per_page . " offset " . $offset . " " ;
2014-07-23 06:24:57 +02:00
$prep_statement = $db -> prepare ( check_sql ( $sql ));
$prep_statement -> execute ();
$result = $prep_statement -> fetchAll ( PDO :: FETCH_NAMED );
unset ( $prep_statement , $sql );
2012-06-04 16:58:40 +02:00
2015-02-06 02:26:06 +01:00
foreach ( $result as $domain ) {
$domains [ $domain [ 'domain_uuid' ]][ 'name' ] = $domain [ 'domain_name' ];
$domains [ $domain [ 'domain_uuid' ]][ 'parent_uuid' ] = $domain [ 'domain_parent_uuid' ];
$domains [ $domain [ 'domain_uuid' ]][ 'enabled' ] = $domain [ 'domain_enabled' ];
$domains [ $domain [ 'domain_uuid' ]][ 'description' ] = $domain [ 'domain_description' ];
}
2012-06-04 16:58:40 +02:00
$c = 0 ;
$row_style [ " 0 " ] = " row_style0 " ;
$row_style [ " 1 " ] = " row_style1 " ;
2014-06-21 09:51:31 +02:00
echo " <table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'> \n " ;
2012-06-04 16:58:40 +02:00
echo " <tr> \n " ;
2013-05-14 07:34:04 +02:00
echo th_order_by ( 'domain_name' , $text [ 'label-domain' ], $order_by , $order );
2014-07-24 08:05:05 +02:00
echo " <th> " . $text [ 'label-tools' ] . " </th> " ;
2013-05-14 07:34:04 +02:00
echo th_order_by ( 'domain_description' , $text [ 'label-description' ], $order_by , $order );
2014-02-26 07:21:37 +01:00
echo " <td class='list_control_icons'> " ;
2012-09-27 02:34:10 +02:00
if ( permission_exists ( 'domain_add' )) {
2014-02-26 07:21:37 +01:00
echo " <a href='domain_edit.php' alt=' " . $text [ 'button-add' ] . " '> $v_link_label_add </a> " ;
2012-09-27 02:34:10 +02:00
}
2012-06-04 16:58:40 +02:00
echo " </td> \n " ;
2014-06-22 03:16:49 +02:00
echo " </tr> \n " ;
2012-06-04 16:58:40 +02:00
2015-02-06 02:26:06 +01:00
if ( count ( $domains ) > 0 ) {
function get_child_domains ( $domain_parent_uuid ) {
global $domains , $indent ;
global $c , $row_style , $text , $v_link_label_edit , $v_link_label_delete ;
foreach ( $domains as $domain_uuid => $domain ) {
if ( $domain [ 'parent_uuid' ] == $domain_parent_uuid ) {
$tr_link = ( permission_exists ( 'domain_edit' )) ? " href='domain_edit.php?id= " . $domain_uuid . " ' " : null ;
echo " <tr " . $tr_link . " > \n " ;
echo " <td valign='top' class=' " . $row_style [ $c ] . " ' " . (( $indent != 0 ) ? " style='padding-left: " . ( $indent * 20 ) . " px;' " : null ) . " > " ;
echo " <a href='domain_edit.php?id= " . $domain_uuid . " '> " . $domain [ 'name' ] . " </a> " ;
if ( $domain [ 'enabled' ] != '' && $domain [ 'enabled' ] != 'true' ) {
echo " <span style='color: #aaa; font-size: 80%;'> ( " . $text [ 'label-disabled' ] . " )</span> " ;
}
echo " </td> \n " ;
echo " <td valign='top' class=' " . $row_style [ $c ] . " '> " ;
if ( permission_exists ( 'domain_edit' )) {
echo " <a href=' " . PROJECT_PATH . " /core/domain_settings/domains.php?domain_uuid= " . $domain_uuid . " &domain_change=true'> " . $text [ 'label-manage' ] . " </a> " ;
}
echo " </td> " ;
echo " <td valign='top' class='row_stylebg'> " . $domain [ 'description' ] . " </td> \n " ;
echo " <td class='list_control_icons'> " ;
if ( permission_exists ( 'domain_edit' )) {
echo " <a href='domain_edit.php?id= " . $domain_uuid . " ' alt=' " . $text [ 'button-edit' ] . " '> " . $v_link_label_edit . " </a> " ;
}
if ( permission_exists ( 'domain_delete' )) {
if ( $_SESSION [ " groups " ][ 0 ][ " domain_uuid " ] != $domain_uuid && count ( $domains ) > 1 ) {
echo " <a href='domain_delete.php?id= " . $domain_uuid . " ' alt=' " . $text [ 'button-delete' ] . " ' onclick= \" return confirm(' " . $text [ 'confirm-delete' ] . " ') \" > " . $v_link_label_delete . " </a> " ;
}
else {
echo " <span onclick= \" alert('You cannot delete your own domain. \\ n \\ nPlease login with a user account under a different domain, then try again.'); \" > " . $v_link_label_delete . " </span> " ;
}
}
echo " </td> \n " ;
echo " </tr> \n " ;
$c = ( $c == 0 ) ? 1 : 0 ;
$indent ++ ;
get_child_domains ( $domain_uuid );
$indent -- ;
2014-06-17 23:24:44 +02:00
}
2012-09-27 02:34:10 +02:00
}
2015-02-06 02:26:06 +01:00
}
$indent = 0 ;
get_child_domains ();
2012-06-04 16:58:40 +02:00
} //end if results
echo " <tr> \n " ;
2014-07-24 07:58:01 +02:00
echo " <td colspan='4' align='left'> \n " ;
2012-06-04 16:58:40 +02:00
echo " <table width='100%' cellpadding='0' cellspacing='0'> \n " ;
echo " <tr> \n " ;
echo " <td width='33.3%' nowrap> </td> \n " ;
echo " <td width='33.3%' align='center' nowrap> $paging_controls </td> \n " ;
2014-02-26 07:21:37 +01:00
echo " <td class='list_control_icons'> " ;
2012-09-27 02:34:10 +02:00
if ( permission_exists ( 'domain_add' )) {
2014-02-26 07:21:37 +01:00
echo " <a href='domain_edit.php' alt=' " . $text [ 'button-add' ] . " '> $v_link_label_add </a> " ;
2012-09-27 02:34:10 +02:00
}
2012-06-04 16:58:40 +02:00
echo " </td> \n " ;
echo " </tr> \n " ;
echo " </table> \n " ;
echo " </td> \n " ;
echo " </tr> \n " ;
echo " </table> " ;
echo " <br /><br /> " ;
//include the footer
2013-07-06 08:29:50 +02:00
require_once " resources/footer.php " ;
2012-06-04 16:58:40 +02:00
?>