| 
									
										
										
										
											2025-01-26 13:33:45 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |                 <!-- config file --> | 
					
						
							|  |  |  |                 <div class="container-fluid mt-2"> | 
					
						
							|  |  |  |                     <div class="row mb-4"> | 
					
						
							| 
									
										
										
										
											2025-01-26 15:32:37 +00:00
										 |  |  |                         <div class="col-12 mb-4"> | 
					
						
							| 
									
										
										
										
											2025-01-29 08:45:24 +00:00
										 |  |  |                             <h2 class="mb-0">Configuration</h2> | 
					
						
							| 
									
										
										
										
											2025-01-26 16:32:29 +00:00
										 |  |  |                             <small>Jilo Web configuration file: <em><?= htmlspecialchars($localConfigPath) ?></em></small>
 | 
					
						
							| 
									
										
										
										
											2025-01-26 15:32:37 +00:00
										 |  |  | <?php if ($configMessage) { ?>
 | 
					
						
							| 
									
										
										
										
											2025-01-26 13:33:45 +00:00
										 |  |  |                                 <?= $configMessage ?>
 | 
					
						
							| 
									
										
										
										
											2025-01-26 15:32:37 +00:00
										 |  |  | <?php } ?>
 | 
					
						
							| 
									
										
										
										
											2025-01-26 13:33:45 +00:00
										 |  |  |                         </div> | 
					
						
							| 
									
										
										
										
											2025-01-26 15:32:37 +00:00
										 |  |  |                     </div> | 
					
						
							| 
									
										
										
										
											2025-01-26 13:33:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-26 15:32:37 +00:00
										 |  |  |                     <div class="card shadow-sm"> | 
					
						
							|  |  |  |                         <div class="card-header bg-light d-flex justify-content-between align-items-center py-3"> | 
					
						
							|  |  |  |                             <h5 class="card-title mb-0"> | 
					
						
							|  |  |  |                                 <i class="fas fa-wrench me-2 text-secondary"></i> | 
					
						
							|  |  |  |                                 Jilo Web app configuration | 
					
						
							|  |  |  |                             </h5> | 
					
						
							| 
									
										
										
										
											2025-01-26 13:33:45 +00:00
										 |  |  | <?php if ($userObject->hasRight($user_id, 'edit config file')) { ?>
 | 
					
						
							| 
									
										
										
										
											2025-01-26 15:32:37 +00:00
										 |  |  |                             <div> | 
					
						
							|  |  |  |                                 <button type="button" class="btn btn-outline-primary btn-sm toggle-edit" <?= !$isWritable ? 'disabled' : '' ?>>
 | 
					
						
							|  |  |  |                                     <i class="fas fa-edit me-2"></i>Edit | 
					
						
							|  |  |  |                                 </button> | 
					
						
							|  |  |  |                                 <div class="edit-controls d-none"> | 
					
						
							|  |  |  |                                     <button type="button" class="btn btn-danger btn-sm save-config"> | 
					
						
							|  |  |  |                                         <i class="fas fa-save me-2"></i>Save | 
					
						
							|  |  |  |                                     </button> | 
					
						
							|  |  |  |                                     <button type="button" class="btn btn-outline-secondary btn-sm ms-2 cancel-edit"> | 
					
						
							|  |  |  |                                         Cancel | 
					
						
							| 
									
										
										
										
											2025-01-26 13:33:45 +00:00
										 |  |  |                                     </button> | 
					
						
							| 
									
										
										
										
											2025-01-23 10:42:27 +00:00
										 |  |  |                                 </div> | 
					
						
							| 
									
										
										
										
											2025-01-26 13:33:45 +00:00
										 |  |  |                             </div> | 
					
						
							| 
									
										
										
										
											2025-01-26 15:32:37 +00:00
										 |  |  | <?php } ?>
 | 
					
						
							|  |  |  |                         </div> | 
					
						
							| 
									
										
										
										
											2025-01-26 13:33:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-26 15:32:37 +00:00
										 |  |  |                         <div class="card-body p-4"> | 
					
						
							|  |  |  |                             <form id="configForm"> | 
					
						
							| 
									
										
										
										
											2025-01-26 13:33:45 +00:00
										 |  |  | <?php | 
					
						
							|  |  |  | function renderConfigItem($key, $value, $path = '') { | 
					
						
							|  |  |  |     $fullPath = $path ? $path . '[' . $key . ']' : $key; | 
					
						
							|  |  |  |     // Only capitalize first letter, not every word
 | 
					
						
							|  |  |  |     $displayName = ucfirst(str_replace('_', ' ', $key)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (is_array($value)) { | 
					
						
							| 
									
										
										
										
											2025-01-26 15:32:37 +00:00
										 |  |  |         echo "\t\t\t\t\t\t\t\t<div class=\"config-section mb-4\">"; | 
					
						
							|  |  |  |         echo "\n\t\t\t\t\t\t\t\t\t<h6 class=\"border-bottom pb-2 mb-3\">" . htmlspecialchars($displayName) . '</h6>'; | 
					
						
							|  |  |  |         echo "\n\t\t\t\t\t\t\t\t\t<div class=\"ps-4\">\n"; | 
					
						
							|  |  |  |         foreach ($value as $subKey => $subValue) { | 
					
						
							|  |  |  |             renderConfigItem($subKey, $subValue, $fullPath); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-01-26 13:33:45 +00:00
										 |  |  |         echo "\t\t\t\t\t\t\t\t\t</div>\n"; | 
					
						
							| 
									
										
										
										
											2025-01-26 15:32:37 +00:00
										 |  |  |         echo "\t\t\t\t\t\t\t\t</div>\n"; | 
					
						
							| 
									
										
										
										
											2025-01-26 13:33:45 +00:00
										 |  |  |     } else { | 
					
						
							|  |  |  | ?>
 | 
					
						
							| 
									
										
										
										
											2025-01-26 15:32:37 +00:00
										 |  |  |                                 <div class="config-item row mb-3 align-items-center"> | 
					
						
							|  |  |  |                                     <div class="col-md-4 text-end"> | 
					
						
							|  |  |  |                                         <label class="form-label mb-0"><?= htmlspecialchars($displayName) ?></label>
 | 
					
						
							|  |  |  |                                     </div> | 
					
						
							|  |  |  |                                     <div class="col-md-8"> | 
					
						
							|  |  |  |                                         <div class="view-mode"> | 
					
						
							| 
									
										
										
										
											2025-01-26 13:33:45 +00:00
										 |  |  | <?php if (is_bool($value) || $key === 'registration_enabled') { ?>
 | 
					
						
							| 
									
										
										
										
											2025-01-26 15:32:37 +00:00
										 |  |  |                                             <span class="badge <?= $value ? 'bg-success' : 'bg-secondary' ?>"><?= $value ? 'Enabled' : 'Disabled' ?></span>
 | 
					
						
							| 
									
										
										
										
											2025-01-26 13:33:45 +00:00
										 |  |  | <?php } elseif ($key === 'environment') { ?>
 | 
					
						
							| 
									
										
										
										
											2025-01-26 15:32:37 +00:00
										 |  |  |                                             <span class="badge <?= $value === 'production' ? 'bg-danger' : 'bg-info' ?>"><?= htmlspecialchars($value) ?></span>
 | 
					
						
							| 
									
										
										
										
											2025-01-26 13:33:45 +00:00
										 |  |  | <?php } else { | 
					
						
							|  |  |  |         if (empty($value) && $value !== '0') { ?>
 | 
					
						
							| 
									
										
										
										
											2025-01-26 15:32:37 +00:00
										 |  |  |                                             <span class="text-muted fst-italic">blank</span> | 
					
						
							| 
									
										
										
										
											2025-01-26 13:33:45 +00:00
										 |  |  | <?php   } else { ?>
 | 
					
						
							| 
									
										
										
										
											2025-01-26 15:32:37 +00:00
										 |  |  |                                             <span class="text-body"><?= htmlspecialchars($value) ?></span>
 | 
					
						
							| 
									
										
										
										
											2025-01-26 13:33:45 +00:00
										 |  |  | <?php   } ?>
 | 
					
						
							|  |  |  | <?php } ?>
 | 
					
						
							| 
									
										
										
										
											2025-01-26 15:32:37 +00:00
										 |  |  |                                         </div> | 
					
						
							|  |  |  |                                         <div class="edit-mode d-none"> | 
					
						
							| 
									
										
										
										
											2025-01-26 13:33:45 +00:00
										 |  |  | <?php if (is_bool($value) || $key === 'registration_enabled') { ?>
 | 
					
						
							| 
									
										
										
										
											2025-01-26 15:32:37 +00:00
										 |  |  |                                             <div class="form-check form-switch"> | 
					
						
							|  |  |  |                                                 <input class="form-check-input" type="checkbox" name="<?= htmlspecialchars($fullPath) ?>" <?= $value ? 'checked' : '' ?>>
 | 
					
						
							|  |  |  |                                             </div> | 
					
						
							| 
									
										
										
										
											2025-01-26 13:33:45 +00:00
										 |  |  | <?php } elseif ($key === 'environment') { ?>
 | 
					
						
							| 
									
										
										
										
											2025-01-26 15:32:37 +00:00
										 |  |  |                                             <select class="form-select form-select-sm" name="<?= htmlspecialchars($fullPath) ?>"> | 
					
						
							|  |  |  |                                                 <option value="development" <?= $value === 'development' ? 'selected' : '' ?>>Development</option>
 | 
					
						
							|  |  |  |                                                 <option value="production" <?= $value === 'production' ? 'selected' : '' ?>>Production</option>
 | 
					
						
							|  |  |  |                                             </select> | 
					
						
							| 
									
										
										
										
											2025-01-26 13:33:45 +00:00
										 |  |  | <?php } else { ?>
 | 
					
						
							| 
									
										
										
										
											2025-01-26 15:32:37 +00:00
										 |  |  |                                             <input type="text" class="form-control form-control-sm" name="<?= htmlspecialchars($fullPath) ?>" value="<?= htmlspecialchars($value ?? '') ?>"> | 
					
						
							| 
									
										
										
										
											2025-01-26 13:33:45 +00:00
										 |  |  | <?php } ?>
 | 
					
						
							|  |  |  |                                         </div> | 
					
						
							|  |  |  |                                     </div> | 
					
						
							| 
									
										
										
										
											2025-01-26 15:32:37 +00:00
										 |  |  |                                 </div> | 
					
						
							| 
									
										
										
										
											2025-01-26 13:33:45 +00:00
										 |  |  | <?php } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     foreach ($config as $key => $value) { | 
					
						
							|  |  |  |         renderConfigItem($key, $value); | 
					
						
							|  |  |  |     } ?>
 | 
					
						
							| 
									
										
										
										
											2025-01-26 15:32:37 +00:00
										 |  |  |                             </form> | 
					
						
							| 
									
										
										
										
											2025-01-23 10:42:27 +00:00
										 |  |  |                         </div> | 
					
						
							| 
									
										
										
										
											2025-01-26 13:33:45 +00:00
										 |  |  |                     </div> | 
					
						
							|  |  |  |                 </div> | 
					
						
							| 
									
										
										
										
											2025-01-26 15:32:37 +00:00
										 |  |  |             </div> | 
					
						
							| 
									
										
										
										
											2025-01-23 10:42:27 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | <script> | 
					
						
							|  |  |  | $(function() { | 
					
						
							|  |  |  |     // Toggle edit mode
 | 
					
						
							|  |  |  |     $('.toggle-edit').click(function() { | 
					
						
							|  |  |  |         $(this).hide(); | 
					
						
							|  |  |  |         $('.edit-controls').removeClass('d-none'); | 
					
						
							|  |  |  |         $('.view-mode').hide(); | 
					
						
							|  |  |  |         $('.edit-mode').removeClass('d-none'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Cancel edit
 | 
					
						
							|  |  |  |     $('.cancel-edit').click(function() { | 
					
						
							|  |  |  |         $('.toggle-edit').show(); | 
					
						
							|  |  |  |         $('.edit-controls').addClass('d-none'); | 
					
						
							|  |  |  |         $('.view-mode').show(); | 
					
						
							|  |  |  |         $('.edit-mode').addClass('d-none'); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Save config
 | 
					
						
							|  |  |  |     $('.save-config').click(function() { | 
					
						
							|  |  |  |         const $btn = $(this).prop('disabled', true).html('<i class="fas fa-spinner fa-spin me-2"></i>Saving...'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Build form data object
 | 
					
						
							|  |  |  |         const data = {}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Handle text inputs
 | 
					
						
							|  |  |  |         $('#configForm input[type="text"]').each(function() { | 
					
						
							|  |  |  |             const name = $(this).attr('name'); | 
					
						
							|  |  |  |             data[name] = $(this).val(); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Handle checkboxes
 | 
					
						
							|  |  |  |         $('#configForm input[type="checkbox"]').each(function() { | 
					
						
							|  |  |  |             const name = $(this).attr('name'); | 
					
						
							|  |  |  |             data[name] = $(this).prop('checked') ? '1' : '0'; | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // Handle selects
 | 
					
						
							|  |  |  |         $('#configForm select').each(function() { | 
					
						
							|  |  |  |             const name = $(this).attr('name'); | 
					
						
							|  |  |  |             data[name] = $(this).val(); | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-26 15:32:37 +00:00
										 |  |  |         $.ajax({ | 
					
						
							|  |  |  |             url: '<?= htmlspecialchars($app_root) ?>?page=config', | 
					
						
							| 
									
										
										
										
											2025-01-23 10:42:27 +00:00
										 |  |  |             method: 'POST', | 
					
						
							| 
									
										
										
										
											2025-01-26 15:32:37 +00:00
										 |  |  |             data: JSON.stringify(data), | 
					
						
							|  |  |  |             contentType: 'application/json', | 
					
						
							| 
									
										
										
										
											2025-01-23 10:42:27 +00:00
										 |  |  |             headers: { | 
					
						
							|  |  |  |                 'X-Requested-With': 'XMLHttpRequest' | 
					
						
							|  |  |  |             }, | 
					
						
							| 
									
										
										
										
											2025-01-26 15:32:37 +00:00
										 |  |  |             success: function(response) { | 
					
						
							|  |  |  |                 // Show message first
 | 
					
						
							|  |  |  |                 if (response.messageData) { | 
					
						
							| 
									
										
										
										
											2025-01-26 16:18:43 +00:00
										 |  |  |                     JsMessages.success(response.messageData['message']); | 
					
						
							| 
									
										
										
										
											2025-01-26 15:32:37 +00:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2025-01-26 16:06:00 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-26 15:32:37 +00:00
										 |  |  |                 // Only update UI if save was successful
 | 
					
						
							|  |  |  |                 if (response.success) { | 
					
						
							|  |  |  |                     // Update view mode values
 | 
					
						
							|  |  |  |                     Object.entries(data).forEach(([key, value]) => { | 
					
						
							|  |  |  |                         const $item = $(`[name="${key}"]`).closest('.config-item'); | 
					
						
							|  |  |  |                         const $viewMode = $item.find('.view-mode'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                         if ($item.length) { | 
					
						
							|  |  |  |                             if ($item.find('input[type="checkbox"]').length) { | 
					
						
							|  |  |  |                                 // Boolean value
 | 
					
						
							|  |  |  |                                 const isEnabled = value === '1'; | 
					
						
							|  |  |  |                                 $viewMode.html(` | 
					
						
							|  |  |  |                                     <span class="badge ${isEnabled ? 'bg-success' : 'bg-secondary'}"> | 
					
						
							|  |  |  |                                         ${isEnabled ? 'Enabled' : 'Disabled'} | 
					
						
							|  |  |  |                                     </span> | 
					
						
							|  |  |  |                                 `); | 
					
						
							|  |  |  |                             } else if ($item.find('select').length) { | 
					
						
							|  |  |  |                                 // Environment value
 | 
					
						
							|  |  |  |                                 $viewMode.html(` | 
					
						
							|  |  |  |                                     <span class="badge ${value === 'production' ? 'bg-danger' : 'bg-info'}"> | 
					
						
							|  |  |  |                                         ${value} | 
					
						
							|  |  |  |                                     </span> | 
					
						
							|  |  |  |                                 `); | 
					
						
							| 
									
										
										
										
											2025-01-23 10:42:27 +00:00
										 |  |  |                             } else { | 
					
						
							| 
									
										
										
										
											2025-01-26 15:32:37 +00:00
										 |  |  |                                 // Text value
 | 
					
						
							|  |  |  |                                 if (value === '') { | 
					
						
							|  |  |  |                                     $viewMode.html('<span class="text-muted fst-italic">blank</span>'); | 
					
						
							|  |  |  |                                 } else { | 
					
						
							|  |  |  |                                     $viewMode.html(`<span class="text-body">${value}</span>`); | 
					
						
							|  |  |  |                                 } | 
					
						
							| 
									
										
										
										
											2025-01-23 10:42:27 +00:00
										 |  |  |                             } | 
					
						
							|  |  |  |                         } | 
					
						
							| 
									
										
										
										
											2025-01-26 15:32:37 +00:00
										 |  |  |                     }); | 
					
						
							|  |  |  |                     // Finally, exit edit mode
 | 
					
						
							|  |  |  |                     $('.toggle-edit').show(); | 
					
						
							|  |  |  |                     $('.edit-controls').addClass('d-none'); | 
					
						
							|  |  |  |                     $('.view-mode').show(); | 
					
						
							|  |  |  |                     $('.edit-mode').addClass('d-none'); | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |             error: function(xhr, status, error) { | 
					
						
							| 
									
										
										
										
											2025-01-26 16:06:00 +00:00
										 |  |  |                 JsMessages.error('Error saving config: ' + error); | 
					
						
							| 
									
										
										
										
											2025-01-26 15:32:37 +00:00
										 |  |  |             }, | 
					
						
							|  |  |  |             complete: function() { | 
					
						
							|  |  |  |                 $btn.prop('disabled', false).html('<i class="fas fa-save me-2"></i>Save'); | 
					
						
							| 
									
										
										
										
											2025-01-23 10:42:27 +00:00
										 |  |  |             } | 
					
						
							|  |  |  |         }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | </script> | 
					
						
							| 
									
										
										
										
											2025-01-26 15:32:37 +00:00
										 |  |  | <!-- /config file --> |