示例#1
0
/**
 * TODO: my_directory_to_array() - maybe within the main API there is already a suitable function?
 * @param   string  $directory  Full path to a directory
 * @return  array   A list of files and dirs in the directory
 */
function my_directory_to_array($directory)
{
    $array_items = array();
    if ($handle = opendir($directory)) {
        while (false !== ($file = readdir($handle))) {
            if ($file != "." && $file != "..") {
                if (is_dir($directory . "/" . $file)) {
                    $array_items = array_merge($array_items, my_directory_to_array($directory . '/' . $file));
                    $file = $directory . "/" . $file;
                    $array_items[] = preg_replace("/\\/\\//si", '/', $file);
                }
            }
        }
        closedir($handle);
    }
    return $array_items;
}
						}
					}

					// Work Tool Folder Update
					// We search into DB all the folders in the work tool
					if ($singleDbForm) {
						$my_course_table = "$prefix{$row_course['db_name']}_student_publication";
					} else {
						$my_course_table = $row_course['db_name'].".student_publication";
					}

					$sys_course_path = $_configuration['root_sys'].$_configuration['course_folder'];

					$course_dir = $sys_course_path.$row_course['directory'].'/work';

					$dir_to_array = my_directory_to_array($course_dir, true);
					$only_dir = array();

					$sql_select = "SELECT filetype FROM " . $my_course_table . " WHERE  filetype = 'folder'";
					$result = Database::query($sql_select);
					$num_row = Database::num_rows($result);

					// Check if there are already folder registered
					if ($num_row == 0) {
						for ($i = 0; $i < count($dir_to_array); $i++) {
							$only_dir[] = substr($dir_to_array[$i], strlen($course_dir), strlen($dir_to_array[$i]));
						}

						for ($i = 0; $i < count($only_dir); $i++) {
							$sql_insert_all= "INSERT INTO " . $my_course_table . " SET url = '" . $only_dir[$i] . "', " .
											"title        = '',