diff --git a/html/includes/forms/config-item.inc.php b/html/includes/forms/config-item.inc.php index 084c612316..726756d8e7 100644 --- a/html/includes/forms/config-item.inc.php +++ b/html/includes/forms/config-item.inc.php @@ -30,10 +30,11 @@ $config_extra = mres($_POST['config_extra']); $config_room_id = mres($_POST['config_room_id']); $config_from = mres($_POST['config_from']); $config_userkey = mres($_POST['config_userkey']); +$config_to = mres($_POST['config_to']); $status = 'error'; $message = 'Error with config'; -if ($action == 'remove' || $action == 'remove-slack' || $action == 'remove-hipchat' || $action == 'remove-pushover' || $action == 'remove-boxcar') { +if ($action == 'remove' || $action == 'remove-slack' || $action == 'remove-hipchat' || $action == 'remove-pushover' || $action == 'remove-boxcar' || $action == 'remove-clickatell') { $config_id = mres($_POST['config_id']); if (empty($config_id)) { $message = 'No config id passed'; @@ -52,6 +53,9 @@ if ($action == 'remove' || $action == 'remove-slack' || $action == 'remove-hipch elseif ($action == 'remove-boxcar') { dbDelete('config', "`config_name` LIKE 'alert.transports.boxcar.$config_id.%'"); } + elseif ($action == 'remove-clickatell') { + dbDelete('config', "`config_name` LIKE 'alert.transports.clickatell.$config_id.%'"); + } $status = 'ok'; $message = 'Config item removed'; @@ -156,6 +160,31 @@ else if ($action == 'add-boxcar') { } } } +else if ($action == 'add-clickatell') { + if (empty($config_value)) { + $message = 'No Clickatell token provided'; + } + elseif (empty($config_to)) { + $message = 'No mobile numbers provided'; + } + else { + $config_id = dbInsert(array('config_name' => 'alert.transports.clickatell.', 'config_value' => $config_value, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $config_value, 'config_descr' => 'Clickatell Transport'), 'config'); + if ($config_id > 0) { + dbUpdate(array('config_name' => 'alert.transports.clickatell.'.$config_id.'.token'), 'config', 'config_id=?', array($config_id)); + $status = 'ok'; + $message = 'Config item created'; + $mobiles = explode('\n', $config_to); + foreach ($mobiles as $mobile) { + if (!empty($mobile)) { + dbInsert(array('config_name' => 'alert.transports.clickatell.'.$config_id.'.to', 'config_value' => $mobile, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $v, 'config_descr' => 'Clickatell mobile'), 'config'); + } + } + } + else { + $message = 'Could not create config item'; + } + } +} else { if (empty($config_group) || empty($config_sub_group) || empty($config_name) || empty($config_value)) { $message = 'Missing config name or value'; diff --git a/html/pages/settings/alerting.inc.php b/html/pages/settings/alerting.inc.php index 9c763811dd..18f0b5725f 100644 --- a/html/pages/settings/alerting.inc.php +++ b/html/pages/settings/alerting.inc.php @@ -173,6 +173,34 @@ $no_refresh = true; + + + + +
+
+

+ Clickatell transport +

+
+
+
+
+
+ +
+
'; +$clickatells = get_config_like_name('alert.transports.clickatell.%.token'); +foreach ($clickatells as $clickatell) { + $to = get_config_like_name('alert.transports.clickatell.'.$clickatell['config_id'].'.to'); + $new_extra = array(); + unset($upd_extra); + foreach ($to as $number) { + $split_extra = explode('.', $number['config_name']); + if ($split_extra[4] != 'token') { + $new_extra[] = $number['config_value']; + } + } + $upd_extra = implode(PHP_EOL, $new_extra); + echo '
+
+ +
+ + +
+
+ +
+
+
+
+ + +
+
+
'; +}//end foreach + +echo '
+
+ +
+ + +
+
+ +
+
+
+
+ +
+
+
+
+
+
'; @@ -955,6 +1048,42 @@ echo '
}); });// End Add Boxcar config + // Add Clickatell config + itemIndex = 0; + $("button#submit-clickatell").click(function(){ + var config_value = $('#clickatell_value').val(); + var config_to = $('#clickatell_to').val(); + $.ajax({ + type: "POST", + url: "ajax_form.php", + data: {type: "config-item", action: 'add-clickatell', config_group: "alerting", config_sub_group: "transports", config_to: config_to, config_value: config_value}, + dataType: "json", + success: function(data){ + if (data.status == 'ok') { + itemIndex++; + var $template = $('#clickatell_token_template'), + $clone = $template + .clone() + .removeClass('hide') + .attr('id',data.config_id) + .attr('boxcar-appkey-index', itemIndex) + .insertBefore($template); + $clone.find('[id="clickatell_token"]').attr('data-config_id',data.config_id); + $clone.find('[id="del-clickatell-call"]').attr('data-config_id',data.config_id); + $clone.find('[name="global-config-input"]').attr('value', config_value); + $clone.find('[id="clickatell_to"]').val(config_to); + $clone.find('[id="clickatell_to"]').attr('data-config_id',data.config_id); + $("#new-config-clickatell").modal('hide'); + } else { + $("#message").html('
' + data.message + '
'); + } + }, + error: function(){ + $("#message").html('
Error creating config item
'); + } + }); + });// End Add Clickatell config + // Delete api config $(document).on('click', 'button[name="del-api-call"]', function(event) { var config_id = $(this).data('config_id'); @@ -1060,6 +1189,27 @@ echo '
}); });// End delete Boxcar config + // Delete Clickatell config + $(document).on('click', 'button[name="del-clickatell-call"]', function(event) { + var config_id = $(this).data('config_id'); + $.ajax({ + type: 'POST', + url: 'ajax_form.php', + data: {type: "config-item", action: 'remove-clickatell', config_id: config_id}, + dataType: "json", + success: function (data) { + if (data.status == 'ok') { + $("#"+config_id).remove(); + } else { + $("#message").html('
' + data.message + '
'); + } + }, + error: function () { + $("#message").html('
An error occurred.
'); + } + }); + });// End delete Clickatell config + $( 'select[name="global-config-select"]').change(function(event) { event.preventDefault(); var $this = $(this);