Advertisement
Guest User

Untitled

a guest
May 16th, 2014
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. <?php
  2.  
  3. class Form_model extends CI_Model
  4. {
  5.  
  6.  
  7. function check()
  8. {
  9. $this -> load -> helper(array('form', 'url'));
  10.  
  11. $this -> load -> library('form_validation');
  12.  
  13. $this -> form_validation -> set_rules('db_driver', 'db_driver', 'required');
  14. $this -> form_validation -> set_rules('db_hostname', 'db_hostname', 'required');
  15. $this -> form_validation -> set_rules('db_username', 'db_username', 'required');
  16. $this -> form_validation -> set_rules('db_password', 'Password');
  17. $this -> form_validation -> set_rules('db_database', 'db_database', 'required');
  18. $this -> form_validation -> set_rules('db_prefix', 'db_prefix');
  19.  
  20. if ($this -> form_validation -> run() == false) {
  21. return FALSE;
  22. } else {
  23. $dbconfig['hostname'] = $this -> input -> post('db_hostname');
  24. $dbconfig['username'] = $this -> input -> post('db_username');
  25. $dbconfig['password'] = $this -> input -> post('db_password');
  26. $dbconfig['database'] = $this -> input -> post('db_database');
  27. $dbconfig['dbprefix'] = $this -> input -> post('db_prefix');
  28. //$dbconfig['pconnect'] = ($this->input->post('pconnect')) ? TRUE : TRUE;
  29. $dbconfig['dbdriver'] = 'mysqli';
  30.  
  31. $this -> load -> helper('file');
  32.  
  33. $prototype = array('hostname' => '', 'username' => '', 'password' => '', 'database' => '', 'dbdriver' => '', 'dbprefix' => '', 'pconnect' => true, 'db_debug' => false, 'cache_on' => false, 'cachedir' => '', 'char_set' => 'utf8', 'dbcollat' => 'utf8_general_ci');
  34. // Now we read the file data as a string
  35. $config_file = read_file(self::$path);
  36. //self::$content = $config_file;
  37. //$this->set_config('hostname','localhost');
  38. // Dollar signs seem to create a problem with our preg_replace
  39. // so we'll temporarily swap them out
  40. $config_file = str_replace('$', '@s@', $config_file);
  41. // Cycle through the newconfig array and swap out the data
  42. if (count($dbconfig) > 0) {
  43. $active_group = 'default';
  44. foreach ($dbconfig as $key => $val) {
  45. if ($val === 'y') {
  46. $val = true;
  47. } elseif ($val == 'n') {
  48. $val = false;
  49. }
  50.  
  51. if (is_bool($val)) {
  52. $val = ($val == true) ? 'TRUE' : 'FALSE';
  53. } else {
  54. $val = '\'' . $val . '\'';
  55. }
  56. $val .= ';';
  57.  
  58. // Update the value
  59. $config_file = preg_replace("#(\@s\@db\[(['\"])" . $active_group . "\\2\]\[(['\"])" . $key . "\\3\]\s*=\s*).*?;#", "\\1$val", $config_file);
  60. }
  61. }
  62.  
  63. return TRUE;
  64.  
  65. }
  66.  
  67. }
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement