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

classes/class.ilUtil.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 
00034 class ilUtil
00035 {
00043         function getImageTagByType($a_type, $a_path, $a_big = false)
00044         {
00045                 global $lng;
00046 
00047                 if ($a_big)
00048                 {
00049                         $big = "_b";
00050                 }
00051                 $filename = "icon_".$a_type."$big.gif";
00052 
00053                 return "<img src=\"".ilUtil::getImagePath($filename)."\" alt=\"".$lng->txt("obj_".$a_type)."\" title=\"".$lng->txt("obj_".$a_type)."\" border=\"0\" vspace=\"0\"/>";
00054                 //return "<img src=\"".$a_path."/images/"."icon_".$a_type."$big.gif\" alt=\"".$lng->txt("obj_".$a_type)."\" title=\"".$lng->txt("obj_".$a_type)."\" border=\"0\" vspace=\"0\"/>";
00055         }
00056 
00065         function getImagePath($img, $in_module = false, $mode = "output", $offline = false)
00066         {
00067                 global $ilias, $styleDefinition, $ilCtrl;
00068 
00069                 if(defined("ILIAS_MODULE") and $mode != "filesystem")
00070                 {
00071                         // added to find path for MODULES like Services/Search
00072                         $base = '';
00073                         for($i = 1;$i < count(explode('/',ILIAS_MODULE));$i++)
00074                         {
00075                                 $base .= "../";
00076                         }
00077 
00078                         $dir .= ($base.".");
00079                         // hschottm: added because module images are not working
00080                         // using ilias.php
00081 //                      if (strlen($base) == 0) $dir = "";
00082                 }
00083                 else
00084                 {
00085                         $dir = "";
00086                 }
00087                 $base = "./";
00088                 if ($in_module)
00089                 {
00090                         // if baseClass functionality is used (ilias.php):
00091                         // get template directory from ilCtrl
00092                         if (!empty($_GET["baseClass"]))
00093                         {
00094                                 $base.= $ilCtrl->getModuleDir()."/";
00095                         }
00096                         else
00097                         {
00098                                 if(defined("ILIAS_MODULE"))
00099                                 {
00100                                         $base.= ILIAS_MODULE."/";
00101                                 }
00102                         }
00103                 }
00104                 $base .= "templates/";
00105                 if (is_object($styleDefinition))
00106                 {
00107 
00108                         $st_image_dir = $styleDefinition->getImageDirectory($ilias->account->prefs["style"]);
00109                         #var_dump("<pre>",$st_image_dir,$ilias->account->prefs["style"],"<pre>");
00110 
00111                         $user_skin_and_style = $base.$ilias->account->skin."/".
00112                         $st_image_dir.
00113                         "/images/".$img;
00114                 }
00115                 $user_skin = $base.$ilias->account->skin."/images/".$img;
00116                 $default = $base."default/images/".$img;
00117                 if ($offline)
00118                 {
00119                         return "./images/".$img;
00120                 }
00121                 else if (@file_exists($user_skin_and_style) && $st_image_dir != "")
00122                 {
00123                         return $dir.$user_skin_and_style;
00124                 }
00125                 else if (file_exists($user_skin))
00126                 {
00127                         return $dir.$user_skin;
00128                 }
00129 
00130                 return $dir.$default;
00131         }
00132 
00141     function getHtmlPath($relative_path)
00142     {
00143         if (substr($relative_path, 0, 2) == './')
00144         {
00145             $relative_path = (substr($relative_path, 1));
00146         }
00147         if (substr($relative_path, 0, 1) != '/')
00148         {
00149             $relative_path = '/' . $relative_path;
00150         }
00151         $htmlpath = ILIAS_HTTP_PATH . $relative_path;
00152         return $htmlpath;
00153     }
00154 
00155         function getJSPath($a_js)
00156         {
00157                 global $ilias;
00158 
00159                 if(defined("ILIAS_MODULE"))
00160                 {
00161                         $dir = ".";
00162                 }
00163                 else
00164                 {
00165                         $dir = "";
00166                 }
00167                 $in_style = "./templates/".$ilias->account->skin."/".$ilias->account->prefs["style"]."/".$a_js;
00168                 $default = "./templates/".$ilias->account->skin."/".$a_js;
00169                 if(@is_file($in_style))
00170                 {
00171                         return $dir.$in_style;
00172                 }
00173                 else
00174                 {
00175                         return $dir.$default;
00176                 }
00177         }
00178 
00184         function getStyleSheetLocation($mode = "output")
00185         {
00186                 global $ilias;
00187 
00188                 if(defined("ILIAS_MODULE") && $mode != "filesystem")
00189                 {
00190                         // added to find Stylesheet for MODULES like Services/Search
00191                         $base = '';
00192                         for($i = 0;$i < count(explode('/',ILIAS_MODULE));$i++)
00193                         {
00194                                 $base .= "../";
00195                         }
00196                 }
00197                 else
00198                 {
00199                         $base = "./";
00200                 }
00201                 
00202                 // add version as parameter to force reload for new releases
00203                 if ($mode != "filesystem")
00204                 {
00205                         $vers = str_replace(" ", "-", $ilias->getSetting("ilias_version"));
00206                         $vers = "?vers=".str_replace(".", "-", $vers);
00207                 }
00208                                 
00209                 return $base."templates/".$ilias->account->skin."/".$ilias->account->prefs["style"].".css".$vers;
00210         }
00211 
00224         function formSelect ($selected,$varname,$options,$multiple = false,$direct_text = false, $size = "0")
00225         {
00226                 global $lng;
00227 
00228                 if ($multiple == true)
00229                 {
00230                         $multiple = " multiple=\"multiple\"";
00231                 }
00232                 else
00233                 {
00234                         $multiple = "";
00235                         $size = 0;
00236                 }
00237 
00238                 $str = "<select name=\"".$varname ."\"".$multiple." size=\"".$size."\">\n";
00239 
00240                 foreach ($options as $key => $val)
00241                 {
00242                         if ($direct_text)
00243                         {
00244                                 $str .= " <option value=\"".$key."\"";
00245                         }
00246                         else
00247                         {
00248                                 $str .= " <option value=\"".$val."\"";
00249                         }
00250                         if (is_array($selected) )
00251                         {
00252                                 if (in_array($key,$selected))
00253                                 {
00254                                         $str .= " selected=\"selected\"";
00255                                 }
00256                         }
00257                         else if ($selected == $key)
00258                         {
00259                                 $str .= " selected=\"selected\"";
00260                         }
00261 
00262                         if ($direct_text)
00263                         {
00264                                 $str .= ">".$val."</option>\n";
00265                         }
00266                         else
00267                         {
00268                                 $str .= ">".$lng->txt($val)."</option>\n";
00269                         }
00270                 }
00271 
00272                 $str .= "</select>\n";
00273 
00274                 return $str;
00275         }
00276 
00284         function getSelectName ($selected,$values)
00285         {
00286                 return($values[$selected]);
00287         }
00288 
00298         function formCheckbox ($checked,$varname,$value,$disabled = false)
00299         {
00300                 $str = "<input type=\"checkbox\" name=\"".$varname."\"";
00301 
00302                 if ($checked == 1)
00303                 {
00304                         $str .= " checked=\"checked\"";
00305                 }
00306 
00307                 if ($disabled)
00308                 {
00309                         $str .= " disabled=\"disabled\"";
00310                 }
00311 
00312                 $array_var = false;
00313 
00314                 if (substr($varname,-2) == "[]")
00315                 {
00316                         $array_var = true;
00317                 }
00318 
00319                 // if varname ends with [], use varname[-2] + _ + value as id tag (e.g. "user_id[]" => "user_id_15")
00320                 if ($array_var)
00321                 {
00322                         $varname_id = substr($varname,0,-2)."_".$value;
00323                 }
00324                 else
00325                 {
00326                         $varname_id = $varname;
00327                 }
00328 
00329                 // dirty removal of other "[]" in string
00330                 $varname_id = ereg_replace("\[","_",$varname_id);
00331                 $varname_id = ereg_replace("\]","",$varname_id);
00332 
00333                 $str .= " value=\"".$value."\" id=\"".$varname_id."\" />\n";
00334 
00335                 return $str;
00336         }
00337 
00347         function formDisabledRadioButton($checked,$varname,$value,$disabled)
00348           {
00349             if ($disabled) {
00350               $str = "<input disabled type=\"radio\" name=\"".$varname."\"";
00351             }
00352             else {
00353               $str = "<input type=\"radio\" name=\"".$varname."\"";
00354             }
00355             if ($checked == 1)
00356               {
00357                 $str .= " checked=\"checked\"";
00358               }
00359 
00360             $str .= " value=\"".$value."\"";
00361             $str .= " id=\"".$value."\" />\n";
00362 
00363             return $str;
00364 
00365           }
00366 
00367 
00376         function formRadioButton($checked,$varname,$value)
00377         {
00378                 $str = "<input type=\"radio\" name=\"".$varname."\"";
00379                 if ($checked == 1)
00380                 {
00381                         $str .= " checked=\"checked\"";
00382                 }
00383 
00384                 $str .= " value=\"".$value."\"";
00385 
00386                 $str .= " id=\"".$value."\" />\n";
00387 
00388                 return $str;
00389         }
00390 
00395         function checkInput ($vars)
00396         {
00397                 // TO DO:
00398                 // Diese Funktion soll Formfeldeingaben berprfen (empty und required)
00399         }
00400 
00406         function setPathStr ($a_path)
00407         {
00408                 if ("" != $a_path && "/" != substr($a_path, -1))
00409                 {
00410                         $a_path .= "/";
00411                         //$a_path = substr($a_path,1);
00412                 }
00413 
00414                 //return getcwd().$a_path;
00415                 return $a_path;
00416         }
00417 
00428         function switchColor ($a_num,$a_css1,$a_css2)
00429         {
00430                 if (!($a_num % 2))
00431                 {
00432                         return $a_css1;
00433                 }
00434                 else
00435                 {
00436                         return $a_css2;
00437                 }
00438         }
00439 
00449         function showTabs($a_hl, $a_o)
00450         {
00451                 global $lng;
00452 
00453                 $tpltab = new ilTemplate("tpl.tabs.html", true, true);
00454 
00455                 for ($i=1; $i<=4; $i++)
00456                 {
00457                         $tpltab->setCurrentBlock("tab");
00458                         if ($a_hl == $i)
00459                         {
00460                                 $tabtype = "tabactive";
00461                                 $tab = $tabtype;
00462                         }
00463                         else
00464                         {
00465                                 $tabtype = "tabinactive";
00466                                 $tab = "tab";
00467                         }
00468 
00469                         switch ($i)
00470                         {
00471                                 case 1:
00472                                 $txt = $lng->txt("view_content");
00473                                 break;
00474                                 case 2:
00475                                 $txt = $lng->txt("edit_properties");
00476                                 break;
00477                                 case 3:
00478                                 $txt = $lng->txt("perm_settings");
00479                                 break;
00480                                 case 4:
00481                                 $txt = $lng->txt("show_owner");
00482                                 break;
00483                         } // switch
00484                         $tpltab->setVariable("CONTENT", $txt);
00485                         $tpltab->setVariable("TABTYPE", $tabtype);
00486                         $tpltab->setVariable("TAB", $tab);
00487                         $tpltab->setVariable("LINK", $a_o["LINK".$i]);
00488                         $tpltab->parseCurrentBlock();
00489                 }
00490 
00491                 return $tpltab->get();
00492         }
00493 
00494 
00495 
00502         function checkFormEmpty ($emptyFields)
00503         {
00504 
00505                 $feedback = "";
00506 
00507                 foreach ($emptyFields as $key => $val)
00508                 {
00509                         if ($val == "") {
00510                                 if ($feedback != "") $feedback .= ", ";
00511                                 $feedback .= $key;
00512                         }
00513                 }
00514 
00515                 return $feedback;
00516         }
00517 
00540         function Linkbar ($AScript,$AHits,$ALimit,$AOffset,$AParams = array(),$ALayout = array())
00541         {
00542                 $LinkBar = "";
00543 
00544                 $layout_link = "";
00545                 $layout_prev = "&lt;&lt;";
00546                 $layout_next = "&gt;&gt;";
00547 
00548                 // layout options
00549                 if (count($ALayout > 0))
00550                 {
00551                         if ($ALayout["link"])
00552                         {
00553                                 $layout_link = " class=\"".$ALayout["link"]."\"";
00554                         }
00555 
00556                         if ($ALayout["prev"])
00557                         {
00558                                 $layout_prev = $ALayout["prev"];
00559                         }
00560 
00561                         if ($ALayout["next"])
00562                         {
00563                                 $layout_next = $ALayout["next"];
00564                         }
00565                 }
00566 
00567                 // Wenn Hits gr?sser Limit, zeige Links an
00568                 if ($AHits > $ALimit)
00569                 {
00570                         if (!empty($AParams))
00571                         {
00572                                 foreach ($AParams as $key => $value)
00573                                 {
00574                                         $params.= $key."=".$value."&";
00575                                 }
00576                         }
00577                         // if ($params) $params = substr($params,0,-1);
00578                         if(strpos($AScript,'&'))
00579                         {
00580                                 $link = $AScript."&".$params."offset=";
00581                         }
00582                         else
00583                         {
00584                                 $link = $AScript."?".$params."offset=";
00585                         }                               
00586 
00587                         // ?bergehe "zurck"-link, wenn offset 0 ist.
00588                         if ($AOffset >= 1)
00589                         {
00590                                 $prevoffset = $AOffset - $ALimit;
00591                                 $LinkBar .= "<a".$layout_link." href=\"".$link.$prevoffset."\">".$layout_prev."&nbsp;</a>";
00592                         }
00593 
00594                         // Ben?tigte Seitenzahl kalkulieren
00595                         $pages=intval($AHits/$ALimit);
00596 
00597                         // Wenn ein Rest bleibt, addiere eine Seite
00598                         if (($AHits % $ALimit))
00599                         $pages++;
00600 
00601                         // Bei Offset = 0 keine Seitenzahlen anzeigen : DEAKTIVIERT
00602                         //                      if ($AOffset != 0) {
00603 
00604                         // ansonsten zeige Links zu den anderen Seiten an
00605                         for ($i = 1 ;$i <= $pages ; $i++)
00606                         {
00607                                 $newoffset=$ALimit*($i-1);
00608 
00609                                 if ($newoffset == $AOffset)
00610                                 {
00611                                         $LinkBar .= "<font color='Gray'>[<b>".$i."</b>]</font> ";
00612                                 }
00613                                 else
00614                                 {
00615                                         $LinkBar .= "[<a".$layout_link." href=\"".$link.$newoffset."\">$i</a>] ";
00616                                 }
00617                         }
00618                         //                      }
00619 
00620                         // Checken, ob letze Seite erreicht ist
00621                         // Wenn nicht, gebe einen "Weiter"-Link aus
00622                         if (! ( ($AOffset/$ALimit)==($pages-1) ) && ($pages!=1) )
00623                         {
00624                                 $newoffset=$AOffset+$ALimit;
00625                                 $LinkBar .= "<a".$layout_link." href=\"".$link.$newoffset."\">&nbsp;".$layout_next."</a>";
00626                         }
00627 
00628                         return $LinkBar;
00629                 }
00630                 else
00631                 {
00632                         return false;
00633                 }
00634         }
00635 
00644         function makeClickable($a_text)
00645         {
00646                 // URL mit ://-Angabe
00647                 $ret = eregi_replace("([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=-])",
00648                 "<a href=\"\\1://\\2\\3\" target=\"_blank\">\\1://\\2\\3</a>", $a_text);
00649 
00650                 // www-URL ohne ://-Angabe
00651                 $ret = eregi_replace("([[:space:]]+)(www\.)([[:alnum:]#?/&=\.-]+)",
00652                 "\\1<a href=\"http://\\2\\3\" target=\"_blank\">\\2\\3</a>", $ret);
00653 
00654                 // ftp-URL ohne ://-Angabe
00655                 $ret = eregi_replace("([[:space:]]+)(ftp\.)([[:alnum:]#?/&=\.-]+)",
00656                 "\\1<a href=\"ftp://\\2\\3\" target=\"_blank\">\\2\\3</a>", $ret);
00657 
00658                 // E-Mail
00659                 $ret = eregi_replace("(([a-z0-9_]|\\-|\\.)+@([^[:space:]]*)([[:alnum:]-]))",
00660                 "<a  href=\"mailto:\\1\">\\1</a>", $ret);
00661 
00662                 return($ret);
00663         }
00664 
00681         function StopWatch($begin = -1)
00682         {
00683                 $m = explode(" ",microtime());
00684                 $m = $m[0] + $m[1];
00685 
00686                 if ($begin != -1)
00687                 {
00688                         $m = $m - $begin;
00689                 }
00690 
00691                 return($m);
00692         }
00693 
00710         function makeDateSelect($prefix, $year = "", $month = "", $day = "", $startyear = "")
00711         {
00712                 global $lng;
00713 
00714                 if (!strlen("$year$month$day")) {
00715                         $now = getdate();
00716                         $year = $now["year"];
00717                         $month = $now["mon"];
00718                         $day = $now["mday"];
00719                 } else {
00720                         // delete leading zeros
00721                         $year = (int)$year;
00722                         $month = (int)$month;
00723                         $day = (int)$day;
00724                 }
00725 
00726                 // build day select
00727                 $sel_day .= "<select name=\"".$prefix."[d]\" id=\"".$prefix."_d\">\n";
00728 
00729                 for ($i = 1; $i <= 31; $i++)
00730                 {
00731                         $sel_day .= "<option value=\"$i\">" . sprintf("%02d", $i) . "</option>\n";
00732                 }
00733                 $sel_day .= "</select>\n";
00734                 $sel_day = preg_replace("/(value\=\"$day\")/", "$1 selected=\"selected\"", $sel_day);
00735 
00736                 // build month select
00737                 $sel_month .= "<select name=\"".$prefix."[m]\" id=\"".$prefix."_m\">\n";
00738 
00739                 for ($i = 1; $i <= 12; $i++)
00740                 {
00741                         $sel_month .= "<option value=\"$i\">" . $lng->txt("month_" . sprintf("%02d", $i) . "_long") . "</option>\n";
00742                 }
00743                 $sel_month .= "</select>\n";
00744                 $sel_month = preg_replace("/(value\=\"$month\")/", "$1 selected=\"selected\"", $sel_month);
00745 
00746                 // build year select
00747                 $sel_year .= "<select name=\"".$prefix."[y]\" id=\"".$prefix."_y\">\n";
00748                 if ((strlen($startyear) == 0) || ($startyear > $year))
00749                 {
00750                         $startyear = $year;
00751                 }
00752                 for ($i = $startyear; $i <= $year + 3; $i++)
00753                 {
00754                         $sel_year .= "<option value=\"$i\">" . sprintf("%04d", $i) . "</option>\n";
00755                 }
00756                 $sel_year .= "</select>\n";
00757                 $sel_year = preg_replace("/(value\=\"$year\")/", "$1 selected=\"selected\"", $sel_year);
00758 
00759                 $dateformat = $lng->text["lang_dateformat"];
00760                 $dateformat = strtolower(preg_replace("/\W/", "", $dateformat));
00761                 $dateformat = strtolower(preg_replace("/(\w)/", "%%$1", $dateformat));
00762                 $dateformat = preg_replace("/%%d/", $sel_day, $dateformat);
00763                 $dateformat = preg_replace("/%%m/", $sel_month, $dateformat);
00764                 $dateformat = preg_replace("/%%y/", $sel_year, $dateformat);
00765                 return $dateformat;
00766         }
00767 
00784         function makeTimeSelect($prefix, $short = true, $hour = "", $minute = "", $second = "",$a_use_default = true)
00785         {
00786                 global $lng;
00787 
00788                 if ($a_use_default and !strlen("$hour$minute$second")) {
00789                         $now = localtime();
00790                         $hour = $now[2];
00791                         $minute = $now[1];
00792                         $second = $now[0];
00793                 } else {
00794                         $hour = (int)$hour;
00795                         $minute = (int)$minute;
00796                         $second = (int)$second;
00797                 }
00798                 // build hour select
00799                 $sel_hour .= "<select name=\"".$prefix."[h]\" id=\"".$prefix."_h\">\n";
00800 
00801                 for ($i = 0; $i <= 23; $i++)
00802                 {
00803                         $sel_hour .= "<option value=\"$i\">" . sprintf("%02d", $i) . "</option>\n";
00804                 }
00805                 $sel_hour .= "</select>\n";
00806                 $sel_hour = preg_replace("/(value\=\"$hour\")/", "$1 selected=\"selected\"", $sel_hour);
00807 
00808                 // build minutes select
00809                 $sel_minute .= "<select name=\"".$prefix."[m]\" id=\"".$prefix."_m\">\n";
00810 
00811                 for ($i = 0; $i <= 59; $i++)
00812                 {
00813                         $sel_minute .= "<option value=\"$i\">" . sprintf("%02d", $i) . "</option>\n";
00814                 }
00815                 $sel_minute .= "</select>\n";
00816                 $sel_minute = preg_replace("/(value\=\"$minute\")/", "$1 selected=\"selected\"", $sel_minute);
00817 
00818                 if (!$short) {
00819                         // build seconds select
00820                         $sel_second .= "<select name=\"".$prefix."[s]\" id=\"".$prefix."_s\">\n";
00821 
00822                         for ($i = 0; $i <= 59; $i++)
00823                         {
00824                                 $sel_second .= "<option value=\"$i\">" . sprintf("%02d", $i) . "</option>\n";
00825                         }
00826                         $sel_second .= "</select>\n";
00827                         $sel_second = preg_replace("/(value\=\"$second\")/", "$1 selected=\"selected\"", $sel_second);
00828                 }
00829                 $timeformat = $lng->text["lang_timeformat"];
00830                 $timeformat = strtolower(preg_replace("/\W/", "", $timeformat));
00831                 $timeformat = preg_replace("/(\w)/", "%%$1", $timeformat);
00832                 $timeformat = preg_replace("/%%h/", $sel_hour, $timeformat);
00833                 $timeformat = preg_replace("/%%i/", $sel_minute, $timeformat);
00834                 if ($short) {
00835                         $timeformat = preg_replace("/%%s/", "", $timeformat);
00836                 } else {
00837                         $timeformat = preg_replace("/%%s/", $sel_second, $timeformat);
00838                 }
00839                 return $timeformat;
00840         }
00841 
00842         /*
00843         * This preg-based function checks whether an e-mail address is formally valid.
00844         * It works with all top level domains including the new ones (.biz, .info, .museum etc.)
00845         * and the special ones (.arpa, .int etc.)
00846         * as well as with e-mail addresses based on IPs (e.g. webmaster@123.45.123.45)
00847         * @author       Unknown <mail@philipp-louis.de> (source: http://www.php.net/preg_match)
00848         * @access       public
00849         * @param        string  email address
00850         * @return       boolean true if valid
00851         */
00852         function is_email($a_email)
00853         {
00854                 return(preg_match("/^[-_.[:alnum:]]+@((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i",$a_email));
00855         }
00856 
00857         /*
00858         * validates a password
00859         * @access       public
00860         * @param        string  password
00861         * @return       boolean true if valid
00862         */
00863         function isPassword($a_passwd)
00864         {
00865                 if (empty($a_passwd))
00866                 {
00867                         return false;
00868                 }
00869 
00870                 if (strlen($a_passwd) < 6)
00871                 {
00872                         return false;
00873                 }
00874                 // due to bug in php does not work
00875                 //if (!ereg("^[A-Za-z0-9_\.\+\-\*\@!\$\%\~]+$", $a_passwd))
00876 
00877                 if (!preg_match("/^[A-Za-z0-9_\.\+\?\#\-\*\@!\$\%\~]+$/", $a_passwd))
00878                 {
00879                         return false;
00880                 }
00881 
00882                 return true;
00883         }
00884 
00885         /*
00886         * validates a login
00887         * @access       public
00888         * @param        string  login
00889         * @return       boolean true if valid
00890         */
00891         function isLogin($a_login)
00892         {
00893                 if (empty($a_login))
00894                 {
00895                         return false;
00896                 }
00897 
00898                 if (strlen($a_login) < 4)
00899                 {
00900                         return false;
00901                 }
00902 
00903                 if (!ereg("^[A-Za-z0-9_\.\+-\*\@!\$\%\~]+$", $a_login))
00904                 {
00905                         return false;
00906                 }
00907 
00908                 return true;
00909         }
00910 
00922         function shortenText ($a_str, $a_len, $a_dots = false, $a_next_blank = false)
00923         {
00924                 include_once("./classes/class.ilStr.php");
00925                 if (ilStr::strLen($a_str) > $a_len)
00926                 {
00927                         if ($a_next_blank)
00928                         {
00929                                 $len = ilStr::strPos($a_str, " ", $a_len);
00930                         }
00931                         else
00932                         {
00933                                 $len = $a_len;
00934                         }
00935                         $a_str = ilStr::subStr($a_str,0,$len);
00936 
00937                         if ($a_dots)
00938                         {
00939                                 $a_str .= "...";
00940                         }
00941                 }
00942 
00943                 return $a_str;
00944         }
00945 
00953         function attribsToArray($a_str)
00954         {
00955                 $attribs = array();
00956                 while (is_int(strpos($a_str, "=")))
00957                 {
00958                         $eq_pos = strpos($a_str, "=");
00959                         $qu1_pos = strpos($a_str, "\"");
00960                         $qu2_pos = strpos(substr($a_str, $qu1_pos + 1), "\"") + $qu1_pos + 1;
00961                         if (is_int($eq_pos) && is_int($qu1_pos) && is_int($qu2_pos))
00962                         {
00963                                 $var = trim(substr($a_str, 0, $eq_pos));
00964                                 $val = trim(substr($a_str, $qu1_pos + 1, ($qu2_pos - $qu1_pos) - 1));
00965                                 $attribs[$var] = $val;
00966                                 $a_str = substr($a_str, $qu2_pos + 1);
00967                         }
00968                         else
00969                         {
00970                                 $a_str = "";
00971                         }
00972                 }
00973                 return $attribs;
00974         }
00975 
00984         function rCopy ($a_sdir, $a_tdir)
00985         {
00986                 // check if arguments are directories
00987                 if (!@is_dir($a_sdir) or
00988                 !@is_dir($a_tdir))
00989                 {
00990                         return FALSE;
00991                 }
00992 
00993                 // read a_sdir, copy files and copy directories recursively
00994                 $dir = opendir($a_sdir);
00995 
00996                 while($file = readdir($dir))
00997                 {
00998                         if ($file != "." and
00999                         $file != "..")
01000                         {
01001                                 // directories
01002                                 if (@is_dir($a_sdir."/".$file))
01003                                 {
01004                                         if (!@is_dir($a_tdir."/".$file))
01005                                         {
01006                                                 if (!ilUtil::makeDir($a_tdir."/".$file))
01007                                                 return FALSE;
01008 
01009                                                 //chmod($a_tdir."/".$file, 0775);
01010                                         }
01011 
01012                                         if (!ilUtil::rCopy($a_sdir."/".$file,$a_tdir."/".$file))
01013                                         {
01014                                                 return FALSE;
01015                                         }
01016                                 }
01017 
01018                                 // files
01019                                 if (@is_file($a_sdir."/".$file))
01020                                 {
01021                                         if (!copy($a_sdir."/".$file,$a_tdir."/".$file))
01022                                         {
01023                                                 return FALSE;
01024                                         }
01025                                 }
01026                         }
01027                 }
01028                 return TRUE;
01029         }
01030 
01038         function getWebspaceDir($mode = "filesystem")
01039         {
01040                 global $ilias;
01041 
01042                 if ($mode == "filesystem")
01043                 {
01044                         return "./".ILIAS_WEB_DIR."/".$ilias->client_id;
01045                 }
01046                 else
01047                 {
01048                         if (defined("ILIAS_MODULE"))
01049                         {
01050                                 return "../".ILIAS_WEB_DIR."/".$ilias->client_id;
01051                         }
01052                         else
01053                         {
01054                                 return "./".ILIAS_WEB_DIR."/".$ilias->client_id;
01055                         }
01056                 }
01057 
01058                 //return $ilias->ini->readVariable("server","webspace_dir");
01059         }
01060 
01064         function getDataDir()
01065         {
01066                 return CLIENT_DATA_DIR;
01067                 //global $ilias;
01068 
01069                 //return $ilias->ini->readVariable("server", "data_dir");
01070         }
01071 
01079         function getUsersOnline($a_user_id = 0)
01080         {
01081                 global $ilias;
01082 
01083                 if ($a_user_id == 0)
01084                 {
01085                         $where = "WHERE user_id != 0";
01086                 }
01087                 else
01088                 {
01089                         $where = "WHERE user_id = '".$a_user_id."'";
01090                 }
01091 
01092                 $q = "SELECT count(user_id) as num,user_id,data,firstname,lastname,title,login,last_login FROM usr_session ".
01093                 "LEFT JOIN usr_data ON user_id=usr_id ".$where.
01094                 " AND expires>UNIX_TIMESTAMP() ".
01095                 "GROUP BY user_id ".
01096                 "ORDER BY lastname, firstname";
01097                 $r = $ilias->db->query($q);
01098 
01099                 while ($user = $r->fetchRow(DB_FETCHMODE_ASSOC))
01100                 {
01101                         $users[$user["user_id"]] = $user;
01102                 }
01103 
01104                 return $users ? $users : array();
01105         }
01106 
01115         function getAssociatedUsersOnline($a_user_id)
01116         {
01117                 global $ilias;
01118 
01119                 // The difference between active time and session time
01120                 $time_diff = 0;
01121 
01122                 // Get a list of object id's of all courses and groups for which
01123                 // the current user has local roles.
01124                 // Note: we have to use DISTINCT here, because a user may assume
01125                 // multiple roles in a group or a course.
01126                 $q = "SELECT DISTINCT dat.obj_id as obj_id ".
01127                 "FROM rbac_ua AS ua ".
01128                 "JOIN rbac_fa AS fa ON fa.rol_id = ua.rol_id ".
01129                 "JOIN object_reference AS r1 ON r1.ref_id = fa.parent ".
01130                 "JOIN tree ON tree.child = r1.ref_id ".
01131                 "JOIN object_reference AS r2 ON r2.ref_id = tree.parent ".
01132                 "JOIN object_data AS dat ON dat.obj_id = r2.obj_id ".
01133                 "WHERE ua.usr_id = ".$a_user_id." ".
01134                 "AND fa.assign = 'y' ".
01135                 "AND dat.type IN ('grp','crs')";
01136                 $r = $ilias->db->query($q);
01137                 while ($row = $r->fetchRow(DB_FETCHMODE_ASSOC))
01138                 {
01139                         $groups_and_courses_of_user[] = $row["obj_id"];
01140                 }
01141 
01142                 // If the user is not in a course or a group, he has no associated users.
01143                 if (count($groups_and_courses_of_user) == 0)
01144                 {
01145                         $q = "SELECT count(user_id) as num,user_id,data,firstname,lastname,title,login,last_login ".
01146                         "FROM usr_session ".
01147                         "JOIN usr_data ON user_id=usr_id ".
01148                         "WHERE user_id = ".$a_user_id." ".
01149                         "AND expires > UNIX_TIMESTAMP() - ".$time_diff." ".
01150                         "GROUP BY user_id";
01151                 }
01152                 else
01153                 {
01154                         $q = "SELECT count(user_id) as num,s.user_id,s.data,ud.firstname,ud.lastname,ud.title,ud.login,ud.last_login ".
01155                         "FROM usr_session AS s ".
01156                         "JOIN usr_data AS ud ON ud.usr_id = s.user_id ".
01157                         "JOIN rbac_ua AS ua ON ua.usr_id = s.user_id ".
01158                         "JOIN rbac_fa AS fa ON fa.rol_id = ua.rol_id ".
01159                         "JOIN tree ON tree.child = fa.parent ".
01160                         "JOIN object_reference AS or1 ON or1.ref_id = tree.parent ".
01161                         "JOIN object_data AS od ON od.obj_id = or1.obj_id ".
01162                         "WHERE s.user_id != 0 ".
01163                         "AND s.expires > UNIX_TIMESTAMP() - ".$time_diff." ".
01164                         "AND fa.assign = 'y' ".
01165                         "AND od.obj_id IN (".implode(",",$groups_and_courses_of_user).") ".
01166                         "GROUP BY s.user_id ".
01167                         "ORDER BY ud.lastname, ud.firstname";
01168                 }
01169                 $r = $ilias->db->query($q);
01170 
01171                 while ($user = $r->fetchRow(DB_FETCHMODE_ASSOC))
01172                 {
01173                         $users[$user["user_id"]] = $user;
01174                 }
01175 
01176                 return $users ? $users : array();
01177         }
01178 
01184         function ilTempnam()
01185         {
01186                 $temp_path = ilUtil::getDataDir() . "/temp";
01187                 if (!is_dir($temp_path))
01188                 {
01189                         ilUtil::createDirectory($temp_path);
01190                 }
01191                 $temp_name = tempnam($temp_path, "tmp");
01192                 // --->
01193                 // added the following line because tempnam creates a backslash on some
01194                 // Windows systems which leads to problems, because the "...\tmp..." can be
01195                 // interpreted as "...{TAB-CHARACTER}...". The normal slash works fine
01196                 // even under windows (Helmut Schottmüller, 2005-08-31)
01197                 $temp_name = str_replace("\\", "/", $temp_name);
01198                 // --->
01199                 unlink($temp_name);
01200                 return $temp_name;
01201         }
01202 
01208         function createDirectory($a_dir, $a_mod = 0755)
01209         {
01210                 ilUtil::makeDir($a_dir);
01211                 //@mkdir($a_dir);
01212                 //@chmod($a_dir, $a_mod);
01213         }
01214 
01215 
01222         function unzip($a_file, $overwrite = false)
01223         {
01224                 //global $ilias;
01225 
01226                 $pathinfo = pathinfo($a_file);
01227                 $dir = $pathinfo["dirname"];
01228                 $file = $pathinfo["basename"];
01229 
01230                 // unzip
01231                 $cdir = getcwd();
01232                 chdir($dir);
01233                 $unzip = PATH_TO_UNZIP;
01234                 //$unzip = $ilias->getSetting("unzip_path");
01235 
01236                 // workaround for unzip problem (unzip of subdirectories fails, so
01237                 // we create the subdirectories ourselves first)
01238                 // get list
01239                 $unzipcmd = $unzip." -Z -1 ".ilUtil::escapeShellArg($file);
01240                 exec($unzipcmd, $arr);
01241                 $zdirs = array();
01242 
01243                 foreach($arr as $line)
01244                 {
01245                         if(is_int(strpos($line, "/")))
01246                         {
01247                                 $zdir = substr($line, 0, strrpos($line, "/"));
01248                                 $nr = substr_count($zdir, "/");
01249                                 //echo $zdir." ".$nr."<br>";
01250                                 while ($zdir != "")
01251                                 {
01252                                         $nr = substr_count($zdir, "/");
01253                                         $zdirs[$zdir] = $nr;                            // collect directories
01254                                         //echo $dir." ".$nr."<br>";
01255                                         $zdir = substr($zdir, 0, strrpos($zdir, "/"));
01256                                 }
01257                         }
01258                 }
01259 
01260                 asort($zdirs);
01261 
01262                 foreach($zdirs as $zdir => $nr)                         // create directories
01263                 {
01264                         ilUtil::createDirectory($zdir);
01265                 }
01266 
01267                 // real unzip
01268                 if ($overvwrite)
01269                 {
01270                         $unzipcmd = $unzip." ".ilUtil::escapeShellArg($file);
01271                 }
01272                 else
01273                 {
01274                         $unzipcmd = $unzip." -o ".ilUtil::escapeShellArg($file);
01275                 }
01276                 exec($unzipcmd);
01277 
01278                 chdir($cdir);
01279         }
01280 
01284         function zip($a_dir, $a_file)
01285         {
01286                 //global $ilias;
01287 
01288                 $cdir = getcwd();
01289 
01290                 $pathinfo = pathinfo($a_file);
01291                 $dir = $pathinfo["dirname"];
01292                 $file = $pathinfo["basename"];
01293 
01294                 // unzip
01295                 $cdir = getcwd();
01296                 chdir($dir);
01297 
01298                 $zip = PATH_TO_ZIP;
01299                 //$zip = $ilias->getSetting("zip_path");
01300 
01301                 if (is_array($a_dir))
01302                 {
01303                         $source = "";
01304                         foreach($a_dir as $dir)
01305                         {
01306                                 $name = basename($dir);
01307                                 $source.= " ".ilUtil::escapeShellArg($name);
01308                         }
01309                 }
01310                 else
01311                 {
01312                         $name = basename($a_dir);
01313                         $source = ilUtil::escapeShellArg($name);
01314                 }
01315 
01316                 $zipcmd = $zip." -r ".ilUtil::escapeShellArg($a_file)." ".$source;
01317                 exec($zipcmd);
01318 //echo htmlentities($zipcmd);
01319                 chdir($cdir);
01320         }
01321 
01325         function getConvertCmd()
01326         {
01327                 return PATH_TO_CONVERT;
01328                 //global $ilias;
01329 
01330                 //return $ilias->getSetting("convert_path");
01331         }
01332 
01340         function convertImage($a_from, $a_to, $a_target_format = "", $a_geometry = "")
01341         {
01342                 $format_str = ($a_target_format != "")
01343                 ? strtoupper($a_target_format).":"
01344                 : "";
01345                 $geometry = ($a_geometry != "")
01346                 ? " -geometry ".$a_geometry."x".$a_geometry." "
01347                 : "";
01348                 $convert_cmd = ilUtil::getConvertCmd()." ".
01349                 ilUtil::escapeShellArg($a_from)." ".$geometry.ilUtil::escapeShellArg($format_str.$a_to);
01350                 system($convert_cmd);
01351         }
01352 
01361         function resizeImage($a_from, $a_to, $a_width, $a_height)
01362         {
01363                 $size = " -resize ".$a_width."x".$a_height."! ";
01364                 $convert_cmd = ilUtil::getConvertCmd()." ".
01365                         ilUtil::escapeShellArg($a_from)." ".$size.ilUtil::escapeShellArg($a_to);
01366                 system($convert_cmd);
01367         }
01368 
01374         function html2pdf($html, $pdf_file)
01375         {
01376                 //global $ilias;
01377 
01378                 $html_file = str_replace(".pdf",".html",$pdf_file);
01379 
01380                 $fp = fopen( $html_file ,"wb");
01381                 fwrite($fp, $html);
01382                 fclose($fp);
01383 
01384                 $htmldoc_path = PATH_TO_HTMLDOC;
01385                 //$htmldoc_path = $ilias->getSetting("htmldoc_path");
01386 
01387                 $htmldoc = $htmldoc_path." ";
01388                 $htmldoc .= "--no-toc ";
01389                 $htmldoc .= "--no-jpeg ";
01390                 $htmldoc .= "--webpage ";
01391                 $htmldoc .= "--outfile " . ilUtil::escapeShellArg($pdf_file) . " ";
01392                 $htmldoc .= "--bodyfont Arial ";
01393                 $htmldoc .= "--charset iso-8859-15 ";
01394                 $htmldoc .= "--color ";
01395                 $htmldoc .= "--size A4  ";      // --landscape
01396                 $htmldoc .= "--format pdf ";
01397                 $htmldoc .= "--footer ... ";
01398                 $htmldoc .= "--header ... ";
01399                 $htmldoc .= "--left 60 ";
01400                 // $htmldoc .= "--right 200 ";
01401                 $htmldoc .= $html_file;
01402                 exec($htmldoc);
01403 
01404         }
01405 
01409         function deliverData($a_data, $a_filename, $mime = "application/octet-stream", $charset = "")
01410         {
01411                 $disposition = "attachment"; // "inline" to view file in browser or "attachment" to download to hard disk
01412                 //              $mime = "application/octet-stream"; // or whatever the mime type is
01413 
01414                 if (isset($_SERVER["HTTPS"])) {
01415 
01416                         // Added different handling for IE and HTTPS => send pragma after content informations
01420                         #header("Pragma: ");
01421                         #header("Cache-Control: ");
01422                         #header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
01423                         #header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
01424                         #header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
01425                         #header("Cache-Control: post-check=0, pre-check=0", false);
01426                 }
01427                 else if ($disposition == "attachment")
01428                 {
01429                         header("Cache-control: private");
01430                 }
01431                 else
01432                 {
01433                         header("Cache-Control: no-cache, must-revalidate");
01434                         header("Pragma: no-cache");
01435                 }
01436 
01437                 $ascii_filename = ilUtil::getASCIIFilename($a_filename);
01438 
01439                 if (strlen($charset))
01440                 {
01441                         $charset = "; charset=$charset";
01442                 }
01443                 header("Content-Type: $mime$charset");
01444                 header("Content-Disposition:$disposition; filename=\"".$ascii_filename."\"");
01445                 header("Content-Description: ".$ascii_filename);
01446                 header("Content-Length: ".(string)(strlen($a_data)));
01447 
01448                 if($_SERVER['HTTPS'])
01449                 {
01450             header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
01451             header('Pragma: public');   
01452                 }
01453 
01454                 header("Connection: close");
01455                 echo $a_data;
01456                 exit;
01457         }
01458 
01462         function deliverFile($a_file, $a_filename)
01463         {
01464                 $disposition = "attachment"; // "inline" to view file in browser or "attachment" to download to hard disk
01465                 $mime = "application/octet-stream"; // or whatever the mime type is
01466 
01467                 if (isset($_SERVER["HTTPS"]))
01468                 {
01469                         // Added different handling for IE and HTTPS => send pragma after content informations
01470 
01474                         #header("Pragma: ");
01475                         #header("Pragma: no-cache");
01476                         #header("Cache-Control: ");
01477                         #header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
01478                         #header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
01479                         #header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
01480                         ##header("Cache-Control: post-check=0, pre-check=0", false);
01481                 }
01482                 else if ($disposition == "attachment")
01483                 {
01484                         header("Cache-control: private");
01485                 }
01486                 else
01487                 {
01488                         header("Cache-Control: no-cache, must-revalidate");
01489                         header("Pragma: no-cache");
01490                 }
01491 
01492                 $ascii_filename = ilUtil::getASCIIFilename($a_filename);
01493 
01494                 header("Content-Type: $mime");
01495                 header("Content-Disposition:$disposition; filename=\"".$ascii_filename."\"");
01496                 header("Content-Description: ".$ascii_filename);
01497                 header("Content-Length: ".(string)(filesize($a_file)));
01498 
01499                 if($_SERVER['HTTPS'])
01500                 {
01501             header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
01502             header('Pragma: public');   
01503                 }
01504 
01505                 header("Connection: close");
01506                 ilUtil::readFile( $a_file );
01507                 exit;
01508         }
01509 
01510 
01517         function readFile($a_file)
01518         {
01519                 $chunksize = 1*(1024*1024); // how many bytes per chunk
01520                 $buffer = '';
01521                 $handle = fopen($a_file, 'rb');
01522                 if ($handle === false)
01523                 {
01524                         return false;
01525                 }
01526                 while (!feof($handle))
01527                 {
01528                         $buffer = fread($handle, $chunksize);
01529                         print $buffer;
01530                 }
01531                 return fclose($handle);
01532         }
01533 
01539         function getASCIIFilename($a_filename)
01540         {
01541                 // The filename must be converted to ASCII, as of RFC 2183,
01542                 // section 2.3.
01543                 // Despite the RFC, Internet Explorer on Windows supports
01544                 // ISO 8895-1 encoding for the file name. We use this fact, to
01545                 // produce a better result, if the user uses IE.
01546 
01558 
01559                 $user_agent = strtolower($_SERVER["HTTP_USER_AGENT"]);
01560                 if ((is_integer(strpos($user_agent, "msie"))) && is_integer(strpos($user_agent, "win")))
01561                 {
01564 
01565                         $ascii_filename = utf8_decode($a_filename);
01566                 }
01567                 else
01568                 {
01571 
01572                         $ascii_filename = htmlentities($a_filename,ENT_NOQUOTES,'UTF-8');
01573                         $ascii_filename = preg_replace('/\&(.)[^;]*;/','\\1', $ascii_filename);
01574                         $ascii_filename = preg_replace('/[\x7f-\xff]/','_', $ascii_filename);
01575                 }
01576 
01577                 // Windows does not allow the following characters in filenames:
01578                 // \/:*?"<>|
01579                 if (is_integer(strpos($user_agent, "win")))
01580                 {
01581                         $ascii_filename = preg_replace('/[:\x5c\/\*\?\"<>\|]/','_', $ascii_filename);
01582                 }
01583 
01584                 return $ascii_filename;
01585         }
01586 
01590         function getJavaPath()
01591         {
01592                 return PATH_TO_JAVA;
01593                 //global $ilias;
01594 
01595                 //return $ilias->getSetting("java_path");
01596         }
01597 
01602         function appendUrlParameterString($a_url, $a_par)
01603         {
01604                 $url = (is_int(strpos($a_url, "?")))
01605                 ? $a_url."&".$a_par
01606                 : $a_url."?".$a_par;
01607 
01608                 return $url;
01609         }
01610 
01625         function makeDir($a_dir)
01626         {
01627                 $a_dir = trim($a_dir);
01628 
01629                 // remove trailing slash (bugfix for php 4.2.x)
01630                 if (substr($a_dir,-1) == "/")
01631                 {
01632                         $a_dir = substr($a_dir,0,-1);
01633                 }
01634 
01635                 // check if a_dir comes with a path
01636                 if (!($path = substr($a_dir,0, strrpos($a_dir,"/") - strlen($a_dir))))
01637                 {
01638                         $path = ".";
01639                 }
01640 
01641                 // create directory with file permissions of parent directory
01642                 umask(0000);
01643                 return @mkdir($a_dir,fileperms($path));
01644         }
01645 
01646 
01659         function makeDirParents($a_dir)
01660         {
01661                 $dirs = array($a_dir);
01662                 $a_dir = dirname($a_dir);
01663                 $last_dirname = '';
01664                 while($last_dirname != $a_dir)
01665                 {
01666                         array_unshift($dirs, $a_dir);
01667                         $last_dirname = $a_dir;
01668                         $a_dir = dirname($a_dir);
01669                 }
01670 
01671                 // find the first existing dir
01672                 $reverse_paths = array_reverse($dirs, TRUE);
01673                 $found_index = -1;
01674                 foreach ($reverse_paths as $key => $value)
01675                 {
01676                         if ($found_index == -1)
01677                         {
01678                                 if (is_dir($value))
01679                                 {
01680                                         $found_index = $key;
01681                                 }
01682                         }
01683                 }
01684 
01685                 umask(0000);
01686                 foreach ($dirs as $dirindex => $dir)
01687                 {
01688                         // starting with the longest existing path
01689                         if ($dirindex >= $found_index)
01690                         {
01691                                 if (! file_exists($dir))
01692                                 {
01693                                         if (! mkdir($dir, $umask))
01694                                         {
01695                                                 error_log("Can't make directory: $dir");
01696                                                 return false;
01697                                         }
01698                                 }
01699                                 elseif (! is_dir($dir))
01700                                 {
01701                                         error_log("$dir is not a directory");
01702                                         return false;
01703                                 }
01704                                 else
01705                                 {
01706                                         // get umask of the last existing parent directory
01707                                         $umask = fileperms($dir);
01708                                 }
01709                         }
01710                 }
01711                 return true;
01712         }
01713 
01721         function delDir($a_dir)
01722         {
01723                 if (!is_dir($a_dir) || is_int(strpos($a_dir, "..")))
01724                 {
01725                         return;
01726                 }
01727 
01728                 $current_dir = opendir($a_dir);
01729 
01730                 $files = array();
01731 
01732                 // this extra loop has been necessary because of a strange bug
01733                 // at least on MacOS X. A looped readdir() didn't work
01734                 // correctly with larger directories
01735                 // when an unlink happened inside the loop. Getting all files
01736                 // into the memory first solved the problem.
01737                 while($entryname = readdir($current_dir))
01738                 {
01739                         $files[] = $entryname;
01740                 }
01741 
01742                 foreach($files as $file)
01743                 {
01744                         if(is_dir($a_dir."/".$file) and ($file != "." and $file!=".."))
01745                         {
01746                                 ilUtil::delDir(${a_dir}."/".${file});
01747                         }
01748                         elseif ($file != "." and $file != "..")
01749                         {
01750                                 unlink(${a_dir}."/".${file});
01751                         }
01752                 }
01753 
01754                 closedir($current_dir);
01755                 rmdir(${a_dir});
01756         }
01757 
01758 
01762         function getDir($a_dir)
01763         {
01764                 $current_dir = opendir($a_dir);
01765 
01766                 $dirs = array();
01767                 $files = array();
01768                 while($entry = readdir($current_dir))
01769                 {
01770                         if(is_dir($a_dir."/".$entry))
01771                         {
01772                                 $dirs[$entry] = array("type" => "dir", "entry" => $entry);
01773                         }
01774                         else
01775                         {
01776                                 $size = filesize($a_dir."/".$entry);
01777                                 $files[$entry] = array("type" => "file", "entry" => $entry,
01778                                 "size" => $size);
01779                         }
01780                 }
01781                 ksort($dirs);
01782                 ksort($files);
01783 
01784                 return array_merge($dirs, $files);
01785         }
01786 
01787 
01795         function getGroupId($a_parent_ref)
01796         {
01797                 return false;
01798 
01799                 global $ilias;
01800 
01801                 $q = "SELECT DISTINCT tree FROM grp_tree WHERE child='".$a_parent_ref."'";
01802                 $r = $ilias->db->query($q);
01803                 $row = $r->fetchRow();
01804 
01805                 return $row[0] ? $row[0] : false;
01806         }
01807 
01813         function stripSlashes($a_str, $a_strip_html = true, $a_allow = "")
01814         {
01815                 if (ini_get("magic_quotes_gpc"))
01816                 {
01817                         $a_str = stripslashes($a_str);
01818                 }
01819 
01820                 // default behaviour: allow only fundamental tags 1:1
01821                 if ($a_allow == "" && $a_strip_html)
01822                 {
01823                         //$a_allow = "<b><i><strong><em><code><cite><gap><sub><sup><pre><strike>";
01824                         
01825                         $tags = array("b", "i", "strong", "em", "code", "cite", "gap", "sub", "sup", "pre", "strike");
01826                         
01827                         foreach ($tags as $t)           // mask allowed tags
01828                         {
01829                                 $a_str = str_replace(array("<$t>", "<".strtoupper($t).">"),
01830                                         "&lt;".$t."&gt;", $a_str);
01831                                 $a_str = str_replace(array("</$t>", "</".strtoupper($t).">"),
01832                                         "&lt;/".$t."&gt;", $a_str);
01833                         }
01834                         
01835                         $a_str = strip_tags($a_str);            // strip all other tags
01836                         
01837                         foreach ($tags as $t)           // mask allowed tags
01838                         {
01839                                 $a_str = str_replace("&lt;".$t."&gt;", "<".$t.">", $a_str);
01840                                 $a_str = str_replace("&lt;/".$t."&gt;", "</".$t.">", $a_str);
01841                         }
01842                         
01843                 }
01844                 else
01845                 {
01846                         // only for scripts, that need to allow more/other tags and parameters
01847                         if ($a_strip_html)
01848                         {
01849                                 $a_str = ilUtil::stripScriptHTML($a_str, $a_allow);
01850                         }
01851                 }
01852                 
01853                 return $a_str;
01854         }
01855 
01856 
01868         function stripScriptHTML($a_str, $a_allow = "", $a_rm_js = true)
01869         {
01870                 //$a_str = strip_tags($a_str, $a_allow);
01871 
01872                 $negativestr = "a,abbr,acronym,address,applet,area,b,base,basefont,".
01873                         "bdo,big,blockquote,body,br,button,caption,center,cite,code,col,".
01874                         "colgroup,dd,del,dfn,dir,div,dl,dt,em,fieldset,font,form,frame,".
01875                         "frameset,h1,h2,h3,h4,h5,h6,head,hr,html,i,iframe,img,input,ins,isindex,kbd,".
01876                         "label,legend,li,link,map,menu,meta,noframes,noscript,object,ol,".
01877                         "optgroup,option,p,param,q,s,samp,script,select,small,span,".
01878                         "strike,strong,style,sub,sup,table,tbody,td,textarea,tfoot,th,thead,".
01879                         "title,tr,tt,u,ul,var";
01880                 $a_allow = strtolower ($a_allow);
01881                 $negatives = split (",",$negativestr);
01882                 $outer_old_str = "";
01883                 while($outer_old_str != $a_str)
01884                 {
01885                         $outer_old_str = $a_str;
01886                         foreach ($negatives as $item)
01887                         {
01888                                 $pos = strpos($a_allow, "<$item>");
01889         
01890                                 // remove complete tag, if not allowed
01891                                 if ($pos === false)
01892                                 {
01893                                         $old_str = "";
01894                                         while($old_str != $a_str)
01895                                         {
01896                                                 $old_str = $a_str;
01897                                                 $a_str = preg_replace("/<\/?\s*$item(\/?)\s*>/i", "", $a_str);
01898                                                 $a_str = preg_replace("/<\/?\s*$item(\/?)\s+([^>]*)>/i", "", $a_str);
01899                                         }
01900                                 }
01901                         }
01902                 }
01903                 
01904                 if ($a_rm_js)
01905                 {
01906                         // remove all attributes if an "on..." attribute is given
01907                         $a_str = preg_replace("/<\s*\w*(\/?)(\s+[^>]*)?(\s+on[^>]*)>/i", "", $a_str);
01908 
01909                         // remove all attributes if a "javascript" is within tag
01910                         $a_str = preg_replace("/<\s*\w*(\/?)\s+[^>]*javascript[^>]*>/i", "", $a_str);
01911                         
01912                         // remove all attributes if an "expression" is within tag
01913                         // (IE allows something like <b style='width:expression(alert(1))'>test</b>)
01914                         $a_str = preg_replace("/<\s*\w*(\/?)\s+[^>]*expression[^>]*>/i", "", $a_str);
01915                 }
01916 
01917                 return $a_str;
01918         }
01919 
01920 
01926         function addSlashes($a_str)
01927         {
01928                 if (ini_get("magic_quotes_gpc"))
01929                 {
01930                         return $a_str;
01931                 }
01932                 else
01933                 {
01934                         return addslashes($a_str);
01935                 }
01936         }
01937 
01947         function prepareFormOutput($a_str, $a_strip = false)
01948         {
01949                 if($a_strip)
01950                 {
01951                         $a_str = ilUtil::stripSlashes($a_str);
01952                 }
01953                 return htmlspecialchars($a_str);
01954         }
01955 
01956 
01964         function prepareDBString($a_str)
01965         {
01966                 return addslashes($a_str);
01967         }
01968 
01969 
01976         function removeItemFromDesktops($a_id)
01977         {
01978                 global $ilDB;
01979 
01980                 $q = "SELECT user_id FROM desktop_item WHERE item_id = '".$a_id."'";
01981                 $r = $ilDB->query($q);
01982 
01983                 $users = array();
01984 
01985                 while ($row = $r->fetchRow(DB_FETCHMODE_OBJECT))
01986                 {
01987                         $users[] = $row->user_id;
01988                 } // while
01989 
01990                 if (count($users) > 0)
01991                 {
01992                         $q = "DELETE FROM desktop_item WHERE item_id = '".$a_id."'";
01993                         $ilDB->query($q);
01994                 }
01995 
01996                 return $users;
01997         }
01998 
01999 
02007         function extractParameterString($a_parstr)
02008         {
02009                 // parse parameters in array
02010                 $par = array();
02011                 $ok=true;
02012                 while(($spos=strpos($a_parstr,"=")) && $ok)
02013                 {
02014                         // extract parameter
02015                         $cpar = substr($a_parstr,0,$spos);
02016                         $a_parstr = substr($a_parstr,$spos,strlen($a_parstr)-$spos);
02017                         while(substr($cpar,0,1)=="," ||substr($cpar,0,1)==" " || substr($cpar,0,1)==chr(13) || substr($cpar,0,1)==chr(10))
02018                         $cpar = substr($cpar,1,strlen($cpar)-1);
02019                         while(substr($cpar,strlen($cpar)-1,1)==" " || substr($cpar,strlen($cpar)-1,1)==chr(13) || substr($cpar,strlen($cpar)-1,1)==chr(10))
02020                         $cpar = substr($cpar,0,strlen($cpar)-1);
02021 
02022                         // extract value
02023                         if($spos=strpos($a_parstr,"\""))
02024                         {
02025                                 $a_parstr = substr($a_parstr,$spos+1,strlen($a_parstr)-$spos);
02026                                 $spos=strpos($a_parstr,"\"");
02027                                 if(is_int($spos))
02028                                 {
02029                                         $cval = substr($a_parstr,0,$spos);
02030                                         $par[$cpar]=$cval;
02031                                         $a_parstr = substr($a_parstr,$spos+1,strlen($a_parstr)-$spos-1);
02032                                 }
02033                                 else
02034                                 $ok=false;
02035                         }
02036                         else
02037                         $ok=false;
02038                 }
02039 
02040                 if($ok) return $par; else return false;
02041         }
02042 
02043         function assembleParameterString($a_par_arr)
02044         {
02045                 if (is_array($a_par_arr))
02046                 {
02047                         $target_arr = array();
02048                         foreach ($a_par_arr as $par => $val)
02049                         {
02050                                 $target_arr[] = "$par=\"$val\"";
02051                         }
02052                         $target_str = implode(", ", $target_arr);
02053                 }
02054 
02055                 return $target_str;
02056         }
02057 
02061         function dumpString($a_str)
02062         {
02063                 $ret = $a_str.": ";
02064                 for($i=0; $i<strlen($a_str); $i++)
02065                 {
02066                         $ret.= ord(substr($a_str,$i,1))." ";
02067                 }
02068                 return $ret;
02069         }
02070 
02071 
02075         function yn2tf($a_yn)
02076         {
02077                 if(strtolower($a_yn) == "y")
02078                 {
02079                         return true;
02080                 }
02081                 else
02082                 {
02083                         return false;
02084                 }
02085         }
02086 
02090         function tf2yn($a_tf)
02091         {
02092                 if($a_tf)
02093                 {
02094                         return "y";
02095                 }
02096                 else
02097                 {
02098                         return "n";
02099                 }
02100         }
02101 
02110         function sort_func ($a, $b)
02111         {
02112                 global $array_sortby,$array_sortorder;
02113 
02114                 if ($array_sortorder == "asc")
02115                 {
02116                         return strcasecmp($a[$array_sortby], $b[$array_sortby]);
02117                 }
02118 
02119                 if ($array_sortorder == "desc")
02120                 {
02121                         return strcasecmp($b[$array_sortby], $a[$array_sortby]);
02122                 }
02123         }
02124 
02133         function sort_func_numeric ($a, $b)
02134         {
02135                 global $array_sortby,$array_sortorder;
02136 
02137                 if ($array_sortorder == "asc")
02138                 {
02139                         return $a["$array_sortby"] > $b["$array_sortby"];
02140                 }
02141 
02142                 if ($array_sortorder == "desc")
02143                 {
02144                         return $a["$array_sortby"] < $b["$array_sortby"];
02145                 }
02146         }
02157         function sortArray($array,$a_array_sortby,$a_array_sortorder = 0,$a_numeric = false)
02158         {
02159                 global $array_sortby,$array_sortorder;
02160 
02161                 $array_sortby = $a_array_sortby;
02162 
02163                 if ($a_array_sortorder == "desc")
02164                 {
02165                         $array_sortorder = "desc";
02166                 }
02167                 else
02168                 {
02169                         $array_sortorder = "asc";
02170                 }
02171                 if($a_numeric)
02172                 {
02173                         usort($array, array("ilUtil", "sort_func_numeric"));
02174                 }
02175                 else
02176                 {
02177                         usort($array, array("ilUtil", "sort_func"));
02178                 }
02179                 //usort($array,"ilUtil::sort_func");
02180 
02181                 return $array;
02182         }
02183 
02193         function unique_multi_array($array, $sub_key)
02194         {
02195                 $target = array();
02196                 $existing_sub_key_values = array();
02197 
02198                 foreach ($array as $key=>$sub_array)
02199                 {
02200                         if (!in_array($sub_array[$sub_key], $existing_sub_key_values))
02201                         {
02202                                 $existing_sub_key_values[] = $sub_array[$sub_key];
02203                                 $target[$key] = $sub_array;
02204                         }
02205                 }
02206 
02207                 return $target;
02208         }
02209 
02210 
02218         function getGDSupportedImageType($a_desired_type)
02219         {
02220                 $a_desired_type = strtolower($a_desired_type);
02221                 // get supported Image Types
02222                 $im_types = ImageTypes();
02223 
02224                 switch($a_desired_type)
02225                 {
02226                         case "jpg":
02227                         if ($im_types & IMG_JPG) return "jpg";
02228                         if ($im_types & IMG_GIF) return "gif";
02229                         if ($im_types & IMG_PNG) return "png";
02230                         break;
02231 
02232                         case "gif":
02233                         if ($im_types & IMG_GIF) return "gif";
02234                         if ($im_types & IMG_JPG) return "jpg";
02235                         if ($im_types & IMG_PNG) return "png";
02236                         break;
02237 
02238                         case "png":
02239                         if ($im_types & IMG_PNG) return "png";
02240                         if ($im_types & IMG_JPG) return "jpg";
02241                         if ($im_types & IMG_GIF) return "gif";
02242                         break;
02243                 }
02244 
02245                 return "";
02246         }
02247 
02255         function deducibleSize($a_mime)
02256         {
02257                 if (($a_mime == "image/gif") || ($a_mime == "image/jpeg") ||
02258                 ($a_mime == "image/png") || ($a_mime == "application/x-shockwave-flash") ||
02259                 ($a_mime == "image/tiff") || ($a_mime == "image/x-ms-bmp") ||
02260                 ($a_mime == "image/psd") || ($a_mime == "image/iff"))
02261                 {
02262                         return true;
02263                 }
02264                 else
02265                 {
02266                         return false;
02267                 }
02268         }
02269 
02270 
02276         function redirect($a_script)
02277         {
02278                 global $log, $PHP_SELF;
02279 //$log->write("redirect FROM:".$PHP_SELF." to ".$a_script);
02280                         //vd($a_script);
02281                 header("Location: ".$a_script);
02282                 exit();
02283         }
02284 
02290         function insertInstIntoID($a_value)
02291         {
02292                 if (substr($a_value, 0, 4) == "il__")
02293                 {
02294                         $a_value = "il_".IL_INST_ID."_".substr($a_value, 4, strlen($a_value) - 4);
02295                 }
02296 
02297                 return $a_value;
02298         }
02299 
02308         function groupNameExists($a_group_name,$a_id = 0)
02309         {
02310                 global $ilDB,$ilErr;
02311 
02312                 if (empty($a_group_name))
02313                 {
02314                         $message = get_class($this)."::_NameExists(): No groupname given!";
02315                         $ilErr->raiseError($message,$ilErr->WARNING);
02316                 }
02317 
02318                 $clause = ($a_id) ? " AND obj_id != '".$a_id."'" : "";
02319 
02320                 $q = "SELECT obj_id FROM object_data ".
02321                 "WHERE title = '".addslashes($a_group_name)."' ".
02322                 "AND type = 'grp'".
02323                 $clause;
02324 
02325                 $r = $ilDB->query($q);
02326 
02327                 if ($r->numRows())
02328                 {
02329                         return true;
02330                 }
02331                 else
02332                 {
02333                         return false;
02334                 }
02335         }
02336 
02337         /*
02338         * get the user_ids which correspond a search string
02339         * static function
02340         * @param        string search string
02341         * @access       public
02342         */
02343         function searchGroups($a_search_str)
02344         {
02345                 global $ilDB;
02346 
02347                 $q = "SELECT * ".
02348                         "FROM object_data ,object_reference ".
02349                         "WHERE (object_data.title LIKE '%".$a_search_str."%' ".
02350                         "OR object_data.description LIKE '%".$a_search_str."%') ".
02351                         "AND object_data.type = 'grp' ".
02352                         "AND object_data.obj_id = object_reference.obj_id ".
02353                         "ORDER BY title ";
02354 
02355                 $res = $ilDB->query($q);
02356 
02357                 while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
02358                 {
02359                         // STORE DATA IN ARRAY WITH KEY obj_id
02360                         // SO DUPLICATE ENTRIES ( LINKED OBJECTS ) ARE UNIQUE
02361                         $ids[$row->obj_id] = array(
02362                         "ref_id"        => $row->ref_id,
02363                         "title"         => $row->title,
02364                         "description"   => $row->description);
02365                 }
02366 
02367                 return $ids ? $ids : array();
02368         }
02369 
02373         function getMemString()
02374         {
02375                 $my_pid = getmypid();
02376                 return ("MEMORY USAGE (% KB PID ): ".`ps -eo%mem,rss,pid | grep $my_pid`);
02377         }
02378 
02382         function isWindows()
02383         {
02384                 if (strtolower(substr(php_uname(), 0, 3)) == "win")
02385                 {
02386                         return true;
02387                 }
02388                 return false;
02389         }
02390 
02391         function escapeShellArg($a_arg)
02392         {
02393                 global $PHP_OS;
02394 
02395                 if (ini_get("safe_mode") == 1 || ilUtil::isWindows())
02396                 {
02397                         return $a_arg;
02398                 }
02399                 else
02400                 {
02401                         return escapeshellarg($a_arg);
02402                 }
02403         }
02404 
02405         /*
02406         * Calculates a Microsoft Excel date/time value
02407         *
02408         * Calculates a Microsoft Excel date/time value (nr of days after 1900/1/1 0:00) for
02409         * a given date and time. The function only accepts dates after 1970/1/1, because the
02410         * unix timestamp functions used in the function are starting with that date.
02411         * If you don't enter parameters the date/time value for the actual date/time
02412         * will be calculated.
02413         *
02414         * static function
02415         *
02416         * @param        integer $year Year
02417         * @param        integer $month Month
02418         * @param        integer $day Day
02419         * @param        integer $hour Hour
02420         * @param        integer $minute Minute
02421         * @param        integer $second Second
02422         * @return float The Microsoft Excel date/time value
02423         * @access       public
02424         */
02425         function excelTime($year = "", $month = "", $day = "", $hour = "", $minute = "", $second = "")
02426         {
02427                 $starting_time = mktime(0, 0, 0, 1, 2, 1970);
02428                 if (strcmp("$year$month$day$hour$minute$second", "") == 0)
02429                 {
02430                         $target_time = time();
02431                 }
02432                 else
02433                 {
02434                         if ($year < 1970)
02435                         {
02436                                 return 0;
02437                         }
02438                 }
02439                 $target_time = mktime($hour, $minute, $second, $month, $day, $year);
02440                 $difference = $target_time - $starting_time;
02441                 $days = (($difference - ($difference % 86400)) / 86400);
02442                 $difference = $difference - ($days * 86400) + 3600;
02443                 return ($days + 25570 + ($difference / 86400));
02444         }
02445 
02449         function renameExecutables($a_dir)
02450         {
02451                 ilUtil::rRenameSuffix($a_dir, "php", "sec");
02452                 ilUtil::rRenameSuffix($a_dir, "php3", "sec");
02453                 ilUtil::rRenameSuffix($a_dir, "php4", "sec");
02454                 ilUtil::rRenameSuffix($a_dir, "inc", "sec");
02455                 ilUtil::rRenameSuffix($a_dir, "lang", "sec");
02456                 ilUtil::rRenameSuffix($a_dir, "phtml", "sec");
02457                 ilUtil::rRenameSuffix($a_dir, "htaccess", "sec");
02458         }
02459 
02468         function rRenameSuffix ($a_dir, $a_old_suffix, $a_new_suffix)
02469         {
02470                 if ($a_dir == "/" || $a_dir == "" || is_int(strpos($a_dir, "..")))
02471                 {
02472                         return false;
02473                 }
02474 
02475                 // check if argument is directory
02476                 if (!@is_dir($a_dir))
02477                 {
02478                         return false;
02479                 }
02480 
02481                 // read a_dir
02482                 $dir = opendir($a_dir);
02483 
02484                 while($file = readdir($dir))
02485                 {
02486                         if ($file != "." and
02487                         $file != "..")
02488                         {
02489                                 // directories
02490                                 if (@is_dir($a_dir."/".$file))
02491                                 {
02492                                         ilUtil::rRenameSuffix($a_dir."/".$file, $a_old_suffix, $a_new_suffix);
02493                                 }
02494 
02495                                 // files
02496                                 if (@is_file($a_dir."/".$file))
02497                                 {
02498                                         $path_info = pathinfo($a_dir."/".$file);
02499                                         if (strtolower($path_info["extension"]) ==
02500                                         strtolower($a_old_suffix))
02501                                         {
02502                                                 $pos = strrpos($a_dir."/".$file, ".");
02503                                                 $new_name = substr($a_dir."/".$file, 0, $pos).".".$a_new_suffix;
02504                                                 rename($a_dir."/".$file, $new_name);
02505                                         }
02506                                 }
02507                         }
02508                 }
02509                 return true;
02510         }
02511 
02512         function isAPICall () {
02513                 return  strpos($_SERVER["SCRIPT_FILENAME"],"api") !== false ||
02514                 strpos($_SERVER["SCRIPT_FILENAME"],"dummy") !== false;
02515         }
02516 
02517         function KT_replaceParam($qstring, $paramName, $paramValue) {
02518                 if (preg_match("/&" . $paramName . "=/", $qstring)) {
02519                         return preg_replace("/&" . $paramName . "=[^&]+/", "&" . $paramName . "=" . urlencode($paramValue), $qstring);
02520                 } else {
02521                         return $qstring . "&" . $paramName . "=" . urlencode($paramValue);
02522                 }
02523         }
02524 
02525         function replaceUrlParameterString ($url, $parametersArray) {
02526 
02527                 foreach ($parametersArray as $paramName => $paramValue ) {
02528                         $url = ilUtil::KT_replaceParam($url, $paramName, $paramValue);
02529                 }
02530                 return $url;
02531         }
02532 
02533     function generatePasswords ($a_number)
02534     {
02535         $ret = array();
02536         srand((double) microtime()*1000000);
02537 
02538         for ($i=1; $i<=$a_number; $i++)
02539         {
02540             $length  = rand(6,10);
02541             $next  = rand(1,2);
02542             //$chars = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
02543             $vowels = "aeiou";
02544             $consonants = "bcdfghjklmnpqrstvwxyz";
02545             $pw = "";
02546 
02547             for ($j=0; $j < $length; $j++)
02548             {
02549                 switch ($next)
02550                 {
02551                     case 1:
02552                                         $pw.= $consonants[rand(0,strlen($consonants)-1)];
02553                                         $next = 2;
02554                     break;
02555 
02556                     case 2:
02557                                         $pw.= $vowels[rand(0,strlen($vowels)-1)];
02558                                         $next = 1;
02559                                 break;
02560                 }
02561              }
02562 
02563              $ret[] = $pw;
02564          }
02565 
02566          return $ret;
02567     }
02568 
02569         function removeTrailingPathSeparators($path)
02570         {
02571                 $path = preg_replace("/[\/\\\]+$/", "", $path);
02572                 return $path;
02573         }
02574 
02583         function array_php2js($data)
02584         {
02585                 if (empty($data))
02586                 {
02587                         $data = array();
02588                 }
02589 
02590                 foreach($data as $k=>$datum)
02591                 {
02592                         if(is_null($datum)) $data[$k] = 'null';
02593                         if(is_string($datum)) $data[$k] = "'" . $datum . "'";
02594                         if(is_array($datum)) $data[$k] = array_php2js($datum);
02595                 }
02596 
02597                 return "[" . implode(', ', $data) . "]";
02598         }
02599 
02604         function virusHandling($a_file, $a_orig_name = "", $a_clean = true)
02605         {
02606                 global $lng;
02607 
02608                 if (IL_VIRUS_SCANNER != "None")
02609                 {
02610                         require_once("classes/class.ilVirusScannerFactory.php");
02611                         $vs = ilVirusScannerFactory::_getInstance();
02612                         if (($vs_txt = $vs->scanFile($a_file, $a_orig_name)) != "")
02613                         {
02614                                 if ($a_clean && (IL_VIRUS_CLEAN_COMMAND != ""))
02615                                 {
02616                                         $clean_txt = $vs->cleanFile($a_file, $a_orig_name);
02617                                         if ($vs->fileCleaned())
02618                                         {
02619                                                 $vs_txt.= "<br />".$lng->txt("cleaned_file").
02620                                                         "<br />".$clean_txt;
02621                                                 $vs_txt.= "<br />".$lng->txt("repeat_scan");
02622                                                 if (($vs2_txt = $vs->scanFile($a_file, $a_orig_name)) != "")
02623                                                 {
02624                                                         return array(false, nl2br($vs_txt)."<br />".$lng->txt("repeat_scan_failed").
02625                                                                 "<br />".nl2br($vs2_txt));
02626                                                 }
02627                                                 else
02628                                                 {
02629                                                         return array(true, nl2br($vs_txt)."<br />".$lng->txt("repeat_scan_succeded"));
02630                                                 }
02631                                         }
02632                                         else
02633                                         {
02634                                                 return array(false, nl2br($vs_txt)."<br />".$lng->txt("cleaning_failed"));
02635                                         }
02636                                 }
02637                                 else
02638                                 {
02639                                         return array(false, nl2br($vs_txt));
02640                                 }
02641                         }
02642                 }
02643                 return array(true,"");
02644         }
02645 
02646 
02650         function moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors = true)
02651         {
02652                 global $lng, $ilias;
02653 //echo "<br>ilUtli::moveuploadedFile($a_name)";
02654                 if (!is_file($a_file))
02655                 {
02656                         $lng->txt("upload_error_file_not_found");
02657                 }
02658 
02659                 // virus handling
02660                 $vir = ilUtil::virusHandling($a_file, $a_name);
02661                 if (!$vir[0])
02662                 {
02663                         unlink($a_file);
02664                         if ($a_raise_errors)
02665                         {
02666                                 $ilias->raiseError($lng->txt("file_is_infected")."<br />".
02667                                         $vir[1],
02668                                         $ilias->error_obj->MESSAGE);
02669                         }
02670                         else
02671                         {
02672                                 sendInfo($lng->txt("file_is_infected")."<br />".
02673                                         $vir[1], true);
02674                         }
02675                         return false;
02676                 }
02677                 else
02678                 {
02679                         if ($vir[1] != "")
02680                         {
02681                                 sendInfo($vir[1], true);
02682                         }
02683                         return move_uploaded_file($a_file, $a_target);
02684                 }
02685         }
02686 
02687 
02691          function date_mysql2time($mysql_date_time) {
02692                 list($datum, $uhrzeit) = explode (" ",$mysql_date_time);
02693                 list($jahr, $monat, $tag) = explode("-", $datum);
02694                 list($std, $min, $sec) = explode(":", $uhrzeit);
02695                 return mktime ((int) $std, (int) $min, (int) $sec, (int) $monat, (int) $tag, (int) $jahr);
02696          }
02697 
02711         function &processCSVRow(&$row, $quoteAll = FALSE, $separator = ";", $outUTF8 = FALSE, $compatibleWithMSExcel = TRUE)
02712         {
02713                 $resultarray = array();
02714                 foreach ($row as $rowindex => $entry)
02715                 {
02716                         $surround = FALSE;
02717                         if ($quoteAll)
02718                         {
02719                                 $surround = TRUE;
02720                         }
02721                         if (strpos($entry, "\"") !== FALSE)
02722                         {
02723                                 $entry = str_replace("\"", "\"\"", $entry);
02724                                 $surround = TRUE;
02725                         }
02726                         if (strpos($entry, $separator) !== FALSE)
02727                         {
02728                                 $surround = TRUE;
02729                         }
02730                         if ($compatibleWithMSExcel)
02731                         {
02732                                 // replace all CR LF with LF (for Excel for Windows compatibility
02733                                 $entry = str_replace(chr(13).chr(10), chr(10), $entry);
02734                         }
02735                         if ($surround)
02736                         {
02737                                 if ($outUTF8)
02738                                 {
02739                                         $resultarray[$rowindex] = "\"" . $entry . "\"";
02740                                 }
02741                                 else
02742                                 {
02743                                         $resultarray[$rowindex] = utf8_decode("\"" . $entry . "\"");
02744                                 }
02745                         }
02746                         else
02747                         {
02748                                 if ($outUTF8)
02749                                 {
02750                                         $resultarray[$rowindex] = $entry;
02751                                 }
02752                                 else
02753                                 {
02754                                         $resultarray[$rowindex] = utf8_decode($entry);
02755                                 }
02756                         }
02757                 }
02758                 return $resultarray;
02759         }
02760 
02761         // validates a domain name (example: www.ilias.de)
02762         function isDN($a_str)
02763         {
02764                 return(preg_match("/^[a-z]+([a-z0-9-]*[a-z0-9]+)?(\.([a-z]+([a-z0-9-]*[a-z0-9]+)?)+)*$/",$a_str));
02765         }
02766 
02767         // validates an IP address (example: 192.168.1.1)
02768         function isIPv4($a_str)
02769         {
02770                 return(preg_match("/^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.".
02771                                                   "(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/",$a_str));
02772         }
02773 
02774 
02801         function _getObjectsByOperations($a_obj_type,$a_operation,$a_usr_id = 0,$limit = 0)
02802         {
02803                 global $ilDB,$rbacreview,$ilAccess,$ilUser,$ilias;
02804 
02805                 if(!is_array($a_obj_type))
02806                 {
02807                         $where = "WHERE type = '".$a_obj_type."' ";
02808                 }
02809                 else
02810                 {
02811                         $where = "WHERE type IN('";
02812                         $where .= implode("','",$a_obj_type);
02813                         $where .= "') ";
02814                 }
02815                                 
02816 
02817                 // limit number of results default is search result limit
02818                 if(!$limit)
02819                 {
02820                         $limit = $ilias->getSetting('search_max_hits',100);
02821                 }
02822                 if($limit = -1)
02823                 {
02824                         $limit = 10000;
02825                 }
02826 
02827                 // default to logged in usr
02828                 $a_usr_id = $a_usr_id ? $a_usr_id : $ilUser->getId();
02829                 $a_roles = $rbacreview->assignedRoles($a_usr_id);
02830 
02831                 // Since no rbac_pa entries are available for the system role. This function returns !all! ref_ids in the case the user
02832                 // is assigned to the system role
02833                 if($rbacreview->isAssigned($a_usr_id,SYSTEM_ROLE_ID))
02834                 {
02835                         $query = "SELECT ref_id FROM object_reference AS obr LEFT JOIN object_data AS obd USING(obj_id) ".
02836                                 "LEFT JOIN tree ON obr.ref_id = tree.child ".
02837                                 $where.
02838                                 "AND tree = 1";
02839 
02840                         $res = $ilDB->query($query);
02841                         $counter = 0;
02842                         while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
02843                         {
02844                                 if(++$counter == $limit)
02845                                 {
02846                                         break;
02847                                 }
02848                                 $ref_ids[] = $row->ref_id;
02849                         }
02850                         return $ref_ids ? $ref_ids : array();
02851                 }
02852 
02853                 $ops_ids = ilRbacReview::_getOperationIdsByName(array($a_operation));
02854                 $ops_id = $ops_ids[0];
02855 
02856                 $query = "SELECT DISTINCT(obr.ref_id),obr.obj_id,type FROM rbac_pa ".
02857                         "LEFT JOIN object_reference AS obr  ON obr.ref_id = rbac_pa.ref_id ".
02858                         "LEFT JOIN object_data AS obd ON obd.obj_id = obr.obj_id ".
02859                         $where.
02860                         "AND ops_id LIKE '%i:".$ops_id."%'";
02861                 $res = $ilDB->query($query);
02862                 $counter = 0;
02863                 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
02864                 {
02865                         if(++$counter == $limit)
02866                         {
02867                                 break;
02868                         }
02869                         // Check deleted, hierarchical access ...
02870                         if($ilAccess->checkAccessOfUser($a_usr_id,$a_operation,'',$row->ref_id,$row->type,$row->obj_id))
02871                         {
02872                                 $ref_ids[] = $row->ref_id;
02873                         }
02874                 }
02875                 return $ref_ids ? $ref_ids : array();
02876         }
02877 
02878 } // END class.ilUtil
02879 ?>

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