Cannot modify header information
In mijn script, om bepaalde user wijzigen te kunnen doorvoeren gebruik ik vaak de header(); functie.
Nu loop ik bijna aan het einde van het script tegen het volgende aan:
Warning: Cannot modify header information - headers already sent by (output started at /path/user_view.php:316) in /path/user_view.php on line 345
De code die hierbij hoort is:
Code (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
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
echo '<div id="other">';
if(isset($_POST['other']))
{
$ssh->exec('zarafa-admin -u "'.getUserDetails('Username').'" -a "'.$_POST['type'].'" -n "'.$_POST['status'].'"');
header('Location: index.php?page=user_view&user='.getUserDetails('Username').'');
}
echo '<form method="post">';
echo '<table id="edit" class="user">';
echo '<tr>';
echo '<td>Type</td> <td><select name="type">'.(isset($_POST['type']) ? ($_POST['type'] == '0' ? '<option value="0" selected="selected">Gebruiker</option><option value="1">Administrator</option>' : '') : '<option value="0" '.(getUserDetails('Administrator') == 'no' ? 'selected="selected"' : '').'>Gebruiker</option>').(isset($_POST['type']) ? ($_POST['type'] == '1' ? '<option value="0">Gebruiker</option><option value="1" selected="selected">Administrator</option>' : '') : '<option value="1" '.(getUserDetails('Administrator') == 'yes' ? 'selected="selected"' : '').'>Administrator</option>').'</select></td>';
echo '</tr>';
echo '<tr>';
echo '<td>Status</td> <td><select name="status">'.(isset($_POST['status']) ? ($_POST['status'] == '0' ? '<option value="0" selected="selected">Actief</option><option value="1">Niet actief</option>' : '') : '<option value="0" '.(getUserDetails('Active') == 'yes' ? 'selected="selected"' : '').'>Actief</option>').(isset($_POST['status']) ? ($_POST['status'] == '1' ? '<option value="0">Actief</option><option value="1" selected="selected">Niet actief</option>' : '') : '<option value="1" '.(getUserDetails('Active') == 'no' ? 'selected="selected"' : '').'>Niet actief</option>').'</select></td>';
echo '</tr>';
echo '<tr>';
echo '<td></td> <td><input type="submit" name="other" value="Opslaan" /> <input type="submit" name="cancel" value="Annuleren" /></td>';
echo '</tr>';
echo '</table>';
echo '</form>';
echo '</div>';
echo '<div id="groups">';
echo '</div>';
echo '<div id="sendas">';
if(isset($_POST['sendas']))
{
foreach($_POST as $key => $value)
{
if(strpos($key, 'user-') === 0)
{
$getValue = explode ('-', $value);
if($getValue[0] == 1)
{
$ssh->exec('zarafa-admin -u "'.getUserDetails('Username').'" --add-sendas "'.$getValue[1].'"');
header('Location: index.php?page=user_view&user='.getUserDetails('Username').'');
}
if($getValue[0] == 0)
{
$ssh->exec('zarafa-admin -u "'.getUserDetails('Username').'" --del-sendas "'.$getValue[1].'"');
header('Location: index.php?page=user_view&user='.getUserDetails('Username').'');
}
}
}
}
echo '<form method="post">';
echo '<table>';
echo '<tr>';
echo '<th></th>';
echo '<th>Ja</th>';
echo '<th>Nee</th>';
echo '</tr>';
$getUsername = getUsers('0x6701001E');
$getType = getUsers('0x67B10003');
$getSendAsUsers = getSendAsUsers();
$i = 0;
foreach($getUsername as $key => $value)
{
$i++;
echo '<tr>';
if($getUsername[$key] != getUserDetails('Username'))
{
if($getType[$key] < 2)
{
echo '<td>'.$getUsername[$key].'</td>';
echo '<td><input type="radio" name="user-'.$i.'" value="1-'.$getUsername[$key].'" '.(in_array($getUsername[$key], $getSendAsUsers) ? 'checked' : '').' /></td>';
echo '<td><input type="radio" name="user-'.$i.'" value="0-'.$getUsername[$key].'" '.(!in_array($getUsername[$key], $getSendAsUsers) ? 'checked' : '').' /></td>';
}
}
echo '</tr>';
}
echo '<tr>';
echo '<td><input type="submit" name="sendas" value="Opslaan" /> <input type="submit" name="cancel" value="Annuleren" /></td>';
echo '</tr>';
echo '</table>';
echo '</form>';
echo '</div>';
if(isset($_POST['other']))
{
$ssh->exec('zarafa-admin -u "'.getUserDetails('Username').'" -a "'.$_POST['type'].'" -n "'.$_POST['status'].'"');
header('Location: index.php?page=user_view&user='.getUserDetails('Username').'');
}
echo '<form method="post">';
echo '<table id="edit" class="user">';
echo '<tr>';
echo '<td>Type</td> <td><select name="type">'.(isset($_POST['type']) ? ($_POST['type'] == '0' ? '<option value="0" selected="selected">Gebruiker</option><option value="1">Administrator</option>' : '') : '<option value="0" '.(getUserDetails('Administrator') == 'no' ? 'selected="selected"' : '').'>Gebruiker</option>').(isset($_POST['type']) ? ($_POST['type'] == '1' ? '<option value="0">Gebruiker</option><option value="1" selected="selected">Administrator</option>' : '') : '<option value="1" '.(getUserDetails('Administrator') == 'yes' ? 'selected="selected"' : '').'>Administrator</option>').'</select></td>';
echo '</tr>';
echo '<tr>';
echo '<td>Status</td> <td><select name="status">'.(isset($_POST['status']) ? ($_POST['status'] == '0' ? '<option value="0" selected="selected">Actief</option><option value="1">Niet actief</option>' : '') : '<option value="0" '.(getUserDetails('Active') == 'yes' ? 'selected="selected"' : '').'>Actief</option>').(isset($_POST['status']) ? ($_POST['status'] == '1' ? '<option value="0">Actief</option><option value="1" selected="selected">Niet actief</option>' : '') : '<option value="1" '.(getUserDetails('Active') == 'no' ? 'selected="selected"' : '').'>Niet actief</option>').'</select></td>';
echo '</tr>';
echo '<tr>';
echo '<td></td> <td><input type="submit" name="other" value="Opslaan" /> <input type="submit" name="cancel" value="Annuleren" /></td>';
echo '</tr>';
echo '</table>';
echo '</form>';
echo '</div>';
echo '<div id="groups">';
echo '</div>';
echo '<div id="sendas">';
if(isset($_POST['sendas']))
{
foreach($_POST as $key => $value)
{
if(strpos($key, 'user-') === 0)
{
$getValue = explode ('-', $value);
if($getValue[0] == 1)
{
$ssh->exec('zarafa-admin -u "'.getUserDetails('Username').'" --add-sendas "'.$getValue[1].'"');
header('Location: index.php?page=user_view&user='.getUserDetails('Username').'');
}
if($getValue[0] == 0)
{
$ssh->exec('zarafa-admin -u "'.getUserDetails('Username').'" --del-sendas "'.$getValue[1].'"');
header('Location: index.php?page=user_view&user='.getUserDetails('Username').'');
}
}
}
}
echo '<form method="post">';
echo '<table>';
echo '<tr>';
echo '<th></th>';
echo '<th>Ja</th>';
echo '<th>Nee</th>';
echo '</tr>';
$getUsername = getUsers('0x6701001E');
$getType = getUsers('0x67B10003');
$getSendAsUsers = getSendAsUsers();
$i = 0;
foreach($getUsername as $key => $value)
{
$i++;
echo '<tr>';
if($getUsername[$key] != getUserDetails('Username'))
{
if($getType[$key] < 2)
{
echo '<td>'.$getUsername[$key].'</td>';
echo '<td><input type="radio" name="user-'.$i.'" value="1-'.$getUsername[$key].'" '.(in_array($getUsername[$key], $getSendAsUsers) ? 'checked' : '').' /></td>';
echo '<td><input type="radio" name="user-'.$i.'" value="0-'.$getUsername[$key].'" '.(!in_array($getUsername[$key], $getSendAsUsers) ? 'checked' : '').' /></td>';
}
}
echo '</tr>';
}
echo '<tr>';
echo '<td><input type="submit" name="sendas" value="Opslaan" /> <input type="submit" name="cancel" value="Annuleren" /></td>';
echo '</tr>';
echo '</table>';
echo '</form>';
echo '</div>';
Waarbij de dik gedrukte regel 13 regel 316 is in het script.
Eerder is het script heb ik ook al 4/5 stukken met de header functie en dat gaat gewoon goed, en heb daar niks geen errors.
Ook heb ik helemaal boven en onderaan de pagina's het volgende al, zonder enig resultaat:
ob_start();
ob_end_flush();
Wat doe ik fout?
Gewijzigd op 08/01/2014 10:09:19 door Gerben Kwakkel
Als je header wil gebruiken, moet je dat doen vóór de eerste echo.
Er is geen enkele goede reden te verzinnen waarom je eerst <div id="other"> naar de client stuurt; om daarna nog met header de pagina te verlaten
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
echo '<div id="other">';
if(isset($_POST['other']))
{
$ssh->exec('zarafa-admin -u "'.getUserDetails('Username').'" -a "'.$_POST['type'].'" -n "'.$_POST['status'].'"');
header('Location: index.php?page=user_view&user='.getUserDetails('Username').'');
}
echo '<form method="post">';
echo '<table id="edit" class="user">';
echo '<tr>';
echo '<td>Type</td> <td><select name="type">'.(isset($_POST['type']) ? ($_POST['type'] == '0' ? '<option value="0" selected="selected">Gebruiker</option><option value="1">Administrator</option>' : '') : '<option value="0" '.(getUserDetails('Administrator') == 'no' ? 'selected="selected"' : '').'>Gebruiker</option>').(isset($_POST['type']) ? ($_POST['type'] == '1' ? '<option value="0">Gebruiker</option><option value="1" selected="selected">Administrator</option>' : '') : '<option value="1" '.(getUserDetails('Administrator') == 'yes' ? 'selected="selected"' : '').'>Administrator</option>').'</select></td>';
echo '</tr>';
echo '<tr>';
echo '<td>Status</td> <td><select name="status">'.(isset($_POST['status']) ? ($_POST['status'] == '0' ? '<option value="0" selected="selected">Actief</option><option value="1">Niet actief</option>' : '') : '<option value="0" '.(getUserDetails('Active') == 'yes' ? 'selected="selected"' : '').'>Actief</option>').(isset($_POST['status']) ? ($_POST['status'] == '1' ? '<option value="0">Actief</option><option value="1" selected="selected">Niet actief</option>' : '') : '<option value="1" '.(getUserDetails('Active') == 'no' ? 'selected="selected"' : '').'>Niet actief</option>').'</select></td>';
echo '</tr>';
echo '<tr>';
echo '<td></td> <td><input type="submit" name="other" value="Opslaan" /> <input type="submit" name="cancel" value="Annuleren" /></td>';
echo '</tr>';
echo '</table>';
echo '</form>';
echo '</div>';
if(isset($_POST['other']))
{
$ssh->exec('zarafa-admin -u "'.getUserDetails('Username').'" -a "'.$_POST['type'].'" -n "'.$_POST['status'].'"');
header('Location: index.php?page=user_view&user='.getUserDetails('Username').'');
}
echo '<form method="post">';
echo '<table id="edit" class="user">';
echo '<tr>';
echo '<td>Type</td> <td><select name="type">'.(isset($_POST['type']) ? ($_POST['type'] == '0' ? '<option value="0" selected="selected">Gebruiker</option><option value="1">Administrator</option>' : '') : '<option value="0" '.(getUserDetails('Administrator') == 'no' ? 'selected="selected"' : '').'>Gebruiker</option>').(isset($_POST['type']) ? ($_POST['type'] == '1' ? '<option value="0">Gebruiker</option><option value="1" selected="selected">Administrator</option>' : '') : '<option value="1" '.(getUserDetails('Administrator') == 'yes' ? 'selected="selected"' : '').'>Administrator</option>').'</select></td>';
echo '</tr>';
echo '<tr>';
echo '<td>Status</td> <td><select name="status">'.(isset($_POST['status']) ? ($_POST['status'] == '0' ? '<option value="0" selected="selected">Actief</option><option value="1">Niet actief</option>' : '') : '<option value="0" '.(getUserDetails('Active') == 'yes' ? 'selected="selected"' : '').'>Actief</option>').(isset($_POST['status']) ? ($_POST['status'] == '1' ? '<option value="0">Actief</option><option value="1" selected="selected">Niet actief</option>' : '') : '<option value="1" '.(getUserDetails('Active') == 'no' ? 'selected="selected"' : '').'>Niet actief</option>').'</select></td>';
echo '</tr>';
echo '<tr>';
echo '<td></td> <td><input type="submit" name="other" value="Opslaan" /> <input type="submit" name="cancel" value="Annuleren" /></td>';
echo '</tr>';
echo '</table>';
echo '</form>';
echo '</div>';
Nadeel daarvan is, dan je script prima werkt voor iemand met een korte naam die op een kort adres woont:
jo de bie
kerkstr 1
maar dan
jan-willem van hier-tot-ginder en terug
laan van meerdevoort 1542
ineens met een foutmelding geconfronteerd wordt, omdat je dan ineens wel de buffer geleegd hebt.
Hmm, oke! Wat zou hiervoor eventueel een oplossing kunnen zijn om toch de header te kunnen gebruiken?
Als je simpel regel 1 verplaatst naar regel 9, dan is het juist, maar in je script zitten nog meer headers die fout kunnen gaan. Of de headers of output verplaatsen of voor een minder mooie oplossing als meta refresh kiezen.
Gerben Kwakkel op 08/01/2014 10:25:11:
Omdat die als het ware mijn tabjes scheiden.
Je moet dat anders zien.
Het eerste onderscheid dat je moet maken, is:
- PHP logica bovenaan in de code zetten
- HTML genereren / echo'en onderaan de code
Vooraleer je <!doctype html> op het scherm zet, moet je al weten of je header zal gebruiken; of niet.
Die logica kan je perfect helemaal bovenaan het script al uitwerken.
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
echo '<div id="delete">';
if(isset($_POST['delete']))
{
$ssh->exec('zarafa-admin -d "'.getUserDetails('Username').'" && lat-users -d -f -c "'.getUserDetails('Username').'"');
header('Location: index.php?page=user_summary');
}
else
{
echo 'Weet u zeker dat u gebruiker <b>'.getUserDetails('Fullname').'</b> wilt verwijderen?<br /><br />';
echo '<form method="post">';
echo '<input type="submit" name="delete" value="Verwijderen" /> <input type="submit" name="cancel" value="Annuleren" />';
echo '</form>';
}
echo '</div>';
if(isset($_POST['delete']))
{
$ssh->exec('zarafa-admin -d "'.getUserDetails('Username').'" && lat-users -d -f -c "'.getUserDetails('Username').'"');
header('Location: index.php?page=user_summary');
}
else
{
echo 'Weet u zeker dat u gebruiker <b>'.getUserDetails('Fullname').'</b> wilt verwijderen?<br /><br />';
echo '<form method="post">';
echo '<input type="submit" name="delete" value="Verwijderen" /> <input type="submit" name="cancel" value="Annuleren" />';
echo '</form>';
}
echo '</div>';
regel 1 naar regel 11 verplaatsen...
if(isset($_POST['delete'])) is toch op geen enkele wijze afhankelijk van echo '<div id="delete">'; ?
Ik denk nog veel meer. Je begint een html pagina normaal gesproken niet met '<div>', daar zit nog een rits boven. Met andere woorden, gewoon alle php code waarin je een header wilt versturen gewoon boven de eerste output zetten (zoals Kris al meldde). Dat is toch niet zo moeilijk?
Code (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
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
echo '<div id="quota">';
if(isset($_POST['quota']))
{
$error = false;
$errorMessage = array();
if(!is_numeric($_POST['warninglevel']))
{
$error = true;
$errorMessage[] = 'Warning level is ongeldig';
}
elseif($_POST['warninglevel'] > $_POST['softlevel'])
{
$error = true;
$errorMessage[] = 'Warning level mag niet hoger zijn als het soft level';
}
elseif($_POST['warninglevel'] > $_POST['hardlevel'])
{
$error = true;
$errorMessage[] = 'Warning level mag niet hoger zijn als het hard level';
}
if(!is_numeric($_POST['softlevel']))
{
$error = true;
$errorMessage[] = 'Soft level is ongeldig';
}
elseif($_POST['softlevel'] > $_POST['hardlevel'])
{
$error = true;
$errorMessage[] = 'Soft level mag niet hoger zijn als het hard level';
}
elseif($_POST['softlevel'] < $_POST['warninglevel'])
{
$error = true;
$errorMessage[] = 'Soft level mag niet lager zijn als het warning level';
}
if(!is_numeric($_POST['hardlevel']))
{
$error = true;
$errorMessage[] = 'Hard level is ongeldig';
}
elseif($_POST['hardlevel'] < $_POST['softlevel'])
{
$error = true;
$errorMessage[] = 'Hard level mag niet lager zijn als het soft level';
}
elseif($_POST['hardlevel'] < $_POST['warninglevel'])
{
$error = true;
$errorMessage[] = 'Hard level mag niet lager zijn als het warning level';
}
if($error)
{
echo '<p class="error"><b>Er is een probleem opgetreden:</b><br />';
foreach($errorMessage as $message)
{
echo '- '.$message.'<br />';
}
echo '</p>';
}
else
{
$ssh->exec('zarafa-admin -u "'.getUserDetails('Username').'" --qo "'.$_POST['quotasetting'].'" --qw "'.$_POST['warninglevel'].'" --qs "'.$_POST['softlevel'].'" --qh "'.$_POST['hardlevel'].'"');
header('Location: index.php?page=user_view&user='.getUserDetails('Username').'');
}
}
echo '<form method="post">';
echo '<table id="edit" class="user">';
echo '<tr>';
echo '<td>Eigen quota</td> <td><select name="quotasetting">'.(isset($_POST['quotasetting']) ? ($_POST['quotasetting'] == '1' ? '<option value="1" selected="selected">Ja</option><option value="0">Nee</option>' : '') : '<option value="1" '.(getUserDetails('Quota overrides') == 'yes' ? 'selected="selected"' : '').'>Ja</option>').(isset($_POST['quotasetting']) ? ($_POST['quotasetting'] == '0' ? '<option value="1">Ja</option><option value="0" selected="selected">Nee</option>' : '') : '<option value="0" '.(getUserDetails('Quota overrides') == 'no' ? 'selected="selected"' : '').'>Nee</option>').'</select></td>';
echo '</tr>';
echo '<tr>';
echo '<td>Warning level</td> <td><input type="text" name="warninglevel" value="'.(isset($_POST['warninglevel']) ? formValue('warninglevel') : (getUserDetails('Warning level') == 'unlimited' ? '0' : '').(substr(getUserDetails('Warning level'), -2) == 'KB' ? ''.round(getUserDetails('Warning level') / 1024, 0).'' : '').(substr(getUserDetails('Warning level'), -2) == 'MB' ? ''.round(getUserDetails('Warning level'), 0).'' : '')).'" size="3" autocomplete="off" />MB</td>';
echo '</tr>';
echo '<tr>';
echo '<td>Soft level</td> <td><input type="text" name="softlevel" value="'.(isset($_POST['softlevel']) ? formValue('softlevel') : (getUserDetails('Soft level') == 'unlimited' ? '0' : '').(substr(getUserDetails('Soft level'), -2) == 'KB' ? ''.round(getUserDetails('Soft level') / 1024, 0).'' : '').(substr(getUserDetails('Soft level'), -2) == 'MB' ? ''.round(getUserDetails('Soft level'), 0).'' : '')).'" size="3" autocomplete="off" />MB</td>';
echo '</tr>';
echo '<tr>';
echo '<td>Hard level</td> <td><input type="text" name="hardlevel" value="'.(isset($_POST['hardlevel']) ? formValue('hardlevel') : (getUserDetails('Hard level') == 'unlimited' ? '0' : '').(substr(getUserDetails('Hard level'), -2) == 'KB' ? ''.round(getUserDetails('Hard level') / 1024, 0).'' : '').(substr(getUserDetails('Hard level'), -2) == 'MB' ? ''.round(getUserDetails('Hard level'), 0).'' : '')).'" size="3" autocomplete="off" />MB</td>';
echo '</tr>';
echo '<tr>';
echo '<td></td> <td><input type="submit" name="quota" value="Opslaan" /> <input type="submit" name="cancel" value="Annuleren" /></td>';
echo '</tr>';
echo '</table>';
echo '</form>';
echo '</div>';
if(isset($_POST['quota']))
{
$error = false;
$errorMessage = array();
if(!is_numeric($_POST['warninglevel']))
{
$error = true;
$errorMessage[] = 'Warning level is ongeldig';
}
elseif($_POST['warninglevel'] > $_POST['softlevel'])
{
$error = true;
$errorMessage[] = 'Warning level mag niet hoger zijn als het soft level';
}
elseif($_POST['warninglevel'] > $_POST['hardlevel'])
{
$error = true;
$errorMessage[] = 'Warning level mag niet hoger zijn als het hard level';
}
if(!is_numeric($_POST['softlevel']))
{
$error = true;
$errorMessage[] = 'Soft level is ongeldig';
}
elseif($_POST['softlevel'] > $_POST['hardlevel'])
{
$error = true;
$errorMessage[] = 'Soft level mag niet hoger zijn als het hard level';
}
elseif($_POST['softlevel'] < $_POST['warninglevel'])
{
$error = true;
$errorMessage[] = 'Soft level mag niet lager zijn als het warning level';
}
if(!is_numeric($_POST['hardlevel']))
{
$error = true;
$errorMessage[] = 'Hard level is ongeldig';
}
elseif($_POST['hardlevel'] < $_POST['softlevel'])
{
$error = true;
$errorMessage[] = 'Hard level mag niet lager zijn als het soft level';
}
elseif($_POST['hardlevel'] < $_POST['warninglevel'])
{
$error = true;
$errorMessage[] = 'Hard level mag niet lager zijn als het warning level';
}
if($error)
{
echo '<p class="error"><b>Er is een probleem opgetreden:</b><br />';
foreach($errorMessage as $message)
{
echo '- '.$message.'<br />';
}
echo '</p>';
}
else
{
$ssh->exec('zarafa-admin -u "'.getUserDetails('Username').'" --qo "'.$_POST['quotasetting'].'" --qw "'.$_POST['warninglevel'].'" --qs "'.$_POST['softlevel'].'" --qh "'.$_POST['hardlevel'].'"');
header('Location: index.php?page=user_view&user='.getUserDetails('Username').'');
}
}
echo '<form method="post">';
echo '<table id="edit" class="user">';
echo '<tr>';
echo '<td>Eigen quota</td> <td><select name="quotasetting">'.(isset($_POST['quotasetting']) ? ($_POST['quotasetting'] == '1' ? '<option value="1" selected="selected">Ja</option><option value="0">Nee</option>' : '') : '<option value="1" '.(getUserDetails('Quota overrides') == 'yes' ? 'selected="selected"' : '').'>Ja</option>').(isset($_POST['quotasetting']) ? ($_POST['quotasetting'] == '0' ? '<option value="1">Ja</option><option value="0" selected="selected">Nee</option>' : '') : '<option value="0" '.(getUserDetails('Quota overrides') == 'no' ? 'selected="selected"' : '').'>Nee</option>').'</select></td>';
echo '</tr>';
echo '<tr>';
echo '<td>Warning level</td> <td><input type="text" name="warninglevel" value="'.(isset($_POST['warninglevel']) ? formValue('warninglevel') : (getUserDetails('Warning level') == 'unlimited' ? '0' : '').(substr(getUserDetails('Warning level'), -2) == 'KB' ? ''.round(getUserDetails('Warning level') / 1024, 0).'' : '').(substr(getUserDetails('Warning level'), -2) == 'MB' ? ''.round(getUserDetails('Warning level'), 0).'' : '')).'" size="3" autocomplete="off" />MB</td>';
echo '</tr>';
echo '<tr>';
echo '<td>Soft level</td> <td><input type="text" name="softlevel" value="'.(isset($_POST['softlevel']) ? formValue('softlevel') : (getUserDetails('Soft level') == 'unlimited' ? '0' : '').(substr(getUserDetails('Soft level'), -2) == 'KB' ? ''.round(getUserDetails('Soft level') / 1024, 0).'' : '').(substr(getUserDetails('Soft level'), -2) == 'MB' ? ''.round(getUserDetails('Soft level'), 0).'' : '')).'" size="3" autocomplete="off" />MB</td>';
echo '</tr>';
echo '<tr>';
echo '<td>Hard level</td> <td><input type="text" name="hardlevel" value="'.(isset($_POST['hardlevel']) ? formValue('hardlevel') : (getUserDetails('Hard level') == 'unlimited' ? '0' : '').(substr(getUserDetails('Hard level'), -2) == 'KB' ? ''.round(getUserDetails('Hard level') / 1024, 0).'' : '').(substr(getUserDetails('Hard level'), -2) == 'MB' ? ''.round(getUserDetails('Hard level'), 0).'' : '')).'" size="3" autocomplete="off" />MB</td>';
echo '</tr>';
echo '<tr>';
echo '<td></td> <td><input type="submit" name="quota" value="Opslaan" /> <input type="submit" name="cancel" value="Annuleren" /></td>';
echo '</tr>';
echo '</table>';
echo '</form>';
echo '</div>';
Gerben Kwakkel op 17/01/2014 09:10:21:
if en else omdraaien, ipv else nog een if, div naar beneden
Code (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
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
<?php
if(isset($_POST['quota']))
{
$error = false;
$errorMessage = array();
if(!is_numeric($_POST['warninglevel']))
{
$error = true;
$errorMessage[] = 'Warning level is ongeldig';
}
elseif($_POST['warninglevel'] > $_POST['softlevel'])
{
$error = true;
$errorMessage[] = 'Warning level mag niet hoger zijn als het soft level';
}
elseif($_POST['warninglevel'] > $_POST['hardlevel'])
{
$error = true;
$errorMessage[] = 'Warning level mag niet hoger zijn als het hard level';
}
if(!is_numeric($_POST['softlevel']))
{
$error = true;
$errorMessage[] = 'Soft level is ongeldig';
}
elseif($_POST['softlevel'] > $_POST['hardlevel'])
{
$error = true;
$errorMessage[] = 'Soft level mag niet hoger zijn als het hard level';
}
elseif($_POST['softlevel'] < $_POST['warninglevel'])
{
$error = true;
$errorMessage[] = 'Soft level mag niet lager zijn als het warning level';
}
if(!is_numeric($_POST['hardlevel']))
{
$error = true;
$errorMessage[] = 'Hard level is ongeldig';
}
elseif($_POST['hardlevel'] < $_POST['softlevel'])
{
$error = true;
$errorMessage[] = 'Hard level mag niet lager zijn als het soft level';
}
elseif($_POST['hardlevel'] < $_POST['warninglevel'])
{
$error = true;
$errorMessage[] = 'Hard level mag niet lager zijn als het warning level';
}
if($error == false){
$ssh->exec('zarafa-admin -u "'.getUserDetails('Username').'" --qo "'.$_POST['quotasetting'].'" --qw "'.$_POST['warninglevel'].'" --qs "'.$_POST['softlevel'].'" --qh "'.$_POST['hardlevel'].'"');
header('Location: index.php?page=user_view&user='.getUserDetails('Username').'');
}
echo '<div id="quota">';
if($error == true){
echo '<p class="error"><b>Er is een probleem opgetreden:</b><br />';
foreach($errorMessage as $message)
{
echo '- '.$message.'<br />';
}
echo '</p>';
}
}
echo '<form method="post">';
echo '<table id="edit" class="user">';
echo '<tr>';
echo '<td>Eigen quota</td> <td><select name="quotasetting">'.(isset($_POST['quotasetting']) ? ($_POST['quotasetting'] == '1' ? '<option value="1" selected="selected">Ja</option><option value="0">Nee</option>' : '') : '<option value="1" '.(getUserDetails('Quota overrides') == 'yes' ? 'selected="selected"' : '').'>Ja</option>').(isset($_POST['quotasetting']) ? ($_POST['quotasetting'] == '0' ? '<option value="1">Ja</option><option value="0" selected="selected">Nee</option>' : '') : '<option value="0" '.(getUserDetails('Quota overrides') == 'no' ? 'selected="selected"' : '').'>Nee</option>').'</select></td>';
echo '</tr>';
echo '<tr>';
echo '<td>Warning level</td> <td><input type="text" name="warninglevel" value="'.(isset($_POST['warninglevel']) ? formValue('warninglevel') : (getUserDetails('Warning level') == 'unlimited' ? '0' : '').(substr(getUserDetails('Warning level'), -2) == 'KB' ? ''.round(getUserDetails('Warning level') / 1024, 0).'' : '').(substr(getUserDetails('Warning level'), -2) == 'MB' ? ''.round(getUserDetails('Warning level'), 0).'' : '')).'" size="3" autocomplete="off" />MB</td>';
echo '</tr>';
echo '<tr>';
echo '<td>Soft level</td> <td><input type="text" name="softlevel" value="'.(isset($_POST['softlevel']) ? formValue('softlevel') : (getUserDetails('Soft level') == 'unlimited' ? '0' : '').(substr(getUserDetails('Soft level'), -2) == 'KB' ? ''.round(getUserDetails('Soft level') / 1024, 0).'' : '').(substr(getUserDetails('Soft level'), -2) == 'MB' ? ''.round(getUserDetails('Soft level'), 0).'' : '')).'" size="3" autocomplete="off" />MB</td>';
echo '</tr>';
echo '<tr>';
echo '<td>Hard level</td> <td><input type="text" name="hardlevel" value="'.(isset($_POST['hardlevel']) ? formValue('hardlevel') : (getUserDetails('Hard level') == 'unlimited' ? '0' : '').(substr(getUserDetails('Hard level'), -2) == 'KB' ? ''.round(getUserDetails('Hard level') / 1024, 0).'' : '').(substr(getUserDetails('Hard level'), -2) == 'MB' ? ''.round(getUserDetails('Hard level'), 0).'' : '')).'" size="3" autocomplete="off" />MB</td>';
echo '</tr>';
echo '<tr>';
echo '<td></td> <td><input type="submit" name="quota" value="Opslaan" /> <input type="submit" name="cancel" value="Annuleren" /></td>';
echo '</tr>';
echo '</table>';
echo '</form>';
echo '</div>';
?>
if(isset($_POST['quota']))
{
$error = false;
$errorMessage = array();
if(!is_numeric($_POST['warninglevel']))
{
$error = true;
$errorMessage[] = 'Warning level is ongeldig';
}
elseif($_POST['warninglevel'] > $_POST['softlevel'])
{
$error = true;
$errorMessage[] = 'Warning level mag niet hoger zijn als het soft level';
}
elseif($_POST['warninglevel'] > $_POST['hardlevel'])
{
$error = true;
$errorMessage[] = 'Warning level mag niet hoger zijn als het hard level';
}
if(!is_numeric($_POST['softlevel']))
{
$error = true;
$errorMessage[] = 'Soft level is ongeldig';
}
elseif($_POST['softlevel'] > $_POST['hardlevel'])
{
$error = true;
$errorMessage[] = 'Soft level mag niet hoger zijn als het hard level';
}
elseif($_POST['softlevel'] < $_POST['warninglevel'])
{
$error = true;
$errorMessage[] = 'Soft level mag niet lager zijn als het warning level';
}
if(!is_numeric($_POST['hardlevel']))
{
$error = true;
$errorMessage[] = 'Hard level is ongeldig';
}
elseif($_POST['hardlevel'] < $_POST['softlevel'])
{
$error = true;
$errorMessage[] = 'Hard level mag niet lager zijn als het soft level';
}
elseif($_POST['hardlevel'] < $_POST['warninglevel'])
{
$error = true;
$errorMessage[] = 'Hard level mag niet lager zijn als het warning level';
}
if($error == false){
$ssh->exec('zarafa-admin -u "'.getUserDetails('Username').'" --qo "'.$_POST['quotasetting'].'" --qw "'.$_POST['warninglevel'].'" --qs "'.$_POST['softlevel'].'" --qh "'.$_POST['hardlevel'].'"');
header('Location: index.php?page=user_view&user='.getUserDetails('Username').'');
}
echo '<div id="quota">';
if($error == true){
echo '<p class="error"><b>Er is een probleem opgetreden:</b><br />';
foreach($errorMessage as $message)
{
echo '- '.$message.'<br />';
}
echo '</p>';
}
}
echo '<form method="post">';
echo '<table id="edit" class="user">';
echo '<tr>';
echo '<td>Eigen quota</td> <td><select name="quotasetting">'.(isset($_POST['quotasetting']) ? ($_POST['quotasetting'] == '1' ? '<option value="1" selected="selected">Ja</option><option value="0">Nee</option>' : '') : '<option value="1" '.(getUserDetails('Quota overrides') == 'yes' ? 'selected="selected"' : '').'>Ja</option>').(isset($_POST['quotasetting']) ? ($_POST['quotasetting'] == '0' ? '<option value="1">Ja</option><option value="0" selected="selected">Nee</option>' : '') : '<option value="0" '.(getUserDetails('Quota overrides') == 'no' ? 'selected="selected"' : '').'>Nee</option>').'</select></td>';
echo '</tr>';
echo '<tr>';
echo '<td>Warning level</td> <td><input type="text" name="warninglevel" value="'.(isset($_POST['warninglevel']) ? formValue('warninglevel') : (getUserDetails('Warning level') == 'unlimited' ? '0' : '').(substr(getUserDetails('Warning level'), -2) == 'KB' ? ''.round(getUserDetails('Warning level') / 1024, 0).'' : '').(substr(getUserDetails('Warning level'), -2) == 'MB' ? ''.round(getUserDetails('Warning level'), 0).'' : '')).'" size="3" autocomplete="off" />MB</td>';
echo '</tr>';
echo '<tr>';
echo '<td>Soft level</td> <td><input type="text" name="softlevel" value="'.(isset($_POST['softlevel']) ? formValue('softlevel') : (getUserDetails('Soft level') == 'unlimited' ? '0' : '').(substr(getUserDetails('Soft level'), -2) == 'KB' ? ''.round(getUserDetails('Soft level') / 1024, 0).'' : '').(substr(getUserDetails('Soft level'), -2) == 'MB' ? ''.round(getUserDetails('Soft level'), 0).'' : '')).'" size="3" autocomplete="off" />MB</td>';
echo '</tr>';
echo '<tr>';
echo '<td>Hard level</td> <td><input type="text" name="hardlevel" value="'.(isset($_POST['hardlevel']) ? formValue('hardlevel') : (getUserDetails('Hard level') == 'unlimited' ? '0' : '').(substr(getUserDetails('Hard level'), -2) == 'KB' ? ''.round(getUserDetails('Hard level') / 1024, 0).'' : '').(substr(getUserDetails('Hard level'), -2) == 'MB' ? ''.round(getUserDetails('Hard level'), 0).'' : '')).'" size="3" autocomplete="off" />MB</td>';
echo '</tr>';
echo '<tr>';
echo '<td></td> <td><input type="submit" name="quota" value="Opslaan" /> <input type="submit" name="cancel" value="Annuleren" /></td>';
echo '</tr>';
echo '</table>';
echo '</form>';
echo '</div>';
?>
op regel 58 kun je die .'' aan het einde weg laten.
Je kunt ipv $error true,false ook evengoed controleren op $errorMessage.
Je controleert of een formulier gepost is met if($_SERVER['REQUEST_METHOD'] == 'POST')
Gewijzigd op 17/01/2014 09:29:33 door Michael -
Code (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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<?php
echo '<div id="general">';
list($getFirstname, $getLastname) = explode(' ', getUserDetails('Fullname'), 2);
if(isset($_POST['general']))
{
$error = false;
$errorMessage = array();
if(empty($_POST['firstname']) || !preg_match("/^[a-zA-Z -]+$/", $_POST['firstname']))
{
$error = true;
$errorMessage[] = 'Voornaam is ongeldig';
}
if(empty($_POST['lastname']) || !preg_match("/^[a-zA-Z -]+$/", $_POST['lastname']))
{
$error = true;
$errorMessage[] = 'Achternaam is ongeldig';
}
if(empty($_POST['emailaddress']) || !filter_var($_POST['emailaddress'], FILTER_VALIDATE_EMAIL))
{
$error = true;
$errorMessage[] = 'E-mailadres is ongeldig';
}
if($error)
{
echo '<p class="error"><b>Er is een probleem opgetreden:</b><br />';
foreach($errorMessage as $message)
{
echo '- '.$message.'<br />';
}
echo '</p>';
}
else
{
if(empty($_POST['password']) && (empty($_POST['confirm_password'])))
{
$ssh->exec('zarafa-admin -u "'.getUserDetails('Username').'" -f "'.$_POST['firstname'].' '.$_POST['lastname'].'" -e "'.$_POST['emailaddress'].'" && lat-pseudonyms -d -f -c "'.getUserDetails('Username').' | '.str_replace(array(' ', '-'), array('.', '.'), strtolower($getFirstname)).'.'.str_replace(array(' ', '-'), array('.', '.'), strtolower($getLastname)).' | '.str_replace(array(' ', '-'), array('_', '_'), strtolower($getFirstname)).'_'.str_replace(array(' ', '-'), array('_', '_'), strtolower($getLastname)).'" && lat-users -a -c "'.getUserDetails('Username').' | '.$_POST['firstname'].' | '.$_POST['lastname'].'" && lat-pseudonyms -a -c "'.getUserDetails('Username').' | '.str_replace(array(' ', '-'), array('.', '.'), strtolower($_POST['firstname'])).'.'.str_replace(array(' ', '-'), array('.', '.'), strtolower($_POST['lastname'])).' | '.str_replace(array(' ', '-'), array('_', '_'), strtolower($_POST['firstname'])).'_'.str_replace(array(' ', '-'), array('_', '_'), strtolower($_POST['lastname'])).'"');
header('Location: index.php?page=user_view&user='.getUserDetails('Username').'');
}
if(!empty($_POST['password']))
{
$error = false;
$errorMessage = array();
if($_POST['password'] != $_POST['confirm_password'] || !preg_match('~^(?=[^a-z]*[a-z])(?=[^A-Z]*[A-Z])(?=\D*\d)(?=[A-Za-z0-9]*[^A-Za-z0-9])\S{7,}$~', $_POST['password']))
{
$error = true;
$errorMessage[] = 'Wachtwoorden is ongeldig';
}
if($error)
{
echo '<p class="error"><b>Er is een probleem opgetreden:</b><br />';
foreach($errorMessage as $message)
{
echo '- '.$message.'<br />';
}
echo '</p>';
}
else
{
$ssh->exec('zarafa-admin -u "'.getUserDetails('Username').'" -f "'.$_POST['firstname'].' '.$_POST['lastname'].'" -e "'.$_POST['emailaddress'].'" -p "'.$_POST['password'].'" && lat-pseudonyms -d -f -c "'.getUserDetails('Username').' | '.str_replace(array(' ', '-'), array('.', '.'), strtolower($getFirstname)).'.'.str_replace(array(' ', '-'), array('.', '.'), strtolower($getLastname)).' | '.str_replace(array(' ', '-'), array('_', '_'), strtolower($getFirstname)).'_'.str_replace(array(' ', '-'), array('_', '_'), strtolower($getLastname)).'" && lat-users -a -c "'.getUserDetails('Username').' | '.$_POST['firstname'].' | '.$_POST['lastname'].' | '.$_POST['password'].'" && lat-pseudonyms -a -c "'.getUserDetails('Username').' | '.str_replace(array(' ', '-'), array('.', '.'), strtolower($_POST['firstname'])).'.'.str_replace(array(' ', '-'), array('.', '.'), strtolower($_POST['lastname'])).' | '.str_replace(array(' ', '-'), array('_', '_'), strtolower($_POST['firstname'])).'_'.str_replace(array(' ', '-'), array('_', '_'), strtolower($_POST['lastname'])).'"');
header('Location: index.php?page=user_view&user='.getUserDetails('Username').'');
}
}
}
}
echo '<form method="post">';
echo '<table id="edit" class="user">';
echo '<tr>';
echo '<td>Voornaam</td> <td><input type="text" name="firstname" value="'.(isset($_POST['firstname']) ? formValue('firstname') : $getFirstname).'" size="25" autocomplete="off" /></td>';
echo '</tr>';
echo '<tr>';
echo '<td>Achternaam</td> <td><input type="text" name="lastname" value="'.(isset($_POST['lastname']) ? formValue('lastname') : $getLastname).'" size="25" autocomplete="off" /></td>';
echo '</tr>';
echo '<tr>';
echo '<td>E-mailadres</td> <td><input type="text" name="emailaddress" value="'.(isset($_POST['emailaddress']) ? formValue('emailaddress') : getUserDetails('Emailaddress')).'" size="25" autocomplete="off" /></td>';
echo '</tr>';
echo '<tr>';
echo '<td>Wachtwoord</td> <td><input type="password" name="password" value="" size="25" autocomplete="off" /></td>';
echo '</tr>';
echo '<tr>';
echo '<td>Bevestig wachtwoord</td> <td><input type="password" name="confirm_password" value="" size="25" autocomplete="off" /></td>';
echo '</tr>';
echo '<tr>';
echo '<td></td> <td><input type="submit" name="general" value="Opslaan" /> <input type="submit" name="cancel" value="Annuleren" /></td>';
echo '</tr>';
echo '</table>';
echo '</form>';
echo '</div>';
echo '<div id="quota">';
if(isset($_POST['quota']))
{
$error = false;
$errorMessage = array();
if(!is_numeric($_POST['warninglevel']))
{
$error = true;
$errorMessage[] = 'Warning level is ongeldig';
}
elseif($_POST['warninglevel'] > $_POST['softlevel'])
{
$error = true;
$errorMessage[] = 'Warning level mag niet hoger zijn als het soft level';
}
elseif($_POST['warninglevel'] > $_POST['hardlevel'])
{
$error = true;
$errorMessage[] = 'Warning level mag niet hoger zijn als het hard level';
}
if(!is_numeric($_POST['softlevel']))
{
$error = true;
$errorMessage[] = 'Soft level is ongeldig';
}
elseif($_POST['softlevel'] > $_POST['hardlevel'])
{
$error = true;
$errorMessage[] = 'Soft level mag niet hoger zijn als het hard level';
}
elseif($_POST['softlevel'] < $_POST['warninglevel'])
{
$error = true;
$errorMessage[] = 'Soft level mag niet lager zijn als het warning level';
}
if(!is_numeric($_POST['hardlevel']))
{
$error = true;
$errorMessage[] = 'Hard level is ongeldig';
}
elseif($_POST['hardlevel'] < $_POST['softlevel'])
{
$error = true;
$errorMessage[] = 'Hard level mag niet lager zijn als het soft level';
}
elseif($_POST['hardlevel'] < $_POST['warninglevel'])
{
$error = true;
$errorMessage[] = 'Hard level mag niet lager zijn als het warning level';
}
if($error)
{
echo '<p class="error"><b>Er is een probleem opgetreden:</b><br />';
foreach($errorMessage as $message)
{
echo '- '.$message.'<br />';
}
echo '</p>';
}
else
{
$ssh->exec('zarafa-admin -u "'.getUserDetails('Username').'" --qo "'.$_POST['quotasetting'].'" --qw "'.$_POST['warninglevel'].'" --qs "'.$_POST['softlevel'].'" --qh "'.$_POST['hardlevel'].'"');
header('Location: index.php?page=user_view&user='.getUserDetails('Username').'');
}
}
echo '<form method="post">';
echo '<table id="edit" class="user">';
echo '<tr>';
echo '<td>Eigen quota</td> <td><select name="quotasetting">'.(isset($_POST['quotasetting']) ? ($_POST['quotasetting'] == '1' ? '<option value="1" selected="selected">Ja</option><option value="0">Nee</option>' : '') : '<option value="1" '.(getUserDetails('Quota overrides') == 'yes' ? 'selected="selected"' : '').'>Ja</option>').(isset($_POST['quotasetting']) ? ($_POST['quotasetting'] == '0' ? '<option value="1">Ja</option><option value="0" selected="selected">Nee</option>' : '') : '<option value="0" '.(getUserDetails('Quota overrides') == 'no' ? 'selected="selected"' : '').'>Nee</option>').'</select></td>';
echo '</tr>';
echo '<tr>';
echo '<td>Warning level</td> <td><input type="text" name="warninglevel" value="'.(isset($_POST['warninglevel']) ? formValue('warninglevel') : (getUserDetails('Warning level') == 'unlimited' ? '0' : '').(substr(getUserDetails('Warning level'), -2) == 'KB' ? ''.round(getUserDetails('Warning level') / 1024, 0).'' : '').(substr(getUserDetails('Warning level'), -2) == 'MB' ? ''.round(getUserDetails('Warning level'), 0).'' : '')).'" size="3" autocomplete="off" />MB</td>';
echo '</tr>';
echo '<tr>';
echo '<td>Soft level</td> <td><input type="text" name="softlevel" value="'.(isset($_POST['softlevel']) ? formValue('softlevel') : (getUserDetails('Soft level') == 'unlimited' ? '0' : '').(substr(getUserDetails('Soft level'), -2) == 'KB' ? ''.round(getUserDetails('Soft level') / 1024, 0).'' : '').(substr(getUserDetails('Soft level'), -2) == 'MB' ? ''.round(getUserDetails('Soft level'), 0).'' : '')).'" size="3" autocomplete="off" />MB</td>';
echo '</tr>';
echo '<tr>';
echo '<td>Hard level</td> <td><input type="text" name="hardlevel" value="'.(isset($_POST['hardlevel']) ? formValue('hardlevel') : (getUserDetails('Hard level') == 'unlimited' ? '0' : '').(substr(getUserDetails('Hard level'), -2) == 'KB' ? ''.round(getUserDetails('Hard level') / 1024, 0).'' : '').(substr(getUserDetails('Hard level'), -2) == 'MB' ? ''.round(getUserDetails('Hard level'), 0).'' : '')).'" size="3" autocomplete="off" />MB</td>';
echo '</tr>';
echo '<tr>';
echo '<td></td> <td><input type="submit" name="quota" value="Opslaan" /> <input type="submit" name="cancel" value="Annuleren" /></td>';
echo '</tr>';
echo '</table>';
echo '</form>';
echo '</div>';
?>
echo '<div id="general">';
list($getFirstname, $getLastname) = explode(' ', getUserDetails('Fullname'), 2);
if(isset($_POST['general']))
{
$error = false;
$errorMessage = array();
if(empty($_POST['firstname']) || !preg_match("/^[a-zA-Z -]+$/", $_POST['firstname']))
{
$error = true;
$errorMessage[] = 'Voornaam is ongeldig';
}
if(empty($_POST['lastname']) || !preg_match("/^[a-zA-Z -]+$/", $_POST['lastname']))
{
$error = true;
$errorMessage[] = 'Achternaam is ongeldig';
}
if(empty($_POST['emailaddress']) || !filter_var($_POST['emailaddress'], FILTER_VALIDATE_EMAIL))
{
$error = true;
$errorMessage[] = 'E-mailadres is ongeldig';
}
if($error)
{
echo '<p class="error"><b>Er is een probleem opgetreden:</b><br />';
foreach($errorMessage as $message)
{
echo '- '.$message.'<br />';
}
echo '</p>';
}
else
{
if(empty($_POST['password']) && (empty($_POST['confirm_password'])))
{
$ssh->exec('zarafa-admin -u "'.getUserDetails('Username').'" -f "'.$_POST['firstname'].' '.$_POST['lastname'].'" -e "'.$_POST['emailaddress'].'" && lat-pseudonyms -d -f -c "'.getUserDetails('Username').' | '.str_replace(array(' ', '-'), array('.', '.'), strtolower($getFirstname)).'.'.str_replace(array(' ', '-'), array('.', '.'), strtolower($getLastname)).' | '.str_replace(array(' ', '-'), array('_', '_'), strtolower($getFirstname)).'_'.str_replace(array(' ', '-'), array('_', '_'), strtolower($getLastname)).'" && lat-users -a -c "'.getUserDetails('Username').' | '.$_POST['firstname'].' | '.$_POST['lastname'].'" && lat-pseudonyms -a -c "'.getUserDetails('Username').' | '.str_replace(array(' ', '-'), array('.', '.'), strtolower($_POST['firstname'])).'.'.str_replace(array(' ', '-'), array('.', '.'), strtolower($_POST['lastname'])).' | '.str_replace(array(' ', '-'), array('_', '_'), strtolower($_POST['firstname'])).'_'.str_replace(array(' ', '-'), array('_', '_'), strtolower($_POST['lastname'])).'"');
header('Location: index.php?page=user_view&user='.getUserDetails('Username').'');
}
if(!empty($_POST['password']))
{
$error = false;
$errorMessage = array();
if($_POST['password'] != $_POST['confirm_password'] || !preg_match('~^(?=[^a-z]*[a-z])(?=[^A-Z]*[A-Z])(?=\D*\d)(?=[A-Za-z0-9]*[^A-Za-z0-9])\S{7,}$~', $_POST['password']))
{
$error = true;
$errorMessage[] = 'Wachtwoorden is ongeldig';
}
if($error)
{
echo '<p class="error"><b>Er is een probleem opgetreden:</b><br />';
foreach($errorMessage as $message)
{
echo '- '.$message.'<br />';
}
echo '</p>';
}
else
{
$ssh->exec('zarafa-admin -u "'.getUserDetails('Username').'" -f "'.$_POST['firstname'].' '.$_POST['lastname'].'" -e "'.$_POST['emailaddress'].'" -p "'.$_POST['password'].'" && lat-pseudonyms -d -f -c "'.getUserDetails('Username').' | '.str_replace(array(' ', '-'), array('.', '.'), strtolower($getFirstname)).'.'.str_replace(array(' ', '-'), array('.', '.'), strtolower($getLastname)).' | '.str_replace(array(' ', '-'), array('_', '_'), strtolower($getFirstname)).'_'.str_replace(array(' ', '-'), array('_', '_'), strtolower($getLastname)).'" && lat-users -a -c "'.getUserDetails('Username').' | '.$_POST['firstname'].' | '.$_POST['lastname'].' | '.$_POST['password'].'" && lat-pseudonyms -a -c "'.getUserDetails('Username').' | '.str_replace(array(' ', '-'), array('.', '.'), strtolower($_POST['firstname'])).'.'.str_replace(array(' ', '-'), array('.', '.'), strtolower($_POST['lastname'])).' | '.str_replace(array(' ', '-'), array('_', '_'), strtolower($_POST['firstname'])).'_'.str_replace(array(' ', '-'), array('_', '_'), strtolower($_POST['lastname'])).'"');
header('Location: index.php?page=user_view&user='.getUserDetails('Username').'');
}
}
}
}
echo '<form method="post">';
echo '<table id="edit" class="user">';
echo '<tr>';
echo '<td>Voornaam</td> <td><input type="text" name="firstname" value="'.(isset($_POST['firstname']) ? formValue('firstname') : $getFirstname).'" size="25" autocomplete="off" /></td>';
echo '</tr>';
echo '<tr>';
echo '<td>Achternaam</td> <td><input type="text" name="lastname" value="'.(isset($_POST['lastname']) ? formValue('lastname') : $getLastname).'" size="25" autocomplete="off" /></td>';
echo '</tr>';
echo '<tr>';
echo '<td>E-mailadres</td> <td><input type="text" name="emailaddress" value="'.(isset($_POST['emailaddress']) ? formValue('emailaddress') : getUserDetails('Emailaddress')).'" size="25" autocomplete="off" /></td>';
echo '</tr>';
echo '<tr>';
echo '<td>Wachtwoord</td> <td><input type="password" name="password" value="" size="25" autocomplete="off" /></td>';
echo '</tr>';
echo '<tr>';
echo '<td>Bevestig wachtwoord</td> <td><input type="password" name="confirm_password" value="" size="25" autocomplete="off" /></td>';
echo '</tr>';
echo '<tr>';
echo '<td></td> <td><input type="submit" name="general" value="Opslaan" /> <input type="submit" name="cancel" value="Annuleren" /></td>';
echo '</tr>';
echo '</table>';
echo '</form>';
echo '</div>';
echo '<div id="quota">';
if(isset($_POST['quota']))
{
$error = false;
$errorMessage = array();
if(!is_numeric($_POST['warninglevel']))
{
$error = true;
$errorMessage[] = 'Warning level is ongeldig';
}
elseif($_POST['warninglevel'] > $_POST['softlevel'])
{
$error = true;
$errorMessage[] = 'Warning level mag niet hoger zijn als het soft level';
}
elseif($_POST['warninglevel'] > $_POST['hardlevel'])
{
$error = true;
$errorMessage[] = 'Warning level mag niet hoger zijn als het hard level';
}
if(!is_numeric($_POST['softlevel']))
{
$error = true;
$errorMessage[] = 'Soft level is ongeldig';
}
elseif($_POST['softlevel'] > $_POST['hardlevel'])
{
$error = true;
$errorMessage[] = 'Soft level mag niet hoger zijn als het hard level';
}
elseif($_POST['softlevel'] < $_POST['warninglevel'])
{
$error = true;
$errorMessage[] = 'Soft level mag niet lager zijn als het warning level';
}
if(!is_numeric($_POST['hardlevel']))
{
$error = true;
$errorMessage[] = 'Hard level is ongeldig';
}
elseif($_POST['hardlevel'] < $_POST['softlevel'])
{
$error = true;
$errorMessage[] = 'Hard level mag niet lager zijn als het soft level';
}
elseif($_POST['hardlevel'] < $_POST['warninglevel'])
{
$error = true;
$errorMessage[] = 'Hard level mag niet lager zijn als het warning level';
}
if($error)
{
echo '<p class="error"><b>Er is een probleem opgetreden:</b><br />';
foreach($errorMessage as $message)
{
echo '- '.$message.'<br />';
}
echo '</p>';
}
else
{
$ssh->exec('zarafa-admin -u "'.getUserDetails('Username').'" --qo "'.$_POST['quotasetting'].'" --qw "'.$_POST['warninglevel'].'" --qs "'.$_POST['softlevel'].'" --qh "'.$_POST['hardlevel'].'"');
header('Location: index.php?page=user_view&user='.getUserDetails('Username').'');
}
}
echo '<form method="post">';
echo '<table id="edit" class="user">';
echo '<tr>';
echo '<td>Eigen quota</td> <td><select name="quotasetting">'.(isset($_POST['quotasetting']) ? ($_POST['quotasetting'] == '1' ? '<option value="1" selected="selected">Ja</option><option value="0">Nee</option>' : '') : '<option value="1" '.(getUserDetails('Quota overrides') == 'yes' ? 'selected="selected"' : '').'>Ja</option>').(isset($_POST['quotasetting']) ? ($_POST['quotasetting'] == '0' ? '<option value="1">Ja</option><option value="0" selected="selected">Nee</option>' : '') : '<option value="0" '.(getUserDetails('Quota overrides') == 'no' ? 'selected="selected"' : '').'>Nee</option>').'</select></td>';
echo '</tr>';
echo '<tr>';
echo '<td>Warning level</td> <td><input type="text" name="warninglevel" value="'.(isset($_POST['warninglevel']) ? formValue('warninglevel') : (getUserDetails('Warning level') == 'unlimited' ? '0' : '').(substr(getUserDetails('Warning level'), -2) == 'KB' ? ''.round(getUserDetails('Warning level') / 1024, 0).'' : '').(substr(getUserDetails('Warning level'), -2) == 'MB' ? ''.round(getUserDetails('Warning level'), 0).'' : '')).'" size="3" autocomplete="off" />MB</td>';
echo '</tr>';
echo '<tr>';
echo '<td>Soft level</td> <td><input type="text" name="softlevel" value="'.(isset($_POST['softlevel']) ? formValue('softlevel') : (getUserDetails('Soft level') == 'unlimited' ? '0' : '').(substr(getUserDetails('Soft level'), -2) == 'KB' ? ''.round(getUserDetails('Soft level') / 1024, 0).'' : '').(substr(getUserDetails('Soft level'), -2) == 'MB' ? ''.round(getUserDetails('Soft level'), 0).'' : '')).'" size="3" autocomplete="off" />MB</td>';
echo '</tr>';
echo '<tr>';
echo '<td>Hard level</td> <td><input type="text" name="hardlevel" value="'.(isset($_POST['hardlevel']) ? formValue('hardlevel') : (getUserDetails('Hard level') == 'unlimited' ? '0' : '').(substr(getUserDetails('Hard level'), -2) == 'KB' ? ''.round(getUserDetails('Hard level') / 1024, 0).'' : '').(substr(getUserDetails('Hard level'), -2) == 'MB' ? ''.round(getUserDetails('Hard level'), 0).'' : '')).'" size="3" autocomplete="off" />MB</td>';
echo '</tr>';
echo '<tr>';
echo '<td></td> <td><input type="submit" name="quota" value="Opslaan" /> <input type="submit" name="cancel" value="Annuleren" /></td>';
echo '</tr>';
echo '</table>';
echo '</form>';
echo '</div>';
?>
Helemaal boven aan begin je met if($_SERVER['REQUEST_METHOD'] == 'POST')
Daarna kijk je welk formulier is gepost, quota of general.
Op basis van welk formulier doe je de controles voor de velden, sla je errors op in variabelen en bij OK stuur je header.
Daarna komt je html gedeelte <html>... <div>
Vervolgens ga je controleren of er errors zijn en zo ja deze weergeven.
Daarna de formulieren etc.
Toevoeging op 17/01/2014 11:20:28:
Hopelijk helpt dit je verder op weg. Ik heb het error gedeelte eruit gehaald, ik controleer in plaats daarvan op errorMessage.
Je wachtwoord controle is een beetje vreemd en je inputs blijven niet onthouden naar de post, maar dat zijn dan nog dingen die je zelf kunt verbeteren.
Code (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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<?php
list($getFirstname, $getLastname) = explode(' ', getUserDetails('Fullname'), 2);
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$errorMessage = array();
if(isset($_POST['general']))
{
if(empty($_POST['firstname']) || !preg_match("/^[a-zA-Z -]+$/", $_POST['firstname']))
{
$errorMessage['general'][] = 'Voornaam is ongeldig';
}
if(empty($_POST['lastname']) || !preg_match("/^[a-zA-Z -]+$/", $_POST['lastname']))
{
$errorMessage['general'][] = 'Achternaam is ongeldig';
}
if(empty($_POST['emailaddress']) || !filter_var($_POST['emailaddress'], FILTER_VALIDATE_EMAIL))
{
$errorMessage['general'][] = 'E-mailadres is ongeldig';
}
if(!isset($errorMessage['general']) || count($errorMessage['general']) == 0)
{
if(empty($_POST['password']) && (empty($_POST['confirm_password'])))
{
$ssh->exec('zarafa-admin -u "'.getUserDetails('Username').'" -f "'.$_POST['firstname'].' '.$_POST['lastname'].'" -e "'.$_POST['emailaddress'].'" && lat-pseudonyms -d -f -c "'.getUserDetails('Username').' | '.str_replace(array(' ', '-'), array('.', '.'), strtolower($getFirstname)).'.'.str_replace(array(' ', '-'), array('.', '.'), strtolower($getLastname)).' | '.str_replace(array(' ', '-'), array('_', '_'), strtolower($getFirstname)).'_'.str_replace(array(' ', '-'), array('_', '_'), strtolower($getLastname)).'" && lat-users -a -c "'.getUserDetails('Username').' | '.$_POST['firstname'].' | '.$_POST['lastname'].'" && lat-pseudonyms -a -c "'.getUserDetails('Username').' | '.str_replace(array(' ', '-'), array('.', '.'), strtolower($_POST['firstname'])).'.'.str_replace(array(' ', '-'), array('.', '.'), strtolower($_POST['lastname'])).' | '.str_replace(array(' ', '-'), array('_', '_'), strtolower($_POST['firstname'])).'_'.str_replace(array(' ', '-'), array('_', '_'), strtolower($_POST['lastname'])).'"');
header('Location: index.php?page=user_view&user='.getUserDetails('Username'));
}
if(!empty($_POST['password']))
{
if($_POST['password'] != $_POST['confirm_password'] || !preg_match('~^(?=[^a-z]*[a-z])(?=[^A-Z]*[A-Z])(?=\D*\d)(?=[A-Za-z0-9]*[^A-Za-z0-9])\S{7,}$~', $_POST['password']))
{
$errorMessage['general'][] = 'Wachtwoorden is ongeldig';
}
if(!isset($errorMessage['general']) || count($errorMessage['general']) == 0)
{
$ssh->exec('zarafa-admin -u "'.getUserDetails('Username').'" -f "'.$_POST['firstname'].' '.$_POST['lastname'].'" -e "'.$_POST['emailaddress'].'" -p "'.$_POST['password'].'" && lat-pseudonyms -d -f -c "'.getUserDetails('Username').' | '.str_replace(array(' ', '-'), array('.', '.'), strtolower($getFirstname)).'.'.str_replace(array(' ', '-'), array('.', '.'), strtolower($getLastname)).' | '.str_replace(array(' ', '-'), array('_', '_'), strtolower($getFirstname)).'_'.str_replace(array(' ', '-'), array('_', '_'), strtolower($getLastname)).'" && lat-users -a -c "'.getUserDetails('Username').' | '.$_POST['firstname'].' | '.$_POST['lastname'].' | '.$_POST['password'].'" && lat-pseudonyms -a -c "'.getUserDetails('Username').' | '.str_replace(array(' ', '-'), array('.', '.'), strtolower($_POST['firstname'])).'.'.str_replace(array(' ', '-'), array('.', '.'), strtolower($_POST['lastname'])).' | '.str_replace(array(' ', '-'), array('_', '_'), strtolower($_POST['firstname'])).'_'.str_replace(array(' ', '-'), array('_', '_'), strtolower($_POST['lastname'])).'"');
header('Location: index.php?page=user_view&user='.getUserDetails('Username'));
}
}
}
}
else if(isset($_POST['quota']))
{
if(!is_numeric($_POST['warninglevel']))
{
$errorMessage['quota'][] = 'Warning level is ongeldig';
}
elseif($_POST['warninglevel'] > $_POST['softlevel'])
{
$errorMessage['quota'][] = 'Warning level mag niet hoger zijn als het soft level';
}
elseif($_POST['warninglevel'] > $_POST['hardlevel'])
{
$errorMessage['quota'][] = 'Warning level mag niet hoger zijn als het hard level';
}
if(!is_numeric($_POST['softlevel']))
{
$errorMessage['quota'][] = 'Soft level is ongeldig';
}
elseif($_POST['softlevel'] > $_POST['hardlevel'])
{
$errorMessage['quota'][] = 'Soft level mag niet hoger zijn als het hard level';
}
elseif($_POST['softlevel'] < $_POST['warninglevel'])
{
$errorMessage['quota'][] = 'Soft level mag niet lager zijn als het warning level';
}
if(!is_numeric($_POST['hardlevel']))
{
$errorMessage['quota'][] = 'Hard level is ongeldig';
}
elseif($_POST['hardlevel'] < $_POST['softlevel'])
{
$errorMessage['quota'][] = 'Hard level mag niet lager zijn als het soft level';
}
elseif($_POST['hardlevel'] < $_POST['warninglevel'])
{
$errorMessage['quota'][] = 'Hard level mag niet lager zijn als het warning level';
}
if(!isset($errorMessage['quota']) || count($errorMessage['quota']) == 0)
{
$ssh->exec('zarafa-admin -u "'.getUserDetails('Username').'" --qo "'.$_POST['quotasetting'].'" --qw "'.$_POST['warninglevel'].'" --qs "'.$_POST['softlevel'].'" --qh "'.$_POST['hardlevel'].'"');
header('Location: index.php?page=user_view&user='.getUserDetails('Username'));
}
}
}
echo '<div id="general">';
if(isset($errorMessage['general']) && count($errorMessage['general'] > 0))
{
echo '<p class="error"><b>Er is een probleem opgetreden:</b><br />';
foreach($errorMessage['general'] as $message)
{
echo '- '.$message.'<br />';
}
echo '</p>';
}
echo '<form method="post">';
echo '<table id="edit" class="user">';
echo '<tr>';
echo '<td>Voornaam</td> <td><input type="text" name="firstname" value="'.(isset($_POST['firstname']) ? formValue('firstname') : $getFirstname).'" size="25" autocomplete="off" /></td>';
echo '</tr>';
echo '<tr>';
echo '<td>Achternaam</td> <td><input type="text" name="lastname" value="'.(isset($_POST['lastname']) ? formValue('lastname') : $getLastname).'" size="25" autocomplete="off" /></td>';
echo '</tr>';
echo '<tr>';
echo '<td>E-mailadres</td> <td><input type="text" name="emailaddress" value="'.(isset($_POST['emailaddress']) ? formValue('emailaddress') : getUserDetails('Emailaddress')).'" size="25" autocomplete="off" /></td>';
echo '</tr>';
echo '<tr>';
echo '<td>Wachtwoord</td> <td><input type="password" name="password" value="" size="25" autocomplete="off" /></td>';
echo '</tr>';
echo '<tr>';
echo '<td>Bevestig wachtwoord</td> <td><input type="password" name="confirm_password" value="" size="25" autocomplete="off" /></td>';
echo '</tr>';
echo '<tr>';
echo '<td></td> <td><input type="submit" name="general" value="Opslaan" /> <input type="submit" name="cancel" value="Annuleren" /></td>';
echo '</tr>';
echo '</table>';
echo '</form>';
echo '</div>';
echo '<div id="quota">';
if(isset($errorMessage['quota']) && count($errorMessage['quota'] > 0))
{
echo '<p class="error"><b>Er is een probleem opgetreden:</b><br />';
foreach($errorMessage['quota'] as $message)
{
echo '- '.$message.'<br />';
}
echo '</p>';
}
echo '<form method="post">';
echo '<table id="edit" class="user">';
echo '<tr>';
echo '<td>Eigen quota</td> <td><select name="quotasetting">'.(isset($_POST['quotasetting']) ? ($_POST['quotasetting'] == '1' ? '<option value="1" selected="selected">Ja</option><option value="0">Nee</option>' : '') : '<option value="1" '.(getUserDetails('Quota overrides') == 'yes' ? 'selected="selected"' : '').'>Ja</option>').(isset($_POST['quotasetting']) ? ($_POST['quotasetting'] == '0' ? '<option value="1">Ja</option><option value="0" selected="selected">Nee</option>' : '') : '<option value="0" '.(getUserDetails('Quota overrides') == 'no' ? 'selected="selected"' : '').'>Nee</option>').'</select></td>';
echo '</tr>';
echo '<tr>';
echo '<td>Warning level</td> <td><input type="text" name="warninglevel" value="'.(isset($_POST['warninglevel']) ? formValue('warninglevel') : (getUserDetails('Warning level') == 'unlimited' ? '0' : '').(substr(getUserDetails('Warning level'), -2) == 'KB' ? ''.round(getUserDetails('Warning level') / 1024, 0).'' : '').(substr(getUserDetails('Warning level'), -2) == 'MB' ? ''.round(getUserDetails('Warning level'), 0).'' : '')).'" size="3" autocomplete="off" />MB</td>';
echo '</tr>';
echo '<tr>';
echo '<td>Soft level</td> <td><input type="text" name="softlevel" value="'.(isset($_POST['softlevel']) ? formValue('softlevel') : (getUserDetails('Soft level') == 'unlimited' ? '0' : '').(substr(getUserDetails('Soft level'), -2) == 'KB' ? ''.round(getUserDetails('Soft level') / 1024, 0).'' : '').(substr(getUserDetails('Soft level'), -2) == 'MB' ? ''.round(getUserDetails('Soft level'), 0).'' : '')).'" size="3" autocomplete="off" />MB</td>';
echo '</tr>';
echo '<tr>';
echo '<td>Hard level</td> <td><input type="text" name="hardlevel" value="'.(isset($_POST['hardlevel']) ? formValue('hardlevel') : (getUserDetails('Hard level') == 'unlimited' ? '0' : '').(substr(getUserDetails('Hard level'), -2) == 'KB' ? ''.round(getUserDetails('Hard level') / 1024, 0).'' : '').(substr(getUserDetails('Hard level'), -2) == 'MB' ? ''.round(getUserDetails('Hard level'), 0).'' : '')).'" size="3" autocomplete="off" />MB</td>';
echo '</tr>';
echo '<tr>';
echo '<td></td> <td><input type="submit" name="quota" value="Opslaan" /> <input type="submit" name="cancel" value="Annuleren" /></td>';
echo '</tr>';
echo '</table>';
echo '</form>';
echo '</div>';
?>
list($getFirstname, $getLastname) = explode(' ', getUserDetails('Fullname'), 2);
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$errorMessage = array();
if(isset($_POST['general']))
{
if(empty($_POST['firstname']) || !preg_match("/^[a-zA-Z -]+$/", $_POST['firstname']))
{
$errorMessage['general'][] = 'Voornaam is ongeldig';
}
if(empty($_POST['lastname']) || !preg_match("/^[a-zA-Z -]+$/", $_POST['lastname']))
{
$errorMessage['general'][] = 'Achternaam is ongeldig';
}
if(empty($_POST['emailaddress']) || !filter_var($_POST['emailaddress'], FILTER_VALIDATE_EMAIL))
{
$errorMessage['general'][] = 'E-mailadres is ongeldig';
}
if(!isset($errorMessage['general']) || count($errorMessage['general']) == 0)
{
if(empty($_POST['password']) && (empty($_POST['confirm_password'])))
{
$ssh->exec('zarafa-admin -u "'.getUserDetails('Username').'" -f "'.$_POST['firstname'].' '.$_POST['lastname'].'" -e "'.$_POST['emailaddress'].'" && lat-pseudonyms -d -f -c "'.getUserDetails('Username').' | '.str_replace(array(' ', '-'), array('.', '.'), strtolower($getFirstname)).'.'.str_replace(array(' ', '-'), array('.', '.'), strtolower($getLastname)).' | '.str_replace(array(' ', '-'), array('_', '_'), strtolower($getFirstname)).'_'.str_replace(array(' ', '-'), array('_', '_'), strtolower($getLastname)).'" && lat-users -a -c "'.getUserDetails('Username').' | '.$_POST['firstname'].' | '.$_POST['lastname'].'" && lat-pseudonyms -a -c "'.getUserDetails('Username').' | '.str_replace(array(' ', '-'), array('.', '.'), strtolower($_POST['firstname'])).'.'.str_replace(array(' ', '-'), array('.', '.'), strtolower($_POST['lastname'])).' | '.str_replace(array(' ', '-'), array('_', '_'), strtolower($_POST['firstname'])).'_'.str_replace(array(' ', '-'), array('_', '_'), strtolower($_POST['lastname'])).'"');
header('Location: index.php?page=user_view&user='.getUserDetails('Username'));
}
if(!empty($_POST['password']))
{
if($_POST['password'] != $_POST['confirm_password'] || !preg_match('~^(?=[^a-z]*[a-z])(?=[^A-Z]*[A-Z])(?=\D*\d)(?=[A-Za-z0-9]*[^A-Za-z0-9])\S{7,}$~', $_POST['password']))
{
$errorMessage['general'][] = 'Wachtwoorden is ongeldig';
}
if(!isset($errorMessage['general']) || count($errorMessage['general']) == 0)
{
$ssh->exec('zarafa-admin -u "'.getUserDetails('Username').'" -f "'.$_POST['firstname'].' '.$_POST['lastname'].'" -e "'.$_POST['emailaddress'].'" -p "'.$_POST['password'].'" && lat-pseudonyms -d -f -c "'.getUserDetails('Username').' | '.str_replace(array(' ', '-'), array('.', '.'), strtolower($getFirstname)).'.'.str_replace(array(' ', '-'), array('.', '.'), strtolower($getLastname)).' | '.str_replace(array(' ', '-'), array('_', '_'), strtolower($getFirstname)).'_'.str_replace(array(' ', '-'), array('_', '_'), strtolower($getLastname)).'" && lat-users -a -c "'.getUserDetails('Username').' | '.$_POST['firstname'].' | '.$_POST['lastname'].' | '.$_POST['password'].'" && lat-pseudonyms -a -c "'.getUserDetails('Username').' | '.str_replace(array(' ', '-'), array('.', '.'), strtolower($_POST['firstname'])).'.'.str_replace(array(' ', '-'), array('.', '.'), strtolower($_POST['lastname'])).' | '.str_replace(array(' ', '-'), array('_', '_'), strtolower($_POST['firstname'])).'_'.str_replace(array(' ', '-'), array('_', '_'), strtolower($_POST['lastname'])).'"');
header('Location: index.php?page=user_view&user='.getUserDetails('Username'));
}
}
}
}
else if(isset($_POST['quota']))
{
if(!is_numeric($_POST['warninglevel']))
{
$errorMessage['quota'][] = 'Warning level is ongeldig';
}
elseif($_POST['warninglevel'] > $_POST['softlevel'])
{
$errorMessage['quota'][] = 'Warning level mag niet hoger zijn als het soft level';
}
elseif($_POST['warninglevel'] > $_POST['hardlevel'])
{
$errorMessage['quota'][] = 'Warning level mag niet hoger zijn als het hard level';
}
if(!is_numeric($_POST['softlevel']))
{
$errorMessage['quota'][] = 'Soft level is ongeldig';
}
elseif($_POST['softlevel'] > $_POST['hardlevel'])
{
$errorMessage['quota'][] = 'Soft level mag niet hoger zijn als het hard level';
}
elseif($_POST['softlevel'] < $_POST['warninglevel'])
{
$errorMessage['quota'][] = 'Soft level mag niet lager zijn als het warning level';
}
if(!is_numeric($_POST['hardlevel']))
{
$errorMessage['quota'][] = 'Hard level is ongeldig';
}
elseif($_POST['hardlevel'] < $_POST['softlevel'])
{
$errorMessage['quota'][] = 'Hard level mag niet lager zijn als het soft level';
}
elseif($_POST['hardlevel'] < $_POST['warninglevel'])
{
$errorMessage['quota'][] = 'Hard level mag niet lager zijn als het warning level';
}
if(!isset($errorMessage['quota']) || count($errorMessage['quota']) == 0)
{
$ssh->exec('zarafa-admin -u "'.getUserDetails('Username').'" --qo "'.$_POST['quotasetting'].'" --qw "'.$_POST['warninglevel'].'" --qs "'.$_POST['softlevel'].'" --qh "'.$_POST['hardlevel'].'"');
header('Location: index.php?page=user_view&user='.getUserDetails('Username'));
}
}
}
echo '<div id="general">';
if(isset($errorMessage['general']) && count($errorMessage['general'] > 0))
{
echo '<p class="error"><b>Er is een probleem opgetreden:</b><br />';
foreach($errorMessage['general'] as $message)
{
echo '- '.$message.'<br />';
}
echo '</p>';
}
echo '<form method="post">';
echo '<table id="edit" class="user">';
echo '<tr>';
echo '<td>Voornaam</td> <td><input type="text" name="firstname" value="'.(isset($_POST['firstname']) ? formValue('firstname') : $getFirstname).'" size="25" autocomplete="off" /></td>';
echo '</tr>';
echo '<tr>';
echo '<td>Achternaam</td> <td><input type="text" name="lastname" value="'.(isset($_POST['lastname']) ? formValue('lastname') : $getLastname).'" size="25" autocomplete="off" /></td>';
echo '</tr>';
echo '<tr>';
echo '<td>E-mailadres</td> <td><input type="text" name="emailaddress" value="'.(isset($_POST['emailaddress']) ? formValue('emailaddress') : getUserDetails('Emailaddress')).'" size="25" autocomplete="off" /></td>';
echo '</tr>';
echo '<tr>';
echo '<td>Wachtwoord</td> <td><input type="password" name="password" value="" size="25" autocomplete="off" /></td>';
echo '</tr>';
echo '<tr>';
echo '<td>Bevestig wachtwoord</td> <td><input type="password" name="confirm_password" value="" size="25" autocomplete="off" /></td>';
echo '</tr>';
echo '<tr>';
echo '<td></td> <td><input type="submit" name="general" value="Opslaan" /> <input type="submit" name="cancel" value="Annuleren" /></td>';
echo '</tr>';
echo '</table>';
echo '</form>';
echo '</div>';
echo '<div id="quota">';
if(isset($errorMessage['quota']) && count($errorMessage['quota'] > 0))
{
echo '<p class="error"><b>Er is een probleem opgetreden:</b><br />';
foreach($errorMessage['quota'] as $message)
{
echo '- '.$message.'<br />';
}
echo '</p>';
}
echo '<form method="post">';
echo '<table id="edit" class="user">';
echo '<tr>';
echo '<td>Eigen quota</td> <td><select name="quotasetting">'.(isset($_POST['quotasetting']) ? ($_POST['quotasetting'] == '1' ? '<option value="1" selected="selected">Ja</option><option value="0">Nee</option>' : '') : '<option value="1" '.(getUserDetails('Quota overrides') == 'yes' ? 'selected="selected"' : '').'>Ja</option>').(isset($_POST['quotasetting']) ? ($_POST['quotasetting'] == '0' ? '<option value="1">Ja</option><option value="0" selected="selected">Nee</option>' : '') : '<option value="0" '.(getUserDetails('Quota overrides') == 'no' ? 'selected="selected"' : '').'>Nee</option>').'</select></td>';
echo '</tr>';
echo '<tr>';
echo '<td>Warning level</td> <td><input type="text" name="warninglevel" value="'.(isset($_POST['warninglevel']) ? formValue('warninglevel') : (getUserDetails('Warning level') == 'unlimited' ? '0' : '').(substr(getUserDetails('Warning level'), -2) == 'KB' ? ''.round(getUserDetails('Warning level') / 1024, 0).'' : '').(substr(getUserDetails('Warning level'), -2) == 'MB' ? ''.round(getUserDetails('Warning level'), 0).'' : '')).'" size="3" autocomplete="off" />MB</td>';
echo '</tr>';
echo '<tr>';
echo '<td>Soft level</td> <td><input type="text" name="softlevel" value="'.(isset($_POST['softlevel']) ? formValue('softlevel') : (getUserDetails('Soft level') == 'unlimited' ? '0' : '').(substr(getUserDetails('Soft level'), -2) == 'KB' ? ''.round(getUserDetails('Soft level') / 1024, 0).'' : '').(substr(getUserDetails('Soft level'), -2) == 'MB' ? ''.round(getUserDetails('Soft level'), 0).'' : '')).'" size="3" autocomplete="off" />MB</td>';
echo '</tr>';
echo '<tr>';
echo '<td>Hard level</td> <td><input type="text" name="hardlevel" value="'.(isset($_POST['hardlevel']) ? formValue('hardlevel') : (getUserDetails('Hard level') == 'unlimited' ? '0' : '').(substr(getUserDetails('Hard level'), -2) == 'KB' ? ''.round(getUserDetails('Hard level') / 1024, 0).'' : '').(substr(getUserDetails('Hard level'), -2) == 'MB' ? ''.round(getUserDetails('Hard level'), 0).'' : '')).'" size="3" autocomplete="off" />MB</td>';
echo '</tr>';
echo '<tr>';
echo '<td></td> <td><input type="submit" name="quota" value="Opslaan" /> <input type="submit" name="cancel" value="Annuleren" /></td>';
echo '</tr>';
echo '</table>';
echo '</form>';
echo '</div>';
?>
Maar mijn pagina bestaat uit verschillende tabjes door middel van <div id="quota">, <div id="general">. Deze divjes moeten dus de pagina's/tabjes scheiden. Dat kan dan niet zoals Michael - het vermeld volgens mij.
Misschien wordt het overzichtelijker als je eerst je script opgebouwd denkt als
Code (php)
Dat vereist dus dat je evenzoveel "view"files voor je tabs aanmaakt.
Je hebt nu nog steeds hetzelfde probleem, maar nu doen we een aanpassing:
Code (php)
dus wat eerder al gezegd wordt:
doe eerst je complete php afhandeling (die in feite gewoon vars vult met de benodigde waarden)
en toon dan eventueel pas wat
Gewijzigd op 17/01/2014 12:05:35 door Ivo P
Gerben Kwakkel op 17/01/2014 11:31:11:
Maar mijn pagina bestaat uit verschillende tabjes door middel van <div id="quota">, <div id="general">. Deze divjes moeten dus de pagina's/tabjes scheiden. Dat kan dan niet zoals Michael - het vermeld volgens mij.
Heb je de toegevoegde code al bekeken?