summaryrefslogtreecommitdiff
path: root/getcode.php
blob: 2feaf4ac7c62fdc8c393a1f06aacc214d18691eb (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
<?php
	require_once('db-connect.php');
	if(isset($_REQUEST['eid'])) {
		$extensions = array('sce', 'sci');
		$data = "";
		$query = "select filepath from textbook_companion_dependency_files where id in (select dependency_id from textbook_companion_example_dependency where example_id=".$_REQUEST['eid'].")";
		$result = mysql_query($query);
		while($row = mysql_fetch_array($result)) {
			if(in_array(end(explode('.', $row['filepath'])), $extensions)) {
				$file = file_get_contents('../scilab_in_2015/uploads/'.$row['filepath'], true);
				$data .= $file;
			}
		}
		$query = "select filepath from textbook_companion_example_files where example_id=".$_REQUEST['eid'];
		$result = mysql_query($query);
		while($row = mysql_fetch_array($result)) {
			if(in_array(end(explode('.', $row['filepath'])), $extensions)) {
				$file = file_get_contents('../scilab_in_2015/uploads/'.$row['filepath'], true);
				$data .= $file;
			}
		}
        $query = "
            SELECT id FROM scilab_cloud_comment
            WHERE example = {$_REQUEST['eid']}
        ";
        $result = mysql_query($query);
        $nos = mysql_num_rows($result);
        
        echo json_encode(array(
            "code" => $data,
            "nos" => $nos
        ));
		exit;
	}else {
		echo "Invalid request!";
		exit;
	}
?>