[3526] | 1 | <?php |
---|
| 2 | function getFolder($id) |
---|
| 3 | { |
---|
| 4 | if (!is_numeric($id)) |
---|
| 5 | die ("invalid folderid"); |
---|
[4362] | 6 | $queryStr = "SELECT id,name,parent,comment,owner,inheritaccess,defaultaccess,sequence FROM phpgw_mydms_folders WHERE id = " . $id; |
---|
| 7 | |
---|
| 8 | //echo "<br>folderrrrr".$queryStr."<br>"; |
---|
[3526] | 9 | $resArr = $GLOBALS['mydms']->db->getResultArray($queryStr); |
---|
| 10 | |
---|
| 11 | if (is_bool($resArr) && $resArr == false) |
---|
| 12 | return false; |
---|
| 13 | else if (count($resArr) != 1) |
---|
| 14 | return false; |
---|
| 15 | |
---|
| 16 | $resArr = $resArr[0]; |
---|
| 17 | if($id == 1) { |
---|
[4362] | 18 | $resArr[6] = M_READ; |
---|
[3526] | 19 | } |
---|
[4362] | 20 | // echo $resArr["id"]." ".$resArr[6]." ".$resArr["parent"]." ".$id." ".$GLOBALS['phpgw_info']['user']['account_id']." dddd ".$resArr[5]." dddd ".$resArr["defaultAccess"]; |
---|
[3526] | 21 | |
---|
[4362] | 22 | $newFolder = new Folder($resArr["id"], $resArr["name"], $resArr["parent"], $resArr["comment"], $resArr["owner"], $resArr["inheritaccess"], $resArr["defaultaccess"], $resArr["sequence"]); |
---|
| 23 | //echo "llll".$GLOBALS['phpgw_info']['user']['account_id']." ".$resArr["inheritaccess"]; |
---|
[3526] | 24 | #print $resArr["name"]."<br>"; |
---|
| 25 | #print $newFolder->getAccessMode(getUser($GLOBALS['phpgw_info']['user']['account_id']))."<br>"; |
---|
[4362] | 26 | if($newFolder->getAccessMode(getUser($GLOBALS['phpgw_info']['user']['account_id'])) > 1){ |
---|
| 27 | //echo "retornoooo"; |
---|
| 28 | return $newFolder; |
---|
| 29 | } |
---|
| 30 | else{ |
---|
[3526] | 31 | return false; |
---|
[4362] | 32 | } |
---|
[3526] | 33 | } |
---|
| 34 | |
---|
| 35 | |
---|
| 36 | /**********************************************************************\ |
---|
| 37 | | Folder-Klasse | |
---|
| 38 | \**********************************************************************/ |
---|
| 39 | |
---|
| 40 | class Folder |
---|
| 41 | { |
---|
| 42 | var $_id; |
---|
| 43 | var $_name; |
---|
| 44 | var $_parentID; |
---|
| 45 | var $_comment; |
---|
| 46 | var $_ownerID; |
---|
| 47 | var $_inheritAccess; |
---|
| 48 | var $_defaultAccess; |
---|
| 49 | var $_sequence; |
---|
| 50 | |
---|
| 51 | function Folder($id, $name, $parentID, $comment, $ownerID, $inheritAccess, $defaultAccess, $sequence) |
---|
| 52 | { |
---|
[4362] | 53 | //echo "aaaaaccccseexxx".$inheritAccess; |
---|
| 54 | if($inheritAccess=='f'){ |
---|
| 55 | unset($inheritAccess); |
---|
| 56 | } |
---|
[3526] | 57 | $this->_id = $id; |
---|
| 58 | $this->_name = $name; |
---|
| 59 | $this->_parentID = $parentID; |
---|
| 60 | $this->_comment = $comment; |
---|
| 61 | $this->_ownerID = $ownerID; |
---|
| 62 | $this->_inheritAccess = $inheritAccess; |
---|
| 63 | $this->_defaultAccess = $defaultAccess; |
---|
| 64 | $this->_sequence = $sequence; |
---|
| 65 | $this->db = clone($GLOBALS['phpgw']->db); |
---|
| 66 | $this->db->set_app('mydms'); |
---|
[4362] | 67 | // echo"accc".$defaultAccess."lll{ñ{{ñ".$inheritAccess; |
---|
[3526] | 68 | } |
---|
| 69 | |
---|
| 70 | function getID() { return $this->_id; } |
---|
| 71 | |
---|
| 72 | function getName() { return $this->_name; } |
---|
| 73 | |
---|
| 74 | function setName($newName) |
---|
| 75 | { |
---|
| 76 | $data = array('name' => $newName); |
---|
| 77 | $where = array('id' => $this->_id); |
---|
| 78 | |
---|
[4362] | 79 | if(!$this->db->update('phpgw_mydms_folders', $data, $where, __LINE__, __FILE__)) |
---|
[3526] | 80 | return false; |
---|
| 81 | |
---|
| 82 | $this->_name = $newName; |
---|
| 83 | |
---|
| 84 | return true; |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | function getComment() { return $this->_comment; } |
---|
| 88 | |
---|
| 89 | function setComment($newComment) |
---|
| 90 | { |
---|
| 91 | $data = array('comment' => $newComment); |
---|
| 92 | $where = array('id' => $this->_id); |
---|
| 93 | |
---|
[4362] | 94 | if(!$this->db->update('phpgw_mydms_folders', $data, $where, __LINE__, __FILE__)) |
---|
[3526] | 95 | return false; |
---|
| 96 | |
---|
| 97 | $this->_comment = $newComment; |
---|
| 98 | |
---|
| 99 | return true; |
---|
| 100 | } |
---|
| 101 | |
---|
| 102 | function getParent() |
---|
| 103 | { |
---|
| 104 | if (!isset($this->_parentID) || ($this->_parentID == "") || ($this->_parentID == 0)) |
---|
| 105 | return false; |
---|
| 106 | |
---|
| 107 | if (!isset($this->_parent)) |
---|
| 108 | $this->_parent = getFolder($this->_parentID); |
---|
| 109 | return $this->_parent; |
---|
| 110 | } |
---|
| 111 | |
---|
| 112 | function setParent($newParent) |
---|
| 113 | { |
---|
| 114 | $data = array('parent' => $newParent->getID()); |
---|
| 115 | $where = array('id' => $this->_id); |
---|
| 116 | |
---|
[4362] | 117 | if(!$this->db->update('phpgw_mydms_folders', $data, $where, __LINE__, __FILE__)) |
---|
[3526] | 118 | return false; |
---|
| 119 | |
---|
| 120 | $this->_parentID = $newParent->getID(); |
---|
| 121 | $this->_parent = $newParent; |
---|
| 122 | |
---|
| 123 | return true; |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | function getOwner() |
---|
| 127 | { |
---|
| 128 | if (!isset($this->_owner)) |
---|
| 129 | $this->_owner = getUser($this->_ownerID); |
---|
| 130 | return $this->_owner; |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | function setOwner($user) |
---|
| 134 | { |
---|
| 135 | $data = array('owner' => $user->getID()); |
---|
| 136 | $where = array('id' => $this->_id); |
---|
| 137 | |
---|
[4362] | 138 | if(!$this->db->update('phpgw_mydms_folders', $data, $where, __LINE__, __FILE__)) |
---|
[3526] | 139 | return false; |
---|
| 140 | |
---|
| 141 | $this->_ownerID = $user->getID(); |
---|
| 142 | $this->_owner = $user; |
---|
| 143 | return true; |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | function getDefaultAccess() |
---|
| 147 | { |
---|
| 148 | if ($this->inheritsAccess()) |
---|
| 149 | { |
---|
| 150 | $res = $this->getParent(); |
---|
| 151 | if (!$res) return false; |
---|
| 152 | return $this->_parent->getDefaultAccess(); |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | return $this->_defaultAccess; |
---|
| 156 | } |
---|
| 157 | |
---|
| 158 | function setDefaultAccess($mode) |
---|
| 159 | { |
---|
| 160 | $data = array('defaultAccess' => $mode); |
---|
| 161 | $where = array('id' => $this->_id); |
---|
| 162 | |
---|
[4362] | 163 | if(!$this->db->update('phpgw_mydms_folders', $data, $where, __LINE__, __FILE__)) |
---|
[3526] | 164 | return false; |
---|
| 165 | |
---|
| 166 | $this->_defaulAccess = $mode; |
---|
| 167 | return true; |
---|
| 168 | } |
---|
| 169 | |
---|
| 170 | function inheritsAccess() { return $this->_inheritAccess; } |
---|
| 171 | |
---|
| 172 | function setInheritAccess($inheritAccess) |
---|
| 173 | { |
---|
| 174 | $inheritAccess = $inheritAccess ? "1" : "0"; |
---|
| 175 | |
---|
| 176 | $data = array('inheritAccess' => $inheritAccess); |
---|
| 177 | $where = array('id' => $this->_id); |
---|
| 178 | |
---|
[4362] | 179 | if(!$this->db->update('phpgw_mydms_folders', $data, $where, __LINE__, __FILE__)) |
---|
[3526] | 180 | return false; |
---|
| 181 | |
---|
| 182 | $this->_inheritAccess = $inheritAccess; |
---|
| 183 | return true; |
---|
| 184 | } |
---|
| 185 | |
---|
| 186 | function getSequence() { return $this->_sequence; } |
---|
| 187 | |
---|
| 188 | function setSequence($seq) |
---|
| 189 | { |
---|
| 190 | $data = array('sequence' => $seq); |
---|
| 191 | $where = array('id' => $this->_id); |
---|
| 192 | |
---|
[4362] | 193 | if(!$this->db->update('phpgw_mydms_folders', $data, $where, __LINE__, __FILE__)) |
---|
[3526] | 194 | return false; |
---|
| 195 | |
---|
| 196 | $this->_sequence = $seq; |
---|
| 197 | return true; |
---|
| 198 | } |
---|
| 199 | |
---|
| 200 | function getSubFolders() |
---|
| 201 | { |
---|
| 202 | if (!isset($this->_subFolders)) |
---|
| 203 | { |
---|
[4362] | 204 | $queryStr = "SELECT * FROM phpgw_mydms_folders WHERE parent = " . $this->_id . " ORDER BY sequence"; |
---|
[3526] | 205 | |
---|
| 206 | |
---|
| 207 | $resArr = $GLOBALS['mydms']->db->getResultArray($queryStr); |
---|
| 208 | if (is_bool($resArr) && $resArr == false) |
---|
| 209 | return false; |
---|
| 210 | |
---|
| 211 | $this->_subFolders = array(); |
---|
| 212 | for ($i = 0; $i < count($resArr); $i++) |
---|
| 213 | { |
---|
| 214 | $newSubFolder = new Folder($resArr[$i]["id"], $resArr[$i]["name"], $resArr[$i]["parent"], $resArr[$i]["comment"], $resArr[$i]["owner"], $resArr[$i]["inheritaccess"], $resArr[$i]["defaultaccess"], $resArr[$i]["sequence"]); |
---|
| 215 | |
---|
| 216 | if($newSubFolder->getAccessMode(getUser($GLOBALS['phpgw_info']['user']['account_id'])) > 1) |
---|
| 217 | $this->_subFolders[$i] = $newSubFolder; |
---|
| 218 | } |
---|
| 219 | } |
---|
| 220 | |
---|
| 221 | return $this->_subFolders; |
---|
| 222 | } |
---|
| 223 | |
---|
| 224 | function addSubFolder($name, $comment, $owner, $sequence) |
---|
| 225 | { |
---|
| 226 | $ownerid = $GLOBALS['phpgw_info']['user']['account_id']; |
---|
| 227 | //inheritAccess = true, defaultAccess = M_READ |
---|
| 228 | |
---|
| 229 | $insertData = array( |
---|
| 230 | 'name' => $name, |
---|
| 231 | 'parent' => $this->_id, |
---|
| 232 | 'comment' => $comment, |
---|
| 233 | 'owner' => $ownerid, |
---|
| 234 | 'inheritAccess' => true, |
---|
| 235 | 'defaultAccess' => M_READ, |
---|
| 236 | 'sequence' => $sequence, |
---|
| 237 | ); |
---|
[4362] | 238 | $res = $this->db->insert('phpgw_mydms_folders', $insertData, '', __LINE__, __FILE__, 'mydms'); |
---|
[3526] | 239 | |
---|
| 240 | if (!$res) |
---|
| 241 | return false; |
---|
| 242 | |
---|
| 243 | unset($this->_subFolders); |
---|
| 244 | |
---|
[4362] | 245 | return getFolder($this->db->get_last_insert_id('phpgw_mydms_folders','id')); |
---|
[3526] | 246 | } |
---|
| 247 | |
---|
| 248 | /** |
---|
| 249 | * Gibt ein Array mit allen Eltern, "Groï¿œelter" usw bis zum RootFolder zurï¿œck |
---|
| 250 | * Der Ordner selbst ist das letzte Element dieses Arrays |
---|
| 251 | */ |
---|
| 252 | function getPath() |
---|
| 253 | { |
---|
| 254 | if (!isset($this->_parentID) || ($this->_parentID == "") || ($this->_parentID == 0)) |
---|
| 255 | return array($this); |
---|
| 256 | else |
---|
| 257 | { |
---|
| 258 | $res = $this->getParent(); |
---|
| 259 | if (!$res) return false; |
---|
| 260 | |
---|
| 261 | $path = $this->_parent->getPath(); |
---|
| 262 | if (!$path) return false; |
---|
| 263 | |
---|
| 264 | array_push($path, $this); |
---|
| 265 | return $path; |
---|
| 266 | } |
---|
| 267 | } |
---|
| 268 | |
---|
| 269 | /** |
---|
| 270 | * Gibt ein Array mit allen Eltern, "Groï¿œelter" usw bis zum RootFolder zurï¿œck |
---|
| 271 | * Der Ordner selbst ist das letzte Element dieses Arrays |
---|
| 272 | */ |
---|
| 273 | function getPathNew() |
---|
| 274 | { |
---|
| 275 | if (!isset($this->_parentID) || ($this->_parentID == "") || ($this->_parentID == 0)) |
---|
| 276 | return array($this->_id => $this); |
---|
| 277 | else |
---|
| 278 | { |
---|
| 279 | $res = $this->getParent(); |
---|
| 280 | if (!$res) return false; |
---|
| 281 | |
---|
| 282 | #print "search parent ".$this->_id."<br>"; |
---|
| 283 | $path = $this->_parent->getPathNew(); |
---|
| 284 | #print "_parent->getPathNew(".$this->_id."):<br>"; |
---|
| 285 | #print "my parent ".$this->_id."<br>"; |
---|
| 286 | #_debug_array($path); |
---|
| 287 | if (!$path) return false; |
---|
| 288 | |
---|
| 289 | #$path = array_merge($path, array($this->_id => $this)); |
---|
| 290 | #$path[] = array($this); |
---|
| 291 | unset($this->_parent); |
---|
| 292 | #print "me ".$this->_id."<br>"; |
---|
| 293 | #_debug_array($this); |
---|
| 294 | $path[$this->_id] = $this; |
---|
| 295 | return $path; |
---|
| 296 | } |
---|
| 297 | } |
---|
| 298 | |
---|
| 299 | /** |
---|
| 300 | * ï¿œberprï¿œft, ob dieser Ordner ein Unterordner von $folder ist |
---|
| 301 | */ |
---|
| 302 | function isDescendant($folder) |
---|
| 303 | { |
---|
| 304 | if ($this->_parentID == $folder->getID()) |
---|
| 305 | return true; |
---|
| 306 | else if (isset($this->_parentID)) |
---|
| 307 | { |
---|
| 308 | $res = $this->getParent(); |
---|
| 309 | if (!$res) return false; |
---|
| 310 | |
---|
| 311 | return $this->_parent->isDescendant($folder); |
---|
| 312 | } |
---|
| 313 | else |
---|
| 314 | return false; |
---|
| 315 | } |
---|
| 316 | |
---|
| 317 | function getDocuments() |
---|
| 318 | { |
---|
[4362] | 319 | |
---|
| 320 | // echo "aaaaaaaquoooooo"; |
---|
[3526] | 321 | if (!isset($this->_documents)) |
---|
| 322 | { |
---|
[4362] | 323 | $queryStr = "SELECT * FROM phpgw_mydms_documents WHERE folder = " . $this->_id . " ORDER BY id desc,sequence"; |
---|
| 324 | // echo "eeeeee".$queryStr; |
---|
[3526] | 325 | $resArr = $GLOBALS['mydms']->db->getResultArray($queryStr); |
---|
| 326 | if (is_bool($resArr) && !$resArr) |
---|
| 327 | return false; |
---|
| 328 | |
---|
| 329 | $this->_documents = array(); |
---|
| 330 | foreach ($resArr as $row) |
---|
| 331 | array_push($this->_documents, new Document($row["id"], $row["name"], $row["comment"], $row["date"], $row["expires"], $row["owner"], $row["folder"], $row["inheritaccess"], $row["defaultaccess"], $row["locked"], $row["keywords"], $row["sequence"])); |
---|
| 332 | } |
---|
| 333 | return $this->_documents; |
---|
| 334 | } |
---|
| 335 | |
---|
| 336 | function addDocument($name, $comment, $expires, $owner, $keywords, $tmpFile, $orgFileName, $fileType, $mimeType, $sequence) |
---|
| 337 | { |
---|
| 338 | $ownerid = $GLOBALS['phpgw_info']['user']['account_id']; |
---|
| 339 | |
---|
| 340 | $expires = (!$expires) ? 0 : $expires; |
---|
| 341 | |
---|
| 342 | |
---|
| 343 | $insertData = array( |
---|
| 344 | 'name' => $name, |
---|
| 345 | 'comment' => $comment, |
---|
| 346 | 'date' => mktime(), |
---|
| 347 | 'expires' => $expires, |
---|
| 348 | 'owner' => $ownerid, |
---|
| 349 | 'folder' => $this->_id, |
---|
| 350 | 'inheritAccess' => true, |
---|
| 351 | 'defaultAccess' => M_READ, |
---|
| 352 | 'locked' => -1, |
---|
| 353 | 'keywords' => $keywords, |
---|
| 354 | 'sequence' => $sequence, |
---|
| 355 | ); |
---|
[4362] | 356 | $res = $this->db->insert('phpgw_mydms_documents', $insertData, '', __LINE__, __FILE__, 'mydms'); |
---|
[3526] | 357 | |
---|
| 358 | if (!$res) |
---|
| 359 | return false; |
---|
| 360 | |
---|
| 361 | #unset($this->_subFolders); |
---|
| 362 | |
---|
| 363 | #return getFolder($this->db->get_last_insert_id('phpgw_mydms_Folders','id')); |
---|
| 364 | |
---|
| 365 | #$queryStr = "INSERT INTO phpgw_mydms_Documents (name, comment, date, expires, owner, folder, inheritAccess, defaultAccess, locked, keywords, sequence) VALUES ". |
---|
| 366 | # "('".$name."', '".$comment."', " . mktime().", ".$expires.", ".$ownerid.", ".$this->_id.", true, ".M_READ.", -1, '".$keywords."', " . $sequence . ")"; |
---|
| 367 | #if (!$GLOBALS['mydms']->db->getResult($queryStr)) |
---|
| 368 | # return false; |
---|
| 369 | |
---|
[4362] | 370 | $document = getDocument($this->db->get_last_insert_id('phpgw_mydms_documents','id')); |
---|
[3526] | 371 | |
---|
| 372 | $res = $document->addContent($comment, $owner, $tmpFile, $orgFileName, $fileType, $mimeType); |
---|
| 373 | if (is_bool($res) && !$res) |
---|
| 374 | { |
---|
[4362] | 375 | $queryStr = "DELETE FROM phpgw_mydms_documents WHERE id = " . $document->getID(); |
---|
[3526] | 376 | $GLOBALS['mydms']->db->getResult($queryStr); |
---|
| 377 | return false; |
---|
| 378 | } |
---|
| 379 | |
---|
| 380 | return $document; |
---|
| 381 | } |
---|
| 382 | |
---|
| 383 | function remove() |
---|
| 384 | { |
---|
| 385 | //Entfernen der Unterordner und Dateien |
---|
| 386 | $res = $this->getSubFolders(); |
---|
| 387 | if (is_bool($res) && !$res) return false; |
---|
| 388 | $res = $this->getDocuments(); |
---|
| 389 | if (is_bool($res) && !$res) return false; |
---|
| 390 | |
---|
| 391 | foreach ($this->_subFolders as $subFolder) |
---|
| 392 | { |
---|
| 393 | $res = $subFolder->remove(); |
---|
| 394 | if (!$res) return false; |
---|
| 395 | } |
---|
| 396 | |
---|
| 397 | foreach ($this->_documents as $document) |
---|
| 398 | { |
---|
| 399 | $res = $document->remove(); |
---|
| 400 | if (!$res) return false; |
---|
| 401 | } |
---|
| 402 | |
---|
| 403 | //Entfernen der Datenbankeintrï¿œge |
---|
[4362] | 404 | $queryStr = "DELETE FROM phpgw_mydms_folders WHERE id = " . $this->_id; |
---|
[3526] | 405 | if (!$GLOBALS['mydms']->db->getResult($queryStr)) |
---|
| 406 | return false; |
---|
[4362] | 407 | $queryStr = "DELETE FROM phpgw_mydms_acls WHERE target = ". $this->_id. " AND targettype = " . T_FOLDER; |
---|
[3526] | 408 | if (!$GLOBALS['mydms']->db->getResult($queryStr)) |
---|
| 409 | return false; |
---|
[4362] | 410 | $queryStr = "DELETE FROM phpgw_mydms_notify WHERE target = ". $this->_id. " AND targettype = " . T_FOLDER; |
---|
[3526] | 411 | if (!$GLOBALS['mydms']->db->getResult($queryStr)) |
---|
| 412 | return false; |
---|
| 413 | |
---|
| 414 | return true; |
---|
| 415 | } |
---|
| 416 | |
---|
| 417 | |
---|
| 418 | function getAccessList() |
---|
| 419 | { |
---|
| 420 | |
---|
| 421 | if ($this->inheritsAccess()) |
---|
| 422 | { |
---|
| 423 | $res = $this->getParent(); |
---|
| 424 | if (!$res) return false; |
---|
| 425 | return $this->_parent->getAccessList(); |
---|
| 426 | } |
---|
| 427 | |
---|
| 428 | if (!isset($this->_accessList)) |
---|
| 429 | { |
---|
[4362] | 430 | $queryStr = "SELECT * FROM phpgw_mydms_acls WHERE targettype = ".T_FOLDER." AND target = " . $this->_id . " ORDER BY targettype"; |
---|
| 431 | //echo "aqui".$queryStr ; |
---|
[3526] | 432 | $resArr = $GLOBALS['mydms']->db->getResultArray($queryStr); |
---|
| 433 | |
---|
| 434 | |
---|
| 435 | if (is_bool($resArr) && !$resArr) |
---|
| 436 | return false; |
---|
| 437 | |
---|
| 438 | $this->_accessList = array("groups" => array(), "users" => array()); |
---|
| 439 | foreach ($resArr as $row) |
---|
| 440 | { |
---|
[4362] | 441 | //echo "el grupo de acceso es".$row[4]." ".$row["groupid"]."<br>"; |
---|
| 442 | |
---|
[3526] | 443 | if ($row["userid"] != -1) |
---|
| 444 | array_push($this->_accessList["users"], new UserAccess($row["userid"], $row["mode"])); |
---|
| 445 | else //if ($row["groupID"] != -1) |
---|
| 446 | array_push($this->_accessList["groups"], new GroupAccess($row["groupid"], $row["mode"])); |
---|
| 447 | } |
---|
| 448 | } |
---|
| 449 | |
---|
| 450 | return $this->_accessList; |
---|
| 451 | } |
---|
[4362] | 452 | |
---|
| 453 | |
---|
| 454 | |
---|
| 455 | function getAccessList2() |
---|
| 456 | { |
---|
| 457 | |
---|
| 458 | $grupos=read_repository2($GLOBALS['phpgw_info']['user']['account_id']); |
---|
| 459 | // echo "".$GLOBALS['phpgw_info']['user']['account_id']; |
---|
[3526] | 460 | |
---|
[4362] | 461 | if($grupos!=''){ |
---|
| 462 | $queryStr = "SELECT * FROM phpgw_mydms_acls WHERE targettype = ".T_FOLDER." AND target = " . $this->_id . " and (userid=".$GLOBALS['phpgw_info']['user']['account_id']." or groupid in (".$grupos.")) ORDER BY targettype"; |
---|
| 463 | }else{ |
---|
| 464 | $queryStr = "SELECT * FROM phpgw_mydms_acls WHERE targettype = ".T_FOLDER." AND target = " . $this->_id . " and (userid=".$GLOBALS['phpgw_info']['user']['account_id']." ) ORDER BY targettype"; |
---|
| 465 | |
---|
| 466 | } |
---|
| 467 | //echo "<br>aqui".$queryStr ; |
---|
| 468 | $resArr = $GLOBALS['mydms']->db->getResultArray($queryStr); |
---|
| 469 | |
---|
| 470 | |
---|
| 471 | if (is_bool($resArr) && !$resArr) |
---|
| 472 | return false; |
---|
| 473 | |
---|
| 474 | //$this->_accessList = array("groups" => array(), "users" => array()); |
---|
| 475 | foreach ($resArr as $row) |
---|
| 476 | { |
---|
| 477 | //echo "acceso".$row["mode"]; |
---|
| 478 | //echo "el grupo de acceso es".$row[4]." ".$row["groupid"]."<br>"; |
---|
| 479 | return $row["mode"]; |
---|
| 480 | /*if ($row["userid"] != -1) |
---|
| 481 | array_push($this->_accessList["users"], new UserAccess($row["userid"], $row["mode"])); |
---|
| 482 | else //if ($row["groupID"] != -1) |
---|
| 483 | array_push($this->_accessList["groups"], new GroupAccess($row["groupid"], $row["mode"]));*/ |
---|
| 484 | } |
---|
| 485 | |
---|
| 486 | return false; |
---|
| 487 | } |
---|
| 488 | |
---|
[3526] | 489 | function clearAccessList() |
---|
| 490 | { |
---|
[4362] | 491 | $queryStr = "DELETE FROM phpgw_mydms_acls WHERE targettype = " . T_FOLDER . " AND target = " . $this->_id; |
---|
[3526] | 492 | if (!$GLOBALS['mydms']->db->getResult($queryStr)) |
---|
| 493 | return false; |
---|
| 494 | |
---|
| 495 | unset($this->_accessList); |
---|
| 496 | return true; |
---|
| 497 | } |
---|
| 498 | |
---|
| 499 | function addAccess($mode, $userOrGroupID, $isUser) |
---|
| 500 | { |
---|
| 501 | $userOrGroup = ($isUser) ? "userid" : "groupid"; |
---|
| 502 | |
---|
[4362] | 503 | $queryStr = "INSERT INTO phpgw_mydms_acls (target, targettype, ".$userOrGroup.", mode) VALUES |
---|
[3526] | 504 | (".$this->_id.", ".T_FOLDER.", " . $userOrGroupID . ", " .$mode. ")"; |
---|
| 505 | if (!$GLOBALS['mydms']->db->getResult($queryStr)) |
---|
| 506 | return false; |
---|
| 507 | |
---|
| 508 | unset($this->_accessList); |
---|
| 509 | return true; |
---|
| 510 | } |
---|
| 511 | |
---|
| 512 | function changeAccess($newMode, $userOrGroupID, $isUser) |
---|
| 513 | { |
---|
| 514 | $userOrGroup = ($isUser) ? "userID" : "groupID"; |
---|
| 515 | |
---|
[4362] | 516 | $queryStr = "UPDATE phpgw_mydms_acls SET mode = " . $newMode . " WHERE targettype = ".T_FOLDER." AND target = " . $this->_id . " AND " . $userOrGroup . " = " . $userOrGroupID; |
---|
[3526] | 517 | if (!$GLOBALS['mydms']->db->getResult($queryStr)) |
---|
| 518 | return false; |
---|
| 519 | |
---|
| 520 | unset($this->_accessList); |
---|
| 521 | return true; |
---|
| 522 | } |
---|
| 523 | |
---|
| 524 | function removeAccess($userOrGroupID, $isUser) |
---|
| 525 | { |
---|
| 526 | $userOrGroup = ($isUser) ? "userID" : "groupID"; |
---|
| 527 | |
---|
[4362] | 528 | $queryStr = "DELETE FROM phpgw_mydms_acls WHERE targettype = ".T_FOLDER." AND target = ".$this->_id." AND ".$userOrGroup." = " . $userOrGroupID; |
---|
[3526] | 529 | if (!$GLOBALS['mydms']->db->getResult($queryStr)) |
---|
| 530 | return false; |
---|
| 531 | |
---|
| 532 | unset($this->_accessList); |
---|
| 533 | return true; |
---|
| 534 | } |
---|
| 535 | |
---|
| 536 | /* |
---|
| 537 | * Liefert die Art der Zugriffsberechtigung fï¿œr den User $user; Mï¿œgliche Rechte: n (keine), r (lesen), w (schreiben+lesen), a (alles) |
---|
| 538 | * Zunï¿œchst wird Geprï¿œft, ob die Berechtigung geerbt werden soll; in diesem Fall wird die Anfrage an den Eltern-Ordner weitergeleitet. |
---|
| 539 | * Ansonsten werden die ACLs durchgegangen: Die hï¿œchstwertige Berechtigung gilt. |
---|
| 540 | * Wird bei den ACLs nicht gefunden, wird die Standard-Berechtigung zurï¿œckgegeben. |
---|
| 541 | * Ach ja: handelt es sich bei $user um den Besitzer ist die Berechtigung automatisch "a". |
---|
| 542 | */ |
---|
| 543 | function getAccessMode($user) |
---|
| 544 | { |
---|
[4362] | 545 | |
---|
[3526] | 546 | GLOBAL $settings; |
---|
| 547 | |
---|
| 548 | |
---|
| 549 | //Admin?? |
---|
| 550 | if ($user->isAdmin()) |
---|
| 551 | return M_ALL; |
---|
| 552 | |
---|
| 553 | //Besitzer ?? |
---|
| 554 | if ($user->getID() == $this->_ownerID) |
---|
| 555 | return M_ALL; |
---|
| 556 | |
---|
| 557 | //Gast-Benutzer?? |
---|
| 558 | if (($user->getID() == $settings->_guestID) && ($settings->_enableGuestLogin)) |
---|
| 559 | { |
---|
| 560 | $mode = $this->getDefaultAccess(); |
---|
| 561 | if ($mode >= M_READ) |
---|
| 562 | return M_READ; |
---|
| 563 | else |
---|
| 564 | return M_NONE; |
---|
| 565 | } |
---|
| 566 | |
---|
| 567 | //Berechtigung erben?? |
---|
| 568 | // wird ï¿œber GetAccessList() bereits realisiert. |
---|
| 569 | // durch das Verwenden der folgenden Zeilen wï¿œren auch Owner-Rechte vererbt worden. |
---|
| 570 | /* |
---|
| 571 | if ($this->inheritsAccess()) |
---|
| 572 | { |
---|
| 573 | if (isset($this->_parentID)) |
---|
| 574 | { |
---|
| 575 | if (!$this->getParent()) |
---|
| 576 | return false; |
---|
| 577 | return $this->_parent->getAccessMode($user); |
---|
| 578 | } |
---|
| 579 | } |
---|
| 580 | */ |
---|
| 581 | |
---|
| 582 | $highestPrivileged = M_NONE; |
---|
| 583 | |
---|
| 584 | //ACLs durchforsten |
---|
| 585 | $foundInACL = false; |
---|
[4362] | 586 | |
---|
| 587 | return $this->getAccessList2(); |
---|
| 588 | /*$accessList = $this->getAccessList(); |
---|
[3526] | 589 | if (!$accessList) { |
---|
| 590 | return false; |
---|
| 591 | } |
---|
| 592 | |
---|
| 593 | foreach ($accessList["users"] as $userAccess) |
---|
| 594 | { |
---|
| 595 | |
---|
| 596 | |
---|
| 597 | if ($userAccess->getUserID() == $user->getID()) |
---|
| 598 | { |
---|
| 599 | $foundInACL = true; |
---|
| 600 | if ($userAccess->getMode() > $highestPrivileged) |
---|
| 601 | $highestPrivileged = $userAccess->getMode(); |
---|
| 602 | if ($highestPrivileged == M_ALL) //hï¿œher geht's nicht -> wir kï¿œnnen uns die arbeit schenken |
---|
| 603 | return $highestPrivileged; |
---|
| 604 | } |
---|
| 605 | } |
---|
| 606 | foreach ($accessList["groups"] as $groupAccess) |
---|
| 607 | { |
---|
[4362] | 608 | |
---|
[3526] | 609 | if ($user->isMemberOfGroup($groupAccess->getGroup())) |
---|
| 610 | { |
---|
[4362] | 611 | |
---|
| 612 | // echo "entro grupoooo<br>";//.$groupAccess->getGroup()." <br>"; |
---|
| 613 | |
---|
[3526] | 614 | $foundInACL = true; |
---|
| 615 | if ($groupAccess->getMode() > $highestPrivileged) |
---|
| 616 | $highestPrivileged = $groupAccess->getMode(); |
---|
| 617 | if ($highestPrivileged == M_ALL) //hï¿œher geht's nicht -> wir kï¿œnnen uns die arbeit schenken |
---|
| 618 | return $highestPrivileged; |
---|
| 619 | } |
---|
| 620 | } |
---|
| 621 | if ($foundInACL) |
---|
[4362] | 622 | return $highestPrivileged;*/ |
---|
[3526] | 623 | |
---|
| 624 | //Standard-Berechtigung verwenden |
---|
[4362] | 625 | //return $this->getDefaultAccess(); |
---|
[3526] | 626 | } |
---|
| 627 | |
---|
| 628 | function getNotifyList() |
---|
| 629 | { |
---|
| 630 | if (!isset($this->_notifyList)) |
---|
| 631 | { |
---|
[4362] | 632 | $queryStr ="SELECT * FROM phpgw_mydms_notify WHERE targettype = " . T_FOLDER . " AND target = " . $this->_id; |
---|
[3526] | 633 | $resArr = $GLOBALS['mydms']->db->getResultArray($queryStr); |
---|
| 634 | if (is_bool($resArr) && $resArr == false) |
---|
| 635 | return false; |
---|
| 636 | |
---|
| 637 | $this->_notifyList = array("groups" => array(), "users" => array()); |
---|
| 638 | foreach ($resArr as $row) |
---|
| 639 | { |
---|
| 640 | if ($row["userid"] != -1) |
---|
| 641 | array_push($this->_notifyList["users"], getUser($row["userid"]) ); |
---|
| 642 | else //if ($row["groupID"] != -1) |
---|
| 643 | array_push($this->_notifyList["groups"], getGroup($row["groupid"]) ); |
---|
| 644 | } |
---|
| 645 | } |
---|
| 646 | return $this->_notifyList; |
---|
| 647 | } |
---|
| 648 | |
---|
| 649 | function addNotify($userOrGroupID, $isUser) |
---|
| 650 | { |
---|
| 651 | $userOrGroup = ($isUser) ? "userID" : "groupID"; |
---|
| 652 | |
---|
[4362] | 653 | $queryStr = "INSERT INTO phpgw_mydms_notify (target, targettype, " . $userOrGroup . ") VALUES (" . $this->_id . ", " . T_FOLDER . ", " . $userOrGroupID . ")"; |
---|
[3526] | 654 | if (!$GLOBALS['mydms']->db->getResult($queryStr)) |
---|
| 655 | return false; |
---|
| 656 | |
---|
| 657 | unset($this->_notifyList); |
---|
| 658 | return true; |
---|
| 659 | } |
---|
| 660 | |
---|
| 661 | function removeNotify($userOrGroupID, $isUser) |
---|
| 662 | { |
---|
| 663 | $userOrGroup = ($isUser) ? "userID" : "groupID"; |
---|
| 664 | |
---|
[4362] | 665 | $queryStr = "DELETE FROM phpgw_mydms_notify WHERE target = " . $this->_id . " AND targettype = " . T_FOLDER . " AND " . $userOrGroup . " = " . $userOrGroupID; |
---|
[3526] | 666 | if (!$GLOBALS['mydms']->db->getResult($queryStr)) |
---|
| 667 | return false; |
---|
| 668 | |
---|
| 669 | unset($this->_notifyList); |
---|
| 670 | return true; |
---|
| 671 | } |
---|
| 672 | } |
---|
| 673 | |
---|
| 674 | ?> |
---|