<?php


# ******************************************* LICENCE******************************************* 
/*
	Copyright (c) PORTANEO.

	This file is part of POSH (Portaneo Open Source Homepage) http://sourceforge.net/projects/posh/.

	POSH is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version

	POSH is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with Posh.  If not, see <http://www.gnu.org/licenses/>.
*/
/**
 POSH delete a widget created by Typo3 through url
 
 concerns url widget only
 
 Parameter: 
    
    url=
   
 !! be careful, this file must be saved under uft8 format, and display an e accentuated here : é
**/

$folder="";
$not_access=1;
$isScript=true;
$isPortal=false;
$granted="A";
$pagename="api/delwidget.php";
//includes
require_once("includes_api.php");
require_once("../includes/admin_tools.php");
require_once("authentication.php");

//require_once("../tutorial/addwidget.inc.php");
require_once('../includes/file.inc.php');
require_once('../includes/xml.inc.php');
require_once('../includes/http.inc.php');
require_once('../includes/log.inc.php');
require_once('../includes/misc.inc.php');

require_once('../includes/xmldom_tool.php');
include('../includes/fixmagic.php'); 
include_once('../db_layer/'.__DBTYPE.'/tutorial.php');
require_once("../includes/modules_tools.php");
require_once("../includes/tutorial-dom.inc.php");

if (isset($_GET['url'])) {
    $url = $_GET['url'];
} else {
    print "File missing";
    exit;
}


$datas = array();
$datas['DB'] = $DB;
//get id of widget from url
$DB->getResults(   $module_getbyUrl,$DB->quote("%$url%") );

if ($DB->nbResults() > 0) {
    $row = $DB->fetch(0);
    $id = $row['id'];
    $DB->freeResults();
    //remove $module_updateremove
    $DB->execute($module_updateremove,$DB->escape($id));
    $DB->getResults($module_getModuleDirectory,$DB->escape($id));
    if ($DB->nbResults() > 0) {
        $categories = array();
        $ap=0;
        while ($row = $DB->fetch(0)) {
            $catid = $row['category_id'];
            array_push($categories,$catid);
        }
        $DB->freeResults();
        foreach ($categories as $c) {
            $DB->execute($module_deleteModuleCategory,$DB->escape($id),$DB->escape($catid));
        }
    }

}


//





?>