<?php
//+-----------------------------------------------------+//
//+ Copyright Floopo.com
//+ helper.deletecontent.php
//+ Ajax content deleting helper
//+-----------------------------------------------------+//

//__________Favorite Texts and Images________________________________________________________-

defined('BASEPATH') or die('You can not directly access this file'); //check its within this framework

if(Sanatize($_GET['type']) == 'del_text' || Sanatize($_GET['type']) == 'del_image') {

    //__Login check______
    if($_SESSION['admin'] != 1){ //skip admin
    loggedin_check_simple();
    }
    
    //_____set some vars__________________
    $content_id = Sanatize(mysql_real_escape_string($_GET['id']));
    $content_type = Sanatize(mysql_real_escape_string($_GET['type']));


    //______check that input is ok________
    ($content_id == '' || !is_numeric($content_id)) ? die($lang['generic_error']) : null;
    $content_table = (($content_type == 'del_text') ? 'content_text' :
        'content_images');
    $favorite_table = (($content_type == 'del_text') ? 'favorite_text' :
        'favorite_images');


    //_________Check if I am owner___________
    if($_SESSION['admin'] != 1){ //skip admin
    if($dbase->CountRows("SELECT content_id 
                          FROM $content_table 
					      WHERE content_id = $content_id 
					      AND user_name = '$env_user_name'") == 0) {

        die($lang['generic_error']); //not your content
    }
    }

    //____get images file name__________________
    if($content_type == 'del_image') {
        $image = $dbase->SelectRecord("SELECT filename
                                   FROM content_images
                                   WHERE content_id = $content_id");

        $image_path = BASEPATH.'/content/images/'.$image['filename'];
        $thumb_path = BASEPATH.'/content/images/thumbs/'.$image['filename'];

    }



    //___delete from main____________________________
    $dbase->DeleteRecord("DELETE FROM $content_table 
	                      WHERE content_id = $content_id");

    //____delete from other members favs________________
    $dbase->DeleteRecord("DELETE FROM $favorite_table 
	                      WHERE content_id = $content_id");


    //check if went ok an die
    if($dbase->obj_status) {

        if($content_type == 'del_image') {
            @unlink($thumb_path);
            @unlink($image_path);
        }

        die($lang['request_completed']);

    } else {

        die($lang['generic_error']);
    }

}else{
die($lang['generic_error']);
}


?>