#!/usr/bin/php
<?php
/* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4:
  Codificación: UTF-8
  +----------------------------------------------------------------------+
  | Elastix version 2.0                                                  |
  | http://www.elastix.org                                               |
  +----------------------------------------------------------------------+
  | Copyright (c) 2006 Palosanto Solutions S. A.                         |
  +----------------------------------------------------------------------+
  | Cdla. Nueva Kennedy Calle E 222 y 9na. Este                          |
  | Telfs. 2283-268, 2294-440, 2284-356                                  |
  | Guayaquil - Ecuador                                                  |
  | http://www.palosanto.com                                             |
  +----------------------------------------------------------------------+
  | The contents of this file are subject to the General Public License  |
  | (GPL) Version 2 (the "License"); you may not use this file except in |
  | compliance with the License. You may obtain a copy of the License at |
  | http://www.opensource.org/licenses/gpl-license.php                   |
  |                                                                      |
  | Software distributed under the License is distributed on an "AS IS"  |
  | basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See  |
  | the License for the specific language governing rights and           |
  | limitations under the License.                                       |
  +----------------------------------------------------------------------+
  | The Original Code is: Elastix Open Source.                           |
  | The Initial Developer of the Original Code is PaloSanto Solutions    |
  +----------------------------------------------------------------------+
 */

/*
This script takes one argument, the name parent module or rpm name section. 
This script delete menus and resources elastix.
*/

if ($argc < 2) die("Please specify the name of parent id menu.\n");

$documentRoot="/var/www/html";
require_once("$documentRoot/libs/misc.lib.php");
require_once("$documentRoot/configs/default.conf.php");

//global variables framework
global $arrConf;
global $arrLang;
require_once("$arrConf[basePath]/libs/paloSantoDB.class.php");
require_once("$arrConf[basePath]/libs/paloSantoMenu.class.php");
require_once("$arrConf[basePath]/libs/paloSantoACL.class.php");

$pDB = new paloDB("sqlite3:///{$arrConf['elastix_dbdir']}/menu.db");
$pDBACL = new paloDB("sqlite3:///{$arrConf['elastix_dbdir']}/acl.db");

if(!empty($pDB->errMsg)) echo "ERROR DE DB: {$pDB->errMsg}\n";
if(!empty($pDBACL->errMsg)) echo "ERROR DE DB: {$pDBACL->errMsg}\n";

$oMenu = new paloMenu($pDB);
$oACL = new paloACL($pDBACL);

if(isset($_SERVER['argv'][1])){
    $idmenu = $_SERVER['argv'][1];
    
    $oMenu->_DB->beginTransaction();
    $oACL->_DB->beginTransaction();
 
    if($oMenu->deleteFather($idmenu, $oACL)){
        $oMenu->_DB->commit();
        $oACL->_DB->commit();
	echo "The menus have been removed\n";
    }
    else{
        $oMenu->_DB->rollBack();
        $oACL->_DB->rollBack();	
	echo "Error: The menus haven't been removed\n";
    }
}
else{
    echo "Error: arg not defined. Usage: {$_SERVER['argv'][0]} system\n";
    return 1;
}
?>
