Subversion Repositories public

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4 andreas 1
<?
2
 
3
# Kapitelnummerierung :-)
4
#
5
# #snum enthaelt eine Nummer der Form x.y.z, wobei es beliebig viele Abschnitte
6
# geben kann.
7
#
8
# #level enthaelt den Level, also welche der Teilnummern veraendert werden soll.
9
#
10
# #dir enthaelt die Richtung in die veraendert werden soll, wobei 0 eins nach
11
# unten und 1 eins nach oben bedeutet. -1 bedeutet alle Ziffern groesser
12
# #level wegschneiden und die letzte Nummer erhoehen. -2 tut das selbe,
13
# reduziert jedoch die letzte Nummer. -3 bedeutet die Nummern gleich lassen,
14
# aber die Anzahl der Elemente an #level anpassen.
15
#
16
# #level zaehlt von 0 weg!
17
#
18
function kNumber($snum, $level, $dir) {
19
	$anz = str_wordcount($snum);
20
	$kpnum = $snum;
21
 
22
	# Haben wir weniger Einzelnummern im String, haengen wir ".1" so
23
	# lange an, bis wir #level erreicht haben.
24
	if ($anz <= $level) {
25
	   while ($anz <= $level) {
26
	      $kpnum .= ".1";
27
	      $anz++;
28
	   }
29
 
30
	   if ($dir == -3) {
31
	      return $kpnum;
32
	   }
33
	}
34
 
35
	$anz = $level + 1;
36
	$anum = explode(".", $kpnum);
37
 
38
	if ($dir < 0) {
39
	   if ($dir == -1) {
40
	      $anum[$level]++;
41
	   } else if ($dir == -2) {
42
	      $anum[$level]--;
43
	   }
44
	} else {
45
	   if ($dir == 0) {
46
	      $anum[$level]++;
47
	   } else {
48
	      $anum[$level]--;
49
	   }
50
	}
51
 
52
	$num = "";
53
 
54
	for ($i = 0; $i < $anz; $i++) {
55
	   if ($i > 0) {
56
	      $num .= "." . (string)$anum[$i];
57
	   } else {
58
	      $num = (string)$anum[$i];
59
	   }
60
	}
61
 
62
	return $num;
63
}
64
 
65
function SelectTask($pl_num, $id, $sel=0) {
66
	global $phase;
67
	global $numphase;
68
 
69
	$lodb = OpenDB();
70
	$loquery = "select ta_num, ta_name, ta_id, ta_level, ta_meeting,";
71
	$loquery .= "ta_phase from task where ta_plnum = $pl_num order by ta_id";
72
	$loresult = QueryDB($lodb, $loquery);
73
 
74
	if (!$loresult) {
75
	   closeDB($lodb);
76
	   return false;
77
	}
78
 
79
	$numrows = numrowsDB($loresult);
80
	$row = 0;
81
	$snum = "1";
82
	$olevel = 0;
83
 
84
	while ($row < $numrows) {
85
	   $data = fetchDB($loresult, $row);
86
	   $ta_num = $data[0];
87
	   $ta_name = $data[1];
88
	   $ta_id = $data[2];
89
	   $ta_level = $data[3];
90
	   $ta_meeting = $data[4];
91
	   $tphase = $data[5];
92
 
93
	   $loquery = "select ta_level from task where ";
94
	   $loquery .= "ta_plnum = $pl_num and ta_id > $ta_id order by ta_id";
95
	   $loresult2 = QueryDB($lodb, $loquery);
96
 
97
	   if (!$loresult2) {
98
	      closeDB($lodb);
99
	      return false;
100
	   }
101
 
102
	   $nr = numrowsDB($loresult2);
103
 
104
	   if ($nr > 0) {
105
	      $data = fetchDB($loresult2, 0);
106
	      $xlevel = $data[0];
107
	   } else {
108
	      $xlevel = $ta_level;
109
	   }
110
 
111
	   if ($olevel == 0) {
112
	      $level = 0;
113
	      $olevel = $ta_level;
114
	      $dir = -3;
115
	   } else if ($olevel < $ta_level) {
116
	      $level = $ta_level - 1;
117
	      $olevel = $ta_level;
118
	      $dir = -3;
119
	   } else if ($olevel == $ta_level) {
120
	      $level = $ta_level - 1;
121
	      $dir = 0;
122
	   } else if ($olevel > $ta_level) {
123
	      $level = $ta_level - 1;
124
	      $olevel = $ta_level;
125
	      $dir = -1;
126
	   }
127
 
128
	   $snum = kNumber ($snum, $level, $dir);
129
 
130
	   if ($phase == 1 && $numphase == 1 && isset($tphase)) {
131
	      $p = strpos($snum, ".");
132
 
133
	      if ($p === false)
134
	         $rest = "";
135
	      else
136
	         $rest = substr($snum, $p);
137
 
138
	      $snum = (string)$tphase . $rest;
139
	   }
140
 
141
	   if (!$ta_meeting && $ta_level > 1 && $xlevel <= $ta_level) {
142
	      if (!$id) {
143
	         echo "<option value=\"$ta_num\"";
144
		 $comp = $ta_num;
145
	      } else {
146
	         echo "<option value=\"$ta_id\"";
147
		 $comp = $ta_id;
148
	      }
149
 
150
	      if ($comp == $sel)
151
	         echo "selected";
152
 
153
	      echo ">$snum $ta_name</option>\n";
154
	   }
155
 
156
	   $row++;
157
	}
158
 
159
//	closeDB($lodb);
160
	return true;
161
}
162
 
163
function GetTaskNum($pl_num, $ta_id, $ta_level, $ta_phase, $ta_meeting, $snum, $typ, $db=-1) {
164
	global $phase;
165
	global $numphase;
166
 
167
	if (strlen($snum) <= 0)
168
	   $snum = "1";
169
 
170
	if ($db == -1)
171
	   $dbs = OpenDB();
172
	else
173
	   $dbs = $db;
174
 
175
	# Finde den naechsten Level
176
	$query = "select ta_level from task where ta_plnum = $pl_num and ";
177
	$query .= "ta_id > $ta_id order by ta_id";
178
	$result = QueryDB($dbs, $query);
179
 
180
	if (!$result) {
181
	   return false;
182
	}
183
 
184
	$numrows = numrowsDB($result);
185
 
186
	if ($numrows > 0) {
187
	   $data = fetchDB($result, 0);
188
	   $xlevel = $data[0];
189
	} else {
190
	   $xlevel = $ta_level;
191
	}
192
 
193
	# Finde den vorhergehenden Level
194
	$query = "select ta_level from task where ta_plnum = $pl_num and ";
195
	$query .= "ta_id < $ta_id order by ta_id desc";
196
	$result = QueryDB($dbs, $query);
197
 
198
	if (!$result) {
199
	   return false;
200
	}
201
 
202
	$numrows = numrowsDB($result);
203
 
204
	if ($numrows > 0) {
205
	   $data = fetchDB($result, 0);
206
	   $olevel = $data[0];
207
	} else {
208
	   $olevel = 0;
209
	}
210
 
211
 
212
	if ($olevel == 0) {
213
	   $level = 0;
214
	   $dir = -3;
215
	} else if ($olevel < $ta_level) {
216
	   $level = $ta_level - 1;
217
	   $dir = -3;
218
	} else if ($olevel == $ta_level) {
219
	   $level = $ta_level - 1;
220
	   $dir = 0;
221
	} else if ($olevel > $ta_level) {
222
	   $level = $ta_level - 1;
223
	   $dir = -1;
224
	}
225
 
226
	$kpnum = kNumber ($snum, $level, $dir);
227
 
228
	if ($phase == 1 && $numphase == 1 && isset($ta_phase) && $ta_phase >= 0) {
229
	   $p = strpos($kpnum, ".");
230
 
231
	   if ($p === false)
232
	      $rest = "";
233
	   else
234
	      $rest = substr($kpnum, $p);
235
 
236
	   $kpnum = (string)$ta_phase . $rest;
237
	}
238
 
239
	if (!$ta_meeting && $ta_level > 1 && $xlevel <= $ta_level)
240
	   $typ = true;
241
	else
242
	   $typ = false;
243
 
244
	if ($db == -1)
245
	   closeDB($dbs);
246
 
247
	return $kpnum;
248
}
249
 
250
?>