1: <?php
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: function build_saved_reps_table($order_by, $order_type, $username, $user_url, &$num_reps, $self = true){
44: global $db;
45:
46: $row_headers_ar = array (
47: 'rep_timestamp' => _("Date"),
48: 'rep_id' => _("RepNo"),
49: 'patient_id' => _("Patient"),
50: 'rep_public' => _("public")
51: );
52: $saved_reps_table = "<div class='scrollableContainer'>\n";
53: $saved_reps_table .= " <div class='scrollingArea'>\n";
54: $saved_reps_table .= " <table class='saved_reps'>\n";
55:
56:
57: $saved_reps_table .= " <thead>\n";
58: $saved_reps_table .= " <tr>\n";
59: $saved_reps_table .= " <th class='radio'><div> </div></th>\n";
60: foreach ($row_headers_ar as $row => $header) {
61: $saved_reps_table .= " <th class='$row'><div>";
62: $field_is_current_order_by = 0;
63: if ($order_by != $row){
64: $link_class="order_link_2";
65: if ($row == "rep_timestamp") {
66: $new_order_type = "DESC";
67: } else {
68: $new_order_type = "ASC";
69: }
70: } else {
71: $field_is_current_order_by = 1;
72: $link_class="order_link_2_selected";
73: if ( $order_type == "DESC") {
74: $new_order_type = "ASC";
75: } else {
76: $new_order_type = "DESC";
77: }
78: }
79:
80: $saved_reps_table .= "<a class='$link_class' href='" . $user_url . "order_by=$row&order_type=$new_order_type'";
81: if ($self) {
82: $saved_reps_table .= " onclick=\"return reloadSavedRepsTable('$row', '$new_order_type')\"";
83: }
84: $saved_reps_table .= ">";
85:
86: if ($field_is_current_order_by === 1) {
87: if ($order_type === 'ASC') {
88: $saved_reps_table .= '↑ ';
89: } else {
90: $saved_reps_table .= '↓ ';
91: }
92: }
93:
94: $saved_reps_table .= "$header</a></div></th>\n";
95: }
96: $saved_reps_table .= " </tr>\n";
97: $saved_reps_table .= " </thead>\n";
98:
99:
100: $i = 0;
101: $class = "unchecked_1";
102: $query = "SELECT rep_id, patient_id, rep_prescription, rep_note, UNIX_TIMESTAMP(rep_timestamp), rep_public FROM repertorizations WHERE username = '$username' ";
103: if (!$self) {
104: $query .= "AND rep_public = 1 ";
105: }
106: if ($order_by == 'rep_timestamp') {
107: $query .= "ORDER BY $order_by $order_type, rep_id $order_type";
108: } else {
109: $query .= "ORDER BY $order_by $order_type";
110: }
111: $db->send_query($query);
112: $saved_reps_table .= " <tbody>\n";
113: while (list($rep_id, $patient_id, $rep_prescription, $rep_note, $rep_timestamp, $rep_public) = $db->db_fetch_row()) {
114: $i++;
115: $date = date ("d.m.Y", $rep_timestamp);
116: if ($rep_public == 1) {
117: $public = _("yes");
118: } else {
119: $public = _("no");
120: }
121: if (empty($patient_id)) {
122: $patient_id = " ";
123: }
124: $saved_reps_table .= " <tr class='$class' id='row_$i'>\n";
125: $saved_reps_table .= " <td class='radio'><div><input type='radio' id='radio_$i' value='$rep_id%$patient_id%$rep_prescription%$rep_note%$rep_timestamp%$rep_public' name='saved_rep' onclick=\"return colorizeRadioRow('radio','row','saved_reps_form');\" onkeyup=\"return colorizeRadioRow('radio','row','saved_reps_form');\"></div></td>\n";
126: $saved_reps_table .= " <td class='rep_timestamp'><div><label for='radio_$i'>$date</label></div></td>\n";
127: $saved_reps_table .= " <td class='rep_id'><div><label for='radio_$i'>$rep_id</label></div></td>\n";
128: $saved_reps_table .= " <td class='patient_id'><div><label for='radio_$i'>$patient_id</label></div></td>\n";
129: $saved_reps_table .= " <td class='rep_public'><div><label for='radio_$i'>$public</label></div></td>\n";
130: $saved_reps_table .= " </tr>\n";
131: $class = ($class == "unchecked_1") ? "unchecked_2" : "unchecked_1";
132: }
133: $num_reps = $db->db_num_rows();
134: $db->free_result();
135: $saved_reps_table .= " </tbody>\n";
136:
137: $saved_reps_table .= " </table>\n";
138: $saved_reps_table .= " </div>\n";
139: $saved_reps_table .= "</div>\n";
140:
141: return $saved_reps_table;
142: }
143:
144: if (!empty($_REQUEST['ajax'])) {
145: chdir("..");
146: include_once ("include/classes/login/session.php");
147: $username = $session->username;
148: }
149: if (!$tabbed && !isset($_REQUEST['tab'])) {
150: $user_url = "userinfo.php?";
151: } else {
152: $user_url = "index.php?tab=4&";
153: }
154:
155: $loesch = 0;
156: $public = 0;
157: if (!empty($_REQUEST['loesch']) && !empty($_REQUEST['rep'])) {
158: $rep_id = $_REQUEST['rep'];
159: $query1 = "DELETE FROM rep_sym WHERE rep_id='$rep_id'";
160: $query2 = "DELETE FROM repertorizations WHERE rep_id='$rep_id'";
161: $loesch = 2;
162: if ($db->send_query($query1) && $db->send_query($query2)) {
163: $loesch = 1;
164: }
165: } elseif (!empty($_REQUEST['public']) && !empty($_REQUEST['rep'])) {
166: $rep_id = $_REQUEST['rep'];
167: if ($_REQUEST['rep_public'] == "1"){
168: $rep_public_new = 0;
169: } else {
170: $rep_public_new = 1;
171: }
172: $query = "SELECT rep_timestamp FROM repertorizations WHERE rep_id = $rep_id";
173: $db->send_query($query);
174: list($rep_timestamp) = $db->db_fetch_row();
175: $db->free_result();
176: $query = "UPDATE repertorizations SET rep_public = $rep_public_new, rep_timestamp = '$rep_timestamp' WHERE rep_id = $rep_id";
177: if ($db->send_query($query)) {
178: $public = 1;
179: }
180: }
181: if ($loesch != 0 || $public != 0) {
182: echo (" <div class='alert_box'>\n");
183: if ($loesch == 1) {
184: printf(" " . _("Repertorization No. %d was deleted.") . "\n", $rep_id);
185: } elseif ($loesch == 2) {
186: printf(" <span class='red'>" . _("Repertorization No. %d couldn't be deleted totally!") . "</span>\n", $rep_id);
187: } elseif ($public == 1) {
188: printf(" " . _("The public status of the repertorization no. %d changed.") . "\n", $rep_id);
189: }
190: echo (" </div>\n");
191: }
192: if (!$tabbed && !isset($_REQUEST['tab'])) {
193: $tab = -1;
194: } else {
195: $tab = 1;
196: }
197: ?>
198: <form id="saved_reps_form" accept-charset="utf-8">
199: <div class = 'select'>
200: <?php
201: $order_by = "rep_timestamp";
202: $order_type = "DESC";
203: if (!empty($_REQUEST['order_by'])) {
204: $order_by = $_REQUEST['order_by'];
205: }
206: if (!empty($_REQUEST['order_type'])) {
207: $order_type = $_REQUEST['order_type'];
208: }
209: echo build_saved_reps_table($order_by, $order_type, $username, $user_url, $num_reps);
210: printf(" <p class='label'>" . ngettext("%d saved repertorization", "%d saved repertorizations", $num_reps) . "</p>\n", $num_reps);
211: ?>
212: <div class="button_area_2">
213: <input class="submit" type="button" onclick='repCall(<?php echo($tab);?>)' value=" <?php echo _("Show repertorization"); ?> ">
214: <br>
215: <br>
216: <?php
217: if ($tab == 1) {
218: $tab = 0;
219: }
220: ?>
221: <input class="submit" type="button" onclick='repContinue(<?php echo($tab);?>)' value=" <?php echo _("Add more symptoms"); ?> ">
222: <br>
223: <br>
224: <input class="submit" type="button" onclick='repDelete()' value=" <?php echo _("Delete repertorization"); ?> ">
225: <br>
226: <br>
227: <input class="submit" type="button" onclick='repPublic()' value=" <?php echo _("Change public-state"); ?> ">
228: </div>
229: </div>
230: </form>
231: