[ Index ]
 

Code source de eGroupWare 1.2.106-2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/mydms/inc/ -> inc.ClassFolder.php (source)

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


Généré le : Sun Feb 25 17:20:01 2007 par Balluche grâce à PHPXref 0.7