• 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;
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                 // set anonymous user & role id and system role id
00237                 define ("ANONYMOUS_USER_ID",$this->getSetting("anonymous_user_id"));
00238                 define ("ANONYMOUS_ROLE_ID",$this->getSetting("anonymous_role_id"));
00239                 define ("SYSTEM_USER_ID",$this->getSetting("system_user_id"));
00240                 define ("SYSTEM_ROLE_ID",$this->getSetting("system_role_id"));
00241                 define ("RECOVERY_FOLDER_ID",$this->getSetting("recovery_folder_id"));
00242 
00243                 // installation id
00244                 define ("IL_INST_ID", $this->getSetting("inst_id"));
00245                 
00246                 // auth modes
00247                 define ("AUTH_LOCAL",1);
00248                 define ("AUTH_LDAP",2);
00249                 define ("AUTH_RADIUS",3);
00250                 define ("AUTH_SCRIPT",4);
00251 
00252                 $auth_mode = $this->getSetting("auth_mode");
00253                 
00254                 // set local auth mode (1) in case database wasn't updated
00255                 if ($auth_mode === false)
00256                 {
00257                         $auth_mode = AUTH_LOCAL;
00258                 }
00259                 
00260                 define ("AUTH_CURRENT",$auth_mode);
00261                 
00262                 // set session.save_handler to "user" & set expiry time
00263 
00264                 if(ini_get('session.save_handler') != 'user')
00265                 {
00266                         ini_set("session.save_handler", "user");
00267                 }
00268                 
00269                 switch (AUTH_CURRENT)
00270                 {
00271                         case AUTH_LOCAL:
00272                                 // build option string for PEAR::Auth
00273                                 $this->auth_params = array(
00274                                                                                         'dsn'             => $this->dsn,
00275                                                                                         'table'       => $this->ini->readVariable("auth", "table"),
00276                                                                                         'usernamecol' => $this->ini->readVariable("auth", "usercol"),
00277                                                                                         'passwordcol' => $this->ini->readVariable("auth", "passcol")
00278                                                                                         );
00279                                 // We use MySQL as storage container
00280                                 $this->auth = new Auth("DB", $this->auth_params,"",false);
00281                                 break;
00282                         
00283                         case AUTH_LDAP:
00284                                 $settings = $this->getAllSettings();
00285 
00286                                 // build option string for PEAR::Auth
00287                                 $this->auth_params = array(
00288                                                                                         'host'          => $settings["ldap_server"],
00289                                                                                         'port'          => $settings["ldap_port"],
00290                                                                                         'basedn'        => $settings["ldap_basedn"],
00291                                                                                         'userdn'        => $settings["ldap_search_base"],
00292                                                                                         'useroc'        => $settings["ldap_objectclass"],
00293                                                                                         'userattr'      => $settings["ldap_login_key"]
00294                                                                                         );
00295                                 $this->auth = new Auth("LDAP", $this->auth_params,"",false);
00296 
00297                                 break;
00298                                 
00299                         default:
00300                                 // build option string for PEAR::Auth
00301                                 $this->auth_params = array(
00302                                                                                         'dsn'             => $this->dsn,
00303                                                                                         'table'       => $this->ini->readVariable("auth", "table"),
00304                                                                                         'usernamecol' => $this->ini->readVariable("auth", "usercol"),
00305                                                                                         'passwordcol' => $this->ini->readVariable("auth", "passcol")
00306                                                                                         );
00307                                 // We use MySQL as storage container
00308                                 $this->auth = new Auth("DB", $this->auth_params,"",false);
00309                                 break;
00310 
00311                 }
00312                 
00313                 /*
00314                 ini_set("session.gc_maxlifetime",$this->ini->readVariable("session","expire"));
00315                 ini_set("session.cookie_lifetime",$this->ini->readVariable("session","expire"));
00316                 */
00317                 //ini_set("session.gc_maxlifetime", 10);
00318                 //ini_set("session.cookie_lifetime", 10);
00319 
00320                 $this->auth->setIdle($this->ini->readVariable("session","expire"), false);
00321                 $this->auth->setExpire(0);
00322 
00323                 // Error Handling
00324                 $this->error_obj =& $ilErr;
00325 
00326                 // create instance of object factory
00327                 require_once("classes/class.ilObjectFactory.php");
00328                 $this->obj_factory =& new ilObjectFactory();
00329         }
00330 
00336         function _ILIAS()
00337         {
00338                 if ($this->ini->readVariable("db", "type") != "")
00339                 {
00340                         $this->db->disconnect();
00341                 }
00342                 
00343                 return true;
00344         }
00345 
00352         function getSetting($a_keyword)
00353         {
00354                 if ($a_keyword == "ilias_version")
00355                 {
00356                         return ILIAS_VERSION;
00357                 }
00358                 
00359                 $query = "SELECT value FROM settings WHERE keyword='".$a_keyword."'";
00360                 $res = $this->db->query($query);
00361 
00362                 if ($res->numRows() > 0)
00363                 {
00364                         $row = $res->fetchRow();
00365                         return ilUtil::stripSlashes($row[0]);
00366                 }
00367                 else
00368                 {
00369                         return false;
00370                 }
00371         }
00372         
00379         function deleteSetting($a_keyword)
00380         {
00381                 $query = "DELETE FROM settings WHERE keyword = '".$a_keyword."'";
00382                 $this->db->query($query);
00383 
00384                 return true;
00385         }
00386 
00387 
00393         function getAllSettings()
00394         {
00395                 $query = "SELECT * FROM settings";
00396                 $res = $this->db->query($query);
00397 
00398                 while ($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
00399                 {
00400                         $arr[$row["keyword"]] = ilUtil::stripSlashes($row["value"]);
00401                 }
00402 
00403                 return $arr;
00404         }
00405 
00415         function setSetting($a_key, $a_val)
00416         {
00417                 $sql = "DELETE FROM settings WHERE keyword='".$a_key."'";
00418                 $r = $this->db->query($sql);
00419 
00420                 $sql = "INSERT INTO settings (keyword, value) VALUES ('".$a_key."','".addslashes($a_val)."')";
00421                 $r = $this->db->query($sql);
00422 
00423                 return true;
00424         }
00425 
00436         /*
00437         function getSkins()
00438         {
00439                 $skins = array();
00440 
00441                 //open directory for reading and search for subdirectories
00442                 //$tplpath = $this->ini->readVariable("server", "tpl_path");
00443                 //$tplpath = "./templates";
00444 
00445                 if ($dp = @opendir($this->tplPath))
00446                 {
00447                         while (($file = readdir($dp)) != false)
00448                         {
00449                                 //is the file a directory?
00450                                 if (is_dir($this->tplPath.$file) && $file != "." && $file != ".." && $file != "CVS")
00451                                 {
00452                                         $skins[] = array(
00453                                                 "name" => $file
00454                                         );
00455                                 }
00456                         } // while
00457                 }
00458                 else
00459                 {
00460                         return false;
00461                 }
00462 
00463                 $this->skins = $skins;
00464 
00465                 return true;
00466         }*/
00467 
00480         /*
00481         function getStyles($a_skin)
00482         {
00483                 $styles = array();
00484 
00485                 //open directory for reading and search for subdirectories
00486                 //$tplpath = $this->ini->readVariable("server", "tpl_path")."/".$skin;
00487                 //$tplpath = "./templates/".$a_skin;
00488 
00489                 if ($dp = @opendir($this->tplPath.$a_skin))
00490                 {
00491                         while (($file = readdir($dp)) != false)
00492                         {
00493                                 //is the file a stylesheet?
00494                                 if (strpos($file, ".css") > 0)
00495                                 {
00496                                         $styles[] = array(
00497                                                                                 "name" => substr($file,0,-4)
00498                                                                         );
00499                                 }
00500                         } // while
00501                 }
00502                 else
00503                 {
00504                         return false;
00505                 }
00506 
00507                 $this->styles = $styles;
00508 
00509                 return true;
00510         }*/
00511 
00518         function getFirstStyle($a_skin)
00519         {
00520                 if (!is_array($this->styles))
00521                 {
00522                         $this->getStyles($a_skin);
00523                 }
00524 
00525                 return $this->styles[0]["name"];
00526         }
00527         
00534         function checkTemplate($a_name)
00535         {
00536                 return file_exists($this->tplPath.$a_name);
00537         }
00538 
00542         function &getCurrentUser()
00543         {
00544                 return $this->account;
00545         }
00546         
00547         function getClientId()
00548         {
00549                 return $this->client_id;
00550         }
00551         
00555         function raiseError($a_msg,$a_err_obj)
00556         {
00557                 global $ilErr;
00558 
00559                 $ilErr->raiseError($a_msg,$a_err_obj);
00560         }
00561 
00562 } // END class.ilias
00563 ?>

Generated on Fri Dec 13 2013 08:00:14 for ILIAS Release_3_3_x_branch .rev 46803 by  doxygen 1.7.1