ILIAS  Release_4_2_x_branch Revision 61807
 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
 getDB ()
 get mysql version
 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
 getDbPort ()
 get db port
 setDbPort ($a_str)
 set db port
 setDbPass ($a_str)
 set db password
 getDbPass ()
 get db password
 setDbType ($a_str)
 set the type of database
 getDbType ()
 get type of database
 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
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Version
Id:
class.ilClient.php 30830 2011-09-27 09:33:38Z akill

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

Member Function Documentation

ilClient::checkDatabaseExists ( )

check database connection with database name

Returns
boolean

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

References MDB2\isError(), and 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 407 of file class.ilClient.php.

References $lng, getDbType(), and MDB2\isError().

{
global $lng;
if ($this->getDbType() == "oracle")
{
return true;
}
//connect to databasehost
$db = $this->db_connections->connectHost($this->dsn_host);
//var_dump($db); exit;
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;
}

+ Here is the call graph for this function:

ilClient::connect ( )

connect to client database

Returns
boolean true on success

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

References $GLOBALS, and ilDBWrapperFactory\getWrapper().

Referenced by init(), and reconnect().

{
// check parameters
// To support oracle tnsnames.ora dbname is not required
if (!$this->getdbHost() || !$this->getdbUser())
{
$this->error = "empty_fields";
return false;
}
/*
if (!$this->getdbHost() || !$this->getdbName() || !$this->getdbUser())
{
$this->error = "empty_fields";
return false;
}
*/
include_once("./Services/Database/classes/class.ilDBWrapperFactory.php");
$this->db = ilDBWrapperFactory::getWrapper($this->getdbType());
$this->db->setDBUser($this->getdbUser());
$this->db->setDBPort($this->getdbPort());
$this->db->setDBPassword($this->getdbPass());
$this->db->setDBHost($this->getdbHost());
$this->db->setDBName($this->getdbName());
//if ($this->getdbType() != "oracle")
//{
$con = $this->db->connect(true);
//}
if (!$con)
{
$this->error = "Database connection failed.";
return false;
}
$GLOBALS["ilDB"] = $this->db;
$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 678 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 649 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 473 of file class.ilClient.php.

Referenced by getURLStringForNIC().

{
include_once './Services/Administration/classes/class.ilSetting.php';
$set = new ilSetting("common", true);
return $set->getAll();
}

+ Here is the caller graph for this function:

ilClient::getDataDir ( )

get client datadir path

Returns
string client datadir path

Definition at line 389 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::getDB ( )

get mysql version

Get DB object

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

{
return $this->db;
}
ilClient::getDbHost ( )

get db host

Returns
string db host

Definition at line 282 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 300 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 354 of file class.ilClient.php.

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

get db port

Returns
string db port

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

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

get type of database

Returns
string name of database

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

Referenced by checkDatabaseHost(), and setDSN().

{
$val = $this->ini->readVariable("db","type");
if ($val == "")
{
return "mysql";
}
else
{
return $val;
}
}

+ Here is the caller graph for this function:

ilClient::getDbUser ( )

get db user

Returns
string db user

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

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

Definition at line 615 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 129 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 633 of file class.ilClient.php.

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

get client id

Returns
string client id

Definition at line 92 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::getName ( )

get client name

Returns
string client name

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

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

get nic_key public

Returns
string nic_key

Definition at line 603 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 461 of file class.ilClient.php.

Referenced by getDefaultLanguage(), and getNICkey().

{
include_once './Services/Administration/classes/class.ilSetting.php';
$set = new ilSetting("common", true);
return $set->get($a_keyword);
}

+ 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 498 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 398 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 29 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 48 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))
{
//echo "<br>A-".$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 207 of file class.ilClient.php.

Referenced by checkDatabaseExists(), and init().

{
if(method_exists($a_db,'loadModule'))
{
$a_db->loadModule('Manager');
}
if(!$tables = $a_db->listTables())
{
return false;
}
// 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::reconnect ( )

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

References connect().

{
$this->connect();
}

+ Here is the call graph for this function:

ilClient::setDbHost (   $a_str)

set the host

Parameters
string

Definition at line 272 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 291 of file class.ilClient.php.

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

set db password

Parameters
string

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

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

set db port

Parameters
string

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

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

set the type of database

Parameters
string

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

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

set db user

Parameters
stringdb user

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

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

Definition at line 620 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 138 of file class.ilClient.php.

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

set the dsn and dsn_host

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

References getDbType().

{
switch($this->getDbType())
{
case "oracle":
//$this->dsn_host = "oci8://".$this->getdbUser().":".$this->getdbPass()."@".$this->getdbHost();
$this->dsn_host = array(
'phptype' => 'oci8',
'hostspec' => $this->getdbHost(),
'username' => $this->getdbUser(),
'port' => $this->getdbPort(),
'password' => $this->getdbPass(),
);
//$this->dsn = "oci8://".$this->getdbUser().":".$this->getdbPass()."@".$this->getdbHost()."/?service=".$this->getdbName();
$this->dsn = $this->dsn = array(
'phptype' => 'oci8',
'hostspec' => $this->getdbHost(),
'username' => $this->getdbUser(),
'port' => $this->getdbPort(),
'password' => $this->getdbPass(),
'service' => $this->getdbName()
);
break;
case "mysql":
default:
$db_port_str = "";
if (trim($this->getdbPort()) != "")
{
$db_port_str = ":".$this->getdbPort();
}
$this->dsn_host = "mysql://".$this->getdbUser().":".$this->getdbPass()."@".$this->getdbHost().$db_port_str;
$this->dsn = "mysql://".$this->getdbUser().":".$this->getdbPass()."@".$this->getdbHost().$db_port_str."/".$this->getdbName();
break;
}
}

+ Here is the call graph for this function:

ilClient::setId (   $a_client_id)

set client id

Parameters
stringclient id

Definition at line 101 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 120 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 585 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 487 of file class.ilClient.php.

Referenced by setDefaultLanguage(), and setNICkey().

{
include_once './Services/Administration/classes/class.ilSetting.php';
$set = new ilSetting("common", true);
$set->set($a_key, $a_val);
}

+ 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 547 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 20 of file class.ilClient.php.

ilClient::$db_exists = false

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

ilClient::$db_installed = false

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

ilClient::$dir

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

ilClient::$id

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

Referenced by getId(), and setId().

ilClient::$name

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

ilClient::$nic_status

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

ilClient::$setup_ok = false

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

ilClient::$status

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


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