1 | <?php |
---|
2 | |
---|
3 | function getDocument($id) |
---|
4 | { |
---|
5 | |
---|
6 | // echo "aggggi".$id; |
---|
7 | if (!is_numeric($id)) |
---|
8 | die ("invalid documentid"); |
---|
9 | |
---|
10 | $queryStr = "SELECT * FROM phpgw_mydms_Documents WHERE id = " . $id; |
---|
11 | |
---|
12 | //echo "<br>documentos".$queryStr."<br>"; |
---|
13 | $resArr = $GLOBALS['mydms']->db->getResultArray($queryStr); |
---|
14 | if (is_bool($resArr) && $resArr == false) |
---|
15 | return false; |
---|
16 | |
---|
17 | if (count($resArr) != 1) |
---|
18 | return false; |
---|
19 | |
---|
20 | $resArr = $resArr[0]; |
---|
21 | $newDocument = new Document($resArr["id"], $resArr["name"], $resArr["comment"], $resArr["date"], $resArr["expires"], $resArr["owner"], $resArr["folder"], $resArr[7], $resArr[8], $resArr[9], $resArr["keywords"], $resArr["sequence"]); |
---|
22 | |
---|
23 | |
---|
24 | if($newDocument->getAccessMode(getUser($GLOBALS['phpgw_info']['user']['account_id'])) > M_NONE) |
---|
25 | return $newDocument; |
---|
26 | else |
---|
27 | return false; |
---|
28 | } |
---|
29 | |
---|
30 | class Document |
---|
31 | { |
---|
32 | var $_id; |
---|
33 | var $_name; |
---|
34 | var $_comment; |
---|
35 | var $_ownerID; |
---|
36 | var $_folderID; |
---|
37 | var $_expires; |
---|
38 | var $_inheritAccess; |
---|
39 | var $_defaultAccess; |
---|
40 | var $_locked; |
---|
41 | var $_keywords; |
---|
42 | var $_sequence; |
---|
43 | |
---|
44 | function Document($id, $name, $comment, $date, $expires, $ownerID, $folderID, $inheritAccess, $defaultAccess, $locked, $keywords, $sequence) |
---|
45 | { |
---|
46 | $this->_id = $id; |
---|
47 | $this->_name = $name; |
---|
48 | $this->_comment = $comment; |
---|
49 | $this->_date = $date; |
---|
50 | $this->_expires = $expires; |
---|
51 | $this->_ownerID = $ownerID; |
---|
52 | $this->_folderID = $folderID; |
---|
53 | $this->_inheritAccess = $inheritAccess; |
---|
54 | $this->_defaultAccess = $defaultAccess; |
---|
55 | $this->_locked = $locked; |
---|
56 | $this->_keywords = $keywords; |
---|
57 | $this->_sequence = $sequence; |
---|
58 | |
---|
59 | $this->db = clone($GLOBALS['phpgw']->db); |
---|
60 | $this->db->set_app('mydms'); |
---|
61 | } |
---|
62 | |
---|
63 | function getID() { return $this->_id; } |
---|
64 | |
---|
65 | function getName() { return $this->_name; } |
---|
66 | |
---|
67 | function setName($newName) |
---|
68 | { |
---|
69 | $data = array('name' => $newName); |
---|
70 | $where = array('id' => $this->_id); |
---|
71 | |
---|
72 | if(!$this->db->update('phpgw_mydms_Documents', $data, $where, __LINE__, __FILE__)) { |
---|
73 | return false; |
---|
74 | } |
---|
75 | |
---|
76 | $this->_name = $newName; |
---|
77 | return true; |
---|
78 | } |
---|
79 | |
---|
80 | function getComment() { return $this->_comment; } |
---|
81 | |
---|
82 | function setComment($newComment) |
---|
83 | { |
---|
84 | $data = array('comment' => $newComment); |
---|
85 | $where = array('id' => $this->_id); |
---|
86 | |
---|
87 | if(!$this->db->update('phpgw_mydms_Documents', $data, $where, __LINE__, __FILE__)) { |
---|
88 | return false; |
---|
89 | } |
---|
90 | |
---|
91 | $this->_comment = $newComment; |
---|
92 | return true; |
---|
93 | } |
---|
94 | |
---|
95 | function getKeywords() { return $this->_keywords; } |
---|
96 | |
---|
97 | function setKeywords($newKeywords) |
---|
98 | { |
---|
99 | $data = array('keywords' => $newKeywords); |
---|
100 | $where = array('id' => $this->_id); |
---|
101 | |
---|
102 | if(!$this->db->update('phpgw_mydms_Documents', $data, $where, __LINE__, __FILE__)) { |
---|
103 | return false; |
---|
104 | } |
---|
105 | |
---|
106 | $this->_keywords = $newKeywords; |
---|
107 | return true; |
---|
108 | } |
---|
109 | |
---|
110 | function getDate() |
---|
111 | { |
---|
112 | return $this->_date; |
---|
113 | } |
---|
114 | |
---|
115 | function getFolder() |
---|
116 | { |
---|
117 | if (!isset($this->_folder)) |
---|
118 | $this->_folder = getFolder($this->_folderID); |
---|
119 | return $this->_folder; |
---|
120 | } |
---|
121 | |
---|
122 | function setFolder($newFolder) |
---|
123 | { |
---|
124 | $data = array('folder' => $newFolder->getID()); |
---|
125 | $where = array('id' => $this->_id); |
---|
126 | |
---|
127 | if(!$this->db->update('phpgw_mydms_Documents', $data, $where, __LINE__, __FILE__)) { |
---|
128 | return false; |
---|
129 | } |
---|
130 | |
---|
131 | $this->_folderID = $newFolder->getID(); |
---|
132 | $this->_folder = $newFolder; |
---|
133 | return true; |
---|
134 | } |
---|
135 | |
---|
136 | function getOwner() |
---|
137 | { |
---|
138 | if (!isset($this->_owner)) |
---|
139 | $this->_owner = getUser($this->_ownerID); |
---|
140 | return $this->_owner; |
---|
141 | } |
---|
142 | |
---|
143 | function setOwner($user) |
---|
144 | { |
---|
145 | $data = array('owner' => $user->getID()); |
---|
146 | $where = array('id' => $this->_id); |
---|
147 | |
---|
148 | if(!$this->db->update('phpgw_mydms_Documents', $data, $where, __LINE__, __FILE__)) { |
---|
149 | return false; |
---|
150 | } |
---|
151 | |
---|
152 | $this->_ownerID = $user->getID(); |
---|
153 | $this->_owner = $user; |
---|
154 | return true; |
---|
155 | } |
---|
156 | |
---|
157 | function getDefaultAccess() |
---|
158 | { |
---|
159 | if ($this->inheritsAccess()) |
---|
160 | { |
---|
161 | $res = $this->getFolder(); |
---|
162 | if (!$res) return false; |
---|
163 | return $this->_folder->getDefaultAccess(); |
---|
164 | } |
---|
165 | return $this->_defaultAccess; |
---|
166 | } |
---|
167 | |
---|
168 | function setDefaultAccess($mode) |
---|
169 | { |
---|
170 | $data = array('defaultAccess' => $mode); |
---|
171 | $where = array('id' => $this->_id); |
---|
172 | |
---|
173 | if(!$this->db->update('phpgw_mydms_Documents', $data, $where, __LINE__, __FILE__)) { |
---|
174 | return false; |
---|
175 | } |
---|
176 | |
---|
177 | $this->_defaulAccess = $mode; |
---|
178 | return true; |
---|
179 | } |
---|
180 | |
---|
181 | function inheritsAccess() { return $this->_inheritAccess; } |
---|
182 | |
---|
183 | function setInheritAccess($inheritAccess) |
---|
184 | { |
---|
185 | $inheritAccess = ($inheritAccess) ? "1" : "0"; |
---|
186 | $data = array('inheritAccess' => $inheritAccess); |
---|
187 | $where = array('id' => $this->_id); |
---|
188 | |
---|
189 | if(!$this->db->update('phpgw_mydms_Documents', $data, $where, __LINE__, __FILE__)) { |
---|
190 | return false; |
---|
191 | } |
---|
192 | |
---|
193 | $this->_inheritAccess = $inheritAccess; |
---|
194 | return true; |
---|
195 | } |
---|
196 | |
---|
197 | function expires() |
---|
198 | { |
---|
199 | if (intval($this->_expires) == 0) |
---|
200 | return false; |
---|
201 | else |
---|
202 | return true; |
---|
203 | } |
---|
204 | |
---|
205 | function getExpires() |
---|
206 | { |
---|
207 | if (intval($this->_expires) == 0) |
---|
208 | return false; |
---|
209 | else |
---|
210 | return $this->_expires; |
---|
211 | } |
---|
212 | |
---|
213 | function setExpires($expires) |
---|
214 | { |
---|
215 | $expires = (!$expires) ? 0 : $expires; |
---|
216 | $data = array('expires' => $expires); |
---|
217 | $where = array('id' => $this->_id); |
---|
218 | |
---|
219 | if(!$this->db->update('phpgw_mydms_Documents', $data, $where, __LINE__, __FILE__)) { |
---|
220 | return false; |
---|
221 | } |
---|
222 | |
---|
223 | $this->_expires = $expires; |
---|
224 | return true; |
---|
225 | } |
---|
226 | |
---|
227 | function isLocked() { return $this->_locked != -1; } |
---|
228 | |
---|
229 | function setLocked($falseOrUser) |
---|
230 | { |
---|
231 | $locked = (is_object($falseOrUser)) ? $falseOrUser->getID() : -1; |
---|
232 | $data = array('locked' => $locked); |
---|
233 | $where = array('id' => $this->_id); |
---|
234 | |
---|
235 | if(!$this->db->update('phpgw_mydms_Documents', $data, $where, __LINE__, __FILE__)) { |
---|
236 | return false; |
---|
237 | } |
---|
238 | |
---|
239 | unset($this->_lockingUser); |
---|
240 | $this->_locked = $locked; |
---|
241 | return true; |
---|
242 | } |
---|
243 | |
---|
244 | function getLockingUser() |
---|
245 | { |
---|
246 | if (!$this->isLocked()) |
---|
247 | return false; |
---|
248 | |
---|
249 | if (!isset($this->_lockingUser)) |
---|
250 | $this->_lockingUser = getUser($this->_locked); |
---|
251 | return $this->_lockingUser; |
---|
252 | } |
---|
253 | |
---|
254 | function getSequence() { return $this->_sequence; } |
---|
255 | |
---|
256 | function setSequence($seq) |
---|
257 | { |
---|
258 | $data = array('sequence' => $seq); |
---|
259 | $where = array('id' => $this->_id); |
---|
260 | |
---|
261 | if(!$this->db->update('phpgw_mydms_Documents', $data, $where, __LINE__, __FILE__)) { |
---|
262 | return false; |
---|
263 | } |
---|
264 | |
---|
265 | $this->_sequence = $seq; |
---|
266 | return true; |
---|
267 | } |
---|
268 | |
---|
269 | function clearAccessList() |
---|
270 | { |
---|
271 | $where = array( |
---|
272 | 'targetType' => T_DOCUMENT, |
---|
273 | 'target' => $this->_id, |
---|
274 | ); |
---|
275 | |
---|
276 | if(!$this->db->delete('phpgw_mydms_ACLs', $where, __LINE__, __FILE__)) { |
---|
277 | return false; |
---|
278 | } |
---|
279 | |
---|
280 | unset($this->_accessList); |
---|
281 | return true; |
---|
282 | } |
---|
283 | |
---|
284 | function getAccessList() |
---|
285 | { |
---|
286 | if ($this->inheritsAccess()) |
---|
287 | { |
---|
288 | $res = $this->getFolder(); |
---|
289 | if (!$res) return false; |
---|
290 | return $this->_folder->getAccessList(); |
---|
291 | } |
---|
292 | |
---|
293 | if (!isset($this->_accessList)) |
---|
294 | { |
---|
295 | $cols = array('userID', 'groupID', 'mode'); |
---|
296 | $where = array( |
---|
297 | 'targetType' => T_DOCUMENT, |
---|
298 | 'target' => $this->_id, |
---|
299 | ); |
---|
300 | |
---|
301 | if(!$this->db->select('phpgw_mydms_ACLs', $cols, $where, __LINE__, __FILE__, false, 'ORDER BY targetType')) { |
---|
302 | return false; |
---|
303 | } |
---|
304 | |
---|
305 | $this->_accessList = array("groups" => array(), "users" => array()); |
---|
306 | while ($this->db->next_record()) { |
---|
307 | if ($this->db->f('userID') != -1) |
---|
308 | array_push($this->_accessList["users"], new UserAccess($this->db->f('userid'), $this->db->f('mode'))); |
---|
309 | else //if ($row["groupID"] != -1) |
---|
310 | array_push($this->_accessList["groups"], new GroupAccess($this->db->f('groupid'), $this->db->f('mode'))); |
---|
311 | } |
---|
312 | |
---|
313 | # $queryStr = "SELECT * FROM phpgw_mydms_ACLs WHERE targetType = ".T_DOCUMENT." AND target = " . $this->_id . " ORDER BY targetType"; |
---|
314 | # $resArr = $GLOBALS['mydms']->db->getResultArray($queryStr); |
---|
315 | # if (is_bool($resArr) && !$resArr) |
---|
316 | # return false; |
---|
317 | # |
---|
318 | # $this->_accessList = array("groups" => array(), "users" => array()); |
---|
319 | # foreach ($resArr as $row) |
---|
320 | # { |
---|
321 | # if ($row["userID"] != -1) |
---|
322 | # array_push($this->_accessList["users"], new UserAccess($row["userID"], $row["mode"])); |
---|
323 | # else //if ($row["groupID"] != -1) |
---|
324 | # array_push($this->_accessList["groups"], new GroupAccess($row["groupID"], $row["mode"])); |
---|
325 | # } |
---|
326 | } |
---|
327 | |
---|
328 | return $this->_accessList; |
---|
329 | } |
---|
330 | |
---|
331 | function addAccess($mode, $userOrGroupID, $isUser) |
---|
332 | { |
---|
333 | $userOrGroup = ($isUser) ? "userID" : "groupID"; |
---|
334 | |
---|
335 | $data = array ( |
---|
336 | 'target' => $this->_id, |
---|
337 | 'targetType' => T_DOCUMENT, |
---|
338 | $userOrGroup => $userOrGroupID, |
---|
339 | 'mode' => $mode, |
---|
340 | ); |
---|
341 | $res = $this->db->insert('phpgw_mydms_ACLs', $data, '', __LINE__, __FILE__); |
---|
342 | if (!$res) { |
---|
343 | return false; |
---|
344 | } |
---|
345 | |
---|
346 | #$queryStr = "INSERT INTO phpgw_mydms_ACLs (target, targetType, ".$userOrGroup.", mode) VALUES |
---|
347 | # (".$this->_id.", ".T_DOCUMENT.", " . $userOrGroupID . ", " .$mode. ")"; |
---|
348 | #if (!$GLOBALS['mydms']->db->getResult($queryStr)) |
---|
349 | # return false; |
---|
350 | |
---|
351 | unset($this->_accessList); |
---|
352 | return true; |
---|
353 | } |
---|
354 | |
---|
355 | function changeAccess($newMode, $userOrGroupID, $isUser) |
---|
356 | { |
---|
357 | $userOrGroup = ($isUser) ? "userID" : "groupID"; |
---|
358 | |
---|
359 | $data = array('mode' => $newMode); |
---|
360 | $where = array( |
---|
361 | 'targetType' => T_DOCUMENT, |
---|
362 | 'target' => $this->_id, |
---|
363 | $userOrGroup => $userOrGroupID, |
---|
364 | ); |
---|
365 | |
---|
366 | if(!$this->db->update('phpgw_mydms_ACLs', $data, $where, __LINE__, __FILE__)) { |
---|
367 | return false; |
---|
368 | } |
---|
369 | |
---|
370 | # $queryStr = "UPDATE phpgw_mydms_ACLs SET mode = " . $newMode . " WHERE targetType = ".T_DOCUMENT." AND target = " . $this->_id . " AND " . $userOrGroup . " = " . $userOrGroupID; |
---|
371 | # if (!$GLOBALS['mydms']->db->getResult($queryStr)) |
---|
372 | # return false; |
---|
373 | |
---|
374 | unset($this->_accessList); |
---|
375 | return true; |
---|
376 | } |
---|
377 | |
---|
378 | function removeAccess($userOrGroupID, $isUser) |
---|
379 | { |
---|
380 | $userOrGroup = ($isUser) ? "userID" : "groupID"; |
---|
381 | |
---|
382 | $where = array( |
---|
383 | 'targetType' => T_DOCUMENT, |
---|
384 | 'target' => $this->_id, |
---|
385 | $userOrGroup => $userOrGroupID, |
---|
386 | ); |
---|
387 | |
---|
388 | if(!$this->db->delete('phpgw_mydms_ACLs', $where, __LINE__, __FILE__)) { |
---|
389 | return false; |
---|
390 | } |
---|
391 | |
---|
392 | # $queryStr = "DELETE FROM phpgw_mydms_ACLs WHERE targetType = ".T_DOCUMENT." AND target = ".$this->_id." AND ".$userOrGroup." = " . $userOrGroupID; |
---|
393 | # if (!$GLOBALS['mydms']->db->getResult($queryStr)) |
---|
394 | # return false; |
---|
395 | |
---|
396 | unset($this->_accessList); |
---|
397 | return true; |
---|
398 | } |
---|
399 | |
---|
400 | /* |
---|
401 | * Liefert die Art der Zugriffsberechtigung fï¿œr den User $user; Mï¿œgliche Rechte: n (keine), r (lesen), w (schreiben+lesen), a (alles) |
---|
402 | * Zunï¿œchst wird Geprï¿œft, ob die Berechtigung geerbt werden soll; in diesem Fall wird die Anfrage an den Eltern-Ordner weitergeleitet. |
---|
403 | * Ansonsten werden die ACLs durchgegangen: Die hï¿œchstwertige Berechtigung gilt. |
---|
404 | * Wird bei den ACLs nicht gefunden, wird die Standard-Berechtigung zurï¿œckgegeben. |
---|
405 | * Ach ja: handelt es sich bei $user um den Besitzer ist die Berechtigung automatisch "a". |
---|
406 | */ |
---|
407 | function getAccessMode($user) |
---|
408 | { |
---|
409 | //Administrator?? |
---|
410 | if ($user->isAdmin()) |
---|
411 | return M_ALL; |
---|
412 | |
---|
413 | //Besitzer?? |
---|
414 | if ($user->getID() == $this->_ownerID) |
---|
415 | return M_ALL; |
---|
416 | |
---|
417 | //Gast-Benutzer?? |
---|
418 | if (($user->getID() == $GLOBALS['mydms']->settings->_guestID) && ($GLOBALS['mydms']->settings->_enableGuestLogin)) |
---|
419 | { |
---|
420 | $mode = $this->getDefaultAccess(); |
---|
421 | if ($mode >= M_READ) |
---|
422 | return M_READ; |
---|
423 | else |
---|
424 | return M_NONE; |
---|
425 | } |
---|
426 | return $this->getAccessList2(); |
---|
427 | //Berechtigung erben?? |
---|
428 | // wird ï¿œber GetAccessList() bereits realisiert. |
---|
429 | // durch das Verwenden der folgenden Zeilen wï¿œren auch Owner-Rechte vererbt worden. |
---|
430 | /* |
---|
431 | if ($this->inheritsAccess()) |
---|
432 | { |
---|
433 | if (!$this->getFolder()) |
---|
434 | return false; |
---|
435 | return $this->_folder->getAccessMode($user); |
---|
436 | } |
---|
437 | */ |
---|
438 | /* $highestPrivileged = M_NONE; |
---|
439 | |
---|
440 | //ACLs durchforsten |
---|
441 | $foundInACL = false; |
---|
442 | $accessList = $this->getAccessList(); |
---|
443 | if (!$accessList) |
---|
444 | return false; |
---|
445 | |
---|
446 | foreach ($accessList["users"] as $userAccess) |
---|
447 | { |
---|
448 | if ($userAccess->getUserID() == $user->getID()) |
---|
449 | { |
---|
450 | $foundInACL = true; |
---|
451 | if ($userAccess->getMode() > $highestPrivileged) |
---|
452 | $highestPrivileged = $userAccess->getMode(); |
---|
453 | if ($highestPrivileged == M_ALL) //hï¿œher geht's nicht -> wir kï¿œnnen uns die arbeit schenken |
---|
454 | return $highestPrivileged; |
---|
455 | } |
---|
456 | } |
---|
457 | foreach ($accessList["groups"] as $groupAccess) |
---|
458 | { |
---|
459 | if ($user->isMemberOfGroup($groupAccess->getGroup())) |
---|
460 | { |
---|
461 | $foundInACL = true; |
---|
462 | if ($groupAccess->getMode() > $highestPrivileged) |
---|
463 | $highestPrivileged = $groupAccess->getMode(); |
---|
464 | if ($highestPrivileged == M_ALL) //hï¿œher geht's nicht -> wir kï¿œnnen uns die arbeit schenken |
---|
465 | return $highestPrivileged; |
---|
466 | } |
---|
467 | } |
---|
468 | if ($foundInACL) |
---|
469 | return $highestPrivileged; |
---|
470 | |
---|
471 | //Standard-Berechtigung verwenden |
---|
472 | return $this->getDefaultAccess();*/ |
---|
473 | } |
---|
474 | function getAccessList2() |
---|
475 | { |
---|
476 | |
---|
477 | $grupos=read_repository2($GLOBALS['phpgw_info']['user']['account_id']); |
---|
478 | // echo "".$GLOBALS['phpgw_info']['user']['account_id']; |
---|
479 | |
---|
480 | if($grupos!=''){ |
---|
481 | $queryStr = "SELECT * FROM phpgw_mydms_acls WHERE targettype = ".T_FOLDER." AND target in ( select folder from phpgw_mydms_Documents WHERE id=" . $this->_id . ") and (userid=".$GLOBALS['phpgw_info']['user']['account_id']." or groupid in (".$grupos.")) ORDER BY targettype"; |
---|
482 | }else{ |
---|
483 | $queryStr = "SELECT * FROM phpgw_mydms_acls WHERE targettype = ".T_FOLDER." AND target in ( select folder from phpgw_mydms_Documents WHERE id=" . $this->_id . ") and (userid=".$GLOBALS['phpgw_info']['user']['account_id']." ) ORDER BY targettype"; |
---|
484 | |
---|
485 | } |
---|
486 | //echo "aqui".$queryStr ; |
---|
487 | $resArr = $GLOBALS['mydms']->db->getResultArray($queryStr); |
---|
488 | |
---|
489 | |
---|
490 | if (is_bool($resArr) && !$resArr) |
---|
491 | return false; |
---|
492 | |
---|
493 | //$this->_accessList = array("groups" => array(), "users" => array()); |
---|
494 | foreach ($resArr as $row) |
---|
495 | { |
---|
496 | |
---|
497 | //echo "el grupo de acceso es".$row[4]." ".$row["groupid"]."<br>"; |
---|
498 | return $row["mode"]; |
---|
499 | /*if ($row["userid"] != -1) |
---|
500 | array_push($this->_accessList["users"], new UserAccess($row["userid"], $row["mode"])); |
---|
501 | else //if ($row["groupID"] != -1) |
---|
502 | array_push($this->_accessList["groups"], new GroupAccess($row["groupid"], $row["mode"]));*/ |
---|
503 | } |
---|
504 | |
---|
505 | |
---|
506 | return $this->_accessList; |
---|
507 | } |
---|
508 | function getNotifyList() |
---|
509 | { |
---|
510 | if (!isset($this->_notifyList)) |
---|
511 | { |
---|
512 | $cols = array('userID', 'groupID'); |
---|
513 | $where = array( |
---|
514 | 'targetType' => T_DOCUMENT, |
---|
515 | 'target' => $this->_id, |
---|
516 | ); |
---|
517 | |
---|
518 | if(!$this->db->select('phpgw_mydms_Notify', $cols, $where, __LINE__, __FILE__)) { |
---|
519 | return false; |
---|
520 | } |
---|
521 | |
---|
522 | $this->_notifyList = array("groups" => array(), "users" => array()); |
---|
523 | while ($this->db->next_record()) { |
---|
524 | if ($this->db->f('userID') != -1) |
---|
525 | array_push($this->_notifyList["users"], getUser($this->db->f('userid'))); |
---|
526 | else //if ($row["groupID"] != -1) |
---|
527 | array_push($this->_notifyList["groups"], getGroup($this->db->f('groupid'))); |
---|
528 | } |
---|
529 | |
---|
530 | # $queryStr ="SELECT * FROM phpgw_mydms_Notify WHERE targetType = " . T_DOCUMENT . " AND target = " . $this->_id; |
---|
531 | # $resArr = $GLOBALS['mydms']->db->getResultArray($queryStr); |
---|
532 | # if (is_bool($resArr) && $resArr == false) |
---|
533 | # return false; |
---|
534 | # |
---|
535 | # $this->_notifyList = array("groups" => array(), "users" => array()); |
---|
536 | # foreach ($resArr as $row) |
---|
537 | # { |
---|
538 | # if ($row["userID"] != -1) |
---|
539 | # array_push($this->_notifyList["users"], getUser($row["userID"]) ); |
---|
540 | # else //if ($row["groupID"] != -1) |
---|
541 | # array_push($this->_notifyList["groups"], getGroup($row["groupID"]) ); |
---|
542 | # } |
---|
543 | } |
---|
544 | return $this->_notifyList; |
---|
545 | } |
---|
546 | |
---|
547 | function addNotify($userOrGroupID, $isUser) |
---|
548 | { |
---|
549 | $userOrGroup = ($isUser) ? "userID" : "groupID"; |
---|
550 | |
---|
551 | $data = array ( |
---|
552 | 'target' => $this->_id, |
---|
553 | 'targetType' => T_DOCUMENT, |
---|
554 | $userOrGroup => $userOrGroupID, |
---|
555 | ); |
---|
556 | $res = $this->db->insert('phpgw_mydms_Notify', $data, '', __LINE__, __FILE__); |
---|
557 | if (!$res) { |
---|
558 | return false; |
---|
559 | } |
---|
560 | |
---|
561 | # $queryStr = "INSERT INTO phpgw_mydms_Notify (target, targetType, " . $userOrGroup . ") VALUES (" . $this->_id . ", " . T_DOCUMENT . ", " . $userOrGroupID . ")"; |
---|
562 | # if (!$GLOBALS['mydms']->db->getResult($queryStr)) |
---|
563 | # return false; |
---|
564 | |
---|
565 | unset($this->_notifyList); |
---|
566 | return true; |
---|
567 | } |
---|
568 | |
---|
569 | function removeNotify($userOrGroupID, $isUser) |
---|
570 | { |
---|
571 | $userOrGroup = ($isUser) ? "userID" : "groupID"; |
---|
572 | |
---|
573 | $where = array( |
---|
574 | 'targetType' => T_DOCUMENT, |
---|
575 | 'target' => $this->_id, |
---|
576 | $userOrGroup => $userOrGroupID, |
---|
577 | ); |
---|
578 | |
---|
579 | if(!$this->db->delete('phpgw_mydms_Notify', $where, __LINE__, __FILE__)) { |
---|
580 | return false; |
---|
581 | } |
---|
582 | |
---|
583 | # $queryStr = "DELETE FROM phpgw_mydms_Notify WHERE target = " . $this->_id . " AND targetType = " . T_DOCUMENT . " AND " . $userOrGroup . " = " . $userOrGroupID; |
---|
584 | # if (!$GLOBALS['mydms']->db->getResult($queryStr)) |
---|
585 | # return false; |
---|
586 | |
---|
587 | unset($this->_notifyList); |
---|
588 | return true; |
---|
589 | } |
---|
590 | |
---|
591 | |
---|
592 | function addContent($comment, $user, $tmpFile, $orgFileName, $fileType, $mimeType) |
---|
593 | { |
---|
594 | // if ($this->isLocked() && ($user->getID() != $this->getLockingUser()->getID())) |
---|
595 | // return false; |
---|
596 | |
---|
597 | $res = $this->getContent(); |
---|
598 | if (is_bool($res) && !$res) |
---|
599 | return false; |
---|
600 | |
---|
601 | if (count($this->_content) == 0) { |
---|
602 | $newVersion = 1; |
---|
603 | } else { |
---|
604 | $res = $this->getLatestContent(); |
---|
605 | if (is_bool($res) && !$res) |
---|
606 | return false; |
---|
607 | $newVersion = $this->_latestContent->getVersion()+1; |
---|
608 | } |
---|
609 | |
---|
610 | $dir = getSuitableDocumentDir(); |
---|
611 | if (is_bool($res) && !$res) |
---|
612 | return false; |
---|
613 | |
---|
614 | //Kopieren der temporï¿œren Datei |
---|
615 | if(!file_exists($GLOBALS['mydms']->settings->_contentDir . $dir)) |
---|
616 | { |
---|
617 | if (!makeDir($GLOBALS['mydms']->settings->_contentDir . $dir)) |
---|
618 | return false; |
---|
619 | } |
---|
620 | |
---|
621 | if (!copyFile($tmpFile, $GLOBALS['mydms']->settings->_contentDir . $dir . "data" . $fileType)) |
---|
622 | return false; |
---|
623 | |
---|
624 | //Eintrag in phpgw_mydms_DocumentContent |
---|
625 | $insertData = array( |
---|
626 | 'document' => $this->_id, |
---|
627 | 'version' => $newVersion, |
---|
628 | 'comment' => $comment, |
---|
629 | 'date' => mktime(), |
---|
630 | 'createdBy' => $user->getID(), |
---|
631 | 'dir' => $dir, |
---|
632 | 'orgFileName' => $orgFileName, |
---|
633 | 'fileType' => $fileType, |
---|
634 | 'mimeType' => $mimeType, |
---|
635 | ); |
---|
636 | $res = $this->db->insert('phpgw_mydms_DocumentContent', $insertData, '', __LINE__, __FILE__); |
---|
637 | if (!$res) |
---|
638 | return false; |
---|
639 | |
---|
640 | # $queryStr = "INSERT INTO phpgw_mydms_DocumentContent (document, version, comment, date, createdBy, dir, orgFileName, fileType, mimeType) VALUES ". |
---|
641 | # "(".$this->_id.", ".$newVersion.", '".$comment."', ".mktime().", ".$user->getID().", '".$dir."', '".$orgFileName."', '".$fileType."', '" . $mimeType . "')"; |
---|
642 | # if (!$GLOBALS['mydms']->db->getResult($queryStr)) |
---|
643 | # return false; |
---|
644 | |
---|
645 | unset($this->_content); |
---|
646 | unset($this->_latestContent); |
---|
647 | |
---|
648 | $this->getLatestContent(); |
---|
649 | # if ($GLOBALS['mydms']->settings->_enableConverting && in_array($this->_latestContent->getFileType(), array_keys($GLOBALS['mydms']->settings->_convertFileTypes))) |
---|
650 | # $this->_latestContent->convert(); //Auch wenn das schiefgeht, wird deswegen nicht gleich alles "hingeschmissen" (sprich: false zurï¿œckgegeben) |
---|
651 | |
---|
652 | // $this->setLocked(false); |
---|
653 | |
---|
654 | return true; |
---|
655 | } |
---|
656 | |
---|
657 | function getContent() |
---|
658 | { |
---|
659 | if (!isset($this->_content)) |
---|
660 | { |
---|
661 | $cols = array('id', 'document', 'version', 'comment', 'date', 'createdBy', 'dir', 'orgFileName', 'fileType', 'mimeType'); |
---|
662 | $where = array( |
---|
663 | 'document' => $this->_id, |
---|
664 | ); |
---|
665 | |
---|
666 | if(!$this->db->select('phpgw_mydms_DocumentContent', $cols, $where, __LINE__, __FILE__, false, 'ORDER BY version')) { |
---|
667 | return false; |
---|
668 | } |
---|
669 | |
---|
670 | $this->_content = array(); |
---|
671 | while ($this->db->next_record()) { |
---|
672 | array_push( |
---|
673 | $this->_content, |
---|
674 | new DocumentContent( |
---|
675 | $this->db->f('id'), |
---|
676 | $this->db->f('document'), |
---|
677 | $this->db->f('version'), |
---|
678 | $this->db->f('comment'), |
---|
679 | $this->db->f('date'), |
---|
680 | $this->db->f('createdby'), |
---|
681 | $this->db->f('dir'), |
---|
682 | $this->db->f('orgfilename'), |
---|
683 | $this->db->f('filetype'), |
---|
684 | $this->db->f('mimetype') |
---|
685 | ) |
---|
686 | ); |
---|
687 | } |
---|
688 | |
---|
689 | # $queryStr = "SELECT * FROM phpgw_mydms_DocumentContent WHERE document = ".$this->_id." ORDER BY version"; |
---|
690 | # $resArr = $GLOBALS['mydms']->db->getResultArray($queryStr); |
---|
691 | # if (is_bool($resArr) && !$res) |
---|
692 | # return false; |
---|
693 | # |
---|
694 | # $this->_content = array(); |
---|
695 | # foreach ($resArr as $row) |
---|
696 | # array_push($this->_content, new DocumentContent($row["id"], $row["document"], $row["version"], $row["comment"], $row["date"], $row["createdBy"], $row["dir"], $row["orgFileName"], $row["fileType"], $row["mimeType"])); |
---|
697 | } |
---|
698 | |
---|
699 | return $this->_content; |
---|
700 | } |
---|
701 | |
---|
702 | function getContentByVersion($version) |
---|
703 | { |
---|
704 | if (!is_numeric($version)) |
---|
705 | die ("invalid version"); |
---|
706 | |
---|
707 | if (isset($this->_content)) |
---|
708 | { |
---|
709 | foreach ($this->_content as $revision) |
---|
710 | { |
---|
711 | if ($revision->getVersion() == $version) |
---|
712 | return $revision; |
---|
713 | } |
---|
714 | return false; |
---|
715 | } |
---|
716 | |
---|
717 | $cols = array('id', 'document', 'version', 'comment', 'date', 'createdBy', 'dir', 'orgFileName', 'fileType', 'mimeType'); |
---|
718 | $where = array( |
---|
719 | 'document' => $this->_id, |
---|
720 | 'version' => $version, |
---|
721 | ); |
---|
722 | |
---|
723 | if(!$this->db->select('phpgw_mydms_DocumentContent', $cols, $where, __LINE__, __FILE__, false, 'ORDER BY version,id desc')) { |
---|
724 | return false; |
---|
725 | } |
---|
726 | |
---|
727 | if ($this->db->next_record()) { |
---|
728 | return new DocumentContent( |
---|
729 | $this->db->f('id'), |
---|
730 | $this->db->f('document'), |
---|
731 | $this->db->f('version'), |
---|
732 | $this->db->f('comment'), |
---|
733 | $this->db->f('date'), |
---|
734 | $this->db->f('createdby'), |
---|
735 | $this->db->f('dir'), |
---|
736 | $this->db->f('orgfilename'), |
---|
737 | $this->db->f('filetype'), |
---|
738 | $this->db->f('mimetype') |
---|
739 | ); |
---|
740 | } else { |
---|
741 | return false; |
---|
742 | } |
---|
743 | |
---|
744 | # $queryStr = "SELECT * FROM phpgw_mydms_DocumentContent WHERE document = ".$this->_id." AND version = " . $version; |
---|
745 | # $resArr = $GLOBALS['mydms']->db->getResultArray($queryStr); |
---|
746 | # if (is_bool($resArr) && !$res) |
---|
747 | # return false; |
---|
748 | # if (count($resArr) != 1) |
---|
749 | # return false; |
---|
750 | # |
---|
751 | # $resArr = $resArr[0]; |
---|
752 | # return new DocumentContent($resArr["id"], $resArr["document"], $resArr["version"], $resArr["comment"], $resArr["date"], $resArr["createdBy"], $resArr["dir"], $resArr["orgFileName"], $resArr["fileType"], $resArr["mimeType"]); |
---|
753 | } |
---|
754 | |
---|
755 | function getLatestContent() |
---|
756 | { |
---|
757 | if (!isset($this->_latestContent)) |
---|
758 | { |
---|
759 | /* if (isset($this->_content)) |
---|
760 | { |
---|
761 | $this->getContent(); |
---|
762 | $this->_latestContent = $this->_content[count($this->_content)-1]; |
---|
763 | return $this->_latestContent; |
---|
764 | } |
---|
765 | */ |
---|
766 | $cols = array('id', 'document', 'version', 'comment', 'date', 'createdBy', 'dir', 'orgFileName', 'fileType', 'mimeType'); |
---|
767 | $where = array( |
---|
768 | 'document' => $this->_id, |
---|
769 | ); |
---|
770 | |
---|
771 | if(!$this->db->select('phpgw_mydms_DocumentContent', $cols, $where, __LINE__, __FILE__, false, 'ORDER BY version DESC')) { |
---|
772 | return false; |
---|
773 | } |
---|
774 | |
---|
775 | $this->_latestContent = array(); |
---|
776 | if ($this->db->next_record()) { |
---|
777 | $this->_latestContent = new DocumentContent( |
---|
778 | $this->db->f('id'), |
---|
779 | $this->db->f('document'), |
---|
780 | $this->db->f('version'), |
---|
781 | $this->db->f('comment'), |
---|
782 | $this->db->f('date'), |
---|
783 | $this->db->f('createdby'), |
---|
784 | $this->db->f('dir'), |
---|
785 | $this->db->f('orgfilename'), |
---|
786 | $this->db->f('filetype'), |
---|
787 | $this->db->f('mimeType') |
---|
788 | ); |
---|
789 | } |
---|
790 | |
---|
791 | # $queryStr = "SELECT * FROM phpgw_mydms_DocumentContent WHERE document = ".$this->_id." ORDER BY version DESC"; |
---|
792 | # $resArr = $GLOBALS['mydms']->db->getResultArray($queryStr); |
---|
793 | # if (is_bool($resArr) && !$resArr) |
---|
794 | # return false; |
---|
795 | # |
---|
796 | # $resArr = $resArr[0]; |
---|
797 | # $this->_latestContent = new DocumentContent($resArr["id"], $resArr["document"], $resArr["version"], $resArr["comment"], $resArr["date"], $resArr["createdBy"], $resArr["dir"], $resArr["orgFileName"], $resArr["fileType"], $resArr["mimeType"]); |
---|
798 | } |
---|
799 | return $this->_latestContent; |
---|
800 | } |
---|
801 | |
---|
802 | function getDocumentLinks() |
---|
803 | { |
---|
804 | if (!isset($this->_documentLinks)) |
---|
805 | { |
---|
806 | $queryStr = "SELECT * FROM phpgw_mydms_DocumentLinks WHERE document = " . $this->_id; |
---|
807 | $resArr = $GLOBALS['mydms']->db->getResultArray($queryStr); |
---|
808 | if (is_bool($resArr) && !$resArr) |
---|
809 | return false; |
---|
810 | $this->_documentLinks = array(); |
---|
811 | |
---|
812 | foreach ($resArr as $row) |
---|
813 | array_push($this->_documentLinks, new DocumentLink($row["id"], $row["document"], $row["target"], $row["userID"], $row["public"])); |
---|
814 | } |
---|
815 | return $this->_documentLinks; |
---|
816 | } |
---|
817 | |
---|
818 | function addDocumentLink($targetID, $userID, $public) |
---|
819 | { |
---|
820 | $data = array( |
---|
821 | 'document' => $this->_id, |
---|
822 | 'target' => $targetID, |
---|
823 | 'userID' => $userID, |
---|
824 | 'public' => $GLOBALS['phpgw']->db->quote($public,'bool'), |
---|
825 | ); |
---|
826 | $res = $this->db->insert('phpgw_mydms_DocumentLinks', $data, '', __LINE__, __FILE__); |
---|
827 | if (!$res) |
---|
828 | return false; |
---|
829 | |
---|
830 | # $queryStr = "INSERT INTO phpgw_mydms_DocumentLinks(document, target, userID, public) VALUES (".$this->_id.", ".$targetID.", ".$userID.", " . $GLOBALS['phpgw']->db->quote($public,'bool').")"; |
---|
831 | # if (!$GLOBALS['mydms']->db->getResult($queryStr)) |
---|
832 | # return false; |
---|
833 | |
---|
834 | unset($this->_documentLinks); |
---|
835 | return true; |
---|
836 | } |
---|
837 | |
---|
838 | function removeDocumentLink($linkID) |
---|
839 | { |
---|
840 | $where = array( |
---|
841 | 'id' => $linkID, |
---|
842 | ); |
---|
843 | |
---|
844 | if(!$this->db->delete('phpgw_mydms_DocumentLinks', $where, __LINE__, __FILE__)) { |
---|
845 | return false; |
---|
846 | } |
---|
847 | |
---|
848 | # $queryStr = "DELETE FROM phpgw_mydms_DocumentLinks WHERE id = " . $linkID; |
---|
849 | # if (!$GLOBALS['mydms']->db->getResult($queryStr)) |
---|
850 | # return false; |
---|
851 | unset ($this->_documentLinks); |
---|
852 | return true; |
---|
853 | } |
---|
854 | |
---|
855 | |
---|
856 | function remove() |
---|
857 | { |
---|
858 | $res = $this->getContent(); |
---|
859 | if (is_bool($res) && !$res) return false; |
---|
860 | |
---|
861 | for ($i = 0; $i < count($this->_content); $i++) { |
---|
862 | if (!$this->_content[$i]->remove()) { |
---|
863 | return false; |
---|
864 | } |
---|
865 | } |
---|
866 | |
---|
867 | $where = array('id' => $this->_id); |
---|
868 | if(!$this->db->delete('phpgw_mydms_Documents', $where, __LINE__, __FILE__)) { |
---|
869 | return false; |
---|
870 | } |
---|
871 | |
---|
872 | $where = array('target' => $this->_id, 'targetType' => T_DOCUMENT); |
---|
873 | if(!$this->db->delete('phpgw_mydms_ACLs', $where, __LINE__, __FILE__)) { |
---|
874 | return false; |
---|
875 | } |
---|
876 | if(!$this->db->delete('phpgw_mydms_Notify', $where, __LINE__, __FILE__)) { |
---|
877 | return false; |
---|
878 | } |
---|
879 | |
---|
880 | $where = array('document' => $this->_id, 'target' => $this->_id); |
---|
881 | if(!$this->db->delete('phpgw_mydms_DocumentLinks', $where, __LINE__, __FILE__)) { |
---|
882 | return false; |
---|
883 | } |
---|
884 | |
---|
885 | # $queryStr = "DELETE FROM phpgw_mydms_Documents WHERE id = " . $this->_id; |
---|
886 | # if (!$GLOBALS['mydms']->db->getResult($queryStr)) |
---|
887 | # return false; |
---|
888 | # $queryStr = "DELETE FROM phpgw_mydms_ACLs WHERE target = " . $this->_id . " AND targetType = " . T_DOCUMENT; |
---|
889 | # if (!$GLOBALS['mydms']->db->getResult($queryStr)) |
---|
890 | # return false; |
---|
891 | # $queryStr = "DELETE FROM phpgw_mydms_Notify WHERE target = " . $this->_id . " AND targetType = " . T_DOCUMENT; |
---|
892 | # if (!$GLOBALS['mydms']->db->getResult($queryStr)) |
---|
893 | # return false; |
---|
894 | # $queryStr = "DELETE FROM phpgw_mydms_DocumentLinks WHERE document = " . $this->_id . " OR target = " . $this->_id; |
---|
895 | # if (!$GLOBALS['mydms']->db->getResult($queryStr)) |
---|
896 | # return false; |
---|
897 | |
---|
898 | return true; |
---|
899 | } |
---|
900 | } |
---|
901 | |
---|
902 | /* ---------------------------------------------------------------------------------------------------- */ |
---|
903 | |
---|
904 | /** |
---|
905 | * Die Datei wird als "data.ext" (z.b. data.txt) gespeichert. Getrennt davon wird in der DB der ursprï¿œngliche |
---|
906 | * Dateiname festgehalten (-> $orgFileName). Die Datei wird deshalb nicht unter diesem ursprï¿œnglichen Namen |
---|
907 | * gespeichert, da es zu Problemen mit verschiedenen Dateisystemen kommen kann: Linux hat z.b. Probleme mit |
---|
908 | * deutschen Umlauten, wï¿œhrend Windows wiederum den Doppelpunkt in Dateinamen nicht verwenden kann. |
---|
909 | * Der ursprï¿œngliche Dateiname wird nur zum Download verwendet (siehe op.Download.pgp) |
---|
910 | */ |
---|
911 | class DocumentContent |
---|
912 | { |
---|
913 | |
---|
914 | function DocumentContent($id, $documentID, $version, $comment, $date, $userID, $dir, $orgFileName, $fileType, $mimeType) |
---|
915 | { |
---|
916 | $this->_id = $id; |
---|
917 | $this->_documentID = $documentID; |
---|
918 | $this->_version = $version; |
---|
919 | $this->_comment = $comment; |
---|
920 | $this->_date = $date; |
---|
921 | $this->_userID = $userID; |
---|
922 | $this->_dir = $dir; |
---|
923 | $this->_orgFileName = $orgFileName; |
---|
924 | $this->_fileType = $fileType; |
---|
925 | $this->_mimeType = $mimeType; |
---|
926 | |
---|
927 | $this->db = clone($GLOBALS['phpgw']->db); |
---|
928 | $this->db->set_app('mydms'); |
---|
929 | } |
---|
930 | |
---|
931 | function getVersion() { return $this->_version; } |
---|
932 | function getComment() { return $this->_comment; } |
---|
933 | function getDate() { return $this->_date; } |
---|
934 | function getOriginalFileName() { return $this->_orgFileName; } |
---|
935 | function getFileType() { return $this->_fileType; } |
---|
936 | function getFileName(){ return "data" . $this->_fileType; } |
---|
937 | function getDir() { return $this->_dir; } |
---|
938 | function getMimeType() { return $this->_mimeType; } |
---|
939 | function getUser() |
---|
940 | { |
---|
941 | if (!isset($this->_user)) |
---|
942 | $this->_user = getUser($this->_userID); |
---|
943 | return $this->_user; |
---|
944 | } |
---|
945 | function getPath() { return $this->_dir ."data" . $this->_fileType; } |
---|
946 | |
---|
947 | function convert() |
---|
948 | { |
---|
949 | if (file_exists($GLOBALS['mydms']->settings->_contentDir . $this->_dir . "index.html")) |
---|
950 | return true; |
---|
951 | |
---|
952 | if (!in_array($this->_fileType, array_keys($GLOBALS['mydms']->settings->_convertFileTypes))) |
---|
953 | return false; |
---|
954 | |
---|
955 | $source = $GLOBALS['mydms']->settings->_contentDir . $this->_dir . $this->getFileName(); |
---|
956 | $target = $GLOBALS['mydms']->settings->_contentDir . $this->_dir . "index.html"; |
---|
957 | // $source = str_replace("/", "\\", $source); |
---|
958 | // $target = str_replace("/", "\\", $target); |
---|
959 | |
---|
960 | $command = $GLOBALS['mydms']->settings->_convertFileTypes[$this->_fileType]; |
---|
961 | $command = str_replace("{SOURCE}", "\"$source\"", $command); |
---|
962 | $command = str_replace("{TARGET}", "\"$target\"", $command); |
---|
963 | |
---|
964 | $output = array(); |
---|
965 | $res = 0; |
---|
966 | exec($command, $output, $res); |
---|
967 | |
---|
968 | if ($res != 0) |
---|
969 | { |
---|
970 | print (implode("\n", $output)); |
---|
971 | return false; |
---|
972 | } |
---|
973 | return true; |
---|
974 | } |
---|
975 | |
---|
976 | function viewOnline() |
---|
977 | { |
---|
978 | if (in_array($this->_fileType, $GLOBALS['mydms']->settings->_viewOnlineFileTypes)) |
---|
979 | return true; |
---|
980 | if ($GLOBALS['mydms']->settings->_enableConverting && in_array($this->_fileType, array_keys($GLOBALS['mydms']->settings->_convertFileTypes))) |
---|
981 | if ($this->wasConverted()) |
---|
982 | return true; |
---|
983 | |
---|
984 | return false; |
---|
985 | } |
---|
986 | |
---|
987 | function wasConverted() |
---|
988 | { |
---|
989 | return file_exists($GLOBALS['mydms']->settings->_contentDir . $this->_dir . "index.html"); |
---|
990 | } |
---|
991 | |
---|
992 | function getURL() |
---|
993 | { |
---|
994 | if (!$this->viewOnline()) |
---|
995 | return false; |
---|
996 | |
---|
997 | if (in_array($this->_fileType, $GLOBALS['mydms']->settings->_viewOnlineFileTypes)) |
---|
998 | return "/" . $this->_documentID . "/" . $this->_version . "/" . $this->getOriginalFileName(); |
---|
999 | else |
---|
1000 | return "/" . $this->_documentID . "/" . $this->_version . "/index.html"; |
---|
1001 | } |
---|
1002 | |
---|
1003 | function remove() |
---|
1004 | { |
---|
1005 | # does this check make sense here??? Lars |
---|
1006 | #if (!removeDir($GLOBALS['mydms']->settings->_contentDir . $this->_dir)) { |
---|
1007 | # return false; |
---|
1008 | #} |
---|
1009 | |
---|
1010 | $where = array( |
---|
1011 | 'id' => $this->_id, |
---|
1012 | ); |
---|
1013 | |
---|
1014 | if(!$this->db->delete('phpgw_mydms_DocumentContent', $where, __LINE__, __FILE__)) { |
---|
1015 | return false; |
---|
1016 | } |
---|
1017 | |
---|
1018 | return true; |
---|
1019 | } |
---|
1020 | } |
---|
1021 | |
---|
1022 | |
---|
1023 | /* ---------------------------------------------------------------------------------------------------- */ |
---|
1024 | function getDocumentLink($linkID) |
---|
1025 | { |
---|
1026 | if (!is_numeric($linkID)) |
---|
1027 | die ("invalid linkID"); |
---|
1028 | |
---|
1029 | $queryStr = "SELECT * FROM phpgw_mydms_DocumentLinks WHERE id = " . $linkID; |
---|
1030 | $resArr = $GLOBALS['mydms']->db->getResultArray($queryStr); |
---|
1031 | if (is_bool($resArr) && !$resArr) |
---|
1032 | return false; |
---|
1033 | |
---|
1034 | $resArr = $resArr[0]; |
---|
1035 | return new DocumentLink($resArr["id"], $resArr["document"], $resArr["target"], $resArr["userID"], $resArr["public"]); |
---|
1036 | } |
---|
1037 | |
---|
1038 | function filterDocumentLinks($user, $links) |
---|
1039 | { |
---|
1040 | $tmp = array(); |
---|
1041 | foreach ($links as $link) |
---|
1042 | if ($link->isPublic() || ($link->_userID == $user->getID()) || ($user->getID() == $GLOBALS['mydms']->settings->_adminID) ) |
---|
1043 | array_push($tmp, $link); |
---|
1044 | return $tmp; |
---|
1045 | } |
---|
1046 | |
---|
1047 | class DocumentLink |
---|
1048 | { |
---|
1049 | var $_id; |
---|
1050 | var $_documentID; |
---|
1051 | var $_targetID; |
---|
1052 | var $_userID; |
---|
1053 | var $_public; |
---|
1054 | |
---|
1055 | function DocumentLink($id, $documentID, $targetID, $userID, $public) |
---|
1056 | { |
---|
1057 | $this->_id = $id; |
---|
1058 | $this->_documentID = $documentID; |
---|
1059 | $this->_targetID = $targetID; |
---|
1060 | $this->_userID = $userID; |
---|
1061 | $this->_public = $public; |
---|
1062 | |
---|
1063 | $this->db = clone($GLOBALS['phpgw']->db); |
---|
1064 | $this->db->set_app('mydms'); |
---|
1065 | } |
---|
1066 | |
---|
1067 | function getID() { return $this->_id; } |
---|
1068 | |
---|
1069 | function getDocument() |
---|
1070 | { |
---|
1071 | if (!isset($this->_document)) |
---|
1072 | $this->_document = getDocument($this->_documentID); |
---|
1073 | return $this->_document; |
---|
1074 | } |
---|
1075 | |
---|
1076 | function getTarget() |
---|
1077 | { |
---|
1078 | if (!isset($this->_target)) |
---|
1079 | $this->_target = getDocument($this->_targetID); |
---|
1080 | return $this->_target; |
---|
1081 | } |
---|
1082 | |
---|
1083 | function getUser() |
---|
1084 | { |
---|
1085 | if (!isset($this->_user)) |
---|
1086 | $this->_user = getUser($this->_userID); |
---|
1087 | return $this->_user; |
---|
1088 | } |
---|
1089 | |
---|
1090 | function isPublic() { return $this->_public; } |
---|
1091 | |
---|
1092 | function remove() |
---|
1093 | { |
---|
1094 | $where = array( |
---|
1095 | 'id' => $this->_id, |
---|
1096 | ); |
---|
1097 | |
---|
1098 | if(!$this->db->delete('phpgw_mydms_DocumentLinks', $where, __LINE__, __FILE__)) { |
---|
1099 | return false; |
---|
1100 | } |
---|
1101 | # $queryStr = "DELETE FROM phpgw_mydms_DocumentLinks WHERE id = " . $this->_id; |
---|
1102 | # if (!$GLOBALS['mydms']->db->getResult($queryStr)) |
---|
1103 | # return false; |
---|
1104 | |
---|
1105 | return true; |
---|
1106 | } |
---|
1107 | } |
---|