/tags/1.0.3/system/application/controllers/upkeep.php

http://records-authority.googlecode.com/ · PHP · 335 lines · 209 code · 29 blank · 97 comment · 41 complexity · 484f67bdd09eb7afaa7d9349b9fcd688 MD5 · raw file

  1. <?php
  2. /**
  3. * Copyright 2008 University of Denver--Penrose Library--University Records Management Program
  4. * Author fernando.reyes@du.edu
  5. *
  6. * This file is part of Records Authority.
  7. *
  8. * Records Authority is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * Records Authority is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with Records Authority. If not, see <http://www.gnu.org/licenses/>.
  20. **/
  21. class Upkeep extends Controller {
  22. public function __construct() {
  23. parent::Controller();
  24. // admin user must be loggedin in order to use dashboard methods
  25. $this->load->model('SessionManager');
  26. $this->SessionManager->isAdminLoggedIn();
  27. $this->load->model('UpkeepModel');
  28. $this->load->model('LookUpTablesModel');
  29. $this->imagePath = base_url() . "images/ffd40f_11x11_icon_close.gif";
  30. }
  31. /**
  32. * displays division form
  33. *
  34. * @access public
  35. * @return void
  36. */
  37. public function divisionForm() {
  38. $data['divisions'] = $this->LookUpTablesModel->createDivisionDropDown();
  39. $this->load->view('admin/forms/addDivisionForm', $data);
  40. }
  41. /**
  42. * displays department form
  43. *
  44. * @access public
  45. * @return void
  46. */
  47. public function departmentForm() {
  48. $data['divisions'] = $this->LookUpTablesModel->createDivisionDropDown();
  49. $this->load->view('admin/forms/addDepartmentForm', $data);
  50. }
  51. /**
  52. * displays record category form
  53. *
  54. * @access public
  55. * @return void
  56. */
  57. public function recordCategoryForm() {
  58. $this->load->view('admin/forms/addRecordCategoryForm');
  59. }
  60. /**
  61. * displays user form
  62. *
  63. * @access public
  64. * @return void
  65. */
  66. public function userForm() {
  67. $this->load->view('admin/forms/addUserForm');
  68. }
  69. /**
  70. * displays edit division form
  71. *
  72. * @access public
  73. * @return $divisions
  74. */
  75. public function editDivisionForm() {
  76. $data['divisions'] = $this->LookUpTablesModel->createDivisionDropDown();
  77. $this->load->view('admin/forms/editDivisionForm', $data);
  78. }
  79. /**
  80. * displays edit department form
  81. *
  82. * @access public
  83. * @return $departments
  84. */
  85. public function editDepartmentForm() {
  86. $data['divisions'] = $this->LookUpTablesModel->createDivisionDropDown();
  87. $this->load->view('admin/forms/editDepartmentForm', $data);
  88. }
  89. /**
  90. * displays edit record categories form
  91. *
  92. * @access public
  93. * @return $recordCategories
  94. */
  95. public function editRecordCategoryForm() {
  96. $data['recordCategories'] = $this->UpkeepModel->getRecordCategories();
  97. $this->load->view('admin/forms/editRecordCategoryForm', $data);
  98. }
  99. /**
  100. * displays edit user form
  101. *
  102. * @access public
  103. * @return $users
  104. */
  105. public function editUserForm() {
  106. $data['users'] = $this->UpkeepModel->getUsers();
  107. $this->load->view('admin/forms/editUserForm', $data);
  108. }
  109. /**
  110. * displays edit password form
  111. *
  112. * @access public
  113. * @return $users
  114. */
  115. public function editPasswordForm() {
  116. $data['user'] = $this->session->userdata('username');
  117. $this->load->view('admin/forms/editPasswordForm', $data);
  118. }
  119. /**
  120. * displays add doc types form
  121. *
  122. * @access public
  123. * @return $docTypes
  124. */
  125. public function addDocTypeForm() {
  126. $data['docTypes'] = $this->UpkeepModel->getDocTypes();
  127. $this->load->view('admin/forms/addDocTypeForm', $data);
  128. }
  129. /**
  130. * displays edit doc types form
  131. *
  132. * @access public
  133. * @return $docTypes
  134. */
  135. public function editDocTypeForm() {
  136. $data['docTypes'] = $this->UpkeepModel->getDocTypes();
  137. $this->load->view('admin/forms/editDocTypeForm', $data);
  138. }
  139. /**
  140. * saves values to database from upkeep forms
  141. *
  142. * @access public
  143. * @return void
  144. */
  145. public function save() {
  146. if (isset($_POST['recordCategory'])) {
  147. $this->UpkeepModel->saveRecordCategory($_POST);
  148. $data['recordSaved'] = "Record Saved";
  149. $data['imagePath'] = $this->imagePath;
  150. $this->load->view('admin/displays/recordSaved', $data);
  151. }
  152. if (isset($_POST['divisionName'])) {
  153. $this->UpkeepModel->saveDivision($_POST);
  154. $data['recordSaved'] = "Record Saved";
  155. $data['divisions'] = $this->LookUpTablesModel->createDivisionDropDown();
  156. $this->load->view('admin/forms/addDivisionForm', $data);
  157. }
  158. if (isset($_POST['departmentName'])) {
  159. $this->UpkeepModel->saveDepartment($_POST);
  160. $data['recordSaved'] = "Record Saved";
  161. $data['divisions'] = $this->LookUpTablesModel->createDivisionDropDown();
  162. $this->load->view('admin/forms/addDepartmentForm', $data);
  163. }
  164. if (isset($_POST['docType'])) {
  165. $this->UpkeepModel->saveDocType($_POST);
  166. $data['recordSaved'] = "Record Saved";
  167. $data['docTypes'] = $this->UpkeepModel->getDocTypes();
  168. $this->load->view('admin/forms/addDocTypeForm', $data);
  169. }
  170. if (isset($_POST['username'])) {
  171. $this->UpkeepModel->saveUser($_POST);
  172. $data['recordSaved'] = "User Added";
  173. $data['imagePath'] = $this->imagePath;
  174. $this->load->view('admin/displays/recordSaved', $data);
  175. }
  176. }
  177. public function edit() {
  178. if (isset($_POST['divisionID']) && !isset($_POST['getDept']) && !isset($_POST['editDept'])) {
  179. $data['divisionName'] = $this->UpkeepModel->getDivision($_POST);
  180. $data['divisions'] = $this->LookUpTablesModel->createDivisionDropDown();
  181. $this->load->view('admin/forms/editDivisionForm', $data);
  182. }
  183. if (isset($_POST['divisionID']) && isset($_POST['getDept'])) {
  184. $data['departments'] = $this->UpkeepModel->getDepartments($_POST);
  185. $data['divisions'] = $this->LookUpTablesModel->createDivisionDropDown();
  186. $this->load->view('admin/forms/editDepartmentForm', $data);
  187. }
  188. if (isset($_POST['departmentID']) && isset($_POST['editDept']) && isset($_POST['divisionID'])) {
  189. $data['divisions'] = $this->LookUpTablesModel->createDivisionDropDown();
  190. $data['departments'] = $this->UpkeepModel->getDepartments($_POST);
  191. $data['departmentName'] = $this->UpkeepModel->getDepartment($_POST);
  192. $this->load->view('admin/forms/editDepartmentForm', $data);
  193. }
  194. if (isset($_POST['recordCategoryID'])) {
  195. $data['recordCategory'] = $this->UpkeepModel->getRecordCategory($_POST);
  196. $data['recordCategories'] = $this->UpkeepModel->getRecordCategories();
  197. $this->load->view('admin/forms/editRecordCategoryForm', $data);
  198. }
  199. if (isset($_POST['docTypeID'])) {
  200. $data['docTypes'] = $this->UpkeepModel->getDocTypes();
  201. $data['docType'] = $this->UpkeepModel->getDocType($_POST);
  202. $this->load->view('admin/forms/editDocTypeForm', $data);
  203. }
  204. if (isset($_POST['userID'])) {
  205. $data['user'] = $this->UpkeepModel->getUser($_POST);
  206. $data['users'] = $this->UpkeepModel->getUsers();
  207. $this->load->view('admin/forms/editUserForm', $data);
  208. }
  209. }
  210. public function update() {
  211. if (isset($_POST['divisionName'])) {
  212. $this->UpkeepModel->updateDivision($_POST);
  213. $data['divisions'] = $this->LookUpTablesModel->createDivisionDropDown();
  214. $data['recordUpdated'] = "Record Updated.";
  215. $this->load->view('admin/forms/editDivisionForm', $data);
  216. }
  217. if (isset($_POST['departmentName'])) {
  218. $this->UpkeepModel->updateDepartment($_POST);
  219. $data['divisions'] = $this->LookUpTablesModel->createDivisionDropDown();
  220. $data['recordUpdated'] = "Record Updated.";
  221. $this->load->view('admin/forms/editDepartmentForm', $data);
  222. }
  223. if (isset($_POST['recordCategory'])) {
  224. $this->UpkeepModel->updateRecordCategory($_POST);
  225. $data['recordCategories'] = $this->UpkeepModel->getRecordCategories();
  226. $data['recordUpdated'] = "Record Updated.";
  227. $this->load->view('admin/forms/editRecordCategoryForm', $data);
  228. }
  229. if (isset($_POST['docType'])) {
  230. $this->UpkeepModel->updateDocType($_POST);
  231. $data['docTypes'] = $this->UpkeepModel->getDocTypes();
  232. $data['recordUpdated'] = "Record Updated.";
  233. $this->load->view('admin/forms/editDocTypeForm', $data);
  234. }
  235. if (isset($_POST['username'])) {
  236. $this->UpkeepModel->updateUser($_POST);
  237. $data['users'] = $this->UpkeepModel->getUsers();
  238. $data['recordUpdated'] = "User Updated.";
  239. $this->load->view('admin/forms/editUserForm', $data);
  240. }
  241. if (isset($_POST['passcode'])) {
  242. $passtest = $this->UpkeepModel->checkOldPassword($_POST);
  243. if($passtest == TRUE) {
  244. if($_POST['passcode'] == $_POST['passtest']) {
  245. $this->UpkeepModel->updatePassword($_POST);
  246. $data['recordUpdated'] = "Password Changed.";
  247. } else {
  248. $data['recordUpdated'] = "Passwords did not match.";
  249. }
  250. } else {
  251. $data['recordUpdated'] = "Old Password did not match.";
  252. }
  253. $this->load->view('admin/forms/editPasswordForm',$data);
  254. }
  255. }
  256. public function delete() {
  257. // deletes division
  258. if ($this->uri->segment(3,0) == "delDiv") {
  259. $divisionID = $this->uri->segment(4, 0);
  260. $this->UpkeepModel->deleteDivision($divisionID);
  261. $data['divisions'] = $this->LookUpTablesModel->createDivisionDropDown();
  262. $data['recordUpdated'] = "Record Deleted.";
  263. $this->load->view('admin/forms/editDivisionForm', $data);
  264. }
  265. // deletes department
  266. if ($this->uri->segment(3,0) == "delDept") {
  267. $departmentID = $this->uri->segment(4, 0);
  268. $this->UpkeepModel->deleteDepartment($departmentID);
  269. $data['divisions'] = $this->LookUpTablesModel->createDivisionDropDown();
  270. $data['recordUpdated'] = "Record Deleted.";
  271. $this->load->view('admin/forms/editDepartmentForm', $data);
  272. }
  273. // deletes record category
  274. if ($this->uri->segment(3,0) == "delRecCat") {
  275. $recordCategoryID = $this->uri->segment(4, 0);
  276. $this->UpkeepModel->deleteRecordCategory($recordCategoryID);
  277. $data['recordCategories'] = $this->UpkeepModel->getRecordCategories();
  278. $data['recordUpdated'] = "Record Deleted.";
  279. $this->load->view('admin/forms/editRecordCategoryForm', $data);
  280. }
  281. // deletes doc type
  282. if ($this->uri->segment(3,0) == "delDocType") {
  283. $docTypeID = $this->uri->segment(4, 0);
  284. $this->UpkeepModel->deleteDocType($docTypeID);
  285. $data['docTypes'] = $this->UpkeepModel->getDocTypes();
  286. $data['recordUpdated'] = "Record Deleted.";
  287. $this->load->view('admin/forms/editDocTypeForm', $data);
  288. }
  289. // deletes user
  290. if ($this->uri->segment(3,0) == "delUser") {
  291. $userID = $this->uri->segment(4, 0);
  292. if($userID == "1")
  293. {
  294. $data['users'] = $this->UpkeepModel->getUsers();
  295. $data['recordUpdated'] = "Cannot Delete the Admin account.";
  296. $this->load->view('admin/forms/editUserForm', $data);
  297. } else {
  298. $this->UpkeepModel->deleteUser($userID);
  299. $data['users'] = $this->UpkeepModel->getUsers();
  300. $data['recordUpdated'] = "User Deleted.";
  301. $this->load->view('admin/forms/editUserForm', $data);
  302. }
  303. }
  304. }
  305. }
  306. ?>