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
00035 require_once "class.ilObject.php";
00036
00037 class ilObjUserFolder extends ilObject
00038 {
00045 function ilObjUserFolder($a_id,$a_call_by_reference = true)
00046 {
00047 $this->type = "usrf";
00048 $this->ilObject($a_id,$a_call_by_reference);
00049 }
00050
00057 function ilClone($a_parent_ref)
00058 {
00059
00060 return false;
00061
00062 global $rbacadmin;
00063
00064
00065 $new_ref_id = parent::ilClone($a_parent_ref);
00066
00067
00068
00069
00070 return $new_ref_id;
00071 }
00072
00079 function delete()
00080 {
00081
00082 return false;
00083
00084
00085 if (!parent::delete())
00086 {
00087 return false;
00088 }
00089
00090
00091
00092 return true;
00093 }
00094
00095
00096 function getExportFilename($a_mode = "userfolder_export_excel_x86")
00097 {
00098 $filename = "";
00099
00100
00101 $inst_id = IL_INST_ID;
00102
00103 $date = time();
00104
00105 switch($a_mode)
00106 {
00107 case "userfolder_export_excel_x86":
00108 $filename = $date."__".$inst_id."__xls_usrf.xls";
00109 break;
00110 case "userfolder_export_csv":
00111 $filename = $date."__".$inst_id."__csv_usrf.csv";
00112 break;
00113 case "userfolder_export_xml":
00114 $filename = $date."__".$inst_id."__xml_usrf.xml";
00115 break;
00116 }
00117 return $filename;
00118 }
00119
00120
00128 function getExportDirectory()
00129 {
00130 $export_dir = ilUtil::getDataDir()."/usrf_data/export";
00131
00132 return $export_dir;
00133 }
00134
00143 function getExportFiles()
00144 {
00145 $dir = $this->getExportDirectory();
00146
00147
00148 if (!@is_dir($dir) or
00149 !is_writeable($dir))
00150 {
00151 return array();
00152 }
00153
00154
00155 $dir = dir($dir);
00156
00157
00158 $file = array();
00159
00160
00161 while ($entry = $dir->read())
00162 {
00163 if ($entry != "." and
00164 $entry != ".." and
00165 preg_match("/^[0-9]{10}_{2}[0-9]+_{2}([a-z0-9]{3})_usrf\.[a-z]{1,3}\$/", $entry, $matches))
00166 {
00167 $filearray["filename"] = $entry;
00168 $filearray["filesize"] = filesize($this->getExportDirectory()."/".$entry);
00169 array_push($file, $filearray);
00170 }
00171 }
00172
00173
00174 $dir->close();
00175
00176
00177 sort ($file);
00178 reset ($file);
00179
00180 return $file;
00181 }
00182
00183 function escapeXML($value)
00184 {
00185 $value = str_replace("&", "&", $value);
00186 $value = str_replace("<", "<", $value);
00187 $value = str_replace(">", ">", $value);
00188 return $value;
00189 }
00190
00191 function createXMLExport(&$settings, &$data, $filename)
00192 {
00193 include_once 'classes/class.ilUserDefinedData.php';
00194 include_once "./classes/class.ilObjUser.php";
00195
00196 global $rbacreview;
00197 global $ilDB;
00198 global $log;
00199
00200 $file = fopen($filename, "w");
00201 fwrite($file, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
00202 fwrite($file, "<!DOCTYPE Users SYSTEM \"ilias_user_3_7.dtd\">\n");
00203 fwrite($file, "<Users>");
00204 foreach ($data as $row)
00205 {
00206
00207 foreach ($row as $key => $value)
00208 {
00209 $row[$key] = $this->escapeXML($value);
00210 }
00211 $userline = "";
00212
00213 if (strlen($row["language"]) == 0) $row["language"] = "en";
00214 $userline .= "<User Id=\"il_".IL_INST_ID."_usr_".$row["usr_id"]."\" Language=\"".$row["language"]."\" Action=\"Insert\">";
00215 if (array_search("login", $settings) !== FALSE)
00216 {
00217 $userline .= "<Login>".$row["login"]."</Login>";
00218 }
00219
00220 $query = sprintf("SELECT object_data.title, rbac_fa.* FROM object_data, rbac_ua, rbac_fa WHERE rbac_ua.usr_id = %s AND rbac_ua.rol_id = rbac_fa.rol_id AND object_data.obj_id = rbac_fa.rol_id",
00221 $ilDB->quote($row["usr_id"])
00222 );
00223 $rbacresult = $ilDB->query($query);
00224 while ($rbacrow = $rbacresult->fetchRow(DB_FETCHMODE_ASSOC))
00225 {
00226 $type = "";
00227 if ($rbacrow["assign"] == "y")
00228 {
00229 if ($rbacrow["parent"] == ROLE_FOLDER_ID)
00230 {
00231 $type = "Global";
00232 }
00233 else
00234 {
00235 $type = "Local";
00236 }
00237 if (strlen($type))
00238 {
00239 $userline .= "<Role Id=\"il_".IL_INST_ID."_role_".$rbacrow["rol_id"]."\" Type=\"".$type."\">".$this->escapeXML($rbacrow["title"])."</Role>";
00240 }
00241 }
00242 }
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271 $i2passwd = FALSE;
00272 if (array_search("i2passwd", $settings) !== FALSE)
00273 {
00274 if (strlen($row["i2passwd"])) $i2passwd = TRUE;
00275 if ($i2passwd) $userline .= "<Password Type=\"ILIAS2\">".$row["i2passwd"]."</Password>";
00276 }
00277 if ((!$i2passwd) && (array_search("passwd", $settings) !== FALSE))
00278 {
00279 if (strlen($row["passwd"])) $userline .= "<Password Type=\"ILIAS3\">".$row["passwd"]."</Password>";
00280 }
00281 if (array_search("firstname", $settings) !== FALSE)
00282 {
00283 if (strlen($row["firstname"])) $userline .= "<Firstname>".$row["firstname"]."</Firstname>";
00284 }
00285 if (array_search("lastname", $settings) !== FALSE)
00286 {
00287 if (strlen($row["lastname"])) $userline .= "<Lastname>".$row["lastname"]."</Lastname>";
00288 }
00289 if (array_search("title", $settings) !== FALSE)
00290 {
00291 if (strlen($row["title"])) $userline .= "<Title>".$row["title"]."</Title>";
00292 }
00293 if (array_search("upload", $settings) !== FALSE)
00294 {
00295
00296 $q = sprintf("SELECT value FROM usr_pref WHERE usr_id=%s AND keyword='profile_image'", $ilDB->quote($row["usr_id"] . ""));
00297 $r = $ilDB->query($q);
00298 if ($r->numRows() == 1)
00299 {
00300 $personal_picture_data = $r->fetchRow(DB_FETCHMODE_ASSOC);
00301 $personal_picture = $personal_picture_data["value"];
00302 $webspace_dir = ilUtil::getWebspaceDir();
00303 $image_file = $webspace_dir."/usr_images/".$personal_picture;
00304 if (@is_file($image_file))
00305 {
00306 $fh = fopen($image_file, "rb");
00307 if ($fh)
00308 {
00309 $image_data = fread($fh, filesize($image_file));
00310 fclose($fh);
00311 $base64 = base64_encode($image_data);
00312 $imagetype = "image/jpeg";
00313 if (preg_match("/.*\.(png|gif)$/", $personal_picture, $matches))
00314 {
00315 $imagetype = "image/".$matches[1];
00316 }
00317 $userline .= "<PersonalPicture imagetype=\"$imagetype\" encoding=\"Base64\">$base64</PersonalPicture>";
00318 }
00319 }
00320 }
00321 }
00322 if (array_search("gender", $settings) !== FALSE)
00323 {
00324 if (strlen($row["gender"])) $userline .= "<Gender>".$row["gender"]."</Gender>";
00325 }
00326 if (array_search("email", $settings) !== FALSE)
00327 {
00328 if (strlen($row["email"])) $userline .= "<Email>".$row["email"]."</Email>";
00329 }
00330 if (array_search("institution", $settings) !== FALSE)
00331 {
00332 if (strlen($row["institution"])) $userline .= "<Institution>".$row["institution"]."</Institution>";
00333 }
00334 if (array_search("street", $settings) !== FALSE)
00335 {
00336 if (strlen($row["street"])) $userline .= "<Street>".$row["street"]."</Street>";
00337 }
00338 if (array_search("city", $settings) !== FALSE)
00339 {
00340 if (strlen($row["city"])) $userline .= "<City>".$row["city"]."</City>";
00341 }
00342 if (array_search("zipcode", $settings) !== FALSE)
00343 {
00344 if (strlen($row["zipcode"])) $userline .= "<PostalCode>".$row["zipcode"]."</PostalCode>";
00345 }
00346 if (array_search("country", $settings) !== FALSE)
00347 {
00348 if (strlen($row["country"])) $userline .= "<Country>".$row["country"]."</Country>";
00349 }
00350 if (array_search("phone_office", $settings) !== FALSE)
00351 {
00352 if (strlen($row["phone_office"])) $userline .= "<PhoneOffice>".$row["phone_office"]."</PhoneOffice>";
00353 }
00354 if (array_search("phone_home", $settings) !== FALSE)
00355 {
00356 if (strlen($row["phone_home"])) $userline .= "<PhoneHome>".$row["phone_home"]."</PhoneHome>";
00357 }
00358 if (array_search("phone_mobile", $settings) !== FALSE)
00359 {
00360 if (strlen($row["phone_mobile"])) $userline .= "<PhoneMobile>".$row["phone_mobile"]."</PhoneMobile>";
00361 }
00362 if (array_search("fax", $settings) !== FALSE)
00363 {
00364 if (strlen($row["fax"])) $userline .= "<Fax>".$row["fax"]."</Fax>";
00365 }
00366 if (strlen($row["hobby"])) if (array_search("hobby", $settings) !== FALSE)
00367 {
00368 $userline .= "<Hobby>".$row["hobby"]."</Hobby>";
00369 }
00370 if (array_search("department", $settings) !== FALSE)
00371 {
00372 if (strlen($row["department"])) $userline .= "<Department>".$row["department"]."</Department>";
00373 }
00374 if (array_search("referral_comment", $settings) !== FALSE)
00375 {
00376 if (strlen($row["referral_comment"])) $userline .= "<Comment>".$row["referral_comment"]."</Comment>";
00377 }
00378 if (array_search("matriculation", $settings) !== FALSE)
00379 {
00380 if (strlen($row["matriculation"])) $userline .= "<Matriculation>".$row["matriculation"]."</Matriculation>";
00381 }
00382 if (array_search("active", $settings) !== FALSE)
00383 {
00384 if ($row["active"])
00385 {
00386 $userline .= "<Active>true</Active>";
00387 }
00388 else
00389 {
00390 $userline .= "<Active>false</Active>";
00391 }
00392 }
00393 if (array_search("client_ip", $settings) !== FALSE)
00394 {
00395 if (strlen($row["client_ip"])) $userline .= "<ClientIP>".$row["client_ip"]."</ClientIP>";
00396 }
00397 if (array_search("time_limit_owner", $settings) !== FALSE)
00398 {
00399 if (strlen($row["time_limit_owner"])) $userline .= "<TimeLimitOwner>".$row["time_limit_owner"]."</TimeLimitOwner>";
00400 }
00401 if (array_search("time_limit_unlimited", $settings) !== FALSE)
00402 {
00403 if (strlen($row["time_limit_unlimited"])) $userline .= "<TimeLimitUnlimited>".$row["time_limit_unlimited"]."</TimeLimitUnlimited>";
00404 }
00405 if (array_search("time_limit_from", $settings) !== FALSE)
00406 {
00407 if (strlen($row["time_limit_from"])) $userline .= "<TimeLimitFrom>".$row["time_limit_from"]."</TimeLimitFrom>";
00408 }
00409 if (array_search("time_limit_until", $settings) !== FALSE)
00410 {
00411 if (strlen($row["time_limit_until"])) $userline .= "<TimeLimitUntil>".$row["time_limit_until"]."</TimeLimitUntil>";
00412 }
00413 if (array_search("time_limit_message", $settings) !== FALSE)
00414 {
00415 if (strlen($row["time_limit_message"])) $userline .= "<TimeLimitMessage>".$row["time_limit_message"]."</TimeLimitMessage>";
00416 }
00417 if (array_search("approve_date", $settings) !== FALSE)
00418 {
00419 if (strlen($row["approve_date"])) $userline .= "<ApproveDate>".$row["approve_date"]."</ApproveDate>";
00420 }
00421 if (array_search("agree_date", $settings) !== FALSE)
00422 {
00423 if (strlen($row["agree_date"])) $userline .= "<AgreeDate>".$row["agree_date"]."</AgreeDate>";
00424 }
00425 if ((int) $row["ilinc_id"] !=0) {
00426 if (array_search("ilinc_id", $settings) !== FALSE)
00427 {
00428 if (strlen($row["ilinc_id"])) $userline .= "<iLincID>".$row["ilinc_id"]."</iLincID>";
00429 }
00430 if (array_search("ilinc_login", $settings) !== FALSE)
00431 {
00432 if (strlen($row["ilinc_login"])) $userline .= "<iLincLogin>".$row["ilinc_login"]."</iLincLogin>";
00433 }
00434 if (array_search("ilinc_passwd", $settings) !== FALSE)
00435 {
00436 if (strlen($row["ilinc_passwd"])) $userline .= "<iLincPasswd>".$row["ilinc_passwd"]."</iLincPasswd>";
00437 }
00438 }
00439 if (array_search("auth_mode", $settings) !== FALSE)
00440 {
00441 if (strlen($row["auth_mode"])) $userline .= "<AuthMode type=\"".$row["auth_mode"]."\"></AuthMode>";
00442 }
00443 if (array_search("skin_style", $settings) !== FALSE)
00444 {
00445 $userline .=
00446 "<Look Skin=\"" . ilObjUser::_lookupPref($row["usr_id"], "skin") . "\" " .
00447 "Style=\"" . ilObjUser::_lookupPref($row["usr_id"], "style") . "\"></Look>";
00448 }
00449
00450
00451 $udf_data = new ilUserDefinedData($row['usr_id']);
00452 $userline .= $udf_data->toXML();
00453
00454 $userline .= "</User>";
00455 fwrite($file, $userline);
00456 }
00457 fwrite($file, "</Users>");
00458 fclose($file);
00459 }
00460
00461 function createCSVExport(&$settings, &$data, $filename)
00462 {
00463 $headerrow = array();
00464 foreach ($settings as $value)
00465 {
00466 array_push($headerrow, $this->lng->txt($value));
00467 }
00468 $separator = ";";
00469 $file = fopen($filename, "w");
00470 $formattedrow =& ilUtil::processCSVRow($headerrow, TRUE, $separator);
00471 fwrite($file, join ($separator, $formattedrow) ."");
00472 foreach ($data as $row)
00473 {
00474 $csvrow = array();
00475 foreach ($settings as $header)
00476 {
00477 array_push($csvrow, $row[$header]);
00478 }
00479 $formattedrow =& ilUtil::processCSVRow($csvrow, TRUE, $separator);
00480 fwrite($file, join ($separator, $formattedrow) ."");
00481 }
00482 fclose($file);
00483 }
00484
00485 function createExcelExport(&$settings, &$data, $filename, $a_mode)
00486 {
00487 include_once ("./classes/class.ilExcelUtils.php");
00488 include_once "./classes/class.ilExcelWriterAdapter.php";
00489 $adapter = new ilExcelWriterAdapter($filename, FALSE);
00490 $workbook = $adapter->getWorkbook();
00491
00492 $format_bold =& $workbook->addFormat();
00493 $format_bold->setBold();
00494 $format_percent =& $workbook->addFormat();
00495 $format_percent->setNumFormat("0.00%");
00496 $format_datetime =& $workbook->addFormat();
00497 $format_datetime->setNumFormat("DD/MM/YYYY hh:mm:ss");
00498 $format_title =& $workbook->addFormat();
00499 $format_title->setBold();
00500 $format_title->setColor('black');
00501 $format_title->setPattern(1);
00502 $format_title->setFgColor('silver');
00503 $worksheet =& $workbook->addWorksheet();
00504 $row = 0;
00505 $col = 0;
00506
00507 foreach ($settings as $value)
00508 {
00509 $worksheet->write($row, $col, ilExcelUtils::_convert_text($this->lng->txt($value), $a_mode), $format_title);
00510 $col++;
00511 }
00512
00513
00514 foreach ($data as $index => $rowdata)
00515 {
00516 $row++;
00517 $col = 0;
00518 foreach ($settings as $fieldname)
00519 {
00520
00521
00522 $value = $rowdata[$fieldname];
00523 switch ($fieldname)
00524 {
00525 case "language":
00526 $worksheet->write($row, $col, ilExcelUtils::_convert_text($this->lng->txt("lang_".$value), $a_mode));
00527 break;
00528 case "time_limit_from":
00529 case "time_limit_until":
00530 $date = strftime("%Y-%m-%d %H:%M:%S", $value);
00531 if (preg_match("/(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})/", $date, $matches))
00532 {
00533 $worksheet->write($row, $col, ilUtil::excelTime($matches[1],$matches[2],$matches[3],$matches[4],$matches[5],$matches[6]), $format_datetime);
00534 }
00535 break;
00536 case "last_login":
00537 case "last_update":
00538 case "create_date":
00539 case "approve_date":
00540 case "agree_date":
00541 if (preg_match("/(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})/", $value, $matches))
00542 {
00543 $worksheet->write($row, $col, ilUtil::excelTime($matches[1],$matches[2],$matches[3],$matches[4],$matches[5],$matches[6]), $format_datetime);
00544 }
00545 break;
00546 default:
00547 $worksheet->write($row, $col, ilExcelUtils::_convert_text($value, $a_mode));
00548 break;
00549 }
00550 $col++;
00551 }
00552 }
00553 $workbook->close();
00554 }
00555
00556 function getExportSettings()
00557 {
00558 global $ilDB;
00559
00560 $db_settings = array();
00561 $profile_fields =& $this->getProfileFields();
00562 $query = "SELECT * FROM `settings` WHERE keyword LIKE '%usr_settings_export_%' AND value = '1'";
00563 $result = $ilDB->query($query);
00564 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
00565 {
00566 if (preg_match("/usr_settings_export_(.*)/", $row["keyword"], $setting))
00567 {
00568 array_push($db_settings, $setting[1]);
00569 }
00570 }
00571 $export_settings = array();
00572 foreach ($profile_fields as $key => $value)
00573 {
00574 if (in_array($value, $db_settings))
00575 {
00576 if (strcmp($value, "password") == 0)
00577 {
00578 array_push($export_settings, "passwd");
00579 }
00580 else
00581 {
00582 array_push($export_settings, $value);
00583 }
00584 }
00585 }
00586 array_push($export_settings, "login");
00587 array_push($export_settings, "last_login");
00588 array_push($export_settings, "last_update");
00589 array_push($export_settings, "create_date");
00590 array_push($export_settings, "i2passwd");
00591 array_push($export_settings, "time_limit_owner");
00592 array_push($export_settings, "time_limit_unlimited");
00593 array_push($export_settings, "time_limit_from");
00594 array_push($export_settings, "time_limit_until");
00595 array_push($export_settings, "time_limit_message");
00596 array_push($export_settings, "active");
00597 array_push($export_settings, "approve_date");
00598 array_push($export_settings, "agree_date");
00599 array_push($export_settings, "ilinc_id");
00600 array_push($export_settings, "ilinc_login");
00601 array_push($export_settings, "ilinc_passwd");
00602 array_push($export_settings, "client_ip");
00603 array_push($export_settings, "auth_mode");
00604 return $export_settings;
00605 }
00606
00610 function buildExportFile($a_mode = "userfolder_export_excel_x86")
00611 {
00612 global $ilBench;
00613 global $log;
00614 global $ilDB;
00615 global $ilias;
00616
00617
00618 $expDir = $this->getExportDirectory();
00619
00620
00621
00622
00623
00624
00625 $this->createExportDirectory();
00626
00627
00628
00629 $settings =& $this->getExportSettings();
00630 $data = array();
00631 $query = "SELECT usr_data.*, usr_pref.value AS language FROM usr_data, usr_pref WHERE usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = 'language' ORDER BY usr_data.lastname, usr_data.firstname";
00632 $result = $ilDB->query($query);
00633 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
00634 {
00635
00636 array_push($data, $row);
00637
00638 }
00639
00640
00641 $fullname = $expDir."/".$this->getExportFilename($a_mode);
00642 switch ($a_mode)
00643 {
00644 case "userfolder_export_excel_x86":
00645 $this->createExcelExport($settings, $data, $fullname, "latin1");
00646 break;
00647 case "userfolder_export_csv":
00648 $this->createCSVExport($settings, $data, $fullname);
00649 break;
00650 case "userfolder_export_xml":
00651 $this->createXMLExport($settings, $data, $fullname);
00652 break;
00653 }
00654
00655
00656 return $fullname;
00657 }
00658
00659
00665 function createExportDirectory()
00666 {
00667 if (!@is_dir($this->getExportDirectory()))
00668 {
00669 $usrf_data_dir = ilUtil::getDataDir()."/usrf_data";
00670 ilUtil::makeDir($usrf_data_dir);
00671 if(!is_writable($usrf_data_dir))
00672 {
00673 $this->ilias->raiseError("Userfolder data directory (".$usrf_data_dir
00674 .") not writeable.",$this->ilias->error_obj->MESSAGE);
00675 }
00676
00677
00678 $export_dir = $usrf_data_dir."/export";
00679 ilUtil::makeDir($export_dir);
00680 if(!@is_dir($export_dir))
00681 {
00682 $this->ilias->raiseError("Creation of Userfolder Export Directory failed.",$this->ilias->error_obj->MESSAGE);
00683 }
00684 }
00685 }
00686
00687 function &getProfileFields()
00688 {
00689 $profile_fields = array(
00690 "gender",
00691 "firstname",
00692 "lastname",
00693 "title",
00694 "upload",
00695 "password",
00696 "institution",
00697 "department",
00698 "street",
00699 "zipcode",
00700 "city",
00701 "country",
00702 "phone_office",
00703 "phone_home",
00704 "phone_mobile",
00705 "fax",
00706 "email",
00707 "hobby",
00708 "referral_comment",
00709 "matriculation",
00710 "language",
00711 "skin_style",
00712 "hits_per_page",
00713 "show_users_online"
00714 );
00715 return $profile_fields;
00716 }
00717
00718 function _writeNewAccountMail($a_lang, $a_subject, $a_sal_g, $a_sal_f, $a_sal_m, $a_body)
00719 {
00720 global $ilDB;
00721
00722 $ilDB->query("REPLACE INTO usr_new_account_mail ".
00723 "(lang, subject, body, sal_g, sal_f, sal_m) VALUES ".
00724 "(".$ilDB->quote($a_lang).",".$ilDB->quote($a_subject).",".$ilDB->quote($a_body).
00725 ",".$ilDB->quote($a_sal_g).",".$ilDB->quote($a_sal_f).",".$ilDB->quote($a_sal_m).")");
00726 }
00727
00728 function _lookupNewAccountMail($a_lang)
00729 {
00730 global $ilDB;
00731
00732 $set = $ilDB->query("SELECT * FROM usr_new_account_mail ".
00733 " WHERE lang = ".$ilDB->quote($a_lang));
00734
00735 if ($rec = $set->fetchRow(DB_FETCHMODE_ASSOC))
00736 {
00737 return $rec;
00738 }
00739 return array();
00740 }
00741
00742 }
00743 ?>