*/
    $lock_file_data = file_get_contents($xerte_toolkits_site->users_file_area_full . $temp_array[0] . "-" . $temp_array[1] . "-" . $temp_array[2] . "/lockfile.txt");
    $temp = explode("*", $lock_file_data);
    $lock_file_creator = $temp[0];
    $template_id = explode("-", $_POST['file_path']);
    $row_template_name = db_query_one("Select template_name from {$xerte_toolkits_site->database_table_prefix}templatedetails WHERE template_id = ?", array($template_id[0]));
    $user_list = $temp[1];
    $users = explode(" ", $user_list);
    /*
     * Email users in the lock file
     */
    for ($x = 0; $x != count($users) - 1; $x++) {
        mail($users[$x] . "@" . $xerte_toolkits_site->email_add_to_username, "File available - \"" . str_replace("_", " ", $row_template_name['template_name']) . "\"", "Hello, <br><br> You've requested to be informed when the file \"" . str_replace("_", " ", $row_template_name['template_name']) . "\" becomes available for editing. The file was made available at " . date("h:i a") . " on " . date("l, jS F") . " <br><br> Please note that multiple requests may have been made, and as such you may not be the only person to have receive one of these notifications. As such the file may well be locked by somebody else.<br><br> Please log into the site at <a href=\"" . $xerte_toolkits_site->site_url . "\">" . $xerte_toolkits_site->site_url . "</a>. <br><br> Thank you, <br><br> the Xerte Online toolkits team", get_email_headers());
    }
    unlink($xerte_toolkits_site->users_file_area_full . $_POST['file_path'] . "lockfile.txt");
}
/*
 * Code to check to see if we should warn on a publish
 */
if (is_user_an_editor($temp_array[0], $_SESSION['toolkits_logon_id'])) {
    $prefix = $xerte_toolkits_site->users_file_area_full . $temp_array[0] . "-" . $temp_array[1] . "-" . $temp_array[2];
    $preview_file = $prefix . '/preview.xml';
    $data_file = $prefix . '/data.xml';
    if (file_exists($preview_file) && file_exists($data_file)) {
        $preview_xml = file_get_contents($preview_file);
        $data_xml = file_get_contents($data_file);
        if ($data_xml != $preview_xml) {
            echo TEMPLATE_CLOSE_QUESTION . "~*~" . $xerte_toolkits_site->users_file_area_full . $temp_array[0] . "-" . $temp_array[1] . "-" . $temp_array[2] . "~*~" . $temp_array[0];
        }
    }
}
    exit(0);
}
/*
 * Find out if this user has rights to the template
 */
$safe_template_id = (int) $_GET['template_id'];
$query_for_edit_content_strip = str_replace("\" . \$xerte_toolkits_site->database_table_prefix . \"", $xerte_toolkits_site->database_table_prefix, $xerte_toolkits_site->play_edit_preview_query);
$query_for_edit_content = str_replace("TEMPLATE_ID_TO_REPLACE", $safe_template_id, $query_for_edit_content_strip);
$row_edit = db_query_one($query_for_edit_content);
if (empty($row_edit)) {
    die("Invalid template_id (could not find in DB) (1)");
}
if (isset($_SESSION['toolkits_logon_id'])) {
    if (has_rights_to_this_template($safe_template_id, $_SESSION['toolkits_logon_id'])) {
        // Check if user is editor (could be read only)
        if (is_user_an_editor($safe_template_id, $_SESSION['toolkits_logon_id'])) {
            // Check for multiple editors
            if (has_template_multiple_editors($safe_template_id)) {
                // Check for lock file. A lock file is created to prevent more than one
                if (file_exists($xerte_toolkits_site->users_file_area_full . $row_edit['template_id'] . "-" . $row_edit['username'] . "-" . $row_edit['template_name'] . "/lockfile.txt")) {
                    // Lock file exists, so open it up and see who created it
                    $lock_file_data = file_get_contents($xerte_toolkits_site->users_file_area_full . $row_edit['template_id'] . "-" . $row_edit['username'] . "-" . $row_edit['template_name'] . "/lockfile.txt");
                    $temp = explode("*", $lock_file_data);
                    if (count($temp) == 1) {
                        $temp = explode(" ", $lock_file_data);
                    }
                    $lock_file_creator = $temp[0];
                    /*
                     * Check if lock file creator is current user, if so, continue into the code
                     */
                    if ($lock_file_creator == $_SESSION['toolkits_logon_username']) {