= 10) { $num++; } } return $num; } function num_of_users ($school_id) { $result = mysql_query("SELECT user_id FROM Users WHERE school_id='$school_id'"); $num = mysql_numrows($result); return $num; } function num_of_students ($school_id) { $result = mysql_query("SELECT user_id FROM Users WHERE school_id='$school_id' && level=0"); $num = mysql_numrows($result); return $num; } function num_of_teachers ($school_id) { $result = mysql_query("SELECT user_id FROM Users WHERE school_id='$school_id' && level>0"); $num = mysql_numrows($result); return $num; } function num_of_forms ($school_id) { $result = mysql_query("SELECT form_number FROM Forms WHERE school_id='$school_id'"); $num = mysql_numrows($result); return $num; } function num_of_courses ($school_id) { $num_total = 0; $result = mysql_query("SELECT user_id FROM Users WHERE school_id='$school_id' && level>0"); while($row = mysql_fetch_array($result)) { $user_id = $row["user_id"]; $result_courses = mysql_query("SELECT course_id FROM Courses WHERE teacher='$user_id'"); $num = mysql_numrows($result_courses); $num_total = $num_total + $num; } return $num_total; } function size_of_files ($school_id) { $filesize_total = 0; $result = mysql_query("SELECT user_id FROM Users WHERE school_id='$school_id' && level>0"); while($row = mysql_fetch_array($result)){ $user_id = $row["user_id"]; $result_files = mysql_query("SELECT filesize FROM Files WHERE user_id='$user_id'"); while($row = mysql_fetch_array($result_files)){ $filesize = $row["filesize"]; $filesize_total = $filesize_total + $filesize; } } return $filesize_total; } function num_of_students_in_course ($course_id) { $result = mysql_query("SELECT user_id FROM Courses_Users WHERE course_id='$course_id'"); $num = mysql_numrows($result); return $num; } function num_of_files_in_course ($course_id) { $result = mysql_query("SELECT file_id FROM Files WHERE course_id='$course_id'"); $num = mysql_numrows($result); return $num; } function num_of_links_in_course ($course_id) { $result = mysql_query("SELECT link_id FROM Links WHERE course_id='$course_id'"); $num = mysql_numrows($result); return $num; } function num_of_messages_in_course ($course_id) { $result = mysql_query("SELECT message_id FROM Messages WHERE course_id='$course_id'"); $num = mysql_numrows($result); return $num; } function num_of_marks_in_course ($course_id) { $result = mysql_query("SELECT mark FROM Marks WHERE course_id='$course_id'"); $num = mysql_numrows($result); return $num; } function total_views_in_course ($course_id) { $result = mysql_query("SELECT total_views FROM Courses_Users WHERE course_id='$course_id'"); if(mysql_num_rows($result)>0) { $course_total_views = 0; while($row = mysql_fetch_array($result)) { $total_views = $row["total_views"]; $course_total_views = $course_total_views + $total_views; } } else { $course_total_views = 0; } return $course_total_views; } function student_num_of_courses ($student_id) { $result = mysql_query("SELECT course_id FROM Courses_Users WHERE user_id='$student_id'"); $num = mysql_numrows($result); return $num; } function delete_student ($student_id) { $result = mysql_query("DELETE FROM Marks WHERE user_id='$student_id'"); $result = mysql_query("DELETE FROM Messages WHERE user_id='$student_id'"); $result = mysql_query("DELETE FROM Topics WHERE user_id='$student_id'"); $result = mysql_query("DELETE FROM Links WHERE user_id='$student_id'"); $result = mysql_query("DELETE FROM Courses_Users WHERE user_id='$student_id'"); $result = mysql_query("DELETE FROM Users WHERE user_id='$student_id' AND level='0'"); } function delete_course ($course_id) { $result = mysql_query("DELETE FROM Messages WHERE course_id='$course_id'"); $result = mysql_query("DELETE FROM Topics WHERE course_id='$course_id'"); $result = mysql_query("DELETE FROM Links WHERE course_id='$course_id'"); $result = mysql_query("DELETE FROM Links_Folders WHERE course_id='$course_id'"); $result = mysql_query("DELETE FROM Marks WHERE course_id='$course_id'"); $result = mysql_query("DELETE FROM Lessons WHERE course_id='$course_id'"); $result = mysql_query("SELECT file_id FROM Files WHERE course_id='$course_id'"); while($row = mysql_fetch_array($result)){ $file_id = $row["file_id"]; delete_file($file_id); } $result = mysql_query("DELETE FROM Files WHERE course_id='$course_id'"); $result = mysql_query("DELETE FROM Files_Folders WHERE course_id='$course_id'"); $result = mysql_query("DELETE FROM Courses_Users WHERE course_id='$course_id'"); $result = mysql_query("DELETE FROM Courses WHERE course_id='$course_id'"); } function delete_file($file_id) { $result = mysql_query("DELETE FROM Files WHERE file_id='$file_id'"); $dir="../files/$file_id"; $current_dir = opendir($dir); while($entryname = readdir($current_dir)){ if(is_dir("$dir/$entryname") and ($entryname != "." and $entryname!="..")){ deldir("${dir}/${entryname}"); }elseif($entryname != "." and $entryname!=".."){ unlink("${dir}/${entryname}"); } } closedir($current_dir); rmdir(${dir}); } function delete_file_folder($folder_id) { $result = mysql_query("SELECT file_id FROM Files WHERE folder_id='$folder_id'"); while($row = mysql_fetch_array($result)){ $file_id = $row["file_id"]; delete_file($file_id); } $result = mysql_query("DELETE FROM Files_Folders WHERE folder_id='$folder_id'"); } function delete_teacher($teacher_id) { $result = mysql_query("SELECT course_id FROM Courses WHERE teacher='$teacher_id'"); while($row = mysql_fetch_array($result)){ $course_id = $row["course_id"]; delete_course($course_id); } $result = mysql_query("DELETE FROM Users WHERE user_id='$teacher_id' AND level='1'"); } function delete_school($school_id) { $result = mysql_query("SELECT user_id FROM Users WHERE school_id='$school_id' && level>0"); while($row = mysql_fetch_array($result)){ $user_id = $row["user_id"]; delete_teacher($user_id); } $result = mysql_query("SELECT user_id FROM Users WHERE school_id='$school_id' && level=0"); while($row = mysql_fetch_array($result)){ $user_id = $row["user_id"]; delete_student($user_id); } $result = mysql_query("DELETE FROM Forms WHERE school_id='$school_id'"); $result = mysql_query("DELETE FROM Schools WHERE school_id='$school_id'"); } function rename_uploaded_file ($uploaded_filename) { //Replace non-alphanumeric characters $length = strlen($uploaded_filename); $new_filename = ""; $i = 0; while ($i < $length) { $char = $uploaded_filename{$i}; if(!ctype_alnum($char)) { $ascii = ord($char); switch ($ascii) { case 40: $newchar = "("; break; case 41: $newchar = ")"; break; case 45: $newchar = "-"; break; case 32: case 95: $newchar = "_"; break; case 46: $newchar = "."; break; case 192: case 193: case 194: case 195: case 196: case 197: case 198: $newchar = "A"; break; case 210: case 211: case 212: case 213: case 214: $newchar = "O"; break; case 217: case 218: case 219: case 220: case 221: $newchar = "Y"; break; case 224: case 225: case 226: case 227: case 228: case 229: case 230: $newchar = "a"; break; case 242: case 243: case 244: case 245: case 246: $newchar = "o"; break; case 249: case 250: case 251: case 252: case 253: $newchar = "y"; break; default: $newchar = ""; } $new_filename = $new_filename.$newchar; } else { $new_filename = $new_filename.$char; } $i++; } //Replace double underscores while(strpos($new_filename, "__")) { $new_filename=str_replace("__","_",$new_filename); } //Change file extension to lowercase $dot_position = strpos($new_filename, "."); $filename = substr($new_filename, 0, $dot_position); $extensions = strtolower(substr($new_filename, $dot_position)); $new_filename = $filename.$extensions; //Change file extensions $new_filename=str_replace(".php",".txt",$new_filename); $new_filename=str_replace(".php3",".txt",$new_filename); $new_filename=str_replace(".php4",".txt",$new_filename); $new_filename=str_replace(".cgi",".txt",$new_filename); $new_filename=str_replace(".pl",".txt",$new_filename); $new_filename=str_replace(".phtml",".txt",$new_filename); $new_filename=str_replace(".shtml",".txt",$new_filename); return $new_filename; } ?>