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 global $rbacreview;
00194 global $ilDB;
00195 global $log;
00196
00197 $file = fopen($filename, "w");
00198 fwrite($file, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
00199 fwrite($file, "<!DOCTYPE Users SYSTEM \"ilias_user_0_2.dtd\">\n");
00200 fwrite($file, "<Users>\n");
00201 foreach ($data as $row)
00202 {
00203
00204 foreach ($row as $key => $value)
00205 {
00206 $row[$key] = $this->escapeXML($value);
00207 }
00208 $userline = "";
00209
00210 if (strlen($row["language"]) == 0) $row["language"] = "en";
00211 $userline .= "<User Id=\"".$row["usr_id"]."\" Language=\"".$row["language"]."\" Action=\"Insert\">\n";
00212 if (array_search("login", $settings) !== FALSE)
00213 {
00214 $userline .= "<Login>".$row["login"]."</Login>\n";
00215 }
00216
00217 $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",
00218 $ilDB->quote($row["usr_id"])
00219 );
00220 $rbacresult = $ilDB->query($query);
00221 while ($rbacrow = $rbacresult->fetchRow(DB_FETCHMODE_ASSOC))
00222 {
00223 $type = "";
00224 if ($rbacrow["assign"] == "y")
00225 {
00226 if ($rbacrow["parent"] == ROLE_FOLDER_ID)
00227 {
00228 $type = "Global";
00229 }
00230 else
00231 {
00232 $type = "Local";
00233 }
00234 if (strlen($type))
00235 {
00236 $userline .= "<Role Id=\"".$rbacrow["rol_id"]."\" Type=\"".$type."\">".$this->escapeXML($rbacrow["title"])."</Role>\n";
00237 }
00238 }
00239 }
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 $i2passwd = FALSE;
00269 if (array_search("i2passwd", $settings) !== FALSE)
00270 {
00271 if (strlen($row["i2passwd"])) $i2passwd = TRUE;
00272 if ($i2passwd) $userline .= "<Password Type=\"ILIAS2\">".$row["i2passwd"]."</Password>\n";
00273 }
00274 if ((!$i2passwd) && (array_search("passwd", $settings) !== FALSE))
00275 {
00276 if (strlen($row["passwd"])) $userline .= "<Password Type=\"ILIAS3\">".$row["passwd"]."</Password>\n";
00277 }
00278 if (array_search("firstname", $settings) !== FALSE)
00279 {
00280 if (strlen($row["firstname"])) $userline .= "<Firstname>".$row["firstname"]."</Firstname>\n";
00281 }
00282 if (array_search("lastname", $settings) !== FALSE)
00283 {
00284 if (strlen($row["lastname"])) $userline .= "<Lastname>".$row["lastname"]."</Lastname>\n";
00285 }
00286 if (array_search("title", $settings) !== FALSE)
00287 {
00288 if (strlen($row["title"])) $userline .= "<Title>".$row["title"]."</Title>\n";
00289 }
00290 if (array_search("upload", $settings) !== FALSE)
00291 {
00292
00293 $q = sprintf("SELECT value FROM usr_pref WHERE usr_id=%s AND keyword='profile_image'", $ilDB->quote($row["usr_id"] . ""));
00294 $r = $ilDB->query($q);
00295 if ($r->numRows() == 1)
00296 {
00297 $personal_picture_data = $r->fetchRow(DB_FETCHMODE_ASSOC);
00298 $personal_picture = $personal_picture_data["value"];
00299 $webspace_dir = ilUtil::getWebspaceDir();
00300 $image_file = $webspace_dir."/usr_images/".$personal_picture;
00301 if (@is_file($image_file))
00302 {
00303 $fh = fopen($image_file, "rb");
00304 if ($fh)
00305 {
00306 $image_data = fread($fh, filesize($image_file));
00307 fclose($fh);
00308 $base64 = base64_encode($image_data);
00309 $imagetype = "image/jpeg";
00310 if (preg_match("/.*\.(png|gif)$/", $personal_picture, $matches))
00311 {
00312 $imagetype = "image/".$matches[1];
00313 }
00314 $userline .= "<PersonalPicture imagetype=\"$imagetype\" encoding=\"Base64\">$base64</PersonalPicture>\n";
00315 }
00316 }
00317 }
00318 }
00319 if (array_search("gender", $settings) !== FALSE)
00320 {
00321 if (strlen($row["gender"])) $userline .= "<Gender>".$row["gender"]."</Gender>\n";
00322 }
00323 if (array_search("email", $settings) !== FALSE)
00324 {
00325 if (strlen($row["email"])) $userline .= "<Email>".$row["email"]."</Email>\n";
00326 }
00327 if (array_search("institution", $settings) !== FALSE)
00328 {
00329 if (strlen($row["institution"])) $userline .= "<Institution>".$row["institution"]."</Institution>\n";
00330 }
00331 if (array_search("street", $settings) !== FALSE)
00332 {
00333 if (strlen($row["street"])) $userline .= "<Street>".$row["street"]."</Street>\n";
00334 }
00335 if (array_search("city", $settings) !== FALSE)
00336 {
00337 if (strlen($row["city"])) $userline .= "<City>".$row["city"]."</City>\n";
00338 }
00339 if (array_search("zipcode", $settings) !== FALSE)
00340 {
00341 if (strlen($row["zipcode"])) $userline .= "<PostalCode>".$row["zipcode"]."</PostalCode>\n";
00342 }
00343 if (array_search("country", $settings) !== FALSE)
00344 {
00345 if (strlen($row["country"])) $userline .= "<Country>".$row["country"]."</Country>\n";
00346 }
00347 if (array_search("phone_office", $settings) !== FALSE)
00348 {
00349 if (strlen($row["phone_office"])) $userline .= "<PhoneOffice>".$row["phone_office"]."</PhoneOffice>\n";
00350 }
00351 if (array_search("phone_home", $settings) !== FALSE)
00352 {
00353 if (strlen($row["phone_home"])) $userline .= "<PhoneHome>".$row["phone_home"]."</PhoneHome>\n";
00354 }
00355 if (array_search("phone_mobile", $settings) !== FALSE)
00356 {
00357 if (strlen($row["phone_mobile"])) $userline .= "<PhoneMobile>".$row["phone_mobile"]."</PhoneMobile>\n";
00358 }
00359 if (array_search("fax", $settings) !== FALSE)
00360 {
00361 if (strlen($row["fax"])) $userline .= "<Fax>".$row["fax"]."</Fax>\n";
00362 }
00363 if (strlen($row["hobby"])) if (array_search("hobby", $settings) !== FALSE)
00364 {
00365 $userline .= "<Hobby>".$row["hobby"]."</Hobby>\n";
00366 }
00367 if (array_search("department", $settings) !== FALSE)
00368 {
00369 if (strlen($row["department"])) $userline .= "<Department>".$row["department"]."</Department>\n";
00370 }
00371 if (array_search("referral_comment", $settings) !== FALSE)
00372 {
00373 if (strlen($row["referral_comment"])) $userline .= "<Comment>".$row["referral_comment"]."</Comment>\n";
00374 }
00375 if (array_search("matriculation", $settings) !== FALSE)
00376 {
00377 if (strlen($row["matriculation"])) $userline .= "<Matriculation>".$row["matriculation"]."</Matriculation>\n";
00378 }
00379 if (array_search("active", $settings) !== FALSE)
00380 {
00381 if ($row["active"])
00382 {
00383 $userline .= "<Active>true</Active>\n";
00384 }
00385 else
00386 {
00387 $userline .= "<Active>false</Active>\n";
00388 }
00389 }
00390 if (array_search("client_ip", $settings) !== FALSE)
00391 {
00392 if (strlen($row["client_ip"])) $userline .= "<ClientIP>".$row["client_ip"]."</ClientIP>\n";
00393 }
00394 if (array_search("time_limit_owner", $settings) !== FALSE)
00395 {
00396 if (strlen($row["time_limit_owner"])) $userline .= "<TimeLimitOwner>".$row["time_limit_owner"]."</TimeLimitOwner>\n";
00397 }
00398 if (array_search("time_limit_unlimited", $settings) !== FALSE)
00399 {
00400 if (strlen($row["time_limit_unlimited"])) $userline .= "<TimeLimitUnlimited>".$row["time_limit_unlimited"]."</TimeLimitUnlimited>\n";
00401 }
00402 if (array_search("time_limit_from", $settings) !== FALSE)
00403 {
00404 if (strlen($row["time_limit_from"])) $userline .= "<TimeLimitFrom>".$row["time_limit_from"]."</TimeLimitFrom>\n";
00405 }
00406 if (array_search("time_limit_until", $settings) !== FALSE)
00407 {
00408 if (strlen($row["time_limit_until"])) $userline .= "<TimeLimitUntil>".$row["time_limit_until"]."</TimeLimitUntil>\n";
00409 }
00410 if (array_search("time_limit_message", $settings) !== FALSE)
00411 {
00412 if (strlen($row["time_limit_message"])) $userline .= "<TimeLimitMessage>".$row["time_limit_message"]."</TimeLimitMessage>\n";
00413 }
00414 if (array_search("approve_date", $settings) !== FALSE)
00415 {
00416 if (strlen($row["approve_date"])) $userline .= "<ApproveDate>".$row["approve_date"]."</ApproveDate>\n";
00417 }
00418 if (array_search("agree_date", $settings) !== FALSE)
00419 {
00420 if (strlen($row["agree_date"])) $userline .= "<AgreeDate>".$row["agree_date"]."</AgreeDate>\n";
00421 }
00422 if (array_search("ilinc_id", $settings) !== FALSE)
00423 {
00424 if (strlen($row["ilinc_id"])) $userline .= "<iLincID>".$row["ilinc_id"]."</iLincID>\n";
00425 }
00426 if (array_search("ilinc_user", $settings) !== FALSE)
00427 {
00428 if (strlen($row["ilinc_user"])) $userline .= "<iLincUser>".$row["ilinc_user"]."</iLincUser>\n";
00429 }
00430 if (array_search("ilinc_passwd", $settings) !== FALSE)
00431 {
00432 if (strlen($row["ilinc_passwd"])) $userline .= "<iLincPasswd>".$row["ilinc_passwd"]."</iLincPasswd>\n";
00433 }
00434 if (array_search("auth_mode", $settings) !== FALSE)
00435 {
00436 if (strlen($row["auth_mode"])) $userline .= "<AuthMode type=\"".$row["auth_mode"]."\"></AuthMode>\n";
00437 }
00438 $userline .= "</User>\n";
00439 fwrite($file, $userline);
00440 }
00441 fwrite($file, "</Users>\n");
00442 fclose($file);
00443 }
00444
00445 function createCSVExport(&$settings, &$data, $filename)
00446 {
00447 $headerrow = array();
00448 foreach ($settings as $value)
00449 {
00450 array_push($headerrow, $this->lng->txt($value));
00451 }
00452 $separator = ";";
00453 $file = fopen($filename, "w");
00454 $formattedrow =& ilUtil::processCSVRow($headerrow, TRUE, $separator);
00455 fwrite($file, join ($separator, $formattedrow) ."\n");
00456 foreach ($data as $row)
00457 {
00458 $csvrow = array();
00459 foreach ($settings as $header)
00460 {
00461 array_push($csvrow, $row[$header]);
00462 }
00463 $formattedrow =& ilUtil::processCSVRow($csvrow, TRUE, $separator);
00464 fwrite($file, join ($separator, $formattedrow) ."\n");
00465 }
00466 fclose($file);
00467 }
00468
00469 function createExcelExport(&$settings, &$data, $filename, $a_mode)
00470 {
00471 $result = @include_once 'Spreadsheet/Excel/Writer.php';
00472 if (!$result)
00473 {
00474 include_once './classes/Spreadsheet/Excel/Writer.php';
00475 }
00476 include_once ("./classes/class.ilExcelUtils.php");
00477
00478 $workbook = new Spreadsheet_Excel_Writer($filename);
00479
00480
00481
00482
00483
00484 $format_bold =& $workbook->addFormat();
00485 $format_bold->setBold();
00486 $format_percent =& $workbook->addFormat();
00487 $format_percent->setNumFormat("0.00%");
00488 $format_datetime =& $workbook->addFormat();
00489 $format_datetime->setNumFormat("DD/MM/YYYY hh:mm:ss");
00490 $format_title =& $workbook->addFormat();
00491 $format_title->setBold();
00492 $format_title->setColor('black');
00493 $format_title->setPattern(1);
00494 $format_title->setFgColor('silver');
00495 $worksheet =& $workbook->addWorksheet();
00496 $row = 0;
00497 $col = 0;
00498
00499 foreach ($settings as $value)
00500 {
00501 $worksheet->write($row, $col, ilExcelUtils::_convert_text($this->lng->txt($value), $a_mode), $format_title);
00502 $col++;
00503 }
00504
00505
00506 foreach ($data as $index => $rowdata)
00507 {
00508 $row++;
00509 $col = 0;
00510 foreach ($settings as $fieldname)
00511 {
00512
00513
00514 $value = $rowdata[$fieldname];
00515 switch ($fieldname)
00516 {
00517 case "language":
00518 $worksheet->write($row, $col, ilExcelUtils::_convert_text($this->lng->txt("lang_".$value), $a_mode));
00519 break;
00520 case "time_limit_from":
00521 case "time_limit_until":
00522 $date = strftime("%Y-%m-%d %H:%M:%S", $value);
00523 if (preg_match("/(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})/", $date, $matches))
00524 {
00525 $worksheet->write($row, $col, ilUtil::excelTime($matches[1],$matches[2],$matches[3],$matches[4],$matches[5],$matches[6]), $format_datetime);
00526 }
00527 break;
00528 case "last_login":
00529 case "last_update":
00530 case "create_date":
00531 case "approve_date":
00532 case "agree_date":
00533 if (preg_match("/(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})/", $value, $matches))
00534 {
00535 $worksheet->write($row, $col, ilUtil::excelTime($matches[1],$matches[2],$matches[3],$matches[4],$matches[5],$matches[6]), $format_datetime);
00536 }
00537 break;
00538 default:
00539 $worksheet->write($row, $col, ilExcelUtils::_convert_text($value, $a_mode));
00540 break;
00541 }
00542 $col++;
00543 }
00544 }
00545 $workbook->close();
00546 }
00547
00548 function getExportSettings()
00549 {
00550 global $ilDB;
00551
00552 $db_settings = array();
00553 $profile_fields =& $this->getProfileFields();
00554 $query = "SELECT * FROM `settings` WHERE keyword LIKE '%usr_settings_export_%' AND value = '1'";
00555 $result = $ilDB->query($query);
00556 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
00557 {
00558 if (preg_match("/usr_settings_export_(.*)/", $row["keyword"], $setting))
00559 {
00560 array_push($db_settings, $setting[1]);
00561 }
00562 }
00563 $export_settings = array();
00564 foreach ($profile_fields as $key => $value)
00565 {
00566 if (in_array($value, $db_settings))
00567 {
00568 if (strcmp($value, "password") == 0)
00569 {
00570 array_push($export_settings, "passwd");
00571 }
00572 else
00573 {
00574 array_push($export_settings, $value);
00575 }
00576 }
00577 }
00578 array_push($export_settings, "login");
00579 array_push($export_settings, "last_login");
00580 array_push($export_settings, "last_update");
00581 array_push($export_settings, "create_date");
00582 array_push($export_settings, "i2passwd");
00583 array_push($export_settings, "time_limit_owner");
00584 array_push($export_settings, "time_limit_unlimited");
00585 array_push($export_settings, "time_limit_from");
00586 array_push($export_settings, "time_limit_until");
00587 array_push($export_settings, "time_limit_message");
00588 array_push($export_settings, "active");
00589 array_push($export_settings, "approve_date");
00590 array_push($export_settings, "agree_date");
00591 array_push($export_settings, "ilinc_id");
00592 array_push($export_settings, "ilinc_user");
00593 array_push($export_settings, "ilinc_passwd");
00594 array_push($export_settings, "client_ip");
00595 array_push($export_settings, "auth_mode");
00596 return $export_settings;
00597 }
00598
00602 function buildExportFile($a_mode = "userfolder_export_excel_x86")
00603 {
00604 global $ilBench;
00605 global $log;
00606 global $ilDB;
00607 global $ilias;
00608
00609
00610 $expDir = $this->getExportDirectory();
00611
00612
00613
00614
00615
00616
00617 $this->createExportDirectory();
00618
00619
00620
00621 $settings =& $this->getExportSettings();
00622 $data = array();
00623 $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";
00624 $result = $ilDB->query($query);
00625 while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
00626 {
00627
00628 array_push($data, $row);
00629
00630 }
00631
00632
00633 $fullname = $expDir."/".$this->getExportFilename($a_mode);
00634 switch ($a_mode)
00635 {
00636 case "userfolder_export_excel_x86":
00637 $this->createExcelExport($settings, $data, $fullname, "latin1");
00638 break;
00639 case "userfolder_export_csv":
00640 $this->createCSVExport($settings, $data, $fullname);
00641 break;
00642 case "userfolder_export_xml":
00643 $this->createXMLExport($settings, $data, $fullname);
00644 break;
00645 }
00646
00647
00648 return $fullname;
00649 }
00650
00651
00657 function createExportDirectory()
00658 {
00659 if (!@is_dir($this->getExportDirectory()))
00660 {
00661 $usrf_data_dir = ilUtil::getDataDir()."/usrf_data";
00662 ilUtil::makeDir($usrf_data_dir);
00663 if(!is_writable($usrf_data_dir))
00664 {
00665 $this->ilias->raiseError("Userfolder data directory (".$usrf_data_dir
00666 .") not writeable.",$this->ilias->error_obj->MESSAGE);
00667 }
00668
00669
00670 $export_dir = $usrf_data_dir."/export";
00671 ilUtil::makeDir($export_dir);
00672 if(!@is_dir($export_dir))
00673 {
00674 $this->ilias->raiseError("Creation of Userfolder Export Directory failed.",$this->ilias->error_obj->MESSAGE);
00675 }
00676 }
00677 }
00678
00679 function &getProfileFields()
00680 {
00681 $profile_fields = array(
00682 "gender",
00683 "firstname",
00684 "lastname",
00685 "title",
00686 "upload",
00687 "password",
00688 "institution",
00689 "department",
00690 "street",
00691 "zipcode",
00692 "city",
00693 "country",
00694 "phone_office",
00695 "phone_home",
00696 "phone_mobile",
00697 "fax",
00698 "email",
00699 "hobby",
00700 "referral_comment",
00701 "matriculation",
00702 "language",
00703 "skin_style",
00704 "hits_per_page",
00705 "show_users_online"
00706 );
00707 return $profile_fields;
00708 }
00709
00710 }
00711 ?>