PageRenderTime 46ms CodeModel.GetById 4ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/1.2.4/system/application/models/retentionschedulemodel.php

http://records-authority.googlecode.com/
PHP | 1002 lines | 538 code | 83 blank | 381 comment | 53 complexity | 155bc4894e706508c1931807186cc07d MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1
  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 RetentionScheduleModel extends Model {
  22. public function __construct() {
  23. parent::Model();
  24. $this->devEmail = $this->config->item('devEmail');
  25. }
  26. /**
  27. * invokes getRecordInformationQuery();
  28. *
  29. * @param $recordInformationID
  30. * @return $recordInformation
  31. */
  32. public function getRecordInformation($recordInformationID) {
  33. $recordInformation = $this->getRecordInformationQuery($recordInformationID);
  34. return $recordInformation;
  35. }
  36. /**
  37. * gets record information
  38. *
  39. * @param $recordInformationID
  40. * @return $recordInformation
  41. */
  42. private function getRecordInformationQuery($recordInformationID) {
  43. $this->db->select('recordInformationID, recordName, recordDescription, recordCategory, managementDivisionID, managementDepartmentID, vitalRecord');
  44. $this->db->from('rm_recordType');
  45. $this->db->where('recordInformationID', $recordInformationID);
  46. $recordInformationQuery = $this->db->get();
  47. $recordInformation = array();
  48. if ($recordInformationQuery->num_rows > 0) {
  49. foreach ($recordInformationQuery->result() as $recordInformationResults) {
  50. $recordInformation['recordInformationID'] = $recordInformationResults->recordInformationID;
  51. $recordInformation['recordName'] = $recordInformationResults->recordName;
  52. $recordInformation['recordDescription'] = $recordInformationResults->recordDescription;
  53. $recordInformation['recordCategory'] = $recordInformationResults->recordCategory;
  54. $recordInformation['managementDivisionID'] = $recordInformationResults->managementDivisionID;
  55. $recordInformation['managementDepartmentID'] = $recordInformationResults->managementDepartmentID;
  56. $recordInformation['vitalRecord'] = $recordInformationResults->vitalRecord;
  57. }
  58. return $recordInformation;
  59. } else {
  60. //send_email($this->devEmail, 'RecordsAuthority_Error', 'database error: unable to pull record information into retention schedule form - getRecordInformationQuery()');
  61. $recordInformation = "Unable to render retention schedule form.";
  62. return $recordInformation;
  63. }
  64. }
  65. /**
  66. * invokes getRetentionInformationKeywordQuery();
  67. *
  68. * @param $keyword
  69. * @return $retentionInformation
  70. */
  71. public function getRetentionInformationKeyword($keyword) {
  72. $retentionInformation = $this->getRetentionInformationKeywordQuery($keyword);
  73. return $retentionInformation;
  74. }
  75. /**
  76. * gets retention information based on keyword
  77. *
  78. * @param $keyword
  79. * @return $retentionInformation
  80. */
  81. private function getRetentionInformationKeywordQuery($keyword) {
  82. $this->db->select(' retentionScheduleID,
  83. recordCode,
  84. recordName,
  85. recordCategory,
  86. recordDescription,
  87. keywords,
  88. officeOfPrimaryResponsibility,
  89. primaryOwnerOverride,
  90. uuid,
  91. approvedByCounsel');
  92. $this->db->from('rm_retentionSchedule');
  93. //Check for Search all with *
  94. if($keyword != '*') {
  95. $this->db->where('MATCH(
  96. uuid,
  97. recordCode,
  98. recordName,
  99. recordDescription,
  100. recordCategory,
  101. keywords,
  102. retentionPeriod,
  103. primaryAuthorityRetention,
  104. retentionNotes,
  105. retentionDecisions,
  106. disposition,
  107. primaryAuthority,
  108. primaryOwnerOverride,
  109. notes,
  110. approvedByCounsel,
  111. approvedByCounselDate)
  112. AGAINST ("*' . $keyword . '*" IN BOOLEAN MODE)');
  113. }
  114. $this->db->order_by('recordName','asc');
  115. $retentionInformation = $this->db->get();
  116. return $retentionInformation;
  117. }
  118. /**
  119. * invokes getDispositionsQuery()
  120. *
  121. * @return $dispositions
  122. */
  123. public function getDispositions() {
  124. $dispositions = $this->getDispostionsQuery();
  125. return $dispositions;
  126. }
  127. /**
  128. * gets dispositions
  129. *
  130. * @return $dispositions
  131. */
  132. private function getDispostionsQuery() {
  133. $this->db->select('dispositionID, dispositionLong');
  134. $this->db->from('rm_disposition');
  135. $dispositionQuery = $this->db->get();
  136. $dispositions = array();
  137. $dispositionsLong = array();
  138. $dispositionsDescription = array();
  139. if ($dispositionQuery->num_rows > 0) {
  140. foreach ($dispositionQuery->result() as $disposition) {
  141. $dispositions[$disposition->dispositionID] = $disposition->dispositionLong;
  142. }
  143. return $dispositions;
  144. } else {
  145. //send_email($this->devEmail, 'RecordsAuthority_Error', 'database error: unable to pull dispositions from database - getDispositionsQuery()');
  146. echo "database error: unable to pull dispositions from database - getDispositionsQuery()";
  147. }
  148. }
  149. /** not used **
  150. * invokes getDispositionDetailsQuery();
  151. *
  152. * @param $dispositionID
  153. * @return $dispositionDetails
  154. */
  155. public function getDispositionDetails($dispositionID) {
  156. $dispositionDetails = $this->getDispositionDetailsQuery($dispositionID);
  157. return $dispositionDetails;
  158. }
  159. /** not used **
  160. * gets disposition details
  161. *
  162. * @param $dispositionID
  163. * @return $dispositionDetails / $message
  164. */
  165. private function getDispositionDetailsQuery($dispositionID) {
  166. $this->db->select('dispositionLong, description');
  167. $this->db->from('rm_disposition');
  168. $this->db->where('dispositionID', $dispositionID);
  169. $dispositionDetailQuery = $this->db->get();
  170. $dispositionDetail = array();
  171. if ($dispositionDetailQuery->num_rows > 0) {
  172. foreach ($dispositionDetailQuery->result() as $dispositionDetail) {
  173. $dispositionDetails[] = "<br />" . $dispositionDetail->dispositionLong . ":<br />";
  174. $dispositionDetails[] = $dispositionDetail->description . "<br />";
  175. }
  176. return $dispositionDetails;
  177. } else {
  178. return $message = "<br />Please select a disposition";
  179. }
  180. }
  181. /**
  182. * generates unique identifier for retention schedule record
  183. *
  184. * @return $uuid
  185. */
  186. private function createUUID() {
  187. // create uuid
  188. $uuid = uniqid();
  189. return $uuid;
  190. }
  191. /**
  192. * invokes saveRetentionScheduleQuery();
  193. *
  194. * @param $_POST
  195. * @return void
  196. */
  197. public function saveRetentionSchedule($_POST) {
  198. $retentionScheduleID = $this->saveRetentionScheduleQuery($_POST);
  199. return $retentionScheduleID;
  200. }
  201. /**
  202. * saves individual retention Schedule record
  203. *
  204. * @param $_POST
  205. * @return void
  206. */
  207. private function saveRetentionScheduleQuery($_POST) {
  208. $retentionSchedule = array();
  209. $retentionSchedule['recordCode'] = trim(strip_tags($this->input->post('recordCode')));
  210. $retentionSchedule['recordName'] = trim(strip_tags($this->input->post('recordName')));
  211. $retentionSchedule['recordDescription'] = trim(strip_tags($this->input->post('recordDescription')));
  212. $retentionSchedule['recordCategory'] = trim(strip_tags($this->input->post('recordCategory')));
  213. $retentionSchedule['keywords'] = trim(strip_tags($this->input->post('keywords')));
  214. $retentionSchedule['retentionPeriod'] = trim(strip_tags($this->input->post('retentionPeriod')));
  215. $retentionSchedule['primaryAuthorityRetention'] = trim(strip_tags($this->input->post('primaryAuthorityRetention')));
  216. //$retentionSchedule['retentionNotes'] = trim(strip_tags($this->input->post('retentionNotes')));
  217. $retentionSchedule['retentionDecisions'] = trim(strip_tags($this->input->post('retentionDecisions')));
  218. $retentionSchedule['disposition'] = trim(strip_tags($this->input->post('disposition')));
  219. $retentionSchedule['primaryAuthority'] = trim(strip_tags($this->input->post('primaryAuthority')));
  220. // get department
  221. $retentionSchedule['officeOfPrimaryResponsibility'] = trim(strip_tags($this->input->post('departmentID')));
  222. $retentionSchedule['override'] = trim(strip_tags($this->input->post('override')));
  223. $retentionSchedule['primaryOwnerOverride'] = trim(strip_tags($this->input->post('primaryOwnerOverride')));
  224. $retentionSchedule['relatedAuthorities'] = trim(strip_tags($this->input->post('relatedAuthorities')));
  225. $retentionSchedule['notes'] = trim(strip_tags($this->input->post('notes')));
  226. $retentionSchedule['vitalRecord'] = trim(strip_tags($this->input->post('vitalRecord')));
  227. $retentionSchedule['approvedByCounsel'] = trim(strip_tags($this->input->post('approvedByCounsel')));
  228. $retentionSchedule['approvedByCounselDate'] = trim(strip_tags($this->input->post('approvedByCounselDate')));
  229. $retentionSchedule['updateUser'] = $this->session->userdata('username');
  230. // generate record uuid
  231. $uuid = $this->createUUID();
  232. $retentionSchedule['uuid'] = $uuid;
  233. $this->db->trans_start();
  234. // insert data
  235. $this->db->insert('rm_retentionSchedule', $retentionSchedule);
  236. // get max id
  237. $this->db->select_max('retentionScheduleID');
  238. $this->db->trans_complete();
  239. $idQuery = $this->db->get('rm_retentionSchedule');
  240. if ($idQuery->num_rows() > 0) {
  241. $result = $idQuery->row();
  242. $retentionScheduleID = $result->retentionScheduleID;
  243. // indexes retention schedule
  244. //$this->indexRetentionSchedules($retentionScheduleID);
  245. //Old commented section
  246. /*
  247. if (!empty($_POST['relatedAuthorities'])) {
  248. $i = 0; // set loop variable
  249. $relatedAuthority = array();
  250. $rsRelatedAuthorityID = array();
  251. $relatedAuthorities = $_POST['relatedAuthorities'];
  252. foreach ($relatedAuthorities as $rAuthority) {
  253. if (!empty($rAuthority)) {
  254. $relatedAuthority['retentionScheduleID'] = $retentionScheduleID;
  255. $relatedAuthority['rsRelatedAuthority'] = $rAuthority;
  256. $this->db->trans_start();
  257. // insert data
  258. $this->db->insert('rm_rsRelatedAuthorities', $relatedAuthority);
  259. // get max id
  260. $this->db->select_max('rsRelatedAuthorityID');
  261. $this->db->trans_complete();
  262. $idQuery = $this->db->get('rm_rsRelatedAuthorities');
  263. $result = $idQuery->row();
  264. // place result into an array
  265. $rsRelatedAuthorityID[] = $result->rsRelatedAuthorityID;
  266. // get array length
  267. $arrayLength = count($rsRelatedAuthorityID);
  268. while ($i < $arrayLength) {
  269. // shift the array value at location [0] into a variable
  270. $relatedAuthorityRetentionValue = array_shift($_POST['relatedAuthorityRetention']);
  271. $relatedAuthorityRetention['rsRelatedAuthorityRetention'] = $relatedAuthorityRetentionValue;
  272. // update record
  273. $this->db->where('rsRelatedAuthorityID', $rsRelatedAuthorityID[0]); // there is only one value in the array, so grab it
  274. $this->db->update('rm_rsRelatedAuthorities', $relatedAuthorityRetention);
  275. // clear array and update variable
  276. $rsRelatedAuthorityID = array();
  277. $relatedAuthorityRetentionValue = "";
  278. ++$i;
  279. }
  280. $i = 0; // reset loop variable
  281. }
  282. }
  283. } //old commented section
  284. */
  285. // save associated units (departments)
  286. if ($this->session->userdata('uuid')) { // if uuid is in session, then save associated units
  287. $uuid = $this->session->userdata('uuid'); // grab uuid from session
  288. // query temp table
  289. $this->db->select('departmentID');
  290. $this->db->from('rm_associatedUnits_temp');
  291. $this->db->where('uuid', $uuid);
  292. $checkedAus = $this->db->get();
  293. $checkedArray = array();
  294. if ($checkedAus->num_rows > 0) {
  295. foreach ($checkedAus->result() as $checkedAu) {
  296. $checkedArray[] = $checkedAu->departmentID;
  297. }
  298. }
  299. $associatedUnits = array();
  300. foreach ($checkedArray as $associatedUnit) {
  301. $associatedUnits['retentionScheduleID'] = $retentionScheduleID;
  302. $associatedUnits['departmentID'] = $associatedUnit;
  303. $this->db->insert('rm_associatedUnits', $associatedUnits);
  304. }
  305. $this->db->where('uuid', $uuid);
  306. $this->db->delete('rm_associatedUnits_temp');
  307. // remove uuid from session
  308. $this->session->unset_userdata('uuid');
  309. }
  310. return $retentionScheduleID;
  311. }
  312. }
  313. /**
  314. * invokes editRetentionScheduleQuery();
  315. *
  316. * @param $retentionScheduleID
  317. * @return $retentionSchedule
  318. */
  319. public function editRetentionSchedule($retentionScheduleID) {
  320. $retentionSchedule = $this->editRetentionScheduleQuery($retentionScheduleID);
  321. return $retentionSchedule;
  322. }
  323. /**
  324. * gets retention schedule record for edit
  325. *
  326. * @param $retentionScheduleID
  327. * @return $retentionSchedule
  328. */
  329. private function editRetentionScheduleQuery($retentionScheduleID) {
  330. $this->db->select('*');
  331. $this->db->from('rm_retentionSchedule');
  332. $this->db->where('retentionScheduleID', $retentionScheduleID);
  333. $retentionScheduleQuery = $this->db->get();
  334. $retentionSchedule = array();
  335. if ($retentionScheduleQuery->num_rows > 0) {
  336. foreach ($retentionScheduleQuery->result() as $results) {
  337. $retentionSchedule['retentionScheduleID'] = $retentionScheduleID;
  338. $retentionSchedule['uuid'] = $results->uuid;
  339. $retentionSchedule['recordCode'] = $results->recordCode;
  340. $retentionSchedule['recordName'] = $results->recordName;
  341. $retentionSchedule['recordDescription'] = $results->recordDescription;
  342. $retentionSchedule['recordCategory'] = $results->recordCategory;
  343. $retentionSchedule['keywords'] = $results->keywords;
  344. $retentionSchedule['retentionPeriod'] = $results->retentionPeriod;
  345. $retentionSchedule['primaryAuthorityRetention'] = $results->primaryAuthorityRetention;
  346. //$retentionSchedule['retentionNotes'] = $results->retentionNotes;
  347. $retentionSchedule['retentionDecisions'] = $results->retentionDecisions;
  348. $retentionSchedule['disposition'] = $results->disposition;
  349. /*if($results->disposition == "D") {
  350. $retentionSchedule['disposition'] = "Destroy";
  351. } elseif ($results->disposition == "R") {
  352. $retentionSchedule['disposition'] = "Recycle";
  353. } elseif ($results->disposition == "P") {
  354. $retentionSchedule['disposition'] = "Permanent";
  355. } elseif ($results->disposition == "N/A") {
  356. $retentionSchedule = "Not Applicaple";
  357. } else {
  358. $retentionSchedule['disposition'] = $results->disposition;
  359. }*/
  360. $retentionSchedule['primaryAuthority'] = $results->primaryAuthority;
  361. $retentionSchedule['officeOfPrimaryResponsibility'] = $results->officeOfPrimaryResponsibility;
  362. $retentionSchedule['relatedAuthorities'] = $results->relatedAuthorities;
  363. // get divisionID
  364. $this->db->select('divisionID, departmentName');
  365. $this->db->from('rm_departments');
  366. $this->db->where('departmentID', $results->officeOfPrimaryResponsibility);
  367. $divisionQuery = $this->db->get();
  368. foreach ($divisionQuery->result() as $officeOfPrimaryResponsibility) {
  369. $retentionSchedule['divisionID'] = $officeOfPrimaryResponsibility->divisionID;
  370. $retentionSchedule['officeOfPrimaryResponsibilityDept'] = trim(strip_tags($officeOfPrimaryResponsibility->departmentName));
  371. }
  372. $retentionSchedule['override'] = $results->override;
  373. $retentionSchedule['primaryOwnerOverride'] = $results->primaryOwnerOverride;
  374. $retentionSchedule['notes'] = trim(strip_tags($results->notes));
  375. $retentionSchedule['vitalRecord'] = trim(strip_tags($results->vitalRecord));
  376. $retentionSchedule['approvedByCounsel'] = trim(strip_tags($results->approvedByCounsel));
  377. $retentionSchedule['approvedByCounselDate'] = trim(strip_tags($results->approvedByCounselDate));
  378. $retentionSchedule['timestamp'] = trim(strip_tags($results->timestamp));
  379. $retentionSchedule['updateTimestamp'] = trim(strip_tags($results->updateTimestamp));
  380. $retentionSchedule['updateUser'] = trim(strip_tags($results->updateUser));
  381. }
  382. //old commented section
  383. // get related authorities / related authority retentions
  384. $this->db->select('rsRelatedAuthorityID, rsRelatedAuthority, rsRelatedAuthorityRetention');
  385. $this->db->from('rm_rsRelatedAuthorities');
  386. $this->db->where('retentionScheduleID', $retentionScheduleID);
  387. $relatedAuthorityQuery = $this->db->get();
  388. $relatedAuthority = array();
  389. $relatedAuthorityRetention = array();
  390. if ($relatedAuthorityQuery->num_rows > 0) {
  391. foreach ($relatedAuthorityQuery->result() as $authority) {
  392. $relatedAuthority[$authority->rsRelatedAuthorityID] = $authority->rsRelatedAuthority;
  393. $relatedAuthorityRetention[$authority->rsRelatedAuthorityID] = $authority->rsRelatedAuthorityRetention;
  394. }
  395. $retentionSchedule['relatedAuthority'] = $relatedAuthority;
  396. $retentionSchedule['relatedAuthorityRetention'] = $relatedAuthorityRetention;
  397. }//old commented section
  398. // get associated units
  399. $this->db->select('departmentID');
  400. $this->db->from('rm_associatedUnits');
  401. $this->db->where('retentionScheduleID', $retentionScheduleID);
  402. $associatedUnitQuery = $this->db->get();
  403. $checkedDivisions = array();
  404. if ($associatedUnitQuery->num_rows > 0) {
  405. foreach ($associatedUnitQuery->result() as $department) {
  406. $this->db->select('divisionID');
  407. $this->db->from('rm_departments');
  408. $this->db->where('departmentID', $department->departmentID);
  409. $checkedDivisionsQuery = $this->db->get();
  410. if ($checkedDivisionsQuery->num_rows > 0) {
  411. foreach ($checkedDivisionsQuery->result() as $divisions) {
  412. $checkedDivisions[] = $divisions->divisionID;
  413. }
  414. $retentionSchedule['auDivisionIDs'] = $checkedDivisions;
  415. }
  416. }
  417. }
  418. // get divisionIDs
  419. $this->db->select('divisionID');
  420. $this->db->from('rm_departments');
  421. $this->db->where('departmentID', $results->officeOfPrimaryResponsibility);
  422. $divisionQuery = $this->db->get();
  423. if($divisionQuery->num_rows() > 0)
  424. {
  425. $divisionID = $divisionQuery->row();
  426. }
  427. else
  428. {
  429. echo $divisionQuery;
  430. echo "Division ID not found";
  431. }
  432. $retentionSchedule['divisionID'] = $divisionID->divisionID;
  433. return $retentionSchedule;
  434. }
  435. }
  436. /**
  437. * invokes updateRetentionScheduleQuery();
  438. *
  439. * @param $_POST
  440. * @return void
  441. */
  442. public function updateRetentionSchedule($_POST) {
  443. $retentionScheduleID = $this->updateRetentionScheduleQuery($_POST);
  444. return $retentionScheduleID;
  445. }
  446. /**
  447. * updates individual retention Schedule record
  448. *
  449. * @param $_POST
  450. * @return void
  451. */
  452. private function updateRetentionScheduleQuery($_POST) {
  453. $now = time();
  454. $date = unix_to_human($now, TRUE, 'us');
  455. $retentionScheduleID = $_POST['retentionScheduleID'];
  456. $retentionSchedule = array();
  457. $retentionSchedule['recordCode'] = trim(strip_tags($this->input->post('recordCode')));
  458. $retentionSchedule['recordName'] = trim(strip_tags($this->input->post('recordName')));
  459. $retentionSchedule['recordDescription'] = trim(strip_tags($this->input->post('recordDescription')));
  460. $retentionSchedule['recordCategory'] = trim(strip_tags($this->input->post('recordCategory')));
  461. $retentionSchedule['keywords'] = trim(strip_tags($this->input->post('keywords')));
  462. $retentionSchedule['retentionPeriod'] = trim(strip_tags($this->input->post('retentionPeriod')));
  463. //$retentionSchedule['retentionNotes'] = trim(strip_tags($this->input->post('retentionNotes')));
  464. $retentionSchedule['retentionDecisions'] = trim(strip_tags($this->input->post('retentionDecisions')));
  465. $retentionSchedule['disposition'] = trim(strip_tags($this->input->post('disposition')));
  466. $retentionSchedule['primaryAuthority'] = trim(strip_tags($this->input->post('primaryAuthority')));
  467. $retentionSchedule['primaryAuthorityRetention'] = trim(strip_tags($this->input->post('primaryAuthorityRetention')));
  468. $retentionSchedule['officeOfPrimaryResponsibility'] = trim(strip_tags($this->input->post('departmentID')));
  469. $retentionSchedule['override'] = trim(strip_tags($this->input->post('override')));
  470. $retentionSchedule['primaryOwnerOverride'] = trim(strip_tags($this->input->post('primaryOwnerOverride')));
  471. $retentionSchedule['relatedAuthorities'] = trim(strip_tags($this->input->post('relatedAuthorities')));
  472. $retentionSchedule['notes'] = trim(strip_tags($this->input->post('notes')));
  473. $retentionSchedule['vitalRecord'] = trim(strip_tags($this->input->post('vitalRecord')));
  474. $retentionSchedule['approvedByCounsel'] = trim(strip_tags($this->input->post('approvedByCounsel')));
  475. //Test for manual date change, if not overwrite with current date
  476. $this->db->select('approvedByCounselDate');
  477. $query = $this->db->get_where('rm_retentionSchedule', array('retentionScheduleID' => $_POST['retentionScheduleID']));
  478. if($query->num_rows() > 0) {
  479. foreach($query->result() as $results)
  480. if($this->input->post('approvedByCounselDate') == $results->approvedByCounselDate) {
  481. $datestring = "%Y-%m-%d";
  482. $time = time();
  483. $retentionSchedule['approvedByCounselDate'] = mdate($datestring, $time);
  484. } else {
  485. $retentionSchedule['approvedByCounselDate'] = trim(strip_tags($this->input->post('approvedByCounselDate')));
  486. }
  487. } else {
  488. $retentionSchedule['approvedByCounselDate'] = trim(strip_tags($this->input->post('approvedByCounselDate')));
  489. }
  490. $retentionSchedule['updateTimestamp'] = $date;
  491. $retentionSchedule['updateUser'] = $this->session->userdata('username');
  492. // update data
  493. $this->db->where('retentionScheduleID', $retentionScheduleID);
  494. $this->db->update('rm_retentionSchedule', $retentionSchedule);
  495. /*
  496. // update related authorities / related authority retentions
  497. if (isset($_POST['relatedAuthorityID'])) {
  498. $rsRelatedAuthority = array();
  499. $arrayLength = count($_POST['relatedAuthorityID']);
  500. $i = 0;
  501. while ($i < $arrayLength) {
  502. $rsRelatedAuthority['rsRelatedAuthority'] = $_POST['relatedAuthorities'][$i];
  503. $rsRelatedAuthorityID = $_POST['relatedAuthorityID'][$i];
  504. $this->db->where('rsRelatedAuthorityID', $rsRelatedAuthorityID);
  505. $this->db->update('rm_rsRelatedAuthorities', $rsRelatedAuthority);
  506. ++$i;
  507. }
  508. }
  509. if (isset($_POST['relatedAuthorityRetentionID'])) {
  510. $rsRelatedAuthority = array();
  511. $arrayLength = count($_POST['relatedAuthorityRetentionID']);
  512. $j = 0;
  513. while ($j < $arrayLength) {
  514. $rsRelatedAuthorityRetention['rsRelatedAuthorityRetention'] = $_POST['relatedAuthorityRetentions'][$j];
  515. $rsRelatedAuthorityID = $_POST['relatedAuthorityRetentionID'][$j];
  516. $this->db->where('rsRelatedAuthorityID', $rsRelatedAuthorityID);
  517. $this->db->update('rm_rsRelatedAuthorities', $rsRelatedAuthorityRetention);
  518. ++$j;
  519. }
  520. }
  521. // add new authorities
  522. if (isset($_POST['newRelatedAuthorities'])) {
  523. $i = 0; // set loop variable
  524. $relatedAuthority = array();
  525. $rsRelatedAuthorityID = array();
  526. $relatedAuthorities = $_POST['newRelatedAuthorities'];
  527. foreach ($relatedAuthorities as $rAuthority) {
  528. if (!empty($rAuthority)) {
  529. $relatedAuthority['retentionScheduleID'] = $retentionScheduleID;
  530. $relatedAuthority['rsRelatedAuthority'] = $rAuthority;
  531. $this->db->trans_start();
  532. // insert data
  533. $this->db->insert('rm_rsRelatedAuthorities', $relatedAuthority);
  534. // get max id
  535. $this->db->select_max('rsRelatedAuthorityID');
  536. $this->db->trans_complete();
  537. $idQuery = $this->db->get('rm_rsRelatedAuthorities');
  538. $result = $idQuery->row();
  539. // place result into an array
  540. $rsRelatedAuthorityID[] = $result->rsRelatedAuthorityID;
  541. // get array length
  542. $arrayLength = count($rsRelatedAuthorityID);
  543. while ($i < $arrayLength) {
  544. // shift the array value at location [0] into a variable
  545. $relatedAuthorityRetentionValue = array_shift($_POST['newRelatedAuthorityRetentions']);
  546. $relatedAuthorityRetention['rsRelatedAuthorityRetention'] = $relatedAuthorityRetentionValue;
  547. // update record
  548. $this->db->where('rsRelatedAuthorityID', $rsRelatedAuthorityID[0]); // there is only one value in the array, so grab it
  549. $this->db->update('rm_rsRelatedAuthorities', $relatedAuthorityRetention);
  550. // clear array and update variable
  551. $rsRelatedAuthorityID = array();
  552. $relatedAuthorityRetentionValue = "";
  553. ++$i;
  554. }
  555. $i = 0; // reset loop variable
  556. }
  557. }
  558. }
  559. */
  560. // updates retention schedule index
  561. $this->updateIndexRetentionSchedules($retentionScheduleID);
  562. }
  563. /**
  564. * invokes getRetentionScheduleRecordQuery();
  565. *
  566. * @param $retentionScheduleID
  567. * @return void
  568. */
  569. public function getRetentionScheduleRecord($retentionScheduleID) {
  570. $retentionSchedule = $this->getRetentionScheduleRecordQuery($retentionScheduleID);
  571. return $retentionSchedule;
  572. }
  573. /**
  574. * gets individual retention Schedule record
  575. *
  576. * @param $retentionScheduleID
  577. * @return void
  578. */
  579. private function getRetentionScheduleRecordQuery($retentionScheduleID) {
  580. $sql = "SELECT retentionScheduleID, recordCode, recordName, recordCategory, recordDescription, keywords, retentionPeriod, disposition, officeOfPrimaryResponsibility, approvedByCounselDate FROM rm_fullTextSearch " .
  581. "WHERE retentionScheduleID = ? ";
  582. $query = $this->db->query($sql, array($retentionScheduleID));
  583. $retentionSchedule = "";
  584. foreach ($query->result() as $results) {
  585. $retentionSchedule .= "<br />";
  586. //$retentionSchedule .= "<strong>Record ID:</strong><br />";
  587. //$retentionSchedule .= trim(strip_tags($results->retentionScheduleID));
  588. //$retentionSchedule .= "<br /><br />";
  589. $retentionSchedule .= "<strong>Record Code:</strong><br />";
  590. $retentionSchedule .= trim(strip_tags($results->recordCode));
  591. $retentionSchedule .= "<br /><br />";
  592. $retentionSchedule .= "<strong>Functional Category:</strong><br />";
  593. $retentionSchedule .= trim(strip_tags($results->recordCategory));
  594. $retentionSchedule .= "<br /><br />";
  595. $retentionSchedule .= "<strong>Record Group:</strong><br />";
  596. $retentionSchedule .= trim(strip_tags($results->recordName));
  597. $retentionSchedule .= "<br /><br />";
  598. $retentionSchedule .= "<strong>Description:</strong><br />";
  599. $retentionSchedule .= trim(strip_tags($results->recordDescription));
  600. $retentionSchedule .= "<br /><br />";
  601. $retentionSchedule .= "<strong>Search Terms:</strong><br />";
  602. $retentionSchedule .= trim(strip_tags($results->keywords));
  603. $retentionSchedule .= "<br /><br />";
  604. $retentionSchedule .= "<strong>Retention Period:</strong><br />";
  605. $retentionSchedule .= trim(strip_tags($results->retentionPeriod));
  606. $retentionSchedule .= "<br /><br />";
  607. //$retentionSchedule .= "<strong>Retention Notes:</strong><br />";
  608. //$retentionSchedule .= trim(strip_tags($results->retentionNotes));
  609. //$retentionSchedule .= "<br /><br />";
  610. $retentionSchedule .= "<strong>Retention Rules:</strong><br />";
  611. $retentionSchedule .= trim(strip_tags($results->disposition));
  612. $retentionSchedule .= "<br /><br />";
  613. $retentionSchedule .= "<strong>Primary Owner:</strong><br />";
  614. $retentionSchedule .= trim(strip_tags($results->officeOfPrimaryResponsibility));
  615. $retentionSchedule .= "<br /><br />";
  616. $retentionSchedule .= "<strong>Public Retention Schedule - Approved Date: </strong><br />";
  617. $retentionSchedule .= trim(strip_tags($results->approvedByCounselDate));
  618. $retentionSchedule .= "<br /><br />";
  619. }
  620. return $retentionSchedule;
  621. }
  622. /**
  623. * invokes updateOfficeOfPrimaryResponsibilityQuery()
  624. *
  625. * @param $_POST
  626. * @return void
  627. */
  628. public function updateOfficeOfPrimaryResponsibility($_POST) {
  629. $this->updateOfficeOfPrimaryResponsibilityQuery($_POST);
  630. }
  631. /**
  632. * updates office of primary responsibility
  633. *
  634. * @param $_POST
  635. * @return void
  636. */
  637. private function updateOfficeOfPrimaryResponsibilityQuery($_POST) {
  638. $departmentID = $this->input->post('departmentID');
  639. $retentionScheduleID = $this->input->post('retentionScheduleID');
  640. $oprAu = array();
  641. $oprRs = array();
  642. // used to update associated unit table
  643. $oprAu['departmentID'] = $departmentID;
  644. // used to update retentionSchedule table
  645. $oprRs['officeOfPrimaryResponsibility'] = $departmentID;
  646. // get existing office of primary responsibility value
  647. $this->db->select('officeOfPrimaryResponsibility');
  648. $this->db->from('rm_retentionSchedule');
  649. $this->db->where('retentionScheduleID', $retentionScheduleID);
  650. $oprQuery = $this->db->get();
  651. $oprResult = $oprQuery->row();
  652. $officeOfPrimaryResponsibility = $oprResult->officeOfPrimaryResponsibility;
  653. // update office of primary responsibility in retention schedule table
  654. $this->db->where('retentionScheduleID', $retentionScheduleID);
  655. $this->db->update('rm_retentionSchedule', $oprRs);
  656. // update department ID (office of primary responsibility) in associated unit table
  657. $this->db->where('retentionScheduleID', $retentionScheduleID);
  658. $this->db->where('departmentID', $officeOfPrimaryResponsibility);
  659. $this->db->update('rm_associatedUnits', $oprAu);
  660. }
  661. /**
  662. * indexes all retention schedules
  663. *
  664. * @return void
  665. */
  666. public function indexRs() {
  667. $this->indexRetentionSchedules($retentionScheduleID="");
  668. }
  669. /**
  670. * indexes retention schedules
  671. *
  672. * @param $retentionScheduleID
  673. * @return void
  674. */
  675. private function indexRetentionSchedules($retentionScheduleID) {
  676. if ($retentionScheduleID == "") {
  677. $this->db->truncate('rm_fullTextSearch');
  678. }
  679. $this->db->select('retentionScheduleID, recordCode, recordName, recordDescription, recordCategory, keywords, retentionPeriod, disposition, officeOfPrimaryResponsibility, override, primaryOwnerOverride,approvedByCounselDate');
  680. $this->db->from('rm_retentionSchedule');
  681. $this->db->where('approvedByCounsel', 'yes');
  682. if ($retentionScheduleID !== "") {
  683. $this->db->where('retentionScheduleID', $retentionScheduleID);
  684. }
  685. $retentionScheduleQuery = $this->db->get();
  686. echo "<table>";
  687. echo "<tr><th>Code</th><th>Name</th></tr>";
  688. foreach ($retentionScheduleQuery->result() as $rsResults) {
  689. $retentionScheduleArray['retentionScheduleID'] = $rsResults->retentionScheduleID;
  690. $retentionScheduleArray['recordCode'] = $rsResults->recordCode;
  691. $retentionScheduleArray['recordName'] = $rsResults->recordName;
  692. $retentionScheduleArray['recordDescription'] = $rsResults->recordDescription;
  693. $retentionScheduleArray['recordCategory'] = $rsResults->recordCategory;
  694. $retentionScheduleArray['keywords'] = $rsResults->keywords;
  695. $retentionScheduleArray['retentionPeriod'] = $rsResults->retentionPeriod;
  696. //$retentionScheduleArray['retentionNotes'] = $rsResults->retentionNotes;
  697. $retentionScheduleArray['approvedByCounselDate'] = $rsResults->approvedByCounselDate;
  698. $retentionScheduleArray['disposition'] = $rsResults->disposition;
  699. /*// get full dispsition name for search results display
  700. $this->db->select('dispositionLong');
  701. $this->db->from('rm_disposition');
  702. //$this->db->like('dispositionShort', $rsResults->disposition);
  703. $dispositionQuery = $this->db->get();
  704. $dispositionResult = $dispositionQuery->row();
  705. $disposition = $dispositionResult->dispositionLong;
  706. $retentionScheduleArray['disposition'] = $disposition;*/
  707. if($rsResults->override == "yes") {
  708. $retentionScheduleArray['officeOfPrimaryResponsibility'] = $rsResults->primaryOwnerOverride;
  709. } else {
  710. $this->db->select('departmentName, divisionID');
  711. $this->db->from('rm_departments');
  712. $this->db->where('departmentID', $rsResults->officeOfPrimaryResponsibility);
  713. $departmentQuery = $this->db->get();
  714. foreach ($departmentQuery->result() as $results) {
  715. $dept = $results->departmentName;
  716. $this->db->select('divisionName');
  717. $this->db->from('rm_divisions');
  718. $this->db->where('divisionID', $results->divisionID);
  719. $divisionQuery = $this->db->get();
  720. if ($divisionQuery->num_rows() > 0) {
  721. $row = $divisionQuery->row();
  722. $div = $row->divisionName;
  723. $divDept = $div . " - " . $dept;
  724. $retentionScheduleArray['officeOfPrimaryResponsibility'] = $divDept;
  725. }
  726. }
  727. }
  728. $this->db->insert('rm_fullTextSearch', $retentionScheduleArray);
  729. echo "<tr>";
  730. echo "<td>" . $retentionScheduleArray['recordCode'] . "</td><td>" . $retentionScheduleArray['recordName'] . "</td>";
  731. echo "</tr>";
  732. }
  733. echo "</table>";
  734. if ($retentionScheduleID == "") {
  735. echo "<strong>Indexing Complete.</strong>";
  736. }
  737. }
  738. /**
  739. * updates retention schedule index record
  740. *
  741. * @param $retentionScheduleID
  742. * @return void
  743. */
  744. private function updateIndexRetentionSchedules($retentionScheduleID) {
  745. $this->db->select('retentionScheduleID, recordName, recordDescription, recordCategory, retentionPeriod, disposition, officeOfPrimaryResponsibility, override, primaryOwnerOverride, approvedByCounsel');
  746. $this->db->from('rm_retentionSchedule');
  747. $this->db->where('retentionScheduleID', $retentionScheduleID);
  748. //$this->db->where('approvedByCounsel', 'yes');
  749. $retentionScheduleQuery = $this->db->get();
  750. foreach ($retentionScheduleQuery->result() as $rsResults) {
  751. $retentionScheduleArray['retentionScheduleID'] = $rsResults->retentionScheduleID;
  752. $retentionScheduleArray['recordName'] = $rsResults->recordName;
  753. $retentionScheduleArray['recordDescription'] = $rsResults->recordDescription;
  754. $retentionScheduleArray['recordCategory'] = $rsResults->recordCategory;
  755. $retentionScheduleArray['retentionPeriod'] = $rsResults->retentionPeriod;
  756. //$retentionScheduleArray['retentionNotes'] = $rsResults->retentionNotes;
  757. $retentionScheduleArray['disposition'] = $rsResults->disposition;
  758. /*// get full dispsition name for search results display
  759. $this->db->select('dispositionLong');
  760. $this->db->from('rm_disposition');
  761. //$this->db->like('dispositionShort', $rsResults->disposition);
  762. $dispositionQuery = $this->db->get();
  763. $dispositionResult = $dispositionQuery->row();
  764. $disposition = $dispositionResult->dispositionLong;
  765. $retentionScheduleArray['disposition'] = $disposition;*/
  766. if($rsResults->override == "yes") {
  767. $retentionScheduleArray['officeOfPrimaryResponsibility'] = $rsResults->primaryOwnerOverride;
  768. } else {
  769. $this->db->select('departmentName, divisionID');
  770. $this->db->from('rm_departments');
  771. $this->db->where('departmentID', $rsResults->officeOfPrimaryResponsibility);
  772. $departmentQuery = $this->db->get();
  773. foreach ($departmentQuery->result() as $results) {
  774. $dept = $results->departmentName;
  775. $this->db->select('divisionName');
  776. $this->db->from('rm_divisions');
  777. $this->db->where('divisionID', $results->divisionID);
  778. $divisionQuery = $this->db->get();
  779. $row = $divisionQuery->row();
  780. $div = $row->divisionName;
  781. $divDept = $div . " - " . $dept;
  782. $retentionScheduleArray['officeOfPrimaryResponsibility'] = $divDept;
  783. }
  784. }
  785. // check if record exists
  786. $this->db->where('retentionScheduleID', $retentionScheduleID);
  787. $count = $this->db->count_all_results('rm_fullTextSearch');
  788. if ($rsResults->approvedByCounsel == "yes" && $count == 0) {
  789. $this->db->insert('rm_fullTextSearch', $retentionScheduleArray);
  790. } else if ($rsResults->approvedByCounsel == "no" && $count > 0) {
  791. $this->db->where('retentionScheduleID', $retentionScheduleID);
  792. $this->db->delete('rm_fullTextSearch');
  793. } else if ($rsResults->approvedByCounsel == "no" && $count == 0) {
  794. // nothing
  795. } else if ($rsResults->approvedByCounsel == "yes" && $count > 0) {
  796. $this->db->where('retentionScheduleID', $retentionScheduleID);
  797. $this->db->update('rm_fullTextSearch', $retentionScheduleArray);
  798. }
  799. }
  800. //empties temp associated units
  801. $this->db->query('TRUNCATE TABLE rm_associatedUnits_temp; ');
  802. }
  803. /**
  804. * invokes publishRetentionScheduleQuery()
  805. *
  806. * @access public
  807. * @return void
  808. */
  809. public function publishRetentionSchedule($retentionScheduleID, $publish) {
  810. $retentionScheduleID = $this->publishRetentionScheduleQuery($retentionScheduleID, $publish);
  811. }
  812. /**
  813. * publishes Retention Schedule
  814. *
  815. * @access private
  816. * @return void
  817. */
  818. private function publishRetentionScheduleQuery($retentionScheduleID, $publish)
  819. {
  820. $now = time();
  821. $datestring = "%Y-%m-%d";
  822. $date = mdate($datestring, $now);
  823. if($publish == "yes") {
  824. $retentionSchedule['approvedByCounsel'] = "yes";
  825. $retentionSchedule['approvedByCounselDate'] = "$date";
  826. } else {
  827. $retentionSchedule['approvedByCounsel'] = "no";
  828. }
  829. $this->db->trans_start();
  830. $this->db->where('retentionScheduleID', $retentionScheduleID);
  831. $this->db->update('rm_retentionSchedule', $retentionSchedule);
  832. $this->db->trans_complete();
  833. }
  834. /**
  835. * invokes deleteRetentionScheduleQuery()
  836. *
  837. * @access public
  838. * @return void
  839. */
  840. public function deleteRetentionSchedule($retentionScheduleID)
  841. {
  842. $retentionScheduleID = $this->deleteRetentionScheduleQuery($retentionScheduleID);
  843. }
  844. /**
  845. * deletes Retention Schedule and moves it to rm_retentionScheduleDeleted
  846. *
  847. * @access private
  848. * @return void
  849. */
  850. private function deleteRetentionScheduleQuery($retentionScheduleID)
  851. {
  852. $this->db->trans_start();
  853. $this->db->query("INSERT INTO rm_retentionScheduleDeleted SELECT * FROM rm_retentionSchedule WHERE retentionScheduleID = $retentionScheduleID");
  854. $this->db->where('retentionScheduleID',$retentionScheduleID);
  855. $this->db->delete('rm_retentionSchedule');
  856. $this->db->trans_complete();
  857. }
  858. /**
  859. * invokes restoreRetentionScheduleQuery()
  860. *
  861. * @access public
  862. * @return void
  863. */
  864. public function restoreRetentionSchedule($retentionScheduleID)
  865. {
  866. $retentionScheduleID = $this->restoreRetentionScheduleQuery($retentionScheduleID);
  867. }
  868. /**
  869. * restores retention schedule and moves it to rm_retentionSchedule
  870. *
  871. * @access private
  872. * @return void
  873. */
  874. private function restoreRetentionScheduleQuery($retentionScheduleID)
  875. {
  876. $this->db->trans_start();
  877. $this->db->query("INSERT INTO rm_retentionSchedule SELECT * FROM rm_retentionScheduleDeleted WHERE retentionScheduleID = $retentionScheduleID");
  878. $this->db->where('retentionScheduleID',$retentionScheduleID);
  879. $this->db->delete('rm_retentionScheduleDeleted');
  880. $this->db->trans_complete();
  881. }
  882. /**
  883. * invokes permanentDeleteRetentionScheduleQuery()
  884. *
  885. * @access public
  886. * @return void
  887. */
  888. public function permanentDeleteRetentionSchedule($retentionScheduleID)
  889. {
  890. $retentionScheduleID = $this->permanentDeleteRetentionScheduleQuery($retentionScheduleID);
  891. }
  892. /**
  893. * deletes Retention Schedule
  894. *
  895. * @access private
  896. * @return void
  897. */
  898. private function permanentDeleteRetentionScheduleQuery($retentionScheduleID)
  899. {
  900. $this->db->trans_start();
  901. $this->db->where('retentionScheduleID',$retentionScheduleID);
  902. $this->db->delete('rm_retentionScheduleDeleted');
  903. $this->db->trans_complete();
  904. }
  905. }
  906. ?>