/** * Update the url of a dir in the student_publication table * @param string old path * @param string new path */ function update_dir_name($work_data, $new_name, $title) { $course_id = api_get_course_int_id(); $work_id = intval($work_data['id']); $path = $work_data['url']; if ($work_data['title'] == $title) { return true; } $title = Database::escape_string($title); if (!empty($new_name)) { global $base_work_dir; $new_name = Security::remove_XSS($new_name); $new_name = replace_dangerous_char($new_name); $new_name = disable_dangerous_file($new_name); my_rename($base_work_dir . '/' . $path, $new_name); $table = Database::get_course_table(TABLE_STUDENT_PUBLICATION); //update all the files in the other directories according with the next query $sql = "SELECT id, url FROM {$table} WHERE c_id = {$course_id} AND parent_id = {$work_id}"; // like binary (Case Sensitive) $rs = Database::query($sql); $work_len = strlen('work/' . $path); while ($work = Database::fetch_array($rs)) { $new_dir = $work['url']; $name_with_directory = substr($new_dir, $work_len, strlen($new_dir)); $name = Database::escape_string('work/' . $new_name . '/' . $name_with_directory); $sql = 'UPDATE ' . $table . ' SET url= "' . $name . '" WHERE c_id = ' . $course_id . ' AND id= ' . $work['id']; Database::query($sql); } $sql = "UPDATE {$table} SET url= '/" . $new_name . "' , title = '" . $title . "' WHERE c_id = {$course_id} AND id = {$work_id}"; Database::query($sql); } }
/** This function changes the name of a certain file. It needs no global variables, it takes all info from parameters. It returns nothing. @todo check if this function is used */ function change_name($base_work_dir, $source_file, $rename_to, $dir, $doc) { $file_name_for_change = $base_work_dir . $dir . $source_file; $rename_to = disable_dangerous_file($rename_to); // Avoid renaming to .htaccess file $rename_to = my_rename($file_name_for_change, stripslashes($rename_to)); // fileManage API if ($rename_to) { if (isset($dir) && $dir != '') { $source_file = $dir . $source_file; $new_full_file_name = dirname($source_file) . '/' . $rename_to; } else { $source_file = '/' . $source_file; $new_full_file_name = '/' . $rename_to; } update_db_info('update', $source_file, $new_full_file_name); // fileManage API Display::addFlash(Display::return_message(get_lang('fileModified'))); return true; } else { Display::addFlash(Display::return_message(get_lang('FileExists'))); } }
/** This function changes the name of a certain file. It needs no global variables, it takes all info from parameters. It returns nothing. @todo check if this function is used */ function change_name($base_work_dir, $source_file, $rename_to, $dir, $doc) { $file_name_for_change = $base_work_dir . $dir . $source_file; //api_display_debug_info("call my_rename: params $file_name_for_change, $rename_to"); $rename_to = disable_dangerous_file($rename_to); // Avoid renaming to .htaccess file $rename_to = my_rename($file_name_for_change, stripslashes($rename_to)); // fileManage API if ($rename_to) { if (isset($dir) && $dir != '') { $source_file = $dir . $source_file; $new_full_file_name = dirname($source_file) . '/' . $rename_to; } else { $source_file = '/' . $source_file; $new_full_file_name = '/' . $rename_to; } update_db_info('update', $source_file, $new_full_file_name); // fileManage API $name_changed = get_lang('ElRen'); $info_message = get_lang('fileModified'); $GLOBALS['file_name'] = $rename_to; $GLOBALS['doc'] = $rename_to; return $info_message; } else { $dialogBox = get_lang('FileExists'); // TODO: This variable is not used. /* Return to step 1 */ $rename = $source_file; unset($source_file); } }