/lenasys/trunk

To get this branch, use:
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
2
3
class Admin extends CI_Controller {
4
23.1.2 by galaxyAbstractor
Fixed database stuff, added files to database.
5
	/*
6
	* This is the index function. It will be the one called if you do not specify a
7
	* function in the url, example: /admin/
8
	*/
20.1.1 by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff
9
	public function index() {
10
		$this->load->model('admin/Admin_model');
11
		$courses = $this->Admin_model->getCourses();
50.1.1 by galaxyAbstractor
Started implementing categories and a menu
12
		$menu = $this->Admin_model->getMenu();
23.1.1 by galaxyAbstractor
Removed codeigniter user guide, shouldn't be in the repo
13
		$this->load->view('admin/header', array("title" => "Index"));
50.1.1 by galaxyAbstractor
Started implementing categories and a menu
14
		$this->load->view('admin/menu', array("menu" => $menu));
20.1.1 by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff
15
		$this->load->view('admin/index', array("courses" => $courses));
50.1.1 by galaxyAbstractor
Started implementing categories and a menu
16
	} 
20.1.1 by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff
17
50.1.1 by galaxyAbstractor
Started implementing categories and a menu
18
	public function addCourse() {
19
		$this->load->model('admin/Admin_model');
20.1.1 by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff
20
		if(!isset($_POST['cid'])){
21
			$this->load->helper('form');
23.1.1 by galaxyAbstractor
Removed codeigniter user guide, shouldn't be in the repo
22
			$this->load->view('admin/header', array("title" => "Add course"));
50.1.1 by galaxyAbstractor
Started implementing categories and a menu
23
			$menu = $this->Admin_model->getMenu();
24
			$this->load->view('admin/menu', array("menu" => $menu));
20.1.1 by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff
25
			$this->load->view('admin/add_course');
26
		} else {
50.1.1 by galaxyAbstractor
Started implementing categories and a menu
27
			
20.1.1 by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff
28
			$this->Admin_model->addCourse($_POST['cid'], $_POST['name']);
29
			redirect("admin/");
30
		}
31
	}
32
33
	public function manageCourse($cid) {
50.1.1 by galaxyAbstractor
Started implementing categories and a menu
34
		$cid = urldecode($cid);
20.1.1 by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff
35
		$this->load->model('admin/Admin_model');
50.1.1 by galaxyAbstractor
Started implementing categories and a menu
36
		$categories = $this->Admin_model->getCategories($cid);
23.1.1 by galaxyAbstractor
Removed codeigniter user guide, shouldn't be in the repo
37
		$this->load->view('admin/header', array("title" => "Manage course - ".$cid));
50.1.1 by galaxyAbstractor
Started implementing categories and a menu
38
		$menu = $this->Admin_model->getMenu();
39
		$this->load->view('admin/menu', array("menu" => $menu));
40
		$this->load->view('admin/manage_course', array("categories" => $categories, "cid" => $cid));
41
	}
42
43
	public function addCategory($cid){
44
		$cid = urldecode($cid);
45
		$this->load->model('admin/Admin_model');
46
		if(!isset($_POST['categoryName'])){
47
			$this->load->helper('form');
48
			$this->load->view('admin/header', array("title" => "Add category"));
49
			$menu = $this->Admin_model->getMenu();
50
			$this->load->view('admin/menu', array("menu" => $menu));
51
			$this->load->view('admin/add_category', array("cid" => $cid));
52
		} else {
53
			
54
			$this->Admin_model->addCategory($_POST['cid'], $_POST['categoryName']);
55
			redirect("admin/");
56
		}
57
	}
58
59
	public function manageCategory($cid, $categoryName) {
60
		$cid = urldecode($cid);
61
		$categoryName = urldecode($categoryName);
62
		$this->load->model('admin/Admin_model');
63
		$subcategories = $this->Admin_model->getSubCategories($cid,  $categoryName);
64
		$this->load->view('admin/header', array("title" => "Manage category - ".$cid." - ". $categoryName));
65
		$menu = $this->Admin_model->getMenu();
66
		$this->load->view('admin/menu', array("menu" => $menu));
67
		$this->load->view('admin/manage_category', array("subcategories" => $subcategories, "cid" => $cid, "categoryName" => $categoryName));
68
	}
69
70
	public function addSubCategory($cid, $categoryName){
71
		$cid = urldecode($cid);
72
		$categoryName = urldecode($categoryName);
73
		$this->load->model('admin/Admin_model');
74
		if(!isset($_POST['subcategoryname'])){
75
			$this->load->helper('form');
76
			$this->load->view('admin/header', array("title" => "Add subcategory"));
77
			$menu = $this->Admin_model->getMenu();
78
			$this->load->view('admin/menu', array("menu" => $menu));
79
			$this->load->view('admin/add_sub_category', array("cid" => $cid, "category" => $categoryName));
80
		} else {
20.1.1 by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff
81
		
50.1.1 by galaxyAbstractor
Started implementing categories and a menu
82
			$this->Admin_model->addSubCategory($_POST['cid'], $_POST['category'], $_POST['subcategoryname']);
83
			redirect("admin/");
84
		}
85
	}
86
87
	public function manageSubCategory($cid, $categoryName, $subCategoryName) {
88
		$cid = urldecode($cid);
89
		$categoryName = urldecode($categoryName);
90
		$subCategoryName = urldecode($subCategoryName);
91
		$this->load->model('admin/Admin_model');
92
		$examples = $this->Admin_model->getExamples($cid,  $categoryName, $subCategoryName);
93
		$this->load->view('admin/header', array("title" => "Manage category - ".$cid." - ". $categoryName));
94
		$menu = $this->Admin_model->getMenu();
95
		$this->load->view('admin/menu', array("menu" => $menu));
96
		$this->load->view('admin/manage_sub_category', array("examples" => $examples, "cid" => $cid, "categoryName" => $categoryName, "subCategoryName" => $subCategoryName));
97
	}
98
99
	public function addExample($cid, $categoryName, $subCategoryName){
100
		$cid = urldecode($cid);
101
		$categoryName = urldecode($categoryName);
102
		$subCategoryName = urldecode($subCategoryName);
103
		$this->load->model('admin/Admin_model');
20.1.1 by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff
104
		if(!isset($_POST['example'])){
105
			$this->load->helper('form');
23.1.1 by galaxyAbstractor
Removed codeigniter user guide, shouldn't be in the repo
106
			$this->load->view('admin/header', array("title" => "Add example"));
50.1.1 by galaxyAbstractor
Started implementing categories and a menu
107
			$menu = $this->Admin_model->getMenu();
108
			$this->load->view('admin/menu', array("menu" => $menu));
109
			$this->load->view('admin/add_example', array("cid" => $cid, "categoryName" => $categoryName, "subCategoryName" => $subCategoryName));
20.1.1 by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff
110
		} else {
50.1.1 by galaxyAbstractor
Started implementing categories and a menu
111
			
112
			$this->Admin_model->addExample($_POST['cid'],  $_POST['categoryName'], $_POST['subCategoryName'], $_POST['example'], $_POST['description']);
20.1.1 by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff
113
			redirect("admin/");
114
		}
115
	}
116
117
	public function manageExample($cid, $example) {
50.1.1 by galaxyAbstractor
Started implementing categories and a menu
118
		$cid = urldecode($cid);
119
		$example = urldecode($example);
20.1.1 by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff
120
		$this->load->model('admin/Admin_model');
121
		$pages = $this->Admin_model->getPages($cid, $example);
23.1.1 by galaxyAbstractor
Removed codeigniter user guide, shouldn't be in the repo
122
		$this->load->view('admin/header', array("title" => "Manage example - ".$example." - ".$cid));
50.1.1 by galaxyAbstractor
Started implementing categories and a menu
123
		$menu = $this->Admin_model->getMenu();
124
		$this->load->view('admin/menu', array("menu" => $menu));
20.1.1 by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff
125
		$this->load->view('admin/manage_example', array("pages" => $pages, "cid" => $cid, "example" => $example));
126
	}
127
128
	public function addPage($cid, $example){
50.1.1 by galaxyAbstractor
Started implementing categories and a menu
129
		$cid = urldecode($cid);
130
		$example = urldecode($example);
131
		if(!isset($_POST['page'])) {
20.1.1 by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff
132
			$this->load->helper('form');
23.1.1 by galaxyAbstractor
Removed codeigniter user guide, shouldn't be in the repo
133
			$this->load->view('admin/header', array("title" => "Add page"));
50.1.1 by galaxyAbstractor
Started implementing categories and a menu
134
			$menu = $this->Admin_model->getMenu();
135
			$this->load->view('admin/menu', array("menu" => $menu));
20.1.1 by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff
136
			$this->load->view('admin/add_page', array("cid" => $cid, "example" => $example));
137
		} else {
138
			$this->load->model('admin/Admin_model');
23.1.2 by galaxyAbstractor
Fixed database stuff, added files to database.
139
			$this->Admin_model->addPage($_POST['cid'], $_POST['example'],$_POST['page']);
20.1.1 by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff
140
			redirect("admin/");
141
		}
142
	}
143
144
	public function managePage($cid, $example, $page) {
50.1.1 by galaxyAbstractor
Started implementing categories and a menu
145
		$cid = urldecode($cid);
146
		$example = urldecode($example);
147
		$page = urldecode($page);
20.1.1 by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff
148
		if(!isset($_POST['documentation'])){
149
			$this->load->helper('form');
23.1.1 by galaxyAbstractor
Removed codeigniter user guide, shouldn't be in the repo
150
151
			$this->load->model('codeviewer/Codeviewer_model');
152
23.1.2 by galaxyAbstractor
Fixed database stuff, added files to database.
153
			
154
			$editorHTML = $this->Codeviewer_model->getCode($cid, $example, $page);
23.1.1 by galaxyAbstractor
Removed codeigniter user guide, shouldn't be in the repo
155
23.1.2 by galaxyAbstractor
Fixed database stuff, added files to database.
156
			//$doc = $this->Codeviewer_model->getDoc($cid, $example, $page);
23.1.1 by galaxyAbstractor
Removed codeigniter user guide, shouldn't be in the repo
157
158
			$this->load->view('admin/header', array("editors" => $editorHTML, "title" => "Manage page - ".$page." - ".$example." - ".$cid));
23.1.2 by galaxyAbstractor
Fixed database stuff, added files to database.
159
			$this->load->view('admin/manage_page', array("cid" => $cid, "example" => $example, "page" => $page /*,"documentation" => $doc*/));
20.1.1 by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff
160
		} else {
161
			$this->load->model('admin/Admin_model');
23.1.2 by galaxyAbstractor
Fixed database stuff, added files to database.
162
			$this->Admin_model->updatePage($_POST['cid'], $_POST['example'],$_POST['page'], $_POST['documentation'], $_POST['files']);
20.1.1 by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff
163
			redirect("admin/");
164
		}
165
	}
166
167
	public function uploadFile($cid, $example, $page) {
50.1.1 by galaxyAbstractor
Started implementing categories and a menu
168
		$cid = urldecode($cid);
169
		$example = urldecode($example);
170
		$page = urldecode($page);
20.1.1 by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff
171
		$this->load->model('admin/Admin_model');
172
		$this->Admin_model->uploadFile($_FILES['files'],$cid, $example, $page);
173
	}
174
175
}