48 $this->
id = $a_client_id;
49 $this->ini_file_path = ILIAS_ABSOLUTE_PATH.
"/".ILIAS_WEB_DIR.
"/".$this->
getId().
"/client.ini.php";
52 $this->db_connections = $a_db_connections;
55 $this->client_defaults = ILIAS_ABSOLUTE_PATH.
"/setup/client.master.ini.php";
63 require_once(
'./setup/classes/class.ilDbSetup.php');
75 $this->ini =
new ilIniFile($this->ini_file_path);
78 if (!@file_exists($this->ini_file_path)) {
80 $this->ini->GROUPS = parse_ini_file($this->client_defaults,
true);
86 if (!$this->ini->read()) {
87 $this->error = get_class($this) .
": " . $this->ini->getError();
93 define(
"CLIENT_WEB_DIR", ILIAS_ABSOLUTE_PATH .
"/" . ILIAS_WEB_DIR .
"/" . $this->
getId());
94 define(
"CLIENT_DATA_DIR", ILIAS_DATA_DIR .
"/" . $this->
getId());
95 define(
"DEVMODE", $this->ini->readVariable(
'system',
'DEVMODE'));
96 define(
"ROOT_FOLDER_ID", $this->ini->readVariable(
'system',
'ROOT_FOLDER_ID'));
97 define(
"SYSTEM_FOLDER_ID", $this->ini->readVariable(
'system',
'SYSTEM_FOLDER_ID'));
98 define(
"ROLE_FOLDER_ID", $this->ini->readVariable(
'system',
'ROLE_FOLDER_ID'));
99 define(
"ANONYMOUS_USER_ID", 13);
100 define(
"ANONYMOUS_ROLE_ID", 14);
101 define(
"SYSTEM_USER_ID", 6);
102 define(
"SYSTEM_ROLE_ID", 2);
104 $this->db_exists = $this->
getDBSetup()->isConnectable();
106 if ($this->db_exists) {
107 $this->db_installed = $this->
getDBSetup()->isDatabaseInstalled();
138 $this->
id = $a_client_id;
139 $this->webspace_dir = ILIAS_ABSOLUTE_PATH.
"/".ILIAS_WEB_DIR.
"/".
$this->id;
148 return $this->ini->readVariable(
"client",
"name");
157 $this->ini->setVariable(
"client",
"name",$a_str);
166 return $this->ini->readVariable(
"client",
"description");
175 $this->ini->setVariable(
"client",
"description",$a_str);
202 if (!$this->getdbHost() || !$this->getdbUser()) {
203 $this->error =
"empty_fields";
208 include_once(
"./Services/Database/classes/class.ilDBWrapperFactory.php");
209 $this->db = ilDBWrapperFactory::getWrapper($this->getdbType(),
210 $this->ini->readVariable(
"db",
"inactive_mysqli"));
211 $this->db->setDBUser($this->getdbUser());
212 $this->db->setDBPort($this->getdbPort());
213 $this->db->setDBPassword($this->getdbPass());
214 $this->db->setDBHost($this->getdbHost());
215 $this->db->setDBName($this->getdbName());
216 $con = $this->db->connect(
true);
220 $this->error =
"Database connection failed.";
224 $GLOBALS[
"DIC"][
"ilDB"] =
function($c) {
228 $this->db_exists =
true;
239 if(method_exists($a_db,
'loadModule'))
241 $a_db->loadModule(
'Manager');
243 if(!$tables = $a_db->listTables())
249 if (in_array(
"object_data",$tables)
and in_array(
"object_reference",$tables)
and in_array(
"usr_data",$tables)
and in_array(
"rbac_ua",$tables))
251 $this->db_installed =
true;
254 $this->db_installed =
false;
267 $this->dsn_host =
array(
269 'hostspec' => $this->getdbHost(),
270 'username' => $this->getdbUser(),
271 'port' => $this->getdbPort(),
272 'password' => $this->getdbPass(),
275 $this->dsn = $this->dsn =
array(
277 'hostspec' => $this->getdbHost(),
278 'username' => $this->getdbUser(),
279 'port' => $this->getdbPort(),
280 'password' => $this->getdbPass(),
281 'service' => $this->getdbName()
287 if (trim($this->getdbPort()) !=
"")
289 $db_port_str =
":".$this->getdbPort();
291 $this->dsn_host =
"pgsql://".$this->getdbUser().
":".$this->getdbPass().
"@".$this->getdbHost().$db_port_str;
292 $this->dsn =
"pgsql://".$this->getdbUser().
":".$this->getdbPass().
"@".$this->getdbHost().$db_port_str.
"/".$this->getdbName();
299 if (trim($this->getdbPort()) !=
"")
301 $db_port_str =
":".$this->getdbPort();
303 $this->dsn_host =
"mysql://".$this->getdbUser().
":".$this->getdbPass().
"@".$this->getdbHost().$db_port_str;
304 $this->dsn =
"mysql://".$this->getdbUser().
":".$this->getdbPass().
"@".$this->getdbHost().$db_port_str.
"/".$this->getdbName();
315 $this->ini->setVariable(
"db",
"host",$a_str);
325 return $this->ini->readVariable(
"db",
"host");
334 $this->ini->setVariable(
"db",
"name",$a_str);
343 return $this->ini->readVariable(
"db",
"name");
352 $this->ini->setVariable(
"db",
"user",$a_str);
361 return $this->ini->readVariable(
"db",
"user");
370 return $this->ini->readVariable(
"db",
"port");
379 $this->ini->setVariable(
"db",
"port",$a_str);
388 $this->ini->setVariable(
"db",
"pass",$a_str);
397 return $this->ini->readVariable(
"db",
"pass");
406 $this->ini->setVariable(
"db",
"slave_active", (
int) $a_act);
416 return (
int) $this->ini->readVariable(
"db",
"slave_active");
425 $this->ini->setVariable(
"db",
"slave_host",$a_str);
435 return $this->ini->readVariable(
"db",
"slave_host");
444 $this->ini->setVariable(
"db",
"slave_name",$a_str);
453 return $this->ini->readVariable(
"db",
"slave_name");
462 $this->ini->setVariable(
"db",
"slave_user",$a_str);
471 return $this->ini->readVariable(
"db",
"slave_user");
480 return $this->ini->readVariable(
"db",
"slave_port");
489 $this->ini->setVariable(
"db",
"slave_port",$a_str);
498 $this->ini->setVariable(
"db",
"slave_pass",$a_str);
507 return $this->ini->readVariable(
"db",
"slave_pass");
516 $this->ini->setVariable(
"db",
"type",$a_str);
525 $val = $this->ini->readVariable(
"db",
"type");
542 return ILIAS_DATA_DIR.
"/".$this->
getId();
551 return ILIAS_ABSOLUTE_PATH.
"/".ILIAS_WEB_DIR.
"/".$this->
getId();
564 $db = $this->db_connections->connectDB($this->dsn);
576 if($a_keep_connection)
579 $GLOBALS[
"DIC"][
"ilDB"] =
function($c) {
602 if (!$this->
getDBSetup()->isDatabaseInstalled() || !$ilDB) {
605 include_once
'./Services/Administration/classes/class.ilSetting.php';
608 return $set->get($a_keyword);
618 include_once
'./Services/Administration/classes/class.ilSetting.php';
620 return $set->getAll();
632 include_once
'./Services/Administration/classes/class.ilSetting.php';
634 $set->set($a_key, $a_val);
645 $inst_id = (empty($settings[
"inst_id"])) ?
"0" : $settings[
"inst_id"];
652 "&inst_id=".rawurlencode($inst_id).
653 "&hostname=".rawurlencode(
$_SERVER[
"SERVER_NAME"]).
654 "&inst_name=".rawurlencode($this->ini->readVariable(
"client",
"name")).
655 "&inst_info=".rawurlencode($this->ini->readVariable(
"client",
"description")).
656 "&http_path=".rawurlencode(ILIAS_HTTP_PATH).
657 "&contact_firstname=".rawurlencode($settings[
"admin_firstname"]).
658 "&contact_lastname=".rawurlencode($settings[
"admin_lastname"]).
659 "&contact_email=".rawurlencode($settings[
"admin_email"]).
660 "&nic_key=".rawurlencode($this->
getNICkey());
684 require_once(__DIR__.
"/../../Services/WebServices/Curl/classes/class.ilCurlConnection.php");
686 $this->
setError(
"CURL-extension not loaded.");
695 if((
bool)$settings[
'proxy_status'] && strlen($settings[
'proxy_host']) && strlen($settings[
'proxy_port']))
697 $req->setOpt(CURLOPT_HTTPPROXYTUNNEL,
true);
698 $req->setOpt(CURLOPT_PROXY, $settings[
"proxy_host"]);
699 $req->setOpt(CURLOPT_PROXYPORT, $settings[
"proxy_port"]);
702 $req->setOpt(CURLOPT_HEADER, 1);
703 $req->setOpt(CURLOPT_RETURNTRANSFER, 1);
704 $req->setOpt(CURLOPT_CONNECTTIMEOUT, $socket_timeout);
705 $req->setOpt(CURLOPT_MAXREDIRS, $max_redirects);
706 $response = $req->exec();
708 $req->parseResponse($response);
709 $response_body = $req->getResponseBody();
711 $info = $req->getInfo();
712 if (
$info[
"http_code"] !=
"200") {
713 $this->
setError(
"Could not connect to NIC-Server at '".
$url.
"'");
717 $this->nic_status = explode(
"\n", $response_body);
734 mt_srand((
double)microtime()*1000000);
735 $nic_key = md5(str_replace(
".",
"",
$_SERVER[
"SERVER_ADDR"]) +
736 mt_rand(100000,999999));
740 $this->nic_key = $nic_key;
752 $this->nic_key = $this->
getSetting(
"nic_key");
754 if (empty($this->nic_key))
759 return $this->nic_key;
770 $this->ini->setVariable(
"language",
"default",$a_lang_key);
794 $this->error = $error_message;
805 function delete ($a_ini =
true, $a_db =
false, $a_files =
false)
807 if ($a_ini ===
true and file_exists(ILIAS_ABSOLUTE_PATH.
"/".ILIAS_WEB_DIR.
"/".$this->getId().
"/client.ini.php"))
809 unlink(CLIENT_WEB_DIR.
"/client.ini.php");
810 $msg[] =
"ini_deleted";
813 if ($a_db ===
true and $this->db_exists)
815 $this->db->query(
"DROP DATABASE ".$this->
getDbName());
816 $msg[] =
"db_deleted";
819 if ($a_files ===
true and file_exists(CLIENT_WEB_DIR)
and is_dir(CLIENT_WEB_DIR))
824 $msg[] =
"files_deleted";
840 $this->error =
"could_not_create_base_data_dir :".$this->getDataDir();
847 $this->error =
"could_not_create_mail_data_dir :".$this->getDataDir().
"/mail";
853 $this->error =
"could_not_create_lm_data_dir :".$this->getDataDir().
"/lm_data";
859 $this->error =
"could_not_create_forum_data_dir :".$this->getDataDir().
"/forum";
865 $this->error =
"could_not_create_files_data_dir :".$this->getDataDir().
"/files";
872 $this->error =
"could_not_create_base_webspace_dir :".$this->getWebspaceDir();
879 $this->error =
"could_not_create_lm_webspace_dir :".$this->getWebspaceDir().
"/lm_data";
885 $this->error =
"could_not_create_usr_images_webspace_dir :".$this->getWebspaceDir().
"/usr_images";
891 $this->error =
"could_not_create_mobs_webspace_dir :".$this->getWebspaceDir().
"/mobs";
897 $this->error =
"could_not_create_css_webspace_dir :".$this->getWebspaceDir().
"/css";
902 if (!$this->ini->write())
904 $this->error = get_class($this).
": ".$this->ini->getError();
setDSN()
set the dsn and dsn_host
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
isError($data, $code=null)
Tell whether a value is a MDB2 error.
static getInstanceForClient(\ilClient $client)
getDbSlaveName()
get name of slave database
setDescription($a_str)
set client description
isInstalledDB(&$a_db)
check if client db is installed
setDbHost($a_str)
set the host
setSetting($a_key, $a_val)
write one value to settings table public
getDbPass()
get db password
setName($a_str)
set client name
getDbName()
get name of database
__construct($a_client_id, $a_db_connections)
ilClient constructor.
setDbType($a_str)
set the type of database
getDbSlaveHost()
get db slave host
connect()
connect to client database
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
getError()
get error message and clear error var
setDefaultLanguage($a_lang_key)
setId($a_client_id)
set client id
getNICkey()
get nic_key public
setDbUser($a_str)
set db user
getDescription()
get client description
setDbName($a_str)
set the name of database
setDbPass($a_str)
set db password
setNICkey()
set nic_key generate nic_key if nic_key field in cust table is empty.
checkDatabaseExists($a_keep_connection=false)
check database connection with database name
getURLStringForNIC($a_nic_url)
getDbSlavePort()
get slave db port
init()
init client load client.ini and set some constants
setDbSlavePass($a_str)
set slave db password
setDbSlaveUser($a_str)
set slave db user
setDbSlaveName($a_str)
set the name of slave database
static _isCurlExtensionLoaded()
Check if curl extension is loaded.
setDbSlaveActive($a_act)
set the slave active
getDbSlaveActive()
get slave active
getDbSlaveUser()
get slave db user
Create styles array
The data for the language used.
getAllSettings()
read all values from settings table public
getDbType()
get type of database
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
setDbSlaveHost($a_str)
set the slave host
getDataDir()
get client datadir path
getWebspaceDir()
get client webspacedir path
setDbPort($a_str)
set db port
getSetting($a_keyword)
read one value from settings table
static getLogger($a_component_id)
Get component logger.
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
create()
create a new client and its subdirectories
getDbSlavePass()
get slave db password
updateNIC($a_nic_url)
Connect to ILIAS-NIC.
setDbSlavePort($a_str)
set slave db port