From e0f62aa5b90a5282631bdee912f28150fdba12a3 Mon Sep 17 00:00:00 2001 From: Alex <40072887+alexdcrane@users.noreply.github.com> Date: Fri, 26 Dec 2025 17:08:14 -0700 Subject: [PATCH] Display message for limits instead of hiding add and copy buttons (#7681) * Display message for limits instead of hiding add and copy buttons * Update ivr_menus.php * Update gateways.php * Update extensions.php * Update devices.php * Update call_center_queues.php * Update app_languages.php * Update voicemail_greetings.php * Update users.php * Update voicemail_greetings.php * Update call_center_queues.php --- app/call_centers/call_center_queues.php | 23 ++++++++-- app/devices/devices.php | 2 +- app/extensions/extensions.php | 4 +- app/gateways/gateways.php | 14 ++++++ app/ivr_menus/ivr_menus.php | 18 +++++++- app/ring_groups/ring_groups.php | 21 +++++++-- app/voicemail_greetings/app_languages.php | 27 +++++++++++ .../voicemail_greetings.php | 46 ++++++++++++------- core/users/users.php | 18 +++++++- 9 files changed, 144 insertions(+), 29 deletions(-) diff --git a/app/call_centers/call_center_queues.php b/app/call_centers/call_center_queues.php index f5a6525b01..bb0731d2e3 100644 --- a/app/call_centers/call_center_queues.php +++ b/app/call_centers/call_center_queues.php @@ -17,7 +17,7 @@ The Initial Developer of the Original Code is Mark J Crane - Portions created by the Initial Developer are Copyright (C) 2008-2024 + Portions created by the Initial Developer are Copyright (C) 2008-2025 the Initial Developer. All Rights Reserved. Contributor(s): @@ -55,6 +55,21 @@ $call_center_queues = $_POST['call_center_queues']; } +//get total call center queues count from the database, check limit, if defined + if (!empty($action) && $action == 'copy' && !empty($settings->get('limit','call_center_queues', ''))) { + $sql = "select count(*) from v_call_center_queues "; + $sql .= "where domain_uuid = :domain_uuid "; + $parameters['domain_uuid'] = $domain_uuid; + $total_call_center_queues = $database->select($sql, $parameters, 'column'); + unset($sql, $parameters); + + if ($total_call_center_queues >= $settings->get('limit','call_center_queues', 0)) { + message::add($text['message-maximum_queues'].' '.$settings->get('limit','call_center_queues', ''), 'negative'); + header('Location: call_center_queues.php'); + return; + } + } + //process the http post data by action if (!empty($action) && is_array($call_center_queues) && @sizeof($call_center_queues) != 0) { switch ($action) { @@ -144,11 +159,11 @@ echo button::create(['type'=>'button','label'=>$text['button-wallboard'],'icon'=>'th','link'=>PROJECT_PATH.'/app/call_center_wallboard/call_center_wallboard.php']); } $margin_left = permission_exists('call_center_agent_view') || permission_exists('call_center_wallboard') ? 'margin-left: 15px;' : null; - if (permission_exists('call_center_queue_add') && (!is_numeric($settings->get('limit', 'call_center_queues') ?? '') || $num_rows <= $settings->get('limit', 'call_center_queues'))) { + if (permission_exists('call_center_queue_add')) { echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$settings->get('theme', 'button_icon_add'),'id'=>'btn_add','style'=>$margin_left,'link'=>'call_center_queue_edit.php']); unset($margin_left); } - if (permission_exists('call_center_queue_add') && $result && (!is_numeric($settings->get('limit', 'call_center_queues') ?? '') || $num_rows <= $settings->get('limit', 'call_center_queues'))) { + if (permission_exists('call_center_queue_add') && $result) { echo button::create(['type'=>'button','label'=>$text['button-copy'],'icon'=>$settings->get('theme', 'button_icon_copy'),'id'=>'btn_copy','name'=>'btn_copy','style'=>'display: none; '.!empty($margin_left),'onclick'=>"modal_open('modal-copy','btn_copy');"]); unset($margin_left); } @@ -176,7 +191,7 @@ echo "
\n"; echo "\n"; - if (permission_exists('call_center_queue_add') && $result && (!is_numeric($settings->get('limit', 'call_center_queues') ?? '') || $num_rows <= $settings->get('limit', 'call_center_queues'))) { + if (permission_exists('call_center_queue_add') && $result) { echo modal::create(['id'=>'modal-copy','type'=>'copy','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_copy','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('copy'); list_form_submit('form_list');"])]); } if (permission_exists('call_center_queue_delete') && $result) { diff --git a/app/devices/devices.php b/app/devices/devices.php index bd54d0b01f..2121489016 100644 --- a/app/devices/devices.php +++ b/app/devices/devices.php @@ -326,7 +326,7 @@ echo button::create(['type'=>'button','label'=>$text['button-profiles'],'icon'=>'clone','link'=>'device_profiles.php']); } $margin_left = permission_exists('device_import') || permission_exists('device_export') || permission_exists('device_vendor_view') || permission_exists('device_profile_view') ? "margin-left: 15px;" : null; - if (permission_exists('device_add') && (empty($settings->get('limit', 'devices')) || ($total_devices < $settings->get('limit', 'devices')))) { + if (permission_exists('device_add')) { echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$settings->get('theme', 'button_icon_add'),'id'=>'btn_add','style'=>$margin_left,'link'=>'device_edit.php']); unset($margin_left); } diff --git a/app/extensions/extensions.php b/app/extensions/extensions.php index 71fb4c7876..a4ba602119 100644 --- a/app/extensions/extensions.php +++ b/app/extensions/extensions.php @@ -17,7 +17,7 @@ The Initial Developer of the Original Code is Mark J Crane - Portions created by the Initial Developer are Copyright (C) 2008-2024 + Portions created by the Initial Developer are Copyright (C) 2008-2025 the Initial Developer. All Rights Reserved. Contributor(s): @@ -292,7 +292,7 @@ echo button::create(['type'=>'button','label'=>$text['button-export'],'icon'=>$settings->get('theme', 'button_icon_export'),'link'=>'extension_download.php']); } $margin_left = permission_exists('extension_import') || permission_exists('extension_export') ? "margin-left: 15px;" : null; - if (permission_exists('extension_add') && (empty($settings->get('limit', 'extensions', 0)) || $total_extensions < $settings->get('limit', 'extensions'))) { + if (permission_exists('extension_add')) { echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$settings->get('theme', 'button_icon_add'),'id'=>'btn_add','style'=>($margin_left ?? ''),'link'=>'extension_edit.php']); unset($margin_left); } diff --git a/app/gateways/gateways.php b/app/gateways/gateways.php index d690892e53..42c0acb627 100644 --- a/app/gateways/gateways.php +++ b/app/gateways/gateways.php @@ -46,6 +46,20 @@ $gateways = $_POST['gateways'] ?? ''; } +//get total gateway count from the database, check limit, if defined + if (!empty($action) && $action == 'copy' && !empty($settings->get('limit', 'gateways'))) { + $sql = "select count(gateway_uuid) from v_gateways "; + $sql .= "where (domain_uuid = :domain_uuid ".(permission_exists('gateway_domain') ? " or domain_uuid is null " : null).") "; + $parameters['domain_uuid'] = $_SESSION['domain_uuid']; + $total_gateways = $database->select($sql, $parameters, 'column'); + unset($sql, $parameters); + if ($total_gateways >= $settings->get('limit', 'gateways')) { + message::add($text['message-maximum_gateways'].' '.$settings->get('limit', 'gateways'), 'negative'); + header('Location: gateways.php'); + exit; + } + } + //process the http post data by action if (!empty($action) && !empty($gateways)) { switch ($action) { diff --git a/app/ivr_menus/ivr_menus.php b/app/ivr_menus/ivr_menus.php index c41c512f21..1f070aa946 100644 --- a/app/ivr_menus/ivr_menus.php +++ b/app/ivr_menus/ivr_menus.php @@ -51,6 +51,20 @@ $ivr_menus = $_POST['ivr_menus']; } +//get total ivr menu count from the database, check limit, if defined + if (!empty($settings->get('limit', 'ivr_menus'))) { + $sql = "select count(*) as num_rows from v_ivr_menus where domain_uuid = :domain_uuid "; + $parameters['domain_uuid'] = $domain_uuid; + $total_ivr_menus = $database->select($sql, $parameters, 'column'); + unset($sql, $parameters); + + if ($action == 'copy' && $total_ivr_menus >= $settings->get('limit', 'ivr_menus')) { + message::add($text['message-maximum_ivr_menus'].' '.$settings->get('limit', 'ivr_menus'), 'negative'); + header('Location: ivr_menus.php'); + exit; + } + } + //process the http post data by action if (!empty($action) && is_array($ivr_menus) && @sizeof($ivr_menus) != 0) { switch ($action) { @@ -163,10 +177,10 @@ echo "
\n"; echo "
".$text['title-ivr_menus']."
".number_format($num_rows)."
\n"; echo "
\n"; - if (permission_exists('ivr_menu_add') && (empty($settings->get('limit', 'ivr_menus')) || $num_rows < $settings->get('limit', 'ivr_menus'))) { + if (permission_exists('ivr_menu_add')) { echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$settings->get('theme', 'button_icon_add'),'id'=>'btn_add','link'=>'ivr_menu_edit.php']); } - if (permission_exists('ivr_menu_add') && $ivr_menus && (empty($settings->get('limit', 'ivr_menus')) || $num_rows < $settings->get('limit', 'ivr_menus'))) { + if (permission_exists('ivr_menu_add')) { echo button::create(['type'=>'button','label'=>$text['button-copy'],'icon'=>$settings->get('theme', 'button_icon_copy'),'id'=>'btn_copy','name'=>'btn_copy','style'=>'display: none;','onclick'=>"modal_open('modal-copy','btn_copy');"]); } if (permission_exists('ivr_menu_edit') && $ivr_menus) { diff --git a/app/ring_groups/ring_groups.php b/app/ring_groups/ring_groups.php index b1c47036a6..433b5fb32d 100644 --- a/app/ring_groups/ring_groups.php +++ b/app/ring_groups/ring_groups.php @@ -53,6 +53,21 @@ $ring_groups = $_POST['ring_groups']; } +//get total ring group count from the database, check limit, if defined + if (!empty($action) && $action == 'copy' && $settings->get('limit', 'ring_groups', '') ?? '') { + $sql = "select count(*) from v_ring_groups "; + $sql .= "where domain_uuid = :domain_uuid "; + $parameters['domain_uuid'] = $domain_uuid; + $total_ring_groups = $database->select($sql, $parameters, 'column'); + unset($sql, $parameters); + + if (is_numeric($settings->get('limit', 'ring_groups', '')) && $total_ring_groups >= $settings->get('limit', 'ring_groups', '')) { + message::add($text['message-maximum_ring_groups'].' '.$settings->get('limit', 'ring_groups', ''), 'negative'); + header('Location: ring_groups.php'); + exit; + } + } + //process the http post data by action if (!empty($action) && !empty($ring_groups)) { switch ($action) { @@ -180,10 +195,10 @@ echo "
\n"; echo "
".$text['title-ring_groups']."
".number_format($num_rows)."
\n"; echo "
\n"; - if (permission_exists('ring_group_add') && (empty($settings->get('limit', 'ring_groups', 0)) || ($total_ring_groups < $settings->get('limit', 'ring_groups')))) { + if (permission_exists('ring_group_add')) { echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$settings->get('theme', 'button_icon_add'),'id'=>'btn_add','link'=>'ring_group_edit.php']); } - if (permission_exists('ring_group_add') && $ring_groups && (empty($settings->get('limit', 'ring_groups', 0)) || ($total_ring_groups < $settings->get('limit', 'ring_groups')))) { + if (permission_exists('ring_group_add') && $ring_groups) { echo button::create(['type'=>'button','label'=>$text['button-copy'],'icon'=>$settings->get('theme', 'button_icon_copy'),'id'=>'btn_copy','name'=>'btn_copy','style'=>'display: none;','onclick'=>"modal_open('modal-copy','btn_copy');"]); } if (permission_exists('ring_group_edit') && $ring_groups) { @@ -212,7 +227,7 @@ echo "
\n"; echo "
\n"; - if (permission_exists('ring_group_add') && $ring_groups && (empty($settings->get('limit', 'ring_groups', 0)) || ($total_ring_groups < $settings->get('limit', 'ring_groups')))) { + if (permission_exists('ring_group_add') && $ring_groups) { echo modal::create(['id'=>'modal-copy','type'=>'copy','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_copy','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('copy'); list_form_submit('form_list');"])]); } if (permission_exists('ring_group_edit') && $ring_groups) { diff --git a/app/voicemail_greetings/app_languages.php b/app/voicemail_greetings/app_languages.php index 9a227e121b..49f3f19022 100644 --- a/app/voicemail_greetings/app_languages.php +++ b/app/voicemail_greetings/app_languages.php @@ -216,6 +216,33 @@ $text['message-greeting_created']['zh-cn'] = "问候已创建"; $text['message-greeting_created']['ja-jp'] = "挨拶が作成されました"; $text['message-greeting_created']['ko-kr'] = "인사말이 생성되었습니다"; +$text['message-maximum_voicemail_greetings']['en-us'] = "Maximum Voicemail Greetings:"; +$text['message-maximum_voicemail_greetings']['en-gb'] = "Maximum Voicemail Greetings:"; +$text['message-maximum_voicemail_greetings']['ar-eg'] = "الترحيبات الأقصى للمصوات المرئية:"; +$text['message-maximum_voicemail_greetings']['de-at'] = "Maximale Anrufbeantworter-Begrüßungen:"; +$text['message-maximum_voicemail_greetings']['de-ch'] = "Maximale Anrufbeantworter-Begrüßungen:"; +$text['message-maximum_voicemail_greetings']['de-de'] = "Maximale Anrufbeantworter-Begrüßungen:"; +$text['message-maximum_voicemail_greetings']['el-gr'] = "Μέγιστες Καλωσήρχεστε στον υπεύθυνο κλήσημα:"; +$text['message-maximum_voicemail_greetings']['es-cl'] = "Saludos Máximos de Correo de Voz:"; +$text['message-maximum_voicemail_greetings']['es-mx'] = "Saludos Máximos de Correo de Voz:"; +$text['message-maximum_voicemail_greetings']['fr-ca'] = "Messages accueillants max pour messagerie vocale:"; +$text['message-maximum_voicemail_greetings']['fr-fr'] = "Messages accueillants max pour messagerie vocale:"; +$text['message-maximum_voicemail_greetings']['he-il'] = "ברותחן קוליות מקסימליים:"; +$text['message-maximum_voicemail_greetings']['it-it'] = "Saluti di Voicemail Massimi:"; +$text['message-maximum_voicemail_greetings']['ka-ge'] = "აკმაყსი ტელეფონური პასხის გრეეტინგები:"; +$text['message-maximum_voicemail_greetings']['nl-nl'] = "Maximale Voicemail Groetjes:"; +$text['message-maximum_voicemail_greetings']['pl-pl'] = "Maksymalne powitania poczty głosowej:"; +$text['message-maximum_voicemail_greetings']['pt-br'] = "Cumprimentos Máximos da Caixa Postal de Voz:"; +$text['message-maximum_voicemail_greetings']['pt-pt'] = "Cumprimentos Máximos da Mensagem de Voz:"; +$text['message-maximum_voicemail_greetings']['ro-ro'] = "Salutări maxime pentru mesajele vocale:"; +$text['message-maximum_voicemail_greetings']['ru-ru'] = "Максимальное количество приветственных сообщений голосовой почты:"; +$text['message-maximum_voicemail_greetings']['sv-se'] = "Maximalt antal hälsningsmeddelanden för röstbrevlåda:"; +$text['message-maximum_voicemail_greetings']['uk-ua'] = "Максимальна кількість привітань голосової пошти:"; +$text['message-maximum_voicemail_greetings']['tr-tr'] = "Maksimum Sesli Mesaj Selamlamaları:"; +$text['message-maximum_voicemail_greetings']['zh-cn'] = "最大语音留言问候数:"; +$text['message-maximum_voicemail_greetings']['ja-jp'] = "ボイスメールの最大挨拶数:"; +$text['message-maximum_voicemail_greetings']['ko-kr'] = "최대 음성메일 인사말 수:"; + $text['label-tools']['en-us'] = "Tools"; $text['label-tools']['en-gb'] = "Tools"; $text['label-tools']['ar-eg'] = "أدوات"; diff --git a/app/voicemail_greetings/voicemail_greetings.php b/app/voicemail_greetings/voicemail_greetings.php index 3863d05ee8..436cfecf00 100644 --- a/app/voicemail_greetings/voicemail_greetings.php +++ b/app/voicemail_greetings/voicemail_greetings.php @@ -53,7 +53,7 @@ $order = $_GET["order"] ?? ''; //set the back button url - $_SESSION['back'][$_SERVER['PHP_SELF']] = !empty($_GET['back']) ? urldecode($_GET['back']) : $_SESSION['back'][$_SERVER['PHP_SELF']]; + $_SESSION['back'][$_SERVER['PHP_SELF']] = !empty($_GET['back']) ? urldecode($_GET['back']) : $_SESSION['back'][$_SERVER['PHP_SELF']] ?? ''; //define order by default if ($order_by == '') { @@ -158,6 +158,13 @@ exit; } +//greeting limit + if (!empty($_POST['limit_reached']) && $_POST['limit_reached'] == 'true'){ + message::add($text['message-maximum_voicemail_greetings'].' 9', 'negative'); + header('Location: voicemail_greetings.php?id='.urlencode($voicemail_id)); + exit; + } + //upload the greeting if (!empty($_POST['a']) && $_POST['a'] == "upload" && permission_exists('voicemail_greeting_upload') && $_POST['type'] == 'rec' && is_uploaded_file($_FILES['file']['tmp_name'])) { @@ -182,12 +189,12 @@ //find the next available greeting id starting at 1 $greeting_id = 1; - while (true) { + for ($i = 1; $i <= 9; $i++) { $found_existing_file = false; //check for wav, mp3, and ogg files with the current greeting id foreach ($allowed_extensions as $extension) { - $potential_file_name = "greeting_{$greeting_id}.{$extension}"; + $potential_file_name = "greeting_{$i}.{$extension}"; if (file_exists($greeting_dir . '/' . $potential_file_name)) { $found_existing_file = true; break; @@ -195,10 +202,10 @@ } if (!$found_existing_file) { + //found an available greeting id + $greeting_id = $i; break; } - - $greeting_id++; } //set the greeting file name @@ -363,24 +370,31 @@ echo "
\n"; echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$settings->get('theme', 'button_icon_back'),'id'=>'btn_back','link'=>$_SESSION['back'][$_SERVER['PHP_SELF']]]); $margin_left = false; - if (permission_exists('voicemail_greeting_add') && is_array($greetings) && @sizeof($greetings) < 9 && $speech_enabled == 'true') { + if (permission_exists('voicemail_greeting_add') && is_array($greetings) && $speech_enabled == 'true') { echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$settings->get('theme', 'button_icon_add'),'id'=>'btn_add','style'=>'margin-left: 15px;','link'=>'voicemail_greeting_edit.php?voicemail_id='.urlencode($voicemail_id)]); $margin_left = true; } if (permission_exists('voicemail_greeting_upload') && is_array($greetings) && @sizeof($greetings) < 9) { - echo "
\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; + echo " \n"; echo button::create(['type'=>'button','label'=>$text['button-upload'],'icon'=>$settings->get('theme', 'button_icon_add'),'id'=>'btn_upload','style'=>(!$margin_left ? 'margin-left: 15px;' : null),'onclick'=>"$(this).fadeOut(250, function(){ $('span#form_upload').fadeIn(250); document.getElementById('ulfile').click(); });"]); - echo "
\n"; + echo " \n"; + $margin_left = true; + } + else if (permission_exists('voicemail_greeting_upload') && is_array($greetings) && @sizeof($greetings) >= 9) { + echo "
\n"; + echo " \n"; + echo button::create(['type'=>'submit','label'=>$text['button-upload'],'icon'=>$settings->get('theme', 'button_icon_add')]); + echo "
\n"; $margin_left = true; } if (permission_exists('voicemail_greeting_delete') && $greetings) { diff --git a/core/users/users.php b/core/users/users.php index 473d08e196..161513da4c 100644 --- a/core/users/users.php +++ b/core/users/users.php @@ -17,7 +17,7 @@ The Initial Developer of the Original Code is Mark J Crane - Portions created by the Initial Developer are Copyright (C) 2008-2024 + Portions created by the Initial Developer are Copyright (C) 2008-2025 the Initial Developer. All Rights Reserved. Contributor(s): @@ -46,6 +46,22 @@ $users = $_POST['users'] ?? ''; } +//get total user count from the database, check limit, if defined + if (permission_exists('user_add') && !empty($action) && $action == 'copy' && !empty($settings->get('limit', 'users'))) { + $sql = "select count(*) "; + $sql .= "from v_users "; + $sql .= "where domain_uuid = :domain_uuid "; + $parameters['domain_uuid'] = $_SESSION['domain_uuid']; + $num_rows = $database->select($sql, $parameters, 'column'); + unset($sql, $parameters); + + if ($num_rows >= $settings->get('limit', 'users')) { + message::add($text['message-maximum_users'].' '.$settings->get('limit', 'users'), 'negative'); + header('Location: users.php'); + exit; + } + } + //process the http post data by action if (!empty($action) && is_array($users) && @sizeof($users) != 0) { switch ($action) {