ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjFileBasedLMAccess.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 include_once("classes/class.ilObjectAccess.php");
25 
36 {
49  function _checkAccess($a_cmd, $a_permission, $a_ref_id, $a_obj_id, $a_user_id = "")
50  {
51  global $ilUser, $lng, $rbacsystem, $ilAccess;
52 
53  if ($a_user_id == "")
54  {
55  $a_user_id = $ilUser->getId();
56  }
57 
58  switch ($a_cmd)
59  {
60  case "view":
61 
63  && !$rbacsystem->checkAccessOfUser($a_user_id,'write',$a_ref_id)) ||
65  {
66  $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("offline"));
67  return false;
68  }
69  break;
70  }
71 
72  switch ($a_permission)
73  {
74  case "visible":
75  if (!ilObjFileBasedLMAccess::_lookupOnline($a_obj_id) &&
76  (!$rbacsystem->checkAccessOfUser($a_user_id,'write', $a_ref_id)))
77  {
78  $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("offline"));
79  return false;
80  }
81  break;
82  }
83 
84 
85  return true;
86  }
87 
100  function _getCommands()
101  {
102  $commands = array
103  (
104  array("permission" => "read", "cmd" => "view", "lang_var" => "show",
105  "default" => true),
106  array("permission" => "write", "cmd" => "edit", "lang_var" => "edit"),
107  );
108 
109  return $commands;
110  }
111 
112  //
113  // access relevant methods
114  //
115 
119  function _lookupOnline($a_id)
120  {
121  global $ilDB;
122 
123  $q = "SELECT * FROM file_based_lm WHERE id = ".$ilDB->quote($a_id);
124  $set = $ilDB->query($q);
125  $rec = $set->fetchRow(DB_FETCHMODE_ASSOC);
126 
127  return ilUtil::yn2tf($rec["online"]);
128  }
129 
133  function _determineStartUrl($a_id)
134  {
135  global $ilDB;
136 
137  $q = "SELECT * FROM file_based_lm WHERE id = ".$ilDB->quote($a_id);
138  $set = $ilDB->query($q);
139  $rec = $set->fetchRow(DB_FETCHMODE_ASSOC);
140  $start_file = $rec["startfile"];
141  $dir = ilUtil::getWebspaceDir()."/lm_data/lm_".$a_id;
142 
143  if (($start_file != "") &&
144  (@is_file($dir."/".$start_file)))
145  {
146  return "./".$dir."/".$start_file;
147  }
148  else if (@is_file($dir."/index.html"))
149  {
150  return "./".$dir."/index.html";
151  }
152  else if (@is_file($dir."/index.htm"))
153  {
154  return "./".$dir."/index.htm";
155  }
156 
157  return "";
158  }
159 
163  function _checkGoto($a_target)
164  {
165  global $ilAccess;
166 
167  $t_arr = explode("_", $a_target);
168 
169  if ($t_arr[0] != "htlm" || ((int) $t_arr[1]) <= 0)
170  {
171  return false;
172  }
173 
174  if ($ilAccess->checkAccess("visible", "", $t_arr[1]))
175  {
176  return true;
177  }
178  return false;
179  }
180 
181  //BEGIN DiskQuota: Get used disk space
187  function _getDiskSpaceUsed($a_id)
188  {
189  $lm_data_dir = ilUtil::getWebspaceDir('filesystem')."/lm_data";
190  $lm_dir = $lm_data_dir.DIRECTORY_SEPARATOR."lm_".$a_id;
191 
192  return file_exists($lm_dir) ? ilUtil::dirsize($lm_dir) : 0;
193 
194  }
200  function _getDiskSpaceUsedBy($user_id, $as_string = false)
201  {
202  // XXXX - This method is extremely slow. We should
203  // use a cache to speed it up, for example, we should
204  // store the disk space used in table file_data.
205  global $ilDB, $lng;
206 
207 
208  $q = "SELECT obj_id ".
209  "FROM object_data ".
210  "WHERE type = 'htlm' ".
211  "AND owner = ".$ilDB->quote($user_id);
212  $us_set = $ilDB->query($q);
213  $size = 0;
214  $count = 0;
215  while($us_rec = $us_set->fetchRow(DB_FETCHMODE_ASSOC))
216  {
217  $size += ilObjFileBasedLMAccess::_getDiskSpaceUsed($us_rec["obj_id"]);
218  $count++;
219  }
220  include_once("Modules/File/classes/class.ilObjFileAccess.php");
221  return ($as_string) ?
222  $count.' '.$lng->txt('htlm').', '.ilObjFileAccess::_sizeToString($size) :
223  $size;
224  }
225  //END DiskQuota: Get used disk space
226 
227 }
228 
229 ?>