Guest User

Untitled

a guest
Dec 1st, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.88 KB | None | 0 0
  1. <?php
  2.  
  3. class Install extends Public_Controller
  4. {
  5.  
  6. function __construct()
  7. {
  8. log_message('debug', "*** URI: " . $this->uri->ruri_string());
  9. parent::__construct();
  10. }
  11.  
  12. function index()
  13. {
  14. $this->load->model('users_model', 'users');
  15. $this->load->view('install/install_view');
  16. }
  17.  
  18. function gentables()
  19. {
  20.  
  21. $this->load->library('form_validation');
  22. $this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[5]|callback__test');
  23. $this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[5]|matches[passconf]|md5');
  24. $this->form_validation->set_rules('passconf', 'Password Confirmation', 'trim|required');
  25.  
  26. if ($this->form_validation->run() == FALSE)
  27. {
  28.  
  29. $this->index();
  30. } else
  31. {
  32. $us = $this->input->post('username');
  33. $pw = $this->input->post('password');
  34.  
  35. $this->load->dbforge();
  36.  
  37. $db_users_fields = array(
  38. 'id' => array(
  39. 'type' => 'INT',
  40. 'auto_increment' => TRUE,
  41. ),
  42. 'username' => array(
  43. 'type' => 'VARCHAR',
  44. 'constraint' => '255',
  45. ),
  46. 'password' => array(
  47. 'type' => 'VARCHAR',
  48. 'constraint' => '255',
  49. ),
  50. );
  51. $this->dbforge->add_field($db_users_fields);
  52. $this->dbforge->add_key('id', TRUE);
  53. $this->dbforge->create_table('gcms_users', TRUE);
  54.  
  55.  
  56. $gallery_categories_fields = array(
  57. 'id' => array(
  58. 'type' => 'INT',
  59. 'auto_increment' => TRUE,
  60. ),
  61. 'title' => array(
  62. 'type' => 'VARCHAR',
  63. 'constraint' => '255',
  64. ),
  65. 'description' => array(
  66. 'type' => 'TEXT',
  67. ),
  68. 'order_id' => array(
  69. 'type' => 'INT',
  70. ),
  71. );
  72. $this->dbforge->add_field($gallery_categories_fields);
  73. $this->dbforge->add_key('id', TRUE);
  74. $this->dbforge->create_table('gcms_categories', TRUE);
  75.  
  76.  
  77. $gallery_assets_fields = array(
  78. 'img_id' => array(
  79. 'type' => 'INT',
  80. 'auto_increment' => TRUE,
  81. ),
  82. 'cat_id' => array(
  83. 'type' => 'INT',
  84. ),
  85. 'order_num' => array(
  86. 'type' => 'INT',
  87. ),
  88. 'filename' => array(
  89. 'type' => 'VARCHAR',
  90. 'constraint' => '255',
  91. ),
  92. 'thumbnail' => array(
  93. 'type' => 'VARCHAR',
  94. 'constraint' => '255',
  95. ),
  96. 'caption' => array(
  97. 'type' => 'TEXT',
  98. ),
  99. );
  100.  
  101. $this->dbforge->add_field($gallery_assets_fields);
  102. $this->dbforge->add_key('img_id', TRUE);
  103. $this->dbforge->create_table('gcms_assets', TRUE);
  104.  
  105.  
  106. $settings_fields = array(
  107. 'id' => array(
  108. 'type' => 'INT',
  109. 'auto_increment' => TRUE,
  110. ),
  111. 'thumb_width' => array(
  112. 'type' => 'INT',
  113. ),
  114. 'thumb_height' => array(
  115. 'type' => 'INT',
  116. ),
  117. 'crop' => array(
  118. 'type' => 'ENUM',
  119. 'constraint' => "'Y','N'",
  120. 'default' => "Y",
  121. ),
  122. );
  123. $this->dbforge->add_field($settings_fields);
  124. $this->dbforge->add_key('id', TRUE);
  125. $this->dbforge->create_table('gcms_settings', TRUE);
  126.  
  127. $sett->thumb_width = 100;
  128. $sett->thumb_height = 75;
  129. $sett->crop = "Y";
  130.  
  131. $createSampleSettings = $this->db->insert('gcms_settings', $sett);
  132.  
  133. $this->username = $us;
  134. $this->password = $pw;
  135. $insertNew = $this->db->insert('gcms_users', $this);
  136. if ($insertNew)
  137. {
  138. $this->_created($us, $pw);
  139. } else
  140. {
  141. echo("Operation Failed!");
  142. }
  143. }
  144. }
  145.  
  146. function _created($us, $pw)
  147. {
  148. $this->load->model('users_model', 'users');
  149. $results = $this->users->login($us, $pw);
  150. if ($results == false)
  151. {
  152. redirect(base_url() . 'gcmsadmin/login');
  153. }
  154. else
  155. {
  156. $this->load->library('session');
  157. $this->session->set_userdata(array('userid' => $results));
  158. $this->index();
  159. }
  160. }
  161.  
  162. function _does_username_exist($value)
  163. {
  164. $this->load->model('users_model', 'users');
  165. $value = trim($value);
  166. if (count($this->users->getUserByName($value)) === 0)
  167. {
  168. return true;
  169. }
  170. else
  171. {
  172. $this->form_validation->set_message('_does_username_exist', 'The username: ' . $value . ' already exists.');
  173. return false;
  174. }
  175. }
  176. // This is just testing a callback.
  177. function _test($value)
  178. {
  179. if ($value == 'test2')
  180. {
  181. $this->form_validation->set_message('_test', 'The field cannot be the "test2"');
  182. return false;
  183. }
  184. return true;
  185. }
  186. }
Add Comment
Please, Sign In to add comment