".$myts->makeTboxData4Show($file)." | ";
$files=array($dir.$file, $dir.$xoopsModuleConfig['normal_pfx'].$file, $dir.$xoopsModuleConfig['thumb_pfx'].$file);
foreach ($files as $currFile){
$del_pic.= "";
if (is_file($currFile)){
if(@unlink($currFile))
$del_pic.= $green;
else
$del_pic.= $red;
} else
$del_pic.= " ";
$del_pic.= " | ";
}
$deleted=xoops_comment_delete($xoopsModule->getVar('mid'), $pid);
$del_pic.= "";
if($deleted)
$del_pic.= $green;
else
$del_pic.= " ";
$del_pic.= " | ";
$query = "DELETE FROM ".$xoopsDB->prefix("xcgal_pictures")." WHERE pid='$pid' LIMIT 1";
$result = $xoopsDB->queryf($query);
$del_pic.= "";
if($xoopsDB->getAffectedRows() > 0)
$del_pic.= $green;
else
$del_pic.= $red;
$del_pic.= " | ";
$del_pic.= "
\n";
return $aid;
}
function delete_album($aid)
{
global $xoopsDB;
global $del_message,$del_pic,$pic_del;
$query = "SELECT title, category FROM ".$xoopsDB->prefix("xcgal_albums")." WHERE aid ='$aid'";
$result = $xoopsDB->query($query);
if (!$xoopsDB->getRowsNum($result)) redirect_header('index.php',2,_MD_NON_EXIST_AP);
$album_data = $xoopsDB->fetchArray($result);
if (!GALLERY_ADMIN_MODE) {
if ($album_data['category'] != FIRST_USER_CAT + USER_ID) redirect_header('index.php',2,_MD_PERM_DENIED);
}
$query = "SELECT pid FROM ".$xoopsDB->prefix("xcgal_pictures")." WHERE aid='$aid'";
$result = $xoopsDB->query($query);
// Delete all files
$pic_del='';
while($pic = $xoopsDB->fetchArray($result))
{
delete_picture($pic['pid']);
$pic_del.=$del_pic;
$del_pic='';
}
// Delete album
$query = "DELETE from ".$xoopsDB->prefix("xcgal_albums")." WHERE aid='$aid'";
$result = $xoopsDB->queryf($query);
if($xoopsDB->getAffectedRows() > 0){
$del_message=sprintf(_MD_DEL_ALB_DEL_SUC, $album_data['title']);
}
else $del_message ='';
}
/**************************************************************************
* Album manager functions
**************************************************************************/
function parse_select_option($value)
{
global $HTML_SUBST, $myts;
if (!preg_match("/.+?no=(\d+),album_nm='(.+?)',album_sort=(\d+),action=(\d)/", $value, $matches))
return false;
return array(
'album_no' => (int)$matches[1],
'album_nm' => $myts->makeTboxData4Show($matches[2]),
'album_sort' => (int)$matches[3],
'action' => (int)$matches[4]
);
}
function parse_orig_sort_order($value)
{
if (!preg_match("/(\d+)@(\d+)/", $value, $matches))
return false;
return array(
'aid' => (int)$matches[1],
'pos' => (int)$matches[2],
);
}
function parse_list($value)
{
return preg_split("/,/", $value, -1, PREG_SPLIT_NO_EMPTY);
}
/**************************************************************************
* Main code starts here
**************************************************************************/
if (!isset($HTTP_GET_VARS['what']) && !isset($HTTP_POST_VARS['what']) && !isset($HTTP_POST_VARS['picture'])) {
redirect_header('index.php',2,_MD_PARAM_MISSING);
}
if (!isset($HTTP_GET_VARS['what']) && !isset($HTTP_POST_VARS['what']) && isset($HTTP_POST_VARS['picture'])) {
$what='picture';
} else {
$what = isset($HTTP_GET_VARS['what']) ? $HTTP_GET_VARS['what'] : $HTTP_POST_VARS['what'];
}
switch ($what){
//
// Album manager (don't necessarily delete something ;-)
//
case 'albmgr':
if (!(GALLERY_ADMIN_MODE || USER_ADMIN_MODE)) redirect_header('index.php',2,_MD_ACCESS_DENIED);
if(!GALLERY_ADMIN_MODE){
$restrict = "AND category = '".(FIRST_USER_CAT + USER_ID)."'";
} else {
$restrict = '';
}
$out_caption= _MD_DEL_ALBMGR;
$orig_sort_order = parse_list($HTTP_POST_VARS['sort_order']);
foreach ($orig_sort_order as $album){
$op = parse_orig_sort_order($album);
if (count ($op) == 2){
$query = "UPDATE ".$xoopsDB->prefix("xcgal_albums")." SET pos='{$op['pos']}' WHERE aid='{$op['aid']}' $restrict LIMIT 1";
$xoopsDB->query($query);
} else {
redirect_header('index.php',2, sprintf(_MD_DEL_INVALID, $HTTP_POST_VARS['sort_order']));
}
}
$to_delete = parse_list($HTTP_POST_VARS['delete_album']);
$data = array();
foreach ($to_delete as $album_id){
delete_album((int)$album_id);
$data[]= array('del_message' => $del_message,'pic_del'=>$pic_del);
}
$create_update ='';
if (isset($HTTP_POST_VARS['to'])) foreach ($HTTP_POST_VARS['to'] as $option_value){
$op = parse_select_option(stripslashes($option_value));
switch ($op['action']){
case '0':
break;
case '1':
if(GALLERY_ADMIN_MODE){
$category = (int)$HTTP_POST_VARS['cat'];
} else {
$category = FIRST_USER_CAT + USER_ID;
}
$create_update = sprintf(_MD_DEL_CREATE, $op['album_nm']);
$query = "INSERT INTO ".$xoopsDB->prefix("xcgal_albums")." (category, title, uploads, pos) VALUES ('$category', '".addslashes($op['album_nm'])."', 'NO', '{$op['album_sort']}')";
$xoopsDB->query($query);
break;
case '2':
$create_update = sprintf(_MD_DEL_UPDATE, $op['album_no'], $op['album_nm'], $op['album_sort']);
$query = "UPDATE ".$xoopsDB->prefix("xcgal_albums")." SET title='".addslashes($op['album_nm'])."', pos='{$op['album_sort']}' WHERE aid='{$op['album_no']}' $restrict LIMIT 1";
$xoopsDB->query($query);
break;
default:
redirect_header('index.php',2,_MD_DEL_INVALID);
}
}
$continueURL = 'index.php';
break;
//
// Picture
//
case 'picture':
if (!(USER_IS_ADMIN || USER_ADMIN_MODE)) redirect_header('index.php',2,_MD_ACCESS_DENIED);
$pid = (int)$HTTP_POST_VARS['id'];
$out_caption = _MD_DEL_DELPIC;
$aid = delete_picture($pid);
$data = array();
$data[]= array('del_message' => '','pic_del'=>$del_pic);
$continueURL = "thumbnails.php?album={$aid}";
$create_update='';
break;
//
// Album
//
case 'album':
if (!(GALLERY_ADMIN_MODE || USER_ADMIN_MODE)) redirect_header('index.php',2,_MD_ACCESS_DENIED);
$aid = (int)$HTTP_GET_VARS['id'];
$out_caption= _MD_DEL_DELALB;
delete_album($aid);
$data = array();
$data[]= array('del_message' => $del_message,'pic_del'=>$pic_del);
$continueURL ='index.php';
$create_update='';
break;
//
// Unknow command
//
default:
redirect_header('index.php',2,_MD_PARAM_MISSING);
}
if ($out_caption){
$xoopsOption['template_main'] = 'xcgal_delete.html';
include XOOPS_ROOT_PATH."/header.php";
$xoopsTpl->assign('table_header', $out_caption);
//alb pic
foreach ($data as $dels){
$xoopsTpl->append('deletes', array('del_message' => $dels['del_message'],'pic_del'=>$dels['pic_del']));
}
if ($header_printed){
$xoopsTpl->assign('lang_pictures', _MD_PICS);
}
$xoopsTpl->assign('create_update', $create_update);
if ($need_caption){
//output_caption();
$xoopsTpl->assign('need_caption', 1);
$xoopsTpl->assign('lang_caption', _MD_DEL_CAPTION);
$xoopsTpl->assign('lang_fs_pic', _MD_DEL_FS_PIC);
$xoopsTpl->assign('lang_del_success', _MD_DEL_DEL_SUCCESS);
$xoopsTpl->assign('lang_ns_pic', _MD_DEL_NS_PIC);
$xoopsTpl->assign('lang_err_del', _MD_DEL_ERR_DEL);
$xoopsTpl->assign('lang_thumb_pic', _MD_DEL_THUMB);
$xoopsTpl->assign('lang_comment', _MD_DEL_COMMENT);
$xoopsTpl->assign('lang_im_in_alb', _MD_DEL_IMGALB);
}
$xoopsTpl->assign('continue_url', $continueURL);
$xoopsTpl->assign('lang_continue', _MD_CONTINUE);
user_save_profile();
$xoopsTpl->assign('gallery', $xoopsModule->getVar('name'));
include_once "include/theme_func.php";
main_menu();
//$xoopsTpl->assign('xcgal_footer', pagefooter());
do_footer();
include XOOPS_ROOT_PATH."/footer.php";
}
?>