Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2015
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3. /**
  4. * Here's the Install controller which is responsible for
  5. * installation.
  6. *
  7. * @author Nishchal Gautam <gautam.nishchal@gmail.com>
  8. * @access public
  9. * @category installation
  10. * @copyright (c) 2015, Nishchal Gautam
  11. * @since 0.1
  12. * @version 0.1
  13. *
  14. */
  15.  
  16. class Install extends CI_Controller {
  17.  
  18. /**
  19. * Here's the index of Install controller populates database and displays
  20. * form to create a superadmin
  21. *
  22. * @author Nishchal Gautam <gautam.nishchal@gmail.com>
  23. * @access public
  24. * @category installation
  25. * @copyright (c) 2015, Nishchal Gautam
  26. * @since 0.1
  27. * @version 0.1
  28. *
  29. */
  30.  
  31. public function index()
  32. {
  33.  
  34.  
  35. //check if user is already created, if it's not created, create user,
  36. //if it's created, show a disabled page
  37.  
  38. $this->load->model('user');
  39. if($this->user->check_to_install()){
  40. // load installer model and populate the database with table structures
  41.  
  42. $this->load->model('installer');
  43. $this->installer->populate_database();
  44.  
  45. //display creation of super_admin form
  46.  
  47. $data['Title']="Create Admin";
  48. $this->load->library('parser');
  49. $this->parser->parse('templates/header', $data);
  50. $this->parser->parse('create_superadmin',[]);
  51. $this->parser->parse('templates/footer',[]);
  52. }else{
  53. $data['Title']="Create Admin";
  54. $this->load->library('parser');
  55. $this->parser->parse('templates/header', $data);
  56. $this->parser->parse('create_superadmin_disabled',[]);
  57. $this->parser->parse('templates/footer',[]);
  58.  
  59. // or just show_404();
  60.  
  61. }
  62. }
  63. /**
  64. * Save the superadmin creation request
  65. *
  66. * @author Nishchal Gautam <gautam.nishchal@gmail.com>
  67. * @access public
  68. * @category installation
  69. * @copyright (c) 2015, Nishchal Gautam
  70. * @since 0.1
  71. * @todo Probably should log the ip address and everything about user on the else part
  72. * @version 0.1
  73. *
  74. */
  75. public function save()
  76. {
  77.  
  78. //check if user is already created, if it's not created, create user,
  79. //if it's created, show him a warning
  80.  
  81. $this->load->model('user');
  82. if($this->user->check_to_install()){
  83. $this->load->model('installer');
  84. $data=$this->installer->save();
  85. echo json_encode($data);
  86. }else{
  87. //probably should log the ip address
  88. // $data['status']="error";
  89. // $data['message']="Super admin is already created, please login to that account, this page is disabled";
  90. // echo json_encode($data);
  91. show_404();
  92. }
  93. }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement