-
Notifications
You must be signed in to change notification settings - Fork 0
/
management.php
122 lines (101 loc) · 3.22 KB
/
management.php
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
112
113
114
115
116
117
118
119
120
121
122
<?php
/*
* ------------- PHP Code -------------
*/
include 'data.inc.php';
/**
* Retrieve previous content from the form
*/
$loaded_information = read_data();
/**
* Generate a field input based on a name
*
* @param $name
* @param bool|true $with_checkbox
* @return string
*/
function field_input($name, $with_checkbox = true)
{
global $loaded_information, $privacy;
$field_value = isset($loaded_information[$name]) ? $loaded_information[$name] : ['value' => null, 'privacy' => 'public'];
$html = '<input type="text" name="info[' . $name . '][value]" value="' . htmlentities($field_value['value']) . '" placeholder="' . $name . '" />';
if ($with_checkbox === true) {
$checkboxs = '';
foreach ($privacy as $privacy_level => $label) {
$status = ($field_value['privacy'] == $privacy_level ? 'checked="checked"' : '');
$checkboxs .= '<span><input type="radio" name="info[' . $name . '][privacy]" class="toggle-on" value="' . $privacy_level . '" ' . $status . '"/>' . $label . '</span>';
}
$html .= $checkboxs;
}
return $html;
}
/**
* Logic to save the form into a file if triggered
*/
if (isset($_POST['info'])) {
save_data($_POST['info']);
header("Location:management.php");
exit;
}
?>
<?php
/*
* ------------ Code page ---------
*/
?>
<?php
$url = 'management';
include 'header-user.inc.php';
?>
<div id="profile-management">
<form method="post">
<div id="fields-section">
<?php
foreach ($fields as $field => $data) {
if (is_array($data)) {
?>
<fieldset>
<div class="well">
<legend><span><?php echo $field; ?></span></legend>
<?php foreach($data as $key => $value) { ?>
<?php
$with_checkbox = true;
if (!is_int($key)) {
$with_checkbox = false;
$value = $key;
}
?>
<div class="field">
<label><?php echo $value; ?></label>
<div>
<?php echo field_input($value, $with_checkbox); ?>
</div>
</div>
<?php } ?>
</div>
</fieldset>
<?php
} else {
?>
<div class="well">
<div class="field">
<label><?php echo $data; ?></label>
<div>
<?php echo field_input($data); ?>
</div>
</div>
</div>
<?php
}
}
?>
</div>
<div class="text-center">
<input type="submit" value="save"/>
</div>
<br />
</form>
</div>
<?php
include 'footer.inc.php';
?>