Portions created by the Initial Developer are Copyright (C) 2026 the Initial Developer. All Rights Reserved. */ // includes files require_once dirname(__DIR__, 2) . "/resources/require.php"; require_once "resources/check_auth.php"; // check permissions if (!permission_exists('service_view')) { echo "access denied"; exit; } // add multi-lingual support $language = new text; $text = $language->get(); // add the settings object $settings = new settings(["domain_uuid" => $_SESSION['domain_uuid'], "user_uuid" => $_SESSION['user_uuid']]); // set from session variables $list_row_edit_button = $settings->get('theme', 'list_row_edit_button', 'false'); // get the http post data if (!empty($_POST['services']) && is_array($_POST['services'])) { $action = $_POST['action']; $search = $_POST['search']; $services = $_POST['services']; } // process the http post data by action if (!empty($action) && !empty($services) && is_array($services) && @sizeof($services) != 0) { // send the array to the database class switch ($action) { case 'reload': if (permission_exists('service_edit')) { $obj = new services; $obj->reload($services); } break; case 'toggle': if (permission_exists('service_edit')) { $obj = new services; $obj->toggle($services); } break; case 'delete': if (permission_exists('service_delete')) { $obj = new services; $obj->delete($services); } break; } // redirect the user header('Location: services.php'.($search != '' ? '?search='.urlencode($search) : null)); exit; } // get order and order by $order_by = $_GET["order_by"] ?? null; $order = $_GET["order"] ?? null; // define the variables $search = ''; $show = ''; $list_row_url = ''; // add the search variable if (!empty($_GET["search"])) { $search = strtolower($_GET["search"]); } // add the show variable if (!empty($_GET["show"])) { $show = $_GET["show"]; } // get the status of the services $service_object = new services; $service_object->add_missing(); // get the status of the services $service_array = $service_object->get_services('true'); // get the count $sql = "select count(service_uuid) "; $sql .= "from v_services "; $sql .= "where true "; if (!empty($search)) { $sql .= "and ( "; $sql .= " lower(service_name) like :search "; $sql .= " or lower(service_category) like :search "; $sql .= " or lower(service_description) like :search "; $sql .= ") "; $parameters['search'] = '%'.$search.'%'; } $num_rows = $database->select($sql, $parameters ?? null, 'column'); unset($sql, $parameters); // get the list $sql = "select "; $sql .= "service_uuid, "; $sql .= "service_name, "; $sql .= "service_category, "; $sql .= "cast(service_enabled as text), "; $sql .= "service_description "; $sql .= "from v_services "; $sql .= "where true "; if (!empty($search)) { $sql .= "and ( "; $sql .= " lower(service_name) like :search "; $sql .= " or lower(service_category) like :search "; $sql .= " or lower(service_description) like :search "; $sql .= ") "; $parameters['search'] = '%'.$search.'%'; } $sql .= order_by($order_by, $order, 'service_name', 'asc'); $sql .= limit_offset($rows_per_page, $offset); $services = $database->select($sql, $parameters ?? null, 'all'); unset($sql, $parameters); // add the service details to the services array foreach($services as $i => $service) { foreach ($service_array as $row) { if ($service['service_name'] == $row['name']) { $services[$i]['service_status'] = $row['status'] ? 'true' : 'false'; $services[$i]['service_pid'] = $row['pid']; $services[$i]['service_etime'] = $row['etime']; break; } } } // create token $object = new token; $token = $object->create($_SERVER['PHP_SELF']); // additional includes $document['title'] = $text['title-services']; require_once "resources/header.php"; // show the content echo "
\n"; echo "
".$text['title-services']."
".$num_rows."
\n"; echo "
\n"; if (permission_exists('service_edit') && $services) { echo button::create(['type'=>'button','label'=>$text['button-reload'],'icon'=>$_SESSION['theme']['button_icon_reload'],'id'=>'btn_reload','name'=>'btn_reload','style'=>'display:none;','onclick'=>"modal_open('modal-reload','btn_reload');"]); } if (permission_exists('service_edit') && $services) { echo button::create(['type'=>'button','label'=>$text['button-toggle'],'icon'=>$_SESSION['theme']['button_icon_toggle'],'id'=>'btn_toggle','name'=>'btn_toggle','style'=>'display:none;','onclick'=>"modal_open('modal-toggle','btn_toggle');"]); } if (permission_exists('service_delete') && $services) { echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'id'=>'btn_delete','name'=>'btn_delete','style'=>'display:none;','onclick'=>"modal_open('modal-delete','btn_delete');"]); } echo "\n"; echo "
\n"; echo "
\n"; echo "
\n"; if (permission_exists('service_add') && $services) { echo modal::create(['id'=>'modal-copy','type'=>'copy','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_copy','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('copy'); list_form_submit('form_list');"])]); } if (permission_exists('service_edit') && $services) { echo modal::create(['id'=>'modal-reload','type'=>'reload','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_reload','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('reload'); list_form_submit('form_list');"])]); } if (permission_exists('service_edit') && $services) { echo modal::create(['id'=>'modal-toggle','type'=>'toggle','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_toggle','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('toggle'); list_form_submit('form_list');"])]); } if (permission_exists('service_delete') && $services) { echo modal::create(['id'=>'modal-delete','type'=>'delete','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_delete','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('delete'); list_form_submit('form_list');"])]); } echo $text['title_description-services']."\n"; echo "

\n"; echo "
\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; if (permission_exists('service_add') || permission_exists('service_edit') || permission_exists('service_delete')) { echo " \n"; } echo th_order_by('service_name', $text['label-service_name'], $order_by, $order); echo th_order_by('service_status', $text['label-service_status'], $order_by, $order); echo th_order_by('service_category', $text['label-service_category'], $order_by, $order); echo " \n"; echo th_order_by('service_enabled', $text['label-enabled'], $order_by, $order, null, "class='center'"); echo " \n"; if (permission_exists('service_edit') && $list_row_edit_button == 'true') { echo " \n"; } echo "\n"; if (!empty($services) && is_array($services) && @sizeof($services) != 0) { $x = 0; foreach ($services as $row) { $service_status = ($row['service_status'] == 'true') ? "".$text['label-yes']."" : "".$text['label-no'].""; $etime = isset($row['service_etime']) ? $service_object->format_etime($row['service_etime']) : '-'; $pid = $row['service_pid'] ?? ''; $tooltip_attr = $pid ? "title='PID: $pid'" : ''; if (permission_exists('service_edit')) { $list_row_url = "service_edit.php?id=".urlencode($row['service_uuid']); } echo "\n"; if (permission_exists('service_add') || permission_exists('service_edit') || permission_exists('service_delete')) { echo " \n"; } echo " \n"; echo " \n"; echo " \n"; echo " \n"; if (permission_exists('service_edit')) { echo " \n"; echo " \n"; if (permission_exists('service_edit') && $list_row_edit_button == 'true') { echo " \n"; } echo "\n"; $x++; } unset($services); } echo "
\n"; echo " \n"; echo " ".$text['label-service_runtime']."".$text['label-service_description']." 
\n"; echo " \n"; echo " \n"; echo " \n"; if (permission_exists('service_edit')) { echo " ".escape($row['service_name'])."\n"; } else { echo " ".escape($row['service_name']); } echo " ".$service_status."".escape($row['service_category'])."".escape($etime)."\n"; echo $text['label-'.$row['service_enabled']]; } echo " ".escape($row['service_description'])."\n"; echo button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$_SESSION['theme']['button_icon_edit'],'link'=>$list_row_url]); echo "
\n"; echo "
\n"; echo "
".$paging_controls."
\n"; echo "\n"; echo "
\n"; // include the footer require_once "resources/footer.php"; ?>