23 if (!defined(
"XOOPS_ROOT_PATH"))
exit();
30 foreach (
$_POST as $k => $v ) {
46 include_once XOOPS_ROOT_PATH .
"/include/cp_functions.php";
47 include_once XOOPS_ROOT_PATH.
"/modules/system/constants.php";
74 if (isset(
$_GET[
"op"])) {
78 if (isset(
$_GET[
"target"])) {
82 if (isset(
$_GET[
"image_id"])) {
86 if (isset(
$_GET[
"imgcat_id"])) {
87 $imgcat_id = intval(
$_GET[
"imgcat_id"]);
90 if(isset($imgcat_id)) {
91 $imgcat_id = intval($imgcat_id);
100 if ( !empty(
$_POST[
"op"]) &&
$op ==
"save" ) {
101 if (!
$GLOBALS[
"xoopsSecurity"]->check()) {
108 for (
$i = 0;
$i < $count;
$i++) {
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]);
132 if ( !empty(
$_POST[
"op"]) &&
$op ==
"addfile" ) {
133 if (!
$GLOBALS[
"xoopsSecurity"]->check()) {
137 if (!is_object($imgcat)) {
140 include_once XOOPS_ROOT_PATH.
"/class/uploader.php";
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"));
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();
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()));
165 $image->setVar(
"image_body", $fbinary,
true);
166 @unlink($uploader->getSavedDestination());
174 $err = array_merge($err, $uploader->getErrors(
false));
177 if (count($err) > 0) {
185 if ( !empty(
$_POST[
"op"]) &&
$op ==
"addcat" ) {
186 if (!
$GLOBALS[
"xoopsSecurity"]->check()) {
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");
203 $newid = $imagecategory->getVar(
"imgcat_id");
205 if (!isset($readgroup)) {
206 $readgroup = array();
208 if (!in_array(XOOPS_GROUP_ADMIN, $readgroup)) {
209 array_push($readgroup, XOOPS_GROUP_ADMIN);
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);
220 if (!isset($writegroup)) {
221 $writegroup = array();
223 if (!in_array(XOOPS_GROUP_ADMIN, $writegroup)) {
224 array_push($writegroup, XOOPS_GROUP_ADMIN);
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);
240 if ( !empty(
$_POST[
"op"]) &&
$op ==
"updatecat" ) {
241 if (!
$GLOBALS[
"xoopsSecurity"]->check() || $imgcat_id <= 0) {
246 if (!is_object($imagecategory)) {
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);
265 $imagecategoryperm_handler->deleteAll(
$criteria);
266 if (!isset($readgroup)) {
267 $readgroup = array();
269 if (!in_array(XOOPS_GROUP_ADMIN, $readgroup)) {
270 array_push($readgroup, XOOPS_GROUP_ADMIN);
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);
281 if (!isset($writegroup)) {
282 $writegroup = array();
284 if (!in_array(XOOPS_GROUP_ADMIN, $writegroup)) {
285 array_push($writegroup, XOOPS_GROUP_ADMIN);
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);
301 if ( !empty(
$_GET[
"op"]) &&
$op ==
"delcat" ) {
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);
311 if ( !empty(
$_POST[
"op"]) &&
$op ==
"delcatok" ) {
312 if (!
$GLOBALS[
"xoopsSecurity"]->check()) {
315 $imgcat_id = intval($imgcat_id);
316 if ($imgcat_id <= 0) {
321 if (!is_object($imagecategory)) {
324 if ($imagecategory->getVar(
"imgcat_type") !=
"C") {
330 foreach (array_keys($images) as
$i) {
332 $errors[] = sprintf(_MD_FAILDEL, $i);
335 $errors[] = sprintf(_MD_FAILUNLINK, $i);
340 $errors[] = sprintf(_MD_FAILDELCAT, $imagecategory->getVar(
"imgcat_name"));
352 if ( !empty(
$_GET[
"op"]) &&
$op ==
"delfile" ) {
354 echo
"<link href='css/xoopsimagebrowser.css' rel='stylesheet' type='text/css' />";
362 if (
$op ==
"delfileok") {
363 if (!
$GLOBALS[
"xoopsSecurity"]->check()) {
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 .
'">';
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" />';
402 echo
'<div class="tabs">';
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}';
408 echo
'{#xoopsimagebrowser_dlg.tab_listcategories}';
410 echo
'</a></span></li>';
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>';
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>';
420 echo
'<div class="panel_wrapper">';
421 echo
'<div id="imagebrowser_panel" class="panel current" style="overflow:auto;">';
426 echo
'<table width="100%" class="outer" cellspacing="1">';
429 $catcount = count($imagecategories);
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)) ) {
435 $this_imgcat_id = $imagecategories[
$i]->getVar(
'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
' [<a href="' .
$current_file .
'?target=' .
$target .
'&op=listimg&imgcat_id=' . $this_imgcat_id .
'">' .
_LIST .
'</a>]';
441 echo
' [<a href="'.$current_file.
'?target=' .
$target .
'&op=editcat&imgcat_id=' . $this_imgcat_id .
'">' .
_EDIT .
'</a>]';
443 if (
$isadmin && $imagecategories[
$i]->getVar(
'imgcat_type') ==
'C') {
444 echo
' [<a href="' .
$current_file .
'?target=' .
$target .
'&op=delcat&imgcat_id=' . $this_imgcat_id .
'">' .
_DELETE .
'</a>]';
455 if (
$op ==
'listimg') {
456 $imgcat_id = intval($imgcat_id);
457 if ($imgcat_id <= 0) {
462 if (!is_object($imagecategory)) {
474 echo
'<a href="' .
$current_file .
'?target=' .
$target .
'">' .
_MD_IMGMAIN .
'</a> <span style="font-weight:bold;">></span> '.$imagecategory->getVar(
'imgcat_name');
475 echo
'<br /><br /><strong>{#xoopsimagebrowser_dlg.select_image}</strong>';
476 echo
'<form action="'.$current_file.
'?target='.
$target.
'" method="post">';
478 foreach (array_keys($images) as
$i) {
481 if ($imagecategory->getVar(
'imgcat_storetype') ==
'db') {
482 $image_src =
''.XOOPS_URL.
'/image.php?id='.
$i.
'';
484 $image_src =
''.XOOPS_UPLOAD_URL.
'/'.$images[
$i]->getVar(
'image_name').
'';
486 $image_size = getimagesize($image_src);
489 echo
'<table width="100%" class="outer">';
491 echo
'<td rowspan="' . $rowspan .
'" class="xoopsimage">';
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;
"/>';
495 echo ''.$image_size[0].'x'.$image_size[1].'';
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>';
502 echo '<td class="head
">'._IMAGEMIME.'</td>';
503 echo '<td class="odd
">'.$images[$i]->getVar('image_mimetype').'</td>';
506 if ( $catwritelist ) {
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>';
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>';
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
"':'').' />';
536 if ($imgcount > 20) {
537 include_once XOOPS_ROOT_PATH.'/class/pagenav.php';
538 $nav = new XoopsPageNav($imgcount, 20, $start, 'start', 'op=listimg&target='.$target.'&imgcat_id='.$imgcat_id);
539 echo '<div text-align="right
">'.$nav->renderNav().'</div>';
541 if ( $catwritelist ) {
542 echo '<input type="hidden
" name="op
" value="save
" />'.$GLOBALS['xoopsSecurity']->getTokenHTML().'<input type="submit
" name="submit
" value="'._SUBMIT.'" />';
549 //edit category - start
550 if ($op == 'editcat') {
551 if ($imgcat_id <= 0) {
552 redirect_header($current_file . '?target=' . $target, 1);
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);
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> <span style="font-weight:bold;
">></span> '.$imagecategory->getVar('imgcat_name').'<br /><br />';
578 echo '<div class="mceActionPanel floatright
" >';
579 echo '<input type="button
" id="cancel
" name="cancel
" value="{#cancel}
" onclick="tinyMCEPopup.close();
" />';
582 //edit category - end
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');
592 $select->addOptionArray($imgcat_handler->getList());
594 $select->addOptionArray($catwritelist);
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'));
603 echo '<div class="mceActionPanel floatright
" >';
604 echo '<input type="button
" id="cancel
" name="cancel
" value="{#cancel}
" onclick="tinyMCEPopup.close();
" />';
610 //create Category - start
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'));
628 echo '<div class="mceActionPanel floatright
" >';
629 echo '<input type="button
" id="cancel
" name="cancel
" value="{#cancel}
" onclick="tinyMCEPopup.close();
" />';
633 //create Category - end