• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

classes/class.ilias.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00024 
00037 class ILIAS
00038 {
00043         var $INI_FILE;
00044 
00050         var $dsn = "";
00051 
00057         var $db;
00058 
00064         var $tplPath = "./templates/";
00065 
00071         var $account;
00072 
00078         var $auth_params = array();
00079 
00085         var $auth;
00086 
00092         var $ini = array();
00093 
00099         var $error_obj;
00100 
00107         var $obj_factory;
00108 
00115         var $styles;
00116 
00123         var $skins;
00124         
00130         function ILIAS($a_client_id = 0)
00131         {
00132                 global $ilErr, $ilDB;;
00133 
00134                 // load setup.ini
00135                 $this->ini_ilias = new ilIniFile("./ilias.ini.php");
00136                 $this->ini_ilias->read();
00137 
00138                 define("ILIAS_DATA_DIR",$this->ini_ilias->readVariable("clients","datadir"));
00139                 define("ILIAS_WEB_DIR",$this->ini_ilias->readVariable("clients","path"));
00140 
00141                 define ("ILIAS_HTTP_PATH",$this->ini_ilias->readVariable('server','http_path'));
00142                 define ("ILIAS_ABSOLUTE_PATH",$this->ini_ilias->readVariable('server','absolute_path'));
00143 
00144                 // logging
00145                 define ("ILIAS_LOG_DIR",$this->ini_ilias->readVariable("log","path"));
00146                 define ("ILIAS_LOG_FILE",$this->ini_ilias->readVariable("log","file"));
00147                 define ("ILIAS_LOG_ENABLED",$this->ini_ilias->readVariable("log","enabled"));
00148                 define ("ILIAS_LOG_LEVEL",$this->ini_ilias->readVariable("log","level"));
00149   
00150                 // read path + command for third party tools from ilias.ini
00151                 define ("PATH_TO_CONVERT",$this->ini_ilias->readVariable("tools","convert"));
00152                 define ("PATH_TO_ZIP",$this->ini_ilias->readVariable("tools","zip"));
00153                 define ("PATH_TO_UNZIP",$this->ini_ilias->readVariable("tools","unzip"));
00154                 define ("PATH_TO_JAVA",$this->ini_ilias->readVariable("tools","java"));
00155                 define ("PATH_TO_HTMLDOC",$this->ini_ilias->readVariable("tools","htmldoc"));
00156                 define ("PATH_TO_FOP",$this->ini_ilias->readVariable("tools","fop"));
00157                 
00158                 // read virus scanner settings
00159                 switch ($this->ini_ilias->readVariable("tools", "vscantype"))
00160                 {
00161                         case "sophos":
00162                                 define("IL_VIRUS_SCANNER", "Sophos");
00163                                 define("IL_VIRUS_SCAN_COMMAND", $this->ini_ilias->readVariable("tools", "scancommand"));
00164                                 define("IL_VIRUS_CLEAN_COMMAND", $this->ini_ilias->readVariable("tools", "cleancommand"));
00165                                 break;
00166                                 
00167                         case "antivir":
00168                                 define("IL_VIRUS_SCANNER", "AntiVir");
00169                                 define("IL_VIRUS_SCAN_COMMAND", $this->ini_ilias->readVariable("tools", "scancommand"));
00170                                 define("IL_VIRUS_CLEAN_COMMAND", $this->ini_ilias->readVariable("tools", "cleancommand"));
00171                                 break;
00172                                 
00173                         default:
00174                                 define("IL_VIRUS_SCANNER", "None");
00175                                 break;
00176                 }
00177 
00178                 // set to default client if empty
00179                 if (!$a_client_id)
00180                 {
00181                         $this->client_id = $this->ini_ilias->readVariable("clients","default");
00182                         setcookie("ilClientId",$this->client_id);
00183                         $_COOKIE["ilClientId"] = $this->client_id;
00184                 }
00185                 else
00186                 {
00187                         $this->client_id = $_COOKIE["ilClientId"];
00188                 }
00189 
00190                 $this->INI_FILE = "./".ILIAS_WEB_DIR."/".$this->client_id."/client.ini.php";
00191 
00192 //              $this->PEAR();
00193 
00194                 // prepare file access to work with safe mode
00195                 umask(0117);
00196 
00197                 // get settings from ini file
00198                 $this->ini = new ilIniFile($this->INI_FILE);
00199                 $this->ini->read();
00200 
00201                 // if no ini-file found switch to setup routine
00202                 if ($this->ini->ERROR != "")
00203                 {
00204                         ilUtil::redirect("./setup/setup.php");
00205                 }
00206 
00207                 if (!$this->ini->readVariable("client","access"))
00208                 {
00209                         die("client disabled");
00210                 }
00211 
00212                 // set constants
00213                 define ("DEBUG",$this->ini->readVariable("system","DEBUG"));
00214                 define ("DEVMODE",$this->ini->readVariable("system","DEVMODE"));
00215                 define ("ROOT_FOLDER_ID",$this->ini->readVariable('system','ROOT_FOLDER_ID'));
00216                 define ("SYSTEM_FOLDER_ID",$this->ini->readVariable('system','SYSTEM_FOLDER_ID'));
00217                 define ("ROLE_FOLDER_ID",$this->ini->readVariable('system','ROLE_FOLDER_ID'));
00218                 define ("MAIL_SETTINGS_ID",$this->ini->readVariable('system','MAIL_SETTINGS_ID'));
00219 
00220                 define ("MAXLENGTH_OBJ_TITLE",$this->ini->readVariable('system','MAXLENGTH_OBJ_TITLE'));
00221                 define ("MAXLENGTH_OBJ_DESC",$this->ini->readVariable('system','MAXLENGTH_OBJ_DESC'));
00222 
00223                 define ("CLIENT_DATA_DIR",ILIAS_DATA_DIR."/".$this->client_id);
00224                 define ("CLIENT_WEB_DIR",ILIAS_ABSOLUTE_PATH."/".ILIAS_WEB_DIR."/".$this->client_id);
00225                 define ("CLIENT_ID",$this->client_id);
00226 
00227                 // build dsn of database connection and connect
00228                 $this->dsn = $this->ini->readVariable("db","type").
00229                                          "://".$this->ini->readVariable("db", "user").
00230                                          ":".$this->ini->readVariable("db", "pass").
00231                                          "@".$this->ini->readVariable("db", "host").
00232                                          "/".$this->ini->readVariable("db", "name");
00233 
00234                 $this->db = new ilDBx($this->dsn);
00235 
00236                 // Error Handling
00237                 $this->error_obj =& $ilErr;
00238 
00239                 // moved here from inc.header.php (db_set_save_handler needs db object)
00240                 $ilDB = $this->db;
00241                 $GLOBALS['ilDB'] =& $ilDB;
00242 
00243                 // set session.save_handler to "user" & set expiry time
00244                 if(ini_get('session.save_handler') != 'user')
00245                 {
00246                         ini_set("session.save_handler", "user");
00247                 }
00248 
00249                 // moved here from inc.header.php
00250                 if (!db_set_save_handler())
00251                 {
00252                         $message = "Please turn off Safe mode OR set session.save_handler to \"user\" in your php.ini";
00253                         $this->ilias->raiseError($message,$this->ilias->error_obj->WARNING);
00254                 }
00255 
00256                 // set anonymous user & role id and system role id
00257                 define ("ANONYMOUS_USER_ID",$this->getSetting("anonymous_user_id"));
00258                 define ("ANONYMOUS_ROLE_ID",$this->getSetting("anonymous_role_id"));
00259                 define ("SYSTEM_USER_ID",$this->getSetting("system_user_id"));
00260                 define ("SYSTEM_ROLE_ID",$this->getSetting("system_role_id"));
00261                 define ("RECOVERY_FOLDER_ID",$this->getSetting("recovery_folder_id"));
00262 
00263                 // installation id
00264                 define ("IL_INST_ID", $this->getSetting("inst_id"));
00265                 
00266                 // auth modes
00267                 define ("AUTH_LOCAL",1);
00268                 define ("AUTH_LDAP",2);
00269                 define ("AUTH_RADIUS",3);
00270                 define ("AUTH_SCRIPT",4);
00271 
00272                 $auth_mode = $this->getSetting("auth_mode");
00273 
00274                 // set local auth mode (1) in case database wasn't updated
00275                 if ($auth_mode === false)
00276                 {
00277                         $auth_mode = AUTH_LOCAL;
00278                 }
00279                 
00280                 define ("AUTH_CURRENT",$auth_mode);
00281                                 
00282                 switch (AUTH_CURRENT)
00283                 {
00284                         case AUTH_LOCAL:
00285                                 // build option string for PEAR::Auth
00286                                 $this->auth_params = array(
00287                                                                                         'dsn'             => $this->dsn,
00288                                                                                         'table'       => $this->ini->readVariable("auth", "table"),
00289                                                                                         'usernamecol' => $this->ini->readVariable("auth", "usercol"),
00290                                                                                         'passwordcol' => $this->ini->readVariable("auth", "passcol")
00291                                                                                         );
00292                                 // We use MySQL as storage container
00293 
00294                                 $this->auth = new Auth("DB", $this->auth_params,"",false);
00295 
00296                                 break;
00297                         
00298                         case AUTH_LDAP:
00299                                 $settings = $this->getAllSettings();
00300 
00301                                 // build option string for PEAR::Auth
00302                                 $this->auth_params = array(
00303                                                                                         'host'          => $settings["ldap_server"],
00304                                                                                         'port'          => $settings["ldap_port"],
00305                                                                                         'basedn'        => $settings["ldap_basedn"],
00306                                                                                         'userdn'        => $settings["ldap_search_base"],
00307                                                                                         'useroc'        => $settings["ldap_objectclass"],
00308                                                                                         'userattr'      => $settings["ldap_login_key"]
00309                                                                                         );
00310                                 $this->auth = new Auth("LDAP", $this->auth_params,"",false);
00311 
00312                                 break;
00313                                 
00314                         default:
00315                                 // build option string for PEAR::Auth
00316                                 $this->auth_params = array(
00317                                                                                         'dsn'             => $this->dsn,
00318                                                                                         'table'       => $this->ini->readVariable("auth", "table"),
00319                                                                                         'usernamecol' => $this->ini->readVariable("auth", "usercol"),
00320                                                                                         'passwordcol' => $this->ini->readVariable("auth", "passcol")
00321                                                                                         );
00322                                 // We use MySQL as storage container
00323                                 $this->auth = new Auth("DB", $this->auth_params,"",false);
00324                                 break;
00325 
00326                 }
00327                 
00328                 /*
00329                 ini_set("session.gc_maxlifetime",$this->ini->readVariable("session","expire"));
00330                 ini_set("session.cookie_lifetime",$this->ini->readVariable("session","expire"));
00331                 */
00332                 //ini_set("session.gc_maxlifetime", 10);
00333                 //ini_set("session.cookie_lifetime", 10);
00334 
00335                 $this->auth->setIdle($this->ini->readVariable("session","expire"), false);
00336                 $this->auth->setExpire(0);
00337                 ini_set("session.cookie_lifetime", 0);
00338 
00339                 // create instance of object factory
00340                 require_once("classes/class.ilObjectFactory.php");
00341                 $this->obj_factory =& new ilObjectFactory();
00342 
00343         }
00344 
00350         function _ILIAS()
00351         {
00352                 if ($this->ini->readVariable("db", "type") != "")
00353                 {
00354                         $this->db->disconnect();
00355                 }
00356                 
00357                 return true;
00358         }
00359 
00366         function getSetting($a_keyword)
00367         {
00368                 if ($a_keyword == "ilias_version")
00369                 {
00370                         return ILIAS_VERSION;
00371                 }
00372                 
00373                 $query = "SELECT value FROM settings WHERE keyword='".$a_keyword."'";
00374                 $res = $this->db->query($query);
00375 
00376                 if ($res->numRows() > 0)
00377                 {
00378                         $row = $res->fetchRow();
00379                         return ilUtil::stripSlashes($row[0]);
00380                 }
00381                 else
00382                 {
00383                         return false;
00384                 }
00385         }
00386         
00393         function deleteSetting($a_keyword)
00394         {
00395                 $query = "DELETE FROM settings WHERE keyword = '".$a_keyword."'";
00396                 $this->db->query($query);
00397 
00398                 return true;
00399         }
00400 
00401 
00407         function getAllSettings()
00408         {
00409                 $query = "SELECT * FROM settings";
00410                 $res = $this->db->query($query);
00411 
00412                 while ($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
00413                 {
00414                         $arr[$row["keyword"]] = ilUtil::stripSlashes($row["value"]);
00415                 }
00416 
00417                 return $arr;
00418         }
00419 
00429         function setSetting($a_key, $a_val)
00430         {
00431                 $sql = "DELETE FROM settings WHERE keyword='".$a_key."'";
00432                 $r = $this->db->query($sql);
00433 
00434                 $sql = "INSERT INTO settings (keyword, value) VALUES ('".$a_key."','".addslashes($a_val)."')";
00435                 $r = $this->db->query($sql);
00436 
00437                 return true;
00438         }
00439 
00450         /*
00451         function getSkins()
00452         {
00453                 $skins = array();
00454 
00455                 //open directory for reading and search for subdirectories
00456                 //$tplpath = $this->ini->readVariable("server", "tpl_path");
00457                 //$tplpath = "./templates";
00458 
00459                 if ($dp = @opendir($this->tplPath))
00460                 {
00461                         while (($file = readdir($dp)) != false)
00462                         {
00463                                 //is the file a directory?
00464                                 if (is_dir($this->tplPath.$file) && $file != "." && $file != ".." && $file != "CVS")
00465                                 {
00466                                         $skins[] = array(
00467                                                 "name" => $file
00468                                         );
00469                                 }
00470                         } // while
00471                 }
00472                 else
00473                 {
00474                         return false;
00475                 }
00476 
00477                 $this->skins = $skins;
00478 
00479                 return true;
00480         }*/
00481 
00494         /*
00495         function getStyles($a_skin)
00496         {
00497                 $styles = array();
00498 
00499                 //open directory for reading and search for subdirectories
00500                 //$tplpath = $this->ini->readVariable("server", "tpl_path")."/".$skin;
00501                 //$tplpath = "./templates/".$a_skin;
00502 
00503                 if ($dp = @opendir($this->tplPath.$a_skin))
00504                 {
00505                         while (($file = readdir($dp)) != false)
00506                         {
00507                                 //is the file a stylesheet?
00508                                 if (strpos($file, ".css") > 0)
00509                                 {
00510                                         $styles[] = array(
00511                                                                                 "name" => substr($file,0,-4)
00512                                                                         );
00513                                 }
00514                         } // while
00515                 }
00516                 else
00517                 {
00518                         return false;
00519                 }
00520 
00521                 $this->styles = $styles;
00522 
00523                 return true;
00524         }*/
00525 
00532         function getFirstStyle($a_skin)
00533         {
00534                 if (!is_array($this->styles))
00535                 {
00536                         $this->getStyles($a_skin);
00537                 }
00538 
00539                 return $this->styles[0]["name"];
00540         }
00541         
00548         function checkTemplate($a_name)
00549         {
00550                 return file_exists($this->tplPath.$a_name);
00551         }
00552 
00556         function &getCurrentUser()
00557         {
00558                 return $this->account;
00559         }
00560         
00561         function getClientId()
00562         {
00563                 return $this->client_id;
00564         }
00565         
00569         function raiseError($a_msg,$a_err_obj)
00570         {
00571                 global $ilErr;
00572 
00573                 $ilErr->raiseError($a_msg,$a_err_obj);
00574         }
00575 
00576 } // END class.ilias
00577 ?>

Generated on Fri Dec 13 2013 09:06:34 for ILIAS Release_3_4_x_branch .rev 46804 by  doxygen 1.7.1