bzr branch
http://gegoxaren.bato24.eu/bzr/lenasys/trunk
|
20.1.1
by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff |
1 |
<?php
|
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
2 |
/**
|
3 |
* This is a model. It holds the logic.
|
|
4 |
* It's loaded like this in the controllers: $this->load->model("path/to/model");
|
|
5 |
* This specific model is: $this->load->model("admin/admin_model")
|
|
6 |
*
|
|
7 |
* This model is the logic behind the admin panel. It let's you manage courses, pages etc
|
|
8 |
*/
|
|
|
20.1.1
by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff |
9 |
class Admin_model extends CI_Model { |
10 |
||
11 |
function __construct() { |
|
12 |
$this->load->database(); |
|
13 |
}
|
|
14 |
||
15 |
function getCourses() { |
|
|
35.1.1
by Erik Elfstrand
Changed internal table names and attribute names to the correct names |
16 |
$query = $this->db->get('Courses'); |
|
20.1.1
by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff |
17 |
return $query->result(); |
18 |
}
|
|
19 |
||
20 |
function addCourse($cid, $name){ |
|
21 |
$data = array( |
|
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
22 |
'courseID' => $cid , |
|
35.1.1
by Erik Elfstrand
Changed internal table names and attribute names to the correct names |
23 |
'name' => $name |
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
24 |
);
|
|
20.1.1
by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff |
25 |
|
|
35.1.1
by Erik Elfstrand
Changed internal table names and attribute names to the correct names |
26 |
$this->db->insert('Courses', $data); |
|
20.1.1
by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff |
27 |
mkdir("../courses/".$cid); |
28 |
||
29 |
}
|
|
30 |
||
|
64.1.1
by b11johgu
ExamplesController: |
31 |
function getExamples($cid) { |
32 |
$query = $this->db->get_where('Examples', array("courseID" => $cid)); |
|
33 |
return $query->result(); |
|
34 |
}
|
|
35 |
||
36 |
function addExample($cid, $example, $description){ |
|
|
20.1.1
by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff |
37 |
$data = array( |
|
35.1.1
by Erik Elfstrand
Changed internal table names and attribute names to the correct names |
38 |
'courseID' => $cid , |
39 |
'exampleName' => $example, |
|
|
64.1.1
by b11johgu
ExamplesController: |
40 |
'description' => $description |
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
41 |
);
|
|
20.1.1
by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff |
42 |
|
|
35.1.1
by Erik Elfstrand
Changed internal table names and attribute names to the correct names |
43 |
$this->db->insert('Examples', $data); |
|
64.1.1
by b11johgu
ExamplesController: |
44 |
mkdir("../courses/".$cid."/".$example); |
45 |
||
46 |
}
|
|
47 |
||
48 |
function getPages($cid, $example) { |
|
49 |
$query = $this->db->get_where('Pages', array("courseID" => $cid, "exampleName" => $example)); |
|
50 |
return $query->result(); |
|
51 |
}
|
|
52 |
||
53 |
function addPage($cid, $example, $page){ |
|
54 |
$data = array( |
|
55 |
'courseID' => $cid , |
|
56 |
'exampleName' => $example, |
|
57 |
'pageName' => $page |
|
58 |
);
|
|
59 |
||
60 |
$this->db->insert('Pages', $data); |
|
61 |
mkdir("../courses/".$cid."/".$example."/".$page); |
|
62 |
||
63 |
$data = array( |
|
64 |
'fileName' => $cid."/".$example."/".$page."/documentation", |
|
65 |
'codeLanguage' => $file->lang, |
|
66 |
'fileType' => $file->type, |
|
67 |
'dataBlob' => $output |
|
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
68 |
);
|
69 |
||
|
35.1.1
by Erik Elfstrand
Changed internal table names and attribute names to the correct names |
70 |
$this->db->insert('Files', $data); |
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
71 |
|
72 |
$data = array( |
|
|
64.1.1
by b11johgu
ExamplesController: |
73 |
'fileName' => $cid."/".$example."/".$page."/documentation" , |
74 |
'pageName' => $page, |
|
|
35.1.1
by Erik Elfstrand
Changed internal table names and attribute names to the correct names |
75 |
'exampleName' => $example, |
|
64.1.1
by b11johgu
ExamplesController: |
76 |
'courseID' => $cid |
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
77 |
);
|
78 |
||
|
64.1.1
by b11johgu
ExamplesController: |
79 |
$this->db->insert('PageFiles', $data); |
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
80 |
|
|
20.1.1
by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff |
81 |
}
|
82 |
||
|
64.1.1
by b11johgu
ExamplesController: |
83 |
function updatePage($cid, $example, $page, $documentation, $files){ |
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
84 |
|
85 |
$filearr = json_decode($files); |
|
86 |
||
87 |
foreach ($filearr as $file) { |
|
88 |
$output = ""; |
|
|
64.1.1
by b11johgu
ExamplesController: |
89 |
$handle = @fopen("../courses/".$cid."/".$example."/".$page."/".$file->filename, "r"); |
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
90 |
if ($handle) { |
91 |
||
92 |
while (($buffer = fgets($handle, 4096)) !== false) { |
|
93 |
||
94 |
$buffer = str_replace("&", "&", $buffer); |
|
95 |
$buffer = str_replace("<", "<", $buffer); |
|
96 |
$buffer = str_replace(">", ">", $buffer); |
|
97 |
||
98 |
$output .= $buffer; |
|
99 |
}
|
|
100 |
if (!feof($handle)) { |
|
101 |
$output .= "Error: unexpected fgets() fail\n"; |
|
102 |
}
|
|
103 |
fclose($handle); |
|
104 |
}
|
|
105 |
||
106 |
$data = array( |
|
|
64.1.1
by b11johgu
ExamplesController: |
107 |
'fileName' => $file->filename , |
|
35.1.1
by Erik Elfstrand
Changed internal table names and attribute names to the correct names |
108 |
'codeLanguage' => $file->lang, |
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
109 |
'fileType' => $file->type, |
110 |
'dataBlob' => $output |
|
111 |
);
|
|
112 |
||
|
35.1.1
by Erik Elfstrand
Changed internal table names and attribute names to the correct names |
113 |
$this->db->insert('Files', $data); |
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
114 |
|
115 |
$data = array( |
|
|
64.1.1
by b11johgu
ExamplesController: |
116 |
'fileName' => $file->filename , |
117 |
'pageName' => $page, |
|
|
35.1.1
by Erik Elfstrand
Changed internal table names and attribute names to the correct names |
118 |
'exampleName' => $example, |
|
64.1.1
by b11johgu
ExamplesController: |
119 |
'courseID' => $cid |
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
120 |
);
|
121 |
||
|
64.1.1
by b11johgu
ExamplesController: |
122 |
$this->db->insert('PageFiles', $data); |
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
123 |
}
|
124 |
||
|
20.1.1
by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff |
125 |
$data = array( |
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
126 |
'dataBlob' => $documentation |
127 |
);
|
|
128 |
||
|
64.1.1
by b11johgu
ExamplesController: |
129 |
$this->db->where("fileName",$cid."/".$example."/".$page."/"."documentation" ); |
|
35.1.1
by Erik Elfstrand
Changed internal table names and attribute names to the correct names |
130 |
$this->db->update('Files', $data); |
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
131 |
|
132 |
||
|
20.1.1
by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff |
133 |
}
|
134 |
||
|
64.1.1
by b11johgu
ExamplesController: |
135 |
function uploadFile($files, $cid, $example, $page){ |
136 |
if(move_uploaded_file($files['tmp_name'], "../courses/".$cid."/".$example."/".$page."/".$files['name'])){ |
|
|
20.1.1
by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff |
137 |
echo json_encode(array('status'=>'File was uploaded successfuly!')); |
138 |
}
|
|
139 |
}
|
|
140 |
}
|