<commit_before>/**
 * Licensed to The Apereo Foundation under one or more contributor license
 * agreements. See the NOTICE file distributed with this work for
 * additional information regarding copyright ownership.

 * The Apereo Foundation licenses this file to you under the Apache License,
 * Version 2.0 (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.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 *
 * template management, javascript for the management of the templates in the file area and their creation
 *
 * @author <NAME>
 * @version 1.0
 * @package
 */

if (typeof(String.prototype.trim) === "undefined") {
    String.prototype.trim = function() {
        return String(this).replace(/^\s+|\s+$/g, '');
    };
}
var active_div = "";

var edit_window_open = new Array();

/**
 *
 * Function url return
 * This function sorts out the URL depending on whether the htaccess if off or on
 * @param string url = the extra part of the url to make this URL from
 * @param string parameter - the template id
 * @version 1.0
 * @author <NAME>
 */

function url_return(url, parameter) {

    switch (url) {

        case "edit":
            if (site_apache == "true") {

                return url + "_" + parameter;

            } else {

                return url + ".php?template_id=" + parameter;

            }
        case "edithtml":
            if (site_apache == "true") {

                return url + "_" + parameter;

            } else {

                return url + ".php?template_id=" + parameter;

            }
            break;
        case "preview":
            if (site_apache == "true") {

                return url + "_" + parameter;

            } else {

                return url + ".php?template_id=" + parameter;

            }
            break;
        case "play":
            if (site_apache == "true") {

                return url + "_" + parameter;

            } else {

                return url + ".php?template_id=" + parameter;

            }
            break;
        case "properties":
            if (site_apache == "true") {

                return url + "_" + parameter;

            } else {

                return url + ".php?template_id=" + parameter;

            }
            break;
        case "folderproperties":
            if (site_apache == "true") {

                return url + "_" + parameter;

            } else {

                return url + ".php?template_id=" + parameter;

            }
            break;
        case "workspaceproperties":
            if (site_apache == "true") {

                return url;

            } else {

                return url + ".php"

            }
        case "publishproperties":
            if (site_apache == "true") {

                return url + "_" + parameter;

            } else {

                return url + ".php?template_id=" + parameter;

            }
            break;


        default:
            break;

    }
}


/*
 * Function template toggle
 * This function sorts out the display and hiding of the blank templates side of the screen
 * @param string tag = the div to display
 * @version 1.0
 * @author <NAME>
 */

function template_toggle(tag) {

    var temp = document.getElementById(tag);
    var butt = document.getElementById(tag + '_button');

    if ((temp.style.display == "none") || (temp.style.display == "")) {
        temp.style.display = "block";
        butt.style.display = "none";
        temp.querySelector('input[name="filename"]').value = "";
        temp.querySelector('input[name="filename"]').focus();


    } else {
        temp.style.display = "none";
        butt.style.display = "";
    }

}

// Function toggle (obsolete) ********** CHECK ***************
//
// open and close template areas when creating a new one


function toggle(tag) {

    if (document.getElementById(tag).style.display == "none") {
        document.getElementById(tag).style.display = "block";
    } else {
        document.getElementById(tag).style.display = "none";
    }

}

/**
 *
 * Function edit window
 * This function opens an edit window
 * @param string admin = is the user an administrator
 * @version 1.0
 * @author <NAME>
 */

function edit_window(admin, edit, location) {

    if (!admin) {

        var tree = $.jstree.reference("#workspace"),
            ids = tree.get_selected();
        if (ids.length == 0)
            return;

        for (var i = 0; i < ids.length; i++) {
            var node = workspace.nodes[ids[i]];
            if (node.xot_type == "file") {

                if (node.parent != workspace.recyclebin_id) {
                    window_id = "editwindow" + node.id;

                    window_open = false;

                    if (typeof(edit_window_open) != 'undefined') {

                        for (z = 0; z < edit_window_open.length; z++) {
                            if (("editwindow" + edit_window_open[z].id) == window_id) {
                                window_open = edit_window_open[z].window;
                            }
                        }
                    }
                    console.log("Window open length: " + window_open.length);
                    console.log("Window open parent: " + window_open.parent);
                    if (!window_open || window_open.parent == null) {

                        size = node.editor_size.split(",");

                        if (location != null) {
                            if (size.length == 1) {
                                var NewEditWindow = window.open(site_url + url_return(edit, node.xot_id), location);
                            } else {
                                var NewEditWindow = window.open(site_url + url_return(edit, node.xot_id), '_blank');
                            }
                        }
                        else {
                            if (size.length == 1) {
                                var NewEditWindow = window.open(site_url + url_return(edit, node.xot_id), "editwindow" + node.id, "toolbar=yes,location=yes");
                            } else {
                                var NewEditWindow = window.open(site_url + url_return(edit, node.xot_id), "editwindow" + node.id, "toolbar=yes,location=yes,resizable=yes");
                            }
                        }

                        try {

                            xmlHttp = new XMLHttpRequest();

                        } catch (e) { // Internet Explorer
                            try {
                                xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
                            } catch (e) {
                                try {
                                    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
                                } catch (e) {

                                }
                            }
                        }

                        NewEditWindow.ajax_handle = xmlHttp;
                        self.last_reference = self;

                        NewEditWindow.focus();

                        edit_window_open.push({
                            id: node.id,
                            window: NewEditWindow
                        });

                        return NewEditWindow;

                    } else {
                        window_open.focus();
                    }

                } else {

                    alert(RECYCLE_EDIT);

                }

            } else {

                alert(FOLDER_EDIT);

            }

        }

    } else {

        var NewEditWindow = window.open(site_url + url_return("edithtml", admin), "editwindow" + admin, "height=665, width=800");

        NewEditWindow.window_reference = self;

        NewEditWindow.focus();

    }

}

/**
 *
 * Function close edit window
 * This function sorts out the deletion of lock files
 * @param string path = the path to delete the lock file, or an ID number
 * @version 1.0
 * @author <NAME>
 */

function close_edit_window(path) {

    /*
     * if the path variable contains a hyphen, then it is the path to delete a file
     */

    /*
     * use the for loop to check for its place in the array then delete it
     */
    for (x = 0; x < edit_window_open.length; x++) {

        if (path.indexOf("-") != -1) {
            if (edit_window_open[x].id.substr(5, edit_window_open[x].id.length - 5) == path.substr(0, path.indexOf("-"))) {

                edit_window_open.splice(x, 1);

            }

        } else {

            if (edit_window_open[x].id.substr(5, edit_window_open[x].id.length - 5) == path) {

                edit_window_open.splice(x, 1);

            }

        }

    }

}

/**
 *
 * Function file_version_sync
 * This function opens a window to display an example template
 * @version 1.0
 * @author <NAME>
 */

function file_version_sync(response) {
    response = response.trim();
    if (response != "") {
        alert(response);
    }
    refresh_workspace();
}

/**
 *
 * Function example state changed
 * This function opens a window to display an example template
 * @version 1.0
 * @author <NAME>
 */

function file_need_save(response) {
    result = response.split("~*~");

    if (response != "") {

        var response = confirm(result[0]);

        if (response) {
            $.ajax({
                type: "POST",
                url: "wwebsite_code/php/versioncontrol/update_file.php",
                data: {
                    file_path: result[1],
                    template_id: result[2]
                }
            })
            .done(function (response) {
                file_version_sync(response);
            });
        }


    }
}

/**
 *
 * Function edit window close
 * This function is empty to handle the response from the lock file deletion (which generates no response)
 * @version 1.0
 * @author <NAME>
 */

function edit_window_close(path) {

    for (x = 0; x < edit_window_open.length; x++) {

        if (path.indexOf("-") != -1) {

            if (edit_window_open[x].id.substr(edit_window_open[x].id.lastIndexOf("_") + 1, edit_window_open[x].id.length) == path.substr(0, path.indexOf("-"))) {
                //if(edit_window_open[x].substr(5,edit_window_open[x].length-5)==path.substr(0,path.indexOf("-"))){
                edit_window_open.splice(x, 1);
            }

        } else {
            if (edit_window_open[x].id.substr(5, edit_window_open[x].id.length - 5) == path) {
                edit_window_open.splice(x, 1);
            }

        }

    }
    $.ajax({
        type: "POST",
        url: "website_code/php/versioncontrol/template_close.php",
        data: {
            file_path: path
        }
    })
    .done(function (response) {
        file_need_save(response);
    });
}

/**
 *
 * Function example window
 * This function requests the screen size for an example template
 * @param string examole_id = the id of the example
 * @version 1.0
 * @author <NAME>
 */

function example_window(example_id) {

    if (example_id != 0) {

        $.ajax({
            type: "POST",
            url: "website_code/php/properties/screen_size_template.php",
            data: {
                tutorial_id: example_id
            }
        })
        .done(function (response) {
            example_stateChanged(response);
        });

    } else {

        alert(NO_EXAMPLE);

    }

}

/**
 *
 * Function preview window
 * This function opens a window to display a preview of a template
 * @param string admin = whether the user is an admin
 * @version 1.0
 * @author <NAME>
 */

function preview_window(admin) {

    if (!admin) {

        if (setup_ajax() != false) {
            var tree = $.jstree.reference("#workspace"),
                ids = tree.get_selected();
            if (ids.length == 0)
                return;

            for (var i = 0; i < ids.length; i++) {
                var node = workspace.nodes[ids[i]];

                if (node.xot_type == "file") {
                    var mode = (window.event && window.event.shiftKey ? 'play' : 'preview');
                    size = node.preview_size.split(",");
                    if (size.length != 1) {


                        var PreviewWindow = window.open(site_url + url_return(mode, node.xot_id), "previewwindow" + node.id, "height=" + size[1] +
                            ", width=" + size[0] + ", scrollbars=yes,resizable=yes");

                    } else {


                        var PreviewWindow = window.open(site_url + url_return(mode, node.xot_id), "previewwindow" + node.id,
                            "height=768,width=1024,scrollbars=yes,resizable=yes");

                    }

                } else {

                    alert(PROJECT_SELECT);

                }

            }

        }

    } else {

        var PreviewWindow = window.open(site_url + url_return("preview", admin), "previewwindow" + admin, "scrollbars=yes");

    }

}


/**
 *
 * Function example state changed
 * This function opens a window to display an example template
 * @version 1.0
 * @author <NAME>
 */

function example_stateChanged(response) {
    if (response != "") {

        temp = response.toString().split("~");

        parameter = "height=" + temp[1] + ",width=" + temp[0] + ",status=No";

        var property_id = temp[2];

        var NewWindow = window.open(site_url + url_return("play", property_id), "examplewindow" + property_id, parameter);

        NewWindow.focus();
    }
}

/**
 *
 * Function properties window
 * This function opens a properties window
 * @param string admin - is the user an admin
 * @version 1.0
 * @author <NAME>
 */

function publishproperties_window(admin) {
    var tree = $.jstree.reference("#workspace"),
        ids = tree.get_selected();
    if (ids.length == 1) {
        var node = workspace.nodes[ids[0]];

        if (node.xot_type == "file") {
            var NewWindow = window.open(site_url + url_return("publishproperties", node.xot_id), node.xot_id, "height=600, width=635");
            NewWindow.window_reference = self;
            NewWindow.focus();
        }
    }
}

/**
 *
 * Function properties window
 * This function opens a properties window
 * @param string admin - is the user an admin
 * @version 1.0
 * @author <NAME>
 */

function properties_window(admin) {
    if (!admin) {
        var tree = $.jstree.reference("#workspace"),
            ids = tree.get_selected();
        if (ids.length == 0)
            return;

        if (workspace.nodes[ids[0]].type == "workspace") {
            var NewWindow = window.open(site_url + url_return("workspaceproperties", null), "workspace", "height=760, width=1000");
            NewWindow.window_reference = self;
            NewWindow.focus();
        } else {
            for (var i = 0; i < ids.length; i++) {
                if (workspace.nodes[ids[i]].type != "folder") {
                    if (workspace.nodes[ids[i]].parent != workspace.recyclebin_id) {
                        var NewWindow = window.open(site_url + url_return("properties", workspace.nodes[ids[i]].xot_id), workspace.nodes[ids[i]].xot_id,
                            "height=760, width=1000");
                        NewWindow.window_reference = self;
                        NewWindow.focus();
                    } else {
                        alert(RECYCLE_PROPERTIES);
                    }
                } else {
                    var NewWindow = window.open(site_url + url_return("folderproperties", workspace.nodes[ids[i]].xot_id + "_folder"), workspace.nodes[ids[i]].xot_id +
                        "_folder", "height=760, width=1000");
                    NewWindow.window_reference = self;
                    NewWindow.focus();
                }
            }
        }
    } else {
        var NewWindow = window.open(site_url + url_return("properties", admin), admin, "height=760, width=1000");

        NewWindow.window_reference = self;
        NewWindow.focus();
    }
}

/**
 *
 * Function selection changed
 * This function redisplays the file area sorted accordingly
 * @version 1.0
 * @author <NAME>
 */


function refresh_workspace() {
    // if (setup_ajax() != false) {
    //     var url = "website_code/php/templates/get_templates_sorted.php";
    //
    //     xmlHttp.open("post", url, true);
    //     xmlHttp.onreadystatechange = refreshworkspace_stateChanged;
    //     xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    //     xmlHttp.send('sort_type=' + document.sorting.type.value);
    // }
    $.ajax({
        type: "POST",
        url: "website_code/php/templates/get_templates_sorted.php",
        data: {
            sort_type: document.sorting.type.value
        }
    })
    .done(function(response){
        workspace = response;
        init_workspace();
    });
}

function getProjectInformation(user_id, template_id) {
    // if (setup_ajax() != false) {
    //     var url = "website_code/php/templates/get_template_info.php";
    //
    //     xmlHttp.open("post", url, true);
    //     xmlHttp.onreadystatechange = getProjectInformation_stateChanged;
    //     xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    //     xmlHttp.send('user_id=' + user_id + '&template_id=' + template_id);
    // }
    $.ajax({
        type: "POST",
        url: "website_code/php/templates/get_template_info.php",
        data: {user_id: user_id, template_id: template_id},
    })
    .done(function(info) {
        document.getElementById('project_information').innerHTML = info.properties;
        if (info.role == 'read-only') {
            // disable edit button.
            var editbtn = document.getElementById("edit");
            var propertiesbtn = document.getElementById("properties");
            var deletebtn = document.getElementById("delete");<commit_msg>Explicitly expect a json structure<commit_after>/**
 * Licensed to The Apereo Foundation under one or more contributor license
 * agreements. See the NOTICE file distributed with this work for
 * additional information regarding copyright ownership.

 * The Apereo Foundation licenses this file to you under the Apache License,
 * Version 2.0 (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.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 *
 * template management, javascript for the management of the templates in the file area and their creation
 *
 * @author <NAME>
 * @version 1.0
 * @package
 */

if (typeof(String.prototype.trim) === "undefined") {
    String.prototype.trim = function() {
        return String(this).replace(/^\s+|\s+$/g, '');
    };
}
var active_div = "";

var edit_window_open = new Array();

/**
 *
 * Function url return
 * This function sorts out the URL depending on whether the htaccess if off or on
 * @param string url = the extra part of the url to make this URL from
 * @param string parameter - the template id
 * @version 1.0
 * @author <NAME>
 */

function url_return(url, parameter) {

    switch (url) {

        case "edit":
            if (site_apache == "true") {

                return url + "_" + parameter;

            } else {

                return url + ".php?template_id=" + parameter;

            }
        case "edithtml":
            if (site_apache == "true") {

                return url + "_" + parameter;

            } else {

                return url + ".php?template_id=" + parameter;

            }
            break;
        case "preview":
            if (site_apache == "true") {

                return url + "_" + parameter;

            } else {

                return url + ".php?template_id=" + parameter;

            }
            break;
        case "play":
            if (site_apache == "true") {

                return url + "_" + parameter;

            } else {

                return url + ".php?template_id=" + parameter;

            }
            break;
        case "properties":
            if (site_apache == "true") {

                return url + "_" + parameter;

            } else {

                return url + ".php?template_id=" + parameter;

            }
            break;
        case "folderproperties":
            if (site_apache == "true") {

                return url + "_" + parameter;

            } else {

                return url + ".php?template_id=" + parameter;

            }
            break;
        case "workspaceproperties":
            if (site_apache == "true") {

                return url;

            } else {

                return url + ".php"

            }
        case "publishproperties":
            if (site_apache == "true") {

                return url + "_" + parameter;

            } else {

                return url + ".php?template_id=" + parameter;

            }
            break;


        default:
            break;

    }
}


/*
 * Function template toggle
 * This function sorts out the display and hiding of the blank templates side of the screen
 * @param string tag = the div to display
 * @version 1.0
 * @author <NAME>
 */

function template_toggle(tag) {

    var temp = document.getElementById(tag);
    var butt = document.getElementById(tag + '_button');

    if ((temp.style.display == "none") || (temp.style.display == "")) {
        temp.style.display = "block";
        butt.style.display = "none";
        temp.querySelector('input[name="filename"]').value = "";
        temp.querySelector('input[name="filename"]').focus();


    } else {
        temp.style.display = "none";
        butt.style.display = "";
    }

}

// Function toggle (obsolete) ********** CHECK ***************
//
// open and close template areas when creating a new one


function toggle(tag) {

    if (document.getElementById(tag).style.display == "none") {
        document.getElementById(tag).style.display = "block";
    } else {
        document.getElementById(tag).style.display = "none";
    }

}

/**
 *
 * Function edit window
 * This function opens an edit window
 * @param string admin = is the user an administrator
 * @version 1.0
 * @author <NAME>
 */

function edit_window(admin, edit, location) {

    if (!admin) {

        var tree = $.jstree.reference("#workspace"),
            ids = tree.get_selected();
        if (ids.length == 0)
            return;

        for (var i = 0; i < ids.length; i++) {
            var node = workspace.nodes[ids[i]];
            if (node.xot_type == "file") {

                if (node.parent != workspace.recyclebin_id) {
                    window_id = "editwindow" + node.id;

                    window_open = false;

                    if (typeof(edit_window_open) != 'undefined') {

                        for (z = 0; z < edit_window_open.length; z++) {
                            if (("editwindow" + edit_window_open[z].id) == window_id) {
                                window_open = edit_window_open[z].window;
                            }
                        }
                    }
                    console.log("Window open length: " + window_open.length);
                    console.log("Window open parent: " + window_open.parent);
                    if (!window_open || window_open.parent == null) {

                        size = node.editor_size.split(",");

                        if (location != null) {
                            if (size.length == 1) {
                                var NewEditWindow = window.open(site_url + url_return(edit, node.xot_id), location);
                            } else {
                                var NewEditWindow = window.open(site_url + url_return(edit, node.xot_id), '_blank');
                            }
                        }
                        else {
                            if (size.length == 1) {
                                var NewEditWindow = window.open(site_url + url_return(edit, node.xot_id), "editwindow" + node.id, "toolbar=yes,location=yes");
                            } else {
                                var NewEditWindow = window.open(site_url + url_return(edit, node.xot_id), "editwindow" + node.id, "toolbar=yes,location=yes,resizable=yes");
                            }
                        }

                        try {

                            xmlHttp = new XMLHttpRequest();

                        } catch (e) { // Internet Explorer
                            try {
                                xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
                            } catch (e) {
                                try {
                                    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
                                } catch (e) {

                                }
                            }
                        }

                        NewEditWindow.ajax_handle = xmlHttp;
                        self.last_reference = self;

                        NewEditWindow.focus();

                        edit_window_open.push({
                            id: node.id,
                            window: NewEditWindow
                        });

                        return NewEditWindow;

                    } else {
                        window_open.focus();
                    }

                } else {

                    alert(RECYCLE_EDIT);

                }

            } else {

                alert(FOLDER_EDIT);

            }

        }

    } else {

        var NewEditWindow = window.open(site_url + url_return("edithtml", admin), "editwindow" + admin, "height=665, width=800");

        NewEditWindow.window_reference = self;

        NewEditWindow.focus();

    }

}

/**
 *
 * Function close edit window
 * This function sorts out the deletion of lock files
 * @param string path = the path to delete the lock file, or an ID number
 * @version 1.0
 * @author <NAME>
 */

function close_edit_window(path) {

    /*
     * if the path variable contains a hyphen, then it is the path to delete a file
     */

    /*
     * use the for loop to check for its place in the array then delete it
     */
    for (x = 0; x < edit_window_open.length; x++) {

        if (path.indexOf("-") != -1) {
            if (edit_window_open[x].id.substr(5, edit_window_open[x].id.length - 5) == path.substr(0, path.indexOf("-"))) {

                edit_window_open.splice(x, 1);

            }

        } else {

            if (edit_window_open[x].id.substr(5, edit_window_open[x].id.length - 5) == path) {

                edit_window_open.splice(x, 1);

            }

        }

    }

}

/**
 *
 * Function file_version_sync
 * This function opens a window to display an example template
 * @version 1.0
 * @author <NAME>
 */

function file_version_sync(response) {
    response = response.trim();
    if (response != "") {
        alert(response);
    }
    refresh_workspace();
}

/**
 *
 * Function example state changed
 * This function opens a window to display an example template
 * @version 1.0
 * @author <NAME>
 */

function file_need_save(response) {
    result = response.split("~*~");

    if (response != "") {

        var response = confirm(result[0]);

        if (response) {
            $.ajax({
                type: "POST",
                url: "wwebsite_code/php/versioncontrol/update_file.php",
                data: {
                    file_path: result[1],
                    template_id: result[2]
                }
            })
            .done(function (response) {
                file_version_sync(response);
            });
        }


    }
}

/**
 *
 * Function edit window close
 * This function is empty to handle the response from the lock file deletion (which generates no response)
 * @version 1.0
 * @author <NAME>
 */

function edit_window_close(path) {

    for (x = 0; x < edit_window_open.length; x++) {

        if (path.indexOf("-") != -1) {

            if (edit_window_open[x].id.substr(edit_window_open[x].id.lastIndexOf("_") + 1, edit_window_open[x].id.length) == path.substr(0, path.indexOf("-"))) {
                //if(edit_window_open[x].substr(5,edit_window_open[x].length-5)==path.substr(0,path.indexOf("-"))){
                edit_window_open.splice(x, 1);
            }

        } else {
            if (edit_window_open[x].id.substr(5, edit_window_open[x].id.length - 5) == path) {
                edit_window_open.splice(x, 1);
            }

        }

    }
    $.ajax({
        type: "POST",
        url: "website_code/php/versioncontrol/template_close.php",
        data: {
            file_path: path
        }
    })
    .done(function (response) {
        file_need_save(response);
    });
}

/**
 *
 * Function example window
 * This function requests the screen size for an example template
 * @param string examole_id = the id of the example
 * @version 1.0
 * @author <NAME>
 */

function example_window(example_id) {

    if (example_id != 0) {

        $.ajax({
            type: "POST",
            url: "website_code/php/properties/screen_size_template.php",
            data: {
                tutorial_id: example_id
            }
        })
        .done(function (response) {
            example_stateChanged(response);
        });

    } else {

        alert(NO_EXAMPLE);

    }

}

/**
 *
 * Function preview window
 * This function opens a window to display a preview of a template
 * @param string admin = whether the user is an admin
 * @version 1.0
 * @author <NAME>
 */

function preview_window(admin) {

    if (!admin) {

        if (setup_ajax() != false) {
            var tree = $.jstree.reference("#workspace"),
                ids = tree.get_selected();
            if (ids.length == 0)
                return;

            for (var i = 0; i < ids.length; i++) {
                var node = workspace.nodes[ids[i]];

                if (node.xot_type == "file") {
                    var mode = (window.event && window.event.shiftKey ? 'play' : 'preview');
                    size = node.preview_size.split(",");
                    if (size.length != 1) {


                        var PreviewWindow = window.open(site_url + url_return(mode, node.xot_id), "previewwindow" + node.id, "height=" + size[1] +
                            ", width=" + size[0] + ", scrollbars=yes,resizable=yes");

                    } else {


                        var PreviewWindow = window.open(site_url + url_return(mode, node.xot_id), "previewwindow" + node.id,
                            "height=768,width=1024,scrollbars=yes,resizable=yes");

                    }

                } else {

                    alert(PROJECT_SELECT);

                }

            }

        }

    } else {

        var PreviewWindow = window.open(site_url + url_return("preview", admin), "previewwindow" + admin, "scrollbars=yes");

    }

}


/**
 *
 * Function example state changed
 * This function opens a window to display an example template
 * @version 1.0
 * @author <NAME>
 */

function example_stateChanged(response) {
    if (response != "") {

        temp = response.toString().split("~");

        parameter = "height=" + temp[1] + ",width=" + temp[0] + ",status=No";

        var property_id = temp[2];

        var NewWindow = window.open(site_url + url_return("play", property_id), "examplewindow" + property_id, parameter);

        NewWindow.focus();
    }
}

/**
 *
 * Function properties window
 * This function opens a properties window
 * @param string admin - is the user an admin
 * @version 1.0
 * @author <NAME>
 */

function publishproperties_window(admin) {
    var tree = $.jstree.reference("#workspace"),
        ids = tree.get_selected();
    if (ids.length == 1) {
        var node = workspace.nodes[ids[0]];

        if (node.xot_type == "file") {
            var NewWindow = window.open(site_url + url_return("publishproperties", node.xot_id), node.xot_id, "height=600, width=635");
            NewWindow.window_reference = self;
            NewWindow.focus();
        }
    }
}

/**
 *
 * Function properties window
 * This function opens a properties window
 * @param string admin - is the user an admin
 * @version 1.0
 * @author <NAME>
 */

function properties_window(admin) {
    if (!admin) {
        var tree = $.jstree.reference("#workspace"),
            ids = tree.get_selected();
        if (ids.length == 0)
            return;

        if (workspace.nodes[ids[0]].type == "workspace") {
            var NewWindow = window.open(site_url + url_return("workspaceproperties", null), "workspace", "height=760, width=1000");
            NewWindow.window_reference = self;
            NewWindow.focus();
        } else {
            for (var i = 0; i < ids.length; i++) {
                if (workspace.nodes[ids[i]].type != "folder") {
                    if (workspace.nodes[ids[i]].parent != workspace.recyclebin_id) {
                        var NewWindow = window.open(site_url + url_return("properties", workspace.nodes[ids[i]].xot_id), workspace.nodes[ids[i]].xot_id,
                            "height=760, width=1000");
                        NewWindow.window_reference = self;
                        NewWindow.focus();
                    } else {
                        alert(RECYCLE_PROPERTIES);
                    }
                } else {
                    var NewWindow = window.open(site_url + url_return("folderproperties", workspace.nodes[ids[i]].xot_id + "_folder"), workspace.nodes[ids[i]].xot_id +
                        "_folder", "height=760, width=1000");
                    NewWindow.window_reference = self;
                    NewWindow.focus();
                }
            }
        }
    } else {
        var NewWindow = window.open(site_url + url_return("properties", admin), admin, "height=760, width=1000");

        NewWindow.window_reference = self;
        NewWindow.focus();
    }
}

/**
 *
 * Function selection changed
 * This function redisplays the file area sorted accordingly
 * @version 1.0
 * @author <NAME>
 */


function refresh_workspace() {
    // if (setup_ajax() != false) {
    //     var url = "website_code/php/templates/get_templates_sorted.php";
    //
    //     xmlHttp.open("post", url, true);
    //     xmlHttp.onreadystatechange = refreshworkspace_stateChanged;
    //     xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    //     xmlHttp.send('sort_type=' + document.sorting.type.value);
    // }
    $.ajax({
        type: "POST",
        url: "website_code/php/templates/get_templates_sorted.php",
        dataType: 'json',
        data: {
            sort_type: document.sorting.type.value
        }
    })
    .done(function(response){
        workspace = response;
        init_workspace();
    });
}

function getProjectInformation(user_id, template_id) {
    // if (setup_ajax() != false) {
    //     var url = "website_code/php/templates/get_template_info.php";
    //
    //     xmlHttp.open("post", url, true);
    //     xmlHttp.onreadystatechange = getProjectInformation_stateChanged;
    //     xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    //     xmlHttp.send('user_id=' + user_id + '&template_id=' + template_id);
    // }
    $.ajax({
        type: "POST",
        url: "website_code/php/templates/get_template_info.php",
        data: {user_id: user_id, template_id: template_id},
    })
    .done(function(info) {
        document.getElementById('project_information').innerHTML = info.properties;
        if (info.role == 'read-only') {
            // disable edit button.
            var editbtn = document.getElementById("edit");
            var propertiesbtn = document.getElementById("properties");
            var deletebtn = document.getElementById("delete");
{'fraction_non_alphanumeric': 0.12442762743001289, 'fraction_numerical': 0.0066902470455978726, 'mean_word_length': 1.6831457367762819, 'pattern_counts': {'":': 16, '<': 43, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 26}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5097545', 'n_tokens_mistral': 10459, 'n_tokens_neox': 9848, 'n_words': 2409}