/** * * Function make new folder * This function is used to send an error email meesage * @param string $folder_id = id for the new folder * @param string $folder_name = Name of the new folder * @version 1.0 * @author Patrick Lockley */ function make_new_folder($folder_id, $folder_name) { global $xerte_toolkits_site; $mysql_id = database_connect("New folder database connect success", "New folder database connect failed"); $prefix = $xerte_toolkits_site->database_table_prefix; if ($folder_id == "file_area") { $query = "INSERT INTO {$prefix}folderdetails (login_id,folder_parent,folder_name,date_created) values (?,?,?,?)"; $params = array($_SESSION['toolkits_logon_id'], get_user_root_folder(), $folder_name, date('Y-m-d')); } else { $query = "INSERT INTO {$prefix}folderdetails (login_id,folder_parent,folder_name,date_created) values (?,?,?,?)"; $params = array($_SESSION['toolkits_logon_id'], $folder_id, $folder_name, date('Y-m-d')); } $ok = db_query($query, $params); if ($ok !== false) { receive_message($_SESSION['toolkits_logon_username'], "USER", "SUCCESS", "Folder creation succeeded for " . $_SESSION['toolkits_logon_username'], "Folder creation succeeded for " . $_SESSION['toolkits_logon_username']); echo FOLDER_LIBRARY_CREATE; } else { receive_message($_SESSION['toolkits_logon_username'], "USER", "CRITICAL", "Folder creation failed for " . $_SESSION['toolkits_logon_username'], "Folder creation failed for " . $_SESSION['toolkits_logon_username']); echo FOLDER_LIBRARY_FAIL; } }
* @copyright Copyright (c) 2008,2009 University of Nottingham * @package */ require_once "../../../config.php"; include "../user_library.php"; include "../template_library.php"; include "../template_status.php"; _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
/** * * 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']; } }
/** * * Function recycle bin * looks for a reycle bin and if can't find one, make it. * @author Patrick Lockley * @version 1.0 * @copyright Copyright (c) 2008,2009 University of Nottingham * @package */ function recycle_bin() { global $xerte_toolkits_site; $query = "select folder_name from {$xerte_toolkits_site->database_table_prefix}folderdetails where \r\n folder_name = ? AND login_id = ?"; $res = db_query($query, array("recyclebin", $_SESSION['toolkits_logon_id'])); $root_folder = get_user_root_folder(); if (sizeof($res) == 0) { $query = "insert into {$xerte_toolkits_site->database_table_prefix}folderdetails \r\n (login_id,folder_parent,folder_name) VALUES (?,?,?)"; $res = db_query($query, array($_SESSION['toolkits_logon_id'], "0", "recyclebin")); if ($res) { receive_message($_SESSION['toolkits_logon_username'], "ADMIN", "SUCCESS", "Succeeded in creating users recycle bin " . $_SESSION['toolkits_logon_id'], "Succeeded in creating users root folder " . $_SESSION['toolkits_logon_id']); } else { receive_message($_SESSION['toolkits_logon_username'], "ADMIN", "CRITICAL", "Failed to create users recycle bin", "Failed to create users recycle bin"); } } }
\t\t\t<div id="demoParent"> \t\t\t\t<div style="overflow: auto;" id="demoDIV"><div> END; require_once '../' . $xerte_toolkits_site->php_library_path . "display_library.php"; echo "<form method=\"post\">"; //echo "<div class=\"folder\" id=\"folder_workspace\" ondblclick=\"folder_open_close(this)\" onclick=\"highlight_main_toggle(this)\">"; //echo "</div>\r\n<div id=\"folderchild_workspace\" class=\"workspace\">"; $level = 1; $item = 1; $item = list_folder_contents_event_free(get_user_root_folder(), '../', $item, 'radio'); print <<<END </div></div> \t\t\t</div> \t\t\t<div class="demoHeader"></div> \t\t\t<div id="styleDIV"> <input type="submit" name="submit" value="Select"></form> \t\t\t</div> \t\t</div> \t\t<div style="clear:both;"></div> \t\t<div style="clear:both;"></div> \t</div>
/** * * Function move file * This function is used to move files and folders * @param array $files_to_move = an array of files and folders to move * @param string $destination = Name of the new folder * @version 1.0 * @author Patrick Lockley */ function move_file($files_to_move, $destination) { global $xerte_toolkits_site; $mysql_id = database_connect("Move file database connect success", "Move file database connect failure"); $new_files_array = explode(",", $files_to_move); /* * Files array can be complicated, and this thread can lock the system, so limit max files to 50 */ if (count($new_files_array) != 0 && count($new_files_array) <= 50) { /* * check their is a destination */ if ($destination != "") { for ($x = 0; $x != count($new_files_array); $x++) { // check there are files if ($new_files_array[$x] != "") { if ($new_files_array[$x + 1] == "file") { if ($new_files_array[$x + 2] == "folder_workspace") { $parent = get_user_root_folder(); } if ($destination == "folder_workspace") { $destination = get_user_root_folder(); } if ($destination == "recyclebin") { $destination = get_recycle_bin(); } /* * Move files in the database */ $query_file = "UPDATE " . $xerte_toolkits_site->database_table_prefix . "templaterights SET folder = \"" . $destination . "\" where (template_id=\"" . $new_files_array[$x] . "\" AND user_id =\"" . $_SESSION['toolkits_logon_id'] . "\")"; if (mysql_query($query_file)) { receive_message($_SESSION['toolkits_logon_username'], "USER", "SUCCESS", "File " . $new_files_array[$x] . " moved into " . $destination . " for " . $_SESSION['toolkits_logon_username'], "File " . $new_files_array[$x] . " moved into " . $destination . " for " . $_SESSION['toolkits_logon_username']); } else { receive_message($_SESSION['toolkits_logon_username'], "USER", "SUCCESS", "File " . $new_files_array[$x] . " failed to move into " . $destination . " for " . $_SESSION['toolkits_logon_username'], "File " . $new_files_array[$x] . " failed to move into " . $destination . " for " . $_SESSION['toolkits_logon_username']); } } else { /* * destination is the root folder */ if ($destination == "folder_workspace") { $destination = get_user_root_folder(); } $query_folder = "UPDATE " . $xerte_toolkits_site->database_table_prefix . "folderdetails SET folder_parent = \"" . $destination . "\" where (folder_id=\"" . $new_files_array[$x] . "\")"; if (mysql_query($query_folder)) { receive_message($_SESSION['toolkits_logon_username'], "USER", "SUCCESS", "Folder " . $new_files_array[$x] . " moved into " . $destination . " for " . $_SESSION['toolkits_logon_username'], "File " . $new_files_array[$x] . " moved into " . $destination . " for " . $_SESSION['toolkits_logon_username']); } else { receive_message($_SESSION['toolkits_logon_username'], "USER", "SUCCESS", "File " . $new_files_array[$x] . " failed to move into " . $destination . " for " . $_SESSION['toolkits_logon_username'], "Folder " . $new_files_array[$x] . " failed to move into " . $destination . " for " . $_SESSION['toolkits_logon_username']); } } $x += 2; } } } } mysql_close($mysql_id); }
/** * * 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); }
/** * * Function list users projects * This function is used as part of the recursion to display the main file system * @param string $sort_type = A variable which dictates how we are sorting this * @version 1.0 * @author Patrick Lockley */ function list_users_projects($sort_type) { /* * Called by index.php to start off the process */ global $level, $xerte_toolkits_site; $root_folder = get_user_root_folder(); /* * Create the workspace folder */ echo "<div class=\"folder\" id=\"folder_workspace\" ondblclick=\"folder_open_close(this)\" onclick=\"highlight_main_toggle(this)\"><p><img style=\"vertical-align:middle\""; echo " src=\"{$xerte_toolkits_site->site_url}/website_code/images/folder_workspace.gif\""; echo " />" . DISPLAY_WORKSPACE . "</p></div><div id=\"folderchild_workspace\" class=\"workspace\">"; $level = 1; list_folder_contents(get_user_root_folder(), $sort_type); $query = "select folder_id from " . $xerte_toolkits_site->database_table_prefix . "folderdetails where folder_name=\"recyclebin\" and login_id =\"" . $_SESSION['toolkits_logon_id'] . "\""; $query_response = mysql_query($query); $row = mysql_fetch_array($query_response); $level = 1; $query_for_folder_content = "select template_id from " . $xerte_toolkits_site->database_table_prefix . "templaterights where folder=\"" . $row['folder_id'] . "\" UNION SELECT folder_id from " . $xerte_toolkits_site->database_table_prefix . "folderdetails where folder_parent=\"" . $row['folder_id'] . "\""; $query_response_for_folder_content = mysql_query($query_for_folder_content); echo "</div>"; /* * Display the recycle bin */ echo "<div class=\"folder\" id=\"recyclebin\" ondblclick=\"folder_open_close(this)\" onclick=\"highlight_main_toggle(this)\"><p><img id=\"folder_recyclebin\" style=\"vertical-align:middle\""; if (mysql_num_rows($query_response_for_folder_content) == 0) { echo " src=\"{$xerte_toolkits_site->site_url}/website_code/images/rb_empty.gif\""; } else { echo " src=\"{$xerte_toolkits_site->site_url}/website_code/images/rb_full.gif\""; } echo " />" . DISPLAY_RECYCLE . "</p></div><div id=\"folderchild_recyclebin\" class=\"folder_content\">"; list_folder_contents($row['folder_id'], $sort_type); echo "</div>"; }
/** * Builds an array with the whole structure of the workspace suitable for jsTree * Called by an AJAX function, that returns the array as a alternative JSON file for jstree * * @param $sort_type the way the workspace is to be sorte */ function get_users_projects($sort_type) { global $xerte_toolkits_site; $root_folder = get_user_root_folder(); $workspace = new stdClass(); $workspace->user = $_SESSION['toolkits_logon_id']; $workspace->items = array(); /** * We've two toplevel icons * - Workspace * - Recyclebin */ $workspace->workspace_id = "ID_" . $_SESSION['toolkits_logon_id'] . "_F" . get_user_root_folder(); $item = new stdClass(); $item->id = $workspace->workspace_id; $item->xot_id = get_user_root_folder(); $item->parent = "#"; $item->text = DISPLAY_WORKSPACE; $item->type = "workspace"; $item->xot_type = "workspace"; $state = new stdClass(); $state->opened = true; $state->disabled = false; $state->selected = true; $item->state = $state; $workspace->items[] = $item; $workspace->nodes[$item->id] = $item; $items = get_folder_contents($item->xot_id, $item->id, $sort_type); if ($items) { $workspace->items = array_merge($workspace->items, $items); foreach ($items as $item) { $workspace->nodes[$item->id] = $item; } } $prefix = $xerte_toolkits_site->database_table_prefix; $query = "select folder_id from {$prefix}folderdetails where folder_name=? AND login_id = ?"; $params = array("recyclebin", $_SESSION['toolkits_logon_id']); $row = db_query_one($query, $params); $workspace->recyclebin_id = "ID_" . $_SESSION['toolkits_logon_id'] . "_F" . $row['folder_id']; $item = new stdClass(); $item->id = $workspace->recyclebin_id; $item->xot_id = $row['folder_id']; $item->parent = "#"; $item->text = DISPLAY_RECYCLE; $item->type = "recyclebin"; $item->xot_type = "recyclebin"; $workspace->items[] = $item; $workspace->nodes[$item->id] = $item; $items = get_folder_contents($item->xot_id, $item->id, $sort_type); if ($items) { $workspace->items = array_merge($workspace->items, $items); foreach ($items as $item) { $workspace->nodes[$item->id] = $item; } } // setup the templates available in the installation , to determine the node types $query_for_blank_templates = "select * from {$prefix}originaltemplatesdetails order by date_uploaded DESC"; $templates = array(); $rows = db_query($query_for_blank_templates, array()); foreach ($rows as $row) { $templates[] = strtolower($row['template_name']); } $workspace->templates = $templates; return json_encode($workspace); }