<?php
require_once('common/config.php');
require_once('classes/dbclass.php');
include_once('common/publicfun.php');
require_once('conn.php');
require_once('check_user.php');

$flag=$_GET["flag"];
$idList=$_POST["checkbox1"];
$scuser_id=$_SESSION["uid"];

$idstr=implode(',',$idList);
if ($flag==1){
    $sql="delete from {$tablepre}favorites where scuser_id='".$scuser_id."' and id in(".$idstr.")";
	$db->exec($sql);
}
if ($flag==2){
    $sql="delete from {$tablepre}mydown where scuser_id='".$scuser_id."' and id in(".$idstr.")";
	$db->exec($sql);
}
if ($flag==3){

	try {
           
        $db->startTrans();

	    /*删除原来已上传的图片*/
		$idarr=explode(",",$idstr);
		include_once("classes/fileclass.php");
		$file = new fileoperate();  
		foreach ($idarr as $msg_id){
            $sql   = "select * from {$tablepre}message where msg_poster='".$scuser_id."' and msg_id='".$msg_id."'";
		    $myrow = $db->get_row($sql);
            if (empty($myrow)){               
                continue;
			}else{
				$sql="select attach_path,thumbnail_path from {$tablepre}attachmng where msg_id='".$msg_id."'";
				$rm = $db->get_all($sql);
				if(is_array($rm) && !empty($rm)){
				   foreach ($rm as $r){
					  $file->del_attach("./",$r['attach_path']);
					  $file->del_attach("./",$r['thumbnail_path']);
				   }
				}

				$db->exec("delete from {$tablepre}categorymng where msg_id='".$msg_id."'");
				$db->exec("delete from {$tablepre}attachmng where msg_id='".$msg_id."'"); 

				$sql="delete from {$tablepre}message where msg_poster='".$scuser_id."' and msg_id='".$msg_id."'";
	            $db->exec($sql);
			}
		}
		/**********************/

		$db->commit();

	} catch (Exception $e) {
			$db->rollback();
			$response_arr = array("status" => -1,"message"  => $e->getMessage());
		    echo json_encode($response_arr);
            exit;
	}
}

header("Location:".$_SERVER["HTTP_REFERER"]);
?>