/controllers/dataentry.php

https://github.com/ashwanthkumar/webnaplo · PHP · 439 lines · 223 code · 69 blank · 147 comment · 34 complexity · 9989c8b6c2f66bef1063c18ecad60d47 MD5 · raw file

  1. <?php
  2. /**
  3. * DataEntry Controller for performing various functions by Dataentry user
  4. *
  5. * @author Team WebNaplo
  6. * @date 11/11/2011
  7. * @since 1.0
  8. **/
  9. /**
  10. * Data Entry Home Page
  11. *
  12. * @method GET
  13. * @route /dataentry/home/
  14. **/
  15. function dataentry_home() {
  16. layout('dataentry/layout.html.php');
  17. set("title" ,"Data Entry - Home");
  18. set("home_active" ,"true");
  19. return render("dataentry/dataentry.home.html.php");
  20. }
  21. /**
  22. * Add Student View Page
  23. *
  24. * @method GET
  25. * @route /dataentry/student/add/
  26. **/
  27. function dataentry_add_student_render() {
  28. layout('dataentry/layout.html.php');
  29. set("title" ,"Add student");
  30. set("add_active" ,"true");
  31. return render("dataentry/add.student.html.php");
  32. }
  33. /**
  34. * Add Student to the system
  35. *
  36. * @method POST
  37. * @route /dataentry/student/add/
  38. **/
  39. function dataentry_add_student_post() {
  40. $db = $GLOBALS['db'];
  41. // $did = $_POST['dept_FK'];
  42. extract($_POST);
  43. // Delete the student static function to delete the object
  44. $r = Student::LoadAndSave($_POST, $db);
  45. if(is_object($r) && get_class($r) == "PDOException") {
  46. switch($r->getCode()) {
  47. case 23000:
  48. flash('error', "Student with the register number already exist");
  49. break;
  50. default:
  51. flash('error', 'There was an error adding a student, please try again later.');
  52. break;
  53. }
  54. return redirect('/dataentry/student/add');
  55. }
  56. flash('success', "Student $name has been successfully added");
  57. // Redirect the user back
  58. return redirect('/dataentry/student/add');
  59. }
  60. /**
  61. * Add Department View Page
  62. *
  63. * @method GET
  64. * @route /dataentry/department/add/
  65. **/
  66. function dataentry_add_department_render() {
  67. layout('dataentry/layout.html.php');
  68. set("title" ,"Add Department");
  69. set("add_active" ,"true");
  70. return render("dataentry/add.department.html.php");
  71. }
  72. /**
  73. * Add Department to the system
  74. *
  75. * @method POST
  76. * @route /dataentry/department/add/
  77. **/
  78. function dataentry_add_department_post() {
  79. extract($_POST);
  80. if(strlen(trim($name)) < 1) {
  81. flash('error', "Please enter valid Department name");
  82. } else {
  83. $db = $GLOBALS['db'];
  84. // Delete the department static function to delete the object
  85. $department = Department::LoadAndSave($_POST, $db);
  86. if(!$department) {
  87. flash('error', "$name Department already exists");
  88. } else {
  89. flash('success', "Department $name has been successfully added");
  90. }
  91. }
  92. // Redirect the user back
  93. return redirect('/dataentry/department/add');
  94. }
  95. /**
  96. * Method actings as an AJAX proxy during Student Addition
  97. *
  98. * @method GET
  99. * @route /dataentry/student/add/proxy
  100. **/
  101. function dataentry_add_student_proxy() {
  102. $db = $GLOBALS['db'];
  103. // Get the list of programmes for the given department
  104. if(isset($_GET['dept'])) {
  105. $d = $_GET['dept'];
  106. // header("Content-type: application/json");
  107. $pgms = $db->select("programme", "dept_id = :d", array(":d" => $d));
  108. return json(array("data" => $pgms));
  109. }
  110. if(isset($_GET['pgm'])) {
  111. $p = $_GET['pgm'];
  112. $class = $db->select("class", "programme_id = :p", array(":p" => $p));
  113. return json(array("data" => $class));
  114. }
  115. }
  116. /**
  117. * Add programme View page
  118. *
  119. * @method GET
  120. * @route /dataentry/programme/add/
  121. **/
  122. function dataentry_add_programme_render() {
  123. layout('dataentry/layout.html.php');
  124. set("title" ,"Add Programme");
  125. set("add_active" ,"true");
  126. return render("dataentry/add.programme.html.php");
  127. }
  128. /**
  129. * Add Programme to the system
  130. *
  131. * @method POST
  132. * @route /dataentry/programme/add/
  133. **/
  134. function dataentry_add_programme_post() {
  135. // $did = $_POST['dept_FK'];
  136. extract($_POST);
  137. $db = $GLOBALS['db'];
  138. // Delete the programme static function to delete the object
  139. $r = Programme::LoadAndSave($_POST, $db);
  140. if(is_bool($r) && $r == false) {
  141. flash('warning', 'Programme already exist. Please try with another name');
  142. return redirect('/dataentry/programme/add');
  143. }
  144. if(is_object($r) && get_class($r) == "PDOException") {
  145. flash('error', 'Programme cannot be created. Please try again. Error: ' . $r->getMessage());
  146. return redirect('/dataentry/programme/add');
  147. }
  148. flash('success', "Programme $name has been successfully added");
  149. // Redirect the user back
  150. return redirect('/dataentry/programme/add');
  151. }
  152. /**
  153. * Add Section View page
  154. *
  155. * @method GET
  156. * @route /dataentry/section/add/
  157. **/
  158. function dataentry_add_section_render() {
  159. layout('dataentry/layout.html.php');
  160. set("title" ,"Add Section");
  161. set("add_active" ,"true");
  162. return render("dataentry/add.section.html.php");
  163. }
  164. /**
  165. * Add Section View page
  166. *
  167. * @method POST
  168. * @route /dataentry/section/add/
  169. **/
  170. function dataentry_add_section_post() {
  171. // $did = $_POST['dept_FK'];
  172. extract($_POST);
  173. $db = $GLOBALS['db'];
  174. // Delete the section static function to delete the object
  175. $r = Section::LoadAndSave($_POST, $db);
  176. if(is_bool($r) && $r == false) {
  177. flash('warning', 'Section already exist. Please try with another name');
  178. return redirect('/dataentry/section/add');
  179. }
  180. if(is_object($r) && get_class($r) == "PDOException") {
  181. flash('error', 'Section cannot be created. Please try again. Error: ' . $r->getMessage());
  182. return redirect('/dataentry/section/add');
  183. }
  184. flash('success', "Section $name has been successfully added");
  185. // Redirect the user back
  186. return redirect('/dataentry/section/add');
  187. }
  188. /**
  189. * Add Staff View Page
  190. *
  191. * @method GET
  192. * @route /dataentry/staff/add/
  193. **/
  194. function dataentry_add_staff_render() {
  195. layout('dataentry/layout.html.php');
  196. set("title" ,"Add Staff");
  197. set("add_active" ,"true");
  198. return render("dataentry/add.staff.html.php");
  199. }
  200. /**
  201. * Add Staff to the system
  202. *
  203. * @method POST
  204. * @route /dataentry/staff/add/
  205. **/
  206. function dataentry_add_staff_post() {
  207. // $did = $_POST['dept_FK'];
  208. extract($_POST);
  209. // Delete the staff static function to delete the object
  210. $r = Staff::LoadAndSave($_POST, $GLOBALS['db']);
  211. if(is_bool($r) && $r == false) {
  212. flash('warning', 'Staff with $staff_id already exist. Please try with another name');
  213. return redirect('/dataentry/staff/add');
  214. }
  215. if(is_object($r) && get_class($r) == "PDOException") {
  216. flash('error', 'Staff cannot be created. Please try again. Error: ' . $r->getMessage());
  217. return redirect('/dataentry/staff/add');
  218. }
  219. flash('success', "Staff $name has been successfully added");
  220. // Redirect the user back
  221. return redirect('/dataentry/staff/add');
  222. }
  223. /**
  224. * Add Course View Page
  225. *
  226. * @method GET
  227. * @route /dataentry/course/add/
  228. **/
  229. function dataentry_add_course_render() {
  230. layout('dataentry/layout.html.php');
  231. set("title" ,"Add Course");
  232. set("add_active" ,"true");
  233. return render("dataentry/add.course.html.php");
  234. }
  235. /**
  236. * Add Course to the system
  237. *
  238. * @method POST
  239. * @route /dataentry/course/add/
  240. **/
  241. function dataentry_add_course_post() {
  242. // $did = $_POST['dept_FK'];
  243. extract($_POST);
  244. $r = Course::LoadAndSave($_POST, $GLOBALS['db']);
  245. print_r($r);
  246. if(is_bool($r) && $r === FALSE) {
  247. flash('warning', "Course with Course Code ($coursecode) already exist. Please try with another name");
  248. return redirect('/dataentry/course/add');
  249. }
  250. if(is_object($r) && get_class($r) == "PDOException") {
  251. // flash('error', "Course cannot be created. Please try again. Error: " . $r->getMessage());
  252. halt(SERVER_ERROR, $r->getMessage());
  253. // return redirect('/dataentry/course/add');
  254. }
  255. flash('success', "Course $coursename has been successfully added");
  256. // Redirect the user back
  257. return redirect('/dataentry/course/add');
  258. }
  259. /**
  260. * Change the password of the dataentry user
  261. *
  262. * @method POST
  263. * @route /dataentry/changepass/
  264. **/
  265. function dataentry_changepass() {
  266. if(isset($_POST['newPass'])) {
  267. $newPass = $_POST['newPass'];
  268. flash('success', "Your password has been successfully updated");
  269. Configuration::put(Configuration::$CONFIG_DATAENTRY_PASSWORD, $newPass, $GLOBALS['db']);
  270. return redirect("/dataentry/home");
  271. } else {
  272. return redirect("/dataentry/home");
  273. }
  274. }
  275. /**
  276. * List Staff Members of the system
  277. *
  278. * @method GET
  279. * @route /dataentry/staff/list/
  280. **/
  281. function dataentry_list_staff_render() {
  282. return list_staff_render();
  283. }
  284. function list_staff_render() {
  285. $user = get_user();
  286. layout($user->type . '/layout.html.php');
  287. set('title', "Staff List");
  288. set('list_active', "true");
  289. return render("/dataentry/dataentry.list.staff.php");
  290. }
  291. /**
  292. * List All Programmes of the system
  293. *
  294. * @method GET
  295. * @route /dataentry/programme/list/
  296. **/
  297. function dataentry_list_programme_render() {
  298. return list_programme_render();
  299. }
  300. function list_programme_render() {
  301. $user = get_user();
  302. layout($user->type . '/layout.html.php');
  303. set('title', "Programme List");
  304. set('list_active', "true");
  305. return render("/dataentry/dataentry.list.programme.php");
  306. }
  307. /**
  308. * List all Courses of the system
  309. *
  310. * @method GET
  311. * @route /dataentry/course/list/
  312. **/
  313. function dataentry_list_course_render() {
  314. return list_course_render();
  315. }
  316. function list_course_render() {
  317. $user = get_user();
  318. layout($user->type . '/layout.html.php');
  319. set('title', "Course List");
  320. set('list_active', "true");
  321. return render("/dataentry/dataentry.list.course.php");
  322. }
  323. /**
  324. * Used by wkhtmltopdf for generating PDFs in the system
  325. *
  326. * @method GET
  327. * @route /dataentry/report/list/:type
  328. **/
  329. function dataentry_report_list() {
  330. $type = params('type');
  331. return render("/dataentry/export/dataentry.$type.list.html.php");
  332. }
  333. /**
  334. * Used to initiate the export operation using wkhtmltopdf
  335. *
  336. * @method GET
  337. * @route /dataentry/export/list/:type
  338. **/
  339. function dataentry_export_list() {
  340. $type = params('type');
  341. switch($type) {
  342. case "staff":
  343. $print_url = "http://" . $_SERVER['SERVER_NAME'] . url_for('/admin/report/list/staff');
  344. $pdf_path = WTK::exportPDF($print_url);
  345. return render_file($pdf_path);
  346. break;
  347. case "programme":
  348. $print_url = "http://" . $_SERVER['SERVER_NAME'] . url_for('/admin/report/list/programme');
  349. $pdf_path = WTK::exportPDF($print_url);
  350. return render_file($pdf_path);
  351. break;
  352. case "student":
  353. $print_url = "http://" . $_SERVER['SERVER_NAME'] . url_for('/admin/report/list/student');
  354. $pdf_path = WTK::exportPDF($print_url);
  355. return render_file($pdf_path);
  356. break;
  357. case "section":
  358. $print_url = "http://" . $_SERVER['SERVER_NAME'] . url_for('/admin/report/list/section');
  359. $pdf_path = WTK::exportPDF($print_url);
  360. return render_file($pdf_path);
  361. break;
  362. case "course":
  363. $print_url = "http://" . $_SERVER['SERVER_NAME'] . url_for('/admin/report/list/course');
  364. $pdf_path = WTK::exportPDF($print_url);
  365. return render_file($pdf_path);
  366. break;
  367. default:
  368. break;
  369. }
  370. }