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