/application/modules/bank/controllers/IndexController.php

https://github.com/srsree/OurBank · PHP · 168 lines · 100 code · 10 blank · 58 comment · 16 complexity · d82a41ea0d5b9fce40af4a857151fb60 MD5 · raw file

  1. <?php
  2. /*
  3. ############################################################################
  4. # This file is part of OurBank.
  5. ############################################################################
  6. # OurBank is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU Affero General Public License as
  8. # published by the Free Software Foundation, either version 3 of the
  9. # License, or (at your option) any later version.
  10. ############################################################################
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU Affero General Public License for more details.
  15. ############################################################################
  16. # You should have received a copy of the GNU Affero General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. ############################################################################
  19. */
  20. ?>
  21. <?php
  22. /*
  23. * bank controller for add, view,update,delete
  24. */
  25. class Bank_IndexController extends Zend_Controller_Action
  26. {
  27. public function init()
  28. {
  29. $this->view->pageTitle=$this->view->translate('Bank');
  30. $globalsession = new App_Model_Users();
  31. $this->view->globalvalue = $globalsession->getSession();
  32. $this->view->createdby = $this->view->globalvalue[0]['id'];
  33. $this->view->username = $this->view->globalvalue[0]['username'];
  34. // if (($this->view->globalvalue[0]['id'] == 0)) {
  35. // $this->_redirect('index/logout');
  36. // }
  37. $this->view->adm = new App_Model_Adm();
  38. }
  39. public function indexAction()
  40. {
  41. //instance for form
  42. $searchForm = new Management_Form_Search();
  43. $this->view->form = $searchForm;
  44. //form data poster
  45. if ($this->_request->isPost() && $this->_request->getPost('Search')) {
  46. $bank = new Bank_Model_Bank();
  47. $page = $this->_getParam('page',1);
  48. $paginator = Zend_Paginator::factory($bank->search($this->_request->getPost('field2')));
  49. $this->view->errormsg="Record not found";
  50. } else {
  51. $this->view->title=$this->view->translate('Bank');
  52. //session
  53. $storage = new Zend_Auth_Storage_Session();
  54. $data = $storage->read();
  55. if(!$data)
  56. {
  57. $this->_redirect('index/login');
  58. }
  59. $bank = new Bank_Model_Bank();
  60. $page = $this->_getParam('page',1);
  61. $paginator = Zend_Paginator::factory($this->view->adm->viewRecord("ob_bank","id","DESC"));
  62. if(!$paginator){
  63. $this->view->errormsg="Record not found";
  64. }
  65. }
  66. //paginator
  67. $paginator->setItemCountPerPage($this->view->adm->paginator());
  68. $paginator->setCurrentPageNumber($page);
  69. $this->view->paginator = $paginator;
  70. }
  71. public function addbankAction()
  72. {
  73. //Acl
  74. // $access = new App_Model_Access();
  75. // $checkaccess = $access->accessRights('Bank',$this->view->globalvalue[0]['name'],'addbankAction');
  76. // if (($checkaccess != NULL)) {
  77. // add bank
  78. $this->view->title=$this->view->translate('Add Bank');
  79. $form = new Bank_Form_Bank();
  80. $this->view->form = $form;
  81. //new bank form instance
  82. // $this->view->submitform = new Bank_Form_Submit();
  83. if ($this->_request->isPost() && $this->_request->getPost('Submit')) {
  84. if ($this->_request->isPost()) {
  85. $formData = $this->_request->getPost();
  86. if ($form->isValid($formData)) {
  87. // bank Insert
  88. $id = $this->view->adm->addRecord("ob_bank",$form->getValues());
  89. $this->_redirect('/bankcommonview/index/commonview/id/'.$id);
  90. }
  91. }
  92. }
  93. // } else {
  94. // $this->_redirect('index/error');
  95. // }
  96. }
  97. public function editbankAction()
  98. {
  99. //Acl
  100. // $access = new App_Model_Access();
  101. // $checkaccess = $access->accessRights('Bank',$this->view->globalvalue[0]['name'],'editbankAction');
  102. // if (($checkaccess != NULL)) {
  103. // edit bank
  104. $form = new Bank_Form_Bank();
  105. $this->view->form = $form;
  106. $this->view->submitform = new Bank_Form_Submit();
  107. if ($this->_request->isPost() && $this->_request->getPost('update')) {
  108. if ($this->_request->isPost()) {
  109. $formData = $this->_request->getPost();
  110. if ($form->isValid($formData)) {
  111. $bank = new Bank_Model_Bank();
  112. //Update the previous record
  113. $id = intval($this->_request->getPost('id'));
  114. $editinstitution = $this->view->adm->editRecord("ob_bank",$id);
  115. $this->view->adm->updateLog("ob_bank_log",$editinstitution[0],$this->view->createdby);
  116. //update
  117. $this->view->adm->updateRecord("ob_bank",$id,$form->getValues());
  118. $this->_redirect("/bank");
  119. }
  120. }
  121. } else {
  122. $this->view->title=$this->view->translate('Edit Bank');
  123. $this->view->id = intval($this->_request->getParam("id"));
  124. $editBank = $this->view->adm->editRecord("ob_bank",$this->view->id);
  125. $form->populate($editBank[0]);
  126. }
  127. // } else {
  128. // $this->_redirect('index/error');
  129. // }
  130. }
  131. public function viewbankAction ()
  132. {
  133. }
  134. public function deletebankAction()
  135. {
  136. //Acl
  137. // $access = new App_Model_Access();
  138. // $checkaccess = $access->accessRights('Bank',$this->view->globalvalue[0]['name'],'deletebankAction');
  139. // if (($checkaccess != NULL)) {
  140. $this->view->title=$this->view->translate('Delete Bank');
  141. $this->view->id = $this->_request->getParam("id");
  142. $form = new Institution_Form_Delete();
  143. $this->view->form = $form;
  144. $this->view->submitform = new Bank_Form_Submit();
  145. //form poster data
  146. if ($this->_request->isPost() && $this->_request->getPost('Delete')) {
  147. $id=$this->_request->getParam("id");
  148. //adm delete instance
  149. $this->view->adm->deleteAction("ob_bank","bank",$id);
  150. $this->view->adm->deleteSubmodule("contact",$id,2);
  151. $this->view->adm->deleteSubmodule("address",$id,2);
  152. $this->_redirect("/bank");
  153. }
  154. // } else {
  155. // $this->_redirect('index/error');
  156. // }
  157. }
  158. }