| 
									
										
										
										
											2024-08-12 11:12:24 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-18 19:12:45 +00:00
										 |  |  | $action = $_REQUEST['action'] ?? ''; | 
					
						
							| 
									
										
										
										
											2024-09-04 09:53:02 +00:00
										 |  |  | require '../app/classes/config.php'; | 
					
						
							| 
									
										
										
										
											2024-08-18 19:12:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-28 09:59:13 +00:00
										 |  |  | $configure = new Config(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-19 10:25:09 +00:00
										 |  |  | // if a form is submitted, it's from the edit page
 | 
					
						
							|  |  |  | if ($_SERVER['REQUEST_METHOD'] == 'POST') { | 
					
						
							| 
									
										
										
										
											2024-08-18 19:12:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-19 10:25:09 +00:00
										 |  |  |     // load the config file and initialize a copy
 | 
					
						
							|  |  |  |     $content = file_get_contents($config_file); | 
					
						
							|  |  |  |     $updatedContent = $content; | 
					
						
							| 
									
										
										
										
											2024-08-18 19:12:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-26 18:19:21 +00:00
										 |  |  |     // new platform adding
 | 
					
						
							|  |  |  |     if (isset($_POST['new']) && $_POST['new'] === 'true') { | 
					
						
							|  |  |  |         $newPlatform = [ | 
					
						
							| 
									
										
										
										
											2024-08-27 18:18:27 +00:00
										 |  |  |             'name'		=> $_POST['name'], | 
					
						
							|  |  |  |             'jitsi_url'		=> $_POST['jitsi_url'], | 
					
						
							|  |  |  |             'jilo_database'	=> $_POST['jilo_database'], | 
					
						
							| 
									
										
										
										
											2024-08-26 18:19:21 +00:00
										 |  |  |         ]; | 
					
						
							| 
									
										
										
										
											2024-09-04 09:53:02 +00:00
										 |  |  |         $platformObject->addPlatform($newPlatform); | 
					
						
							| 
									
										
										
										
											2024-08-26 18:19:21 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // deleting a platform
 | 
					
						
							|  |  |  |     } elseif (isset($_POST['delete']) && $_POST['delete'] === 'true') { | 
					
						
							|  |  |  |         $platform = $_POST['platform']; | 
					
						
							| 
									
										
										
										
											2024-09-04 09:53:02 +00:00
										 |  |  |         $platformObject->deletePlatform($platform); | 
					
						
							| 
									
										
										
										
											2024-08-26 18:19:21 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // an update to an existing platform
 | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         $platform = $_POST['platform']; | 
					
						
							| 
									
										
										
										
											2024-09-04 09:53:02 +00:00
										 |  |  |         $updatedPlatform = [ | 
					
						
							|  |  |  |             'name'		=> $_POST['name'], | 
					
						
							|  |  |  |             'jitsi_url'		=> $_POST['jitsi_url'], | 
					
						
							|  |  |  |             'jilo_database'	=> $_POST['jilo_database'], | 
					
						
							|  |  |  |         ]; | 
					
						
							|  |  |  |         $platformObject->editPlatform($platform, $updatedPlatform); | 
					
						
							| 
									
										
										
										
											2024-08-26 18:19:21 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-19 10:25:09 +00:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-26 18:19:21 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-19 10:42:16 +00:00
										 |  |  |     // check if file is writable
 | 
					
						
							|  |  |  |     if (!is_writable($config_file)) { | 
					
						
							|  |  |  |         $_SESSION['error'] = getError('Configuration file is not writable.'); | 
					
						
							|  |  |  |         header("Location: $app_root?platform=$platform_id&page=config"); | 
					
						
							|  |  |  |         exit(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // try to update the config file
 | 
					
						
							| 
									
										
										
										
											2024-08-19 10:25:09 +00:00
										 |  |  |     if (file_put_contents($config_file, $updatedContent) !== false) { | 
					
						
							|  |  |  |         // update successful
 | 
					
						
							|  |  |  |         $_SESSION['notice'] = "Configuration for {$_POST['name']} is updated."; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         // unsuccessful
 | 
					
						
							| 
									
										
										
										
											2024-08-19 10:42:16 +00:00
										 |  |  |         $error = error_get_last(); | 
					
						
							|  |  |  |         $_SESSION['error'] = getError('Error updating the config: ' . ($error['message'] ?? 'unknown error')); | 
					
						
							| 
									
										
										
										
											2024-08-19 10:25:09 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2024-08-19 10:42:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-19 10:25:09 +00:00
										 |  |  | // FIXME the new file is not loaded on first page load
 | 
					
						
							|  |  |  |     unset($config); | 
					
						
							|  |  |  |     header("Location: $app_root?platform=$platform_id&page=config"); | 
					
						
							|  |  |  |     exit(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // no form submitted, show the templates
 | 
					
						
							|  |  |  | } else { | 
					
						
							| 
									
										
										
										
											2024-08-31 16:50:58 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // $item - config.js and interface_config.js are special case; remote loaded files
 | 
					
						
							| 
									
										
										
										
											2024-08-28 09:59:13 +00:00
										 |  |  |     switch ($item) { | 
					
						
							|  |  |  |         case 'configjs': | 
					
						
							| 
									
										
										
										
											2024-08-31 16:50:58 +00:00
										 |  |  |             $mode = $_REQUEST['mode'] ?? ''; | 
					
						
							|  |  |  |             $raw = ($mode === 'raw'); | 
					
						
							| 
									
										
										
										
											2024-09-04 09:53:02 +00:00
										 |  |  |             $platformConfigjs = $configure->getPlatformConfigjs($platformDetails[0]['jitsi_url'], $raw); | 
					
						
							| 
									
										
										
										
											2024-08-28 09:59:13 +00:00
										 |  |  |             include('../app/templates/config-list-configjs.php'); | 
					
						
							| 
									
										
										
										
											2024-08-19 10:25:09 +00:00
										 |  |  |             break; | 
					
						
							| 
									
										
										
										
											2024-08-28 09:59:13 +00:00
										 |  |  |         case 'interfaceconfigjs': | 
					
						
							| 
									
										
										
										
											2024-08-31 16:50:58 +00:00
										 |  |  |             $mode = $_REQUEST['mode'] ?? ''; | 
					
						
							|  |  |  |             $raw = ($mode === 'raw'); | 
					
						
							| 
									
										
										
										
											2024-09-04 09:53:02 +00:00
										 |  |  |             $platformInterfaceConfigjs = $configure->getPlatformInterfaceConfigjs($platformDetails[0]['jitsi_url'], $raw); | 
					
						
							| 
									
										
										
										
											2024-08-28 09:59:13 +00:00
										 |  |  |             include('../app/templates/config-list-interfaceconfigjs.php'); | 
					
						
							| 
									
										
										
										
											2024-08-26 18:19:21 +00:00
										 |  |  |             break; | 
					
						
							| 
									
										
										
										
											2024-08-28 09:59:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-31 16:50:58 +00:00
										 |  |  |     // if there is no $item, we work on the local config file
 | 
					
						
							| 
									
										
										
										
											2024-08-19 10:25:09 +00:00
										 |  |  |         default: | 
					
						
							| 
									
										
										
										
											2024-08-28 09:59:13 +00:00
										 |  |  |             switch ($action) { | 
					
						
							|  |  |  |                 case 'add': | 
					
						
							|  |  |  |                     include('../app/templates/config-add-platform.php'); | 
					
						
							|  |  |  |                     break; | 
					
						
							|  |  |  |                 case 'edit': | 
					
						
							|  |  |  |                     include('../app/templates/config-edit-platform.php'); | 
					
						
							|  |  |  |                     break; | 
					
						
							|  |  |  |                 case 'delete': | 
					
						
							|  |  |  |                     include('../app/templates/config-delete-platform.php'); | 
					
						
							|  |  |  |                     break; | 
					
						
							|  |  |  |                 default: | 
					
						
							|  |  |  |                     include('../app/templates/config-list.php'); | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2024-08-19 10:25:09 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2024-08-18 19:12:45 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2024-08-12 11:12:24 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | ?>
 |