XOOPS 2.5.6  Final
 All Classes Namespaces Files Functions Variables Pages
xoopsimagebrowser.php
Go to the documentation of this file.
1 <?php
16 // load mainfile.php
17 $current_path = dirname(__FILE__);
18 if ( DIRECTORY_SEPARATOR != "/" ) {
19  $current_path = str_replace( DIRECTORY_SEPARATOR, "/", $current_path);
20 }
21 $xoops_root_path = substr($current_path, 0, strpos(strtolower($current_path), "/class/xoopseditor/tinymce/"));
22 include_once $xoops_root_path . "/mainfile.php";
23 if (!defined("XOOPS_ROOT_PATH")) exit();
24 
28 $op = "list"; // default
29 if (isset($_POST)) {
30  foreach ( $_POST as $k => $v ) {
31  ${$k} = $v;
32  }
33 }
34 
35 // get current filename
36 $current_file = basename(__FILE__);
37 
38 // load language definitions
39 xoops_loadLanguage("admin", "system");
40 xoops_loadLanguage("/admin/images", "system");
41 
42 
43 // include
44 xoops_load( "xoopsformloader" );
45 xoops_load( "xoopsmodule" );
46 include_once XOOPS_ROOT_PATH . "/include/cp_functions.php";
47 include_once XOOPS_ROOT_PATH."/modules/system/constants.php";
48 
49 global $xoopsConfig;
50 
51 // check user/group - start
52 $isadmin = false;
53 
55 $groups = is_object( $GLOBALS["xoopsUser"] ) ? $GLOBALS["xoopsUser"]->getGroups() : array( XOOPS_GROUP_ANONYMOUS );
56 $isadmin = $gperm_handler->checkRight( 'system_admin', XOOPS_SYSTEM_IMAGE, $groups );
57 
58 // check categories readability/writability
59 $imgcat_handler =& xoops_gethandler('imagecategory');
60 $catreadlist =& $imgcat_handler->getList($groups, 'imgcat_read', 1); // get readable categories
61 $catwritelist =& $imgcat_handler->getList($groups, 'imgcat_write', 1); // get writable categories
62 
63 $catreadcount = count($catreadlist); // count readable categories
64 $catwritecount = count($catwritelist); // count writable categories
65 
66 
67 // check/set parameters - start
68 if (!isset($_REQUEST["target"])) {
69  exit();
70 } else {
71  $target = $_REQUEST["target"];
72 }
73 
74 if (isset($_GET["op"])) {
75  $op = trim($_GET["op"]);
76 }
77 
78 if (isset($_GET["target"])) {
79  $target = trim($_GET["target"]);
80 }
81 
82 if (isset($_GET["image_id"])) {
83  $image_id = intval($_GET["image_id"]);
84 }
85 
86 if (isset($_GET["imgcat_id"])) {
87  $imgcat_id = intval($_GET["imgcat_id"]);
88 }
89 
90 if(isset($imgcat_id)) {
91  $imgcat_id = intval($imgcat_id);
92 }
93 $target = htmlspecialchars($target);
94 
95 
96 if ( ($isadmin) || ($catreadcount > 0) || ($catwritecount > 0) ) {
97 
98 
99  // Save Image modification - start
100  if ( !empty($_POST["op"]) && $op == "save" ) {
101  if (!$GLOBALS["xoopsSecurity"]->check()) {
102  redirect_header($current_file . "?target=" . $target, 3, implode("<br />", $GLOBALS["xoopsSecurity"]->getErrors()));
103  }
104  $count = count($image_id);
105  if ($count > 0) {
106  $image_handler =& xoops_gethandler("image");
107  $error = array();
108  for ($i = 0; $i < $count; $i++) {
109  $image =& $image_handler->get($image_id[$i]);
110  if (!is_object($image)) {
111  $error[] = sprintf(_FAILGETIMG, $image_id[$i]);
112  continue;
113  }
114  $image_display[$i] = empty($image_display[$i]) ? 0 : 1;
115  $image->setVar("image_display", $image_display[$i]);
116  $image->setVar("image_weight", $image_weight[$i]);
117  $image->setVar("image_nicename", $image_nicename[$i]);
118  $image->setVar("imgcat_id", $imgcat_id[$i]);
119  if (!$image_handler->insert($image)) {
120  $error[] = sprintf(_FAILSAVEIMG, $image_id[$i]);
121  }
122  }
123  if (count($error) > 0) {
124  redirect_header($current_file . "?target=" . $target, 3, xoops_error(implode("<br />", $error) ) );
125  }
126  }
127  redirect_header($current_file . "?target=" . $target, 3, _MD_AM_DBUPDATED);
128  }
129  // Save Image modification - end
130 
131  // Add new image - start
132  if ( !empty($_POST["op"]) && $op == "addfile" ) {
133  if (!$GLOBALS["xoopsSecurity"]->check()) {
134  redirect_header($current_file . "?target=" . $target, 3, implode("<br />", $GLOBALS["xoopsSecurity"]->getErrors()));
135  }
136  $imgcat =& $imgcat_handler->get(intval($imgcat_id));
137  if (!is_object($imgcat)) {
138  redirect_header($current_file . "?target=" . $target, 3);
139  }
140  include_once XOOPS_ROOT_PATH."/class/uploader.php";
141 
142  $uploader = new XoopsMediaUploader(XOOPS_UPLOAD_PATH, array("image/gif", "image/jpeg", "image/pjpeg", "image/x-png", "image/png", "image/bmp"), $imgcat->getVar("imgcat_maxsize"), $imgcat->getVar("imgcat_maxwidth"), $imgcat->getVar("imgcat_maxheight"));
143  $uploader->setPrefix("img");
144  $err = array();
145  $ucount = count($_POST["xoops_upload_file"]);
146  for ($i = 0; $i < $ucount; $i++) {
147  if ($uploader->fetchMedia($_POST["xoops_upload_file"][$i])) {
148  if (!$uploader->upload()) {
149  $err[] = $uploader->getErrors();
150  } else {
151  $image_handler =& xoops_gethandler("image");
152  $image =& $image_handler->create();
153  $image->setVar("image_name", $uploader->getSavedFileName());
154  $image->setVar("image_nicename", $image_nicename);
155  $image->setVar("image_mimetype", $uploader->getMediaType());
156  $image->setVar("image_created", time());
157  $image_display = empty($image_display) ? 0 : 1;
158  $image->setVar("image_display", $image_display);
159  $image->setVar("image_weight", $image_weight);
160  $image->setVar("imgcat_id", $imgcat_id);
161  if ($imgcat->getVar("imgcat_storetype") == "db") {
162  $fp = @fopen($uploader->getSavedDestination(), "rb");
163  $fbinary = @fread($fp, filesize($uploader->getSavedDestination()));
164  @fclose($fp);
165  $image->setVar("image_body", $fbinary, true);
166  @unlink($uploader->getSavedDestination());
167  }
168  if (!$image_handler->insert($image)) {
169  $err[] = sprintf(_FAILSAVEIMG, $image->getVar("image_nicename"));
170  }
171  }
172  } else {
173  $err[] = sprintf(_FAILFETCHIMG, $i);
174  $err = array_merge($err, $uploader->getErrors(false));
175  }
176  }
177  if (count($err) > 0) {
178  redirect_header($current_file . "?target=" . $target, 3, xoops_error(implode("<br />", $err) ) );
179  }
180  redirect_header($current_file . "?target=" . $target, 3, _MD_AM_DBUPDATED);
181  }
182  // Add new image - end
183 
184  // Add new catégorie - start
185  if ( !empty($_POST["op"]) && $op == "addcat" ) {
186  if (!$GLOBALS["xoopsSecurity"]->check()) {
187  redirect_header($current_file . "?target=" . $target, 3, implode("<br />", $GLOBALS["xoopsSecurity"]->getErrors()));
188  }
189  $imgcat_handler =& xoops_gethandler("imagecategory");
190  $imagecategory =& $imgcat_handler->create();
191  $imagecategory->setVar("imgcat_name", $imgcat_name);
192  $imagecategory->setVar("imgcat_maxsize", $imgcat_maxsize);
193  $imagecategory->setVar("imgcat_maxwidth", $imgcat_maxwidth);
194  $imagecategory->setVar("imgcat_maxheight", $imgcat_maxheight);
195  $imgcat_display = empty($imgcat_display) ? 0 : 1;
196  $imagecategory->setVar("imgcat_display", $imgcat_display);
197  $imagecategory->setVar("imgcat_weight", $imgcat_weight);
198  $imagecategory->setVar("imgcat_storetype", $imgcat_storetype);
199  $imagecategory->setVar("imgcat_type", "C");
200  if (!$imgcat_handler->insert($imagecategory)) {
201  redirect_header($current_file . "?target=" . $target, 3);
202  }
203  $newid = $imagecategory->getVar("imgcat_id");
204  $imagecategoryperm_handler =& xoops_gethandler("groupperm");
205  if (!isset($readgroup)) {
206  $readgroup = array();
207  }
208  if (!in_array(XOOPS_GROUP_ADMIN, $readgroup)) {
209  array_push($readgroup, XOOPS_GROUP_ADMIN);
210  }
211  foreach ($readgroup as $rgroup) {
212  $imagecategoryperm =& $imagecategoryperm_handler->create();
213  $imagecategoryperm->setVar("gperm_groupid", $rgroup);
214  $imagecategoryperm->setVar("gperm_itemid", $newid);
215  $imagecategoryperm->setVar("gperm_name", 'imgcat_read');
216  $imagecategoryperm->setVar("gperm_modid", 1);
217  $imagecategoryperm_handler->insert($imagecategoryperm);
218  unset($imagecategoryperm);
219  }
220  if (!isset($writegroup)) {
221  $writegroup = array();
222  }
223  if (!in_array(XOOPS_GROUP_ADMIN, $writegroup)) {
224  array_push($writegroup, XOOPS_GROUP_ADMIN);
225  }
226  foreach ($writegroup as $wgroup) {
227  $imagecategoryperm =& $imagecategoryperm_handler->create();
228  $imagecategoryperm->setVar("gperm_groupid", $wgroup);
229  $imagecategoryperm->setVar("gperm_itemid", $newid);
230  $imagecategoryperm->setVar("gperm_name", 'imgcat_write');
231  $imagecategoryperm->setVar("gperm_modid", 1);
232  $imagecategoryperm_handler->insert($imagecategoryperm);
233  unset($imagecategoryperm);
234  }
235  redirect_header($current_file . "?target=" . $target, 3,_MD_AM_DBUPDATED);
236  }
237  // Add new catégorie - end
238 
239  // Update categorie - start
240  if ( !empty($_POST["op"]) && $op == "updatecat" ) {
241  if (!$GLOBALS["xoopsSecurity"]->check() || $imgcat_id <= 0) {
242  redirect_header($current_file . "?target=" . $target, 3, implode("<br />", $GLOBALS["xoopsSecurity"]->getErrors()));
243  }
244  $imgcat_handler = xoops_gethandler("imagecategory");
245  $imagecategory =& $imgcat_handler->get($imgcat_id);
246  if (!is_object($imagecategory)) {
247  redirect_header($current_file . "?target=" . $target, 3);
248  }
249  $imagecategory->setVar("imgcat_name", $imgcat_name);
250  $imgcat_display = empty($imgcat_display) ? 0 : 1;
251  $imagecategory->setVar("imgcat_display", $imgcat_display);
252  $imagecategory->setVar("imgcat_maxsize", $imgcat_maxsize);
253  $imagecategory->setVar("imgcat_maxwidth", $imgcat_maxwidth);
254  $imagecategory->setVar("imgcat_maxheight", $imgcat_maxheight);
255  $imagecategory->setVar("imgcat_weight", $imgcat_weight);
256  if (!$imgcat_handler->insert($imagecategory)) {
257  redirect_header($current_file . "?target=" . $target, 3);
258  }
259  $imagecategoryperm_handler =& xoops_gethandler("groupperm");
260  $criteria = new CriteriaCompo(new Criteria("gperm_itemid", $imgcat_id));
261  $criteria->add(new Criteria("gperm_modid", 1));
262  $criteria2 = new CriteriaCompo(new Criteria("gperm_name", 'imgcat_write'));
263  $criteria2->add(new Criteria("gperm_name", 'imgcat_read'), "OR");
264  $criteria->add($criteria2);
265  $imagecategoryperm_handler->deleteAll($criteria);
266  if (!isset($readgroup)) {
267  $readgroup = array();
268  }
269  if (!in_array(XOOPS_GROUP_ADMIN, $readgroup)) {
270  array_push($readgroup, XOOPS_GROUP_ADMIN);
271  }
272  foreach ($readgroup as $rgroup) {
273  $imagecategoryperm =& $imagecategoryperm_handler->create();
274  $imagecategoryperm->setVar("gperm_groupid", $rgroup);
275  $imagecategoryperm->setVar("gperm_itemid", $imgcat_id);
276  $imagecategoryperm->setVar("gperm_name", 'imgcat_read');
277  $imagecategoryperm->setVar("gperm_modid", 1);
278  $imagecategoryperm_handler->insert($imagecategoryperm);
279  unset($imagecategoryperm);
280  }
281  if (!isset($writegroup)) {
282  $writegroup = array();
283  }
284  if (!in_array(XOOPS_GROUP_ADMIN, $writegroup)) {
285  array_push($writegroup, XOOPS_GROUP_ADMIN);
286  }
287  foreach ($writegroup as $wgroup) {
288  $imagecategoryperm =& $imagecategoryperm_handler->create();
289  $imagecategoryperm->setVar("gperm_groupid", $wgroup);
290  $imagecategoryperm->setVar("gperm_itemid", $imgcat_id);
291  $imagecategoryperm->setVar("gperm_name", 'imgcat_write');
292  $imagecategoryperm->setVar("gperm_modid", 1);
293  $imagecategoryperm_handler->insert($imagecategoryperm);
294  unset($imagecategoryperm);
295  }
296  redirect_header($current_file . "?target=" . $target, 3, _MD_AM_DBUPDATED);
297  }
298  // Update categorie - end
299 
300  // Confirm delete categorie - start
301  if ( !empty($_GET["op"]) && $op == "delcat" ) {
302  xoops_header();
303  echo "<link href='css/xoopsimagebrowser.css' rel='stylesheet' type='text/css' />";
304  xoops_confirm(array("op" => "delcatok", "imgcat_id" => $imgcat_id, "target" => $target), "xoopsimagebrowser.php", _MD_RUDELIMGCAT);
305  xoops_footer();
306  exit();
307  }
308  // Confirm delete categorie - end
309 
310  // Delete categorie - start
311  if ( !empty($_POST["op"]) && $op == "delcatok" ) {
312  if (!$GLOBALS["xoopsSecurity"]->check()) {
313  redirect_header($current_file . "?target=" . $target, 3, implode("<br />", $GLOBALS["xoopsSecurity"]->getErrors()));
314  }
315  $imgcat_id = intval($imgcat_id);
316  if ($imgcat_id <= 0) {
317  redirect_header($current_file . "?target=" . $target, 3);
318  }
319  $imgcat_handler = xoops_gethandler("imagecategory");
320  $imagecategory =& $imgcat_handler->get($imgcat_id);
321  if (!is_object($imagecategory)) {
322  redirect_header($current_file . "?target=" . $target, 3);
323  }
324  if ($imagecategory->getVar("imgcat_type") != "C") {
325  redirect_header($current_file . "?target=" . $target, 3, _MD_SCATDELNG);
326  }
327  $image_handler =& xoops_gethandler("image");
328  $images =& $image_handler->getObjects(new Criteria("imgcat_id", $imgcat_id), true, false);
329  $errors = array();
330  foreach (array_keys($images) as $i) {
331  if (!$image_handler->delete($images[$i])) {
332  $errors[] = sprintf(_MD_FAILDEL, $i);
333  } else {
334  if (file_exists(XOOPS_UPLOAD_PATH."/".$images[$i]->getVar("image_name")) && !unlink(XOOPS_UPLOAD_PATH."/".$images[$i]->getVar("image_name"))) {
335  $errors[] = sprintf(_MD_FAILUNLINK, $i);
336  }
337  }
338  }
339  if (!$imgcat_handler->delete($imagecategory)) {
340  $errors[] = sprintf(_MD_FAILDELCAT, $imagecategory->getVar("imgcat_name"));
341  }
342  if (count($errors) > 0) {
343  redirect_header($current_file . "?target=" . $target, 3, xoops_error(implode("<br />", $error) ) );
344  }
345  redirect_header($current_file . "?target=" . $target, 3, _MD_AM_DBUPDATED);
346  }
347  // Delete categorie - end
348 
349 
350 // ************************* NOT USED ************************************
351  // Confirm delete file - start
352  if ( !empty($_GET["op"]) && $op == "delfile" ) {
353  xoops_header();
354  echo "<link href='css/xoopsimagebrowser.css' rel='stylesheet' type='text/css' />";
355  xoops_confirm(array("op" => "delfileok", "image_id" => $image_id, "target" => $target), "xoopsimagebrowser.php", _MD_RUDELIMG);
356  xoops_footer();
357  exit();
358  }
359  // Confirm delete file - end
360 
361  // Delete file - start
362  if ($op == "delfileok") {
363  if (!$GLOBALS["xoopsSecurity"]->check()) {
364  redirect_header($current_file . "?target=" . $target, 3, implode("<br />", $GLOBALS["xoopsSecurity"]->getErrors()));
365  }
366  $image_id = intval($image_id);
367  if ($image_id <= 0) {
368  redirect_header($current_file . "?target=" . $target, 3);
369  }
370  $image_handler =& xoops_gethandler("image");
372  if (!is_object($image)) {
373  redirect_header($current_file . "?target=" . $target, 3);
374  }
375  if (!$image_handler->delete($image)) {
376  redirect_header($current_file . "?target=" . $target, 3, xoops_error(sprintf(_MD_FAILDEL, $image->getVar("image_id"))) );
377  }
378  @unlink(XOOPS_UPLOAD_PATH."/".$image->getVar("image_name"));
379  redirect_header($current_file . "?target=" . $target, 3, _MD_AM_DBUPDATED);
380  }
381  // Delete file - end
382 // ************************* NOT USED ************************************
383 }
384 
385 echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
386 echo '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="' . _LANGCODE . '" lang="' . _LANGCODE . '">';
387 echo '<head>';
388 echo '<meta http-equiv="content-type" content="text/html; charset=' . _CHARSET . '" />';
389 echo '<meta http-equiv="content-language" content="' . _LANGCODE . '" />';
390 echo '<title>{#xoopsimagebrowser_dlg.dialog_title}</title>';
391 echo '<script type="text/javascript" src="../../tiny_mce_popup.js"></script>';
392 echo '<script type="text/javascript" src="../../utils/mctabs.js"></script>';
393 echo '<script type="text/javascript" src="../../utils/form_utils.js"></script>';
394 echo '<script type="text/javascript" src="../../utils/validate.js"></script>';
395 echo '<script type="text/javascript" src="js/xoopsimagebrowser.js"></script>';
396 echo '<link href="' . xoops_getcss($xoopsConfig['theme_set']) . '" rel="stylesheet" type="text/css" />';
397 echo '<link href="css/xoopsimagebrowser.css" rel="stylesheet" type="text/css" />';
398 echo '<base target="_self" />';
399 echo '</head>';
400 echo '<body>';
401 
402 echo '<div class="tabs">';
403 echo '<ul>';
404 echo '<li id="imagebrowser_tab" class="current"><span><a href="javascript:mcTabs.displayTab(\'imagebrowser_tab\',\'imagebrowser_panel\');" onmousedown="return false;">';
405 if ( $op == 'listimg' ) {
406  echo '{#xoopsimagebrowser_dlg.tab_listimages}';
407 } else {
408  echo '{#xoopsimagebrowser_dlg.tab_listcategories}';
409 }
410 echo '</a></span></li>';
411 if (!empty($catwritelist)) {
412  echo '<li id="loadimage_tab"><span><a href="javascript:mcTabs.displayTab(\'loadimage_tab\',\'loadimage_panel\');" onmousedown="return false;">{#xoopsimagebrowser_dlg.tab_loadimage}</a></span></li>';
413 }
414 if ( $isadmin ) {
415  echo '<li id="createcategory_tab"><span><a href="javascript:mcTabs.displayTab(\'createcategory_tab\',\'createcategory_panel\');" onmousedown="return false;">{#xoopsimagebrowser_dlg.tab_createcategory}</a></span></li>';
416 }
417 echo '</ul>';
418 echo '</div>';
419 
420 echo '<div class="panel_wrapper">';
421  echo '<div id="imagebrowser_panel" class="panel current" style="overflow:auto;">';
422 
423  //list Categories - start
424  if ($op == 'list') {
425  if (!empty($catreadlist)) {
426  echo '<table width="100%" class="outer" cellspacing="1">';
427  // get all categories
428  $imagecategories =& $imgcat_handler->getObjects();
429  $catcount = count($imagecategories);
430  $image_handler =& xoops_gethandler('image');
431  for ($i = 0; $i < $catcount; $i++) {
432  echo '<tr valign="top" align="left"><td class="head">';
433  if ( in_array($imagecategories[$i]->getVar('imgcat_id'), array_keys($catreadlist)) ) {
434  // count images stored in this category
435  $this_imgcat_id = $imagecategories[$i]->getVar('imgcat_id');
436  $countimagesincat = $image_handler->getCount(new Criteria('imgcat_id', $this_imgcat_id));
437  echo $this_imgcat_id . ' - ' . $imagecategories[$i]->getVar('imgcat_name') . ' (' . sprintf(_NUMIMAGES, '<strong>' . $countimagesincat . '</strong>') . ')';
438  echo '</td><td class="even">';
439  echo '&nbsp;[<a href="' . $current_file . '?target=' . $target . '&amp;op=listimg&amp;imgcat_id=' . $this_imgcat_id . '">' . _LIST . '</a>]';
440  if ($isadmin) {
441  echo '&nbsp;[<a href="'.$current_file.'?target=' . $target . '&amp;op=editcat&amp;imgcat_id=' . $this_imgcat_id . '">' . _EDIT . '</a>]';
442  }
443  if ($isadmin && $imagecategories[$i]->getVar('imgcat_type') == 'C') {
444  echo '&nbsp;[<a href="' . $current_file . '?target=' . $target . '&amp;op=delcat&amp;imgcat_id=' . $this_imgcat_id . '">' . _DELETE . '</a>]';
445  }
446  }
447  echo '</td></tr>';
448  }
449  echo '</table>';
450  }
451  }
452  //list Categories - end
453 
454  //list images - start
455  if ($op == 'listimg') {
456  $imgcat_id = intval($imgcat_id);
457  if ($imgcat_id <= 0) {
458  redirect_header($current_file . '?target=' . $target, 1);
459  }
460  $imgcat_handler = xoops_gethandler('imagecategory');
461  $imagecategory =& $imgcat_handler->get($imgcat_id);
462  if (!is_object($imagecategory)) {
463  redirect_header($current_file . '?target=' . $target, 1);
464  }
465  $image_handler = xoops_gethandler('image');
466 
467  $criteria = new Criteria('imgcat_id', $imgcat_id);
468  $imgcount = $image_handler->getCount($criteria);
469  $start = isset($_GET['start']) ? intval($_GET['start']) : 0;
470  $criteria->setStart($start);
471  $criteria->setLimit(20);
472  $images =& $image_handler->getObjects($criteria, true, false);
473 
474  echo '<a href="' . $current_file . '?target=' . $target . '">' . _MD_IMGMAIN . '</a>&nbsp;<span style="font-weight:bold;">&gt;</span>&nbsp;'.$imagecategory->getVar('imgcat_name');
475  echo '<br /><br /><strong>{#xoopsimagebrowser_dlg.select_image}</strong>';
476  echo '<form action="'.$current_file.'?target='.$target.'" method="post">';
477  $rowspan = ($catwritelist) ? 5 : 2;
478  foreach (array_keys($images) as $i) {
479  $image_src = "";
480  // check if image stored in db/as file - start
481  if ($imagecategory->getVar('imgcat_storetype') == 'db') {
482  $image_src = ''.XOOPS_URL.'/image.php?id='.$i.'';
483  } else {
484  $image_src = ''.XOOPS_UPLOAD_URL.'/'.$images[$i]->getVar('image_name').'';
485  }
486  $image_size = getimagesize($image_src);
487  // check if image stored in db/as file - end
488 
489  echo '<table width="100%" class="outer">';
490  echo '<tr>';
491  echo '<td rowspan="' . $rowspan . '" class="xoopsimage">';
492 
493  echo '<img id="imageid' . $images[$i]->getVar('image_id') . '" src="'.$image_src.'" alt="'.$images[$i]->getVar('image_nicename', 'E').'" title="'.$images[$i]->getVar('image_nicename', 'E').'" onclick="XoopsimagebrowserDialog.insertAndClose(\'imageid'.$images[$i]->getVar('image_id').'\');return false;"/>';
494  echo '<br />';
495  echo ''.$image_size[0].'x'.$image_size[1].'';
496  echo '</td>';
497  echo '<td class="head">'._IMAGENAME,'</td>';
498  echo '<td class="even"><input type="hidden" name="image_id[]" value="'.$i.'" /><input type="text" name="image_nicename[]" value="'.$images[$i]->getVar('image_nicename', 'E').'" size="20" maxlength="255" /></td>';
499  echo '</tr>';
500 
501  echo '<tr>';
502  echo '<td class="head">'._IMAGEMIME.'</td>';
503  echo '<td class="odd">'.$images[$i]->getVar('image_mimetype').'</td>';
504  echo '</tr>';
505 
506  if ( $catwritelist ) {
507  echo '<tr>';
508  echo '<td class="head">'._IMAGECAT.'</td>';
509  echo '<td class="even">';
510  echo '<select name="imgcat_id[]" size="1">';
511  $list = $imgcat_handler->getList($groups, null, null, $imagecategory->getVar('imgcat_storetype'));
512  foreach ($list as $value => $name) {
513  echo '<option value="'.$value.'"'.(($value == $images[$i]->getVar('imgcat_id'))?' selected="selected"':'').'>'.$name.'</option>';
514  }
515  echo '</select>';
516  echo '</td>';
517  echo '</tr>';
518 
519  echo '<tr>';
520  echo '<td class="head">'._IMGWEIGHT.'</td>';
521  echo '<td class="odd"><input type="text" name="image_weight[]" value="'.$images[$i]->getVar('image_weight').'" size="3" maxlength="4" /></td>';
522  echo '</tr>';
523 
524  echo '<tr>';
525  echo '<td class="head">'._IMGDISPLAY.'</td>';
526  echo '<td class="even">';
527  echo '<input type="checkbox" name="image_display[]" value="1"'.(($images[$i]->getVar('image_display') == 1)?' checked="checked"':'').' />';
528  echo '</td>';
529  echo '</tr>';
530  }
531  echo '</table>';
532  echo '<br />';
533  }
534 
535  if ($imgcount > 0) {
536  if ($imgcount > 20) {
537  include_once XOOPS_ROOT_PATH.'/class/pagenav.php';
538  $nav = new XoopsPageNav($imgcount, 20, $start, 'start', 'op=listimg&amp;target='.$target.'&amp;imgcat_id='.$imgcat_id);
539  echo '<div text-align="right">'.$nav->renderNav().'</div>';
540  }
541  if ( $catwritelist ) {
542  echo '<input type="hidden" name="op" value="save" />'.$GLOBALS['xoopsSecurity']->getTokenHTML().'<input type="submit" name="submit" value="'._SUBMIT.'" />';
543  echo '</form>';
544  }
545  }
546  }
547  //list images - end
548 
549  //edit category - start
550  if ($op == 'editcat') {
551  if ($imgcat_id <= 0) {
552  redirect_header($current_file . '?target=' . $target, 1);
553  }
554  $imgcat_handler = xoops_gethandler('imagecategory');
555  $imagecategory =& $imgcat_handler->get($imgcat_id);
556  if (!is_object($imagecategory)) {
557  redirect_header($current_file . '?target=' . $target, 1);
558  }
559  include_once XOOPS_ROOT_PATH.'/class/xoopsformloader.php';
560  $imagecategoryperm_handler =& xoops_gethandler('groupperm');
561  $form = new XoopsThemeForm(_MD_EDITIMGCAT, 'imagecat_form', ''.$current_file.'?target='.$target.'', 'post', true);
562  $form->addElement(new XoopsFormText(_MD_IMGCATNAME, 'imgcat_name', 50, 255, $imagecategory->getVar('imgcat_name')), true);
563  $form->addElement(new XoopsFormSelectGroup(_MD_IMGCATRGRP, 'readgroup', true, $imagecategoryperm_handler->getGroupIds('imgcat_read', $imgcat_id), 5, true));
564  $form->addElement(new XoopsFormSelectGroup(_MD_IMGCATWGRP, 'writegroup', true, $imagecategoryperm_handler->getGroupIds('imgcat_write', $imgcat_id), 5, true));
565  $form->addElement(new XoopsFormText(_IMGMAXSIZE, 'imgcat_maxsize', 10, 10, $imagecategory->getVar('imgcat_maxsize')));
566  $form->addElement(new XoopsFormText(_IMGMAXWIDTH, 'imgcat_maxwidth', 3, 4, $imagecategory->getVar('imgcat_maxwidth')));
567  $form->addElement(new XoopsFormText(_IMGMAXHEIGHT, 'imgcat_maxheight', 3, 4, $imagecategory->getVar('imgcat_maxheight')));
568  $form->addElement(new XoopsFormText(_MD_IMGCATWEIGHT, 'imgcat_weight', 3, 4, $imagecategory->getVar('imgcat_weight')));
569  $form->addElement(new XoopsFormRadioYN(_MD_IMGCATDISPLAY, 'imgcat_display', $imagecategory->getVar('imgcat_display'), _YES, _NO));
570  $storetype = array('db' => _MD_INDB, 'file' => _MD_ASFILE);
571  $form->addElement(new XoopsFormLabel(_MD_IMGCATSTRTYPE, $storetype[$imagecategory->getVar('imgcat_storetype')]));
572  $form->addElement(new XoopsFormHidden('imgcat_id', $imgcat_id));
573  $form->addElement(new XoopsFormHidden('op', 'updatecat'));
574  $form->addElement(new XoopsFormButton('', 'imgcat_button', _SUBMIT, 'submit'));
575  echo '<a href="'.$current_file.'?target='.$target.'">'. _MD_IMGMAIN .'</a>&nbsp;<span style="font-weight:bold;">&gt;</span>&nbsp;'.$imagecategory->getVar('imgcat_name').'<br /><br />';
576  $form->display();
577  }
578  echo '<div class="mceActionPanel floatright" >';
579  echo '<input type="button" id="cancel" name="cancel" value="{#cancel}" onclick="tinyMCEPopup.close();" />';
580  echo '</div>';
581  echo '</div>';
582  //edit category - end
583 
584  //create Image - start
585  if ( $isadmin || !empty($catwritelist)) {
586  echo '<div id="loadimage_panel" class="panel" style="overflow:auto;">';
587  $form = new XoopsThemeForm(_ADDIMAGE, 'image_form', '' . $current_file . '?target=' . $target . '', 'post', true);
588  $form->setExtra('enctype="multipart/form-data"');
589  $form->addElement(new XoopsFormText(_IMAGENAME, 'image_nicename', 50, 255), true);
590  $select = new XoopsFormSelect(_IMAGECAT, 'imgcat_id');
591  if ($isadmin) {
592  $select->addOptionArray($imgcat_handler->getList());
593  } else {
594  $select->addOptionArray($catwritelist);
595  }
596  $form->addElement($select, true);
597  $form->addElement(new XoopsFormFile(_IMAGEFILE, 'image_file', 5000000));
598  $form->addElement(new XoopsFormText(_IMGWEIGHT, 'image_weight', 3, 4, 0));
599  $form->addElement(new XoopsFormRadioYN(_IMGDISPLAY, 'image_display', 1, _YES, _NO));
600  $form->addElement(new XoopsFormHidden('op', 'addfile'));
601  $form->addElement(new XoopsFormButton('', 'img_button', _SUBMIT, 'submit'));
602  $form->display();
603  echo '<div class="mceActionPanel floatright" >';
604  echo '<input type="button" id="cancel" name="cancel" value="{#cancel}" onclick="tinyMCEPopup.close();" />';
605  echo '</div>';
606  echo '</div>';
607  }
608  //create Image - end
609 
610  //create Category - start
611  if ( $isadmin ) {
612  echo '<div id="createcategory_panel" class="panel" style="overflow:auto;">';
613  $form = new XoopsThemeForm(_MD_ADDIMGCAT, 'imagecat_form', ''.$current_file.'?target='.$target.'', 'post', true);
614  $form->addElement(new XoopsFormText(_MD_IMGCATNAME, 'imgcat_name', 50, 255), true);
615  $form->addElement(new XoopsFormSelectGroup(_MD_IMGCATRGRP, 'readgroup', true, XOOPS_GROUP_ADMIN, 5, true));
616  $form->addElement(new XoopsFormSelectGroup(_MD_IMGCATWGRP, 'writegroup', true, XOOPS_GROUP_ADMIN, 5, true));
617  $form->addElement(new XoopsFormText(_IMGMAXSIZE, 'imgcat_maxsize', 10, 10, 50000));
618  $form->addElement(new XoopsFormText(_IMGMAXWIDTH, 'imgcat_maxwidth', 3, 4, 120));
619  $form->addElement(new XoopsFormText(_IMGMAXHEIGHT, 'imgcat_maxheight', 3, 4, 120));
620  $form->addElement(new XoopsFormText(_MD_IMGCATWEIGHT, 'imgcat_weight', 3, 4, 0));
621  $form->addElement(new XoopsFormRadioYN(_MD_IMGCATDISPLAY, 'imgcat_display', 1, _YES, _NO));
622  $storetype = new XoopsFormRadio(_MD_IMGCATSTRTYPE.'<br /><span style="color:#ff0000;">'._MD_STRTYOPENG.'</span>', 'imgcat_storetype', 'file');
623  $storetype->addOptionArray(array('file' => _MD_ASFILE, 'db' => _MD_INDB));
624  $form->addElement($storetype);
625  $form->addElement(new XoopsFormHidden('op', 'addcat'));
626  $form->addElement(new XoopsFormButton('', 'imgcat_button', _SUBMIT, 'submit'));
627  $form->display();
628  echo '<div class="mceActionPanel floatright" >';
629  echo '<input type="button" id="cancel" name="cancel" value="{#cancel}" onclick="tinyMCEPopup.close();" />';
630  echo '</div>';
631  echo '</div>';
632  }
633  //create Category - end
634 
635 echo '</div>';
636 xoops_footer();
637 ?>