ILIAS  Release_3_10_x_branch Revision 61812
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilClient Class Reference

client management More...

+ Collaboration diagram for ilClient:

Public Member Functions

 ilClient ($a_client_id, $a_db_connections)
 Constructor.
 init ()
 init client load client.ini and set some constants
 getId ()
 get client id
 setId ($a_client_id)
 set client id
 getName ()
 get client name
 setName ($a_str)
 set client name
 getDescription ()
 get client description
 setDescription ($a_str)
 set client description
 getMySQLVersion ()
 get mysql version
 isMysql4_1OrHigher ()
 check wether current MySQL server is version 4.1.x or higher
 connect ()
 connect to client database
 isInstalledDB (&$a_db)
 check if client db is installed
 setDSN ()
 set the dsn and dsn_host
 setDbHost ($a_str)
 set the host
 getDbHost ()
 get db host
 setDbName ($a_str)
 set the name of database
 getDbName ()
 get name of database
 setDbUser ($a_str)
 set db user
 getDbUser ()
 get db user
 setDbPass ($a_str)
 set db password
 getDbPass ()
 get db password
 getDataDir ()
 get client datadir path
 getWebspaceDir ()
 get client webspacedir path
 checkDatabaseHost ()
 check database connection
 checkDatabaseExists ()
 check database connection with database name
 reconnect ()
 getSetting ($a_keyword)
 read one value from settings table public
 getAllSettings ()
 read all values from settings table public
 setSetting ($a_key, $a_val)
 write one value to settings table public
 getURLStringForNIC ($a_nic_url)
 updateNIC ($a_nic_url)
 Connect to ILIAS-NIC.
 setNICkey ()
 set nic_key generate nic_key if nic_key field in cust table is empty.
 getNICkey ()
 get nic_key public
 getDefaultLanguage ()
 setDefaultLanguage ($a_lang_key)
 getError ()
 get error message and clear error var
 delete ($a_ini=true, $a_db=false, $a_files=false)
 delete client
 create ()
 create a new client and its subdirectories

Data Fields

 $id
 $dir
 $name
 $db_exists = false
 $db_installed = false
 $client_defaults
 $status
 $setup_ok = false
 $nic_status

Detailed Description

client management

Author
Sascha Hofmann shofm.nosp@m.ann@.nosp@m.datab.nosp@m.ay.d.nosp@m.e
Version
Id:
class.ilClient.php 16737 2008-05-30 21:34:44Z akill

Definition at line 32 of file class.ilClient.php.

Member Function Documentation

ilClient::checkDatabaseExists ( )

check database connection with database name

Returns
boolean

Definition at line 399 of file class.ilClient.php.

References isInstalledDB().

{
//try to connect to database
$db = $this->db_connections->connectDB($this->dsn);
if (MDB2::isError($db))
{
return false;
}
if (!$this->isInstalledDB($db))
{
return false;
}
return true;
}

+ Here is the call graph for this function:

ilClient::checkDatabaseHost ( )

check database connection

Returns
boolean

Definition at line 378 of file class.ilClient.php.

References $lng.

{
global $lng;
//connect to databasehost
$db = $this->db_connections->connectHost($this->dsn_host);
if (MDB2::isError($db))
{
//$this->error = $db->getMessage()."! Please check database hostname, username & password.";
$this->error = $db->getMessage()." - ".$lng->txt("db_error_please_check");
return false;
}
return true;
}
ilClient::connect ( )

connect to client database

Returns
boolean true on success

Definition at line 195 of file class.ilClient.php.

References isMysql4_1OrHigher(), and setDSN().

Referenced by init().

{
// check parameters
if (!$this->getdbHost() || !$this->getdbName() || !$this->getdbUser())
{
$this->error = "empty_fields";
return false;
}
$this->setDSN();
//echo "A";
/* if (is_object($this->db))
{
if (!MDB2::isError($this->db))
{
$this->db->disconnect();
}
else
{
echo "+".$this->db->getMessage()."+";
}
//echo "A";
}
*/
//if (!is_object($this->db))
//{
$this->db = $this->db_connections->connectDB($this->dsn);
//}
if (MDB2::isError($this->db))
{
$this->error = $this->db->getMessage()."! not_connected_to_db";
return false;
}
// NOTE: Three sourcecodes use this or a similar handling:
// - classes/class.ilDBx.php
// - calendar/classes/class.ilCalInterface.php->setNames
// - setup/classes/class.ilClient.php
if ($this->isMysql4_1OrHigher())
{
$this->db->query("SET NAMES utf8");
$this->db->query("SET SESSION SQL_MODE = ''");
}
$this->db_exists = true;
return true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilClient::create ( )

create a new client and its subdirectories

Returns
boolean true on success

Definition at line 691 of file class.ilClient.php.

References getDataDir(), getWebspaceDir(), and ilUtil\makeDir().

{
//var_dump($this->getDataDir());exit;
// create base data dir
if (!ilUtil::makeDir($this->getDataDir()))
{
$this->error = "could_not_create_base_data_dir :".$this->getDataDir();
return false;
}
// create sub dirs in base data dir
if (!ilUtil::makeDir($this->getDataDir()."/mail"))
{
$this->error = "could_not_create_mail_data_dir :".$this->getDataDir()."/mail";
return false;
}
if (!ilUtil::makeDir($this->getDataDir()."/lm_data"))
{
$this->error = "could_not_create_lm_data_dir :".$this->getDataDir()."/lm_data";
return false;
}
if (!ilUtil::makeDir($this->getDataDir()."/forum"))
{
$this->error = "could_not_create_forum_data_dir :".$this->getDataDir()."/forum";
return false;
}
if (!ilUtil::makeDir($this->getDataDir()."/files"))
{
$this->error = "could_not_create_files_data_dir :".$this->getDataDir()."/files";
return false;
}
// create base webspace dir
{
$this->error = "could_not_create_base_webspace_dir :".$this->getWebspaceDir();
return false;
}
// create sub dirs in base webspace dir
if (!ilUtil::makeDir($this->getWebspaceDir()."/lm_data"))
{
$this->error = "could_not_create_lm_webspace_dir :".$this->getWebspaceDir()."/lm_data";
return false;
}
if (!ilUtil::makeDir($this->getWebspaceDir()."/usr_images"))
{
$this->error = "could_not_create_usr_images_webspace_dir :".$this->getWebspaceDir()."/usr_images";
return false;
}
if (!ilUtil::makeDir($this->getWebspaceDir()."/mobs"))
{
$this->error = "could_not_create_mobs_webspace_dir :".$this->getWebspaceDir()."/mobs";
return false;
}
if (!ilUtil::makeDir($this->getWebspaceDir()."/css"))
{
$this->error = "could_not_create_css_webspace_dir :".$this->getWebspaceDir()."/css";
return false;
}
// write client ini
if (!$this->ini->write())
{
$this->error = get_class($this).": ".$this->ini->getError();
return false;
}
return true;
}

+ Here is the call graph for this function:

ilClient::delete (   $a_ini = true,
  $a_db = false,
  $a_files = false 
)

delete client

Parameters
booleanremove ini if true
booleanremove db if true
booleanremove files if true
Returns
array confirmation messages

Definition at line 662 of file class.ilClient.php.

References ilUtil\delDir(), getDbName(), ILIAS_ABSOLUTE_PATH, and ILIAS_WEB_DIR.

{
if ($a_ini === true and file_exists(ILIAS_ABSOLUTE_PATH."/".ILIAS_WEB_DIR."/".$this->getId()."/client.ini.php"))
{
unlink(CLIENT_WEB_DIR."/client.ini.php");
$msg[] = "ini_deleted";
}
if ($a_db === true and $this->db_exists)
{
$this->db->query("DROP DATABASE ".$this->getDbName());
$msg[] = "db_deleted";
}
if ($a_files === true and file_exists(CLIENT_WEB_DIR) and is_dir(CLIENT_WEB_DIR))
{
// rmdir();
ilUtil::delDir(CLIENT_WEB_DIR);
ilUtil::delDir(CLIENT_DATA_DIR);
$msg[] = "files_deleted";
}
return $msg;
}

+ Here is the call graph for this function:

ilClient::getAllSettings ( )

read all values from settings table public

Returns
array keyword/value pairs

Definition at line 459 of file class.ilClient.php.

References DB_FETCHMODE_ASSOC.

Referenced by getURLStringForNIC().

{
$q = "SELECT * FROM settings";
$r = $this->db->query($q);
while ($row = $r->fetchRow(DB_FETCHMODE_ASSOC))
{
$arr[$row["keyword"]] = $row["value"];
}
return $arr;
}

+ Here is the caller graph for this function:

ilClient::getDataDir ( )

get client datadir path

Returns
string client datadir path

Definition at line 360 of file class.ilClient.php.

References getId().

Referenced by create().

{
return ILIAS_DATA_DIR."/".$this->getId();
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilClient::getDbHost ( )

get db host

Returns
string db host

Definition at line 297 of file class.ilClient.php.

{
return $this->ini->readVariable("db","host");
}
ilClient::getDbName ( )

get name of database

Returns
string name of database

Definition at line 315 of file class.ilClient.php.

Referenced by delete().

{
return $this->ini->readVariable("db","name");
}

+ Here is the caller graph for this function:

ilClient::getDbPass ( )

get db password

Returns
string db password

Definition at line 351 of file class.ilClient.php.

{
return $this->ini->readVariable("db","pass");
}
ilClient::getDbUser ( )

get db user

Returns
string db user

Definition at line 333 of file class.ilClient.php.

{
return $this->ini->readVariable("db","user");
}
ilClient::getDefaultLanguage ( )

Definition at line 628 of file class.ilClient.php.

References getSetting().

{
return $this->getSetting("language");
}

+ Here is the call graph for this function:

ilClient::getDescription ( )

get client description

Returns
string client description

Definition at line 149 of file class.ilClient.php.

{
return $this->ini->readVariable("client","description");
}
ilClient::getError ( )

get error message and clear error var

Returns
string error message

Definition at line 646 of file class.ilClient.php.

{
$error = $this->error;
$this->error = "";
return $error;
}
ilClient::getId ( )

get client id

Returns
string client id

Definition at line 112 of file class.ilClient.php.

References $id.

Referenced by getDataDir(), getWebspaceDir(), and ilClient().

{
return $this->id;
}

+ Here is the caller graph for this function:

ilClient::getMySQLVersion ( )

get mysql version

Definition at line 166 of file class.ilClient.php.

{
return mysql_get_server_info();
}
ilClient::getName ( )

get client name

Returns
string client name

Definition at line 131 of file class.ilClient.php.

{
return $this->ini->readVariable("client","name");
}
ilClient::getNICkey ( )

get nic_key public

Returns
string nic_key

Definition at line 616 of file class.ilClient.php.

References getSetting(), and setNICkey().

Referenced by getURLStringForNIC().

{
$this->nic_key = $this->getSetting("nic_key");
if (empty($this->nic_key))
{
$this->setNICkey();
}
return $this->nic_key;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilClient::getSetting (   $a_keyword)

read one value from settings table public

Parameters
stringkeyword
Returns
string value

Definition at line 428 of file class.ilClient.php.

Referenced by getDefaultLanguage(), and getNICkey().

{
$q = "SELECT value FROM settings WHERE keyword='".$a_keyword."'";
$r = $this->db->query($q);
/*if ($r->db->database_name == "ilias3blabla")
{
var_dump($r);
}*/
if ($r->numRows() > 0)
{
$row = $r->fetchRow();
/*if ($r->db->database_name == "ilias3blabla")
{//
var_dump($row);
}*/
return $row[0];
}
else
{
//echo "-nosetting-";
return false;
}
}

+ Here is the caller graph for this function:

ilClient::getURLStringForNIC (   $a_nic_url)
Parameters
stringurl to ilias nic server
Returns
string url with required parameters

Definition at line 511 of file class.ilClient.php.

References getAllSettings(), and getNICkey().

Referenced by updateNIC().

{
$settings = $this->getAllSettings();
$inst_id = (empty($settings["inst_id"])) ? "0" : $settings["inst_id"];
// send host information to ilias-nic
$url = $a_nic_url.
"?cmd=getid".
"&inst_id=".rawurlencode($inst_id).
"&hostname=".rawurlencode($_SERVER["SERVER_NAME"]).
"&ipadr=".rawurlencode($_SERVER["SERVER_ADDR"]).
"&server_port=".rawurlencode($_SERVER["SERVER_PORT"]).
"&server_software=".rawurlencode($_SERVER["SERVER_SOFTWARE"]).
"&inst_name=".rawurlencode($this->ini->readVariable("client","name")).
"&inst_info=".rawurlencode($this->ini->readVariable("client","description")).
"&institution=".rawurlencode($settings["inst_institution"]).
"&http_path=".rawurlencode(ILIAS_HTTP_PATH).
"&contact_firstname=".rawurlencode($settings["admin_firstname"]).
"&contact_lastname=".rawurlencode($settings["admin_lastname"]).
"&contact_title=".rawurlencode($settings["admin_title"]).
"&contact_position=".rawurlencode($settings["admin_position"]).
"&contact_institution=".rawurlencode($settings["admin_institution"]).
"&contact_street=".rawurlencode($settings["admin_street"]).
"&contact_pcode=".rawurlencode($settings["admin_zipcode"]).
"&contact_city=".rawurlencode($settings["admin_city"]).
"&contact_country=".rawurlencode($settings["admin_country"]).
"&contact_phone=".rawurlencode($settings["admin_phone"]).
"&contact_email=".rawurlencode($settings["admin_email"]).
"&nic_key=".rawurlencode($this->getNICkey()).
"&version=".rawurlencode($settings["ilias_version"]);
return $url;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilClient::getWebspaceDir ( )

get client webspacedir path

Returns
string clietn webspacedir path

Definition at line 369 of file class.ilClient.php.

References getId(), ILIAS_ABSOLUTE_PATH, and ILIAS_WEB_DIR.

Referenced by create().

{
return ILIAS_ABSOLUTE_PATH."/".ILIAS_WEB_DIR."/".$this->getId();
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilClient::ilClient (   $a_client_id,
  $a_db_connections 
)

Constructor.

Parameters
stringclient id

Definition at line 49 of file class.ilClient.php.

References getId(), ILIAS_ABSOLUTE_PATH, and ILIAS_WEB_DIR.

{
if ($a_client_id)
{
$this->id = $a_client_id;
$this->ini_file_path = ILIAS_ABSOLUTE_PATH."/".ILIAS_WEB_DIR."/".$this->getId()."/client.ini.php";
}
$this->db_connections = $a_db_connections;
// set path default.ini
$this->client_defaults = ILIAS_ABSOLUTE_PATH."/setup/client.master.ini.php";
}

+ Here is the call graph for this function:

ilClient::init ( )

init client load client.ini and set some constants

Returns
boolean

Definition at line 68 of file class.ilClient.php.

References connect(), ILIAS_ABSOLUTE_PATH, ILIAS_WEB_DIR, and isInstalledDB().

{
$this->ini = new ilIniFile($this->ini_file_path);
// load defaults only if no client.ini was found
if (!@file_exists($this->ini_file_path))
{
$this->ini->GROUPS = parse_ini_file($this->client_defaults,true);
return false;
}
// read client.ini
if (!$this->ini->read())
{
$this->error = get_class($this).": ".$this->ini->getError();
return false;
}
// only for ilias main
define("CLIENT_WEB_DIR",ILIAS_ABSOLUTE_PATH."/".ILIAS_WEB_DIR."/".$this->getId());
define("CLIENT_DATA_DIR",ILIAS_DATA_DIR."/".$this->getId());
define ("DEVMODE",$this->ini->readVariable('system','DEVMODE'));
define ("ROOT_FOLDER_ID",$this->ini->readVariable('system','ROOT_FOLDER_ID'));
define ("SYSTEM_FOLDER_ID",$this->ini->readVariable('system','SYSTEM_FOLDER_ID'));
define ("ROLE_FOLDER_ID",$this->ini->readVariable('system','ROLE_FOLDER_ID'));
define ("ANONYMOUS_USER_ID",13);
define ("ANONYMOUS_ROLE_ID",14);
define ("SYSTEM_USER_ID",6);
define ("SYSTEM_ROLE_ID",2);
$this->db_exists = $this->connect();
if ($this->db_exists)
{
$this->db_installed = $this->isInstalledDB($this->db);
}
return true;
}

+ Here is the call graph for this function:

ilClient::isInstalledDB ( $a_db)

check if client db is installed

Parameters
objectdb object
Returns
boolean true if installed

Definition at line 250 of file class.ilClient.php.

References DB_FETCHMODE_ASSOC.

Referenced by checkDatabaseExists(), and init().

{
$q = "SHOW TABLES";
$r = $a_db->query($q);
$tables = array();
while ($row = $r->fetchRow(DB_FETCHMODE_ASSOC))
{
$tables[] = implode($row);
}
// check existence of some basic tables from ilias3 to determine if ilias3 is already installed in given database
if (in_array("object_data",$tables) and in_array("object_reference",$tables) and in_array("usr_data",$tables) and in_array("rbac_ua",$tables))
{
$this->db_installed = true;
return true;
}
$this->db_installed = false;
return false;
}

+ Here is the caller graph for this function:

ilClient::isMysql4_1OrHigher ( )

check wether current MySQL server is version 4.1.x or higher

NOTE: Three sourcecodes use this or a similar handling:

Definition at line 179 of file class.ilClient.php.

Referenced by connect().

{
$version = explode(".", $this->getMysqlVersion());
if ((int)$version[0] >= 5 ||
((int)$version[0] == 4 && (int)$version[1] >= 1))
{
return true;
}
return false;
}

+ Here is the caller graph for this function:

ilClient::reconnect ( )

Definition at line 417 of file class.ilClient.php.

{
$this->db = $this->db_connections->connectDB($this->dsn);
}
ilClient::setDbHost (   $a_str)

set the host

Parameters
string

Definition at line 287 of file class.ilClient.php.

{
$this->ini->setVariable("db","host",$a_str);
}
ilClient::setDbName (   $a_str)

set the name of database

Parameters
string

Definition at line 306 of file class.ilClient.php.

{
$this->ini->setVariable("db","name",$a_str);
}
ilClient::setDbPass (   $a_str)

set db password

Parameters
string

Definition at line 342 of file class.ilClient.php.

{
$this->ini->setVariable("db","pass",$a_str);
}
ilClient::setDbUser (   $a_str)

set db user

Parameters
stringdb user

Definition at line 324 of file class.ilClient.php.

{
$this->ini->setVariable("db","user",$a_str);
}
ilClient::setDefaultLanguage (   $a_lang_key)

Definition at line 633 of file class.ilClient.php.

References setSetting().

{
$this->setSetting("language",$a_lang_key);
$this->ini->setVariable("language","default",$a_lang_key);
$this->ini->write();
return true;
}

+ Here is the call graph for this function:

ilClient::setDescription (   $a_str)

set client description

Parameters
stringclient description

Definition at line 158 of file class.ilClient.php.

{
$this->ini->setVariable("client","description",$a_str);
}
ilClient::setDSN ( )

set the dsn and dsn_host

Definition at line 276 of file class.ilClient.php.

Referenced by connect().

{
$this->dsn_host = "mysql://".$this->getdbUser().":".$this->getdbPass()."@".$this->getdbHost();
$this->dsn = "mysql://".$this->getdbUser().":".$this->getdbPass()."@".$this->getdbHost()."/".$this->getdbName();
}

+ Here is the caller graph for this function:

ilClient::setId (   $a_client_id)

set client id

Parameters
stringclient id

Definition at line 121 of file class.ilClient.php.

References $id, ILIAS_ABSOLUTE_PATH, and ILIAS_WEB_DIR.

{
$this->id = $a_client_id;
$this->webspace_dir = ILIAS_ABSOLUTE_PATH."/".ILIAS_WEB_DIR."/".$this->id;
}
ilClient::setName (   $a_str)

set client name

Parameters
stringclient name

Definition at line 140 of file class.ilClient.php.

{
$this->ini->setVariable("client","name",$a_str);
}
ilClient::setNICkey ( )

set nic_key generate nic_key if nic_key field in cust table is empty.

the nic_key is used for authentication update requests sent to the ILIAS-NIC server. public

Returns
boolean

Definition at line 598 of file class.ilClient.php.

References setSetting().

Referenced by getNICkey().

{
mt_srand((double)microtime()*1000000);
$nic_key = md5(str_replace(".","",$_SERVER["SERVER_ADDR"]) +
mt_rand(100000,999999));
$this->setSetting("nic_key",$nic_key);
$this->nic_key = $nic_key;
return true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilClient::setSetting (   $a_key,
  $a_val 
)

write one value to settings table public

Parameters
stringkeyword
stringvalue
Returns
boolean true on success

Definition at line 479 of file class.ilClient.php.

References DB_FETCHMODE_ASSOC.

Referenced by setDefaultLanguage(), and setNICkey().

{
//$q = "REPLACE INTO settings SET keyword = '".$a_key."', value = '".$a_val."'";
//$r = $this->db->query($q);
//echo "<br><b>SETTING:$a_key-$a_val-</b>";
$q = "REPLACE INTO settings (keyword,value) VALUES ('".$a_key."', '".$a_val."')";
$r = $this->db->query($q);
$set = $this->db->query("SELECT * FROM settings WHERE keyword = '".$a_key."'");
$rec = $set->fetchRow(DB_FETCHMODE_ASSOC);
if ($a_key == "setup_ok")
{
// nj();
}
/*if ($set->db->database_name == "ilias3blabla")
{
var_dump($set);
var_dump($rec);
}*/
return true;
}

+ Here is the caller graph for this function:

ilClient::updateNIC (   $a_nic_url)

Connect to ILIAS-NIC.

This function establishes a HTTP connection to the ILIAS Network Information Center (NIC) in order to update the ILIAS-NIC host database and - in case of a newly installed system - obtain an installation id at first connection. This function my be put into a dedicated include file as soon as there are more functions concerning the interconnection of ILIAS hosts

Parameters
void
Returns
string/array $ret error message or data array

Definition at line 560 of file class.ilClient.php.

References $ret, and getURLStringForNIC().

{
$url = $this->getURLStringForNIC($a_nic_url);
$conn =fopen($url,"r");
$input = "";
if (!$conn)
{
return false;
}
else
{
while(!feof($conn))
{
$input.= fgets($conn, 4096);
}
fclose($conn);
$line = explode("\n",$input);
$ret = $line;
}
$this->nic_status = $ret;
return true;
}

+ Here is the call graph for this function:

Field Documentation

ilClient::$client_defaults

Definition at line 40 of file class.ilClient.php.

ilClient::$db_exists = false

Definition at line 37 of file class.ilClient.php.

ilClient::$db_installed = false

Definition at line 38 of file class.ilClient.php.

ilClient::$dir

Definition at line 35 of file class.ilClient.php.

ilClient::$id

Definition at line 34 of file class.ilClient.php.

Referenced by getId(), and setId().

ilClient::$name

Definition at line 36 of file class.ilClient.php.

ilClient::$nic_status

Definition at line 43 of file class.ilClient.php.

ilClient::$setup_ok = false

Definition at line 42 of file class.ilClient.php.

ilClient::$status

Definition at line 41 of file class.ilClient.php.


The documentation for this class was generated from the following file: