aboutsummaryrefslogtreecommitdiff
path: root/www/functions/notused/func_content.php
blob: ad0c87e83e0d57ac4d82761162e5312e4d2d2790 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php

function collect_content($db,$username, $folder_path){
	$owner = user_id($db, $username);

	if(!$owner){
		failure("This user doesn't exist!");
	}

	$file_id = select_file_id($db, $owner, $folder_path);

	if(!$file_id){
		return FILE_NOT_FOUND;
	}

	$content = get_content($db, $file_id, $owner);

	if(!$content){
		return EMPTY_FOLDER;
	}
	
	return $content;
}

function get_content($db, $file_id, $owner){

	if($_SESSION["login"] && $_SESSION["userid"] == $owner){
		$share="";
	} else {
		$share =" AND share='PUBLIC'";
	}

	$content_db = $db->query("SELECT * FROM files WHERE parent=" . $file_id . " AND owner=" . $owner . $share . " ORDER BY folder, name;");
	
	$count=0;

	while($row = $content_db->fetchArray(SQLITE3_NUM)){
		$content[$count][0] = $row[0];
		$content[$count][1] = $row[1];
		$content[$count][2] = $row[2];
		$content[$count][3] = $row[3];
		$content[$count][4] = $row[4];
		$content[$count][5] = $row[5];
		$content[$count][6] = $row[6];
		$content[$count][7] = $row[7];
		$content[$count][8] = $row[8];
		$count++;
	}

	if(!empty($content)){
		return $content;	// returns everything listed in the folder which is commited as parameter
	} else {
		return false;		// empty folder
	}
}

function get_path_to_wrong_folder($db, $username, $folder_path){

	$owner = user_id($db, $username);

	if($_SESSION["login"] && $_SESSION["userid"] == $owner){
		$share = "";
	} else {
		$share =" AND share='PUBLIC'";
	}

	$folder_array_unsafe = explode("/",$folder_path);
	$length = count($folder_array_unsafe);

	$root_db = $db->query("SELECT id FROM files WHERE parent=0 AND owner=" . SQLite3::escapeString($owner) . " AND folder='DIRECTORY' " . $share . ";");
	$root_ar = $root_db->fetchArray(SQLITE3_NUM);
	$root_id = $root_ar[0];

	if(empty($root_id)){
		return FOLDER_NOT_PUBLIC;
	}

	$parentdir = $root_id;
	
	for($i=0; $i<$length; $i++){
		$parentdir_db = $db->query("SELECT id, parent FROM files WHERE owner=" . $owner . $share . " AND parent=". $parentdir . " AND name='" . SQLite3::escapeString($folder_array_unsafe[$i]) . "';");
		$prim_id = $parentdir_db->fetchArray(SQLITE3_NUM);

		if($parentdir != $prim_id[1]){
			$wrong_folder = $folder_array_unsafe[$i];
			$working_path[0] = $wrong_folder;

			for($j=0; $j<$i; $j++){
				$working_path[$j] = $folder_array_unsafe[$j];
			}

			$lwp = count($working_path);
			$working_path[$lwp] = $wrong_folder;

			if($i == 0){
				$working_path[0] = "";	// shows just the root slash
			}

			return $working_path; 	// returns working path and wrong folder as an array
		}

		$parentdir = $prim_id[0];

	}

	return false;
}

function print_wrong_folder($content){

	$length = count($content);

	$wrong_folder = $content[$length-1];
	$working_path[0] = $wrong_folder;	// initialize empty array
	
	for($i=0; $i<$length-1; $i++){
		$working_path[$i] = $content[$i];
	}

	get_404($working_path, $wrong_folder);
}