| 
									
										
										
										
											2015-05-25 21:51:27 +01:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* | 
					
						
							|  |  |  |  * LibreNMS | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Copyright (c) 2014 Neil Lathwood <https://github.com/laf/ http://www.lathwood.co.uk/fa> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software: you can redistribute it and/or modify it | 
					
						
							|  |  |  |  * under the terms of the GNU General Public License as published by the | 
					
						
							|  |  |  |  * Free Software Foundation, either version 3 of the License, or (at your | 
					
						
							|  |  |  |  * option) any later version.  Please see LICENSE.txt at the top level of | 
					
						
							|  |  |  |  * the source code distribution for details. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  | if (is_admin() === false) { | 
					
						
							|  |  |  |     $response = array( | 
					
						
							|  |  |  |         'status'  => 'error', | 
					
						
							|  |  |  |         'message' => 'Need to be admin', | 
					
						
							|  |  |  |     ); | 
					
						
							| 
									
										
										
										
											2015-05-25 21:51:27 +01:00
										 |  |  |     echo _json_encode($response); | 
					
						
							|  |  |  |     exit; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  | $action           = mres($_POST['action']); | 
					
						
							|  |  |  | $config_group     = mres($_POST['config_group']); | 
					
						
							| 
									
										
										
										
											2015-05-25 21:51:27 +01:00
										 |  |  | $config_sub_group = mres($_POST['config_sub_group']); | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  | $config_name      = mres($_POST['config_name']); | 
					
						
							|  |  |  | $config_value     = mres($_POST['config_value']); | 
					
						
							|  |  |  | $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']); | 
					
						
							| 
									
										
										
										
											2015-11-16 10:40:09 -08:00
										 |  |  | $config_user      = mres($_POST['config_user']); | 
					
						
							| 
									
										
										
										
											2015-11-16 08:56:46 -08:00
										 |  |  | $config_to        = mres($_POST['config_to']); | 
					
						
							| 
									
										
										
										
											2015-11-16 10:40:09 -08:00
										 |  |  | $config_token     = mres($_POST['config_token']); | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  | $status           = 'error'; | 
					
						
							|  |  |  | $message          = 'Error with config'; | 
					
						
							| 
									
										
										
										
											2015-05-25 21:51:27 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-16 10:40:09 -08:00
										 |  |  | if ($action == 'remove' || $action == 'remove-slack' || $action == 'remove-hipchat' || $action == 'remove-pushover' || $action == 'remove-boxcar' || $action == 'remove-clickatell' || $action == 'remove-playsms') { | 
					
						
							| 
									
										
										
										
											2015-05-25 21:51:27 +01:00
										 |  |  |     $config_id = mres($_POST['config_id']); | 
					
						
							|  |  |  |     if (empty($config_id)) { | 
					
						
							|  |  |  |         $message = 'No config id passed'; | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							| 
									
										
										
										
											2015-05-25 21:51:27 +01:00
										 |  |  |         if (dbDelete('config', '`config_id`=?', array($config_id))) { | 
					
						
							|  |  |  |             if ($action == 'remove-slack') { | 
					
						
							|  |  |  |                 dbDelete('config', "`config_name` LIKE 'alert.transports.slack.$config_id.%'"); | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  |             } | 
					
						
							|  |  |  |             else if ($action == 'remove-hipchat') { | 
					
						
							| 
									
										
										
										
											2015-05-25 21:51:27 +01:00
										 |  |  |                 dbDelete('config', "`config_name` LIKE 'alert.transports.hipchat.$config_id.%'"); | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  |             } | 
					
						
							|  |  |  |             else if ($action == 'remove-pushover') { | 
					
						
							| 
									
										
										
										
											2015-06-20 12:18:37 +01:00
										 |  |  |                 dbDelete('config', "`config_name` LIKE 'alert.transports.pushover.$config_id.%'"); | 
					
						
							| 
									
										
										
										
											2015-05-25 21:51:27 +01:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2015-07-19 21:13:06 +01:00
										 |  |  |             elseif ($action == 'remove-boxcar') { | 
					
						
							|  |  |  |                 dbDelete('config', "`config_name` LIKE 'alert.transports.boxcar.$config_id.%'"); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2015-11-16 08:56:46 -08:00
										 |  |  |             elseif ($action == 'remove-clickatell') { | 
					
						
							|  |  |  |                 dbDelete('config', "`config_name` LIKE 'alert.transports.clickatell.$config_id.%'"); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2015-11-16 10:40:09 -08:00
										 |  |  |             elseif ($action == 'remove-playsms') { | 
					
						
							|  |  |  |                 dbDelete('config', "`config_name` LIKE 'alert.transports.playsms.$config_id.%'"); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |             $status  = 'ok'; | 
					
						
							| 
									
										
										
										
											2015-05-25 21:51:27 +01:00
										 |  |  |             $message = 'Config item removed'; | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							| 
									
										
										
										
											2015-05-25 21:51:27 +01:00
										 |  |  |             $message = 'General error, could not remove config'; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  | } | 
					
						
							|  |  |  | else if ($action == 'add-slack') { | 
					
						
							| 
									
										
										
										
											2015-05-25 21:51:27 +01:00
										 |  |  |     if (empty($config_value)) { | 
					
						
							|  |  |  |         $message = 'No Slack url provided'; | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |         $config_id = dbInsert(array('config_name' => 'alert.transports.slack.', 'config_value' => $config_value, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $config_value, 'config_descr' => 'Slack Transport'), 'config'); | 
					
						
							| 
									
										
										
										
											2015-05-25 21:51:27 +01:00
										 |  |  |         if ($config_id > 0) { | 
					
						
							|  |  |  |             dbUpdate(array('config_name' => 'alert.transports.slack.'.$config_id.'.url'), 'config', 'config_id=?', array($config_id)); | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  |             $status  = 'ok'; | 
					
						
							| 
									
										
										
										
											2015-05-25 21:51:27 +01:00
										 |  |  |             $message = 'Config item created'; | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  |             $extras  = explode('\n', $config_extra); | 
					
						
							| 
									
										
										
										
											2015-05-25 21:51:27 +01:00
										 |  |  |             foreach ($extras as $option) { | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  |                 list($k,$v) = explode('=', $option, 2); | 
					
						
							| 
									
										
										
										
											2015-05-25 21:51:27 +01:00
										 |  |  |                 if (!empty($k) || !empty($v)) { | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  |                     dbInsert(array('config_name' => 'alert.transports.slack.'.$config_id.'.'.$k, 'config_value' => $v, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $v, 'config_descr' => 'Slack Transport'), 'config'); | 
					
						
							| 
									
										
										
										
											2015-05-25 21:51:27 +01:00
										 |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							| 
									
										
										
										
											2015-05-25 21:51:27 +01:00
										 |  |  |             $message = 'Could not create config item'; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  | } | 
					
						
							|  |  |  | else if ($action == 'add-hipchat') { | 
					
						
							| 
									
										
										
										
											2015-05-25 21:51:27 +01:00
										 |  |  |     if (empty($config_value) || empty($config_room_id) || empty($config_from)) { | 
					
						
							|  |  |  |         $message = 'No hipchat url, room id or from provided'; | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |         $config_id = dbInsert(array('config_name' => 'alert.transports.hipchat.', 'config_value' => $config_value, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $config_value, 'config_descr' => 'Hipchat Transport'), 'config'); | 
					
						
							| 
									
										
										
										
											2015-05-25 21:51:27 +01:00
										 |  |  |         if ($config_id > 0) { | 
					
						
							|  |  |  |             dbUpdate(array('config_name' => 'alert.transports.hipchat.'.$config_id.'.url'), 'config', 'config_id=?', array($config_id)); | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  |             $additional_id['room_id'] = dbInsert(array('config_name' => 'alert.transports.hipchat.'.$config_id.'.room_id', 'config_value' => $config_room_id, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $config_room_id, 'config_descr' => 'Hipchat URL'), 'config'); | 
					
						
							|  |  |  |             $additional_id['from']    = dbInsert(array('config_name' => 'alert.transports.hipchat.'.$config_id.'.from', 'config_value' => $config_from, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $config_from, 'config_descr' => 'Hipchat From'), 'config'); | 
					
						
							|  |  |  |             $status                   = 'ok'; | 
					
						
							|  |  |  |             $message                  = 'Config item created'; | 
					
						
							|  |  |  |             $extras                   = explode('\n', $config_extra); | 
					
						
							| 
									
										
										
										
											2015-05-25 21:51:27 +01:00
										 |  |  |             foreach ($extras as $option) { | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  |                 list($k,$v) = explode('=', $option, 2); | 
					
						
							| 
									
										
										
										
											2015-05-25 21:51:27 +01:00
										 |  |  |                 if (!empty($k) || !empty($v)) { | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  |                     dbInsert(array('config_name' => 'alert.transports.hipchat.'.$config_id.'.'.$k, 'config_value' => $v, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $v, 'config_descr' => 'Hipchat '.$v), 'config'); | 
					
						
							| 
									
										
										
										
											2015-05-25 21:51:27 +01:00
										 |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							| 
									
										
										
										
											2015-05-25 21:51:27 +01:00
										 |  |  |             $message = 'Could not create config item'; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  |     }//end if
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | else if ($action == 'add-pushover') { | 
					
						
							| 
									
										
										
										
											2015-06-20 12:18:37 +01:00
										 |  |  |     if (empty($config_value) || empty($config_userkey)) { | 
					
						
							|  |  |  |         $message = 'No pushover appkey or userkey provided'; | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |         $config_id = dbInsert(array('config_name' => 'alert.transports.pushover.', 'config_value' => $config_value, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $config_value, 'config_descr' => 'Pushover Transport'), 'config'); | 
					
						
							| 
									
										
										
										
											2015-06-20 12:18:37 +01:00
										 |  |  |         if ($config_id > 0) { | 
					
						
							|  |  |  |             dbUpdate(array('config_name' => 'alert.transports.pushover.'.$config_id.'.appkey'), 'config', 'config_id=?', array($config_id)); | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  |             $additional_id['userkey'] = dbInsert(array('config_name' => 'alert.transports.pushover.'.$config_id.'.userkey', 'config_value' => $config_userkey, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $config_userkey, 'config_descr' => 'Pushver Userkey'), 'config'); | 
					
						
							|  |  |  |             $status                   = 'ok'; | 
					
						
							|  |  |  |             $message                  = 'Config item created'; | 
					
						
							|  |  |  |             $extras                   = explode('\n', $config_extra); | 
					
						
							| 
									
										
										
										
											2015-06-20 12:18:37 +01:00
										 |  |  |             foreach ($extras as $option) { | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  |                 list($k,$v) = explode('=', $option, 2); | 
					
						
							| 
									
										
										
										
											2015-06-20 12:18:37 +01:00
										 |  |  |                 if (!empty($k) || !empty($v)) { | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  |                     dbInsert(array('config_name' => 'alert.transports.pushover.'.$config_id.'.'.$k, 'config_value' => $v, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $v, 'config_descr' => 'Pushover '.$v), 'config'); | 
					
						
							| 
									
										
										
										
											2015-06-20 12:18:37 +01:00
										 |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							| 
									
										
										
										
											2015-06-20 12:18:37 +01:00
										 |  |  |             $message = 'Could not create config item'; | 
					
						
							| 
									
										
										
										
											2015-07-19 21:13:06 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | else if ($action == 'add-boxcar') { | 
					
						
							|  |  |  |     if (empty($config_value)) { | 
					
						
							|  |  |  |         $message = 'No Boxcar access token provided'; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |         $config_id = dbInsert(array('config_name' => 'alert.transports.boxcar.', 'config_value' => $config_value, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $config_value, 'config_descr' => 'Boxcar Transport'), 'config'); | 
					
						
							|  |  |  |         if ($config_id > 0) { | 
					
						
							|  |  |  |             dbUpdate(array('config_name' => 'alert.transports.boxcar.'.$config_id.'.access_token'), 'config', 'config_id=?', array($config_id)); | 
					
						
							|  |  |  |             $status                   = 'ok'; | 
					
						
							|  |  |  |             $message                  = 'Config item created'; | 
					
						
							|  |  |  |             $extras                   = explode('\n', $config_extra); | 
					
						
							|  |  |  |             foreach ($extras as $option) { | 
					
						
							|  |  |  |                 list($k,$v) = explode('=', $option, 2); | 
					
						
							|  |  |  |                 if (!empty($k) || !empty($v)) { | 
					
						
							|  |  |  |                     dbInsert(array('config_name' => 'alert.transports.boxcar.'.$config_id.'.'.$k, 'config_value' => $v, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $v, 'config_descr' => 'Boxcar '.$v), 'config'); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							|  |  |  |             $message = 'Could not create config item'; | 
					
						
							| 
									
										
										
										
											2015-11-16 08:56:46 -08:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 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); | 
					
						
							| 
									
										
										
										
											2015-11-16 19:22:28 -08:00
										 |  |  |             $x=0; | 
					
						
							| 
									
										
										
										
											2015-11-16 08:56:46 -08:00
										 |  |  |             foreach ($mobiles as $mobile) { | 
					
						
							|  |  |  |                 if (!empty($mobile)) { | 
					
						
							| 
									
										
										
										
											2015-11-16 19:22:28 -08:00
										 |  |  |                     dbInsert(array('config_name' => 'alert.transports.clickatell.'.$config_id.'.to.'.$x, 'config_value' => $mobile, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $v, 'config_descr' => 'Clickatell mobile'), 'config'); | 
					
						
							|  |  |  |                     $x++; | 
					
						
							| 
									
										
										
										
											2015-11-16 08:56:46 -08:00
										 |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							|  |  |  |             $message = 'Could not create config item'; | 
					
						
							| 
									
										
										
										
											2015-11-16 10:40:09 -08:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 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); | 
					
						
							| 
									
										
										
										
											2015-11-16 19:22:28 -08:00
										 |  |  |             $x=0; | 
					
						
							| 
									
										
										
										
											2015-11-16 10:40:09 -08:00
										 |  |  |             foreach ($mobiles as $mobile) { | 
					
						
							|  |  |  |                 if (!empty($mobile)) { | 
					
						
							| 
									
										
										
										
											2015-11-16 19:22:28 -08:00
										 |  |  |                     dbInsert(array('config_name' => 'alert.transports.playsms.'.$config_id.'.to.'.$x, 'config_value' => $mobile, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $v, 'config_descr' => 'PlaySMS mobile'), 'config'); | 
					
						
							|  |  |  |                     $x++; | 
					
						
							| 
									
										
										
										
											2015-11-16 10:40:09 -08:00
										 |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							|  |  |  |             $message = 'Could not create config item'; | 
					
						
							| 
									
										
										
										
											2015-06-20 12:18:37 +01:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  | } | 
					
						
							|  |  |  | else { | 
					
						
							| 
									
										
										
										
											2015-05-25 21:51:27 +01:00
										 |  |  |     if (empty($config_group) || empty($config_sub_group) || empty($config_name) || empty($config_value)) { | 
					
						
							|  |  |  |         $message = 'Missing config name or value'; | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |         $config_id = dbInsert(array('config_name' => $config_name, 'config_value' => $config_value, 'config_group' => $config_group, 'config_sub_group' => $config_sub_group, 'config_default' => $config_value, 'config_descr' => 'API Transport'), 'config'); | 
					
						
							| 
									
										
										
										
											2015-05-25 21:51:27 +01:00
										 |  |  |         if ($config_id > 0) { | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  |             dbUpdate(array('config_name' => $config_name.$config_id), 'config', 'config_id=?', array($config_id)); | 
					
						
							|  |  |  |             $status  = 'ok'; | 
					
						
							| 
									
										
										
										
											2015-05-25 21:51:27 +01:00
										 |  |  |             $message = 'Config item created'; | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							| 
									
										
										
										
											2015-05-25 21:51:27 +01:00
										 |  |  |             $message = 'Could not create config item'; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  | }//end if
 | 
					
						
							| 
									
										
										
										
											2015-05-25 21:51:27 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-13 20:10:26 +02:00
										 |  |  | $response = array( | 
					
						
							|  |  |  |     'status'        => $status, | 
					
						
							|  |  |  |     'message'       => $message, | 
					
						
							|  |  |  |     'config_id'     => $config_id, | 
					
						
							|  |  |  |     'additional_id' => $additional_id, | 
					
						
							|  |  |  | ); | 
					
						
							| 
									
										
										
										
											2015-05-25 21:51:27 +01:00
										 |  |  | echo _json_encode($response); |