<?php
/**
 *
 * @category        admin
 * @package         admintools
 * @author          Ryan Djurovich, WebsiteBaker Project
 * @author          Werner v.d. Decken
 * @copyright       WebsiteBaker Org. e.V.
 * @link            http://websitebaker.org/
 * @license         http://www.gnu.org/licenses/gpl.html
 * @platform        WebsiteBaker 2.8.3
 * @requirements    PHP 5.3.6 and higher
 * @version         $Id: tool.php 2 2017-07-02 15:14:29Z Manuela $
 * @filesource      $HeadURL: svn://isteam.dynxs.de/wb/2.10.x/trunk/admin/admintools/tool.php $
 * @lastmodified    $Date: 2017-07-02 17:14:29 +0200 (Sun, 02 Jul 2017) $
 *
 */
if ( !defined( 'WB_PATH' ) ){ require( dirname(dirname((__DIR__))).'/config.php' ); }
if ( !class_exists('admin', false) ) { require(WB_PATH.'/framework/class.admin.php'); }
require_once(WB_PATH.'/framework/functions.php');

    $toolDir = (isset($_GET['tool']) && (trim($_GET['tool']) != '') ? trim($_GET['tool']) : '');
    $doSave = (isset($_POST['save_settings']) || (isset($_POST['action']) && strtolower($_POST['action']) == 'save'));
// test for valid tool name

    if(preg_match('/^[a-z][a-z_\-0-9]{2,}$/i', $toolDir)) {
    // Check if tool is installed
        $sql = 'SELECT `name` FROM `'.TABLE_PREFIX.'addons` '.
               'WHERE `type`=\'module\' AND `function`=\'tool\' '.
                      'AND `directory`=\''.$database->escapeString($toolDir).'\'';
        if(($toolName = $database->get_one($sql))) {
        // create admin-object and print header if FTAN is NOT supported AND function 'save' is requested
            $admin_header = !(is_file(WB_PATH.'/modules/'.$toolDir.'/FTAN_SUPPORTED') && $doSave);
            $admin = new admin('admintools', 'admintools', $admin_header );
            if(!$doSave) {
            // show title if not function 'save' is requested
                print '<h4><a href="'.ADMIN_URL.'/admintools/index.php" '.
                      'title="'.$HEADING['ADMINISTRATION_TOOLS'].'">'.
                      $HEADING['ADMINISTRATION_TOOLS'].'</a>'.
                      '&nbsp;&raquo;&nbsp;'.$toolName.'</h4>'."\n";
            }
            // include modules tool.php
            require(WB_PATH.'/modules/'.$toolDir.'/tool.php');
            $admin->print_footer();
        }else {
        // no installed module found, jump to index.php of admintools
            header('location: '.ADMIN_URL.'/admintools/index.php');
            exit(0);
        }
    }else {
    // invalid module name requested, jump to index.php of admintools
        header('location: '.ADMIN_URL.'/admintools/index.php');
        exit(0);
    }
