<?php
/* * ****************************************************************************
 *
 * Purpose: p.mapper application main entry file 
 * Author:  Armin Burger
 *
 * *****************************************************************************
 *
 * Copyright (c) 2003-2009 Armin Burger
 *
 * This file is part of p.mapper.
 *
 * p.mapper 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 2 of the License, or
 * (at your option) any later version. See the COPYING file.
 *
 * p.mapper 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 p.mapper; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * **************************************************************************** */
// prevent XSS
if (isset($_REQUEST['PM_INCPHP']))
    exit();

require_once("incphp/pmsession.php");

// INCLUDE PHP FILES
require_once("config/__startup_config.php");
require_once("incphp/group.php");
$_SESSION['mapObjModifierFirstInclude'] = true;
require_once("incphp/globals.php");
$_SESSION['mapObjModifierFirstInclude'] = false;
require_once("incphp/common.php");
require_once("incphp/init/initmap.php");
require_once("incphp/legend.php");
include_once("incphp/init/init.php");
include_once("incphp/uielement.php");

header("Content-type: text/html; charset=$defCharset");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" lang="<?php echo $gLanguage ?>" xml:lang="<?php echo $gLanguage ?>">

    <head>
        <meta http-equiv="Content-Script-Type" content="text/javascript" />
        <meta name="description" content="p.mapper - MapServer PHP/MapScript Framework" />
        <meta name="author" content="Armin Burger" />
        <meta name="keywords" content="p.mapper, pmapper, MapServer, PHP, MapScript" />

        <title><?php echo $_SESSION['pmTitle'] ?></title>

        <?php
        // Load all JS files from 'javascript' and 'config' directory
        echo $jsReference;

        echo $jsConfigReference;

        // Reference all global JS variables
        include("incphp/js/js_init.php");
        ?>

        <script type="text/javascript" src="javascript/facebox/facebox.js"></script>
        <script type="text/javascript" src="javascript/jquery.interface.js"></script>
        <link rel="stylesheet" href="javascript/facebox/facebox.css" type="text/css" />

        <link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon" />
        <link rel="stylesheet" href="templates/default.css" type="text/css" />
        <link rel="stylesheet" href="templates/layout.css" type="text/css" />
        <link rel="stylesheet" href="templates/jquery.treeview.css" type="text/css" />
        <link rel="stylesheet" href="templates/toc.css" type="text/css" />
        <link rel="stylesheet" href="templates/query.css" type="text/css" />
        <link rel="stylesheet" href="templates/dialog.css" type="text/css" />
        <link rel="stylesheet" href="templates/jquery.layout.css" type="text/css" />
        <!--[if lt IE 7]> 
        <link rel="stylesheet" href="templates/ie6.css" type="text/css" />
        <![endif]--> 

        <style type="text/css">
            <!--
            .ui-layout-east {border: 1px solid #999999; background-color:#e9e9e9;}
            .ui-layout-center {border: 1px solid #999999;}
            .ui-layout-root {border: 1px solid #000000;}
            -->
        </style>


        <?php
// Load all CSS files from config directory
        echo $cssReference;
        ?>

        <script type="text/javascript">

            $.extend(PM.Layout,
            {
                /**
                 * Resize UI containers after root element resize
                 */
                resizeContainers: function() {
                    //var rootElem = $(window);
                    var rootElem = $('#uiLayoutRoot'); 
                    var rootH = rootElem.height();
                    var rootW = rootElem.width();
                    var northH = $('#uiLayoutNorth').outerHeight({margin:true, border:true});
                    var southH = $('#uiLayoutSouth').outerHeight({margin:true});
                    var mH = rootH - northH - southH;
            
                    $('#uiLayoutCenter').css({position:'absolute'})
                    .height(mH)
                    .width(rootW - $('#uiLayoutWest').outerWidth({margin:true}) - $('#uiLayoutEast').outerWidth({margin:true}) - 3)
                    .top(northH)
                    .left($('#uiLayoutWest').outerWidth({margin:true}));
                    $('#uiLayoutEast').height(mH).top(northH);
                    $('#toc, #toclegend').height(mH - $('#refmap').height() - $('#toc').itop() - 8).css({'overflow':'auto'});
                                
                    PM.Layout.resizeMapZone();
                }
        
            });
    
    
            /**
             * Settings for jquery.ui.layout
             * ======= ADAPT TO PAGE LAYOUT =======
             */
            $(document).ready(function () {
                var mrgH = 6;
                var mrgV = 6;
                $('#uiLayoutRoot').css({position:'absolute',  top:10, bottom:10, left:10, right:10});
                $('#uiLayoutWest').css({position:'absolute', width:0, 'margin-right':mrgH});
                $('#uiLayoutEast').css({position:'absolute', right:0, width:240, height:'100%', 'margin-left':mrgH, 'margin-right':mrgH, 'z-index':99});
                $('#uiLayoutNorth').css({position:'absolute', top:0, height:40, width:'100%', 'margin-bottom':mrgV});
                $('#uiLayoutSouth').css({position:'absolute', bottom:0, height:35, width:'100%', 'margin-top':mrgV+2});
        
                /** Some components to be added to UI */
                $('#uiLayoutCenter').pmToolBar(PM.buttonsDefault);  // ToolBar, REQUIRED
                $('#uiLayoutNorth').pmToolLinks(PM.linksDefault);   // Tool links
                $('#uiLayoutCenter').appendElement('div').addClass('map-top-bar');  // Top bar over map
        
                PM.Layout.resizeContainers();
                $(window).resize(function(){
                    PM.Layout.resizeContainers();
                });
            });

    
        </script>

    </head>

    <body>

        <!-- ======================= ADAPT START ======================== -->
        <div class="ui-layout-root" id="uiLayoutRoot" >

            <div class="ui-layout-north" id="uiLayoutNorth">
                <?php echo UiElement::pmHeader() ?>
            </div>

            <div class="ui-layout-west" id="uiLayoutWest">
                <div id="legend"></div>
            </div>

            <div class="ui-layout-south" id="uiLayoutSouth">
                <?php echo UiElement::displayCoordinates() ?>
                <?php echo UiElement::pmFooter() ?>
            </div>

            <div class="ui-layout-east" id="uiLayoutEast">
                <!-- Legend/TOC -->
                <?php echo UiElement::tocContainer($_SESSION['userAgent']) ?>

                <!-- Reference Map -->
                <?php echo UiElement::refMap($refH, $refW, $refImg, $refH, $refW) ?>
            </div>

            <div class="ui-layout-center" id="uiLayoutCenter">
                <!-- Map Zone -->
                <?php echo UiElement::mapZone() ?>

                <!-- Slider -->
                <?php echo UiElement::zoomSlider() ?>

                <!-- Search Container -->
                <?php echo UiElement::searchContainer("inline") ?>

                <!-- Scale -->
                <?php echo UiElement::scaleForm() ?>

            </div>

            <!-- ======================= ADAPT END ======================== -->
        </div>

        <div style="visibility:hidden"><img id="pmMapRefreshImg" src="images/pixel.gif" alt="" /></div>
        <div style="visibility:hidden"><img src="images/pixel.gif" alt="" /></div>

        <!-- MANDATORY form element for update events; DO NOT REMOVE! -->
        <?php echo UiElement::addUpdateEventForm() ?>


        <script type="text/javascript">
            // use jQuery for intitialization 
            $(document).ready(function() {
                PM.Init.main();
<?php echo $jsInitFunctions ?>
    });
    
    // Create drawing object for measure function
    jg = new jsGraphics('measureLayer');
    jg.setColor(PM.measureObjects.line.color); 
    jg.setStroke(PM.measureObjects.line.width);
    
    //#fede
    jg_tmp = new jsGraphics('measureLayerTmp');
    
        </script>

    </body>
</html>