• 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;
00068 
00069                 if(defined("ILIAS_MODULE") and !defined("KEEP_IMAGE_PATH") 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                 }
00080                 else
00081                 {
00082                         $dir = "";
00083                 }
00084                 $base = "./";
00085                 if ($in_module)
00086                 {
00087                         $base.= ILIAS_MODULE."/";
00088                 }
00089                 $base .= "templates/";
00090 
00091                 if (is_object($styleDefinition))
00092                 {
00093                         $st_image_dir = $styleDefinition->getImageDirectory($ilias->account->prefs["style"]);
00094                         $user_skin_and_style = $base.$ilias->account->skin."/".
00095                         $st_image_dir.
00096                         "/images/".$img;
00097                 }
00098 
00099                 $user_skin = $base.$ilias->account->skin."/images/".$img;
00100                 $default = $base."default/images/".$img;
00101                 if ($offline)
00102                 {
00103                         return "./images/".$img;
00104                 }
00105                 else if (@file_exists($user_skin_and_style) && $st_image_dir != "")
00106                 {
00107                         return $dir.$user_skin_and_style;
00108                 }
00109                 else if (file_exists($user_skin))
00110                 {
00111                         return $dir.$user_skin;
00112                 }
00113 
00114                 return $dir.$default;
00115         }
00116 
00125     function getHtmlPath($relative_path)
00126     {
00127         if (substr($relative_path, 0, 2) == './')
00128         {
00129             $relative_path = (substr($relative_path, 1));
00130         }
00131         if (substr($relative_path, 0, 1) != '/')
00132         {
00133             $relative_path = '/' . $relative_path;
00134         }
00135         $htmlpath = ILIAS_HTTP_PATH . $relative_path;
00136         return $htmlpath;
00137     }
00138 
00139         function getJSPath($a_js)
00140         {
00141                 global $ilias;
00142 
00143                 if(defined("ILIAS_MODULE"))
00144                 {
00145                         $dir = ".";
00146                 }
00147                 else
00148                 {
00149                         $dir = "";
00150                 }
00151                 $in_style = "./templates/".$ilias->account->skin."/".$ilias->account->prefs["style"]."/".$a_js;
00152                 $default = "./templates/".$ilias->account->skin."/".$a_js;
00153                 if(@is_file($in_style))
00154                 {
00155                         return $dir.$in_style;
00156                 }
00157                 else
00158                 {
00159                         return $dir.$default;
00160                 }
00161         }
00162 
00168         function getStyleSheetLocation($mode = "output")
00169         {
00170                 global $ilias;
00171 
00172                 if(defined("ILIAS_MODULE") && $mode != "filesystem")
00173                 {
00174                         // added to find Stylesheet for MODULES like Services/Search
00175                         $base = '';
00176                         for($i = 0;$i < count(explode('/',ILIAS_MODULE));$i++)
00177                         {
00178                                 $base .= "../";
00179                         }
00180                 }
00181                 else
00182                 {
00183                         $base = "./";
00184                 }
00185                 return $base."templates/".$ilias->account->skin."/".$ilias->account->prefs["style"].".css";
00186         }
00187 
00200         function formSelect ($selected,$varname,$options,$multiple = false,$direct_text = false, $size = "0")
00201         {
00202                 global $lng;
00203 
00204                 if ($multiple == true)
00205                 {
00206                         $multiple = "multiple";
00207                 }
00208                 else
00209                 {
00210                         $multiple = "";
00211                         $size = 0;
00212                 }
00213 
00214                 $str = "<select name=\"".$varname ."\"".$multiple." size=\"".$size."\">\n";
00215 
00216                 foreach ($options as $key => $val)
00217                 {
00218                         if ($direct_text)
00219                         {
00220                                 $str .= " <option value=\"".$key."\"";
00221                         }
00222                         else
00223                         {
00224                                 $str .= " <option value=\"".$val."\"";
00225                         }
00226                         if (is_array($selected) )
00227                         {
00228                                 if (in_array($key,$selected))
00229                                 {
00230                                         $str .= " selected=\"selected\"";
00231                                 }
00232                         }
00233                         else if ($selected == $key)
00234                         {
00235                                 $str .= " selected=\"selected\"";
00236                         }
00237 
00238                         if ($direct_text)
00239                         {
00240                                 $str .= ">".$val."</option>\n";
00241                         }
00242                         else
00243                         {
00244                                 $str .= ">".$lng->txt($val)."</option>\n";
00245                         }
00246                 }
00247 
00248                 $str .= "</select>\n";
00249 
00250                 return $str;
00251         }
00252 
00260         function getSelectName ($selected,$values)
00261         {
00262                 return($values[$selected]);
00263         }
00264 
00274         function formCheckbox ($checked,$varname,$value,$disabled = false)
00275         {
00276                 $str = "<input type=\"checkbox\" name=\"".$varname."\"";
00277 
00278                 if ($checked == 1)
00279                 {
00280                         $str .= " checked=\"checked\"";
00281                 }
00282 
00283                 if ($disabled)
00284                 {
00285                         $str .= " disabled=\"disabled\"";
00286                 }
00287                 
00288                 $array_var = false;
00289                 
00290                 if (substr($varname,-2) == "[]")
00291                 {
00292                         $array_var = true;
00293                 }
00294 
00295                 // if varname ends with [], use varname[-2] + _ + value as id tag (e.g. "user_id[]" => "user_id_15")
00296                 if ($array_var)
00297                 {
00298                         $varname_id = substr($varname,0,-2)."_".$value;
00299                 }
00300                 else
00301                 {
00302                         $varname_id = $varname;
00303                 }
00304                 
00305                 // dirty removal of other "[]" in string
00306                 $varname_id = ereg_replace("\[","_",$varname_id);
00307                 $varname_id = ereg_replace("\]","",$varname_id);
00308 
00309                 $str .= " value=\"".$value."\" id=\"".$varname_id."\" />\n";
00310 
00311                 return $str;
00312         }
00313 
00322         function formRadioButton($checked,$varname,$value)
00323         {
00324                 $str = "<input type=\"radio\" name=\"".$varname."\"";
00325                 if ($checked == 1)
00326                 {
00327                         $str .= " checked=\"checked\"";
00328                 }
00329 
00330                 $str .= " value=\"".$value."\"";
00331                 
00332                 $str .= " id=\"".$value."\" />\n";
00333 
00334                 return $str;
00335         }
00336 
00341         function checkInput ($vars)
00342         {
00343                 // TO DO:
00344                 // Diese Funktion soll Formfeldeingaben berprfen (empty und required)
00345         }
00346 
00352         function setPathStr ($a_path)
00353         {
00354                 if ("" != $a_path && "/" != substr($a_path, -1))
00355                 {
00356                         $a_path .= "/";
00357                         //$a_path = substr($a_path,1);
00358                 }
00359 
00360                 //return getcwd().$a_path;
00361                 return $a_path;
00362         }
00363 
00374         function switchColor ($a_num,$a_css1,$a_css2)
00375         {
00376                 if (!($a_num % 2))
00377                 {
00378                         return $a_css1;
00379                 }
00380                 else
00381                 {
00382                         return $a_css2;
00383                 }
00384         }
00385 
00393         function showTabs($a_hl, $a_o)
00394         {
00395                 global $lng;
00396 
00397                 $tpltab = new ilTemplate("tpl.tabs.html", true, true);
00398 
00399                 for ($i=1; $i<=4; $i++)
00400                 {
00401                         $tpltab->setCurrentBlock("tab");
00402                         if ($a_hl == $i)
00403                         {
00404                                 $tabtype = "tabactive";
00405                                 $tab = $tabtype;
00406                         }
00407                         else
00408                         {
00409                                 $tabtype = "tabinactive";
00410                                 $tab = "tab";
00411                         }
00412 
00413                         switch ($i)
00414                         {
00415                                 case 1:
00416                                 $txt = $lng->txt("view_content");
00417                                 break;
00418                                 case 2:
00419                                 $txt = $lng->txt("edit_properties");
00420                                 break;
00421                                 case 3:
00422                                 $txt = $lng->txt("perm_settings");
00423                                 break;
00424                                 case 4:
00425                                 $txt = $lng->txt("show_owner");
00426                                 break;
00427                         } // switch
00428                         $tpltab->setVariable("CONTENT", $txt);
00429                         $tpltab->setVariable("TABTYPE", $tabtype);
00430                         $tpltab->setVariable("TAB", $tab);
00431                         $tpltab->setVariable("LINK", $a_o["LINK".$i]);
00432                         $tpltab->parseCurrentBlock();
00433                 }
00434 
00435                 return $tpltab->get();
00436         }
00437 
00462         function getObjectsByOperations($a_type,$a_operation,$a_checkpath = true)
00463         {
00464                 global $ilDB, $rbacsystem, $tree;
00465                 
00466                 $objects = array();
00467                 
00468                 // return if root node ist not accessible
00469                 if ($a_checkpath === true and !$rbacsystem->checkAccess('read', ROOT_FOLDER_ID, $a_type))
00470                 {
00471                         return $objects;
00472                 }
00473 
00474                 // get all nodes of a_type that which are not deleted
00475                 $q = "SELECT * FROM tree ".
00476                      "LEFT JOIN object_reference ON tree.child=object_reference.ref_id ".
00477                          "LEFT JOIN object_data ON object_reference.obj_id=object_data.obj_id ".
00478                          "WHERE object_data.type = '".$a_type."' ".
00479                          "AND tree.tree = 1";
00480 
00481                 $r = $ilDB->query($q);
00482                 
00483                 // check the desired operation of all found nodes
00484                 while ($row = $r->fetchRow(DB_FETCHMODE_ASSOC))
00485                 {
00486                         if ($rbacsystem->checkAccess($a_operation, $row["ref_id"], $a_type))
00487                         {
00488                                 $objects[] = $row;
00489                         }
00490                 }
00491                 
00492                 // check access of nodes up in the tree for all accessible nodes
00493                 if ($a_checkpath === true)
00494                 {
00495                         $nodes_checked = array(ROOT_FOLDER_ID);
00496                         $nodes_passed = array(ROOT_FOLDER_ID);
00497 
00498                         foreach ($objects as $key => $node)
00499                         {
00500                                 $path = $tree->getPathId($node["ref_id"],ROOT_FOLDER_ID);
00501                                 
00502                                 array_push($nodes_checked,$node["ref_id"]);
00503                                 array_push($nodes_passed,$node["ref_id"]);
00504 
00505                                 if (($num = count($path)) > 2)
00506                                 {
00507                                     for ($i = 1; $i <= ($num - 2); $i++)
00508                                     {
00509 //echo "<br/>i:".$i;
00510                                                 if (in_array($path[$i],$nodes_passed))
00511                                                 {
00512 //echo "<br/>".$i." already passed";
00513                                                         continue;
00514                                                 }
00515                                                 
00516                                                 if (!in_array($path[$i],$nodes_checked))
00517                                                 {
00518                                                     array_push($nodes_checked,$path[$i]);
00519 //echo "<br/>".$i." add to checked";
00520                                                         if ($rbacsystem->checkAccess($a_operation, $path[$i], $a_type))
00521                                                         {
00522                                                             array_push($nodes_passed,$path[$i]);
00523 //echo "<br/>".$i." add to passed";
00524                                                         }
00525                                                         else
00526                                                         {
00527                                                                 unset($objects[$key]);
00528                                                                 // break for
00529                                                                 break;
00530                                                         }
00531                                                 }
00532                                         } // end for
00533                                 } // end if $num
00534 //var_dump("<pre>",$node["ref_id"],$path,$num,"</pre>");
00535                         } // end foreach
00536 //var_dump("<pre>",$nodes_checked,$nodes_passed,"</pre>");
00537                 }
00538                 
00539                 unset($nodes_checked);
00540                 unset($nodes_passed);
00541 
00542                 return $objects;
00543         }
00544 
00545 
00552         function checkFormEmpty ($emptyFields)
00553         {
00554 
00555                 $feedback = "";
00556 
00557                 foreach ($emptyFields as $key => $val)
00558                 {
00559                         if ($val == "") {
00560                                 if ($feedback != "") $feedback .= ", ";
00561                                 $feedback .= $key;
00562                         }
00563                 }
00564 
00565                 return $feedback;
00566         }
00567 
00590         function Linkbar ($AScript,$AHits,$ALimit,$AOffset,$AParams = array(),$ALayout = array())
00591         {
00592                 $LinkBar = "";
00593 
00594                 $layout_link = "";
00595                 $layout_prev = "&lt;&lt;";
00596                 $layout_next = "&gt;&gt;";
00597 
00598                 // layout options
00599                 if (count($ALayout > 0))
00600                 {
00601                         if ($ALayout["link"])
00602                         {
00603                                 $layout_link = " class=\"".$ALayout["link"]."\"";
00604                         }
00605 
00606                         if ($ALayout["prev"])
00607                         {
00608                                 $layout_prev = $ALayout["prev"];
00609                         }
00610 
00611                         if ($ALayout["next"])
00612                         {
00613                                 $layout_next = $ALayout["next"];
00614                         }
00615                 }
00616 
00617                 // Wenn Hits gr?sser Limit, zeige Links an
00618                 if ($AHits > $ALimit)
00619                 {
00620                         if (!empty($AParams))
00621                         {
00622                                 foreach ($AParams as $key => $value)
00623                                 {
00624                                         $params.= $key."=".$value."&";
00625                                 }
00626                         }
00627                         // if ($params) $params = substr($params,0,-1);
00628                         $link = $AScript."?".$params."offset=";
00629 
00630                         // ?bergehe "zurck"-link, wenn offset 0 ist.
00631                         if ($AOffset >= 1)
00632                         {
00633                                 $prevoffset = $AOffset - $ALimit;
00634                                 $LinkBar .= "<a".$layout_link." href=\"".$link.$prevoffset."\">".$layout_prev."&nbsp;</a>";
00635                         }
00636 
00637                         // Ben?tigte Seitenzahl kalkulieren
00638                         $pages=intval($AHits/$ALimit);
00639 
00640                         // Wenn ein Rest bleibt, addiere eine Seite
00641                         if (($AHits % $ALimit))
00642                         $pages++;
00643 
00644                         // Bei Offset = 0 keine Seitenzahlen anzeigen : DEAKTIVIERT
00645                         //                      if ($AOffset != 0) {
00646 
00647                         // ansonsten zeige Links zu den anderen Seiten an
00648                         for ($i = 1 ;$i <= $pages ; $i++)
00649                         {
00650                                 $newoffset=$ALimit*($i-1);
00651 
00652                                 if ($newoffset == $AOffset)
00653                                 {
00654                                         $LinkBar .= "<font color='Gray'>[<b>".$i."</b>]</font> ";
00655                                 }
00656                                 else
00657                                 {
00658                                         $LinkBar .= "[<a".$layout_link." href=\"".$link.$newoffset."\">$i</a>] ";
00659                                 }
00660                         }
00661                         //                      }
00662 
00663                         // Checken, ob letze Seite erreicht ist
00664                         // Wenn nicht, gebe einen "Weiter"-Link aus
00665                         if (! ( ($AOffset/$ALimit)==($pages-1) ) && ($pages!=1) )
00666                         {
00667                                 $newoffset=$AOffset+$ALimit;
00668                                 $LinkBar .= "<a".$layout_link." href=\"".$link.$newoffset."\">&nbsp;".$layout_next."</a>";
00669                         }
00670 
00671                         return $LinkBar;
00672                 }
00673                 else
00674                 {
00675                         return false;
00676                 }
00677         }
00678 
00687         function makeClickable($a_text)
00688         {
00689                 // URL mit ://-Angabe
00690                 $ret = eregi_replace("([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=-])",
00691                 "<a href=\"\\1://\\2\\3\" target=\"_blank\">\\1://\\2\\3</a>", $a_text);
00692 
00693                 // www-URL ohne ://-Angabe
00694                 $ret = eregi_replace("([[:space:]]+)(www\.)([[:alnum:]#?/&=\.-]+)",
00695                 "\\1<a href=\"http://\\2\\3\" target=\"_blank\">\\2\\3</a>", $ret);
00696 
00697                 // ftp-URL ohne ://-Angabe
00698                 $ret = eregi_replace("([[:space:]]+)(ftp\.)([[:alnum:]#?/&=\.-]+)",
00699                 "\\1<a href=\"ftp://\\2\\3\" target=\"_blank\">\\2\\3</a>", $ret);
00700 
00701                 // E-Mail
00702                 $ret = eregi_replace("(([a-z0-9_]|\\-|\\.)+@([^[:space:]]*)([[:alnum:]-]))",
00703                 "<a  href=\"mailto:\\1\">\\1</a>", $ret);
00704 
00705                 return($ret);
00706         }
00707 
00724         function StopWatch($begin = -1)
00725         {
00726                 $m = explode(" ",microtime());
00727                 $m = $m[0] + $m[1];
00728 
00729                 if ($begin != -1)
00730                 {
00731                         $m = $m - $begin;
00732                 }
00733 
00734                 return($m);
00735         }
00736 
00753         function makeDateSelect($prefix, $year = "", $month = "", $day = "", $startyear = "")
00754         {
00755                 global $lng;
00756 
00757                 if (!strlen("$year$month$day")) {
00758                         $now = getdate();
00759                         $year = $now["year"];
00760                         $month = $now["mon"];
00761                         $day = $now["mday"];
00762                 } else {
00763                         // delete leading zeros
00764                         $year = (int)$year;
00765                         $month = (int)$month;
00766                         $day = (int)$day;
00767                 }
00768 
00769                 // build day select
00770                 $sel_day .= "<select name=\"".$prefix."[d]\" id=\"".$prefix."_d\">\n";
00771 
00772                 for ($i = 1; $i <= 31; $i++)
00773                 {
00774                         $sel_day .= "<option value=\"$i\">" . sprintf("%02d", $i) . "</option>\n";
00775                 }
00776                 $sel_day .= "</select>\n";
00777                 $sel_day = preg_replace("/(value\=\"$day\")/", "$1 selected=\"selected\"", $sel_day);
00778 
00779                 // build month select
00780                 $sel_month .= "<select name=\"".$prefix."[m]\" id=\"".$prefix."_m\">\n";
00781 
00782                 for ($i = 1; $i <= 12; $i++)
00783                 {
00784                         $sel_month .= "<option value=\"$i\">" . $lng->txt("month_" . sprintf("%02d", $i) . "_long") . "</option>\n";
00785                 }
00786                 $sel_month .= "</select>\n";
00787                 $sel_month = preg_replace("/(value\=\"$month\")/", "$1 selected=\"selected\"", $sel_month);
00788 
00789                 // build year select
00790                 $sel_year .= "<select name=\"".$prefix."[y]\" id=\"".$prefix."_y\">\n";
00791                 if ((strlen($startyear) == 0) || ($startyear > $year))
00792                 {
00793                         $startyear = $year;
00794                 }
00795                 for ($i = $startyear; $i <= $year + 3; $i++)
00796                 {
00797                         $sel_year .= "<option value=\"$i\">" . sprintf("%04d", $i) . "</option>\n";
00798                 }
00799                 $sel_year .= "</select>\n";
00800                 $sel_year = preg_replace("/(value\=\"$year\")/", "$1 selected=\"selected\"", $sel_year);
00801 
00802                 $dateformat = $lng->text["lang_dateformat"];
00803                 $dateformat = strtolower(preg_replace("/\W/", "", $dateformat));
00804                 $dateformat = strtolower(preg_replace("/(\w)/", "%%$1", $dateformat));
00805                 $dateformat = preg_replace("/%%d/", $sel_day, $dateformat);
00806                 $dateformat = preg_replace("/%%m/", $sel_month, $dateformat);
00807                 $dateformat = preg_replace("/%%y/", $sel_year, $dateformat);
00808                 return $dateformat;
00809         }
00810 
00827         function makeTimeSelect($prefix, $short = true, $hour = "", $minute = "", $second = "")
00828         {
00829                 global $lng;
00830 
00831                 if (!strlen("$hour$minute$second")) {
00832                         $now = localtime();
00833                         $hour = $now[2];
00834                         $minute = $now[1];
00835                         $second = $now[0];
00836                 } else {
00837                         $hour = (int)$hour;
00838                         $minute = (int)$minute;
00839                         $second = (int)$second;
00840                 }
00841                 // build hour select
00842                 $sel_hour .= "<select name=\"".$prefix."[h]\" id=\"".$prefix."_h\">\n";
00843 
00844                 for ($i = 0; $i <= 23; $i++)
00845                 {
00846                         $sel_hour .= "<option value=\"$i\">" . sprintf("%02d", $i) . "</option>\n";
00847                 }
00848                 $sel_hour .= "</select>\n";
00849                 $sel_hour = preg_replace("/(value\=\"$hour\")/", "$1 selected=\"selected\"", $sel_hour);
00850 
00851                 // build minutes select
00852                 $sel_minute .= "<select name=\"".$prefix."[m]\" id=\"".$prefix."_m\">\n";
00853 
00854                 for ($i = 0; $i <= 59; $i++)
00855                 {
00856                         $sel_minute .= "<option value=\"$i\">" . sprintf("%02d", $i) . "</option>\n";
00857                 }
00858                 $sel_minute .= "</select>\n";
00859                 $sel_minute = preg_replace("/(value\=\"$minute\")/", "$1 selected=\"selected\"", $sel_minute);
00860 
00861                 if (!$short) {
00862                         // build seconds select
00863                         $sel_second .= "<select name=\"".$prefix."[s]\" id=\"".$prefix."_s\">\n";
00864 
00865                         for ($i = 0; $i <= 59; $i++)
00866                         {
00867                                 $sel_second .= "<option value=\"$i\">" . sprintf("%02d", $i) . "</option>\n";
00868                         }
00869                         $sel_second .= "</select>\n";
00870                         $sel_second = preg_replace("/(value\=\"$second\")/", "$1 selected=\"selected\"", $sel_second);
00871                 }
00872                 $timeformat = $lng->text["lang_timeformat"];
00873                 $timeformat = strtolower(preg_replace("/\W/", "", $timeformat));
00874                 $timeformat = preg_replace("/(\w)/", "%%$1", $timeformat);
00875                 $timeformat = preg_replace("/%%h/", $sel_hour, $timeformat);
00876                 $timeformat = preg_replace("/%%i/", $sel_minute, $timeformat);
00877                 if ($short) {
00878                         $timeformat = preg_replace("/%%s/", "", $timeformat);
00879                 } else {
00880                         $timeformat = preg_replace("/%%s/", $sel_second, $timeformat);
00881                 }
00882                 return $timeformat;
00883         }
00884 
00885         /*
00886         * This preg-based function checks whether an e-mail address is formally valid.
00887         * It works with all top level domains including the new ones (.biz, .info, .museum etc.)
00888         * and the special ones (.arpa, .int etc.)
00889         * as well as with e-mail addresses based on IPs (e.g. webmaster@123.45.123.45)
00890         * @author       Unknown <mail@philipp-louis.de> (source: http://www.php.net/preg_match)
00891         * @access       public
00892         * @param        string  email address
00893         * @return       boolean true if valid
00894         */
00895         function is_email($a_email)
00896         {
00897                 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));
00898         }
00899 
00900         /*
00901         * validates a password
00902         * @access       public
00903         * @param        string  password
00904         * @return       boolean true if valid
00905         */
00906         function isPassword($a_passwd)
00907         {
00908                 if (empty($a_passwd))
00909                 {
00910                         return false;
00911                 }
00912 
00913                 if (strlen($a_passwd) < 6)
00914                 {
00915                         return false;
00916                 }
00917                 // due to bug in php does not work
00918                 //if (!ereg("^[A-Za-z0-9_\.\+\-\*\@!\$\%\~]+$", $a_passwd)) 
00919 
00920                 if (!preg_match("/^[A-Za-z0-9_\.\+\?\#\-\*\@!\$\%\~]+$/", $a_passwd))
00921                 {
00922                         return false;
00923                 }
00924 
00925                 return true;
00926         }
00927 
00928         /*
00929         * validates a login
00930         * @access       public
00931         * @param        string  login
00932         * @return       boolean true if valid
00933         */
00934         function isLogin($a_login)
00935         {
00936                 if (empty($a_login))
00937                 {
00938                         return false;
00939                 }
00940 
00941                 if (strlen($a_login) < 4)
00942                 {
00943                         return false;
00944                 }
00945 
00946                 if (!ereg("^[A-Za-z0-9_\.\+-\*\@!\$\%\~]+$", $a_login))
00947                 {
00948                         return false;
00949                 }
00950 
00951                 return true;
00952         }
00953 
00964         function shortenText ($a_str, $a_len, $a_dots = "false")
00965         {
00966                 if (strlen($a_str) > $a_len)
00967                 {
00968 
00969                         $a_str = substr($a_str,0,$a_len);
00970 
00971                         if ($a_dots)
00972                         {
00973                                 $a_str .= "...";
00974                         }
00975                 }
00976 
00977                 return $a_str;
00978         }
00979 
00987         function attribsToArray($a_str)
00988         {
00989                 $attribs = array();
00990                 while (is_int(strpos($a_str, "=")))
00991                 {
00992                         $eq_pos = strpos($a_str, "=");
00993                         $qu1_pos = strpos($a_str, "\"");
00994                         $qu2_pos = strpos(substr($a_str, $qu1_pos + 1), "\"") + $qu1_pos + 1;
00995                         if (is_int($eq_pos) && is_int($qu1_pos) && is_int($qu2_pos))
00996                         {
00997                                 $var = trim(substr($a_str, 0, $eq_pos));
00998                                 $val = trim(substr($a_str, $qu1_pos + 1, ($qu2_pos - $qu1_pos) - 1));
00999                                 $attribs[$var] = $val;
01000                                 $a_str = substr($a_str, $qu2_pos + 1);
01001                         }
01002                         else
01003                         {
01004                                 $a_str = "";
01005                         }
01006                 }
01007                 return $attribs;
01008         }
01009 
01018         function rCopy ($a_sdir, $a_tdir)
01019         {
01020                 // check if arguments are directories
01021                 if (!@is_dir($a_sdir) or
01022                 !@is_dir($a_tdir))
01023                 {
01024                         return FALSE;
01025                 }
01026 
01027                 // read a_sdir, copy files and copy directories recursively
01028                 $dir = opendir($a_sdir);
01029 
01030                 while($file = readdir($dir))
01031                 {
01032                         if ($file != "." and
01033                         $file != "..")
01034                         {
01035                                 // directories
01036                                 if (@is_dir($a_sdir."/".$file))
01037                                 {
01038                                         if (!@is_dir($a_tdir."/".$file))
01039                                         {
01040                                                 if (!ilUtil::makeDir($a_tdir."/".$file))
01041                                                 return FALSE;
01042 
01043                                                 //chmod($a_tdir."/".$file, 0775);
01044                                         }
01045 
01046                                         if (!ilUtil::rCopy($a_sdir."/".$file,$a_tdir."/".$file))
01047                                         {
01048                                                 return FALSE;
01049                                         }
01050                                 }
01051 
01052                                 // files
01053                                 if (@is_file($a_sdir."/".$file))
01054                                 {
01055                                         if (!copy($a_sdir."/".$file,$a_tdir."/".$file))
01056                                         {
01057                                                 return FALSE;
01058                                         }
01059                                 }
01060                         }
01061                 }
01062                 return TRUE;
01063         }
01064 
01072         function getWebspaceDir($mode = "filesystem")
01073         {
01074                 global $ilias;
01075 
01076                 if ($mode == "filesystem")
01077                 {
01078                         return "./".ILIAS_WEB_DIR."/".$ilias->client_id;
01079                 }
01080                 else
01081                 {
01082                         if (defined("ILIAS_MODULE"))
01083                         {
01084                                 return "../".ILIAS_WEB_DIR."/".$ilias->client_id;
01085                         }
01086                         else
01087                         {
01088                                 return "./".ILIAS_WEB_DIR."/".$ilias->client_id;
01089                         }
01090                 }
01091 
01092                 //return $ilias->ini->readVariable("server","webspace_dir");
01093         }
01094 
01098         function getDataDir()
01099         {
01100                 return CLIENT_DATA_DIR;
01101                 //global $ilias;
01102 
01103                 //return $ilias->ini->readVariable("server", "data_dir");
01104         }
01105 
01113         function getUsersOnline($a_user_id = 0)
01114         {
01115                 global $ilias;
01116 
01117                 if ($a_user_id == 0)
01118                 {
01119                         $where = "WHERE user_id != 0";
01120                 }
01121                 else
01122                 {
01123                         $where = "WHERE user_id = '".$a_user_id."'";
01124                 }
01125 
01126                 $q = "SELECT count(user_id) as num,user_id,data,firstname,lastname,title,login,last_login FROM usr_session ".
01127                 "LEFT JOIN usr_data ON user_id=usr_id ".$where.
01128                 " AND expires>UNIX_TIMESTAMP() ".
01129                 "GROUP BY user_id ".
01130                 "ORDER BY lastname, firstname";
01131                 $r = $ilias->db->query($q);
01132 
01133                 while ($user = $r->fetchRow(DB_FETCHMODE_ASSOC))
01134                 {
01135                         $users[$user["user_id"]] = $user;
01136                 }
01137 
01138                 return $users ? $users : array();
01139         }
01140 
01149         function getAssociatedUsersOnline($a_user_id)
01150         {
01151                 global $ilias;
01152 
01153                 // The difference between active time and session time
01154                 $time_diff = 0;
01155 
01156                 // Get a list of object id's of all courses and groups for which
01157                 // the current user has local roles.
01158                 // Note: we have to use DISTINCT here, because a user may assume
01159                 // multiple roles in a group or a course.
01160                 $q = "SELECT DISTINCT dat.obj_id as obj_id ".
01161                 "FROM rbac_ua AS ua ".
01162                 "JOIN rbac_fa AS fa ON fa.rol_id = ua.rol_id ".
01163                 "JOIN object_reference AS r1 ON r1.ref_id = fa.parent ".
01164                 "JOIN tree ON tree.child = r1.ref_id ".
01165                 "JOIN object_reference AS r2 ON r2.ref_id = tree.parent ".
01166                 "JOIN object_data AS dat ON dat.obj_id = r2.obj_id ".
01167                 "WHERE ua.usr_id = ".$a_user_id." ".
01168                 "AND fa.assign = 'y' ".
01169                 "AND dat.type IN ('grp','crs')";
01170                 $r = $ilias->db->query($q);
01171                 while ($row = $r->fetchRow(DB_FETCHMODE_ASSOC))
01172                 {
01173                         $groups_and_courses_of_user[] = $row["obj_id"];
01174                 }
01175 
01176                 // If the user is not in a course or a group, he has no associated users.
01177                 if (count($groups_and_courses_of_user) == 0) 
01178                 {
01179                         $q = "SELECT count(user_id) as num,user_id,data,firstname,lastname,title,login,last_login ".
01180                         "FROM usr_session ".
01181                         "JOIN usr_data ON user_id=usr_id ".
01182                         "WHERE user_id = ".$a_user_id." ".
01183                         "AND expires > UNIX_TIMESTAMP() - ".$time_diff." ".
01184                         "GROUP BY user_id";
01185                 }
01186                 else
01187                 {
01188                         $q = "SELECT count(user_id) as num,s.user_id,s.data,ud.firstname,ud.lastname,ud.title,ud.login,ud.last_login ".
01189                         "FROM usr_session AS s ".
01190                         "JOIN usr_data AS ud ON ud.usr_id = s.user_id ".
01191                         "JOIN rbac_ua AS ua ON ua.usr_id = s.user_id ".
01192                         "JOIN rbac_fa AS fa ON fa.rol_id = ua.rol_id ".
01193                         "JOIN tree ON tree.child = fa.parent ".
01194                         "JOIN object_reference AS or1 ON or1.ref_id = tree.parent ".
01195                         "JOIN object_data AS od ON od.obj_id = or1.obj_id ".
01196                         "WHERE s.user_id != 0 ".
01197                         "AND s.expires > UNIX_TIMESTAMP() - ".$time_diff." ".
01198                         "AND fa.assign = 'y' ".
01199                         "AND od.obj_id IN (".implode(",",$groups_and_courses_of_user).") ".
01200                         "GROUP BY s.user_id ".
01201                         "ORDER BY ud.lastname, ud.firstname";
01202                 }
01203                 $r = $ilias->db->query($q);
01204 
01205                 while ($user = $r->fetchRow(DB_FETCHMODE_ASSOC))
01206                 {
01207                         $users[$user["user_id"]] = $user;
01208                 }
01209 
01210                 return $users ? $users : array();
01211         }
01212 
01218         function ilTempnam()
01219         {
01220                 $temp_path = ilUtil::getDataDir() . "/temp";
01221                 if (!is_dir($temp_path))
01222                 {
01223                         ilUtil::createDirectory($temp_path);
01224                 }
01225                 $temp_name = tempnam($temp_path, "tmp");
01226                 // --->
01227                 // added the following line because tempnam creates a backslash on some
01228                 // Windows systems which leads to problems, because the "...\tmp..." can be
01229                 // interpreted as "...{TAB-CHARACTER}...". The normal slash works fine
01230                 // even under windows (Helmut Schottmüller, 2005-08-31)
01231                 $temp_name = str_replace("\\", "/", $temp_name);
01232                 // --->
01233                 unlink($temp_name);
01234                 return $temp_name;
01235         }
01236 
01242         function createDirectory($a_dir, $a_mod = 0755)
01243         {
01244                 ilUtil::makeDir($a_dir);
01245                 //@mkdir($a_dir);
01246                 //@chmod($a_dir, $a_mod);
01247         }
01248 
01249 
01256         function unzip($a_file, $overwrite = false)
01257         {
01258                 //global $ilias;
01259 
01260                 $pathinfo = pathinfo($a_file);
01261                 $dir = $pathinfo["dirname"];
01262                 $file = $pathinfo["basename"];
01263 
01264                 // unzip
01265                 $cdir = getcwd();
01266                 chdir($dir);
01267                 $unzip = PATH_TO_UNZIP;
01268                 //$unzip = $ilias->getSetting("unzip_path");
01269 
01270                 // workaround for unzip problem (unzip of subdirectories fails, so
01271                 // we create the subdirectories ourselves first)
01272                 // get list
01273                 $unzipcmd = $unzip." -Z -1 ".ilUtil::escapeShellArg($file);
01274                 exec($unzipcmd, $arr);
01275                 $zdirs = array();
01276 
01277                 foreach($arr as $line)
01278                 {
01279                         if(is_int(strpos($line, "/")))
01280                         {
01281                                 $zdir = substr($line, 0, strrpos($line, "/"));
01282                                 $nr = substr_count($zdir, "/");
01283                                 //echo $zdir." ".$nr."<br>";
01284                                 while ($zdir != "")
01285                                 {
01286                                         $nr = substr_count($zdir, "/");
01287                                         $zdirs[$zdir] = $nr;                            // collect directories
01288                                         //echo $dir." ".$nr."<br>";
01289                                         $zdir = substr($zdir, 0, strrpos($zdir, "/"));
01290                                 }
01291                         }
01292                 }
01293 
01294                 asort($zdirs);
01295 
01296                 foreach($zdirs as $zdir => $nr)                         // create directories
01297                 {
01298                         ilUtil::createDirectory($zdir);
01299                 }
01300 
01301                 // real unzip
01302                 if ($overvwrite) 
01303                 {
01304                         $unzipcmd = $unzip." ".ilUtil::escapeShellArg($file);
01305                 }
01306                 else
01307                 {
01308                         $unzipcmd = $unzip." -o ".ilUtil::escapeShellArg($file);
01309                 }
01310                 exec($unzipcmd);
01311 
01312                 chdir($cdir);
01313         }
01314 
01318         function zip($a_dir, $a_file)
01319         {
01320                 //global $ilias;
01321 
01322                 $cdir = getcwd();
01323 
01324                 $pathinfo = pathinfo($a_file);
01325                 $dir = $pathinfo["dirname"];
01326                 $file = $pathinfo["basename"];
01327 
01328                 // unzip
01329                 $cdir = getcwd();
01330                 chdir($dir);
01331 
01332                 $zip = PATH_TO_ZIP;
01333                 //$zip = $ilias->getSetting("zip_path");
01334 
01335                 if (is_array($a_dir))
01336                 {
01337                         $source = "";
01338                         foreach($a_dir as $dir)
01339                         {
01340                                 $name = basename($dir);
01341                                 $source.= " ".ilUtil::escapeShellArg($name);
01342                         }
01343                 }
01344                 else
01345                 {
01346                         $name = basename($a_dir);
01347                         $source = ilUtil::escapeShellArg($name);
01348                 }
01349 
01350                 $zipcmd = $zip." -r ".ilUtil::escapeShellArg($a_file)." ".$source;
01351                 exec($zipcmd);
01352 //echo htmlentities($zipcmd);
01353                 chdir($cdir);
01354         }
01355 
01359         function getConvertCmd()
01360         {
01361                 return PATH_TO_CONVERT;
01362                 //global $ilias;
01363 
01364                 //return $ilias->getSetting("convert_path");
01365         }
01366 
01374         function convertImage($a_from, $a_to, $a_target_format = "", $a_geometry = "")
01375         {
01376                 $format_str = ($a_target_format != "")
01377                 ? strtoupper($a_target_format).":"
01378                 : "";
01379                 $geometry = ($a_geometry != "")
01380                 ? " -geometry ".$a_geometry."x".$a_geometry." "
01381                 : "";
01382                 $convert_cmd = ilUtil::getConvertCmd()." ".
01383                 ilUtil::escapeShellArg($a_from)." ".$geometry.ilUtil::escapeShellArg($format_str.$a_to);
01384                 system($convert_cmd);
01385         }
01386 
01395         function resizeImage($a_from, $a_to, $a_width, $a_height)
01396         {
01397                 $size = " -resize ".$a_width."x".$a_height."! ";
01398                 $convert_cmd = ilUtil::getConvertCmd()." ".
01399                         ilUtil::escapeShellArg($a_from)." ".$size.ilUtil::escapeShellArg($a_to);
01400                 system($convert_cmd);
01401         }
01402 
01408         function html2pdf($html, $pdf_file)
01409         {
01410                 //global $ilias;
01411 
01412                 $html_file = str_replace(".pdf",".html",$pdf_file);
01413 
01414                 $fp = fopen( $html_file ,"wb");
01415                 fwrite($fp, $html);
01416                 fclose($fp);
01417 
01418                 $htmldoc_path = PATH_TO_HTMLDOC;
01419                 //$htmldoc_path = $ilias->getSetting("htmldoc_path");
01420 
01421                 $htmldoc = $htmldoc_path." ";
01422                 $htmldoc .= "--no-toc ";
01423                 $htmldoc .= "--no-jpeg ";
01424                 $htmldoc .= "--webpage ";
01425                 $htmldoc .= "--outfile " . ilUtil::escapeShellArg($pdf_file) . " ";
01426                 $htmldoc .= "--bodyfont Arial ";
01427                 $htmldoc .= "--charset iso-8859-15 ";
01428                 $htmldoc .= "--color ";
01429                 $htmldoc .= "--size A4  ";      // --landscape
01430                 $htmldoc .= "--format pdf ";
01431                 $htmldoc .= "--footer ... ";
01432                 $htmldoc .= "--header ... ";
01433                 $htmldoc .= "--left 60 ";
01434                 // $htmldoc .= "--right 200 ";
01435                 $htmldoc .= $html_file;
01436                 exec($htmldoc);
01437 
01438         }
01439 
01443         function deliverData($a_data, $a_filename, $mime = "application/octet-stream", $charset = "")
01444         {
01445                 $disposition = "attachment"; // "inline" to view file in browser or "attachment" to download to hard disk
01446                 //              $mime = "application/octet-stream"; // or whatever the mime type is
01447 
01448                 if (isset($_SERVER["HTTPS"])) {
01449 
01450                         // Added different handling for IE and HTTPS => send pragma after content informations
01454                         #header("Pragma: ");
01455                         #header("Cache-Control: ");
01456                         #header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
01457                         #header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
01458                         #header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
01459                         #header("Cache-Control: post-check=0, pre-check=0", false);
01460                 }
01461                 else if ($disposition == "attachment")
01462                 {
01463                         header("Cache-control: private");
01464                 }
01465                 else
01466                 {
01467                         header("Cache-Control: no-cache, must-revalidate");
01468                         header("Pragma: no-cache");
01469                 }
01470 
01471                 $ascii_filename = ilUtil::getASCIIFilename($a_filename);
01472 
01473                 if (strlen($charset))
01474                 {
01475                         $charset = "; charset=$charset";
01476                 }
01477                 header("Content-Type: $mime$charset");
01478                 header("Content-Disposition:$disposition; filename=\"".$ascii_filename."\"");
01479                 header("Content-Description: ".$ascii_filename);
01480                 header("Content-Length: ".(string)(strlen($a_data)));
01481 
01482                 if($_SERVER['HTTPS'])
01483                 {
01484             header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
01485             header('Pragma: public');   
01486                 }
01487 
01488                 header("Connection: close");
01489                 echo $a_data;
01490                 exit;
01491         }
01492 
01496         function deliverFile($a_file, $a_filename)
01497         {
01498                 $disposition = "attachment"; // "inline" to view file in browser or "attachment" to download to hard disk
01499                 $mime = "application/octet-stream"; // or whatever the mime type is
01500 
01501                 if (isset($_SERVER["HTTPS"]))
01502                 {
01503                         // Added different handling for IE and HTTPS => send pragma after content informations
01504 
01508                         #header("Pragma: ");
01509                         #header("Pragma: no-cache");
01510                         #header("Cache-Control: ");
01511                         #header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
01512                         #header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
01513                         #header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
01514                         ##header("Cache-Control: post-check=0, pre-check=0", false);
01515                 }
01516                 else if ($disposition == "attachment")
01517                 {
01518                         header("Cache-control: private");
01519                 }
01520                 else
01521                 {
01522                         header("Cache-Control: no-cache, must-revalidate");
01523                         header("Pragma: no-cache");
01524                 }
01525 
01526                 $ascii_filename = ilUtil::getASCIIFilename($a_filename);
01527 
01528                 header("Content-Type: $mime");
01529                 header("Content-Disposition:$disposition; filename=\"".$ascii_filename."\"");
01530                 header("Content-Description: ".$ascii_filename);
01531                 header("Content-Length: ".(string)(filesize($a_file)));
01532 
01533                 if($_SERVER['HTTPS'])
01534                 {
01535             header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
01536             header('Pragma: public');   
01537                 }
01538 
01539                 header("Connection: close");
01540                 ilUtil::readFile( $a_file );
01541                 exit;
01542         }
01543         
01544         
01551         function readFile($a_file)
01552         {
01553                 $chunksize = 1*(1024*1024); // how many bytes per chunk
01554                 $buffer = '';
01555                 $handle = fopen($a_file, 'rb');
01556                 if ($handle === false)
01557                 {
01558                         return false;
01559                 }
01560                 while (!feof($handle))
01561                 {
01562                         $buffer = fread($handle, $chunksize);
01563                         print $buffer;
01564                 }
01565                 return fclose($handle); 
01566         }
01567 
01573         function getASCIIFilename($a_filename)
01574         {
01575                 // The filename must be converted to ASCII, as of RFC 2183,
01576                 // section 2.3.
01577                 // Despite the RFC, Internet Explorer on Windows supports
01578                 // ISO 8895-1 encoding for the file name. We use this fact, to
01579                 // produce a better result, if the user uses IE.
01580 
01592 
01593                 $user_agent = strtolower($_SERVER["HTTP_USER_AGENT"]);
01594                 if ((is_integer(strpos($user_agent, "msie"))) && is_integer(strpos($user_agent, "win")))
01595                 {
01598 
01599                         $ascii_filename = utf8_decode($a_filename);
01600                 }
01601                 else
01602                 {
01605 
01606                         $ascii_filename = htmlentities($a_filename,ENT_NOQUOTES,'UTF-8');
01607                         $ascii_filename = preg_replace('/\&(.)[^;]*;/','\\1', $ascii_filename);
01608                         $ascii_filename = preg_replace('/[\x7f-\xff]/','_', $ascii_filename);
01609                 }
01610 
01611                 // Windows does not allow the following characters in filenames:
01612                 // \/:*?"<>|
01613                 if (is_integer(strpos($user_agent, "win")))
01614                 {
01615                         $ascii_filename = preg_replace('/[:\x5c\/\*\?\"<>\|]/','_', $ascii_filename);
01616                 }
01617 
01618                 return $ascii_filename;
01619         }
01620 
01624         function getJavaPath()
01625         {
01626                 return PATH_TO_JAVA;
01627                 //global $ilias;
01628 
01629                 //return $ilias->getSetting("java_path");
01630         }
01631 
01636         function appendUrlParameterString($a_url, $a_par)
01637         {
01638                 $url = (is_int(strpos($a_url, "?")))
01639                 ? $a_url."&".$a_par
01640                 : $a_url."?".$a_par;
01641 
01642                 return $url;
01643         }
01644 
01659         function makeDir($a_dir)
01660         {
01661                 $a_dir = trim($a_dir);
01662 
01663                 // remove trailing slash (bugfix for php 4.2.x)
01664                 if (substr($a_dir,-1) == "/")
01665                 {
01666                         $a_dir = substr($a_dir,0,-1);
01667                 }
01668 
01669                 // check if a_dir comes with a path
01670                 if (!($path = substr($a_dir,0, strrpos($a_dir,"/") - strlen($a_dir))))
01671                 {
01672                         $path = ".";
01673                 }
01674 
01675                 // create directory with file permissions of parent directory
01676                 umask(0000);
01677                 return @mkdir($a_dir,fileperms($path));
01678         }
01679 
01680 
01693         function makeDirParents($a_dir)
01694         {
01695                 $dirs = array($a_dir);
01696                 $a_dir = dirname($a_dir);
01697                 $last_dirname = '';
01698                 while($last_dirname != $a_dir)
01699                 {
01700                         array_unshift($dirs, $a_dir);
01701                         $last_dirname = $a_dir;
01702                         $a_dir = dirname($a_dir);
01703                 }
01704 
01705                 // find the first existing dir
01706                 $reverse_paths = array_reverse($dirs, TRUE);
01707                 $found_index = -1;
01708                 foreach ($reverse_paths as $key => $value)
01709                 {
01710                         if ($found_index == -1)
01711                         {
01712                                 if (is_dir($value))
01713                                 {
01714                                         $found_index = $key;
01715                                 }
01716                         }
01717                 }
01718                 
01719                 umask(0000);
01720                 foreach ($dirs as $dirindex => $dir)
01721                 {
01722                         // starting with the longest existing path
01723                         if ($dirindex >= $found_index) 
01724                         {
01725                                 if (! file_exists($dir))
01726                                 {
01727                                         if (! mkdir($dir, $umask))
01728                                         {
01729                                                 error_log("Can't make directory: $dir");
01730                                                 return false;
01731                                         }
01732                                 }
01733                                 elseif (! is_dir($dir))
01734                                 {
01735                                         error_log("$dir is not a directory");
01736                                         return false;
01737                                 }
01738                                 else
01739                                 {
01740                                         // get umask of the last existing parent directory
01741                                         $umask = fileperms($dir);
01742                                 }
01743                         }
01744                 }
01745                 return true;
01746         }
01747 
01755         function delDir($a_dir)
01756         {
01757                 if (!is_dir($a_dir) || is_int(strpos($a_dir, "..")))
01758                 {
01759                         return;
01760                 }
01761 
01762                 $current_dir = opendir($a_dir);
01763 
01764                 $files = array();
01765                 
01766                 // this extra loop has been necessary because of a strange bug
01767                 // at least on MacOS X. A looped readdir() didn't work
01768                 // correctly with larger directories 
01769                 // when an unlink happened inside the loop. Getting all files
01770                 // into the memory first solved the problem.
01771                 while($entryname = readdir($current_dir))
01772                 {
01773                         $files[] = $entryname;
01774                 }
01775                 
01776                 foreach($files as $file)
01777                 {
01778                         if(is_dir($a_dir."/".$file) and ($file != "." and $file!=".."))
01779                         {
01780                                 ilUtil::delDir(${a_dir}."/".${file});
01781                         }
01782                         elseif ($file != "." and $file != "..")
01783                         {
01784                                 unlink(${a_dir}."/".${file});
01785                         }
01786                 }
01787 
01788                 closedir($current_dir);
01789                 rmdir(${a_dir});
01790         }
01791 
01792 
01796         function getDir($a_dir)
01797         {
01798                 $current_dir = opendir($a_dir);
01799 
01800                 $dirs = array();
01801                 $files = array();
01802                 while($entry = readdir($current_dir))
01803                 {
01804                         if(is_dir($a_dir."/".$entry))
01805                         {
01806                                 $dirs[$entry] = array("type" => "dir", "entry" => $entry);
01807                         }
01808                         else
01809                         {
01810                                 $size = filesize($a_dir."/".$entry);
01811                                 $files[$entry] = array("type" => "file", "entry" => $entry,
01812                                 "size" => $size);
01813                         }
01814                 }
01815                 ksort($dirs);
01816                 ksort($files);
01817 
01818                 return array_merge($dirs, $files);
01819         }
01820 
01821 
01829         function getGroupId($a_parent_ref)
01830         {
01831                 return false;
01832 
01833                 global $ilias;
01834 
01835                 $q = "SELECT DISTINCT tree FROM grp_tree WHERE child='".$a_parent_ref."'";
01836                 $r = $ilias->db->query($q);
01837                 $row = $r->fetchRow();
01838 
01839                 return $row[0] ? $row[0] : false;
01840         }
01841 
01847         function stripSlashes($a_str, $a_strip_html = true, $a_allow = "")
01848         {
01849                 if (ini_get("magic_quotes_gpc"))
01850                 {
01851                         $a_str = stripslashes($a_str);
01852                 }
01853 
01854                 // set default allowed tags
01855                 if ($a_allow == "")
01856                 {
01857                         $a_allow = "<b><i><strong><em><code><cite><gap><sub><sup><pre><strike>";
01858                 }
01859 
01860                 if ($a_strip_html)
01861                 {
01862                         $a_str = ilUtil::stripScriptHTML($a_str, $a_allow);
01863                 }
01864 
01865                 return $a_str;
01866         }
01867 
01868 
01880         function stripScriptHTML($a_str, $a_allow = "", $a_rm_js = true)
01881         {
01882                 //$a_str = strip_tags($a_str, $a_allow);
01883 
01884                 $negativestr = "a,abbr,acronym,address,applet,area,b,base,basefont,".
01885                         "bdo,big,blockquote,body,br,button,caption,center,cite,code,col,".
01886                         "colgroup,dd,del,dfn,dir,div,dl,dt,em,fieldset,font,form,frame,".
01887                         "frameset,h1,h2,h3,h4,h5,h6,head,hr,html,i,iframe,img,input,ins,isindex,kbd,".
01888                         "label,legend,li,link,map,menu,meta,noframes,noscript,object,ol,".
01889                         "optgroup,option,p,param,q,s,samp,script,select,small,span,".
01890                         "strike,strong,style,sub,sup,table,tbody,td,textarea,tfoot,th,thead,".
01891                         "title,tr,tt,u,ul,var";
01892                 $a_allow = strtolower ($a_allow);
01893                 $negatives = split (",",$negativestr);
01894                 foreach ($negatives as $item)
01895                 {
01896                         $pos = strpos($a_allow, "<$item>");
01897 
01898                         // remove complete tag, if not allowed
01899                         if ($pos === false)
01900                         {
01901                                 $old_str = "";
01902                                 while($old_str != $a_str)
01903                                 {
01904                                         $old_str = $a_str;
01905                                         $a_str = preg_replace("/<\/?\s*$item(\/?)\s*>/i", "", $a_str);
01906                                         $a_str = preg_replace("/<\/?\s*$item(\/?)\s+([^>]*)>/i", "", $a_str);
01907                                 }
01908                         }
01909                 }
01910                 
01911                 if ($a_rm_js)
01912                 {
01913                         // remove all attributes if an "on..." attribute is given
01914                         $a_str = preg_replace("/<\s*\w*(\/?)(\s+[^>]*)?(\s+on[^>]*)>/i", "", $a_str);
01915 
01916                         // remove all attributes if a "javascript" is within tag
01917                         $a_str = preg_replace("/<\s*\w*(\/?)\s+[^>]*javascript[^>]*>/i", "", $a_str);
01918                         
01919                         // remove all attributes if an "expression" is within tag
01920                         // (IE allows something like <b style='width:expression(alert(1))'>test</b>)
01921                         $a_str = preg_replace("/<\s*\w*(\/?)\s+[^>]*expression[^>]*>/i", "", $a_str);
01922                 }
01923 
01924                 return $a_str;
01925         }
01926 
01927 
01933         function addSlashes($a_str)
01934         {
01935                 if (ini_get("magic_quotes_gpc"))
01936                 {
01937                         return $a_str;
01938                 }
01939                 else
01940                 {
01941                         return addslashes($a_str);
01942                 }
01943         }
01944 
01954         function prepareFormOutput($a_str, $a_strip = false)
01955         {
01956                 if($a_strip)
01957                 {
01958                         $a_str = ilUtil::stripSlashes($a_str);
01959                 }
01960                 return htmlspecialchars($a_str);
01961         }
01962 
01963 
01971         function prepareDBString($a_str)
01972         {
01973                 return addslashes($a_str);
01974         }
01975 
01976 
01983         function removeItemFromDesktops($a_id)
01984         {
01985                 global $ilias;
01986 
01987                 $q = "SELECT user_id FROM desktop_item WHERE item_id = '".$a_id."'";
01988                 $r = $ilias->db->query($q);
01989 
01990                 $users = array();
01991 
01992                 while ($row = $r->fetchRow(DB_FETCHMODE_OBJECT))
01993                 {
01994                         $users[] = $row->user_id;
01995                 } // while
01996 
01997                 if (count($users) > 0)
01998                 {
01999                         $q = "DELETE FROM desktop_item WHERE item_id = '".$a_id."'";
02000                         $ilias->db->query($q);
02001                 }
02002 
02003                 return $users;
02004         }
02005 
02006 
02014         function extractParameterString($a_parstr)
02015         {
02016                 // parse parameters in array
02017                 $par = array();
02018                 $ok=true;
02019                 while(($spos=strpos($a_parstr,"=")) && $ok)
02020                 {
02021                         // extract parameter
02022                         $cpar = substr($a_parstr,0,$spos);
02023                         $a_parstr = substr($a_parstr,$spos,strlen($a_parstr)-$spos);
02024                         while(substr($cpar,0,1)=="," ||substr($cpar,0,1)==" " || substr($cpar,0,1)==chr(13) || substr($cpar,0,1)==chr(10))
02025                         $cpar = substr($cpar,1,strlen($cpar)-1);
02026                         while(substr($cpar,strlen($cpar)-1,1)==" " || substr($cpar,strlen($cpar)-1,1)==chr(13) || substr($cpar,strlen($cpar)-1,1)==chr(10))
02027                         $cpar = substr($cpar,0,strlen($cpar)-1);
02028 
02029                         // extract value
02030                         if($spos=strpos($a_parstr,"\""))
02031                         {
02032                                 $a_parstr = substr($a_parstr,$spos+1,strlen($a_parstr)-$spos);
02033                                 $spos=strpos($a_parstr,"\"");
02034                                 if(is_int($spos))
02035                                 {
02036                                         $cval = substr($a_parstr,0,$spos);
02037                                         $par[$cpar]=$cval;
02038                                         $a_parstr = substr($a_parstr,$spos+1,strlen($a_parstr)-$spos-1);
02039                                 }
02040                                 else
02041                                 $ok=false;
02042                         }
02043                         else
02044                         $ok=false;
02045                 }
02046 
02047                 if($ok) return $par; else return false;
02048         }
02049 
02050         function assembleParameterString($a_par_arr)
02051         {
02052                 if (is_array($a_par_arr))
02053                 {
02054                         $target_arr = array();
02055                         foreach ($a_par_arr as $par => $val)
02056                         {
02057                                 $target_arr[] = "$par=\"$val\"";
02058                         }
02059                         $target_str = implode(", ", $target_arr);
02060                 }
02061 
02062                 return $target_str;
02063         }
02064 
02068         function dumpString($a_str)
02069         {
02070                 $ret = $a_str.": ";
02071                 for($i=0; $i<strlen($a_str); $i++)
02072                 {
02073                         $ret.= ord(substr($a_str,$i,1))." ";
02074                 }
02075                 return $ret;
02076         }
02077 
02078 
02082         function yn2tf($a_yn)
02083         {
02084                 if(strtolower($a_yn) == "y")
02085                 {
02086                         return true;
02087                 }
02088                 else
02089                 {
02090                         return false;
02091                 }
02092         }
02093 
02097         function tf2yn($a_tf)
02098         {
02099                 if($a_tf)
02100                 {
02101                         return "y";
02102                 }
02103                 else
02104                 {
02105                         return "n";
02106                 }
02107         }
02108 
02117         function sort_func ($a, $b)
02118         {
02119                 global $array_sortby,$array_sortorder;
02120 
02121                 if ($array_sortorder == "asc")
02122                 {
02123                         return strcasecmp($a[$array_sortby], $b[$array_sortby]);
02124                 }
02125 
02126                 if ($array_sortorder == "desc")
02127                 {
02128                         return strcasecmp($b[$array_sortby], $a[$array_sortby]);
02129                 }
02130         }
02131 
02140         function sort_func_numeric ($a, $b)
02141         {
02142                 global $array_sortby,$array_sortorder;
02143 
02144                 if ($array_sortorder == "asc")
02145                 {
02146                         return $a["$array_sortby"] > $b["$array_sortby"];
02147                 }
02148 
02149                 if ($array_sortorder == "desc")
02150                 {
02151                         return $a["$array_sortby"] < $b["$array_sortby"];
02152                 }
02153         }
02164         function sortArray($array,$a_array_sortby,$a_array_sortorder = 0,$a_numeric = false)
02165         {
02166                 global $array_sortby,$array_sortorder;
02167 
02168                 $array_sortby = $a_array_sortby;
02169 
02170                 if ($a_array_sortorder == "desc")
02171                 {
02172                         $array_sortorder = "desc";
02173                 }
02174                 else
02175                 {
02176                         $array_sortorder = "asc";
02177                 }
02178                 if($a_numeric)
02179                 {
02180                         usort($array, array("ilUtil", "sort_func_numeric"));
02181                 }
02182                 else
02183                 {
02184                         usort($array, array("ilUtil", "sort_func"));
02185                 }
02186                 //usort($array,"ilUtil::sort_func");
02187 
02188                 return $array;
02189         }
02190 
02200         function unique_multi_array($array, $sub_key)
02201         {
02202                 $target = array();
02203                 $existing_sub_key_values = array();
02204 
02205                 foreach ($array as $key=>$sub_array)
02206                 {
02207                         if (!in_array($sub_array[$sub_key], $existing_sub_key_values))
02208                         {
02209                                 $existing_sub_key_values[] = $sub_array[$sub_key];
02210                                 $target[$key] = $sub_array;
02211                         }
02212                 }
02213 
02214                 return $target;
02215         }
02216 
02217 
02225         function getGDSupportedImageType($a_desired_type)
02226         {
02227                 $a_desired_type = strtolower($a_desired_type);
02228                 // get supported Image Types
02229                 $im_types = ImageTypes();
02230 
02231                 switch($a_desired_type)
02232                 {
02233                         case "jpg":
02234                         if ($im_types & IMG_JPG) return "jpg";
02235                         if ($im_types & IMG_GIF) return "gif";
02236                         if ($im_types & IMG_PNG) return "png";
02237                         break;
02238 
02239                         case "gif":
02240                         if ($im_types & IMG_GIF) return "gif";
02241                         if ($im_types & IMG_JPG) return "jpg";
02242                         if ($im_types & IMG_PNG) return "png";
02243                         break;
02244 
02245                         case "png":
02246                         if ($im_types & IMG_PNG) return "png";
02247                         if ($im_types & IMG_JPG) return "jpg";
02248                         if ($im_types & IMG_GIF) return "gif";
02249                         break;
02250                 }
02251 
02252                 return "";
02253         }
02254 
02262         function deducibleSize($a_mime)
02263         {
02264                 if (($a_mime == "image/gif") || ($a_mime == "image/jpeg") ||
02265                 ($a_mime == "image/png") || ($a_mime == "application/x-shockwave-flash") ||
02266                 ($a_mime == "image/tiff") || ($a_mime == "image/x-ms-bmp") ||
02267                 ($a_mime == "image/psd") || ($a_mime == "image/iff"))
02268                 {
02269                         return true;
02270                 }
02271                 else
02272                 {
02273                         return false;
02274                 }
02275         }
02276 
02277 
02283         function redirect($a_script)
02284         {
02285                 global $log, $PHP_SELF;
02286 //$log->write("redirect FROM:".$PHP_SELF." to ".$a_script);
02287                 header("Location: ".$a_script);
02288                 exit();
02289         }
02290 
02296         function insertInstIntoID($a_value)
02297         {
02298                 if (substr($a_value, 0, 4) == "il__")
02299                 {
02300                         $a_value = "il_".IL_INST_ID."_".substr($a_value, 4, strlen($a_value) - 4);
02301                 }
02302 
02303                 return $a_value;
02304         }
02305 
02314         function groupNameExists($a_group_name,$a_id = 0)
02315         {
02316                 global $ilDB,$ilErr;
02317 
02318                 if (empty($a_group_name))
02319                 {
02320                         $message = get_class($this)."::_NameExists(): No groupname given!";
02321                         $ilErr->raiseError($message,$ilErr->WARNING);
02322                 }
02323 
02324                 $clause = ($a_id) ? " AND obj_id != '".$a_id."'" : "";
02325 
02326                 $q = "SELECT obj_id FROM object_data ".
02327                 "WHERE title = '".addslashes($a_group_name)."' ".
02328                 "AND type = 'grp'".
02329                 $clause;
02330                 $r = $ilDB->query($q);
02331 
02332                 if ($r->numRows() == 1)
02333                 {
02334                         return true;
02335                 }
02336                 else
02337                 {
02338                         return false;
02339                 }
02340         }
02341 
02342         /*
02343         * get the user_ids which correspond a search string
02344         * static function
02345         * @param        string search string
02346         * @access       public
02347         */
02348         function searchGroups($a_search_str)
02349         {
02350                 global $ilDB;
02351 
02352                 $q = "SELECT * ".
02353                 "FROM object_data ,object_reference ".
02354                 "WHERE (object_data.title LIKE '%".$a_search_str."%' ".
02355                 "OR object_data.description LIKE '%".$a_search_str."%') ".
02356                 "AND object_data.type = 'grp' ".
02357                 "AND object_data.obj_id = object_reference.obj_id";
02358 
02359                 $res = $ilDB->query($q);
02360 
02361                 while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
02362                 {
02363                         // STORE DATA IN ARRAY WITH KEY obj_id
02364                         // SO DUPLICATE ENTRIES ( LINKED OBJECTS ) ARE UNIQUE
02365                         $ids[$row->obj_id] = array(
02366                         "ref_id"        => $row->ref_id,
02367                         "title"         => $row->title,
02368                         "description"   => $row->description);
02369                 }
02370 
02371                 return $ids ? $ids : array();
02372         }
02373 
02377         function getMemString()
02378         {
02379                 $my_pid = getmypid();
02380                 return ("MEMORY USAGE (% KB PID ): ".`ps -eo%mem,rss,pid | grep $my_pid`);
02381         }
02382 
02386         function isWindows()
02387         {
02388                 if (strtolower(substr(php_uname(), 0, 3)) == "win")
02389                 {
02390                         return true;
02391                 }
02392                 return false;
02393         }
02394 
02395         function escapeShellArg($a_arg)
02396         {
02397                 global $PHP_OS;
02398 
02399                 if (ini_get("safe_mode") == 1 || ilUtil::isWindows())
02400                 {
02401                         return $a_arg;
02402                 }
02403                 else
02404                 {
02405                         return escapeshellarg($a_arg);
02406                 }
02407         }
02408 
02409         /*
02410         * Calculates a Microsoft Excel date/time value
02411         *
02412         * Calculates a Microsoft Excel date/time value (nr of days after 1900/1/1 0:00) for
02413         * a given date and time. The function only accepts dates after 1970/1/1, because the
02414         * unix timestamp functions used in the function are starting with that date.
02415         * If you don't enter parameters the date/time value for the actual date/time
02416         * will be calculated.
02417         *
02418         * static function
02419         *
02420         * @param        integer $year Year
02421         * @param        integer $month Month
02422         * @param        integer $day Day
02423         * @param        integer $hour Hour
02424         * @param        integer $minute Minute
02425         * @param        integer $second Second
02426         * @return float The Microsoft Excel date/time value
02427         * @access       public
02428         */
02429         function excelTime($year = "", $month = "", $day = "", $hour = "", $minute = "", $second = "")
02430         {
02431                 $starting_time = mktime(0, 0, 0, 1, 2, 1970);
02432                 if (strcmp("$year$month$day$hour$minute$second", "") == 0)
02433                 {
02434                         $target_time = time();
02435                 }
02436                 else
02437                 {
02438                         if ($year < 1970)
02439                         {
02440                                 return 0;
02441                         }
02442                 }
02443                 $target_time = mktime($hour, $minute, $second, $month, $day, $year);
02444                 $difference = $target_time - $starting_time;
02445                 $days = (($difference - ($difference % 86400)) / 86400);
02446                 $difference = $difference - ($days * 86400) + 3600;
02447                 return ($days + 25570 + ($difference / 86400));
02448         }
02449 
02453         function renameExecutables($a_dir)
02454         {
02455                 ilUtil::rRenameSuffix($a_dir, "php", "sec");
02456                 ilUtil::rRenameSuffix($a_dir, "php3", "sec");
02457                 ilUtil::rRenameSuffix($a_dir, "php4", "sec");
02458                 ilUtil::rRenameSuffix($a_dir, "inc", "sec");
02459                 ilUtil::rRenameSuffix($a_dir, "lang", "sec");
02460                 ilUtil::rRenameSuffix($a_dir, "phtml", "sec");
02461                 ilUtil::rRenameSuffix($a_dir, "htaccess", "sec");
02462         }
02463 
02472         function rRenameSuffix ($a_dir, $a_old_suffix, $a_new_suffix)
02473         {
02474                 if ($a_dir == "/" || $a_dir == "" || is_int(strpos($a_dir, "..")))
02475                 {
02476                         return false;
02477                 }
02478 
02479                 // check if argument is directory
02480                 if (!@is_dir($a_dir))
02481                 {
02482                         return false;
02483                 }
02484 
02485                 // read a_dir
02486                 $dir = opendir($a_dir);
02487 
02488                 while($file = readdir($dir))
02489                 {
02490                         if ($file != "." and
02491                         $file != "..")
02492                         {
02493                                 // directories
02494                                 if (@is_dir($a_dir."/".$file))
02495                                 {
02496                                         ilUtil::rRenameSuffix($a_dir."/".$file, $a_old_suffix, $a_new_suffix);
02497                                 }
02498 
02499                                 // files
02500                                 if (@is_file($a_dir."/".$file))
02501                                 {
02502                                         $path_info = pathinfo($a_dir."/".$file);
02503                                         if (strtolower($path_info["extension"]) ==
02504                                         strtolower($a_old_suffix))
02505                                         {
02506                                                 $pos = strrpos($a_dir."/".$file, ".");
02507                                                 $new_name = substr($a_dir."/".$file, 0, $pos).".".$a_new_suffix;
02508                                                 rename($a_dir."/".$file, $new_name);
02509                                         }
02510                                 }
02511                         }
02512                 }
02513                 return true;
02514         }
02515 
02516         function isAPICall () {
02517                 return  strpos($_SERVER["SCRIPT_FILENAME"],"api") !== false ||
02518                 strpos($_SERVER["SCRIPT_FILENAME"],"dummy") !== false;
02519         }
02520 
02521         function KT_replaceParam($qstring, $paramName, $paramValue) {
02522                 if (preg_match("/&" . $paramName . "=/", $qstring)) {
02523                         return preg_replace("/&" . $paramName . "=[^&]+/", "&" . $paramName . "=" . urlencode($paramValue), $qstring);
02524                 } else {
02525                         return $qstring . "&" . $paramName . "=" . urlencode($paramValue);
02526                 }
02527         }
02528 
02529         function replaceUrlParameterString ($url, $parametersArray) {
02530                 
02531                 foreach ($parametersArray as $paramName => $paramValue ) {
02532                         $url = ilUtil::KT_replaceParam($url, $paramName, $paramValue);
02533                 }
02534                 return $url;
02535         }
02536 
02537     function generatePasswords ($a_number)
02538     {
02539         $ret = array();
02540         srand((double) microtime()*1000000);
02541 
02542         for ($i=1; $i<=$a_number; $i++)
02543         {
02544             $length  = rand(6,10);
02545             $next  = rand(1,2);
02546             //$chars = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
02547             $vowels = "aeiou";
02548             $consonants = "bcdfghjklmnpqrstvwxyz";
02549             $pw = "";
02550 
02551             for ($j=0; $j < $length; $j++)
02552             {
02553                 switch ($next)
02554                 {
02555                     case 1:
02556                                         $pw.= $consonants[rand(0,strlen($consonants)-1)];
02557                                         $next = 2;
02558                     break;
02559                     
02560                     case 2:
02561                                         $pw.= $vowels[rand(0,strlen($vowels)-1)];
02562                                         $next = 1;
02563                                 break;
02564                 }
02565              }
02566 
02567              $ret[] = $pw;
02568          }
02569 
02570          return $ret;
02571     }
02572         
02573         function removeTrailingPathSeparators($path)
02574         {
02575                 $path = preg_replace("/[\/\\\]+$/", "", $path);
02576                 return $path;
02577         }
02578         
02587         function array_php2js($data)
02588         {
02589                 if (empty($data))
02590                 {
02591                         $data = array();
02592                 }
02593 
02594                 foreach($data as $k=>$datum)
02595                 {
02596                         if(is_null($datum)) $data[$k] = 'null';
02597                         if(is_string($datum)) $data[$k] = "'" . $datum . "'";
02598                         if(is_array($datum)) $data[$k] = array_php2js($datum);
02599                 }
02600                 
02601                 return "[" . implode(', ', $data) . "]";
02602         }
02603 
02608         function virusHandling($a_file, $a_orig_name = "", $a_clean = true)
02609         {
02610                 global $lng;
02611 
02612                 if (IL_VIRUS_SCANNER != "None")
02613                 {
02614                         require_once("classes/class.ilVirusScannerFactory.php");
02615                         $vs = ilVirusScannerFactory::_getInstance();
02616                         if (($vs_txt = $vs->scanFile($a_file, $a_orig_name)) != "")
02617                         {
02618                                 if ($a_clean && (IL_VIRUS_CLEAN_COMMAND != ""))
02619                                 {
02620                                         $clean_txt = $vs->cleanFile($a_file, $a_orig_name);
02621                                         if ($vs->fileCleaned())
02622                                         {
02623                                                 $vs_txt.= "<br />".$lng->txt("cleaned_file").
02624                                                         "<br />".$clean_txt;
02625                                                 $vs_txt.= "<br />".$lng->txt("repeat_scan");
02626                                                 if (($vs2_txt = $vs->scanFile($a_file, $a_orig_name)) != "")
02627                                                 {
02628                                                         return array(false, nl2br($vs_txt)."<br />".$lng->txt("repeat_scan_failed").
02629                                                                 "<br />".nl2br($vs2_txt));
02630                                                 }
02631                                                 else
02632                                                 {
02633                                                         return array(true, nl2br($vs_txt)."<br />".$lng->txt("repeat_scan_succeded"));
02634                                                 }
02635                                         }
02636                                         else
02637                                         {
02638                                                 return array(false, nl2br($vs_txt)."<br />".$lng->txt("cleaning_failed"));
02639                                         }
02640                                 }
02641                                 else
02642                                 {
02643                                         return array(false, nl2br($vs_txt));
02644                                 }
02645                         }
02646                 }
02647                 return array(true,"");
02648         }
02649 
02650 
02654         function moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors = true)
02655         {
02656                 global $lng, $ilias;
02657 //echo "<br>ilUtli::moveuploadedFile($a_name)";
02658                 if (!is_file($a_file))
02659                 {
02660                         $lng->txt("upload_error_file_not_found");
02661                 }
02662 
02663                 // virus handling
02664                 $vir = ilUtil::virusHandling($a_file, $a_name);
02665                 if (!$vir[0])
02666                 {
02667                         unlink($a_file);
02668                         if ($a_raise_errors)
02669                         {
02670                                 $ilias->raiseError($lng->txt("file_is_infected")."<br />".
02671                                         $vir[1],
02672                                         $ilias->error_obj->MESSAGE);
02673                         }
02674                         else
02675                         {
02676                                 sendInfo($lng->txt("file_is_infected")."<br />".
02677                                         $vir[1], true);
02678                         }
02679                         return false;
02680                 }
02681                 else
02682                 {
02683                         if ($vir[1] != "")
02684                         {
02685                                 sendInfo($vir[1], true);
02686                         }
02687                         return move_uploaded_file($a_file, $a_target);
02688                 }
02689         }
02690         
02691         
02695          function date_mysql2time($mysql_date_time) {
02696                 list($datum, $uhrzeit) = explode (" ",$mysql_date_time);
02697                 list($jahr, $monat, $tag) = explode("-", $datum);
02698                 list($std, $min, $sec) = explode(":", $uhrzeit);
02699                 return mktime ((int) $std, (int) $min, (int) $sec, (int) $monat, (int) $tag, (int) $jahr);
02700          }
02701         
02715         function &processCSVRow(&$row, $quoteAll = FALSE, $separator = ";", $outUTF8 = FALSE, $compatibleWithMSExcel = TRUE)
02716         {
02717                 $resultarray = array();
02718                 foreach ($row as $rowindex => $entry)
02719                 {
02720                         $surround = FALSE;
02721                         if ($quoteAll)
02722                         {
02723                                 $surround = TRUE;
02724                         }
02725                         if (strpos($entry, "\"") !== FALSE)
02726                         {
02727                                 $entry = str_replace("\"", "\"\"", $entry);
02728                                 $surround = TRUE;
02729                         }
02730                         if (strpos($entry, $separator) !== FALSE)
02731                         {
02732                                 $surround = TRUE;
02733                         }
02734                         if ($compatibleWithMSExcel)
02735                         {
02736                                 // replace all CR LF with LF (for Excel for Windows compatibility
02737                                 $entry = str_replace(chr(13).chr(10), chr(10), $entry);
02738                         }
02739                         if ($surround)
02740                         {
02741                                 if ($outUTF8)
02742                                 {
02743                                         $resultarray[$rowindex] = "\"" . $entry . "\"";
02744                                 }
02745                                 else
02746                                 {
02747                                         $resultarray[$rowindex] = utf8_decode("\"" . $entry . "\"");
02748                                 }
02749                         }
02750                         else
02751                         {
02752                                 if ($outUTF8)
02753                                 {
02754                                         $resultarray[$rowindex] = $entry;
02755                                 }
02756                                 else
02757                                 {
02758                                         $resultarray[$rowindex] = utf8_decode($entry);
02759                                 }
02760                         }
02761                 }
02762                 return $resultarray;
02763         }
02764 
02765         // validates a domain name (example: www.ilias.de)
02766         function isDN($a_str)
02767         {
02768                 return(preg_match("/^[a-z]+([a-z0-9-]*[a-z0-9]+)?(\.([a-z]+([a-z0-9-]*[a-z0-9]+)?)+)*$/",$a_str));
02769         }
02770         
02771         // validates an IP address (example: 192.168.1.1)
02772         function isIPv4($a_str)
02773         {
02774                 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])\.(\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));
02775         }
02776 
02777 } // END class.ilUtil
02778 ?>

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