47 $this->
id = $a_client_id;
48 $this->ini_file_path = ILIAS_ABSOLUTE_PATH .
"/" . ILIAS_WEB_DIR .
"/" . $this->
getId() .
"/client.ini.php";
51 $this->db_connections = $a_db_connections;
54 $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();
140 $this->
id = $a_client_id;
141 $this->webspace_dir = ILIAS_ABSOLUTE_PATH .
"/" . ILIAS_WEB_DIR .
"/" .
$this->id;
150 return $this->ini->readVariable(
"client",
"name");
159 $this->ini->setVariable(
"client",
"name", $a_str);
168 return $this->ini->readVariable(
"client",
"description");
177 $this->ini->setVariable(
"client",
"description", $a_str);
204 if (!$this->getdbHost() || !$this->getdbUser()) {
205 $this->error =
"empty_fields";
210 include_once(
"./Services/Database/classes/class.ilDBWrapperFactory.php");
211 $this->db = ilDBWrapperFactory::getWrapper(
213 $this->ini->readVariable(
"db",
"inactive_mysqli")
215 $this->db->setDBUser($this->getdbUser());
216 $this->db->setDBPort($this->getdbPort());
217 $this->db->setDBPassword($this->getdbPass());
218 $this->db->setDBHost($this->getdbHost());
219 $this->db->setDBName($this->getdbName());
220 $con = $this->db->connect(
true);
223 $this->error =
"Database connection failed.";
228 if (
$GLOBALS[
"DIC"]->offsetExists(
"ilDB")) {
229 $GLOBALS[
"DIC"]->offsetUnset(
"ilDB");
232 $GLOBALS[
"DIC"][
"ilDB"] =
function ($c) {
236 $this->db_exists =
true;
247 if (method_exists($a_db,
'loadModule')) {
248 $a_db->loadModule(
'Manager');
250 if (!$tables = $a_db->listTables()) {
255 if (in_array(
"object_data", $tables) and in_array(
"object_reference", $tables) and in_array(
"usr_data", $tables) and in_array(
"rbac_ua", $tables)) {
256 $this->db_installed =
true;
259 $this->db_installed =
false;
271 $this->dsn_host =
array(
273 'hostspec' => $this->getdbHost(),
274 'username' => $this->getdbUser(),
275 'port' => $this->getdbPort(),
276 'password' => $this->getdbPass(),
279 $this->dsn = $this->dsn =
array(
281 'hostspec' => $this->getdbHost(),
282 'username' => $this->getdbUser(),
283 'port' => $this->getdbPort(),
284 'password' => $this->getdbPass(),
285 'service' => $this->getdbName()
291 if (trim($this->getdbPort()) !=
"") {
292 $db_port_str =
":" . $this->getdbPort();
294 $this->dsn_host =
"pgsql://" . $this->getdbUser() .
":" . $this->getdbPass() .
"@" . $this->getdbHost() . $db_port_str;
295 $this->dsn =
"pgsql://" . $this->getdbUser() .
":" . $this->getdbPass() .
"@" . $this->getdbHost() . $db_port_str .
"/" . $this->getdbName();
302 if (trim($this->getdbPort()) !=
"") {
303 $db_port_str =
":" . $this->getdbPort();
305 $this->dsn_host =
"mysql://" . $this->getdbUser() .
":" . $this->getdbPass() .
"@" . $this->getdbHost() . $db_port_str;
306 $this->dsn =
"mysql://" . $this->getdbUser() .
":" . $this->getdbPass() .
"@" . $this->getdbHost() . $db_port_str .
"/" . $this->getdbName();
317 $this->ini->setVariable(
"db",
"host", $a_str);
327 return $this->ini->readVariable(
"db",
"host");
336 $this->ini->setVariable(
"db",
"name", $a_str);
345 return $this->ini->readVariable(
"db",
"name");
354 $this->ini->setVariable(
"db",
"user", $a_str);
363 return $this->ini->readVariable(
"db",
"user");
372 return $this->ini->readVariable(
"db",
"port");
381 $this->ini->setVariable(
"db",
"port", $a_str);
390 $this->ini->setVariable(
"db",
"pass", $a_str);
399 return $this->ini->readVariable(
"db",
"pass");
408 $this->ini->setVariable(
"db",
"slave_active", (
int) $a_act);
418 return (
int) $this->ini->readVariable(
"db",
"slave_active");
427 $this->ini->setVariable(
"db",
"slave_host", $a_str);
437 return $this->ini->readVariable(
"db",
"slave_host");
446 $this->ini->setVariable(
"db",
"slave_name", $a_str);
455 return $this->ini->readVariable(
"db",
"slave_name");
464 $this->ini->setVariable(
"db",
"slave_user", $a_str);
473 return $this->ini->readVariable(
"db",
"slave_user");
482 return $this->ini->readVariable(
"db",
"slave_port");
491 $this->ini->setVariable(
"db",
"slave_port", $a_str);
500 $this->ini->setVariable(
"db",
"slave_pass", $a_str);
509 return $this->ini->readVariable(
"db",
"slave_pass");
518 $this->ini->setVariable(
"db",
"type", $a_str);
527 $val = $this->ini->readVariable(
"db",
"type");
541 return ILIAS_DATA_DIR .
"/" . $this->
getId();
550 return ILIAS_ABSOLUTE_PATH .
"/" . ILIAS_WEB_DIR .
"/" . $this->
getId();
563 $db = $this->db_connections->connectDB($this->dsn);
573 if ($a_keep_connection) {
575 $GLOBALS[
"DIC"][
"ilDB"] =
function ($c) {
599 if (!$this->
getDBSetup()->isDatabaseInstalled() || !$ilDB) {
602 include_once
'./Services/Administration/classes/class.ilSetting.php';
605 return $set->get($a_keyword);
615 include_once
'./Services/Administration/classes/class.ilSetting.php';
617 return $set->getAll();
629 include_once
'./Services/Administration/classes/class.ilSetting.php';
631 $set->set($a_key, $a_val);
642 $inst_id = (empty($settings[
"inst_id"])) ?
"0" : $settings[
"inst_id"];
649 "&inst_id=" . rawurlencode($inst_id) .
650 "&hostname=" . rawurlencode(
$_SERVER[
"SERVER_NAME"]) .
651 "&inst_name=" . rawurlencode($this->ini->readVariable(
"client",
"name")) .
652 "&inst_info=" . rawurlencode($this->ini->readVariable(
"client",
"description")) .
653 "&http_path=" . rawurlencode(ILIAS_HTTP_PATH) .
654 "&contact_firstname=" . rawurlencode($settings[
"admin_firstname"]) .
655 "&contact_lastname=" . rawurlencode($settings[
"admin_lastname"]) .
656 "&contact_email=" . rawurlencode($settings[
"admin_email"]) .
657 "&nic_key=" . rawurlencode($this->
getNICkey());
681 require_once(__DIR__ .
"/../../Services/WebServices/Curl/classes/class.ilCurlConnection.php");
683 $this->
setError(
"CURL-extension not loaded.");
692 if ((
bool) $settings[
'proxy_status'] && strlen($settings[
'proxy_host']) && strlen($settings[
'proxy_port'])) {
693 $req->setOpt(CURLOPT_HTTPPROXYTUNNEL,
true);
694 $req->setOpt(CURLOPT_PROXY, $settings[
"proxy_host"]);
695 $req->setOpt(CURLOPT_PROXYPORT, $settings[
"proxy_port"]);
698 $req->setOpt(CURLOPT_HEADER, 1);
699 $req->setOpt(CURLOPT_RETURNTRANSFER, 1);
700 $req->setOpt(CURLOPT_CONNECTTIMEOUT, $socket_timeout);
701 $req->setOpt(CURLOPT_MAXREDIRS, $max_redirects);
705 $response_body =
$req->getResponseBody();
708 if (
$info[
"http_code"] !=
"200") {
709 $this->
setError(
"Could not connect to NIC-Server at '" .
$url .
"'");
713 $this->nic_status = explode(
"\n", $response_body);
730 mt_srand((
double) microtime()*1000000);
731 $nic_key = md5(str_replace(
".",
"",
$_SERVER[
"SERVER_ADDR"]) +
732 mt_rand(100000, 999999));
736 $this->nic_key = $nic_key;
748 $this->nic_key = $this->
getSetting(
"nic_key");
750 if (empty($this->nic_key)) {
754 return $this->nic_key;
765 $this->ini->setVariable(
"language",
"default", $a_lang_key);
791 $this->error = $error_message;
802 public function delete($a_ini =
true, $a_db =
false, $a_files =
false)
804 if ($a_ini ===
true and file_exists(ILIAS_ABSOLUTE_PATH .
"/" . ILIAS_WEB_DIR .
"/" . $this->
getId() .
"/client.ini.php")) {
805 unlink(CLIENT_WEB_DIR .
"/client.ini.php");
806 $msg[] =
"ini_deleted";
809 if ($a_db ===
true and $this->db_exists) {
810 $this->db->query(
"DROP DATABASE " . $this->
getDbName());
811 $msg[] =
"db_deleted";
814 if ($a_files ===
true and file_exists(CLIENT_WEB_DIR) and is_dir(CLIENT_WEB_DIR)) {
818 $msg[] =
"files_deleted";
833 $this->error =
"could_not_create_base_data_dir :" . $this->
getDataDir();
839 $this->error =
"could_not_create_mail_data_dir :" . $this->
getDataDir() .
"/mail";
844 $this->error =
"could_not_create_lm_data_dir :" . $this->
getDataDir() .
"/lm_data";
849 $this->error =
"could_not_create_forum_data_dir :" . $this->
getDataDir() .
"/forum";
854 $this->error =
"could_not_create_files_data_dir :" . $this->
getDataDir() .
"/files";
860 $this->error =
"could_not_create_base_webspace_dir :" . $this->
getWebspaceDir();
866 $this->error =
"could_not_create_lm_webspace_dir :" . $this->
getWebspaceDir() .
"/lm_data";
871 $this->error =
"could_not_create_usr_images_webspace_dir :" . $this->
getWebspaceDir() .
"/usr_images";
876 $this->error =
"could_not_create_mobs_webspace_dir :" . $this->
getWebspaceDir() .
"/mobs";
881 $this->error =
"could_not_create_css_webspace_dir :" . $this->
getWebspaceDir() .
"/css";
886 if (!$this->ini->write()) {
887 $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