00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00034 class ilUtil
00035 {
00043 function getImageTagByType($a_type,$a_path)
00044 {
00045 global $lng;
00046
00047 return "<img src=\"".$a_path."/images/"."icon_".$a_type."_b.gif\" alt=\"".$lng->txt("obj_".$a_type)."\" title=\"".$lng->txt("obj_".$a_type)."\" border=\"0\" vspace=\"0\"/>";
00048 }
00049
00058 function getImagePath($img, $in_module = false, $mode = "output", $offline = false)
00059 {
00060 global $ilias, $styleDefinition;
00061
00062 if(defined("ILIAS_MODULE") and !defined("KEEP_IMAGE_PATH") and $mode != "filesystem")
00063 {
00064 $dir = ".";
00065 }
00066 else
00067 {
00068 $dir = "";
00069 }
00070 $base = "./";
00071 if ($in_module)
00072 {
00073 $base.= ILIAS_MODULE."/";
00074 }
00075 $base .= "templates/";
00076
00077 if (is_object($styleDefinition))
00078 {
00079 $st_image_dir = $styleDefinition->getImageDirectory($ilias->account->prefs["style"]);
00080 $user_skin_and_style = $base.$ilias->account->skin."/".
00081 $st_image_dir.
00082 "/images/".$img;
00083 }
00084 $user_skin = $base.$ilias->account->skin."/images/".$img;
00085 $default = $base."default/images/".$img;
00086 if ($offline)
00087 {
00088 return "./images/".$img;
00089 }
00090 else if (@file_exists($user_skin_and_style) && $st_image_dir != "")
00091 {
00092 return $dir.$user_skin_and_style;
00093 }
00094 else if (file_exists($user_skin))
00095 {
00096 return $dir.$user_skin;
00097 }
00098
00099 return $dir.$default;
00100 }
00101
00110 function getHtmlPath($relative_path)
00111 {
00112 if (substr($relative_path, 0, 2) == './')
00113 {
00114 $relative_path = (substr($relative_path, 1));
00115 }
00116 if (substr($relative_path, 0, 1) != '/')
00117 {
00118 $relative_path = '/' . $relative_path;
00119 }
00120 $htmlpath = ILIAS_HTTP_PATH . $relative_path;
00121 return $htmlpath;
00122 }
00123
00124 function getJSPath($a_js)
00125 {
00126 global $ilias;
00127
00128 if(defined("ILIAS_MODULE"))
00129 {
00130 $dir = ".";
00131 }
00132 else
00133 {
00134 $dir = "";
00135 }
00136 $in_style = "./templates/".$ilias->account->skin."/".$ilias->account->prefs["style"]."/".$a_js;
00137 $default = "./templates/".$ilias->account->skin."/".$a_js;
00138 if(@is_file($in_style))
00139 {
00140 return $dir.$in_style;
00141 }
00142 else
00143 {
00144 return $dir.$default;
00145 }
00146 }
00147
00153 function getStyleSheetLocation($mode = "output")
00154 {
00155 global $ilias;
00156
00157 if(defined("ILIAS_MODULE") && $mode != "filesystem")
00158 {
00159 $base = "../";
00160 }
00161 else
00162 {
00163 $base = "./";
00164 }
00165 return $base."templates/".$ilias->account->skin."/".$ilias->account->prefs["style"].".css";
00166 }
00167
00180 function formSelect ($selected,$varname,$options,$multiple = false,$direct_text = false, $size = "0")
00181 {
00182 global $lng;
00183
00184 if ($multiple == true)
00185 {
00186 $multiple = "multiple";
00187 }
00188 else
00189 {
00190 $multiple = "";
00191 $size = 0;
00192 }
00193
00194 $str = "<select name=\"".$varname ."\"".$multiple." size=\"".$size."\">\n";
00195
00196 foreach ($options as $key => $val)
00197 {
00198 if ($direct_text)
00199 {
00200 $str .= " <option value=\"".$key."\"";
00201 }
00202 else
00203 {
00204 $str .= " <option value=\"".$val."\"";
00205 }
00206 if (is_array($selected) )
00207 {
00208 if (in_array($key,$selected))
00209 {
00210 $str .= " selected=\"selected\"";
00211 }
00212 }
00213 else if ($selected == $key)
00214 {
00215 $str .= " selected=\"selected\"";
00216 }
00217
00218 if ($direct_text)
00219 {
00220 $str .= ">".$val."</option>\n";
00221 }
00222 else
00223 {
00224 $str .= ">".$lng->txt($val)."</option>\n";
00225 }
00226 }
00227
00228 $str .= "</select>\n";
00229
00230 return $str;
00231 }
00232
00240 function getSelectName ($selected,$values)
00241 {
00242 return($values[$selected]);
00243 }
00244
00254 function formCheckbox ($checked,$varname,$value,$disabled = false)
00255 {
00256 $str = "<input type=\"checkbox\" name=\"".$varname."\"";
00257
00258 if ($checked == 1)
00259 {
00260 $str .= " checked=\"checked\"";
00261 }
00262
00263 if ($disabled)
00264 {
00265 $str .= " disabled=\"disabled\"";
00266 }
00267
00268 $str .= " value=\"".$value."\" id=\"".$varname."\" />\n";
00269
00270 return $str;
00271 }
00272
00281 function formRadioButton($checked,$varname,$value)
00282 {
00283 $str = "<input type=\"radio\" name=\"".$varname."\"";
00284 if ($checked == 1)
00285 {
00286 $str .= " checked=\"checked\"";
00287 }
00288
00289 $str .= " value=\"".$value."\"";
00290
00291 $str .= " id=\"".$value."\" />\n";
00292
00293 return $str;
00294 }
00295
00300 function checkInput ($vars)
00301 {
00302
00303
00304 }
00305
00311 function setPathStr ($a_path)
00312 {
00313 if ("" != $a_path && "/" != substr($a_path, -1))
00314 {
00315 $a_path .= "/";
00316
00317 }
00318
00319
00320 return $a_path;
00321 }
00322
00333 function switchColor ($a_num,$a_css1,$a_css2)
00334 {
00335 if (!($a_num % 2))
00336 {
00337 return $a_css1;
00338 }
00339 else
00340 {
00341 return $a_css2;
00342 }
00343 }
00344
00352 function showTabs($a_hl, $a_o)
00353 {
00354 global $lng;
00355
00356 $tpltab = new ilTemplate("tpl.tabs.html", true, true);
00357
00358 for ($i=1; $i<=4; $i++)
00359 {
00360 $tpltab->setCurrentBlock("tab");
00361 if ($a_hl == $i)
00362 {
00363 $tabtype = "tabactive";
00364 $tab = $tabtype;
00365 }
00366 else
00367 {
00368 $tabtype = "tabinactive";
00369 $tab = "tab";
00370 }
00371
00372 switch ($i)
00373 {
00374 case 1:
00375 $txt = $lng->txt("view_content");
00376 break;
00377 case 2:
00378 $txt = $lng->txt("edit_properties");
00379 break;
00380 case 3:
00381 $txt = $lng->txt("perm_settings");
00382 break;
00383 case 4:
00384 $txt = $lng->txt("show_owner");
00385 break;
00386 }
00387 $tpltab->setVariable("CONTENT", $txt);
00388 $tpltab->setVariable("TABTYPE", $tabtype);
00389 $tpltab->setVariable("TAB", $tab);
00390 $tpltab->setVariable("LINK", $a_o["LINK".$i]);
00391 $tpltab->parseCurrentBlock();
00392 }
00393
00394 return $tpltab->get();
00395 }
00396
00421 function getObjectsByOperations($a_type,$a_operation,$a_checkpath = true)
00422 {
00423 global $ilDB, $rbacsystem, $tree;
00424
00425 $objects = array();
00426
00427
00428 if ($a_checkpath === true and !$rbacsystem->checkAccess('read', ROOT_FOLDER_ID, $a_type))
00429 {
00430 return $objects;
00431 }
00432
00433
00434 $q = "SELECT * FROM tree ".
00435 "LEFT JOIN object_reference ON tree.child=object_reference.ref_id ".
00436 "LEFT JOIN object_data ON object_reference.obj_id=object_data.obj_id ".
00437 "WHERE object_data.type = '".$a_type."' ".
00438 "AND tree.tree = 1";
00439
00440 $r = $ilDB->query($q);
00441
00442
00443 while ($row = $r->fetchRow(DB_FETCHMODE_ASSOC))
00444 {
00445 if ($rbacsystem->checkAccess($a_operation, $row["ref_id"], $a_type))
00446 {
00447 $objects[] = $row;
00448 }
00449 }
00450
00451
00452 if ($a_checkpath === true)
00453 {
00454 $nodes_checked = array(ROOT_FOLDER_ID);
00455 $nodes_passed = array(ROOT_FOLDER_ID);
00456
00457 foreach ($objects as $key => $node)
00458 {
00459 $path = $tree->getPathId($node["ref_id"],ROOT_FOLDER_ID);
00460
00461 array_push($nodes_checked,$node["ref_id"]);
00462 array_push($nodes_passed,$node["ref_id"]);
00463
00464 if (($num = count($path)) > 2)
00465 {
00466 for ($i = 1; $i <= ($num - 2); $i++)
00467 {
00468
00469 if (in_array($path[$i],$nodes_passed))
00470 {
00471
00472 continue;
00473 }
00474
00475 if (!in_array($path[$i],$nodes_checked))
00476 {
00477 array_push($nodes_checked,$path[$i]);
00478
00479 if ($rbacsystem->checkAccess($a_operation, $path[$i], $a_type))
00480 {
00481 array_push($nodes_passed,$path[$i]);
00482
00483 }
00484 else
00485 {
00486 unset($objects[$key]);
00487
00488 break;
00489 }
00490 }
00491 }
00492 }
00493
00494 }
00495
00496 }
00497
00498 unset($nodes_checked);
00499 unset($nodes_passed);
00500
00501 return $objects;
00502 }
00503
00504
00511 function checkFormEmpty ($emptyFields)
00512 {
00513
00514 $feedback = "";
00515
00516 foreach ($emptyFields as $key => $val)
00517 {
00518 if ($val == "") {
00519 if ($feedback != "") $feedback .= ", ";
00520 $feedback .= $key;
00521 }
00522 }
00523
00524 return $feedback;
00525 }
00526
00549 function Linkbar ($AScript,$AHits,$ALimit,$AOffset,$AParams = array(),$ALayout = array())
00550 {
00551 $LinkBar = "";
00552
00553 $layout_link = "";
00554 $layout_prev = "<<";
00555 $layout_next = ">>";
00556
00557
00558 if (count($ALayout > 0))
00559 {
00560 if ($ALayout["link"])
00561 {
00562 $layout_link = " class=\"".$ALayout["link"]."\"";
00563 }
00564
00565 if ($ALayout["prev"])
00566 {
00567 $layout_prev = $ALayout["prev"];
00568 }
00569
00570 if ($ALayout["next"])
00571 {
00572 $layout_next = $ALayout["next"];
00573 }
00574 }
00575
00576
00577 if ($AHits > $ALimit)
00578 {
00579 if (!empty($AParams))
00580 {
00581 foreach ($AParams as $key => $value)
00582 {
00583 $params.= $key."=".$value."&";
00584 }
00585 }
00586
00587 $link = $AScript."?".$params."offset=";
00588
00589
00590 if ($AOffset >= 1)
00591 {
00592 $prevoffset = $AOffset - $ALimit;
00593 $LinkBar .= "<a".$layout_link." href=\"".$link.$prevoffset."\">".$layout_prev." </a>";
00594 }
00595
00596
00597 $pages=intval($AHits/$ALimit);
00598
00599
00600 if (($AHits % $ALimit))
00601 $pages++;
00602
00603
00604
00605
00606
00607 for ($i = 1 ;$i <= $pages ; $i++)
00608 {
00609 $newoffset=$ALimit*($i-1);
00610
00611 if ($newoffset == $AOffset)
00612 {
00613 $LinkBar .= "<font color='Gray'>[<b>".$i."</b>]</font> ";
00614 }
00615 else
00616 {
00617 $LinkBar .= "[<a".$layout_link." href=\"".$link.$newoffset."\">$i</a>] ";
00618 }
00619 }
00620
00621
00622
00623
00624 if (! ( ($AOffset/$ALimit)==($pages-1) ) && ($pages!=1) )
00625 {
00626 $newoffset=$AOffset+$ALimit;
00627 $LinkBar .= "<a".$layout_link." href=\"".$link.$newoffset."\"> ".$layout_next."</a>";
00628 }
00629
00630 return $LinkBar;
00631 }
00632 else
00633 {
00634 return false;
00635 }
00636 }
00637
00646 function makeClickable($a_text)
00647 {
00648
00649 $ret = eregi_replace("([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=-])",
00650 "<a href=\"\\1://\\2\\3\" target=\"_blank\">\\1://\\2\\3</a>", $a_text);
00651
00652
00653 $ret = eregi_replace("([[:space:]]+)(www\.)([[:alnum:]#?/&=\.-]+)",
00654 "\\1<a href=\"http://\\2\\3\" target=\"_blank\">\\2\\3</a>", $ret);
00655
00656
00657 $ret = eregi_replace("([[:space:]]+)(ftp\.)([[:alnum:]#?/&=\.-]+)",
00658 "\\1<a href=\"ftp://\\2\\3\" target=\"_blank\">\\2\\3</a>", $ret);
00659
00660
00661 $ret = eregi_replace("(([a-z0-9_]|\\-|\\.)+@([^[:space:]]*)([[:alnum:]-]))",
00662 "<a href=\"mailto:\\1\">\\1</a>", $ret);
00663
00664 return($ret);
00665 }
00666
00683 function StopWatch($begin = -1)
00684 {
00685 $m = explode(" ",microtime());
00686 $m = $m[0] + $m[1];
00687
00688 if ($begin != -1)
00689 {
00690 $m = $m - $begin;
00691 }
00692
00693 return($m);
00694 }
00695
00712 function makeDateSelect($prefix, $year = "", $month = "", $day = "", $startyear = "")
00713 {
00714 global $lng;
00715
00716 if (!strlen("$year$month$day")) {
00717 $now = getdate();
00718 $year = $now["year"];
00719 $month = $now["mon"];
00720 $day = $now["mday"];
00721 } else {
00722
00723 $year = (int)$year;
00724 $month = (int)$month;
00725 $day = (int)$day;
00726 }
00727
00728
00729 $sel_day .= "<select name=\"".$prefix."[d]\" id=\"".$prefix."_d\">\n";
00730
00731 for ($i = 1; $i <= 31; $i++)
00732 {
00733 $sel_day .= "<option value=\"$i\">" . sprintf("%02d", $i) . "</option>\n";
00734 }
00735 $sel_day .= "</select>\n";
00736 $sel_day = preg_replace("/(value\=\"$day\")/", "$1 selected=\"selected\"", $sel_day);
00737
00738
00739 $sel_month .= "<select name=\"".$prefix."[m]\" id=\"".$prefix."_m\">\n";
00740
00741 for ($i = 1; $i <= 12; $i++)
00742 {
00743 $sel_month .= "<option value=\"$i\">" . $lng->txt("month_" . sprintf("%02d", $i) . "_long") . "</option>\n";
00744 }
00745 $sel_month .= "</select>\n";
00746 $sel_month = preg_replace("/(value\=\"$month\")/", "$1 selected=\"selected\"", $sel_month);
00747
00748
00749 $sel_year .= "<select name=\"".$prefix."[y]\" id=\"".$prefix."_y\">\n";
00750 if ((strlen($startyear) == 0) || ($startyear > $year))
00751 {
00752 $startyear = $year;
00753 }
00754 for ($i = $startyear; $i <= $year + 3; $i++)
00755 {
00756 $sel_year .= "<option value=\"$i\">" . sprintf("%04d", $i) . "</option>\n";
00757 }
00758 $sel_year .= "</select>\n";
00759 $sel_year = preg_replace("/(value\=\"$year\")/", "$1 selected=\"selected\"", $sel_year);
00760
00761 $dateformat = $lng->text["lang_dateformat"];
00762 $dateformat = strtolower(preg_replace("/\W/", "", $dateformat));
00763 $dateformat = strtolower(preg_replace("/(\w)/", "%%$1", $dateformat));
00764 $dateformat = preg_replace("/%%d/", $sel_day, $dateformat);
00765 $dateformat = preg_replace("/%%m/", $sel_month, $dateformat);
00766 $dateformat = preg_replace("/%%y/", $sel_year, $dateformat);
00767 return $dateformat;
00768 }
00769
00786 function makeTimeSelect($prefix, $short = true, $hour = "", $minute = "", $second = "")
00787 {
00788 global $lng;
00789
00790 if (!strlen("$hour$minute$second")) {
00791 $now = localtime();
00792 $hour = $now[2];
00793 $minute = $now[1];
00794 $second = $now[0];
00795 } else {
00796 $hour = (int)$hour;
00797 $minute = (int)$minute;
00798 $second = (int)$second;
00799 }
00800
00801 $sel_hour .= "<select name=\"".$prefix."[h]\" id=\"".$prefix."_h\">\n";
00802
00803 for ($i = 0; $i <= 23; $i++)
00804 {
00805 $sel_hour .= "<option value=\"$i\">" . sprintf("%02d", $i) . "</option>\n";
00806 }
00807 $sel_hour .= "</select>\n";
00808 $sel_hour = preg_replace("/(value\=\"$hour\")/", "$1 selected=\"selected\"", $sel_hour);
00809
00810
00811 $sel_minute .= "<select name=\"".$prefix."[m]\" id=\"".$prefix."_m\">\n";
00812
00813 for ($i = 0; $i <= 59; $i++)
00814 {
00815 $sel_minute .= "<option value=\"$i\">" . sprintf("%02d", $i) . "</option>\n";
00816 }
00817 $sel_minute .= "</select>\n";
00818 $sel_minute = preg_replace("/(value\=\"$minute\")/", "$1 selected=\"selected\"", $sel_minute);
00819
00820 if (!$short) {
00821
00822 $sel_second .= "<select name=\"".$prefix."[s]\" id=\"".$prefix."_s\">\n";
00823
00824 for ($i = 0; $i <= 59; $i++)
00825 {
00826 $sel_second .= "<option value=\"$i\">" . sprintf("%02d", $i) . "</option>\n";
00827 }
00828 $sel_second .= "</select>\n";
00829 $sel_second = preg_replace("/(value\=\"$second\")/", "$1 selected=\"selected\"", $sel_second);
00830 }
00831 $timeformat = $lng->text["lang_timeformat"];
00832 $timeformat = strtolower(preg_replace("/\W/", "", $timeformat));
00833 $timeformat = preg_replace("/(\w)/", "%%$1", $timeformat);
00834 $timeformat = preg_replace("/%%h/", $sel_hour, $timeformat);
00835 $timeformat = preg_replace("/%%i/", $sel_minute, $timeformat);
00836 if ($short) {
00837 $timeformat = preg_replace("/%%s/", "", $timeformat);
00838 } else {
00839 $timeformat = preg_replace("/%%s/", $sel_second, $timeformat);
00840 }
00841 return $timeformat;
00842 }
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854 function is_email($a_email)
00855 {
00856 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));
00857 }
00858
00859
00860
00861
00862
00863
00864
00865 function isPassword($a_passwd)
00866 {
00867 if (empty($a_passwd))
00868 {
00869 return false;
00870 }
00871
00872 if (strlen($a_passwd) < 6)
00873 {
00874 return false;
00875 }
00876
00877
00878
00879 if (!preg_match("/^[A-Za-z0-9_\.\+\-\*\@!\$\%\~]+$/", $a_passwd))
00880 {
00881 return false;
00882 }
00883
00884 return true;
00885 }
00886
00887
00888
00889
00890
00891
00892
00893 function isLogin($a_login)
00894 {
00895 if (empty($a_login))
00896 {
00897 return false;
00898 }
00899
00900 if (strlen($a_login) < 4)
00901 {
00902 return false;
00903 }
00904
00905 if (!ereg("^[A-Za-z0-9_\.\+-\*\@!\$\%\~]+$", $a_login))
00906 {
00907 return false;
00908 }
00909
00910 return true;
00911 }
00912
00923 function shortenText ($a_str, $a_len, $a_dots = "false")
00924 {
00925 if (strlen($a_str) > $a_len)
00926 {
00927
00928 $a_str = substr($a_str,0,$a_len);
00929
00930 if ($a_dots)
00931 {
00932 $a_str .= "...";
00933 }
00934 }
00935
00936 return $a_str;
00937 }
00938
00946 function attribsToArray($a_str)
00947 {
00948 $attribs = array();
00949 while (is_int(strpos($a_str, "=")))
00950 {
00951 $eq_pos = strpos($a_str, "=");
00952 $qu1_pos = strpos($a_str, "\"");
00953 $qu2_pos = strpos(substr($a_str, $qu1_pos + 1), "\"") + $qu1_pos + 1;
00954 if (is_int($eq_pos) && is_int($qu1_pos) && is_int($qu2_pos))
00955 {
00956 $var = trim(substr($a_str, 0, $eq_pos));
00957 $val = trim(substr($a_str, $qu1_pos + 1, ($qu2_pos - $qu1_pos) - 1));
00958 $attribs[$var] = $val;
00959 $a_str = substr($a_str, $qu2_pos + 1);
00960 }
00961 else
00962 {
00963 $a_str = "";
00964 }
00965 }
00966 return $attribs;
00967 }
00968
00977 function rCopy ($a_sdir, $a_tdir)
00978 {
00979
00980 if (!@is_dir($a_sdir) or
00981 !@is_dir($a_tdir))
00982 {
00983 return FALSE;
00984 }
00985
00986
00987 $dir = opendir($a_sdir);
00988
00989 while($file = readdir($dir))
00990 {
00991 if ($file != "." and
00992 $file != "..")
00993 {
00994
00995 if (@is_dir($a_sdir."/".$file))
00996 {
00997 if (!@is_dir($a_tdir."/".$file))
00998 {
00999 if (!ilUtil::makeDir($a_tdir."/".$file))
01000 return FALSE;
01001
01002
01003 }
01004
01005 if (!ilUtil::rCopy($a_sdir."/".$file,$a_tdir."/".$file))
01006 {
01007 return FALSE;
01008 }
01009 }
01010
01011
01012 if (@is_file($a_sdir."/".$file))
01013 {
01014 if (!copy($a_sdir."/".$file,$a_tdir."/".$file))
01015 {
01016 return FALSE;
01017 }
01018 }
01019 }
01020 }
01021 return TRUE;
01022 }
01023
01031 function getWebspaceDir($mode = "filesystem")
01032 {
01033 global $ilias;
01034
01035 if ($mode == "filesystem")
01036 {
01037 return "./".ILIAS_WEB_DIR."/".$ilias->client_id;
01038 }
01039 else
01040 {
01041 if (defined("ILIAS_MODULE"))
01042 {
01043 return "../".ILIAS_WEB_DIR."/".$ilias->client_id;
01044 }
01045 else
01046 {
01047 return "./".ILIAS_WEB_DIR."/".$ilias->client_id;
01048 }
01049 }
01050
01051
01052 }
01053
01057 function getDataDir()
01058 {
01059 return CLIENT_DATA_DIR;
01060
01061
01062
01063 }
01064
01072 function getUsersOnline($a_user_id = 0)
01073 {
01074 global $ilias;
01075
01076 if ($a_user_id == 0)
01077 {
01078 $where = "WHERE user_id != 0";
01079 }
01080 else
01081 {
01082 $where = "WHERE user_id = '".$a_user_id."'";
01083 }
01084
01085 $q = "SELECT count(user_id) as num,user_id,data,firstname,lastname,title,login,last_login FROM usr_session ".
01086 "LEFT JOIN usr_data ON user_id=usr_id ".$where.
01087 " AND expires>UNIX_TIMESTAMP() GROUP BY user_id";
01088 $r = $ilias->db->query($q);
01089
01090 while ($user = $r->fetchRow(DB_FETCHMODE_ASSOC))
01091 {
01092 $users[$user["user_id"]] = $user;
01093 }
01094
01095 return $users ? $users : array();
01096 }
01097
01103 function ilTempnam()
01104 {
01105 $temp_path = ilUtil::getDataDir() . "/temp";
01106 if (!is_dir($temp_path))
01107 {
01108 ilUtil::createDirectory($temp_path);
01109 }
01110 $temp_name = tempnam($temp_path, "tmp");
01111 unlink($temp_name);
01112 return $temp_name;
01113 }
01114
01120 function createDirectory($a_dir, $a_mod = 0755)
01121 {
01122 ilUtil::makeDir($a_dir);
01123
01124
01125 }
01126
01127
01133 function unzip($a_file)
01134 {
01135
01136
01137 $pathinfo = pathinfo($a_file);
01138 $dir = $pathinfo["dirname"];
01139 $file = $pathinfo["basename"];
01140
01141
01142 $cdir = getcwd();
01143 chdir($dir);
01144 $unzip = PATH_TO_UNZIP;
01145
01146
01147
01148
01149
01150 $unzipcmd = $unzip." -Z -1 ".ilUtil::escapeShellArg($file);
01151 exec($unzipcmd, $arr);
01152 $zdirs = array();
01153
01154 foreach($arr as $line)
01155 {
01156 if(is_int(strpos($line, "/")))
01157 {
01158 $zdir = substr($line, 0, strrpos($line, "/"));
01159 $nr = substr_count($zdir, "/");
01160
01161 while ($zdir != "")
01162 {
01163 $nr = substr_count($zdir, "/");
01164 $zdirs[$zdir] = $nr;
01165
01166 $zdir = substr($zdir, 0, strrpos($zdir, "/"));
01167 }
01168 }
01169 }
01170
01171 asort($zdirs);
01172
01173 foreach($zdirs as $zdir => $nr)
01174 {
01175 ilUtil::createDirectory($zdir);
01176 }
01177
01178
01179 $unzipcmd = $unzip." -o ".ilUtil::escapeShellArg($file);
01180 exec($unzipcmd);
01181
01182 chdir($cdir);
01183 }
01184
01188 function zip($a_dir, $a_file)
01189 {
01190
01191
01192 $cdir = getcwd();
01193
01194 $pathinfo = pathinfo($a_file);
01195 $dir = $pathinfo["dirname"];
01196 $file = $pathinfo["basename"];
01197
01198
01199 $cdir = getcwd();
01200 chdir($dir);
01201
01202 $zip = PATH_TO_ZIP;
01203
01204
01205 $name = basename($a_dir);
01206
01207 $zipcmd = $zip." -r ".ilUtil::escapeShellArg($a_file)." ".ilUtil::escapeShellArg($name);
01208 exec($zipcmd);
01209
01210 chdir($cdir);
01211 }
01212
01216 function getConvertCmd()
01217 {
01218 return PATH_TO_CONVERT;
01219
01220
01221
01222 }
01223
01231 function convertImage($a_from, $a_to, $a_target_format = "", $a_geometry = "")
01232 {
01233 $format_str = ($a_target_format != "")
01234 ? strtoupper($a_target_format).":"
01235 : "";
01236 $geometry = ($a_geometry != "")
01237 ? " -geometry ".$a_geometry."x".$a_geometry." "
01238 : "";
01239 $convert_cmd = ilUtil::getConvertCmd()." ".
01240 ilUtil::escapeShellArg($a_from)." ".$geometry.ilUtil::escapeShellArg($format_str.$a_to);
01241 system($convert_cmd);
01242 }
01243
01249 function html2pdf($html, $pdf_file)
01250 {
01251
01252
01253 $html_file = str_replace(".pdf",".html",$pdf_file);
01254
01255 $fp = fopen( $html_file ,"wb");
01256 fwrite($fp, $html);
01257 fclose($fp);
01258
01259 $htmldoc_path = PATH_TO_HTMLDOC;
01260
01261
01262 $htmldoc = $htmldoc_path." ";
01263 $htmldoc .= "--no-toc ";
01264 $htmldoc .= "--no-jpeg ";
01265 $htmldoc .= "--webpage ";
01266 $htmldoc .= "--outfile " . ilUtil::escapeShellArg($pdf_file) . " ";
01267 $htmldoc .= "--bodyfont Arial ";
01268 $htmldoc .= "--charset iso-8859-15 ";
01269 $htmldoc .= "--color ";
01270 $htmldoc .= "--size A4 ";
01271 $htmldoc .= "--format pdf ";
01272 $htmldoc .= "--footer ... ";
01273 $htmldoc .= "--header ... ";
01274 $htmldoc .= "--left 60 ";
01275
01276 $htmldoc .= $html_file;
01277 exec($htmldoc);
01278
01279 }
01280
01284 function deliverData($a_data, $a_filename, $mime = "application/octet-stream")
01285 {
01286 $disposition = "attachment";
01287
01288
01289 if (isset($_SERVER["HTTPS"])) {
01293 header("Pragma: ");
01294 header("Cache-Control: ");
01295 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
01296 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
01297 header("Cache-Control: no-store, no-cache, must-revalidate");
01298 header("Cache-Control: post-check=0, pre-check=0", false);
01299 }
01300 else if ($disposition == "attachment")
01301 {
01302 header("Cache-control: private");
01303 }
01304 else
01305 {
01306 header("Cache-Control: no-cache, must-revalidate");
01307 header("Pragma: no-cache");
01308 }
01309
01310 $ascii_filename = ilUtil::getASCIIFilename($a_filename);
01311
01312 header("Content-Type: $mime");
01313 header("Content-Disposition:$disposition; filename=\"".$ascii_filename."\"");
01314 header("Content-Description: ".$ascii_filename);
01315 header("Content-Length: ".(string)(strlen($a_data)));
01316 header("Connection: close");
01317
01318 echo $a_data;
01319 exit;
01320 }
01321
01325 function deliverFile($a_file, $a_filename)
01326 {
01327 $disposition = "attachment";
01328 $mime = "application/octet-stream";
01329 if (isset($_SERVER["HTTPS"]))
01330 {
01334 header("Pragma: ");
01335 header("Cache-Control: ");
01336 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
01337 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
01338 header("Cache-Control: no-store, no-cache, must-revalidate");
01339 header("Cache-Control: post-check=0, pre-check=0", false);
01340 }
01341 else if ($disposition == "attachment")
01342 {
01343 header("Cache-control: private");
01344 }
01345 else
01346 {
01347 header("Cache-Control: no-cache, must-revalidate");
01348 header("Pragma: no-cache");
01349 }
01350
01351 $ascii_filename = ilUtil::getASCIIFilename($a_filename);
01352
01353 header("Content-Type: $mime");
01354 header("Content-Disposition:$disposition; filename=\"".$ascii_filename."\"");
01355 header("Content-Description: ".$ascii_filename);
01356 header("Content-Length: ".(string)(filesize($a_file)));
01357 header("Connection: close");
01358 readfile( $a_file );
01359 exit;
01360 }
01361
01367 function getASCIIFilename($a_filename)
01368 {
01369
01370
01371
01372
01373
01374
01386
01387 $user_agent = strtolower($_SERVER["HTTP_USER_AGENT"]);
01388 if ((is_integer(strpos($user_agent, "msie"))) && is_integer(strpos($user_agent, "win")))
01389 {
01392
01393 $ascii_filename = utf8_decode($a_filename);
01394 }
01395 else
01396 {
01399
01400 $ascii_filename = htmlentities($a_filename,ENT_NOQUOTES,'UTF-8');
01401 $ascii_filename = preg_replace('/\&(.)[^;]*;/','\\1', $ascii_filename);
01402 $ascii_filename = preg_replace('/[\x7f-\xff]/','_', $ascii_filename);
01403 }
01404
01405
01406
01407 if (is_integer(strpos($user_agent, "win")))
01408 {
01409 $ascii_filename = preg_replace('/[:\x5c\/\*\?\"<>\|]/','_', $ascii_filename);
01410 }
01411
01412 return $ascii_filename;
01413 }
01414
01418 function getJavaPath()
01419 {
01420 return PATH_TO_JAVA;
01421
01422
01423
01424 }
01425
01430 function appendUrlParameterString($a_url, $a_par)
01431 {
01432 $url = (is_int(strpos($a_url, "?")))
01433 ? $a_url."&".$a_par
01434 : $a_url."?".$a_par;
01435
01436 return $url;
01437 }
01438
01453 function makeDir($a_dir)
01454 {
01455 $a_dir = trim($a_dir);
01456
01457
01458 if (substr($a_dir,-1) == "/")
01459 {
01460 $a_dir = substr($a_dir,0,-1);
01461 }
01462
01463
01464 if (!($path = substr($a_dir,0, strrpos($a_dir,"/") - strlen($a_dir))))
01465 {
01466 $path = ".";
01467 }
01468
01469
01470 umask(0000);
01471 return @mkdir($a_dir,fileperms($path));
01472 }
01473
01474
01487 function makeDirParents($a_dir)
01488 {
01489 $dirs = array($a_dir);
01490 $a_dir = dirname($a_dir);
01491 $last_dirname = '';
01492 while($last_dirname != $a_dir)
01493 {
01494 array_unshift($dirs, $a_dir);
01495 $last_dirname = $a_dir;
01496 $a_dir = dirname($a_dir);
01497 }
01498
01499
01500 $reverse_paths = array_reverse($dirs, TRUE);
01501 $found_index = -1;
01502 foreach ($reverse_paths as $key => $value)
01503 {
01504 if ($found_index == -1)
01505 {
01506 if (is_dir($value))
01507 {
01508 $found_index = $key;
01509 }
01510 }
01511 }
01512
01513 umask(0000);
01514 foreach ($dirs as $dirindex => $dir)
01515 {
01516
01517 if ($dirindex >= $found_index)
01518 {
01519 if (! file_exists($dir))
01520 {
01521 if (! mkdir($dir, $umask))
01522 {
01523 error_log("Can't make directory: $dir");
01524 return false;
01525 }
01526 }
01527 elseif (! is_dir($dir))
01528 {
01529 error_log("$dir is not a directory");
01530 return false;
01531 }
01532 else
01533 {
01534
01535 $umask = fileperms($dir);
01536 }
01537 }
01538 }
01539 return true;
01540 }
01541
01549 function delDir($a_dir)
01550 {
01551 if (!is_dir($a_dir) || is_int(strpos($a_dir, "..")))
01552 {
01553 return;
01554 }
01555
01556 $current_dir = opendir($a_dir);
01557
01558 $files = array();
01559
01560
01561
01562
01563
01564
01565 while($entryname = readdir($current_dir))
01566 {
01567 $files[] = $entryname;
01568 }
01569
01570 foreach($files as $file)
01571 {
01572 if(is_dir($a_dir."/".$file) and ($file != "." and $file!=".."))
01573 {
01574 ilUtil::delDir(${a_dir}."/".${file});
01575 }
01576 elseif ($file != "." and $file != "..")
01577 {
01578 unlink(${a_dir}."/".${file});
01579 }
01580 }
01581
01582 closedir($current_dir);
01583 rmdir(${a_dir});
01584 }
01585
01586
01590 function getDir($a_dir)
01591 {
01592 $current_dir = opendir($a_dir);
01593
01594 $dirs = array();
01595 $files = array();
01596 while($entry = readdir($current_dir))
01597 {
01598 if(is_dir($a_dir."/".$entry))
01599 {
01600 $dirs[$entry] = array("type" => "dir", "entry" => $entry);
01601 }
01602 else
01603 {
01604 $size = filesize($a_dir."/".$entry);
01605 $files[$entry] = array("type" => "file", "entry" => $entry,
01606 "size" => $size);
01607 }
01608 }
01609 ksort($dirs);
01610 ksort($files);
01611
01612 return array_merge($dirs, $files);
01613 }
01614
01615
01623 function getGroupId($a_parent_ref)
01624 {
01625 return false;
01626
01627 global $ilias;
01628
01629 $q = "SELECT DISTINCT tree FROM grp_tree WHERE child='".$a_parent_ref."'";
01630 $r = $ilias->db->query($q);
01631 $row = $r->fetchRow();
01632
01633 return $row[0] ? $row[0] : false;
01634 }
01635
01641 function stripSlashes($a_str, $a_strip_html = true, $a_allow = "")
01642 {
01643 if (ini_get("magic_quotes_gpc"))
01644 {
01645 $a_str = stripslashes($a_str);
01646 }
01647
01648
01649 if ($a_allow == "")
01650 {
01651 $a_allow = "<b><i><strong><em><code><cite><gap><sub><sup><pre><strike>";
01652 }
01653
01654 if ($a_strip_html)
01655 {
01656 $a_str = ilUtil::stripScriptHTML($a_str, $a_allow);
01657 }
01658
01659 return $a_str;
01660 }
01661
01662
01674 function stripScriptHTML($a_str, $a_allow = "", $a_rm_js = true)
01675 {
01676
01677
01678 $negativestr = "a,abbr,acronym,address,applet,area,b,base,basefont,".
01679 "bdo,big,blockquote,body,br,button,caption,center,cite,code,col,".
01680 "colgroup,dd,del,dfn,dir,div,dl,dt,em,fieldset,font,form,frame,".
01681 "frameset,h1,h2,h3,h4,h5,h6,head,hr,html,i,iframe,img,input,ins,isindex,kbd,".
01682 "label,legend,li,link,map,menu,meta,noframes,noscript,object,ol,".
01683 "optgroup,option,p,param,pre,q,s,samp,script,select,small,span,".
01684 "strike,strong,style,sub,sup,table,tbody,td,textarea,tfoot,th,thead,".
01685 "title,tr,tt,u,ul,var";
01686 $a_allow = strtolower ($a_allow);
01687 $negatives = split (",",$negativestr);
01688 foreach ($negatives as $item)
01689 {
01690 $pos = strpos($a_allow, "<$item>");
01691
01692
01693 if ($pos === false)
01694 {
01695 $a_str = preg_replace("/<\/?\s*$item\s*>/i", "", $a_str);
01696 $a_str = preg_replace("/<\/?\s*$item\s+([^>]*)>/i", "", $a_str);
01697 }
01698
01699 if ($a_rm_js)
01700 {
01701
01702 $a_str = preg_replace("/<\s*".$item."(\s+[^>]*)?(\s+on[^>]*)>/i", "<$item>", $a_str);
01703
01704
01705 $a_str = preg_replace("/<\s*".$item."\s+[^>]*javascript[^>]*>/i", "<$item>", $a_str);
01706 }
01707 }
01708
01709 return $a_str;
01710 }
01711
01712
01718 function addSlashes($a_str)
01719 {
01720 if (ini_get("magic_quotes_gpc"))
01721 {
01722 return $a_str;
01723 }
01724 else
01725 {
01726 return addslashes($a_str);
01727 }
01728 }
01729
01739 function prepareFormOutput($a_str, $a_strip = false)
01740 {
01741 if($a_strip)
01742 {
01743 $a_str = ilUtil::stripSlashes($a_str);
01744 }
01745 return htmlspecialchars($a_str);
01746 }
01747
01748
01756 function prepareDBString($a_str)
01757 {
01758 return addslashes($a_str);
01759 }
01760
01761
01768 function removeItemFromDesktops($a_id)
01769 {
01770 global $ilias;
01771
01772 $q = "SELECT user_id FROM desktop_item WHERE item_id = '".$a_id."'";
01773 $r = $ilias->db->query($q);
01774
01775 $users = array();
01776
01777 while ($row = $r->fetchRow(DB_FETCHMODE_OBJECT))
01778 {
01779 $users[] = $row->user_id;
01780 }
01781
01782 if (count($users) > 0)
01783 {
01784 $q = "DELETE FROM desktop_item WHERE item_id = '".$a_id."'";
01785 $ilias->db->query($q);
01786 }
01787
01788 return $users;
01789 }
01790
01791
01799 function extractParameterString($a_parstr)
01800 {
01801
01802 $par = array();
01803 $ok=true;
01804 while(($spos=strpos($a_parstr,"=")) && $ok)
01805 {
01806
01807 $cpar = substr($a_parstr,0,$spos);
01808 $a_parstr = substr($a_parstr,$spos,strlen($a_parstr)-$spos);
01809 while(substr($cpar,0,1)=="," ||substr($cpar,0,1)==" " || substr($cpar,0,1)==chr(13) || substr($cpar,0,1)==chr(10))
01810 $cpar = substr($cpar,1,strlen($cpar)-1);
01811 while(substr($cpar,strlen($cpar)-1,1)==" " || substr($cpar,strlen($cpar)-1,1)==chr(13) || substr($cpar,strlen($cpar)-1,1)==chr(10))
01812 $cpar = substr($cpar,0,strlen($cpar)-1);
01813
01814
01815 if($spos=strpos($a_parstr,"\""))
01816 {
01817 $a_parstr = substr($a_parstr,$spos+1,strlen($a_parstr)-$spos);
01818 $spos=strpos($a_parstr,"\"");
01819 if(is_int($spos))
01820 {
01821 $cval = substr($a_parstr,0,$spos);
01822 $par[$cpar]=$cval;
01823 $a_parstr = substr($a_parstr,$spos+1,strlen($a_parstr)-$spos-1);
01824 }
01825 else
01826 $ok=false;
01827 }
01828 else
01829 $ok=false;
01830 }
01831
01832 if($ok) return $par; else return false;
01833 }
01834
01835 function assembleParameterString($a_par_arr)
01836 {
01837 if (is_array($a_par_arr))
01838 {
01839 $target_arr = array();
01840 foreach ($a_par_arr as $par => $val)
01841 {
01842 $target_arr[] = "$par=\"$val\"";
01843 }
01844 $target_str = implode(", ", $target_arr);
01845 }
01846
01847 return $target_str;
01848 }
01849
01853 function dumpString($a_str)
01854 {
01855 $ret = $a_str.": ";
01856 for($i=0; $i<strlen($a_str); $i++)
01857 {
01858 $ret.= ord(substr($a_str,$i,1))." ";
01859 }
01860 return $ret;
01861 }
01862
01863
01867 function yn2tf($a_yn)
01868 {
01869 if(strtolower($a_yn) == "y")
01870 {
01871 return true;
01872 }
01873 else
01874 {
01875 return false;
01876 }
01877 }
01878
01882 function tf2yn($a_tf)
01883 {
01884 if($a_tf)
01885 {
01886 return "y";
01887 }
01888 else
01889 {
01890 return "f";
01891 }
01892 }
01893
01902 function sort_func ($a, $b)
01903 {
01904 global $array_sortby,$array_sortorder;
01905
01906 if ($array_sortorder == "asc")
01907 {
01908 return strcasecmp($a[$array_sortby], $b[$array_sortby]);
01909 }
01910
01911 if ($array_sortorder == "desc")
01912 {
01913 return strcasecmp($b[$array_sortby], $a[$array_sortby]);
01914 }
01915 }
01916
01925 function sort_func_numeric ($a, $b)
01926 {
01927 global $array_sortby,$array_sortorder;
01928
01929 if ($array_sortorder == "asc")
01930 {
01931 return $a["$array_sortby"] > $b["$array_sortby"];
01932 }
01933
01934 if ($array_sortorder == "desc")
01935 {
01936 return $a["$array_sortby"] < $b["$array_sortby"];
01937 }
01938 }
01949 function sortArray($array,$a_array_sortby,$a_array_sortorder = 0,$a_numeric = false)
01950 {
01951 global $array_sortby,$array_sortorder;
01952
01953 $array_sortby = $a_array_sortby;
01954
01955 if ($a_array_sortorder == "desc")
01956 {
01957 $array_sortorder = "desc";
01958 }
01959 else
01960 {
01961 $array_sortorder = "asc";
01962 }
01963 if($a_numeric)
01964 {
01965 usort($array, array("ilUtil", "sort_func_numeric"));
01966 }
01967 else
01968 {
01969 usort($array, array("ilUtil", "sort_func"));
01970 }
01971
01972
01973 return $array;
01974 }
01975
01985 function unique_multi_array($array, $sub_key)
01986 {
01987 $target = array();
01988 $existing_sub_key_values = array();
01989
01990 foreach ($array as $key=>$sub_array)
01991 {
01992 if (!in_array($sub_array[$sub_key], $existing_sub_key_values))
01993 {
01994 $existing_sub_key_values[] = $sub_array[$sub_key];
01995 $target[$key] = $sub_array;
01996 }
01997 }
01998
01999 return $target;
02000 }
02001
02002
02010 function getGDSupportedImageType($a_desired_type)
02011 {
02012 $a_desired_type = strtolower($a_desired_type);
02013
02014 $im_types = ImageTypes();
02015
02016 switch($a_desired_type)
02017 {
02018 case "jpg":
02019 if ($im_types & IMG_JPG) return "jpg";
02020 if ($im_types & IMG_GIF) return "gif";
02021 if ($im_types & IMG_PNG) return "png";
02022 break;
02023
02024 case "gif":
02025 if ($im_types & IMG_GIF) return "gif";
02026 if ($im_types & IMG_JPG) return "jpg";
02027 if ($im_types & IMG_PNG) return "png";
02028 break;
02029
02030 case "png":
02031 if ($im_types & IMG_PNG) return "png";
02032 if ($im_types & IMG_JPG) return "jpg";
02033 if ($im_types & IMG_GIF) return "gif";
02034 break;
02035 }
02036
02037 return "";
02038 }
02039
02047 function deducibleSize($a_mime)
02048 {
02049 if (($a_mime == "image/gif") || ($a_mime == "image/jpeg") ||
02050 ($a_mime == "image/png") || ($a_mime == "application/x-shockwave-flash") ||
02051 ($a_mime == "image/tiff") || ($a_mime == "image/x-ms-bmp") ||
02052 ($a_mime == "image/psd") || ($a_mime == "image/iff"))
02053 {
02054 return true;
02055 }
02056 else
02057 {
02058 return false;
02059 }
02060 }
02061
02062
02068 function redirect($a_script)
02069 {
02070 global $log;
02071
02072 header("Location: ".$a_script);
02073 exit();
02074 }
02075
02081 function insertInstIntoID($a_value)
02082 {
02083 if (substr($a_value, 0, 4) == "il__")
02084 {
02085 $a_value = "il_".IL_INST_ID."_".substr($a_value, 4, strlen($a_value) - 4);
02086 }
02087
02088 return $a_value;
02089 }
02090
02099 function groupNameExists($a_group_name,$a_id = 0)
02100 {
02101 global $ilDB,$ilErr;
02102
02103 if (empty($a_group_name))
02104 {
02105 $message = get_class($this)."::_NameExists(): No groupname given!";
02106 $ilErr->raiseError($message,$ilErr->WARNING);
02107 }
02108
02109 $clause = ($a_id) ? " AND obj_id != '".$a_id."'" : "";
02110
02111 $q = "SELECT obj_id FROM object_data ".
02112 "WHERE title = '".addslashes($a_group_name)."' ".
02113 "AND type = 'grp'".
02114 $clause;
02115 $r = $ilDB->query($q);
02116
02117 if ($r->numRows() == 1)
02118 {
02119 return true;
02120 }
02121 else
02122 {
02123 return false;
02124 }
02125 }
02126
02127
02128
02129
02130
02131
02132
02133 function searchGroups($a_search_str)
02134 {
02135 global $ilDB;
02136
02137 $q = "SELECT * ".
02138 "FROM object_data ,object_reference ".
02139 "WHERE (object_data.title LIKE '%".$a_search_str."%' ".
02140 "OR object_data.description LIKE '%".$a_search_str."%') ".
02141 "AND object_data.type = 'grp' ".
02142 "AND object_data.obj_id = object_reference.obj_id";
02143
02144 $res = $ilDB->query($q);
02145
02146 while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
02147 {
02148
02149
02150 $ids[$row->obj_id] = array(
02151 "ref_id" => $row->ref_id,
02152 "title" => $row->title,
02153 "description" => $row->description);
02154 }
02155
02156 return $ids ? $ids : array();
02157 }
02158
02159 function getMemString()
02160 {
02161 $my_pid = getmypid();
02162 return ("MEMORY USAGE (% KB PID ): ".`ps -eo%mem,rss,pid | grep $my_pid`);
02163 }
02164
02165 function isWindows()
02166 {
02167 if (strtolower(substr(php_uname(), 0, 3)) == "win")
02168 {
02169 return true;
02170 }
02171 return false;
02172 }
02173
02174 function escapeShellArg($a_arg)
02175 {
02176 global $PHP_OS;
02177
02178 if (ini_get("safe_mode") == 1 || ilUtil::isWindows())
02179 {
02180 return $a_arg;
02181 }
02182 else
02183 {
02184 return escapeshellarg($a_arg);
02185 }
02186 }
02187
02188
02189
02190
02191
02192
02193
02194
02195
02196
02197
02198
02199
02200
02201
02202
02203
02204
02205
02206
02207
02208 function excelTime($year = "", $month = "", $day = "", $hour = "", $minute = "", $second = "")
02209 {
02210 $starting_time = mktime(0, 0, 0, 1, 1, 1970);
02211 if (strcmp("$year$month$day$hour$minute$second", "") == 0)
02212 {
02213 $target_time = time();
02214 }
02215 else
02216 {
02217 if ($year < 1970)
02218 {
02219 return 0;
02220 }
02221 }
02222 $target_time = mktime($hour, $minute, $second, $month, $day, $year);
02223 $difference = $target_time - $starting_time;
02224 $days = (($difference - ($difference % 86400)) / 86400);
02225 $difference = $difference - ($days * 86400) + 3600;
02226 return ($days + 25569 + ($difference / 86400));
02227 }
02228
02232 function renameExecutables($a_dir)
02233 {
02234 ilUtil::rRenameSuffix($a_dir, "php", "sec");
02235 ilUtil::rRenameSuffix($a_dir, "php3", "sec");
02236 ilUtil::rRenameSuffix($a_dir, "php4", "sec");
02237 ilUtil::rRenameSuffix($a_dir, "inc", "sec");
02238 ilUtil::rRenameSuffix($a_dir, "lang", "sec");
02239 ilUtil::rRenameSuffix($a_dir, "phtml", "sec");
02240 ilUtil::rRenameSuffix($a_dir, "htaccess", "sec");
02241 }
02242
02251 function rRenameSuffix ($a_dir, $a_old_suffix, $a_new_suffix)
02252 {
02253 if ($a_dir == "/" || $a_dir == "" || is_int(strpos($a_dir, "..")))
02254 {
02255 return false;
02256 }
02257
02258
02259 if (!@is_dir($a_dir))
02260 {
02261 return false;
02262 }
02263
02264
02265 $dir = opendir($a_dir);
02266
02267 while($file = readdir($dir))
02268 {
02269 if ($file != "." and
02270 $file != "..")
02271 {
02272
02273 if (@is_dir($a_dir."/".$file))
02274 {
02275 ilUtil::rRenameSuffix($a_dir."/".$file, $a_old_suffix, $a_new_suffix);
02276 }
02277
02278
02279 if (@is_file($a_dir."/".$file))
02280 {
02281 $path_info = pathinfo($a_dir."/".$file);
02282 if (strtolower($path_info["extension"]) ==
02283 strtolower($a_old_suffix))
02284 {
02285 $pos = strrpos($a_dir."/".$file, ".");
02286 $new_name = substr($a_dir."/".$file, 0, $pos).".".$a_new_suffix;
02287 rename($a_dir."/".$file, $new_name);
02288 }
02289 }
02290 }
02291 }
02292 return true;
02293 }
02294
02295 function isAPICall () {
02296 return strpos($_SERVER["SCRIPT_FILENAME"],"api") !== false ||
02297 strpos($_SERVER["SCRIPT_FILENAME"],"dummy") !== false;
02298 }
02299
02300 function KT_replaceParam($qstring, $paramName, $paramValue) {
02301 if (preg_match("/&" . $paramName . "=/", $qstring)) {
02302 return preg_replace("/&" . $paramName . "=[^&]+/", "&" . $paramName . "=" . urlencode($paramValue), $qstring);
02303 } else {
02304 return $qstring . "&" . $paramName . "=" . urlencode($paramValue);
02305 }
02306 }
02307
02308 function replaceUrlParameterString ($url, $parametersArray) {
02309
02310 foreach ($parametersArray as $paramName => $paramValue ) {
02311 $url = ilUtil::KT_replaceParam($url, $paramName, $paramValue);
02312 }
02313 return $url;
02314 }
02315
02316 function generatePasswords ($a_number)
02317 {
02318 $ret = array();
02319 srand((double) microtime()*1000000);
02320
02321 for ($i=1; $i<=$a_number; $i++)
02322 {
02323 $length = rand(6,10);
02324 $next = rand(1,2);
02325
02326 $vowels = "aeiou";
02327 $consonants = "bcdfghjklmnpqrstvwxyz";
02328 $pw = "";
02329
02330 for ($j=0; $j < $length; $j++)
02331 {
02332 switch ($next)
02333 {
02334 case 1:
02335 $pw.= $consonants[rand(0,strlen($consonants)-1)];
02336 $next = 2;
02337 break;
02338
02339 case 2:
02340 $pw.= $vowels[rand(0,strlen($vowels)-1)];
02341 $next = 1;
02342 break;
02343 }
02344 }
02345
02346 $ret[] = $pw;
02347 }
02348
02349 return $ret;
02350 }
02351
02352 function removeTrailingPathSeparators($path)
02353 {
02354 $path = preg_replace("/[\/\\\]+$/", "", $path);
02355 return $path;
02356 }
02357
02366 function array_php2js($data)
02367 {
02368 foreach($data as $k=>$datum)
02369 {
02370 if(is_null($datum)) $data[$k] = 'null';
02371 if(is_string($datum)) $data[$k] = "'" . $datum . "'";
02372 if(is_array($datum)) $data[$k] = array_php2js($datum);
02373 }
02374
02375 return "[" . implode(', ', $data) . "]";
02376 }
02377
02382 function virusHandling($a_file, $a_orig_name = "", $a_clean = true)
02383 {
02384 global $lng;
02385
02386 if (IL_VIRUS_SCANNER != "None")
02387 {
02388 require_once("classes/class.ilVirusScannerFactory.php");
02389 $vs = ilVirusScannerFactory::_getInstance();
02390 if (($vs_txt = $vs->scanFile($a_file, $a_orig_name)) != "")
02391 {
02392 if ($a_clean && (IL_VIRUS_CLEAN_COMMAND != ""))
02393 {
02394 $clean_txt = $vs->cleanFile($a_file, $a_orig_name);
02395 if ($vs->fileCleaned())
02396 {
02397 $vs_txt.= "<br />".$lng->txt("cleaned_file").
02398 "<br />".$clean_txt;
02399 $vs_txt.= "<br />".$lng->txt("repeat_scan");
02400 if (($vs2_txt = $vs->scanFile($a_file, $a_orig_name)) != "")
02401 {
02402 return array(false, nl2br($vs_txt)."<br />".$lng->txt("repeat_scan_failed").
02403 "<br />".nl2br($vs2_txt));
02404 }
02405 else
02406 {
02407 return array(true, nl2br($vs_txt)."<br />".$lng->txt("repeat_scan_succeded"));
02408 }
02409 }
02410 else
02411 {
02412 return array(false, nl2br($vs_txt)."<br />".$lng->txt("cleaning_failed"));
02413 }
02414 }
02415 else
02416 {
02417 return array(false, nl2br($vs_txt));
02418 }
02419 }
02420 }
02421 return array(true,"");
02422 }
02423
02424
02428 function moveUploadedFile($a_file, $a_name, $a_target, $a_raise_errors = true)
02429 {
02430 global $lng, $ilias;
02431
02432 if (!is_file($a_file))
02433 {
02434 $lng->txt("upload_error_file_not_found");
02435 }
02436
02437
02438 $vir = ilUtil::virusHandling($a_file, $a_name);
02439 if (!$vir[0])
02440 {
02441 unlink($a_file);
02442 if ($a_raise_errors)
02443 {
02444 $ilias->raiseError($lng->txt("file_is_infected")."<br />".
02445 $vir[1],
02446 $ilias->error_obj->MESSAGE);
02447 }
02448 else
02449 {
02450 sendInfo($lng->txt("file_is_infected")."<br />".
02451 $vir[1], true);
02452 }
02453 return false;
02454 }
02455 else
02456 {
02457 if ($vir[1] != "")
02458 {
02459 sendInfo($vir[1], true);
02460 }
02461 return move_uploaded_file($a_file, $a_target);
02462 }
02463 }
02464
02465
02466 }
02467 ?>