Location: PHPKode > projects > cPassMan > cpassman_1.55/load.php
<?php
####################################################################################################
## File : load.php
## Author : Nils Laumaillé
## Description : Loads things depending on the pages. It is called by index.php page.
## 
## DON'T CHANGE !!!
## 
####################################################################################################

//Common elements
$html_headers = '
        <link rel="stylesheet" href="includes/css/passman.css" type="text/css" />
        <script type="text/javascript" src="includes/js/functions.js"></script> 

        <script type="text/javascript" src="includes/jquery-ui/js/jquery-'.$k['jquery-version'].'.min.js"></script>
        <script type="text/javascript" src="includes/jquery-ui/js/jquery-ui-'.$k['jquery-ui-version'].'.custom.min.js"></script>
        <link rel="stylesheet" href="includes/jquery-ui/css/'.$k['jquery-ui-theme'].'/jquery-ui-'.$k['jquery-ui-version'].'.custom.css" type="text/css" /> 

        <script language="JavaScript" type="text/javascript" src="includes/js/jquery.tooltip.js"></script>
        <link rel="stylesheet" href="includes/css/jquery.tooltip.css" type="text/css" />

        <script language="JavaScript" type="text/javascript" src="includes/js/pwd_strength.js"></script>';




//For ITEMS page, load specific CSS files for treeview
if ( isset($_GET['page']) && $_GET['page'] == "items")
    $html_headers .= '
        <link rel="stylesheet" type="text/css" href="includes/css/jquery.treeview.css" />
        <link rel="stylesheet" type="text/css" href="includes/css/items.css" />
        
        <script type="text/javascript" src="includes/js/jquery.cookie.pack.js"></script>
        <script type="text/javascript" src="includes/js/jquery.treeview.pack.js"></script>
        
        <script type="text/javascript" src="includes/js/jquery.search.js"></script>
        <script type="text/javascript" src="includes/zeroclipboard/ZeroClipboard.js"></script>
        
        <link rel="stylesheet" type="text/css" href="includes/css/jquery.autocomplete.css" />
        <script type="text/javascript" src="includes/js/jquery.bgiframe.min.js"></script>
        <script type="text/javascript" src="includes/js/jquery.autocomplete.pack.js"></script>
        
        <link rel="stylesheet" type="text/css" href="includes/libraries/uploadify/uploadify.css" />
        <script type="text/javascript" src="includes/libraries/uploadify/jquery.uploadify.v2.1.0.min.js"></script>
        <script type="text/javascript" src="includes/libraries/uploadify/swfobject.js"></script>
        
        <script type="text/javascript" src="includes/js/jquery.autoResizable.min.js"></script>
        
        <link rel="stylesheet" type="text/css" href="includes/libraries/jwysiwyg/jquery.wysiwyg.css" />
        <link rel="stylesheet" type="text/css" href="includes/libraries/jwysiwyg/jquery.wysiwyg.modal.css" />
        <script type="text/javascript" src="includes/libraries/jwysiwyg/jquery.wysiwyg.min.js"></script>';

else
if ( isset($_GET['page']) && $_GET['page'] == "manage_settings")
    $html_headers .= '
        <link rel="stylesheet" type="text/css" href="includes/libraries/uploadify/uploadify.css" />
        <script type="text/javascript" src="includes/libraries/uploadify/jquery.uploadify.v2.1.0.min.js"></script>
        <script type="text/javascript" src="includes/libraries/uploadify/swfobject.js"></script>';

else
if ( isset($_GET['page']) && $_GET['page'] == "find")
    $html_headers .= '
        <link rel="stylesheet" type="text/css" href="includes/libraries/datatable/jquery.dataTables.css" />
        <link rel="stylesheet" type="text/css" href="includes/libraries/datatable/jquery.dataTablesUI.css" />
        <script type="text/javascript" src="includes/libraries/datatable/jquery.dataTables.min.js"></script>';

else
if ( !isset($_GET['page']) )
    $html_headers .= '
        <link rel="stylesheet" type="text/css" href="includes/libraries/uploadify/uploadify.css" />
        <script type="text/javascript" src="includes/libraries/uploadify/jquery.uploadify.v2.1.0.min.js"></script>
        <script type="text/javascript" src="includes/libraries/uploadify/swfobject.js"></script>';
            

//Get Favicon
$html_headers .= isset($_SESSION['settings']['favicon']) ? '
        <link rel="icon" href="'. $_SESSION['settings']['favicon'] . '" type="image/vnd.microsoft.ico" />' : '';

$html_headers .= '
<script type="text/javascript">
<!-- // --><![CDATA[
    //deconnexion
    function MenuAction(val){
        if ( val == "deconnexion" ) {
            document.getElementById("menu_action").value = val;
            document.main_form.submit();
        }
        else {
            if ( val == "") document.location.href="index.php";
            else document.location.href="index.php?page="+val;
        }                
    }
    
    //Identifier l"utilisateur
    function identifyUser(redirect){
        if ( redirect == undefined ) redirect = ""; //Check if redirection
        if ( document.getElementById("login").value != "" && document.getElementById("pw").value != "" ){
            document.getElementById("erreur_connexion").innerHTML = "";
            document.getElementById("ajax_loader_connexion").style.display = "";
            var data = "type=identify_user"+
                        "&login="+escape(document.getElementById("login").value)+
                        "&pw="+escape(document.getElementById("pw").value)+
                        "&duree_session="+document.getElementById("duree_session").value+
                        "&hauteur_ecran="+window.innerHeight;
            httpRequest("sources/main.queries.php",data,redirect);
        }else{
            alert("'.$txt['error_no_password'].'");   
        }
    }
    
    function ouvrir_div(div){
        $("#"+div).slideToggle("slow");
    }
    
    function OpenDialogBox(id){
        $("#"+id).dialog("open");
    }
    
    $(function() {
        //TOOLTIPS
        $("#main *, #footer *, #icon_last_items *, #top *, button, .tip").tooltip({
            delay: 0,
            showURL: false
        });
    
        //Display Tabs
        $("#item_edit_tabs, #item_tabs").tabs();
        
        //BUTTON
        $("#but_identify_user").hover(
            function(){ 
                $(this).addClass("ui-state-hover"); 
            },
            function(){ 
                $(this).removeClass("ui-state-hover"); 
            }
        ).mousedown(function(){
            $(this).addClass("ui-state-active"); 
        })
        .mouseup(function(){
                $(this).removeClass("ui-state-active");
        });
        
        //END SESSION DIALOG BOX
        $("#div_fin_session").dialog({
            bgiframe: true,
            modal: true,
            autoOpen: false,
            width: 400,
            height: 150,
            title: "'.$txt['index_alarm'].'",
            buttons: {
                "'.$txt['index_add_one_hour'].'": function() {
                    AugmenterSession();
                    document.getElementById("div_fin_session").style.display="none";
                    document.getElementById("countdown").style.color="black";
                    $(this).dialog("close");
                }
            }
        });
        
        //WARNING FOR QUERY ERROR
        $("#div_mysql_error").dialog({
            bgiframe: true,
            modal: true,
            autoOpen: false,
            width: 700,
            height: 150,
            title: "'.$txt['error_mysql'].'",
            buttons: {
                "'.$txt['ok'].'": function() {
                    $(this).dialog("close");
                }
            }
        });
        
        //PREPARE MAIN MENU
        $("#main_menu button, #personal_menu_actions button").button();
        
        //PREPARE LANGUGAGE DROPDOWN
            $(".dropdown dt").click(function() {
                $(".dropdown dd ul").toggle();
            });
                        
            $(".dropdown dd ul li a").click(function() {
                var text = $(this).html();
                $(".dropdown dt a span").html(text);
                $(".dropdown dd ul").hide();
                $("#result").html("Selected value is: " + getSelectedValue("sample"));
            });
                        
            function getSelectedValue(id) {
                return $("#" + id).find("dt a span.value").html();
            }

            $(document).bind("click", function(e) {
                var $clicked = $(e.target);
                if (! $clicked.parents().hasClass("dropdown"))
                    $(".dropdown dd ul").hide();
            });
        //END
    });';
    
if ( !isset($_GET['page']) ){
    $html_headers .= '
    $(function() {
        //build nice buttonset
        $("#radio_import_type").buttonset();
        
        //Clear text when clicking on buttonset
        $(".import_radio").click(function() {
            $("#import_status").html("");
        });

        // DIALOG BOX FOR CHANGING PASSWORD
        $("#div_changer_mdp").dialog({
            bgiframe: true,
            modal: true,
            autoOpen: false,
            width: 300,
            height: 190,
            title: "'.$txt['index_change_pw'].'",
            buttons: {
                "'.$txt['index_change_pw_button'].'": function() {
                    ChangerMdp("'. (isset($_SESSION['last_pw']) ? $_SESSION['last_pw'] : ''). '");
                },
                "'.$txt['cancel_button'].'": function() {
                    $(this).dialog("close");
                }
            }
        });
        
        // DIALOG BOX FOR ASKING PASSWORD
        $("#div_forgot_pw").dialog({
            bgiframe: true,
            modal: true,
            autoOpen: false,
            width: 300,
            height: 190,
            title: "'.$txt['forgot_my_pw'].'",
            buttons: {
                "'.$txt['send'].'": function() {
                    var data = "type=send_pw_by_email&email="+document.getElementById("forgot_pw_email").value;
                    httpRequest("sources/main.queries.php",data);
                },
                "'.$txt['cancel_button'].'": function() {
                    $("#forgot_pw_email").val("");
                    $(this).dialog("close");
                }
            }
        });
        
        // DIALOG BOX FOR CSV IMPORT
        $("#div_import_from_csv").dialog({
            bgiframe: true,
            modal: true,
            autoOpen: false,
            width: 600,
            height: 500,
            title: "'.$txt['import_csv_menu_title'].'",
            buttons: {
                "'.$txt['import_button'].'": function() {
                    if ( $(\'#radio1\').attr(\'checked\') ) ImportItemsFromCSV();
                    else $(this).dialog("close");
                },
                "'.$txt['cancel_button'].'": function() {
                    $("#import_status").html("");
                    $(this).dialog("close");
                }
            }
        });
        
        //CALL TO UPLOADIFY FOR CSV IMPORT
        $("#fileInput_csv").uploadify({
            "uploader"  : "includes/libraries/uploadify/uploadify.swf",
            "scriptData": {"type_upload":"import_items_from_file"},
            "script"    : "includes/libraries/uploadify/uploadify.php",
            "cancelImg" : "includes/libraries/uploadify/cancel.png",
            "auto"      : true,
            "folder"    : "files",
            "fileDesc"  : "csv",
            "fileExt"   : "*.csv",
            "onComplete": function(event, queueID, fileObj, reponse, data){$("#import_status_ajax_loader").show();ImportCSV(fileObj.name);},
            "buttonText": \''.$txt['csv_import_button_text'].'\'
        });
        
        //CALL TO UPLOADIFY FOR KEEPASS IMPORT
        $("#fileInput_keepass").uploadify({
            "uploader"  : "includes/libraries/uploadify/uploadify.swf",
            "scriptData": {"type_upload":"import_items_from_file"},
            "script"    : "includes/libraries/uploadify/uploadify.php",
            "cancelImg" : "includes/libraries/uploadify/cancel.png",
            "auto"      : true,
            "folder"    : "files",
            "fileDesc"  : "xml",
            "fileExt"   : "*.xml",
            "onComplete": function(event, queueID, fileObj, reponse, data){$("#import_status_ajax_loader").show();ImportKEEPASS(fileObj.name);},
            "buttonText": \''.$txt['keepass_import_button_text'].'\'
        });
    })
    
    //Change the Users password when he asks for
    function ChangerMdp(old_pw){
        if ( document.getElementById("new_pw").value != "" && document.getElementById("new_pw").value == document.getElementById("new_pw2").value ){            
            var data = "type=change_pw&new_pw="+escape(document.getElementById("new_pw").value)+"&old_pw="+old_pw;
            httpRequest("sources/main.queries.php",data);
        }else{
            $("#change_pwd_error").addClass("ui-state-error ui-corner-all");
            document.getElementById("change_pwd_error").innerHTML = "'.$txt['index_pw_error_identical'].'";
        }
    }
    
    //Permits to upload passwords from KEEPASS file
    function ImportKEEPASS(file){
        //check if file has good format
        var data = "type=import_file_format_keepass&file="+file+"&destination="+$("#import_keepass_items_to").val();
        httpRequest("sources/import.queries.php",data);
    }
    
    //Permits to upload passwords from CSV file
    function ImportCSV(file){
        //check if file has good format
        var data = "type=import_file_format_csv&file="+file;
        httpRequest("sources/import.queries.php",data);
    }
    
    //get list of items checked by user
    function ImportItemsFromCSV(){
        var items = "";
        
        //Get data checked
        $("input[type=checkbox]:checked").each(function() {
            var elem = $(this).attr("id").split("-");
            if ( items == "") items = $("#item_to_import_values-"+elem[1]).val();
            else items = items + "@_#sep#_@" + $("#item_to_import_values-"+elem[1]).val();
            
        });
        
        //Lauchn ajax query that will insert items into DB
        var data = "type=import_items&folder="+document.getElementById("import_items_to").value+"&data="+escape(items);
        httpRequest("sources/import.queries.php",data);
    }
        
    //Toggle details importation
    function toggle_importing_details() {
        $("#div_importing_kp_details").toggle();
    }';
}

//JAVASCRIPT FOR ITEMS PAGE
if ( isset($_GET['page']) && $_GET['page'] == "items"){
    $html_headers .= '   
    //Launch the copy in clipboard script
    ZeroClipboard.setMoviePath( "'.$_SESSION['settings']['cpassman_url'].'/includes/zeroclipboard/ZeroClipboard.swf");';
}

else
//JAVASCRIPT FOR FIND PAGE
if ( isset($_GET['page']) && $_GET['page'] == "find"){
    $html_headers .= '
    $(function() {
        //Launch the datatables pluggin
        $("#t_items").dataTable({
            "aaSorting": [[ 1, "asc" ]],
            "sPaginationType": "full_numbers",
            "bProcessing": true,
            "bServerSide": true,
            "sAjaxSource": "sources/find.queries.php",
            "bJQueryUI": true,
            "oLanguage": {
                "sUrl": "includes/language/dataTables.'.$_SESSION['user_language'].'.txt"
            }
        });
    });';
}

else
//JAVASCRIPT FOR ADMIN PAGE
if ( isset($_GET['page']) && $_GET['page'] == "administration" ){
    $html_headers .= '
            //Function loads informations from cpassman FTP
            function LoadCPMInfo(){
                var data = "type=cpm_status";
                httpRequest("sources/admin.queries.php",data);
            }
            //Load function on page load
            $(function() {
                LoadCPMInfo();
            });';
        
}

else
//JAVASCRIPT FOR FAVOURITES PAGE
if ( isset($_GET['page']) && $_GET['page'] == "favourites" ){
    $html_headers .= '
    $(function() {
        // DIALOG BOX FOR DELETING FAVOURITE
        $("#div_delete_fav").dialog({
            bgiframe: true,
            modal: true,
            autoOpen: false,
            width: 300,
            height: 60,
            title: "'.$txt['item_menu_del_from_fav'].'",
            buttons: {
                "'.$txt['index_change_pw_confirmation'].'": function() {
                    var data = "type=del_fav"+
                                "&id="+document.getElementById(\'detele_fav_id\').value;
                    httpRequest("sources/favourites.queries.php",data);
                },
                "'.$txt['cancel_button'].'": function() {
                    $(this).dialog("close");
                }
            }
        });
    })
    
    function prepare_delete_fav(id){
        document.getElementById("detele_fav_id").value = id;
        OpenDialogBox(\'div_delete_fav\');
    }';
}

else
//JAVASCRIPT FOR ADMIN_SETTIGNS PAGE
if ( isset($_GET['page']) && $_GET['page'] == "manage_settings" ){
    $html_headers .= '
    $(function() {
        //CALL TO UPLOADIFY FOR RESTORE SQL FILE
        $("#fileInput_restore_sql").uploadify({
            "uploader"  : "includes/libraries/uploadify/uploadify.swf",
            "script"    : "includes/libraries/uploadify/uploadify.php",
            "cancelImg" : "includes/libraries/uploadify/cancel.png",
            "auto"      : true,
            "folder"    : "files",
            "fileDesc"  : "sql",
            "fileExt"   : "*.sql",
            "height"   : "18px",
            "width"   : "18px",
            "wmode"     : "transparent",
            "buttonImg" : "includes/images/inbox--plus.png",
            "onComplete": function(event, queueID, fileObj, reponse, data){
                var key = prompt("'.$txt['admin_action_db_restore_key'].'","'.$txt['encrypt_key'].'");
                if ( key != "" ) LaunchAdminActions("admin_action_db_restore",fileObj.name+"&key="+key);
            }
        });
    });
    
    //###########
    //## FUNCTION : Launch the action the admin wants
    //###########
    function LaunchAdminActions(action,option){
        LoadingPage();
        if ( action == "admin_action_db_backup" ) option = $("#result_admin_action_db_backup_key").val();
        var data = "type="+action+"&option="+option;
        httpRequest("sources/admin.queries.php",data);
    }
    ';    
}

$html_headers .= '
// ]]>
</script>';
?>
Return current item: cPassMan