PageRenderTime 59ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/app/controllers/atenciones_integrales_controller.php

http://learning-circles.googlecode.com/
PHP | 107 lines | 93 code | 9 blank | 5 comment | 19 complexity | c6ad411d96575ad784569952f11f07ff MD5 | raw file
  1. <?php
  2. class AtencionesIntegralesController extends AppController {
  3. var $name = 'AtencionesIntegrales';
  4. var $uses = array('UsersEquiposOperativo', 'Zona','AtencionesIntegrale');
  5. var $helpers = array('AtencionesIntegrale');
  6. function index() {
  7. $usuario_activo = $this->Access->getMy('username');
  8. //Verificacion de sesion del sistema
  9. if(!$usuario_activo){
  10. $this->Session->setFlash(__('Por favor inicie sesion', true));
  11. $this->redirect(array('controller'=>'users','action' => 'login'));
  12. }
  13. $this->AtencionesIntegrale->recursive = 0;
  14. $group_id= $this->Access->getMy('group_id');
  15. $user_id= $this->Access->getMy('id');
  16. $eo= $this->UsersEquiposOperativo->find('first',array('conditions'=>array('UsersEquiposOperativo.user_id'=>$user_id)));
  17. $zona_id=$this->Zona->find('all',array('conditions'=>array('Zona.id'=>$eo['EquiposOperativo']['zona_id'])));
  18. if($group_id=="1"){ //Si es administrador
  19. $zona_id = $this->Zona->find('all');
  20. }
  21. $this->set(compact('zona_id'));
  22. $this->set('atencionesIntegrales', $this->paginate());
  23. }
  24. function view($id = null) {
  25. $usuario_activo = $this->Access->getMy('username');
  26. //Verificacion de sesion del sistema
  27. if(!$usuario_activo){
  28. $this->Session->setFlash(__('Por favor inicie sesion', true));
  29. $this->redirect(array('controller'=>'users','action' => 'login'));
  30. }
  31. if (!$id) {
  32. $this->Session->setFlash(__('Invalid atenciones integrale', true));
  33. $this->redirect(array('action' => 'index'));
  34. }
  35. $this->set('atencionesIntegrale', $this->AtencionesIntegrale->read(null, $id));
  36. }
  37. function add($bimestre=null, $year=null, $zona=null) {
  38. $usuario_activo = $this->Access->getMy('username');
  39. //Verificacion de sesion del sistema
  40. if(!$usuario_activo){
  41. $this->Session->setFlash(__('Por favor inicie sesion', true));
  42. $this->redirect(array('controller'=>'users','action' => 'login'));
  43. }
  44. if (!empty($this->data)) {
  45. $this->AtencionesIntegrale->create();
  46. if ($this->AtencionesIntegrale->save($this->data)) {
  47. $this->Session->setFlash(__('The atenciones integrale has been saved', true));
  48. $this->redirect(array('action' => 'index'));
  49. } else {
  50. $this->Session->setFlash(__('The atenciones integrale could not be saved. Please, try again.', true));
  51. }
  52. }
  53. $bimestre=$year."-".$bimestre;
  54. $this->set(compact('zona', 'bimestre'));
  55. }
  56. function edit($bimestre=null, $year=null, $zona=null){
  57. $usuario_activo = $this->Access->getMy('username');
  58. //Verificacion de sesion del sistema
  59. if(!$usuario_activo){
  60. $this->Session->setFlash(__('Por favor inicie sesion', true));
  61. $this->redirect(array('controller'=>'users','action' => 'login'));
  62. }
  63. if (!$bimestre && !$year && !$zona && empty($this->data)) {
  64. $this->Session->setFlash(__('Invalid atenciones integrale', true));
  65. $this->redirect(array('action' => 'index'));
  66. }
  67. if (!empty($this->data)) {
  68. if ($this->AtencionesIntegrale->save($this->data)) {
  69. $this->Session->setFlash(__('The atenciones integrale has been saved', true));
  70. $this->redirect(array('action' => 'index'));
  71. } else {
  72. $this->Session->setFlash(__('The atenciones integrale could not be saved. Please, try again.', true));
  73. }
  74. }
  75. $datos = $this->AtencionesIntegrale->find('first', array('conditions'=>array('AtencionesIntegrale.zona_id'=>$zona,
  76. 'AND'=>array('AtencionesIntegrale.bimestre'=>$year."-".$bimestre))));
  77. $this->set(compact('datos'));
  78. }
  79. function delete($id = null) {
  80. $usuario_activo = $this->Access->getMy('username');
  81. //Verificacion de sesion del sistema
  82. if(!$usuario_activo){
  83. $this->Session->setFlash(__('Por favor inicie sesion', true));
  84. $this->redirect(array('controller'=>'users','action' => 'login'));
  85. }
  86. if (!$id) {
  87. $this->Session->setFlash(__('Invalid id for atenciones integrale', true));
  88. $this->redirect(array('action'=>'index'));
  89. }
  90. if ($this->AtencionesIntegrale->delete($id)) {
  91. $this->Session->setFlash(__('Atenciones integrale deleted', true));
  92. $this->redirect(array('action'=>'index'));
  93. }
  94. $this->Session->setFlash(__('Atenciones integrale was not deleted', true));
  95. $this->redirect(array('action' => 'index'));
  96. }
  97. }
  98. ?>