• 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->raiseError($message, $this->error_obj->FATAL);
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                 // define auth modes
00267                 define ("AUTH_LOCAL",1);
00268                 define ("AUTH_LDAP",2);
00269                 define ("AUTH_RADIUS",3);
00270                 define ("AUTH_SCRIPT",4);
00271                 define ("AUTH_SHIBBOLETH",5);
00272                 
00273                 // get default auth mode 
00274                 //$default_auth_mode = $this->getSetting("auth_mode");
00275                 define ("AUTH_DEFAULT", $this->getSetting("auth_mode") ? $this->getSetting("auth_mode") : AUTH_LOCAL);
00276                 
00277                 // set local auth mode (1) in case database wasn't updated
00278                 /*if ($default_auth_mode === false)
00279                 {
00280                         $default_auth_mode = AUTH_LOCAL;
00281                 }*/
00282                 
00283                 // determine authentication method if no session is found and username & password is posted
00284         if (empty($_SESSION) ||
00285             (!isset($_SESSION['_authsession']['registered']) ||
00286              $_SESSION['_authsession']['registered'] !== true))
00287         {
00288                         // no sesssion found
00289                         if ($_POST['username'] != '' and $_POST['password'] != '')
00290                         {
00291                                 include_once(ILIAS_ABSOLUTE_PATH.'/classes/class.ilAuthUtils.php');
00292                                 $user_auth_mode = ilAuthUtils::_getAuthModeOfUser($_POST['username'],$_POST['password'],$this->db);
00293                         }
00294         }
00295                 
00296                 // If Shibboleth is active and the user is authenticated
00297                 // we set auth_mode to Shibboleth
00298                 if (    
00299                                 $this->getSetting("shib_active")
00300                                 && $_SERVER[$this->getSetting("shib_login")]
00301                         )
00302                 {
00303                         define ("AUTH_CURRENT",AUTH_SHIBBOLETH);
00304                 }
00305                 else
00306                 {
00307                         define ("AUTH_CURRENT",$user_auth_mode);
00308                 }
00309                 
00310                 switch (AUTH_CURRENT)
00311                 {
00312                         case AUTH_LOCAL:
00313                                 // build option string for PEAR::Auth
00314                                 $this->auth_params = array(
00315                                                                                         'dsn'             => $this->dsn,
00316                                                                                         'table'       => $this->ini->readVariable("auth", "table"),
00317                                                                                         'usernamecol' => $this->ini->readVariable("auth", "usercol"),
00318                                                                                         'passwordcol' => $this->ini->readVariable("auth", "passcol")
00319                                                                                         );
00320                                 // We use MySQL as storage container
00321                                 $this->auth = new Auth("DB", $this->auth_params,"",false);
00322                                 break;
00323                         
00324                         case AUTH_LDAP:
00325                                 $settings = $this->getAllSettings();
00326 
00327                                 // build option string for PEAR::Auth
00328                                 $this->auth_params = array(
00329                                                                                         'host'          => $settings["ldap_server"],
00330                                                                                         'port'          => $settings["ldap_port"],
00331                                                                                         'basedn'        => $settings["ldap_basedn"],
00332                                                                                         'userdn'        => $settings["ldap_search_base"],
00333                                                                                         'useroc'        => $settings["ldap_objectclass"],
00334                                                                                         'userattr'      => $settings["ldap_login_key"]
00335                                                                                         );
00336                                 $this->auth = new Auth("LDAP", $this->auth_params,"",false);
00337                                 break;
00338                                 
00339                         case AUTH_RADIUS:
00340                                 include_once('classes/class.ilRADIUSAuthentication.php');
00341                                 $radius_servers = ilRADIUSAuthentication::_getServers($this->db);
00342 
00343                                 $settings = $this->getAllSettings();
00344                                 
00345                                 foreach ($radius_servers as $radius_server)
00346                                 {
00347                                         $rad_params['servers'][] = array($radius_server,$settings["radius_port"],$settings["radius_shared_secret"]);
00348                                 }
00349                                 
00350                                 // build option string for PEAR::Auth
00351                                 //$this->auth_params = array($rad_params);
00352                                 $this->auth_params = $rad_params;
00353                                 $this->auth = new Auth("RADIUS", $this->auth_params,"",false);
00354                                 break;
00355                                 
00356                         case AUTH_SHIBBOLETH:
00357                                 $settings = $this->getAllSettings();
00358 
00359                                 // build option string for SHIB::Auth
00360                                 $this->auth_params = array();
00361                                 $this->auth = new ShibAuth($this->auth_params,true);
00362                                 break;
00363                                 
00364                         default:
00365                                 // build option string for PEAR::Auth
00366                                 $this->auth_params = array(
00367                                                                                         'dsn'             => $this->dsn,
00368                                                                                         'table'       => $this->ini->readVariable("auth", "table"),
00369                                                                                         'usernamecol' => $this->ini->readVariable("auth", "usercol"),
00370                                                                                         'passwordcol' => $this->ini->readVariable("auth", "passcol")
00371                                                                                         );
00372                                 // We use MySQL as storage container
00373                                 $this->auth = new Auth("DB", $this->auth_params,"",false);
00374                                 break;
00375 
00376                 }
00377 
00378                 $this->auth->setIdle($this->ini->readVariable("session","expire"), false);
00379                 $this->auth->setExpire(0);
00380                 ini_set("session.cookie_lifetime", "0");
00381 
00382                 // create instance of object factory
00383                 require_once("classes/class.ilObjectFactory.php");
00384                 $this->obj_factory =& new ilObjectFactory();
00385         }
00386 
00392         function _ILIAS()
00393         {
00394                 if ($this->ini->readVariable("db", "type") != "")
00395                 {
00396                         $this->db->disconnect();
00397                 }
00398                 
00399                 return true;
00400         }
00401         
00402         
00409         function setAuthError($a_error_obj)
00410         {
00411                 $this->auth_error =& $a_error_obj;
00412         }
00413         
00417         function &getAuthError()
00418         {
00419                 return $this->auth_error;
00420         }
00421 
00430         function getSetting($a_keyword, $a_default_value = false)
00431         {
00432 
00433                 if ($a_keyword == "ilias_version")
00434                 {
00435                         return ILIAS_VERSION;
00436                 }
00437                 
00438                 $query = "SELECT value FROM settings WHERE keyword='".$a_keyword."'";
00439                 $res = $this->db->query($query);
00440 
00441                 if ($res->numRows() > 0)
00442                 {
00443                         $row = $res->fetchRow();
00444                         return $row[0];
00445                         //return ilUtil::stripSlashes($row[0]);
00446                 }
00447                 else
00448                 {
00449                         return $a_default_value;
00450                 }
00451         }
00452         
00459         function deleteSetting($a_keyword)
00460         {
00461                 $query = "DELETE FROM settings WHERE keyword = '".$a_keyword."'";
00462                 $this->db->query($query);
00463 
00464                 return true;
00465         }
00466 
00467 
00473         function getAllSettings()
00474         {
00475                 $query = "SELECT * FROM settings";
00476                 $res = $this->db->query($query);
00477 
00478                 while ($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
00479                 {
00480                         $arr[$row["keyword"]] = $row["value"];
00481                         //$arr[$row["keyword"]] = ilUtil::stripSlashes($row["value"]);
00482                 }
00483 
00484                 return $arr;
00485         }
00486 
00496         function setSetting($a_key, $a_val)
00497         {
00498                 $sql = "DELETE FROM settings WHERE keyword='".$a_key."'";
00499                 $r = $this->db->query($sql);
00500 
00501                 $sql = "INSERT INTO settings (keyword, value) VALUES ('".$a_key."','".addslashes($a_val)."')";
00502                 $r = $this->db->query($sql);
00503 
00504                 return true;
00505         }
00506 
00517         /*
00518         function getSkins()
00519         {
00520                 $skins = array();
00521 
00522                 //open directory for reading and search for subdirectories
00523                 //$tplpath = $this->ini->readVariable("server", "tpl_path");
00524                 //$tplpath = "./templates";
00525 
00526                 if ($dp = @opendir($this->tplPath))
00527                 {
00528                         while (($file = readdir($dp)) != false)
00529                         {
00530                                 //is the file a directory?
00531                                 if (is_dir($this->tplPath.$file) && $file != "." && $file != ".." && $file != "CVS")
00532                                 {
00533                                         $skins[] = array(
00534                                                 "name" => $file
00535                                         );
00536                                 }
00537                         } // while
00538                 }
00539                 else
00540                 {
00541                         return false;
00542                 }
00543 
00544                 $this->skins = $skins;
00545 
00546                 return true;
00547         }*/
00548 
00561         /*
00562         function getStyles($a_skin)
00563         {
00564                 $styles = array();
00565 
00566                 //open directory for reading and search for subdirectories
00567                 //$tplpath = $this->ini->readVariable("server", "tpl_path")."/".$skin;
00568                 //$tplpath = "./templates/".$a_skin;
00569 
00570                 if ($dp = @opendir($this->tplPath.$a_skin))
00571                 {
00572                         while (($file = readdir($dp)) != false)
00573                         {
00574                                 //is the file a stylesheet?
00575                                 if (strpos($file, ".css") > 0)
00576                                 {
00577                                         $styles[] = array(
00578                                                                                 "name" => substr($file,0,-4)
00579                                                                         );
00580                                 }
00581                         } // while
00582                 }
00583                 else
00584                 {
00585                         return false;
00586                 }
00587 
00588                 $this->styles = $styles;
00589 
00590                 return true;
00591         }*/
00592 
00599         function getFirstStyle($a_skin)
00600         {
00601                 if (!is_array($this->styles))
00602                 {
00603                         $this->getStyles($a_skin);
00604                 }
00605 
00606                 return $this->styles[0]["name"];
00607         }
00608         
00615         function checkTemplate($a_name)
00616         {
00617                 return file_exists($this->tplPath.$a_name);
00618         }
00619 
00623         function &getCurrentUser()
00624         {
00625                 return $this->account;
00626         }
00627         
00628         function getClientId()
00629         {
00630                 return $this->client_id;
00631         }
00632         
00636         function raiseError($a_msg,$a_err_obj)
00637         {
00638                 global $ilErr;
00639 
00640                 $ilErr->raiseError($a_msg,$a_err_obj);
00641         }
00642 
00643 } // END class.ilias
00644 ?>

Generated on Fri Dec 13 2013 10:18:27 for ILIAS Release_3_5_x_branch .rev 46805 by  doxygen 1.7.1