Moving large chunks of code around so that the functions.inc.php file is the main file to getting data loaded into the phpgw_info array. Basicly functions is the file to follow to see whats being loaded and where. We will need to add a bunch of debugging flags throught this file so that debugging can be turned on and the path can easily be followed.

This commit is contained in:
seek3r 2001-02-07 20:22:17 +00:00
parent 1054c949b4
commit 1ba6eb78d2
4 changed files with 704 additions and 612 deletions

View File

@ -684,39 +684,10 @@
return $count;
}
/* Wrapper to the session->appsession() */
function appsession($data = "##NOTHING##") {
global $phpgw_info, $phpgw;
if ($data == "##NOTHING##") { /* This allows the user to put "" as the value. */
$phpgw->db->query("select content from phpgw_app_sessions where sessionid = '"
.$phpgw_info["user"]["sessionid"]."' and loginid = '"
.$phpgw_info["user"]["userid"]."' and app = '"
.$phpgw_info["flags"]["currentapp"] . "'",__LINE__,__FILE__);
if($phpgw->db->num_rows()) {
$phpgw->db->next_record();
$data = $phpgw->db->f("content");
$data = $this->decrypt($data);
return $data;
}
} else {
$data = $this->encrypt($data);
$phpgw->db->query("select * from phpgw_app_sessions where sessionid = '"
. $phpgw_info["user"]["sessionid"] . "' and app = '"
. $phpgw_info["flags"]["currentapp"] . "'",__LINE__,__FILE__);
if ($phpgw->db->num_rows()==0) {
$phpgw->db->query("INSERT INTO phpgw_app_sessions (sessionid,loginid,app,content)"
." VALUES ('".$phpgw_info["user"]["sessionid"]."','"
.$phpgw_info["user"]["userid"]
."','".$phpgw_info["flags"]["currentapp"]."','".$data."');",__LINE__,__FILE__);
} else {
$phpgw->db->query("update phpgw_app_sessions set content = '$data' where sessionid = '"
.$phpgw_info["user"]["sessionid"]."' and loginid = '"
.$phpgw_info["user"]["userid"]."'",__LINE__,__FILE__);
}
$data = $this->decrypt($data);
return $data;
}
return $phpgw->session->appsession($data);
}
function show_date($t = "", $format = "")

View File

@ -57,7 +57,7 @@
// You could redirect them to login.php with code 2 or use the default
// I recommend using the default until all of the bugs are worked out.
function phpgw_()
function phpgw()
{
global $phpgw_info, $sessionid, $login;
/************************************************************************\
@ -69,134 +69,30 @@
$this->db->Database = $phpgw_info["server"]["db_name"];
$this->db->User = $phpgw_info["server"]["db_user"];
$this->db->Password = $phpgw_info["server"]["db_pass"];
if ($this->debug) {
$this->db->Debug = 1;
}
if ($phpgw_info["flags"]["currentapp"] == "login") {
$this->db->query("select * from config",__LINE__,__FILE__);
while ($this->db->next_record()) {
$phpgw_info["server"][$this->db->f("config_name")] = stripslashes($this->db->f("config_value"));
}
} else {
$config_var = array("encryptkey","auth_type","account_repository");
$c = "";
for ($i=0;$i<count($config_var);$i++) {
if ($i) {
$c .= " OR ";
}
$c .= "config_name='".$config_var[$i]."'";
}
$this->db->query("select * from config where $c",__LINE__,__FILE__);
while ($this->db->next_record()) {
$phpgw_info["server"][$this->db->f("config_name")] = stripslashes($this->db->f("config_value"));
}
}
/************************************************************************\
* Continue adding the classes *
\************************************************************************/
$this->common = CreateObject("phpgwapi.common");
$this->hooks = CreateObject("phpgwapi.hooks");
$this->auth = createobject("phpgwapi.auth");
$this->acl = CreateObject("phpgwapi.acl");
$this->accounts = createobject("phpgwapi.accounts");
$this->session = CreateObject("phpgwapi.sessions");
$this->preferences = CreateObject("phpgwapi.preferences");
$this->applications = CreateObject("phpgwapi.applications");
if ($phpgw_info["flags"]["currentapp"] == "login") {
if ($login != ""){
$login_array = explode("@",$login);
$login_id = $this->accounts->name2id($login_array[0]);
$this->accounts->accounts($login_id);
$this->preferences->preferences($login_id);
}
} elseif (! $this->session->verify()) {
$this->db->query("select config_value from config where config_name='webserver_url'",__LINE__,__FILE__);
$this->db->next_record();
Header("Location: " . $this->redirect($this->link($this->db->f("config_value")."/login.php","cd=10")));
exit;
}
$this->translation = CreateObject("phpgwapi.translation");
$sep = $phpgw_info["server"]["dir_separator"];
$template_root = $this->common->get_tpl_dir();
if (is_dir($template_root)) {
$this->template = CreateObject("phpgwapi.Template", $template_root);
}
}
/**************************************************************************\
* Core functions *
\**************************************************************************/
/* A function to handle session support via url session id, or cookies */
/* Wrapper to the session->link() */
function link($url = "", $extravars = "")
{
global $phpgw, $phpgw_info, $usercookie, $kp3, $PHP_SELF;
if ($url == $PHP_SELF){ $url = ""; } //fix problems when PHP_SELF if used as the param
if (! $kp3) { $kp3 = $phpgw_info["user"]["kp3"]; }
// Explicit hack to work around problems with php running as CGI on windows
// please let us know if this doesn't work for you!
if (! $url && (PHP_OS == "Windows" || PHP_OS == "OS/2" || PHP_OS == "WIN32" || PHP_OS == "WIN16")) {
$exe = strpos($PHP_SELF,"php.exe");
if ($exe != false) {
$exe += 7; // strlen("php.exe")
$url_root = split ("/", $phpgw_info["server"]["webserver_url"]);
$url = (strlen($url_root[0])? $url_root[0].'//':'') . $url_root[2];
$url .= substr($PHP_SELF,$exe,strlen($PHP_SELF)-$exe);
}
}
if (! $url) {
$url_root = split ("/", $phpgw_info["server"]["webserver_url"]);
/* Some hosting providers have their paths screwy.
If the value from $PHP_SELF is not what you expect, you can use this to patch it
It will need to be adjusted to your specific problem tho.
*/
//$patched_php_self = str_replace("/php4/php/phpgroupware", "/phpgroupware", $PHP_SELF);
$patched_php_self = $PHP_SELF;
$url = (strlen($url_root[0])? $url_root[0].'//':'') . $url_root[2] . $patched_php_self;
}
if (isset($phpgw_info["server"]["usecookies"]) &&
$phpgw_info["server"]["usecookies"]) {
if ($extravars) { $url .= "?$extravars"; }
} else {
$url .= "?sessionid=" . $phpgw_info["user"]["sessionid"];
$url .= "&kp3=" . $kp3;
$url .= "&domain=" . $phpgw_info["user"]["domain"];
// This doesn't belong in the API.
// Its up to the app to pass this value. (jengo)
// Putting it into the app requires a massive number of updates in email app.
// Until that happens this needs to stay here (seek3r)
if ($phpgw_info["flags"]["newsmode"]) { $url .= "&newsmode=on"; }
if ($extravars) { $url .= "&$extravars"; }
}
$url = str_replace("/?", "/index.php?", $url);
$webserver_url_count = strlen($phpgw_info["server"]["webserver_url"]);
$slash_check = strtolower(substr($url ,0,1));
if(substr($url ,0,$webserver_url_count) != $phpgw_info["server"]["webserver_url"]) {
$app = $phpgw_info["flags"]["currentapp"];
if($slash_check == "/") {
$url = $phpgw_info["server"]["webserver_url"].$url;
} elseif ($app == "home" || $app == "logout" || $app == "login"){
$url = $phpgw_info["server"]["webserver_url"]."/".$url;
}else{
$url = $phpgw_info["server"]["webserver_url"]."/".$app."/".$url;
}
}
return $url;
}
function strip_html($s)
{
return htmlspecialchars(stripslashes($s));
return $this->session->link($url, $extravars);
}
function redirect($url = "")
@ -228,8 +124,7 @@
function lang($key, $m1 = "", $m2 = "", $m3 = "", $m4 = "")
{
global $phpgw;
return $phpgw->translation->translate($key);
return $this->translation->translate($key);
}
} //end phpgw class
?>

View File

@ -36,6 +36,9 @@
var $db;
var $db2;
/*************************************************************************\
* Constructor just loads up some defaults from cookies *
\*************************************************************************/
function sessions()
{
global $phpgw, $phpgw_info, $sessionid, $kp3;
@ -46,6 +49,9 @@
$this->kp3 = $kp3;
}
/*************************************************************************\
* Functions for creating and verifying the session *
\*************************************************************************/
function getuser_ip()
{
global $REMOTE_ADDR, $HTTP_X_FORWARDED_FOR;
@ -150,37 +156,6 @@
. $this->sessionid . "'",__LINE__,__FILE__);
}
function read_repositories()
{
global $phpgw_info, $phpgw;
$phpgw->acl->acl($this->account_id);
$phpgw->accounts->accounts($this->account_id);
$phpgw->preferences->preferences($this->account_id);
$phpgw->applications->applications($this->account_id);
$phpgw_info["user"] = $phpgw->accounts->read_repository();
$phpgw_info["user"]["acl"] = $phpgw->acl->read_repository();
$phpgw_info["user"]["preferences"] = $phpgw->preferences->read_repository();
$phpgw_info["user"]["apps"] = $phpgw->applications->read_repository();
@reset($phpgw_info["user"]["apps"]);
$phpgw_info["user"]["domain"] = $this->account_domain;
$phpgw_info["user"]["sessionid"] = $this->sessionid;
$phpgw_info["user"]["kp3"] = $this->kp3;
$phpgw_info["user"]["session_ip"] = $this->getuser_ip();
$phpgw_info["user"]["session_lid"] = $this->account_lid."@".$this->account_domain;
$phpgw_info["user"]["account_id"] = $this->account_id;
$phpgw_info["user"]["account_lid"] = $this->account_lid;
$phpgw_info["user"]["userid"] = $this->account_lid;
$phpgw_info["user"]["passwd"] = $this->passwd;
$this->data["user"] = $phpgw_info["user"];
$this->data["apps"] = $phpgw_info["apps"];
$this->data["server"] = $phpgw_info["server"];
$this->data["hooks"] = $phpgw->hooks->read();
$this->data["user"]["preferences"] = $phpgw_info["user"]["preferences"];
$this->data["user"]["kp3"] = "";
}
function create($login,$passwd)
{
global $phpgw_info, $phpgw;
@ -292,5 +267,227 @@
return True;
}
/*************************************************************************\
* Functions for appsession data and session cache *
\*************************************************************************/
function read_repositories()
{
global $phpgw_info, $phpgw;
$phpgw->acl->acl($this->account_id);
$phpgw->accounts->accounts($this->account_id);
$phpgw->preferences->preferences($this->account_id);
$phpgw->applications->applications($this->account_id);
$phpgw_info["user"] = $phpgw->accounts->read_repository();
$phpgw_info["user"]["acl"] = $phpgw->acl->read_repository();
$phpgw_info["user"]["preferences"] = $phpgw->preferences->read_repository();
$phpgw_info["user"]["apps"] = $phpgw->applications->read_repository();
@reset($phpgw_info["user"]["apps"]);
$phpgw_info["user"]["domain"] = $this->account_domain;
$phpgw_info["user"]["sessionid"] = $this->sessionid;
$phpgw_info["user"]["kp3"] = $this->kp3;
$phpgw_info["user"]["session_ip"] = $this->getuser_ip();
$phpgw_info["user"]["session_lid"] = $this->account_lid."@".$this->account_domain;
$phpgw_info["user"]["account_id"] = $this->account_id;
$phpgw_info["user"]["account_lid"] = $this->account_lid;
$phpgw_info["user"]["userid"] = $this->account_lid;
$phpgw_info["user"]["passwd"] = $this->passwd;
$this->data["user"] = $phpgw_info["user"];
$this->data["apps"] = $phpgw_info["apps"];
$this->data["server"] = $phpgw_info["server"];
$this->data["hooks"] = $phpgw->hooks->read();
$this->data["user"]["preferences"] = $phpgw_info["user"]["preferences"];
$this->data["user"]["kp3"] = "";
}
function appsession($data = "##NOTHING##", $location = "default") {
global $phpgw_info, $phpgw;
if ($data == "##NOTHING##") { /* This allows the user to put "" as the value. */
$sql = 'select content from phpgw_app_sessions where'
.' sessionid = "'.$this->sessionid.'"'
.' and loginid = "'.$this->account_id.'"'
.' and app = "'.$phpgw_info["user"]["currentapp"].'"'
.' and location = "'.$location.'"',__LINE__,__FILE__
);
$phpgw->db->query($sql,__LINE__,__FILE__);
if($phpgw->db->num_rows()) {
$phpgw->db->next_record();
$data = $phpgw->db->f("content");
// $data = $phpgw->common->decrypt($data);
return $data;
}
} else {
// $data = $phpgw->common->encrypt($data);
$sql = 'select content from phpgw_app_sessions where'
.' sessionid = "'.$this->sessionid.'"'
.' and loginid = "'.$this->account_id.'"'
.' and app = "'.$phpgw_info["user"]["currentapp"].'"'
.' and location = "'.$location.'"',__LINE__,__FILE__
);
$phpgw->db->query($sql,__LINE__,__FILE__);
if ($phpgw->db->num_rows()==0) {
$sql = 'INSERT INTO phpgw_app_sessions (sessionid,loginid,app,location,content)'
.' VALUES ("'.$this->sessionid.'"'
.' ","'.$this->account_id.'"'
.' ","'.$phpgw_info["flags"]["currentapp"].'"'
.' ","'.$location.'"'
.' ","'.$data.'"')'
);
$phpgw->db->query($sql,__LINE__,__FILE__);
} else {
$sql = 'update phpgw_app_sessions set content = "'.$data.'"'
.' where sessionid = "'.$this->sessionid.'"'
.' and loginid = "'.$this->account_id.'"'
.' and app = "'.$phpgw_info["user"]["currentapp"].'"'
.' and location = "'.$location.'"',__LINE__,__FILE__
);
$phpgw->db->query($sql,__LINE__,__FILE__);
}
//$data = $phpgw->common->decrypt($data);
return $data;
}
}
function restore()
{
global $phpgw;
$serializedData = $phpgw->common->appsession();
$sessionData = unserialize($serializedData);
if (is_array($sessionData))
{
reset($sessionData);
while(list($key,$value) = each($sessionData))
{
global $$key;
$$key = $value;
$this->variableNames[$key]="registered";
#print "restored: ".$key.", $value<br>";
}
}
}
// save the current values of the variables
function save()
{
global $phpgw;
if (is_array($this->variableNames))
{
reset($this->variableNames);
while(list($key, $value) = each($this->variableNames))
{
if ($value == "registered")
{
global $$key;
$sessionData[$key] = $$key;
}
}
$serializedData = addslashes(serialize($sessionData));
$phpgw->common->appsession($serializedData);
}
}
// create a list a variable names, wich data need's to be restored
function register($_variableName)
{
$this->variableNames[$_variableName]="registered";
#print "registered $_variableName<br>";
}
// mark variable as unregistered
function unregister($_variableName)
{
$this->variableNames[$_variableName]="unregistered";
#print "unregistered $_variableName<br>";
}
// check if we have a variable registred already
function is_registered($_variableName)
{
if ($this->variableNames[$_variableName] == "registered")
{
return True;
}
else
{
return False;
}
}
}
/*************************************************************************\
* Function to handle session support via url or cookies *
\*************************************************************************/
function link($url = "", $extravars = "")
{
global $phpgw, $phpgw_info, $usercookie, $kp3, $PHP_SELF;
/* Fix problems when PHP_SELF if used as the param */
if ($url == $PHP_SELF){ $url = ""; }
if (! $kp3) { $kp3 = $phpgw_info["user"]["kp3"]; }
// Explicit hack to work around problems with php running as CGI on windows
// please let us know if this doesn't work for you!
if (! $url && (PHP_OS == "Windows" || PHP_OS == "OS/2" || PHP_OS == "WIN32" || PHP_OS == "WIN16")) {
$exe = strpos($PHP_SELF,"php.exe");
if ($exe != false) {
$exe += 7; // strlen("php.exe")
$url_root = split ("/", $phpgw_info["server"]["webserver_url"]);
$url = (strlen($url_root[0])? $url_root[0].'//':'') . $url_root[2];
$url .= substr($PHP_SELF,$exe,strlen($PHP_SELF)-$exe);
}
}
if (! $url) {
$url_root = split ("/", $phpgw_info["server"]["webserver_url"]);
/* Some hosting providers have their paths screwy.
If the value from $PHP_SELF is not what you expect, you can use this to patch it
It will need to be adjusted to your specific problem tho.
*/
//$patched_php_self = str_replace("/php4/php/phpgroupware", "/phpgroupware", $PHP_SELF);
$patched_php_self = $PHP_SELF;
$url = (strlen($url_root[0])? $url_root[0].'//':'') . $url_root[2] . $patched_php_self;
}
if (isset($phpgw_info["server"]["usecookies"]) &&
$phpgw_info["server"]["usecookies"]) {
if ($extravars) { $url .= "?$extravars"; }
} else {
$url .= "?sessionid=" . $phpgw_info["user"]["sessionid"];
$url .= "&kp3=" . $kp3;
$url .= "&domain=" . $phpgw_info["user"]["domain"];
// This doesn't belong in the API.
// Its up to the app to pass this value. (jengo)
// Putting it into the app requires a massive number of updates in email app.
// Until that happens this needs to stay here (seek3r)
if ($phpgw_info["flags"]["newsmode"]) { $url .= "&newsmode=on"; }
if ($extravars) { $url .= "&$extravars"; }
}
$url = str_replace("/?", "/index.php?", $url);
$webserver_url_count = strlen($phpgw_info["server"]["webserver_url"]);
$slash_check = strtolower(substr($url ,0,1));
if(substr($url ,0,$webserver_url_count) != $phpgw_info["server"]["webserver_url"]) {
$app = $phpgw_info["flags"]["currentapp"];
if($slash_check == "/") {
$url = $phpgw_info["server"]["webserver_url"].$url;
} elseif ($app == "home" || $app == "logout" || $app == "login"){
$url = $phpgw_info["server"]["webserver_url"]."/".$url;
}else{
$url = $phpgw_info["server"]["webserver_url"]."/".$app."/".$url;
}
}
return $url;
}
}
?>

View File

@ -56,7 +56,7 @@
return $value;
}
// Just a temp wrapper.
/* Just a temp wrapper. ###DELETE_ME#### (Seek3r) */
function check_code($code)
{
global $phpgw;
@ -239,22 +239,53 @@
'named' => True
);
/****************************************************************************\
* These lines load up the API, fill up the $phpgw_info array, etc *
\****************************************************************************/
/* Load main class */
$phpgw = CreateObject("phpgwapi.phpgw");
$phpgw->phpgw_();
/* Fill phpgw_info["server"] array */
$phpgw->db->query("select * from config",__LINE__,__FILE__);
while ($phpgw->db->next_record()) {
$phpgw_info["server"][$phpgw->db->f("config_name")] = stripslashes($phpgw->db->f("config_value"));
}
// Handy little shortcut
$sep = $phpgw_info["server"]["dir_separator"];
if ($phpgw_info["flags"]["currentapp"] == "login") {
if ($login != ""){
$login_array = explode("@",$login);
$login_id = $this->accounts->name2id($login_array[0]);
$this->accounts->accounts($login_id);
$this->preferences->preferences($login_id);
}
} elseif (! $this->session->verify()) {
Header("Location: " . $phpgw->redirect($phpgw->session->link($phpgw_info["server"]["webserver_url"]."/login.php","cd=10")));
exit;
}
$template_root = $this->common->get_tpl_dir();
if (is_dir($template_root)) {
$this->template = CreateObject("phpgwapi.Template", $template_root);
}
//incase we are dealing with a fresh login
if (! isset($phpgw_info["user"]["preferences"]["common"]["template_set"])) {
$phpgw_info["user"]["preferences"]["common"]["template_set"] = "default";
}
/****************************************************************************\
* Everything from this point on will ONLY happen if *
* the currentapp is not login or logout *
\****************************************************************************/
if ($phpgw_info["flags"]["currentapp"] != "login" && $phpgw_info["flags"]["currentapp"] != "logout") {
//if (! $phpgw->session->verify()) {
// Header("Location: " . $phpgw->link($phpgw_info["server"]["webserver_url"] . "/login.php", "cd=10"));
// exit;
//}
if (! $phpgw->session->verify()) {
Header("Location: " . $phpgw->redirect($phpgw->session->link($phpgw_info["server"]["webserver_url"]."/login.php","cd=10")));
exit;
}
load_optional();
phpgw_fillarray();
@ -266,7 +297,6 @@
if (! isset($phpgw_info["flags"]["nocommon_preferences"]) || ! $phpgw_info["flags"]["nocommon_preferences"]) {
if (! isset($phpgw_info["user"]["preferences"]["common"]["maxmatchs"]) ||
!$phpgw_info["user"]["preferences"]["common"]["maxmatchs"]) {
// $phpgw->preferences->change("common","maxmatchs",15);
$phpgw->preferences->add("common","maxmatchs",15);
$preferences_update = True;
}
@ -324,7 +354,6 @@
* Verify that the users session is still active otherwise kick them out *
\*************************************************************************/
if ($phpgw_info["flags"]["currentapp"] != "home" &&
$phpgw_info["flags"]["currentapp"] != "logout" &&
$phpgw_info["flags"]["currentapp"] != "preferences" &&
$phpgw_info["flags"]["currentapp"] != "about") {