Public Member Functions | Data Fields

ilClient Class Reference

Public Member Functions

 ilClient ($a_client_id=0)
 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
 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

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


Member Function Documentation

ilClient::checkDatabaseExists (  ) 

check database connection with database name

Returns:
boolean

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

References connect(), and isInstalledDB().

        {
                //try to connect to database
                $db = DB::connect($this->dsn);

                if (DB::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 360 of file class.ilClient.php.

References connect().

        {
                //connect to databasehost
                $db = DB::connect($this->dsn_host);

                if (DB::isError($db))
                {
                        $this->error = $db->getMessage()."! Please check database hostname, username & password.";
                        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 194 of file class.ilClient.php.

References isMysql4_1OrHigher(), and setDSN().

Referenced by checkDatabaseExists(), checkDatabaseHost(), and init().

        {
                // check parameters
                if (!$this->getdbHost() || !$this->getdbName() || !$this->getdbUser())
                {
                        $this->error = "empty_fields";
                        return false;
                }

                $this->setDSN();

                $this->db = DB::connect($this->dsn,true);

                if (DB::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 635 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
                if (!ilUtil::makeDir($this->getWebspaceDir()))
                {
                        $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:
boolean remove ini if true
boolean remove db if true
boolean remove files if true
Returns:
array confirmation messages

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

References ilUtil::delDir(), and getDbName().

        {
                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 423 of file class.ilClient.php.

References $q, and $row.

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 342 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 279 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 297 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 333 of file class.ilClient.php.

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

ilClient::getDbUser (  ) 

get db user

Returns:
string db user

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

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

ilClient::getDefaultLanguage (  ) 

Definition at line 572 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 148 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 590 of file class.ilClient.php.

        {
                $error = $this->error;
                $this->error = "";

                return $error;
        }

ilClient::getId (  ) 

get client id

Returns:
string client id

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

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 165 of file class.ilClient.php.

        {
                return mysql_get_server_info();
        }

ilClient::getName (  ) 

get client name

Returns:
string client name

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

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

ilClient::getNICkey (  ) 

get nic_key public

Returns:
string nic_key

Definition at line 560 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:
string keyword
Returns:
string value

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

References $q, and $row.

Referenced by getDefaultLanguage(), and getNICkey().

        {
                $q = "SELECT value FROM settings WHERE keyword='".$a_keyword."'";
                $r = $this->db->query($q);

                if ($r->numRows() > 0)
                {
                        $row = $r->fetchRow();
                        return $row[0];
                }
                else
                {
                        return false;
                }
        }

Here is the caller graph for this function:

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

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

References getId().

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 = 0  ) 

Constructor.

Parameters:
string client id

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

References getId().

        {
                if ($a_client_id)
                {
                        $this->id = $a_client_id;
                        $this->ini_file_path = ILIAS_ABSOLUTE_PATH."/".ILIAS_WEB_DIR."/".$this->getId()."/client.ini.php";
                }

                // 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 67 of file class.ilClient.php.

References connect(), 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:
object db object
Returns:
boolean true if installed

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

References $q, $row, and $tables.

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 178 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::setDbHost ( a_str  ) 

set the host

Parameters:
string 

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

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

ilClient::setDbPass ( a_str  ) 

set db password

Parameters:
string 

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

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

ilClient::setDbUser ( a_str  ) 

set db user

Parameters:
string db user

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

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

ilClient::setDefaultLanguage ( a_lang_key  ) 

Definition at line 577 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:
string client description

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

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

ilClient::setDSN (  ) 

set the dsn and dsn_host

Definition at line 258 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:
string client id

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

        {
                $this->id = $a_client_id;
                $this->webspace_dir = ILIAS_ABSOLUTE_PATH."/".ILIAS_WEB_DIR."/".$this->id;
        }

ilClient::setName ( a_str  ) 

set client name

Parameters:
string client name

Definition at line 139 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 542 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:
string keyword
string value
Returns:
boolean true on success

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

References $q.

Referenced by setDefaultLanguage(), and setNICkey().

        {
                $q = "REPLACE INTO settings SET keyword = '".$a_key."', value = '".$a_val."'";
                $this->db->query($q);
                
                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 504 of file class.ilClient.php.

References 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 41 of file class.ilClient.php.

ilClient::$db_exists = false

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

ilClient::$db_installed = false

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

ilClient::$dir

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

ilClient::$id

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

ilClient::$name

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

ilClient::$nic_status

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

ilClient::$setup_ok = false

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

ilClient::$status

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


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