39 function ilClient($a_client_id, $a_db_connections)
43 $this->
id = $a_client_id;
47 $this->db_connections = $a_db_connections;
60 $this->ini =
new ilIniFile($this->ini_file_path);
63 if (!@file_exists($this->ini_file_path))
66 $this->ini->GROUPS = parse_ini_file($this->client_defaults,
true);
71 if (!$this->ini->read())
73 $this->error = get_class($this).
": ".$this->ini->getError();
79 define(
"CLIENT_DATA_DIR",ILIAS_DATA_DIR.
"/".$this->getId());
80 define (
"DEVMODE",$this->ini->readVariable(
'system',
'DEVMODE'));
81 define (
"ROOT_FOLDER_ID",$this->ini->readVariable(
'system',
'ROOT_FOLDER_ID'));
82 define (
"SYSTEM_FOLDER_ID",$this->ini->readVariable(
'system',
'SYSTEM_FOLDER_ID'));
83 define (
"ROLE_FOLDER_ID",$this->ini->readVariable(
'system',
'ROLE_FOLDER_ID'));
84 define (
"ANONYMOUS_USER_ID",13);
85 define (
"ANONYMOUS_ROLE_ID",14);
86 define (
"SYSTEM_USER_ID",6);
87 define (
"SYSTEM_ROLE_ID",2);
89 $this->db_exists = $this->
connect();
113 $this->
id = $a_client_id;
123 return $this->ini->readVariable(
"client",
"name");
132 $this->ini->setVariable(
"client",
"name",$a_str);
141 return $this->ini->readVariable(
"client",
"description");
150 $this->ini->setVariable(
"client",
"description",$a_str);
177 if (!$this->getdbHost() || !$this->getdbUser())
179 $this->error =
"empty_fields";
190 include_once(
"./Services/Database/classes/class.ilDBWrapperFactory.php");
192 $this->ini->readVariable(
"db",
"inactive_mysqli"));
193 $this->db->setDBUser($this->getdbUser());
194 $this->db->setDBPort($this->getdbPort());
195 $this->db->setDBPassword($this->getdbPass());
196 $this->db->setDBHost($this->getdbHost());
197 $this->db->setDBName($this->getdbName());
198 $con = $this->db->connect(
true);
202 $this->error =
"Database connection failed.";
207 $this->db_exists =
true;
218 if(method_exists($a_db,
'loadModule'))
220 $a_db->loadModule(
'Manager');
222 if(!$tables = $a_db->listTables())
228 if (in_array(
"object_data",$tables) and in_array(
"object_reference",$tables) and in_array(
"usr_data",$tables) and in_array(
"rbac_ua",$tables))
230 $this->db_installed =
true;
233 $this->db_installed =
false;
246 $this->dsn_host = array(
248 'hostspec' => $this->getdbHost(),
249 'username' => $this->getdbUser(),
250 'port' => $this->getdbPort(),
251 'password' => $this->getdbPass(),
254 $this->dsn = $this->dsn = array(
256 'hostspec' => $this->getdbHost(),
257 'username' => $this->getdbUser(),
258 'port' => $this->getdbPort(),
259 'password' => $this->getdbPass(),
260 'service' => $this->getdbName()
266 if (trim($this->getdbPort()) !=
"")
268 $db_port_str =
":".$this->getdbPort();
270 $this->dsn_host =
"pgsql://".$this->getdbUser().
":".$this->getdbPass().
"@".$this->getdbHost().$db_port_str;
271 $this->dsn =
"pgsql://".$this->getdbUser().
":".$this->getdbPass().
"@".$this->getdbHost().$db_port_str.
"/".$this->getdbName();
278 if (trim($this->getdbPort()) !=
"")
280 $db_port_str =
":".$this->getdbPort();
282 $this->dsn_host =
"mysql://".$this->getdbUser().
":".$this->getdbPass().
"@".$this->getdbHost().$db_port_str;
283 $this->dsn =
"mysql://".$this->getdbUser().
":".$this->getdbPass().
"@".$this->getdbHost().$db_port_str.
"/".$this->getdbName();
294 $this->ini->setVariable(
"db",
"host",$a_str);
304 return $this->ini->readVariable(
"db",
"host");
313 $this->ini->setVariable(
"db",
"name",$a_str);
322 return $this->ini->readVariable(
"db",
"name");
331 $this->ini->setVariable(
"db",
"user",$a_str);
340 return $this->ini->readVariable(
"db",
"user");
349 return $this->ini->readVariable(
"db",
"port");
358 $this->ini->setVariable(
"db",
"port",$a_str);
367 $this->ini->setVariable(
"db",
"pass",$a_str);
376 return $this->ini->readVariable(
"db",
"pass");
385 $this->ini->setVariable(
"db",
"slave_active", (
int) $a_act);
395 return (
int) $this->ini->readVariable(
"db",
"slave_active");
404 $this->ini->setVariable(
"db",
"slave_host",$a_str);
414 return $this->ini->readVariable(
"db",
"slave_host");
423 $this->ini->setVariable(
"db",
"slave_name",$a_str);
432 return $this->ini->readVariable(
"db",
"slave_name");
441 $this->ini->setVariable(
"db",
"slave_user",$a_str);
450 return $this->ini->readVariable(
"db",
"slave_user");
459 return $this->ini->readVariable(
"db",
"slave_port");
468 $this->ini->setVariable(
"db",
"slave_port",$a_str);
477 $this->ini->setVariable(
"db",
"slave_pass",$a_str);
486 return $this->ini->readVariable(
"db",
"slave_pass");
495 $this->ini->setVariable(
"db",
"type",$a_str);
504 $val = $this->ini->readVariable(
"db",
"type");
521 return ILIAS_DATA_DIR.
"/".$this->
getId();
547 $db = $this->db_connections->connectHost($this->dsn_host);
551 $this->error =
$db->getMessage().
" - ".
$db->getUserInfo().
" - ".$lng->txt(
"db_error_please_check");
565 $db = $this->db_connections->connectDB($this->dsn);
577 if($a_keep_connection)
598 include_once
'./Services/Administration/classes/class.ilSetting.php';
600 return $set->get($a_keyword);
610 include_once
'./Services/Administration/classes/class.ilSetting.php';
612 return $set->getAll();
624 include_once
'./Services/Administration/classes/class.ilSetting.php';
626 $set->set($a_key, $a_val);
637 $inst_id = (empty($settings[
"inst_id"])) ?
"0" : $settings[
"inst_id"];
644 "&inst_id=".rawurlencode($inst_id).
645 "&hostname=".rawurlencode($_SERVER[
"SERVER_NAME"]).
646 "&inst_name=".rawurlencode($this->ini->readVariable(
"client",
"name")).
647 "&inst_info=".rawurlencode($this->ini->readVariable(
"client",
"description")).
648 "&http_path=".rawurlencode(ILIAS_HTTP_PATH).
649 "&contact_firstname=".rawurlencode($settings[
"admin_firstname"]).
650 "&contact_lastname=".rawurlencode($settings[
"admin_lastname"]).
651 "&contact_email=".rawurlencode($settings[
"admin_email"]).
652 "&nic_key=".rawurlencode($this->
getNICkey());
674 if((
bool)$settings[
'proxy_status'] && strlen($settings[
'proxy_host']) && strlen($settings[
'proxy_port']))
676 $proxy_options = array(
677 'proxy_host' => $settings[
'proxy_host'],
678 'proxy_port' => $settings[
'proxy_port']
683 $proxy_options = array();
686 include_once(
'HTTP/Request.php');
688 $req =
new HTTP_Request($url, $proxy_options);
691 $response = $req->getResponseBody();
692 $response = explode(
"\n", $response);
694 $this->nic_status = $response;
709 mt_srand((
double)microtime()*1000000);
710 $nic_key = md5(str_replace(
".",
"",$_SERVER[
"SERVER_ADDR"]) +
711 mt_rand(100000,999999));
715 $this->nic_key = $nic_key;
727 $this->nic_key = $this->
getSetting(
"nic_key");
729 if (empty($this->nic_key))
734 return $this->nic_key;
745 $this->ini->setVariable(
"language",
"default",$a_lang_key);
757 $error = $this->error;
771 function delete ($a_ini =
true, $a_db =
false, $a_files =
false)
775 unlink(CLIENT_WEB_DIR.
"/client.ini.php");
776 $msg[] =
"ini_deleted";
779 if ($a_db ===
true and $this->db_exists)
781 $this->db->query(
"DROP DATABASE ".$this->
getDbName());
782 $msg[] =
"db_deleted";
785 if ($a_files ===
true and file_exists(CLIENT_WEB_DIR) and is_dir(CLIENT_WEB_DIR))
790 $msg[] =
"files_deleted";
806 $this->error =
"could_not_create_base_data_dir :".$this->getDataDir();
813 $this->error =
"could_not_create_mail_data_dir :".$this->getDataDir().
"/mail";
819 $this->error =
"could_not_create_lm_data_dir :".$this->getDataDir().
"/lm_data";
825 $this->error =
"could_not_create_forum_data_dir :".$this->getDataDir().
"/forum";
831 $this->error =
"could_not_create_files_data_dir :".$this->getDataDir().
"/files";
838 $this->error =
"could_not_create_base_webspace_dir :".$this->getWebspaceDir();
845 $this->error =
"could_not_create_lm_webspace_dir :".$this->getWebspaceDir().
"/lm_data";
851 $this->error =
"could_not_create_usr_images_webspace_dir :".$this->getWebspaceDir().
"/usr_images";
857 $this->error =
"could_not_create_mobs_webspace_dir :".$this->getWebspaceDir().
"/mobs";
863 $this->error =
"could_not_create_css_webspace_dir :".$this->getWebspaceDir().
"/css";
868 if (!$this->ini->write())
870 $this->error = get_class($this).
": ".$this->ini->getError();