Platform  3.1
PHP API documentation
 All Data Structures Namespaces Files Functions Variables Pages
wenv.php
Go to the documentation of this file.
1 <?php
2 /*
3  * @author Anakeen
4  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
5  * @package FDL
6 */
7 /**
8  * WHAT Environnement
9  *
10  * @author Anakeen 2004
11  * @version $Id: wenv.php,v 1.11 2008/05/06 17:04:16 jerome Exp $
12  * @license http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ Anakeen - licence CC
13  * @package FDL
14  */
15 /**
16  */
17 
18 global $_SERVER;
19 
20 function getBaseDirList()
21 {
22  include_once ('WHAT/Lib.Prefix.php');
23  # $bl[] = "default";
24  if (!is_dir(DEFAULT_PUBDIR . "/context/")) return $bl;
25 
26  if ($dh = opendir(DEFAULT_PUBDIR . "/context/")) {
27  while (($file = readdir($dh)) !== false) {
28  if ($file != ".." && $file != "." && is_dir(DEFAULT_PUBDIR . "/context/" . $file) && file_exists(DEFAULT_PUBDIR . "/context/" . $file . "/dbaccess.php")) $bl[] = $file;
29  }
30  fclose($dh);
31  }
32  return $bl;
33 }
34 
35 function setBaseDir($freedomctx = "default")
36 {
37  include_once ('WHAT/Lib.Prefix.php');
38  if (is_dir(DEFAULT_PUBDIR . "/context/" . $freedomctx)) return DEFAULT_PUBDIR . "/context/" . $freedomctx;
39  else return DEFAULT_PUBDIR;
40 }
41 
42 function isRealDb($freedomctx = "default")
43 {
44  include_once ('WHAT/Lib.Prefix.php');
45  if (file_exists(DEFAULT_PUBDIR . "/context/" . $freedomctx . "/dbaccess.php")) return true;
46  return false;
47 }
48 
49 function getPhpEnv($freedomctx)
50 {
51  include_once ('WHAT/Lib.Prefix.php');
52  $vdir = setBaseDir($freedomctx);
53  if (file_exists($vdir . "/dbaccess.php")) $env = $vdir . "/dbaccess.php";
54  else $env = $vdir . "/dbaccess.php";
55  return $env;
56 }
57 
58 function getShEnv($freedomctx)
59 {
60  error_log("Deprecated call to getShEnv()");
61  return "";
62 
63  include_once ('WHAT/Lib.Prefix.php');
64  $vdir = setBaseDir($freedomctx);
65  if (file_exists($vdir . "/dbaccess.sh")) $env = $vdir . "/dbaccess.sh";
66  else $env = $vdir . "/dbaccess.sh";
67  return $env;
68 }
69 
70 function setCurrentDb($freedomctx = "default")
71 {
72  error_log("Deprecated call to setCurrentDb() in " . __FILE__ . " : use setCurrentContext(ctxName)");
73  return setCurrentContext($freedomctx);
74 }
75 
76 function setCurrentContext($freedomctx = "default")
77 {
78  include_once ('WHAT/Lib.Prefix.php');
79  $fcur = fopen(DEFAULT_PUBDIR . "/.freedom", 'w');
80  fprintf($fcur, $freedomctx);
81  fclose($fcur);
82  $dpath = DEFAULT_PUBDIR . "/context/" . $freedomctx;
83  system(sprintf("ln -sf %s/dbaccess.sh %s/.freedom.sh", escapeshellarg($dpath) , escapeshellarg(DEFAULT_PUBDIR)));
84 }
85 
86 function getCurrentDb()
87 {
88  error_log("Deprecated call to getCurrentDb in " . __FILE___ . " : use getCurrentContext()");
89  return getCurrentContext();
90 }
91 
93 {
94  if (file_exists(DEFAULT_PUBDIR . "/.freedom")) return file_get_contents(DEFAULT_PUBDIR . "/.freedom");
95  return "default";
96 }
97 
98 function initDbContext($freedomctx = "default", $pgservice_core = "anakeen", $pgservice_freedom = "freedom")
99 {
100  include_once ('WHAT/Lib.Prefix.php');
101 
102  $inphpfile = DEFAULT_PUBDIR . "/dbaccess.php.in";
103  $inshfile = DEFAULT_PUBDIR . "/dbaccess.sh.in";
104 
105  $vdir = DEFAULT_PUBDIR . "/context/" . $freedomctx;
106  $dbfphp = "$vdir/dbaccess.php";
107  $dbfsh = "$vdir/dbaccess.sh";
108 
109  if (!is_dir($vdir)) mkdir($vdir, 0755, true);
110 
111  if (file_exists($dbf)) return false;
112 
113  $httpu = getenv("httpuser");
114  $httpconf = getenv("httpconf");
115 
116  $sed_1 = sprintf('s/@PGSERVICE_CORE@/%s/g', str_replace('/', '\/', $pgservice_core));
117  $sed_2 = sprintf('s/@PGSERVICE_FREEDOM@/%s/g', str_replace('/', '\/', $pgservice_freedom));
118  $sed_3 = sprintf('s/@FREEDOM_CONTEXT@/%s/g', str_replace('/', '\/', $freedomctx));
119 
120  $command = sprintf("sed -e %s -e %s -e %s", escapeshellarg($sed_1) , escapeshellarg($sed_2) , escapeshellarg($sed_3));
121 
122  system(sprintf("cat %s | $command > %s", escapeshellarg($inphpfile) , escapeshellarg($dbfphp)));
123  system(sprintf("cat %s | $command > %s", escapeshellarg($inshfile) , escapeshellarg($dbfsh)));
124 
125  setCurrentContext($freedomctx);
126 }
127 ?>
← centre documentaire © anakeen - published under CC License - Dynacase