diff --git a/html/includes/forms/config-item.inc.php b/html/includes/forms/config-item.inc.php index 726756d8e..8b4bc143d 100644 --- a/html/includes/forms/config-item.inc.php +++ b/html/includes/forms/config-item.inc.php @@ -30,11 +30,13 @@ $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_user = mres($_POST['config_user']); $config_to = mres($_POST['config_to']); +$config_token = mres($_POST['config_token']); $status = 'error'; $message = 'Error with config'; -if ($action == 'remove' || $action == 'remove-slack' || $action == 'remove-hipchat' || $action == 'remove-pushover' || $action == 'remove-boxcar' || $action == 'remove-clickatell') { +if ($action == 'remove' || $action == 'remove-slack' || $action == 'remove-hipchat' || $action == 'remove-pushover' || $action == 'remove-boxcar' || $action == 'remove-clickatell' || $action == 'remove-playsms') { $config_id = mres($_POST['config_id']); if (empty($config_id)) { $message = 'No config id passed'; @@ -56,6 +58,9 @@ if ($action == 'remove' || $action == 'remove-slack' || $action == 'remove-hipch elseif ($action == 'remove-clickatell') { dbDelete('config', "`config_name` LIKE 'alert.transports.clickatell.$config_id.%'"); } + elseif ($action == 'remove-playsms') { + dbDelete('config', "`config_name` LIKE 'alert.transports.playsms.$config_id.%'"); + } $status = 'ok'; $message = 'Config item removed'; @@ -185,6 +190,37 @@ else if ($action == 'add-clickatell') { } } } +elseif ($action == 'add-playsms') { + if (empty($config_value)) { + $message = 'No PlaySMS URL provided'; + } + elseif (empty($config_user)) { + $message = 'No PlaySMS User provided'; + } + elseif (empty($config_to)) { + $message = 'No mobile numbers provided'; + } + else { + $config_id = dbInsert(array('config_name' => 'alert.transports.playsms.', 'config_value' => $config_value, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $config_value, 'config_descr' => 'PlaySMS Transport'), 'config'); + if ($config_id > 0) { + dbUpdate(array('config_name' => 'alert.transports.playsms.'.$config_id.'.url'), 'config', 'config_id=?', array($config_id)); + $additional_id['from'] = dbInsert(array('config_name' => 'alert.transports.playsms.'.$config_id.'.from', 'config_value' => $config_from, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $config_from, 'config_descr' => 'PlaySMS From'), 'config'); + $additional_id['user'] = dbInsert(array('config_name' => 'alert.transports.playsms.'.$config_id.'.user', 'config_value' => $config_user, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $config_user, 'config_descr' => 'PlaySMS User'), 'config'); + $additional_id['token'] = dbInsert(array('config_name' => 'alert.transports.playsms.'.$config_id.'.token', 'config_value' => $config_token, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $config_token, 'config_descr' => 'PlaySMS Token'), 'config'); + $status = 'ok'; + $message = 'Config item created'; + $mobiles = explode('\n', $config_to); + foreach ($mobiles as $mobile) { + if (!empty($mobile)) { + dbInsert(array('config_name' => 'alert.transports.playsms.'.$config_id.'.to', 'config_value' => $mobile, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $v, 'config_descr' => 'PlaySMS 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 18f0b5725..923ca1f7d 100644 --- a/html/pages/settings/alerting.inc.php +++ b/html/pages/settings/alerting.inc.php @@ -201,6 +201,46 @@ $no_refresh = true; + + + + +
+
+

+ PlaySMS transport +

+
+
+
+
+
+ +
+
'; +$playsms = get_config_like_name('alert.transports.playsms.%.url'); +foreach ($playsms as $item) { + $playsms_user = get_config_by_name('alert.transports.playsms.'.$item['config_id'].'.user'); + $playsms_token = get_config_by_name('alert.transports.playsms.'.$item['config_id'].'.token'); + $playsms_from = get_config_by_name('alert.transports.playsms.'.$item['config_id'].'.from'); + $to = get_config_like_name('alert.transports.playsms.'.$item['config_id'].'.%'); + $new_extra = array(); + unset($upd_extra); + foreach ($to as $number) { + $split_extra = explode('.', $number['config_name']); + if ($split_extra[4] != 'url' && $split_extra[4] != 'user' && $split_extra[4] != 'token' && $split_extra[4] != 'from') { + $new_extra[] = $number['config_value']; + } + } + $upd_extra = implode(PHP_EOL, $new_extra); + echo '
+
+ +
+ + +
+
+ +
+
+
+ +
+ + +
+
+
+ +
+ + +
+
+
+ +
+ + +
+
+
+
+ + +
+
+
'; +}//end foreach + +echo '
+
+ +
+ + +
+
+ +
+
+
+ +
+ + +
+
+
+ +
+ + +
+
+
+ +
+ + +
+
+
+
+ +
+
+
+
+
+
'; @@ -1066,7 +1216,7 @@ echo '
.clone() .removeClass('hide') .attr('id',data.config_id) - .attr('boxcar-appkey-index', itemIndex) + .attr('clickatell-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); @@ -1084,6 +1234,51 @@ echo '
}); });// End Add Clickatell config + // Add PlaySMS config + itemIndex = 0; + $("button#submit-playsms").click(function(){ + var config_value = $('#playsms_value').val(); + var config_from = $('#playsms_from').val(); + var config_user = $('#playsms_user').val(); + var config_token = $('#playsms_token').val(); + var config_to = $('#playsms_to').val(); + $.ajax({ + type: "POST", + url: "ajax_form.php", + data: {type: "config-item", action: 'add-playsms', config_group: "alerting", config_sub_group: "transports", config_to: config_to, config_value: config_value, config_from: config_from, config_user: config_user, config_token: config_token}, + dataType: "json", + success: function(data){ + if (data.status == 'ok') { + itemIndex++; + var $template = $('#playsms_template'), + $clone = $template + .clone() + .removeClass('hide') + .attr('id',data.config_id) + .attr('playsms-appkey-index', itemIndex) + .insertBefore($template); + $clone.find('[id="playsms_url"]').attr('data-config_id',data.config_id); + $clone.find('[id="del-playsms-call"]').attr('data-config_id',data.config_id); + $clone.find('[name="global-config-input"]').attr('value', config_value); + $clone.find('[id="playsms_to"]').val(config_to); + $clone.find('[id="playsms_to"]').attr('data-config_id',data.config_id); + $clone.find('[id="playsms_from"]').val(config_from); + $clone.find('[id="playsms_from"]').attr('data-config_id',data.config_id); + $clone.find('[id="playsms_token"]').val(config_token); + $clone.find('[id="playsms_token"]').attr('data-config_id',data.config_id); + $clone.find('[id="playsms_user"]').val(config_user); + $clone.find('[id="playsms_user"]').attr('data-config_id',data.config_id); + $("#new-config-playsms").modal('hide'); + } else { + $("#message").html('
' + data.message + '
'); + } + }, + error: function(){ + $("#message").html('
Error creating config item
'); + } + }); + });// End Add PlaySMS config + // Delete api config $(document).on('click', 'button[name="del-api-call"]', function(event) { var config_id = $(this).data('config_id'); @@ -1210,6 +1405,27 @@ echo '
}); });// End delete Clickatell config + // Delete PlaySMS config + $(document).on('click', 'button[name="del-playsms-call"]', function(event) { + var config_id = $(this).data('config_id'); + $.ajax({ + type: 'POST', + url: 'ajax_form.php', + data: {type: "config-item", action: 'remove-playsms', 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 PlaySMS config + $( 'select[name="global-config-select"]').change(function(event) { event.preventDefault(); var $this = $(this);