• 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-2005 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                 $this->__buildHTTPPath();
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                         if (is_file("./maintenance.html"))
00210                         {
00211                                 ilUtil::redirect("./maintenance.html");
00212                         }
00213                         else
00214                         {
00215                                 echo '<br /><p style="text-align:center;">The server is not '.
00216                                         'available due to maintenance. We apologise for any inconvenience.</p>';
00217                                 exit;
00218                         }
00219                 }
00220 
00221                 // set constants
00222                 define ("DEBUG",$this->ini->readVariable("system","DEBUG"));
00223                 define ("DEVMODE",$this->ini->readVariable("system","DEVMODE"));
00224                 define ("ROOT_FOLDER_ID",$this->ini->readVariable('system','ROOT_FOLDER_ID'));
00225                 define ("SYSTEM_FOLDER_ID",$this->ini->readVariable('system','SYSTEM_FOLDER_ID'));
00226                 define ("ROLE_FOLDER_ID",$this->ini->readVariable('system','ROLE_FOLDER_ID'));
00227                 define ("MAIL_SETTINGS_ID",$this->ini->readVariable('system','MAIL_SETTINGS_ID'));
00228 
00229                 define ("MAXLENGTH_OBJ_TITLE",$this->ini->readVariable('system','MAXLENGTH_OBJ_TITLE'));
00230                 define ("MAXLENGTH_OBJ_DESC",$this->ini->readVariable('system','MAXLENGTH_OBJ_DESC'));
00231 
00232                 define ("CLIENT_DATA_DIR",ILIAS_DATA_DIR."/".$this->client_id);
00233                 define ("CLIENT_WEB_DIR",ILIAS_ABSOLUTE_PATH."/".ILIAS_WEB_DIR."/".$this->client_id);
00234                 define ("CLIENT_ID",$this->client_id);
00235 
00236                 // build dsn of database connection and connect
00237                 $this->dsn = $this->ini->readVariable("db","type").
00238                                          "://".$this->ini->readVariable("db", "user").
00239                                          ":".$this->ini->readVariable("db", "pass").
00240                                          "@".$this->ini->readVariable("db", "host").
00241                                          "/".$this->ini->readVariable("db", "name");
00242 
00243                 $this->db = new ilDBx($this->dsn);
00244 
00245                 // Error Handling
00246                 $this->error_obj =& $ilErr;
00247 
00248                 // moved here from inc.header.php (db_set_save_handler needs db object)
00249                 $ilDB = $this->db;
00250                 $GLOBALS['ilDB'] =& $ilDB;
00251 
00252                 // set session.save_handler to "user" & set expiry time
00253                 if(ini_get('session.save_handler') != 'user')
00254                 {
00255                         ini_set("session.save_handler", "user");
00256                 }
00257                 
00258                 // moved here from inc.header.php
00259                 if (!db_set_save_handler())
00260                 {
00261                         $message = "Please turn off Safe mode OR set session.save_handler to \"user\" in your php.ini";
00262                         $this->raiseError($message, $this->error_obj->FATAL);
00263                 }
00264 
00265                 // set anonymous user & role id and system role id
00266                 define ("ANONYMOUS_USER_ID",$this->getSetting("anonymous_user_id"));
00267                 define ("ANONYMOUS_ROLE_ID",$this->getSetting("anonymous_role_id"));
00268                 define ("SYSTEM_USER_ID",$this->getSetting("system_user_id"));
00269                 define ("SYSTEM_ROLE_ID",$this->getSetting("system_role_id"));
00270                 define ("RECOVERY_FOLDER_ID",$this->getSetting("recovery_folder_id"));
00271 
00272                 // installation id
00273                 define ("IL_INST_ID", $this->getSetting("inst_id"));
00274 
00275                 // define auth modes
00276                 define ("AUTH_LOCAL",1);
00277                 define ("AUTH_LDAP",2);
00278                 define ("AUTH_RADIUS",3);
00279                 define ("AUTH_SCRIPT",4);
00280                 define ("AUTH_SHIBBOLETH",5);
00281                 
00282                 // get default auth mode 
00283                 //$default_auth_mode = $this->getSetting("auth_mode");
00284                 define ("AUTH_DEFAULT", $this->getSetting("auth_mode") ? $this->getSetting("auth_mode") : AUTH_LOCAL);
00285                 
00286                 // set local auth mode (1) in case database wasn't updated
00287                 /*if ($default_auth_mode === false)
00288                 {
00289                         $default_auth_mode = AUTH_LOCAL;
00290                 }*/
00291                 
00292                 // determine authentication method if no session is found and username & password is posted
00293         if (empty($_SESSION) ||
00294             (!isset($_SESSION['_authsession']['registered']) ||
00295              $_SESSION['_authsession']['registered'] !== true))
00296         {
00297                         // no sesssion found
00298                         if ($_POST['username'] != '' and $_POST['password'] != '')
00299                         {
00300                                 include_once(ILIAS_ABSOLUTE_PATH.'/classes/class.ilAuthUtils.php');
00301                                 $user_auth_mode = ilAuthUtils::_getAuthModeOfUser($_POST['username'],$_POST['password'],$this->db);
00302                         }
00303         }
00304                 
00305                 // If Shibboleth is active and the user is authenticated
00306                 // we set auth_mode to Shibboleth
00307                 if (    
00308                                 $this->getSetting("shib_active")
00309                                 && $_SERVER[$this->getSetting("shib_login")]
00310                         )
00311                 {
00312                         define ("AUTH_CURRENT",AUTH_SHIBBOLETH);
00313                 }
00314                 else
00315                 {
00316                         define ("AUTH_CURRENT",$user_auth_mode);
00317                 }
00318                 
00319                 switch (AUTH_CURRENT)
00320                 {
00321                         case AUTH_LOCAL:
00322                                 // build option string for PEAR::Auth
00323                                 $this->auth_params = array(
00324                                                                                         'dsn'             => $this->dsn,
00325                                                                                         'table'       => $this->ini->readVariable("auth", "table"),
00326                                                                                         'usernamecol' => $this->ini->readVariable("auth", "usercol"),
00327                                                                                         'passwordcol' => $this->ini->readVariable("auth", "passcol")
00328                                                                                         );
00329                                 // We use MySQL as storage container
00330                                 $this->auth = new Auth("DB", $this->auth_params,"",false);
00331                                 break;
00332                         
00333                         case AUTH_LDAP:
00334                                 $settings = $this->getAllSettings();
00335 
00336                                 // build option string for PEAR::Auth
00337                                 $this->auth_params = array(
00338                                                                                         'host'          => $settings["ldap_server"],
00339                                                                                         'port'          => $settings["ldap_port"],
00340                                                                                         'basedn'        => $settings["ldap_basedn"],
00341                                                                                         'userdn'        => $settings["ldap_search_base"],
00342                                                                                         'useroc'        => $settings["ldap_objectclass"],
00343                                                                                         'userattr'      => $settings["ldap_login_key"]
00344                                                                                         );
00345                                 $this->auth = new Auth("LDAP", $this->auth_params,"",false);
00346                                 break;
00347                                 
00348                         case AUTH_RADIUS:
00349                                 include_once('classes/class.ilRADIUSAuthentication.php');
00350                                 $radius_servers = ilRADIUSAuthentication::_getServers($this->db);
00351 
00352                                 $settings = $this->getAllSettings();
00353                                 
00354                                 foreach ($radius_servers as $radius_server)
00355                                 {
00356                                         $rad_params['servers'][] = array($radius_server,$settings["radius_port"],$settings["radius_shared_secret"]);
00357                                 }
00358                                 
00359                                 // build option string for PEAR::Auth
00360                                 //$this->auth_params = array($rad_params);
00361                                 $this->auth_params = $rad_params;
00362                                 $this->auth = new Auth("RADIUS", $this->auth_params,"",false);
00363                                 break;
00364                                 
00365                         case AUTH_SHIBBOLETH:
00366                                 $settings = $this->getAllSettings();
00367 
00368                                 // build option string for SHIB::Auth
00369                                 $this->auth_params = array();
00370                                 $this->auth = new ShibAuth($this->auth_params,true);
00371                                 break;
00372                                 
00373                         default:
00374                                 // build option string for PEAR::Auth
00375                                 $this->auth_params = array(
00376                                                                                         'dsn'             => $this->dsn,
00377                                                                                         'table'       => $this->ini->readVariable("auth", "table"),
00378                                                                                         'usernamecol' => $this->ini->readVariable("auth", "usercol"),
00379                                                                                         'passwordcol' => $this->ini->readVariable("auth", "passcol")
00380                                                                                         );
00381                                 // We use MySQL as storage container
00382                                 $this->auth = new Auth("DB", $this->auth_params,"",false);
00383                                 break;
00384 
00385                 }
00386 
00387                 $this->auth->setIdle($this->ini->readVariable("session","expire"), false);
00388                 $this->auth->setExpire(0);
00389                 ini_set("session.cookie_lifetime", "0");
00390 
00391                 // create instance of object factory
00392                 require_once("classes/class.ilObjectFactory.php");
00393                 $this->obj_factory =& new ilObjectFactory();
00394         }
00395 
00401         function _ILIAS()
00402         {
00403                 if ($this->ini->readVariable("db", "type") != "")
00404                 {
00405                         $this->db->disconnect();
00406                 }
00407                 
00408                 return true;
00409         }
00410         
00411         
00418         function setAuthError($a_error_obj)
00419         {
00420                 $this->auth_error =& $a_error_obj;
00421         }
00422         
00426         function &getAuthError()
00427         {
00428                 return $this->auth_error;
00429         }
00430 
00439         function getSetting($a_keyword, $a_default_value = false)
00440         {
00441 
00442                 if ($a_keyword == "ilias_version")
00443                 {
00444                         return ILIAS_VERSION;
00445                 }
00446                 
00447                 $query = "SELECT value FROM settings WHERE keyword='".$a_keyword."'";
00448                 $res = $this->db->query($query);
00449 
00450                 if ($res->numRows() > 0)
00451                 {
00452                         $row = $res->fetchRow();
00453                         return $row[0];
00454                         //return ilUtil::stripSlashes($row[0]);
00455                 }
00456                 else
00457                 {
00458                         return $a_default_value;
00459                 }
00460         }
00461         
00468         function deleteSetting($a_keyword)
00469         {
00470                 $query = "DELETE FROM settings WHERE keyword = '".$a_keyword."'";
00471                 $this->db->query($query);
00472 
00473                 return true;
00474         }
00475 
00476 
00482         function getAllSettings()
00483         {
00484                 $query = "SELECT * FROM settings";
00485                 $res = $this->db->query($query);
00486 
00487                 while ($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
00488                 {
00489                         $arr[$row["keyword"]] = $row["value"];
00490                         //$arr[$row["keyword"]] = ilUtil::stripSlashes($row["value"]);
00491                 }
00492 
00493                 return $arr;
00494         }
00495 
00505         function setSetting($a_key, $a_val)
00506         {
00507                 $sql = "DELETE FROM settings WHERE keyword='".$a_key."'";
00508                 $r = $this->db->query($sql);
00509 
00510                 $sql = "INSERT INTO settings (keyword, value) VALUES ('".$a_key."','".addslashes($a_val)."')";
00511                 $r = $this->db->query($sql);
00512 
00513                 return true;
00514         }
00515 
00526         /*
00527         function getSkins()
00528         {
00529                 $skins = array();
00530 
00531                 //open directory for reading and search for subdirectories
00532                 //$tplpath = $this->ini->readVariable("server", "tpl_path");
00533                 //$tplpath = "./templates";
00534 
00535                 if ($dp = @opendir($this->tplPath))
00536                 {
00537                         while (($file = readdir($dp)) != false)
00538                         {
00539                                 //is the file a directory?
00540                                 if (is_dir($this->tplPath.$file) && $file != "." && $file != ".." && $file != "CVS")
00541                                 {
00542                                         $skins[] = array(
00543                                                 "name" => $file
00544                                         );
00545                                 }
00546                         } // while
00547                 }
00548                 else
00549                 {
00550                         return false;
00551                 }
00552 
00553                 $this->skins = $skins;
00554 
00555                 return true;
00556         }*/
00557 
00570         /*
00571         function getStyles($a_skin)
00572         {
00573                 $styles = array();
00574 
00575                 //open directory for reading and search for subdirectories
00576                 //$tplpath = $this->ini->readVariable("server", "tpl_path")."/".$skin;
00577                 //$tplpath = "./templates/".$a_skin;
00578 
00579                 if ($dp = @opendir($this->tplPath.$a_skin))
00580                 {
00581                         while (($file = readdir($dp)) != false)
00582                         {
00583                                 //is the file a stylesheet?
00584                                 if (strpos($file, ".css") > 0)
00585                                 {
00586                                         $styles[] = array(
00587                                                                                 "name" => substr($file,0,-4)
00588                                                                         );
00589                                 }
00590                         } // while
00591                 }
00592                 else
00593                 {
00594                         return false;
00595                 }
00596 
00597                 $this->styles = $styles;
00598 
00599                 return true;
00600         }*/
00601 
00608         function getFirstStyle($a_skin)
00609         {
00610                 if (!is_array($this->styles))
00611                 {
00612                         $this->getStyles($a_skin);
00613                 }
00614 
00615                 return $this->styles[0]["name"];
00616         }
00617         
00624         function checkTemplate($a_name)
00625         {
00626                 return file_exists($this->tplPath.$a_name);
00627         }
00628 
00632         function &getCurrentUser()
00633         {
00634                 return $this->account;
00635         }
00636         
00637         function getClientId()
00638         {
00639                 return $this->client_id;
00640         }
00641         
00645         function raiseError($a_msg,$a_err_obj)
00646         {
00647                 global $ilErr;
00648 
00649                 $ilErr->raiseError($a_msg,$a_err_obj);
00650         }
00651 
00652 
00653         function __buildHTTPPath()
00654         {
00655                 if($_SERVER['HTTPS'] == 'on')
00656                 {
00657                         $protocol = 'https://';
00658                 }
00659                 else
00660                 {
00661                         $protocol = 'http://';
00662                 }
00663                 $host = $_SERVER['HTTP_HOST'];
00664 
00665                 if(!defined('ILIAS_MODULE'))
00666                 {
00667                         $path = pathinfo($_SERVER['REQUEST_URI']);
00668                         if(!$path['extension'])
00669                         {
00670                                 $uri = $_SERVER['REQUEST_URI'];
00671                         }
00672                         else
00673                         {
00674                                 $uri = dirname($_SERVER['REQUEST_URI']);
00675                         }
00676                 }
00677                 else
00678                 {
00679                         // if in module remove module name from HTTP_PATH
00680                         $path = dirname($_SERVER['REQUEST_URI']);
00681                         
00682                         // dirname cuts the last directory from a directory path e.g content/classes return content
00683                         
00684                         $module = ilUtil::removeTrailingPathSeparators(ILIAS_MODULE);
00685 
00686                         $dirs = explode('/',$module);
00687                         $uri = $path;
00688                         foreach($dirs as $dir)
00689                         {
00690                                 $uri = dirname($uri);
00691                         }
00692                 }               
00693                 return define('ILIAS_HTTP_PATH',$protocol.$host.$uri);
00694         }
00695 
00696 } // END class.ilias
00697 ?>

Generated on Fri Dec 13 2013 11:57:54 for ILIAS Release_3_6_x_branch .rev 46809 by  doxygen 1.7.1