aboutsummaryrefslogtreecommitdiff
blob: 72bb383340235a1b79279b87725e06c8a9d1951c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
/**
 *  Operating Systems.
 *  @package mirror
 *  @subpackage admin
 */
$protect=1;  // protect this page
require_once('../cfg/init.php');

// add os
if (!empty($_POST['add-submit'])&&!empty($_POST['os_name'])) {
    if (Mirror::insert_os($_POST['os_name'],$_POST['os_priority'])) {
        set_msg('OS added successfully.');
        header('Location: http://'.$_SERVER['HTTP_HOST'].WEBPATH.'/admin/os.php');
        exit;
    } else {
        set_error('OS could not be added because of an unknown error.');
    }
}

// process actions
if (!empty($_POST['submit'])) {
    if (!empty($_POST['os_id'])) {
        switch($_POST['action']) {
            case 'edit':
                if (!empty($_POST['doit'])) {
                    if (Mirror::update_os($_POST['os_id'],$_POST['os_name'],$_POST['os_priority'])) {
                        set_msg('OS updated successfully.');
                        header('Location: http://'.$_SERVER['HTTP_HOST'].WEBPATH.'/admin/os.php');
                        exit;
                    } else {
                        set_error('OS update failed.');
                    }
                } else {
                    $title = 'Edit OS';
                    $nav = INC.'/admin_nav.php';
                    require_once(HEADER);
                    echo '<h2>Edit OS</h2>';
                    $posts = Mirror::get_one_os($_POST['os_id']);
                    form_start();
                    include_once(INC.'/forms/os.php');
                    form_hidden('doit','1');
                    form_hidden('action','edit');
                    form_hidden('os_id',$_POST['os_id']);
                    form_submit('submit','','button1','Update');
                    form_end();
                    require_once(FOOTER);
                    exit;
                }
                break;
            case 'delete':
                if (!record_exists('mirror_locations','os_id',$_POST['os_id'])&&Mirror::delete_os($_POST['os_id'])) {
                    set_msg('OS deleted successfully.');
                } else {
                    set_error('OS cannot be deleted because it is being used by a file location.');
                }
                break;
        }
    } else {
        set_error('You must select a os to continue.');
    }
}

$title = 'Operating Systems';
$nav = INC.'/admin_nav.php';
require_once(HEADER);
echo '<h2>Operating Systems</h1>';

show_error();
show_msg();

$oss = Mirror::get_oss();

$_GET['sort']=(!empty($_GET['sort']))?$_GET['sort']:'os_name';
$_GET['order']=(!empty($_GET['order']))?$_GET['order']:'ASC';
$oss=array_order_by($oss,$_GET['sort'],$_GET['order']);

$headers = array(
    'os_id'=>'',
    'os_name'=>'OS Name',
    'os_priority'=>'Priority'
);

$actions = array(
    'edit'=>'Edit',
    'delete'=>'Delete'
);

form_start();
show_list($oss,$headers,'radio',$actions);
form_end();

echo '<h2>Add a OS</h2>';
form_start();
include_once(INC.'/forms/os.php');
form_submit('add-submit','','button1','Add OS');
form_end();

require_once(FOOTER);
?>