-
Notifications
You must be signed in to change notification settings - Fork 0
/
projsel.php
158 lines (126 loc) · 5.19 KB
/
projsel.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
<?php
// **********************************************************************************
// ** **
// ** projsel.php (c) Wolfram Plettscher 01/2016 **
// ** **
// **********************************************************************************
// Display page only, if authenticated, otherwise jump to login page
include ('auth.php');
echo "<h1>Project Selection</h1>";
include "mysql/credentials.inc";
$mysqli = new mysqli($host,$username,$password,$database);
// Verbindung prüfen
if (mysqli_connect_errno()) {
printf ("Verbindung fehlgeschlagen: %s\n", mysqli_connect_error());
exit();
}
$mysqli2 = new mysqli($host,$username,$password,$database);
// Verbindung prüfen
if (mysqli_connect_errno()) {
printf ("Verbindung fehlgeschlagen: %s\n", mysqli_connect_error());
exit();
}
//-----------------------------------------------------------------------------------
// react on previously pushed button to update mySQL database ---
// set values to '', if not previously set ---
//-----------------------------------------------------------------------------------
$myacc = $_SESSION['account'];
$myuser = $_SESSION['userid'];
if (!isset ($_POST['select'])) $_POST['select'] = '';
if (!isset ($_POST['default'])) $_POST['default'] = '';
$myselect = $_POST['select'];
$mydefault = $_POST['default'];
if (isset($_POST['submit']) || isset($_POST['editgroups'])) {
// select selected project
$query = $mysqli->query ("SELECT proj_uuid, projshort
FROM user2proj
WHERE user_uuid = '$myuser'
AND acc_uuid = '$myacc'
AND proj_uuid = '$myselect'
ORDER BY defaultproj DESC, projshort ASC
");
if ($result = $query->fetch_object()) {
// $_SESSION['project'] = "Project: " . "{$result->projshort}";
$_SESSION['projid'] = "{$result->proj_uuid}";
}
$myprojid = $result->proj_uuid;
// select long name for selected project
$query = $mysqli->query ("SELECT projlong
FROM project
WHERE proj_uuid = '$myprojid'
");
if ($result = $query->fetch_object()) {
$_SESSION['project'] = "Project: " . "{$result->projlong}";
}
// update default project into db
$query = $mysqli->query ("UPDATE user2proj SET
defaultproj = FALSE
WHERE user_uuid = '$myuser'
AND acc_uuid = '$myacc'");
$query = $mysqli->query ("UPDATE user2proj SET
defaultproj = TRUE
WHERE user_uuid = '$myuser'
AND acc_uuid = '$myacc'
AND proj_uuid = '$mydefault'");
// now we need to refresh the screen; therefore these javascript lines
// switch to 'Project-Groups' form if this button was pressed
$mysqli->close();
echo "<body onLoad='document.form1.submit()'>";
if (isset($_POST['submit']))
echo "<form name='form1' method='post' action='index.php?section=projsel'>";
else
echo "<form name='form1' method='post' action='index.php?section=projgroups'>";
echo "<input type='text' name='sqldone'>";
echo "</form></body>";
}
// This path will be executed after sql update (to update all values on screen based on selection)
// Currently there is no extra action needed; refresh of screen is done at this moment
//if (isset($_POST['sqldone'])) {
// echo "</br> POST = abc </br>";
//}
//-----------------------------------------------------------------------------------
// show user-project assignements ---
//-----------------------------------------------------------------------------------
$query = $mysqli->query ("SELECT proj_uuid, projshort, defaultproj FROM user2proj
WHERE user_uuid = '$myuser'
ORDER by proj_uuid ASC ");
echo "<form method='post' action='index.php?section=projsel'>";
echo "<table class='sqltable' border='0' cellspacing='0' cellpadding='2' >\n";
echo "<tr>
<th> Select </th>
<th> Default </th>
<th> Proj.-ID </th>
<th> Project </th>
</tr>\n";
while ($result = $query->fetch_object())
{
// now select for this element the long-name of project
$myprojid = $result->proj_uuid;
$query2 = $mysqli2->query ("SELECT projlong FROM project
WHERE proj_uuid = '$myprojid' ");
$result2 = $query2->fetch_object();
echo "<tr>";
if ($result->proj_uuid == $_SESSION['projid'])
echo "<td>" . "<input type='radio' name='select' value='{$result->proj_uuid}' checked>" . "</td>";
else
echo "<td>" . "<input type='radio' name='select' value='{$result->proj_uuid}' >" . "</td>";
if ($result->defaultproj == '1' )
echo "<td>" . "<input type='radio' name='default' value='{$result->proj_uuid}' checked>" . "</td>";
else
echo "<td>" . "<input type='radio' name='default' value='{$result->proj_uuid}' >" . "</td>";
echo "<td>" . "{$result->proj_uuid}" . "</td>"
. "<td>" . "{$result2->projlong}" . "</td>"
. "</tr>";
}
echo "</table><br /><br />";
?>
<table>
<tr>
<td><input class='css_btn_class' name='submit' type='submit' value='submit' /></td>
<td><input class='css_btn_class' name='editgroups' type='submit' value='edit groups' /></td>
</tr>
</table>
</form>
<?php
$mysqli->close();
?>