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 |
||
|
50.1.1
by galaxyAbstractor
Started implementing categories and a menu |
31 |
function getMenu(){ |
32 |
$menu = array(); |
|
33 |
$courses = $this->db->get("courses"); |
|
34 |
foreach ($courses->result() as $course) { |
|
35 |
$menu[$course->name] = array(); |
|
36 |
$menu[$course->name]['CID'] = $course->courseID; |
|
37 |
$categories = $this->db->get_where("categories", array("courseID" => $course->courseID)); |
|
38 |
||
39 |
foreach($categories->result() as $category){ |
|
40 |
$menu[$course->name][$category->categoryName] = array(); |
|
41 |
||
42 |
$subcategories = $this->db->get_where("subcategories", array("courseID" => $course->courseID, "categoryName" => $category->categoryName)); |
|
43 |
||
44 |
foreach($subcategories->result() as $subcategory){ |
|
45 |
$menu[$course->name][$category->categoryName][$subcategory->subCategoryName] = array(); |
|
46 |
||
47 |
}
|
|
48 |
}
|
|
49 |
}
|
|
50 |
||
51 |
return $menu; |
|
52 |
||
53 |
}
|
|
54 |
||
55 |
function getCategories($cid) { |
|
56 |
$query = $this->db->get_where('Categories', array("courseID" => $cid)); |
|
57 |
return $query->result(); |
|
58 |
}
|
|
59 |
||
60 |
function addCategory($cid, $categoryName){ |
|
61 |
$this->db->select_max("orderNr"); |
|
62 |
$query = $this->db->get_where('Categories', array("courseID" => $cid)); |
|
63 |
||
64 |
$result = $query->result(); |
|
65 |
$data = array( |
|
66 |
'courseID' => $cid , |
|
67 |
'categoryName' => $categoryName, |
|
68 |
'orderNr' => $result[0]->orderNr+1 |
|
69 |
);
|
|
70 |
||
71 |
$this->db->insert('Categories', $data); |
|
72 |
//mkdir("../courses/".$cid."/".$example);
|
|
73 |
||
74 |
}
|
|
75 |
||
76 |
function getSubCategories($cid, $categoryName) { |
|
77 |
$query = $this->db->get_where('subcategories', array("courseID" => $cid, "categoryName" => $categoryName)); |
|
78 |
return $query->result(); |
|
79 |
}
|
|
80 |
||
81 |
function addSubCategory($cid, $categoryName, $subCategoryName){ |
|
82 |
$this->db->select_max("orderNr"); |
|
83 |
$query = $this->db->get_where('subcategories', array("courseID" => $cid, "categoryName" => $categoryName)); |
|
84 |
||
85 |
$result = $query->result(); |
|
86 |
$data = array( |
|
87 |
'courseID' => $cid , |
|
88 |
'subCategoryName' => $subCategoryName, |
|
89 |
'categoryName' => $categoryName, |
|
90 |
'orderNr' => $result[0]->orderNr+1 |
|
91 |
);
|
|
92 |
||
93 |
$this->db->insert('subcategories', $data); |
|
94 |
//mkdir("../courses/".$cid."/".$example);
|
|
95 |
||
96 |
}
|
|
97 |
||
98 |
function getExamples($cid, $categoryName, $subCategoryName) { |
|
99 |
$query = $this->db->get_where('Examples', array("courseID" => $cid, "categoryName" => $categoryName, "subCategoryName" => $subCategoryName)); |
|
100 |
return $query->result(); |
|
101 |
}
|
|
102 |
||
103 |
function addExample($cid, $categoryName, $subCategoryName, $example, $description){ |
|
104 |
$this->db->select_max("orderNr"); |
|
105 |
$query = $this->db->get_where('examples', array("courseID" => $cid, "categoryName" => $categoryName, "subCategoryName" => $subCategoryName)); |
|
106 |
$result = $query->result(); |
|
|
20.1.1
by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff |
107 |
$data = array( |
|
35.1.1
by Erik Elfstrand
Changed internal table names and attribute names to the correct names |
108 |
'courseID' => $cid , |
109 |
'exampleName' => $example, |
|
|
50.1.1
by galaxyAbstractor
Started implementing categories and a menu |
110 |
'description' => $description, |
111 |
'categoryName' => $categoryName, |
|
112 |
'subCategoryName' => $subCategoryName, |
|
113 |
'orderNr' => $result[0]->orderNr+1 |
|
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
114 |
);
|
|
20.1.1
by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff |
115 |
|
|
35.1.1
by Erik Elfstrand
Changed internal table names and attribute names to the correct names |
116 |
$this->db->insert('Examples', $data); |
|
20.1.1
by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff |
117 |
mkdir("../courses/".$cid."/".$example); |
118 |
||
119 |
}
|
|
120 |
||
121 |
function getPages($cid, $example) { |
|
|
35.1.1
by Erik Elfstrand
Changed internal table names and attribute names to the correct names |
122 |
$query = $this->db->get_where('Pages', array("courseID" => $cid, "exampleName" => $example)); |
|
20.1.1
by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff |
123 |
return $query->result(); |
124 |
}
|
|
125 |
||
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
126 |
function addPage($cid, $example, $page){ |
|
20.1.1
by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff |
127 |
$data = array( |
|
35.1.1
by Erik Elfstrand
Changed internal table names and attribute names to the correct names |
128 |
'courseID' => $cid , |
129 |
'exampleName' => $example, |
|
130 |
'pageName' => $page |
|
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
131 |
);
|
|
20.1.1
by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff |
132 |
|
|
35.1.1
by Erik Elfstrand
Changed internal table names and attribute names to the correct names |
133 |
$this->db->insert('Pages', $data); |
|
20.1.1
by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff |
134 |
mkdir("../courses/".$cid."/".$example."/".$page); |
135 |
||
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
136 |
$data = array( |
137 |
'fileName' => $cid."/".$example."/".$page."/documentation", |
|
|
35.1.1
by Erik Elfstrand
Changed internal table names and attribute names to the correct names |
138 |
'codeLanguage' => $file->lang, |
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
139 |
'fileType' => $file->type, |
140 |
'dataBlob' => $output |
|
141 |
);
|
|
142 |
||
|
35.1.1
by Erik Elfstrand
Changed internal table names and attribute names to the correct names |
143 |
$this->db->insert('Files', $data); |
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
144 |
|
145 |
$data = array( |
|
|
35.1.1
by Erik Elfstrand
Changed internal table names and attribute names to the correct names |
146 |
'fileName' => $cid."/".$example."/".$page."/documentation" , |
147 |
'pageName' => $page, |
|
148 |
'exampleName' => $example, |
|
149 |
'courseID' => $cid |
|
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
150 |
);
|
151 |
||
|
35.1.1
by Erik Elfstrand
Changed internal table names and attribute names to the correct names |
152 |
$this->db->insert('PageFiles', $data); |
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
153 |
|
|
20.1.1
by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff |
154 |
}
|
155 |
||
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
156 |
function updatePage($cid, $example, $page, $documentation, $files){ |
157 |
||
158 |
$filearr = json_decode($files); |
|
159 |
||
160 |
foreach ($filearr as $file) { |
|
161 |
$output = ""; |
|
162 |
$handle = @fopen("../courses/".$cid."/".$example."/".$page."/".$file->filename, "r"); |
|
163 |
if ($handle) { |
|
164 |
||
165 |
while (($buffer = fgets($handle, 4096)) !== false) { |
|
166 |
||
167 |
$buffer = str_replace("&", "&", $buffer); |
|
168 |
$buffer = str_replace("<", "<", $buffer); |
|
169 |
$buffer = str_replace(">", ">", $buffer); |
|
170 |
||
171 |
$output .= $buffer; |
|
172 |
}
|
|
173 |
if (!feof($handle)) { |
|
174 |
$output .= "Error: unexpected fgets() fail\n"; |
|
175 |
}
|
|
176 |
fclose($handle); |
|
177 |
}
|
|
178 |
||
179 |
$data = array( |
|
180 |
'fileName' => $file->filename , |
|
|
35.1.1
by Erik Elfstrand
Changed internal table names and attribute names to the correct names |
181 |
'codeLanguage' => $file->lang, |
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
182 |
'fileType' => $file->type, |
183 |
'dataBlob' => $output |
|
184 |
);
|
|
185 |
||
|
35.1.1
by Erik Elfstrand
Changed internal table names and attribute names to the correct names |
186 |
$this->db->insert('Files', $data); |
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
187 |
|
188 |
$data = array( |
|
|
35.1.1
by Erik Elfstrand
Changed internal table names and attribute names to the correct names |
189 |
'fileName' => $file->filename , |
190 |
'pageName' => $page, |
|
191 |
'exampleName' => $example, |
|
192 |
'courseID' => $cid |
|
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
193 |
);
|
194 |
||
|
35.1.1
by Erik Elfstrand
Changed internal table names and attribute names to the correct names |
195 |
$this->db->insert('PageFiles', $data); |
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
196 |
}
|
197 |
||
|
20.1.1
by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff |
198 |
$data = array( |
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
199 |
'dataBlob' => $documentation |
200 |
);
|
|
201 |
||
202 |
$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 |
203 |
$this->db->update('Files', $data); |
|
23.1.2
by galaxyAbstractor
Fixed database stuff, added files to database. |
204 |
|
205 |
||
|
20.1.1
by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff |
206 |
}
|
207 |
||
208 |
function uploadFile($files, $cid, $example, $page){ |
|
209 |
if(move_uploaded_file($files['tmp_name'], "../courses/".$cid."/".$example."/".$page."/".$files['name'])){ |
|
210 |
echo json_encode(array('status'=>'File was uploaded successfuly!')); |
|
211 |
}
|
|
212 |
}
|
|
213 |
}
|