ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
imagemanager.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 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 
25 foreach($_GET as $k => $v)
26 {
27  $_GET[$k] = str_replace(array("\x00", "\n", "\r", "\\", "'", '"', "\x1a"), "", $v);
28  $_GET[$k] = strip_tags($_GET[$k]);
29 }
30 
31 include_once "config.php";
32 
33 $_GET["client_id"] = str_replace("..", "", $_GET["client_id"]);
34 
35 $dir = getcwd();
36 chdir("../../../../../");
37 include_once "webservice/soap/include/inc.soap_functions.php";
38 $mobs = ilSoapFunctions::getMobsOfObject($_GET["session_id"]."::".$_GET["client_id"], $_GET["obj_type"].":html", $_GET["obj_id"]);
39 chdir($dir);
40 $preview = "";
42 $request_uri = urldecode(empty($_POST['request_uri'])?(empty($_GET['request_uri'])?'':$_GET['request_uri']):$_POST['request_uri']);
44 
45 
46 $img = isset($_POST['imglist'])?$_POST['imglist']:'';
48 $errors = array();
49 
50 // upload images
51 if (isset($_FILES['img_file']['size']) && $_FILES['img_file']['size']>0)
52 {
53  $dir = getcwd();
54  chdir("../../../../../");
55  include_once "webservice/soap/include/inc.soap_functions.php";
56  $safefilename = preg_replace("/[^a-zA-z0-9_\.]/", "", $_FILES["img_file"]["name"]);
57  $media_object = ilSoapFunctions::saveTempFileAsMediaObject($_GET["session_id"]."::".$_GET["client_id"], $safefilename, $_FILES["img_file"]["tmp_name"]);
58  if (file_exists($iliasAbsolutePath.$iliasMobPath."mm_".$media_object->getId() . "/" . $media_object->getTitle()))
59  {
60  // only save usage if the file was uploaded
61  $media_object->_saveUsage($media_object->getId(), $_GET["obj_type"].":html", $_GET["obj_id"]);
62  }
63  chdir($dir);
64  $preview = $iliasHttpPath.$iliasMobPath."mm_".$media_object->getId() . "/" . $media_object->getTitle();
65  $mobs[$media_object->getId()] = $media_object->getId();
66 }
67 
68 //require_once "HTML/Template/ITX.php";
70 $tpl->loadTemplatefile("tpl.imagemanager.html", TRUE, TRUE);
71 
72 // delete image
73 if ($tinyMCE_img_delete_allowed && isset($_POST['lib_action'])
74  && ($_POST['lib_action']=='delete') && !empty($img))
75 {
76  deleteImg();
77 }
78 
80 {
81  $tpl->touchBlock("delete_allowed");
82 }
83 outMobImages();
84 outMobImageParams();
85 $tpl->setVariable("REQUEST_URI", $_GET["request_uri"]);
86 $tpl->setVariable("VALUE_REQUEST_URI", $request_uri);
87 $tpl->setVariable("OBJ_ID", $_GET["obj_id"]);
88 $tpl->setVariable("OBJ_TYPE", $_GET["obj_type"]);
89 $tpl->setVariable("SESSION_ID", $_GET["session_id"]);
90 $tpl->setVariable("CLIENT_ID", $_GET["client_id"]);
91 $tpl->setVariable("VALUE_UPDATE", $_GET["update"]);
92 $tpl->setVariable("ILIAS_INST_PATH", $iliasHttpPath);
93 if ($_GET["update"] == 1)
94 {
95  $tpl->setVariable("INSERT_COMMAND", "{#update}");
96 }
97 else
98 {
99  $tpl->setVariable("INSERT_COMMAND", "{#insert}");
100 }
101 $tpl->setVariable("URL_PREVIEW", $preview);
102 $error_messages = "";
103 if (!empty($errors))
104 {
105  $error_messages .= '<span class="error">';
106  foreach ($errors as $err)
107  {
108  $error_messages .= $err . "<br />";
109  }
110  $error_messages .= "</span>";
111 }
112 $tpl->setVariable("ERROR_MESSAGES", $error_messages);
113 $tpl->show();
114 
115  function outMobImages()
116  {
117  global $mobs;
118  global $iliasMobPath;
119  global $iliasAbsolutePath;
120  global $iliasHttpPath;
121  global $tinyMCE_valid_imgs;
122  global $tpl;
123  global $errors;
124  global $img;
126 
127  $i = 0;
128  // read image directory
129  foreach ($mobs as $mob)
130  {
131  $mobdir = $iliasAbsolutePath.$iliasMobPath."mm_".$mob . "/";
132  $d = @dir($mobdir);
133  if ($d)
134  {
135  while (FALSE !== ($entry = $d->read()))
136  {
137  $ext = strtolower(substr(strrchr($entry,'.'), 1));
138  if (is_file($mobdir.$entry) && in_array($ext, $tinyMCE_valid_imgs))
139  {
140  $arr_tinyMCE_image_files[$i]["file_name"] = $entry;
141  $arr_tinyMCE_image_files[$i]["file_dir"] = $mobdir;
142  $arr_tinyMCE_image_files[$i]["http_dir"] = $iliasHttpPath.$iliasMobPath."mm_".$mob . "/";
143  $i++;
144  }
145  }
146  $d->close();
147  }
148  else
149  {
150  $errors[] = '{#ibrowser.errornodir}';
151  }
152  }
153  // sort the list of image filenames alphabetically.
154  sort($arr_tinyMCE_image_files);
155 
156  for ($k=0; $k<count($arr_tinyMCE_image_files); $k++)
157  {
158  $entry = $arr_tinyMCE_image_files[$k]["file_name"];
159  $size = getimagesize($arr_tinyMCE_image_files[$k]["file_dir"].$entry);
160  $fsize = filesize($arr_tinyMCE_image_files[$k]["file_dir"].$entry);
161  $tpl->setCurrentBlock("imagefile");
162  $tpl->setVariable("IMAGEFILE_VALUE", $arr_tinyMCE_image_files[$k]["http_dir"]);
163  $tpl->setVariable("IMAGEFILE_TEXT", $entry);
164  if ($entry == $img)
165  {
166  $tpl->setVariable("IMAGEFILE_SELECTED", " selected=\"selected\"");
167  }
168  $tpl->parseCurrentBlock();
169  }
170  }
171 
172  function outMobImageParams()
173  {
175  global $tpl;
176  for ($k=0; $k<count($arr_tinyMCE_image_files); $k++)
177  {
178  $tpl->setCurrentBlock("imageparams");
179  $entry = $arr_tinyMCE_image_files[$k]["file_name"];
180  $size = getimagesize($arr_tinyMCE_image_files[$k]["file_dir"].$entry);
181  $fsize = filesize($arr_tinyMCE_image_files[$k]["file_dir"].$entry);
182  $tpl->setVariable("IMG_WIDTH", $size[0]);
183  $tpl->setVariable("IMG_HEIGHT", $size[1]);
184  $tpl->setVariable("IMG_PATH", $arr_tinyMCE_image_files[$k]["http_dir"]);
185  $tpl->setVariable("F_SIZE", filesize_h($fsize,2));
186  $tpl->parseCurrentBlock();
187  }
188  }
189 
190  function deleteImg()
191  {
192  }
193 
194 // Return the human readable size of a file
195 // @param int $size a file size
196 // @param int $dec a number of decimal places
197 
198 function filesize_h($size, $dec = 1)
199 {
200  $sizes = array('byte(s)', 'kb', 'mb', 'gb');
201  $count = count($sizes);
202  $i = 0;
203 
204  while ($size >= 1024 && ($i < $count - 1)) {
205  $size /= 1024;
206  $i++;
207  }
208 
209  return round($size, $dec) . ' ' . $sizes[$i];
210 }
211 
212 function liboptions($arr, $prefix = '', $sel = '')
213 {
214  $buf = '';
215  foreach($arr as $lib) {
216  $buf .= '<option value="'.$lib['value'].'"'.(($lib['value'] == $sel)?' selected':'').'>'.$prefix.$lib['text'].'</option>'."\n";
217  }
218  return $buf;
219 }
220 
221 ?>