aboutsummaryrefslogtreecommitdiff
blob: e058900966368fc8f6285a7b1c1a9471639b9932 (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
101
102
103
104
105
106
107
108
109
110
111
<?php
/**
 *  Regions.
 *  @package mirror
 *  @subpackage admin
 */
$protect=1;  // protect this page
require_once('../cfg/init.php');

// add mirror 
if (!empty($_POST['add-submit'])) {
    if (Mirror::insert_mirror($_POST['mirror_name'],$_POST['region_id'],$_POST['mirror_baseurl'],$_POST['mirror_rating'])) {
        set_msg('Mirror added successfully.');
        header('Location: '.$_SERVER['HTTP_PROTO'].'://'.$_SERVER['HTTP_HOST'].WEBPATH.'/admin/');
        exit;
    } else {
        set_error('Mirror could not be added because of an unknown error.');
    }
}

// process actions
if (!empty($_POST['submit'])) {
    if (!empty($_POST['mirror_id'])) {
        switch($_POST['action']) {
            case 'edit':
                if (!empty($_POST['doit'])) {
                    if (Mirror::update_mirror($_POST['mirror_id'],$_POST['mirror_name'],$_POST['region_id'],$_POST['mirror_baseurl'],$_POST['mirror_rating'])) {
                        set_msg('Mirror updated successfully.');
                        header('Location: '.$_SERVER['HTTP_PROTO'].'://'.$_SERVER['HTTP_HOST'].WEBPATH.'/admin/');
                        exit;
                    } else {
                        set_error('Mirror update failed.');
                    }
                } else {
                    $title = 'Edit Mirror';
                    $nav = INC.'/admin_nav.php';
                    require_once(HEADER);
                    echo '<h2>Edit Mirror</h2>';
                    $posts = Mirror::get_one_mirror($_POST['mirror_id']);
                    form_start();
                    include_once(INC.'/forms/mirror.php');
                    form_hidden('doit','1');
                    form_hidden('action','edit');
                    form_hidden('mirror_id',$_POST['mirror_id']);
                    form_submit('submit','','button1','Update');
                    form_end();
                    require_once(FOOTER);
                    exit;
                }
                break;
            case 'delete':
                if (Mirror::delete_mirror($_POST['mirror_id'])) {
                    set_msg('Mirror deleted successfully.');
                } else {
                    set_error('Mirror could not be deleted.');
                }
                break;
            case 'toggle':
                if (Mirror::toggle($_POST['mirror_id'])) {
                    set_msg('Mirror enabled/disabled.');
                } else {
                    set_error('Mirror could not be enabled/disabled.');
                }
        }
    } else {
        set_error('You must select a mirror to continue.');
    }
}

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

show_error();
show_msg();

$mirrors = Mirror::get_mirrors();

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

$headers = array(
    'mirror_id'=>'',
    'mirror_active'=>'Status',
    'mirror_rating'=>'Rating',
    'mirror_name'=>'Host Name',
    'mirror_baseurl'=>'Address',
    'region_name'=>'Region',
    'mirror_count'=>'Hits'
);

$actions = array(
    'toggle'=>'Enable/Disable',
    'edit'=>'Edit',
    'delete'=>'Delete'
);

form_start();
ListOut::show($mirrors,$headers,'radio',$actions);
form_end();

echo '<h2>Add a Mirror</h2>';
form_start();
$posts = ['mirror_name' => '', 'region_id' => '', 'mirror_baseurl' => '', 'mirror_rating' => ''];
include_once(INC.'/forms/mirror.php');
form_submit('add-submit','','button1','Add Mirror');
form_end();

require_once(FOOTER);