/developer/models/config.php

https://github.com/svrsreeraj/PHPFrame · PHP · 125 lines · 107 code · 10 blank · 8 comment · 17 complexity · 7afc8ead252ee3c80272d32e93ed0cfb MD5 · raw file

  1. <?php
  2. /**************************************************************************************
  3. Created by :Sreeraj
  4. Created on :2011-10-12
  5. Purpose :Admin Home Model Page
  6. ******************* *******************************************************************/
  7. class configModel extends modelclass
  8. {
  9. public $configPath = "../config.inc.php";
  10. public $lineBreak = "\r\n";
  11. public $bcpDirs = "../Backup/Config";
  12. public $byProductsConst = array();
  13. public $adminPanel = "adminpanel";
  14. public $adminPanelModules = "modules";
  15. public $adminPanelCore = "core";
  16. public $adminPanelCorePath = "../adminpanel/core/conf/coreConfig.php";
  17. public function Listing()
  18. {
  19. if(is_file($this->configPath)) require_once $this->configPath;
  20. }
  21. public function Submit()
  22. {
  23. if(is_dir($this->bcpDirs) && is_file($this->configPath))
  24. {
  25. copy($this->configPath, $this->bcpDirs."/config.inc.".strtotime("now").".php");
  26. }
  27. $data = $this->getData("post");
  28. $fp = fopen($this->configPath, 'w');
  29. fwrite($fp, $this->GetHeader());
  30. fwrite($fp, $this->GetProcessedValues($data,$exceptions=array("actionvar")));
  31. fwrite($fp, $this->GetProcessedValues($this->byProductsConst));
  32. fwrite($fp, $this->GetFooter());
  33. fclose($fp);
  34. $this->executeAction(array("action"=>"Dodbactions","navigate"=>true));
  35. }
  36. public function Dodbactions()
  37. {
  38. $this->checkAndInstallCoreDb();//inserting tables and data
  39. $this->executeAction(array("action"=>"Listing","navigate"=>true));
  40. }
  41. public function GetHeader()
  42. {
  43. $string .= "<?php" . $this->lineBreak;
  44. $string .= "/**********************************************************************" . $this->lineBreak;
  45. $string .= "Author - System" . $this->lineBreak;
  46. $string .= "Date - " . date('l jS \of F Y h:i:s A').$this->lineBreak;
  47. $string .= "Purpose - Main configuration file" . $this->lineBreak;
  48. $string .= "**********************************************************************/" . $this->lineBreak;
  49. return $string;
  50. }
  51. public function GetFooter()
  52. {
  53. $string .= "?>";
  54. return $this->returnVal($string);
  55. }
  56. public function GetProcessedValues($data,$exceptions=array())
  57. {
  58. foreach ($data as $key=> $val)
  59. {
  60. if(!in_array(trim($key), $exceptions))
  61. if(trim($val)) $string .= "define('".strtoupper(trim($key))."','". $this->OverRideValue(trim($key),trim($val))."');". $this->lineBreak;
  62. else $string .= "define('".strtoupper(trim($key))."','". "" ."');". $this->lineBreak;
  63. }
  64. $string .= $this->lineBreak.$this->lineBreak;
  65. return $string;
  66. }
  67. public function OverRideValue($key,$value)
  68. {
  69. switch (trim(strtoupper($key)))
  70. {
  71. case "CONST_SITE_ADDRESS":
  72. $userHost = trim($value);
  73. if(strstr($userHost,"https://")) $constHostAddress = "https://";
  74. else $constHostAddress = "http://";
  75. $userHost = str_replace("http://","", $userHost);
  76. $userHost = str_replace("https//","", $userHost);
  77. if($pos = strpos($userHost, "/")) $userHost = substr($userHost,0,$pos);
  78. $this->byProductsConst["CONST_HOST_ADDRESS"] = $constHostAddress.$userHost."/";
  79. $this->byProductsConst["CONST_SITE_ADDRESS_HOST"] = $userHost;
  80. $value = strrev(trim($value));
  81. if($value{0} != "/") $value = strrev($value)."/";
  82. else $value = strrev($value);
  83. $this->byProductsConst["CONST_SITE_ADMIN_ADDRESS"] = $value.$this->adminPanel."/";
  84. $this->byProductsConst["CONST_SITE_ADMIN_MODULE_ADDRESS"] = $value.$this->adminPanel."/".$this->adminPanelModules."/";
  85. $this->byProductsConst["CONST_SITE_ADMIN_CORE_ADDRESS"] = $value.$this->adminPanel."/".$this->adminPanelCore."/";
  86. return $value;
  87. break;
  88. case "CONST_SITE_ABSOLUTE_PATH":
  89. $userAbs = trim($value);
  90. $userAbsFromUser = strrev($userAbs);
  91. if($userAbsFromUser{0} != "/") $userAbsFromUser = strrev($userAbsFromUser)."/";
  92. else $userAbsFromUser = strrev($userAbsFromUser);
  93. return $userAbsFromUser;
  94. break;
  95. case "CONST_LOCAL_OR_ONLINE":
  96. if (strtolower(trim($value)) != "local" && strtolower(trim($value)) != "online") $value = "local";
  97. else $value = strtolower(trim($value));
  98. $this->byProductsConst["WHERE_AM_I"] = $value;
  99. return $value;
  100. break;
  101. }
  102. return $value;
  103. }
  104. public function checkAndInstallCoreDb()
  105. {
  106. require $this->adminPanelCorePath;
  107. foreach($queries["tables"] as $key=>$val)
  108. {
  109. if(!$this->db_query("SELECT count(*) FROM `".$key."` WHERE 1"))
  110. {
  111. if($this->db_query($val)) $this->db_query($queries["insert"][$key]);
  112. }
  113. }
  114. }
  115. }