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