2013-08-15 21:16:03 +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 >
2019-12-19 04:13:47 +01:00
Portions created by the Initial Developer are Copyright ( C ) 2013 - 2019
2013-08-15 21:16:03 +02:00
the Initial Developer . All Rights Reserved .
Contributor ( s ) :
Mark J Crane < markjcrane @ fusionpbx . com >
James Rose < james . o . rose @ gmail . com >
*/
2016-05-29 03:50:20 +02:00
//includes
require_once " root.php " ;
require_once " resources/require.php " ;
2019-12-05 03:08:02 +01:00
require_once " resources/check_auth.php " ;
require_once " resources/paging.php " ;
2016-05-29 03:50:20 +02:00
//check permissions
if ( permission_exists ( 'ring_group_edit' ) || permission_exists ( 'ring_group_forward' )) {
//access granted
}
else {
echo " access denied " ;
exit ;
}
2013-08-15 21:16:03 +02:00
//add multi-lingual support
2015-01-18 11:06:08 +01:00
$language = new text ;
2015-01-29 20:31:06 +01:00
$text = $language -> get ( $_SESSION [ 'domain' ][ 'language' ][ 'code' ], 'app/ring_groups' );
2013-08-15 21:16:03 +02:00
//get variables used to control the order
$order_by = $_GET [ " order_by " ];
$order = $_GET [ " order " ];
2019-08-17 19:55:11 +02:00
//find the path
switch ( $_SERVER [ 'REQUEST_URI' ]) {
case PROJECT_PATH . " /core/user_settings/user_dashboard.php " :
$validated_path = PROJECT_PATH . " /core/user_settings/user_dashboard.php " ;
break ;
case PROJECT_PATH . " /app/ring_groups/ring_group_forward.php " :
$validated_path = PROJECT_PATH . " /app/ring_groups/ring_group_forward.php " ;
break ;
default :
$validated_path = PROJECT_PATH . " /app/ring_groups/ring_group_forward.php " ;
}
2016-03-29 22:15:01 +02:00
//update ring group forwarding
2019-12-05 03:08:02 +01:00
if ( is_array ( $_POST [ 'ring_groups' ]) && @ sizeof ( $_POST [ 'ring_groups' ]) != 0 && permission_exists ( 'ring_group_forward' )) {
//validate the token
$token = new token ;
if ( ! $token -> validate ( '/app/ring_groups/ring_group_forward.php' )) {
message :: add ( $text [ 'message-invalid_token' ], 'negative' );
header ( 'Location: ' . $validated_path );
exit ;
2019-08-13 12:48:28 +02:00
}
2019-08-17 19:55:11 +02:00
2019-12-05 03:08:02 +01:00
$x = 0 ;
foreach ( $_POST [ 'ring_groups' ] as $row ) {
//remove non-numeric characters
$ring_group_uuid = $row [ 'ring_group_uuid' ];
$ring_group_forward_destination = preg_replace ( " ~[^0-9]~ " , " " , $row [ 'ring_group_forward_destination' ]);
$ring_group_forward_enabled = $row [ 'ring_group_forward_enabled' ] == 'true' && is_numeric ( $ring_group_forward_destination ) ? 'true' : 'false' ;
//build array
if ( is_uuid ( $ring_group_uuid )) {
$array [ 'ring_groups' ][ $x ][ 'ring_group_uuid' ] = $ring_group_uuid ;
$array [ 'ring_groups' ][ $x ][ 'domain_uuid' ] = $_SESSION [ 'domain_uuid' ];
$array [ 'ring_groups' ][ $x ][ 'ring_group_forward_enabled' ] = $ring_group_forward_enabled ;
$array [ 'ring_groups' ][ $x ][ 'ring_group_forward_destination' ] = $ring_group_forward_destination ;
}
//increment counter
$x ++ ;
}
if ( is_array ( $array ) && sizeof ( $array ) != 0 ) {
//update ring group
$p = new permissions ;
$p -> add ( 'ring_group_edit' , 'temp' );
2019-08-13 12:48:28 +02:00
2019-12-05 03:08:02 +01:00
$database = new database ;
$database -> app_name = 'ring_groups' ;
$database -> app_uuid = '1d61fb65-1eec-bc73-a6ee-a6203b4fe6f2' ;
$database -> save ( $array );
unset ( $array );
2019-08-13 12:48:28 +02:00
2019-12-05 03:08:02 +01:00
$p -> delete ( 'ring_group_edit' , 'temp' );
2019-08-13 12:48:28 +02:00
2019-12-05 03:08:02 +01:00
//set message
message :: add ( $text [ 'message-update' ]);
2019-08-13 12:48:28 +02:00
2019-12-05 03:08:02 +01:00
//redirect the user
header ( " Location: " . $validated_path );
exit ;
2013-08-15 21:16:03 +02:00
}
2016-03-29 22:15:01 +02:00
}
2013-08-15 21:16:03 +02:00
2016-03-29 22:15:01 +02:00
//prepare to page the results
if ( permission_exists ( 'ring_group_add' ) || permission_exists ( 'ring_group_edit' )) {
//show all ring groups
2019-08-13 12:48:28 +02:00
$sql = " select count(*) from v_ring_groups " ;
$sql .= " where domain_uuid = :domain_uuid " ;
$parameters [ 'domain_uuid' ] = $domain_uuid ;
2016-03-29 22:15:01 +02:00
}
else {
2019-08-13 12:48:28 +02:00
//show only assigned ring groups
2019-08-14 18:53:44 +02:00
$sql = " select count(*) from v_ring_groups as r, v_ring_group_users as u " ;
2016-03-29 22:15:01 +02:00
$sql .= " where r.ring_group_uuid = u.ring_group_uuid " ;
2019-08-13 12:48:28 +02:00
$sql .= " and r.domain_uuid = :domain_uuid " ;
$sql .= " and u.user_uuid = :user_uuid " ;
2019-08-17 19:55:11 +02:00
$parameters [ 'domain_uuid' ] = $_SESSION [ 'user' ][ 'domain_uuid' ];
$parameters [ 'user_uuid' ] = $_SESSION [ 'user' ][ 'user_uuid' ];
2016-03-29 22:15:01 +02:00
}
2019-08-13 12:48:28 +02:00
$database = new database ;
$num_rows = $database -> select ( $sql , $parameters , 'column' );
2019-08-14 18:53:44 +02:00
unset ( $parameters );
2013-08-15 21:16:03 +02:00
2016-03-29 22:15:01 +02:00
//prepare to page the results
2019-08-13 12:48:28 +02:00
$rows_per_page = $is_included ? 10 : ( is_numeric ( $_SESSION [ 'domain' ][ 'paging' ][ 'numeric' ]) ? $_SESSION [ 'domain' ][ 'paging' ][ 'numeric' ] : 50 );
2016-03-29 22:15:01 +02:00
$param = " " ;
2019-12-19 04:13:47 +01:00
if ( isset ( $_GET [ 'page' ])) {
$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 ;
}
2016-03-29 22:15:01 +02:00
//get the list
if ( permission_exists ( 'ring_group_add' ) || permission_exists ( 'ring_group_edit' )) {
//show all ring groups
2019-08-14 18:53:44 +02:00
$sql = " select * from v_ring_groups " ;
$sql .= " where domain_uuid = :domain_uuid " ;
$parameters [ 'domain_uuid' ] = $domain_uuid ;
2016-03-29 22:15:01 +02:00
}
else {
//show only assigned ring groups
2019-08-14 18:53:44 +02:00
$sql = " select r.ring_group_name, r.ring_group_uuid, r.ring_group_extension, r.ring_group_forward_destination, r.ring_group_forward_enabled, r.ring_group_description from v_ring_groups as r, v_ring_group_users as u " ;
$sql .= " where r.ring_group_uuid = u.ring_group_uuid " ;
$sql .= " and r.domain_uuid = :domain_uuid " ;
$sql .= " and u.user_uuid = :user_uuid " ;
2019-08-17 19:55:11 +02:00
$parameters [ 'domain_uuid' ] = $_SESSION [ 'user' ][ 'domain_uuid' ];
$parameters [ 'user_uuid' ] = $_SESSION [ 'user' ][ 'user_uuid' ];
2016-03-29 22:15:01 +02:00
}
2019-08-13 12:48:28 +02:00
$sql .= order_by ( $order_by , $order , 'ring_group_extension' , 'asc' );
$sql .= limit_offset ( $rows_per_page , $offset );
$database = new database ;
$result = $database -> select ( $sql , $parameters , 'all' );
unset ( $sql , $parameters );
2016-03-29 22:15:01 +02:00
2019-12-05 03:08:02 +01:00
//create token
$object = new token ;
$token = $object -> create ( '/app/ring_groups/ring_group_forward.php' );
//include header
require_once " resources/header.php " ;
//show content
echo " <div class='action_bar sub'> \n " ;
echo " <div class='heading'><b> " . $text [ 'header-ring-group-forward' ] . " </b></div> \n " ;
echo " <div class='actions'> \n " ;
if ( $is_included && $num_rows > 10 ) {
echo button :: create ([ 'type' => 'button' , 'label' => $text [ 'button-view_all' ], 'icon' => 'share-square' , 'collapse' => 'hide-xs' , 'link' => PROJECT_PATH . '/app/ring_groups/ring_group_forward.php' ]);
2016-03-29 22:15:01 +02:00
}
2019-12-05 03:08:02 +01:00
echo button :: create ([ 'type' => 'button' , 'label' => $text [ 'button-save' ], 'icon' => $_SESSION [ 'theme' ][ 'button_icon_save' ], 'collapse' => false , 'onclick' => " list_form_submit('form_list_ring_group_forward'); " ]);
2016-03-29 22:15:01 +02:00
echo " </div> \n " ;
2019-12-05 03:08:02 +01:00
echo " <div style='clear: both;'></div> \n " ;
echo " </div> \n " ;
2016-03-29 22:15:01 +02:00
2019-12-05 03:08:02 +01:00
if ( ! $is_included ) {
echo $text [ 'description-ring-group-forward' ] . " \n " ;
echo " <br /><br /> \n " ;
2016-05-29 03:50:20 +02:00
}
2013-08-15 21:16:03 +02:00
2019-12-05 03:08:02 +01:00
echo " <form id='form_list_ring_group_forward' method='post' action=' " . $validated_path . " '> \n " ;
echo " <table class='list'> \n " ;
echo " <tr class='list-header'> \n " ;
2016-01-05 16:17:20 +01:00
echo th_order_by ( 'ring_group_name' , $text [ 'label-name' ], $order_by , $order );
2016-03-04 03:01:58 +01:00
echo th_order_by ( 'ring_group_extension' , $text [ 'label-extension' ], $order_by , $order );
2019-12-05 03:08:02 +01:00
echo " <th class='shrink'> " . $text [ 'label-forwarding' ] . " </th> " ;
2016-03-29 22:15:01 +02:00
if ( ! $is_included ) {
2019-12-05 03:08:02 +01:00
echo th_order_by ( 'ring_group_description' , $text [ 'label-description' ], $order_by , $order , null , " class='hide-sm-dn' " );
2016-03-29 22:15:01 +02:00
}
2016-04-07 22:14:32 +02:00
echo " </tr> \n " ;
2013-08-15 21:16:03 +02:00
2019-08-13 12:48:28 +02:00
if ( is_array ( $result ) && @ sizeof ( $result ) != 0 ) {
2019-12-05 03:08:02 +01:00
$x = 0 ;
foreach ( $result as $row ) {
2019-08-17 19:55:11 +02:00
$onclick = " onclick= \" document.getElementById(' " . escape ( $row [ 'ring_group_uuid' ]) . " ').selectedIndex = (document.getElementById(' " . escape ( $row [ 'ring_group_uuid' ]) . " ').selectedIndex) ? 0 : 1; if (document.getElementById(' " . escape ( $row [ 'ring_group_uuid' ]) . " ').selectedIndex) { document.getElementById('destination').focus(); } \" " ;
2019-12-05 03:08:02 +01:00
echo " <tr class='list-row'> \n " ;
echo " <td " . $onclick . " > " . escape ( $row [ 'ring_group_name' ]) . " </td> \n " ;
echo " <td " . $onclick . " > " . escape ( $row [ 'ring_group_extension' ]) . " </td> \n " ;
echo " <td class='input'> " ;
echo " <input type='hidden' name='ring_groups[ " . $x . " ][ring_group_uuid]' value= \" " . escape ( $row [ " ring_group_uuid " ]) . " \" > " ;
echo " <select class='formfld' name='ring_groups[ " . $x . " ][ring_group_forward_enabled]' id=' " . escape ( $row [ 'ring_group_uuid' ]) . " ' onchange= \" this.selectedIndex ? document.getElementById('destination').focus() : null; \" > " ;
2016-03-29 22:15:01 +02:00
echo " <option value='false'> " . $text [ 'option-disabled' ] . " </option> " ;
2019-12-05 03:08:02 +01:00
echo " <option value='true' " . ( $row [ " ring_group_forward_enabled " ] == 'true' ? " selected='selected' " : null ) . " > " . $text [ 'option-enabled' ] . " </option> " ;
2016-03-29 22:15:01 +02:00
echo " </select> " ;
2019-08-17 19:55:11 +02:00
echo " <input class='formfld' style='width: 100px;' type='text' name='ring_groups[ " . $x . " ][ring_group_forward_destination]' id='destination' placeholder= \" " . $text [ 'label-forward_destination' ] . " \" maxlength='255' value= \" " . escape ( $row [ " ring_group_forward_destination " ]) . " \" > " ;
2016-03-29 22:15:01 +02:00
echo " </td> \n " ;
if ( ! $is_included ) {
2019-12-05 03:08:02 +01:00
echo " <td class='description overflow hide-sm-dn' " . $onclick . " > " . escape ( $row [ 'ring_group_description' ]) . " </td> \n " ;
2016-03-29 22:15:01 +02:00
}
2013-08-15 21:16:03 +02:00
echo " </tr> \n " ;
2019-08-17 19:55:11 +02:00
$x ++ ;
2016-03-29 22:15:01 +02:00
}
}
2019-12-05 03:08:02 +01:00
unset ( $result );
2016-03-04 03:01:58 +01:00
2019-12-05 03:08:02 +01:00
echo " </table> \n " ;
echo " <br /> \n " ;
2016-03-29 22:15:01 +02:00
if ( ! $is_included ) {
2019-12-05 03:08:02 +01:00
echo " <div align='center'> " . $paging_controls . " </div> \n " ;
2016-03-29 22:15:01 +02:00
}
2019-12-05 03:08:02 +01:00
echo " <input type='hidden' name=' " . $token [ 'name' ] . " ' value=' " . $token [ 'hash' ] . " '> \n " ;
echo " </form> \n " ;
2013-08-15 21:16:03 +02:00
//include the footer
2016-05-21 19:51:26 +02:00
if ( ! $is_included ) {
require_once " resources/footer.php " ;
}
2019-08-14 18:53:44 +02:00
2019-12-19 04:13:47 +01:00
?>