PageRenderTime 53ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/application/modules/statu/controllers/admin.php

https://bitbucket.org/matyhaty/senses-designertravelv3
PHP | 189 lines | 155 code | 23 blank | 11 comment | 9 complexity | 5172b2af509cce73c7b0a869c1b93228 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0
  1. <?php
  2. if (!defined('BASEPATH'))
  3. exit('No direct script access allowed');
  4. class Admin extends Base_Controller
  5. {
  6. /**
  7. * Constructor for statu page
  8. *
  9. */
  10. function __construct()
  11. {
  12. $this -> load -> library('form_validation');
  13. $this -> load -> helper(array(
  14. 'form',
  15. 'url'
  16. ));
  17. parent::__construct('Statu');
  18. }
  19. public function manage()
  20. {
  21. $userid = $this -> session -> userdata('userid');
  22. $data['status'] = $this -> model -> adminGetStatus();
  23. $this -> template -> write_view('sheet', 'statu/admin_manage', $data);
  24. $this -> template -> render($region = NULL, $buffer = FALSE, $parse = FALSE);
  25. }
  26. public function autoCreate()
  27. {
  28. $object = $this -> model;
  29. $tasktypeM = new Tasktype();
  30. $departmentM = new Department();
  31. $tt = new Tasktype();
  32. $tt -> where('state', 'Active') -> get();
  33. $de = new Department();
  34. $de -> where('state', 'Active') -> get();
  35. $types = array();
  36. $types[] = 'On Site';
  37. $types[] = 'Off Site';
  38. $types[] = 'On Hold';
  39. $types[] = 'Client Placed on Hold';
  40. $types[] = 'Planning';
  41. $types[] = 'Scheduled';
  42. $types[] = 'Processing';
  43. $types[] = 'Awaiting Resource';
  44. $types[] = 'Currently Processing';
  45. $types[] = 'Back Log';
  46. $types[] = 'Pending';
  47. $types[] = 'Client on Hold';
  48. $types[] = 'Inactive';
  49. $types[] = 'Dead / Deleted';
  50. $types[] = 'Complete';
  51. $types[] = 'Awaiting Payment Check';
  52. $colours = array(
  53. 'F44747',
  54. 'D88934',
  55. 'EEAB41',
  56. 'C39F77',
  57. 'BEC0C0',
  58. 'BFCBAB',
  59. 'DBE5C3',
  60. 'E0E9DD',
  61. 'D4E5F2',
  62. '85A9A6',
  63. '24213E',
  64. 'BA2A46',
  65. '737349',
  66. '723660',
  67. '9B746F',
  68. '5B7E7F',
  69. '5693B4',
  70. 'C7457B',
  71. 'E0E9DD',
  72. 'D4E5F2',
  73. '85A9A6',
  74. '24213E',
  75. 'BA2A46',
  76. '737349',
  77. '723660',
  78. '9B746F',
  79. '5B7E7F',
  80. '5693B4'
  81. );
  82. foreach ($tt as $t)
  83. {
  84. foreach ($de as $d)
  85. {
  86. $c = 0;
  87. foreach ($types as $type)
  88. {
  89. // create array
  90. $statu = new Statu();
  91. $data = '';
  92. $data['title'] = $type;
  93. $data['description'] = '.';
  94. $data['colour'] = $colours[$c];
  95. $data['tasktypeID'] = $t -> id;
  96. $data['departmentID'] = $d -> id;
  97. $test = new Statu();
  98. $test -> where('tasktypeID', $t -> id) -> where('departmentID', $d -> id) -> where('title', $type) -> get();
  99. if ($test -> result_count())
  100. {
  101. // status already exists, do not duplicate.
  102. echo '<hr>status already exists, do not duplicate. - update colours tho! ';
  103. $test->colour = $colours[$c];
  104. $test->save();
  105. }
  106. else
  107. {
  108. echo '<hr>Created: ';
  109. print_r($data);
  110. $saved = DMZ_Array::from_array($statu, $data, NULL, TRUE);
  111. }
  112. $c++;
  113. }
  114. }
  115. }
  116. }
  117. public function create($id = null)
  118. {
  119. $object = $this -> model;
  120. $tasktypeM = new Tasktype();
  121. $departmentM = new Department();
  122. if ($id != 'null' && $id)
  123. {
  124. $object = $this -> model -> getStatu($id);
  125. //$object_tasktype = $this -> model -> getStatu_Tasktype($object);
  126. //$object_department = $this -> model -> getStatu_Department($object);
  127. $formdropdowns['tasktype'] = $tasktypeM -> getOptions($object -> tasktypeID);
  128. $formdropdowns['department'] = $departmentM -> getOptions($object -> departmentID);
  129. }
  130. else
  131. {
  132. $formdropdowns['tasktype'] = $tasktypeM -> getOptions();
  133. $formdropdowns['department'] = $departmentM -> getOptions();
  134. }
  135. $formdata = $this -> xml_forms -> loadXML(APPPATH . 'modules/statu/forms', 'admin_edit');
  136. if ($this -> input -> post())
  137. {
  138. if ($this -> form_validation -> run() == TRUE)
  139. {
  140. $data = $this -> input -> post();
  141. $data['tasktypeID'] = $data['tasktype'];
  142. $data['departmentID'] = $data['department'];
  143. $saved = DMZ_Array::from_array($object, $data, NULL, TRUE);
  144. // Save the job
  145. if ($saved)
  146. {
  147. // relate
  148. $this -> maintaincache -> status($object -> id);
  149. redirect('statu/admin/manage');
  150. }
  151. else
  152. {
  153. $this -> template -> write('validation_errors', validation_errors());
  154. }
  155. }
  156. else
  157. {
  158. $this -> template -> write('validation_errors', validation_errors());
  159. }
  160. }
  161. $form = $this -> xml_forms -> createform($formdata['xml'], $object, $formdropdowns, array());
  162. $this -> template -> write('sheet', $form);
  163. $this -> template -> render($region = NULL, $buffer = FALSE, $parse = FALSE);
  164. }
  165. }
  166. //end class