_load_language_file("/website_code/php/templates/duplicate_template.inc");
$database_connect_id = database_connect("new_template database connect success", "new_template database connect fail");
/*
 * get the root folder for this user
 */
if (is_numeric($_POST['template_id'])) {
    if (is_user_creator(mysql_real_escape_string($_POST['template_id']))) {
        if ($_POST['folder_id'] == "workspace") {
            $folder_id = get_user_root_folder();
        } else {
            $folder_id = $_POST['folder_id'];
        }
        /*
         * get the maximum id number from templates, as the id for this template
         */
        $maximum_template_id = get_maximum_template_number();
        //$query_for_root_folder = "select folder_id from " . $xerte_toolkits_site->database_table_prefix . "folderdetails where login_id = '" .  $_SESSION['toolkits_logon_id'] . "' and folder_parent='0'";
        //$query_for_root_folder_response = mysql_query($query_for_root_folder);
        //$row_root = mysql_fetch_array($query_for_root_folder_response);
        $query_for_template_type_id = "select otd.template_type_id, otd.template_name, otd.template_framework, td.extra_flags from " . $xerte_toolkits_site->database_table_prefix . "originaltemplatesdetails otd, " . $xerte_toolkits_site->database_table_prefix . "templatedetails td where otd.template_type_id = td.template_type_id  AND td.template_id = '" . mysql_real_escape_string($_POST['template_id']) . "'";
        $query_for_template_type_id_response = mysql_query($query_for_template_type_id);
        $row_template_type = mysql_fetch_array($query_for_template_type_id_response);
        /*
         * create the new template record in the database
         */
        $query_for_new_template = "INSERT INTO " . $xerte_toolkits_site->database_table_prefix . "templatedetails (template_id, creator_id, template_type_id, date_created, date_modified, access_to_whom, template_name, extra_flags) VALUES (\"" . ($maximum_template_id + 1) . "\",\"" . $_SESSION['toolkits_logon_id'] . "\", \"" . $row_template_type['template_type_id'] . "\",\"" . date('Y-m-d') . "\",\"" . date('Y-m-d') . "\",\"Private\",\"Copy of " . mysql_real_escape_string($_POST['template_name']) . "\", \"" . mysql_real_escape_string($row_template_type['extra_flags']) . "\")";
        if (mysql_query($query_for_new_template)) {
            $query_for_template_rights = "INSERT INTO " . $xerte_toolkits_site->database_table_prefix . "templaterights (template_id,user_id,role, folder) VALUES (\"" . ($maximum_template_id + 1) . "\",\"" . $_SESSION['toolkits_logon_id'] . "\", \"creator\" ,\"" . mysql_real_escape_string($folder_id) . "\")";
            if (mysql_query($query_for_template_rights)) {
                receive_message($_SESSION['toolkits_logon_username'], "ADMIN", "SUCCESS", "Created new template record for the database", $query_for_new_template . " " . $query_for_template_rights);
                include $xerte_toolkits_site->root_file_path . $xerte_toolkits_site->module_path . $row_template_type['template_framework'] . "/duplicate_template.php";
Example #2
0
    } else {
        return false;
    }
}
if (!isset($_GET['template_id']) || !is_numeric($_GET['template_id'])) {
    /*
     * Was not numeric, so display error message
     */
    echo file_get_contents($xerte_toolkits_site->website_code_path . "error_top") . " " . PLAY_RESOURCE_FAIL . " </div></div></body></html>";
    exit(0);
}
$safe_template_id = (int) $_GET['template_id'];
/*
 * Check to see whether it is less than the highest ID we have created
 */
if (get_maximum_template_number() < $safe_template_id) {
    echo file_get_contents($xerte_toolkits_site->website_code_path . "error_top") . " " . PLAY_RESOURCE_FAIL . " </div></div></body></html>";
    die;
}
/*
 * Take the query from site variable and alter it to suit this request
 */
$query_for_play_content = "select otd.template_name, ld.username, otd.template_framework, tr.user_id, tr.folder, tr.template_id, td.access_to_whom, td.extra_flags";
$query_for_play_content .= " from " . $xerte_toolkits_site->database_table_prefix . "originaltemplatesdetails otd, " . $xerte_toolkits_site->database_table_prefix . "templaterights tr, " . $xerte_toolkits_site->database_table_prefix . "templatedetails td, " . $xerte_toolkits_site->database_table_prefix . "logindetails ld";
$query_for_play_content .= " where td.template_type_id = otd.template_type_id and td.creator_id = ld.login_id and tr.template_id = td.template_id and tr.template_id=" . $safe_template_id . " and role='creator'";
$query_for_play_content_response = mysql_query($query_for_play_content);
$row_play = mysql_fetch_array($query_for_play_content_response);
$query_to_find_out_if_in_recycle_bin = "select folder_name from " . $xerte_toolkits_site->database_table_prefix . "folderdetails where folder_id =\"" . $row_play['folder'] . "\"";
$query_for_recycle_bin_response = mysql_query($query_to_find_out_if_in_recycle_bin);
/*
 * Is the file in the recycle bin?
/**
 * 
 * Function make new template
 * This function checks http security settings
 * @param string $type = type of template
 * @param string $zip_path = the path we are zipping
 * @version 1.0
 * @author Patrick Lockley
 */
function make_new_template($type, $zip_path)
{
    global $xerte_toolkits_site, $delete_folder_array, $folder_id;
    $database_connect_id = database_connect("new_template(import) database connect success", "new_template(import) database connect fail");
    /*
     *get the root folder for this user
     */
    $root_folder_id = get_user_root_folder();
    /*
     * get the maximum id number from templates, as the id for this template
     */
    $maximum_template_id = get_maximum_template_number();
    $root_folder = get_user_root_folder();
    $prefix = $xerte_toolkits_site->database_table_prefix;
    $query_for_template_type_id = "select template_type_id, template_framework from {$prefix}originaltemplatesdetails where template_name = ?";
    $params = array($type);
    $row_template_type = db_query_one($query_for_template_type_id, $params);
    /*
     * create the new template record in the database
     */
    /*
     * See if we have been given a name, if not, use a fixed one.
     */
    if ($_POST['templatename'] != "") {
        $template_name = $_POST['templatename'];
    } else {
        $template_name = IMPORT_NAME_IF_EMPTY;
    }
    $query_for_new_template = "INSERT INTO {$prefix}templatedetails " . "(template_id, creator_id, template_type_id, date_created, date_modified, access_to_whom, template_name, extra_flags) " . "VALUES (?,?,?,?,?,?,?,?)";
    $params = array($maximum_template_id + 1, $_SESSION['toolkits_logon_id'], $row_template_type['template_type_id'], date('Y-m-d'), date('Y-m-d'), "Private", $template_name, "engine=javascript");
    $ok = db_query($query_for_new_template, $params);
    if ($ok !== false) {
        /*
         * Are we importing into a folder
         */
        if ($folder_id == "") {
            $folder_id = $root_folder_id;
        }
        $query_for_template_rights = "INSERT INTO {$prefix}templaterights" . " (template_id,user_id,role, folder)" . "VALUES (?,?,?,?)";
        $params = array($maximum_template_id + 1, $_SESSION['toolkits_logon_id'], "creator", $folder_id);
        $ok = db_query($query_for_template_rights, $params);
        if ($ok !== false) {
            /*
             * Make the folders and copy the files in
             */
            receive_message($_SESSION['toolkits_logon_username'], "ADMIN", "SUCCESS", "Created new template record for the database", $query_for_new_template . " " . $query_for_template_rights);
            mkdir($xerte_toolkits_site->root_file_path . $xerte_toolkits_site->users_file_area_short . ($maximum_template_id + 1) . "-" . $_SESSION['toolkits_logon_username'] . "-" . $type);
            chmod($xerte_toolkits_site->root_file_path . $xerte_toolkits_site->users_file_area_short . ($maximum_template_id + 1) . "-" . $_SESSION['toolkits_logon_username'] . "-" . $type, 0777);
            copy_loop($zip_path, $xerte_toolkits_site->root_file_path . $xerte_toolkits_site->users_file_area_short . ($maximum_template_id + 1) . "-" . $_SESSION['toolkits_logon_username'] . "-" . $type . "/");
            echo IMPORT_SUCCESS . "****";
            /*
             * Remove the files
             */
            array_splice($delete_folder_array, 0);
            delete_loop($zip_path);
            foreach ($delete_folder_array as $delete_folder) {
                rmdir($delete_folder);
            }
            $delete_folder_array = null;
            rmdir($zip_path);
        } else {
            receive_message($_SESSION['toolkits_logon_username'], "ADMIN", "CRITICAL", "Failed to create new template record for the database", $query_for_template_rights);
        }
    } else {
        receive_message($_SESSION['toolkits_logon_username'], "ADMIN", "CRITICAL", "Failed to create new template record for the database", $query_for_new_template);
        echo "FAILED-" . $_SESSION['toolkits_most_recent_error'];
    }
}
     $base_path = $xerte_toolkits_site->root_file_path . $xerte_toolkits_site->users_file_area_short;
     /**
      * Rename the folder where the template is
      */
     rename($base_path . $tutorial_id . "-" . $row_rename['username'] . "-" . $row_rename['template_name'] . "/", $base_path . $tutorial_id . "-" . $row_new_login['username'] . "-" . $row_rename['template_name'] . "/");
     echo "<p>" . GIFT_RESPONSE_FAIL . "</p>";
 } else {
     /**
      * Giving away a duplicate
      */
     $prefix = $xerte_toolkits_site->database_table_prefix;
     $database_id = database_connect("Template sharing rights database connect success", "Template sharing rights database connect failed");
     $query_for_currentdetails = "select *,{$prefix}templatedetails.template_name AS actual_name FROM " . "{$prefix}templatedetails, {$prefix}originaltemplatesdetails where " . "template_id= ? AND {$prefix}originaltemplatesdetails.template_type_id = {$prefix}templatedetails.template_type_id";
     $params = array($tutorial_id);
     $row_currentdetails = db_query_one($query_for_currentdetails, $params);
     $new_template_id = get_maximum_template_number() + 1;
     $creation_query = "INSERT INTO {$prefix}templatedetails " . "(template_id, creator_id, template_type_id,template_name,date_created,date_modified,date_accessed,number_of_uses,access_to_whom,extra_flags) " . " VALUES (?,?,?,?,?,?,?,?,?,?)";
     $params = array($new_template_id, $user_id, $row_currentdetails['template_type_id'], $row_currentdetails['actual_name'], date('Y-m-d'), date('Y-m-d'), date('Y-m-d'), 0, "Private", $row_currentdetails['extra_flags']);
     $ok = db_query($creation_query, $params);
     $query_for_currentrights = "select * from {$prefix}templaterights where template_id = ?";
     $params = array($tutorial_id);
     $row_currentrights = db_query_one($query_for_currentdetails, $params);
     $query_for_root_folder = "select folder_id from {$prefix}folderdetails where login_id= ? AND folder_name != ?  AND folder_parent=0";
     $params = array($user_id, 'recyclebin');
     $row_folder = db_query_one($query_for_root_folder, $params);
     $create_rights_query = "INSERT INTO {$prefix}templaterights (template_id, user_id, role,folder,notes) VALUES (?,?,?,?,?)";
     $params = array($new_template_id, $user_id, "creator", $row_folder['folder_id'], '');
     db_query($create_rights_query, $params);
     $query_for_new_login = "******";
     $params = array($user_id);
     $row_new_login = db_query_one($query_for_new_login, $params);
Example #5
0
/**
 * 
 * Function make new template
 * This function checks http security settings
 * @param string $type = type of template
 * @param string $zip_path = the path we are zipping
 * @version 1.0
 * @author Patrick Lockley
 */
function make_new_template($type, $zip_path)
{
    global $xerte_toolkits_site, $delete_folder_array, $folder_id;
    $database_connect_id = database_connect("new_template(import) database connect success", "new_template(import) database connect fail");
    /*
     *get the root folder for this user
     */
    $root_folder_id = get_user_root_folder();
    /*
     * get the maximum id number from templates, as the id for this template
     */
    $maximum_template_id = get_maximum_template_number();
    $root_folder = get_user_root_folder();
    $query_for_template_type_id = "select template_type_id, template_framework from " . $xerte_toolkits_site->database_table_prefix . "originaltemplatesdetails where template_name = '" . $type . "'";
    $query_for_template_type_id_response = mysql_query($query_for_template_type_id);
    $row_template_type = mysql_fetch_array($query_for_template_type_id_response);
    /*
     * create the new template record in the database
     */
    /*
     * See if we have been given a name, if not, use a fixed one.
     */
    if ($_POST['templatename'] != "") {
        $template_name = mysql_real_escape_string($_POST['templatename']);
    } else {
        $template_name = IMPORT_NAME_IF_EMPTY;
    }
    $query_for_new_template = "INSERT INTO " . $xerte_toolkits_site->database_table_prefix . "templatedetails (template_id, creator_id, template_type_id, date_created, date_modified, access_to_whom, template_name) VALUES (\"" . ($maximum_template_id + 1) . "\",\"" . $_SESSION['toolkits_logon_id'] . "\", \"" . $row_template_type['template_type_id'] . "\",\"" . date('Y-m-d') . "\",\"" . date('Y-m-d') . "\",\"Private\",\"" . $template_name . "\")";
    if (mysql_query($query_for_new_template)) {
        /*
         * Are we importing into a folder
         */
        if ($folder_id == "") {
            $folder_id = $root_folder_id;
        }
        $query_for_template_rights = "INSERT INTO " . $xerte_toolkits_site->database_table_prefix . "templaterights (template_id,user_id,role, folder) VALUES (\"" . ($maximum_template_id + 1) . "\",\"" . $_SESSION['toolkits_logon_id'] . "\", \"creator\" ,\"" . $folder_id . "\")";
        if (mysql_query($query_for_template_rights)) {
            /*
             * Make the folders and copy the files in
             */
            receive_message($_SESSION['toolkits_logon_username'], "ADMIN", "SUCCESS", "Created new template record for the database", $query_for_new_template . " " . $query_for_template_rights);
            mkdir($xerte_toolkits_site->root_file_path . $xerte_toolkits_site->users_file_area_short . ($maximum_template_id + 1) . "-" . $_SESSION['toolkits_logon_username'] . "-" . $type);
            chmod($xerte_toolkits_site->root_file_path . $xerte_toolkits_site->users_file_area_short . ($maximum_template_id + 1) . "-" . $_SESSION['toolkits_logon_username'] . "-" . $type, 0777);
            mkdir($xerte_toolkits_site->root_file_path . $xerte_toolkits_site->users_file_area_short . ($maximum_template_id + 1) . "-" . $_SESSION['toolkits_logon_username'] . "-" . $type . "/media/");
            chmod($xerte_toolkits_site->root_file_path . $xerte_toolkits_site->users_file_area_short . ($maximum_template_id + 1) . "-" . $_SESSION['toolkits_logon_username'] . "-" . $type . "/media/", 0777);
            copy_loop($zip_path, $xerte_toolkits_site->root_file_path . $xerte_toolkits_site->users_file_area_short . ($maximum_template_id + 1) . "-" . $_SESSION['toolkits_logon_username'] . "-" . $type . "/");
            echo IMPORT_SUCCESS . "****";
            /*
             * Remove the files
             */
            array_splice($delete_folder_array, 0);
            delete_loop($zip_path);
            while ($delete_folder = array_pop($delete_folder_array)) {
                rmdir($delete_folder);
            }
            rmdir($zip_path);
        } else {
            receive_message($_SESSION['toolkits_logon_username'], "ADMIN", "CRITICAL", "Failed to create new template record for the database", $query_for_template_rights);
        }
    } else {
        receive_message($_SESSION['toolkits_logon_username'], "ADMIN", "CRITICAL", "Failed to create new template record for the database", $query_for_new_template);
        echo "FAILED-" . $_SESSION['toolkits_most_recent_error'];
    }
    mysql_close($database_connect_id);
}