ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjUserFolder.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 
14 require_once "./classes/class.ilObject.php";
15 
16 define('USER_FOLDER_ID',7);
17 
19 {
26  function ilObjUserFolder($a_id,$a_call_by_reference = true)
27  {
28  $this->type = "usrf";
29  $this->ilObject($a_id,$a_call_by_reference);
30  }
31 
32 
39  function delete()
40  {
41  // DISABLED
42  return false;
43 
44  // always call parent delete function first!!
45  if (!parent::delete())
46  {
47  return false;
48  }
49  // put here userfolder specific stuff
50 
51  // always call parent delete function at the end!!
52  return true;
53  }
54 
55 
56  function getExportFilename($a_mode = "userfolder_export_excel_x86")
57  {
58  $filename = "";
59  //$settings = $this->ilias->getAllSettings();
60  //$this->inst_id = $settings["inst_id"];
61  $inst_id = IL_INST_ID;
62 
63  $date = time();
64 
65  switch($a_mode)
66  {
67  case "userfolder_export_excel_x86":
68  $filename = $date."__".$inst_id."__xls_usrf.xls";
69  break;
70  case "userfolder_export_csv":
71  $filename = $date."__".$inst_id."__csv_usrf.csv";
72  break;
73  case "userfolder_export_xml":
74  $filename = $date."__".$inst_id."__xml_usrf.xml";
75  break;
76  }
77  return $filename;
78  }
79 
80 
88  function getExportDirectory()
89  {
90  $export_dir = ilUtil::getDataDir()."/usrf_data/export";
91 
92  return $export_dir;
93  }
94 
103  function getExportFiles()
104  {
105  $dir = $this->getExportDirectory();
106 
107  // quit if export dir not available
108  if (!@is_dir($dir) or
109  !is_writeable($dir))
110  {
111  return array();
112  }
113 
114  // open directory
115  $dir = dir($dir);
116 
117  // initialize array
118  $file = array();
119 
120  // get files and save the in the array
121  while ($entry = $dir->read())
122  {
123  if ($entry != "." and
124  $entry != ".." and
125  preg_match("/^[0-9]{10}_{2}[0-9]+_{2}([a-z0-9]{3})_usrf\.[a-z]{1,3}\$/", $entry, $matches))
126  {
127  $filearray["filename"] = $entry;
128  $filearray["filesize"] = filesize($this->getExportDirectory()."/".$entry);
129  array_push($file, $filearray);
130  }
131  }
132 
133  // close import directory
134  $dir->close();
135 
136  // sort files
137  sort ($file);
138  reset ($file);
139 
140  return $file;
141  }
142 
143  function escapeXML($value)
144  {
145  $value = str_replace("&", "&amp;", $value);
146  $value = str_replace("<", "&lt;", $value);
147  $value = str_replace(">", "&gt;", $value);
148  return $value;
149  }
150 
151  function createXMLExport(&$settings, &$data, $filename)
152  {
153  include_once './Services/User/classes/class.ilUserDefinedData.php';
154  include_once './Services/User/classes/class.ilObjUser.php';
155 
156  global $rbacreview;
157  global $ilDB;
158  global $log;
159 
160  $file = fopen($filename, "w");
161 
162  if (is_array($data))
163  {
164  include_once './Services/User/classes/class.ilUserXMLWriter.php';
165 
166  $xmlWriter = new ilUserXMLWriter();
167  $xmlWriter->setObjects($data);
168  $xmlWriter->setSettings($settings);
169  $xmlWriter->setAttachRoles (true);
170 
171  if($xmlWriter->start())
172  {
173  fwrite($file, $xmlWriter->getXML());
174  }
175  }
176 
177 /*
178  fwrite($file, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
179  fwrite($file, "<!DOCTYPE Users SYSTEM \"".ILIAS_HTTP_PATH."/xml/ilias_user_3_8.dtd\">\n");
180  fwrite($file, "<Users>");
181  foreach ($data as $row)
182  {
183  //$log->write(date("[y-m-d H:i:s] ")."User data export: processing user " . $row["login"]);
184  foreach ($row as $key => $value)
185  {
186  $row[$key] = $this->escapeXML($value);
187  }
188  $userline = "";
189  // TODO: Define combobox for "Action" ???
190  if (strlen($row["language"]) == 0) $row["language"] = "en";
191  $userline .= "<User Id=\"il_".IL_INST_ID."_usr_".$row["usr_id"]."\" Language=\"".$row["language"]."\" Action=\"Insert\">";
192  if (array_search("login", $settings) !== FALSE)
193  {
194  $userline .= "<Login>".$row["login"]."</Login>";
195  }
196  // Alternative way to get the roles of a user?
197  $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",
198  $ilDB->quote($row["usr_id"])
199  );
200  $rbacresult = $ilDB->query($query);
201  while ($rbacrow = $rbacresult->fetchRow(DB_FETCHMODE_ASSOC))
202  {
203  $type = "";
204  if ($rbacrow["assign"] == "y")
205  {
206  if ($rbacrow["parent"] == ROLE_FOLDER_ID)
207  {
208  $type = "Global";
209  }
210  else
211  {
212  $type = "Local";
213  }
214  if (strlen($type))
215  {
216  $userline .= "<Role Id=\"il_".IL_INST_ID."_role_".$rbacrow["rol_id"]."\" Type=\"".$type."\">".$rbacrow["title"]."</Role>";
217  }
218  }
219  }
220  //$log->write(date("[y-m-d H:i:s] ")."User data export: get all roles");
221  /* the export of roles is to expensive. on a system with 6000 users the following
222  section needs 37 seconds
223 
224  $roles = $rbacreview->getRolesByFilter(1, $row["usr_id"]);
225  $ass_roles = $rbacreview->assignedRoles($row["usr_id"]);
226  foreach ($roles as $role)
227  {
228  if (array_search($role["obj_id"], $ass_roles) !== FALSE)
229  {
230  $type = "";
231  switch ($role["role_type"])
232  {
233  case "global":
234  $type = "Global";
235  break;
236  case "local":
237  $type = "Local";
238  break;
239  }
240  if (strlen($type))
241  {
242  $userline .= "<Role Id=\"".$role["obj_id"]."\" Type=\"".$type."\">".$role["title"]."</Role>";
243  }
244  }
245  }
246  */
247 /* //$log->write(date("[y-m-d H:i:s] ")."User data export: got all roles");
248  $i2passwd = FALSE;
249  if (array_search("i2passwd", $settings) !== FALSE)
250  {
251  if (strlen($row["i2passwd"])) $i2passwd = TRUE;
252  if ($i2passwd) $userline .= "<Password Type=\"ILIAS2\">".$row["i2passwd"]."</Password>";
253  }
254  if ((!$i2passwd) && (array_search("passwd", $settings) !== FALSE))
255  {
256  if (strlen($row["passwd"])) $userline .= "<Password Type=\"ILIAS3\">".$row["passwd"]."</Password>";
257  }
258  if (array_search("firstname", $settings) !== FALSE)
259  {
260  if (strlen($row["firstname"])) $userline .= "<Firstname>".$row["firstname"]."</Firstname>";
261  }
262  if (array_search("lastname", $settings) !== FALSE)
263  {
264  if (strlen($row["lastname"])) $userline .= "<Lastname>".$row["lastname"]."</Lastname>";
265  }
266  if (array_search("title", $settings) !== FALSE)
267  {
268  if (strlen($row["title"])) $userline .= "<Title>".$row["title"]."</Title>";
269  }
270  if (array_search("upload", $settings) !== FALSE)
271  {
272  // personal picture
273  $q = sprintf("SELECT value FROM usr_pref WHERE usr_id=%s AND keyword='profile_image'", $ilDB->quote($row["usr_id"] . ""));
274  $r = $ilDB->query($q);
275  if ($r->numRows() == 1)
276  {
277  $personal_picture_data = $r->fetchRow(DB_FETCHMODE_ASSOC);
278  $personal_picture = $personal_picture_data["value"];
279  $webspace_dir = ilUtil::getWebspaceDir();
280  $image_file = $webspace_dir."/usr_images/".$personal_picture;
281  if (@is_file($image_file))
282  {
283  $fh = fopen($image_file, "rb");
284  if ($fh)
285  {
286  $image_data = fread($fh, filesize($image_file));
287  fclose($fh);
288  $base64 = base64_encode($image_data);
289  $imagetype = "image/jpeg";
290  if (preg_match("/.*\.(png|gif)$/", $personal_picture, $matches))
291  {
292  $imagetype = "image/".$matches[1];
293  }
294  $userline .= "<PersonalPicture imagetype=\"$imagetype\" encoding=\"Base64\">$base64</PersonalPicture>";
295  }
296  }
297  }
298  }
299  if (array_search("gender", $settings) !== FALSE)
300  {
301  if (strlen($row["gender"])) $userline .= "<Gender>".$row["gender"]."</Gender>";
302  }
303  if (array_search("email", $settings) !== FALSE)
304  {
305  if (strlen($row["email"])) $userline .= "<Email>".$row["email"]."</Email>";
306  }
307  if (array_search("institution", $settings) !== FALSE)
308  {
309  if (strlen($row["institution"])) $userline .= "<Institution>".$row["institution"]."</Institution>";
310  }
311  if (array_search("street", $settings) !== FALSE)
312  {
313  if (strlen($row["street"])) $userline .= "<Street>".$row["street"]."</Street>";
314  }
315  if (array_search("city", $settings) !== FALSE)
316  {
317  if (strlen($row["city"])) $userline .= "<City>".$row["city"]."</City>";
318  }
319  if (array_search("zipcode", $settings) !== FALSE)
320  {
321  if (strlen($row["zipcode"])) $userline .= "<PostalCode>".$row["zipcode"]."</PostalCode>";
322  }
323  if (array_search("country", $settings) !== FALSE)
324  {
325  if (strlen($row["country"])) $userline .= "<Country>".$row["country"]."</Country>";
326  }
327  if (array_search("phone_office", $settings) !== FALSE)
328  {
329  if (strlen($row["phone_office"])) $userline .= "<PhoneOffice>".$row["phone_office"]."</PhoneOffice>";
330  }
331  if (array_search("phone_home", $settings) !== FALSE)
332  {
333  if (strlen($row["phone_home"])) $userline .= "<PhoneHome>".$row["phone_home"]."</PhoneHome>";
334  }
335  if (array_search("phone_mobile", $settings) !== FALSE)
336  {
337  if (strlen($row["phone_mobile"])) $userline .= "<PhoneMobile>".$row["phone_mobile"]."</PhoneMobile>";
338  }
339  if (array_search("fax", $settings) !== FALSE)
340  {
341  if (strlen($row["fax"])) $userline .= "<Fax>".$row["fax"]."</Fax>";
342  }
343  if (strlen($row["hobby"])) if (array_search("hobby", $settings) !== FALSE)
344  {
345  $userline .= "<Hobby>".$row["hobby"]."</Hobby>";
346  }
347  if (array_search("department", $settings) !== FALSE)
348  {
349  if (strlen($row["department"])) $userline .= "<Department>".$row["department"]."</Department>";
350  }
351  if (array_search("referral_comment", $settings) !== FALSE)
352  {
353  if (strlen($row["referral_comment"])) $userline .= "<Comment>".$row["referral_comment"]."</Comment>";
354  }
355  if (array_search("matriculation", $settings) !== FALSE)
356  {
357  if (strlen($row["matriculation"])) $userline .= "<Matriculation>".$row["matriculation"]."</Matriculation>";
358  }
359  if (array_search("active", $settings) !== FALSE)
360  {
361  if ($row["active"])
362  {
363  $userline .= "<Active>true</Active>";
364  }
365  else
366  {
367  $userline .= "<Active>false</Active>";
368  }
369  }
370  if (array_search("client_ip", $settings) !== FALSE)
371  {
372  if (strlen($row["client_ip"])) $userline .= "<ClientIP>".$row["client_ip"]."</ClientIP>";
373  }
374  if (array_search("time_limit_owner", $settings) !== FALSE)
375  {
376  if (strlen($row["time_limit_owner"])) $userline .= "<TimeLimitOwner>".$row["time_limit_owner"]."</TimeLimitOwner>";
377  }
378  if (array_search("time_limit_unlimited", $settings) !== FALSE)
379  {
380  if (strlen($row["time_limit_unlimited"])) $userline .= "<TimeLimitUnlimited>".$row["time_limit_unlimited"]."</TimeLimitUnlimited>";
381  }
382  if (array_search("time_limit_from", $settings) !== FALSE)
383  {
384  if (strlen($row["time_limit_from"])) $userline .= "<TimeLimitFrom>".$row["time_limit_from"]."</TimeLimitFrom>";
385  }
386  if (array_search("time_limit_until", $settings) !== FALSE)
387  {
388  if (strlen($row["time_limit_until"])) $userline .= "<TimeLimitUntil>".$row["time_limit_until"]."</TimeLimitUntil>";
389  }
390  if (array_search("time_limit_message", $settings) !== FALSE)
391  {
392  if (strlen($row["time_limit_message"])) $userline .= "<TimeLimitMessage>".$row["time_limit_message"]."</TimeLimitMessage>";
393  }
394  if (array_search("approve_date", $settings) !== FALSE)
395  {
396  if (strlen($row["approve_date"])) $userline .= "<ApproveDate>".$row["approve_date"]."</ApproveDate>";
397  }
398  if (array_search("agree_date", $settings) !== FALSE)
399  {
400  if (strlen($row["agree_date"])) $userline .= "<AgreeDate>".$row["agree_date"]."</AgreeDate>";
401  }
402  if ((int) $row["ilinc_id"] !=0) {
403  if (array_search("ilinc_id", $settings) !== FALSE)
404  {
405  if (strlen($row["ilinc_id"])) $userline .= "<iLincID>".$row["ilinc_id"]."</iLincID>";
406  }
407  if (array_search("ilinc_login", $settings) !== FALSE)
408  {
409  if (strlen($row["ilinc_login"])) $userline .= "<iLincLogin>".$row["ilinc_login"]."</iLincLogin>";
410  }
411  if (array_search("ilinc_passwd", $settings) !== FALSE)
412  {
413  if (strlen($row["ilinc_passwd"])) $userline .= "<iLincPasswd>".$row["ilinc_passwd"]."</iLincPasswd>";
414  }
415  }
416  if (array_search("auth_mode", $settings) !== FALSE)
417  {
418  if (strlen($row["auth_mode"])) $userline .= "<AuthMode type=\"".$row["auth_mode"]."\"></AuthMode>";
419  }
420  if (array_search("skin_style", $settings) !== FALSE)
421  {
422  $userline .=
423  "<Look Skin=\"" . ilObjUser::_lookupPref($row["usr_id"], "skin") . "\" " .
424  "Style=\"" . ilObjUser::_lookupPref($row["usr_id"], "style") . "\"></Look>";
425  }
426 
427  if (array_search("last_update", $settings) !== FALSE)
428  {
429  if (strlen($row["last_update"])) $userline .= "<LastUpdate>".$row["last_update"]."</LastUpdate>";
430  }
431 
432  if (array_search("last_login", $settings) !== FALSE)
433  {
434  if (strlen($row["last_login"])) $userline .= "<LastLogin>".$row["last_login"]."</LastLogin>";
435  }
436 
437  // Append User defined field data
438  $udf_data = new ilUserDefinedData($row['usr_id']);
439  $userline .= $udf_data->toXML();
440 
441  $userline .= "</User>";
442  fwrite($file, $userline);
443  }
444  fwrite($file, "</Users>");
445  fclose($file);*/
446  }
447 
448 
453  {
454  include_once './Services/User/classes/class.ilUserDefinedFields.php';
455  $udf_obj =& ilUserDefinedFields::_getInstance();
456 
457  $udf_ex_fields = array();
458  foreach($udf_obj->getDefinitions() as $definition)
459  {
460  if ($definition["export"] != FALSE)
461  {
462  $udf_ex_fields[] = array("name" => $definition["field_name"],
463  "id" => $definition["field_id"]);
464  }
465  }
466 
467  return $udf_ex_fields;
468  }
469 
470  function createCSVExport(&$settings, &$data, $filename)
471  {
472 
473  // header
474  $headerrow = array();
475  $udf_ex_fields = $this->getUserDefinedExportFields();
476  foreach ($settings as $value) // standard fields
477  {
478  array_push($headerrow, $this->lng->txt($value));
479  }
480  foreach ($udf_ex_fields as $f) // custom fields
481  {
482  array_push($headerrow, $f["name"]);
483  }
484 
485  $separator = ";";
486  $file = fopen($filename, "w");
487  $formattedrow =& ilUtil::processCSVRow($headerrow, TRUE, $separator);
488  fwrite($file, join ($separator, $formattedrow) ."\n");
489  foreach ($data as $row)
490  {
491  $csvrow = array();
492  foreach ($settings as $header) // standard fields
493  {
494  array_push($csvrow, $row[$header]);
495  }
496 
497  // custom fields
498  reset($udf_ex_fields);
499  if (count($udf_ex_fields) > 0)
500  {
501  include_once("./Services/User/classes/class.ilUserDefinedData.php");
502  $udf = new ilUserDefinedData($row["usr_id"]);
503  foreach ($udf_ex_fields as $f) // custom fields
504  {
505  array_push($csvrow, $udf->get("f_".$f["id"]));
506  }
507  }
508 
509  $formattedrow =& ilUtil::processCSVRow($csvrow, TRUE, $separator);
510  fwrite($file, join ($separator, $formattedrow) ."\n");
511  }
512  fclose($file);
513  }
514 
515  function createExcelExport(&$settings, &$data, $filename, $a_mode)
516  {
517  include_once "./Services/Excel/classes/class.ilExcelUtils.php";
518  include_once "./Services/Excel/classes/class.ilExcelWriterAdapter.php";
519  $adapter = new ilExcelWriterAdapter($filename, FALSE);
520  $workbook = $adapter->getWorkbook();
521  // Creating a worksheet
522  $format_bold =& $workbook->addFormat();
523  $format_bold->setBold();
524  $format_percent =& $workbook->addFormat();
525  $format_percent->setNumFormat("0.00%");
526  $format_datetime =& $workbook->addFormat();
527  $format_datetime->setNumFormat("DD/MM/YYYY hh:mm:ss");
528  $format_title =& $workbook->addFormat();
529  $format_title->setBold();
530  $format_title->setColor('black');
531  $format_title->setPattern(1);
532  $format_title->setFgColor('silver');
533  $worksheet =& $workbook->addWorksheet();
534  $row = 0;
535  $col = 0;
536 
537  $udf_ex_fields = $this->getUserDefinedExportFields();
538 
539  // title row
540  foreach ($settings as $value) // standard fields
541  {
542  $worksheet->write($row, $col, ilExcelUtils::_convert_text($this->lng->txt($value), $a_mode), $format_title);
543  $col++;
544  }
545  foreach ($udf_ex_fields as $f) // custom fields
546  {
547  $worksheet->write($row, $col, ilExcelUtils::_convert_text($f["name"], $a_mode), $format_title);
548  $col++;
549  }
550 
551  foreach ($data as $index => $rowdata)
552  {
553  $row++;
554  $col = 0;
555 
556  // standard fields
557  foreach ($settings as $fieldname)
558  {
559  $value = $rowdata[$fieldname];
560  switch ($fieldname)
561  {
562  case "language":
563  $worksheet->write($row, $col, ilExcelUtils::_convert_text($this->lng->txt("lang_".$value), $a_mode));
564  break;
565  case "time_limit_from":
566  case "time_limit_until":
567  $date = strftime("%Y-%m-%d %H:%M:%S", $value);
568  if (preg_match("/(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})/", $date, $matches))
569  {
570  $worksheet->write($row, $col, ilUtil::excelTime($matches[1],$matches[2],$matches[3],$matches[4],$matches[5],$matches[6]), $format_datetime);
571  }
572  break;
573  case "last_login":
574  case "last_update":
575  case "create_date":
576  case "approve_date":
577  case "agree_date":
578  if (preg_match("/(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})/", $value, $matches))
579  {
580  $worksheet->write($row, $col, ilUtil::excelTime($matches[1],$matches[2],$matches[3],$matches[4],$matches[5],$matches[6]), $format_datetime);
581  }
582  break;
583  default:
584  $worksheet->write($row, $col, ilExcelUtils::_convert_text($value, $a_mode));
585  break;
586  }
587  $col++;
588  }
589 
590  // custom fields
591  reset($udf_ex_fields);
592  if (count($udf_ex_fields) > 0)
593  {
594  include_once("./Services/User/classes/class.ilUserDefinedData.php");
595  $udf = new ilUserDefinedData($rowdata["usr_id"]);
596  foreach ($udf_ex_fields as $f) // custom fields
597  {
598  $worksheet->write($row, $col, ilExcelUtils::_convert_text($udf->get("f_".$f["id"]), $a_mode));
599  $col++;
600  }
601  }
602  }
603  $workbook->close();
604  }
605 
611  static function getExportSettings()
612  {
613  global $ilDB;
614 
615  $db_settings = array();
616 
617  include_once("./Services/User/classes/class.ilUserProfile.php");
618  $up = new ilUserProfile();
619  $up->skipField("roles");
620  $profile_fields = $up->getStandardFields();
621 
622  /*$profile_fields =& ilObjUserFolder::getProfileFields();
623  $profile_fields[] = "preferences";*/
624 
625  $query = "SELECT * FROM settings WHERE ".
626  $ilDB->like("keyword", "text", '%usr_settings_export_%');
627  $result = $ilDB->query($query);
628  while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
629  {
630  if ($row["value"] == "1")
631  {
632  if (preg_match("/usr_settings_export_(.*)/", $row["keyword"], $setting))
633  {
634  array_push($db_settings, $setting[1]);
635  }
636  }
637  }
638  $export_settings = array();
639  foreach ($profile_fields as $key => $value)
640  {
641  if (in_array($key, $db_settings))
642  {
643  if (strcmp($key, "password") == 0)
644  {
645  array_push($export_settings, "passwd");
646  }
647  else
648  {
649  array_push($export_settings, $key);
650  }
651  }
652  }
653  array_push($export_settings, "login");
654  array_push($export_settings, "last_login");
655  array_push($export_settings, "last_update");
656  array_push($export_settings, "create_date");
657  array_push($export_settings, "i2passwd");
658  array_push($export_settings, "time_limit_owner");
659  array_push($export_settings, "time_limit_unlimited");
660  array_push($export_settings, "time_limit_from");
661  array_push($export_settings, "time_limit_until");
662  array_push($export_settings, "time_limit_message");
663  array_push($export_settings, "active");
664  array_push($export_settings, "approve_date");
665  array_push($export_settings, "agree_date");
666  array_push($export_settings, "ilinc_id");
667  array_push($export_settings, "ilinc_login");
668  array_push($export_settings, "ilinc_passwd");
669  array_push($export_settings, "client_ip");
670  array_push($export_settings, "auth_mode");
671  array_push($export_settings, "ext_account");
672  array_push($export_settings, "feedhash");
673 
674  return $export_settings;
675  }
676 
680  function buildExportFile($a_mode = "userfolder_export_excel_x86", $user_data_filter = FALSE)
681  {
682  global $ilBench;
683  global $log;
684  global $ilDB;
685  global $ilias;
686  global $lng;
687 
688  //get Log File
689  $expDir = $this->getExportDirectory();
690  //$expLog = &$log;
691  //$expLog->delete();
692  //$expLog->setLogFormat("");
693  //$expLog->write(date("[y-m-d H:i:s] ")."Start export of user data");
694 
695  // create export directory if needed
696  $this->createExportDirectory();
697 
698  //get data
699  //$expLog->write(date("[y-m-d H:i:s] ")."User data export: build an array of all user data entries");
700  $settings =& $this->getExportSettings();
701 
702  // user languages
703  $query = "SELECT * FROM usr_pref WHERE keyword = ".$ilDB->quote('language','text');
704  $res = $ilDB->query($query);
705  $languages = array();
706  while($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
707  {
708  $languages[$row['usr_id']] = $row['value'];
709  }
710 
711 
712  $data = array();
713  $query = "SELECT usr_data.* FROM usr_data ".
714  " ORDER BY usr_data.lastname, usr_data.firstname";
715  $result = $ilDB->query($query);
716  while ($row = $ilDB->fetchAssoc($result))
717  {
718  if(isset($languages[$row['usr_id']]))
719  {
720  $row['language'] = $languages[$row['usr_id']];
721  }
722  else
723  {
724  $row['language'] = $lng->getDefaultLanguage();
725  }
726 
727  if (is_array($user_data_filter))
728  {
729  if (in_array($row["usr_id"], $user_data_filter)) array_push($data, $row);
730  }
731  else
732  {
733  array_push($data, $row);
734  }
735  }
736  //$expLog->write(date("[y-m-d H:i:s] ")."User data export: build an array of all user data entries");
737 
738  $fullname = $expDir."/".$this->getExportFilename($a_mode);
739  switch ($a_mode)
740  {
741  case "userfolder_export_excel_x86":
742  $this->createExcelExport($settings, $data, $fullname, "latin1");
743  break;
744  case "userfolder_export_csv":
745  $this->createCSVExport($settings, $data, $fullname);
746  break;
747  case "userfolder_export_xml":
748  $this->createXMLExport($settings, $data, $fullname);
749  break;
750  }
751  //$expLog->write(date("[y-m-d H:i:s] ")."Finished export of user data");
752 
753  return $fullname;
754  }
755 
756 
763  {
764  if (!@is_dir($this->getExportDirectory()))
765  {
766  $usrf_data_dir = ilUtil::getDataDir()."/usrf_data";
767  ilUtil::makeDir($usrf_data_dir);
768  if(!is_writable($usrf_data_dir))
769  {
770  $this->ilias->raiseError("Userfolder data directory (".$usrf_data_dir
771  .") not writeable.",$this->ilias->error_obj->MESSAGE);
772  }
773 
774  // create Export subdirectory (data_dir/lm_data/lm_<id>/Export)
775  $export_dir = $usrf_data_dir."/export";
776  ilUtil::makeDir($export_dir);
777  if(!@is_dir($export_dir))
778  {
779  $this->ilias->raiseError("Creation of Userfolder Export Directory failed.",$this->ilias->error_obj->MESSAGE);
780  }
781  }
782  }
783 
784 
790  static function &getProfileFields()
791  {
792  include_once("./Services/User/classes/class.ilUserProfile.php");
793  $up = new ilUserProfile();
794  $up->skipField("username");
795  $up->skipField("roles");
796  $up->skipGroup("preferences");
797  $fds = $up->getStandardFields();
798  foreach ($fds as $k => $f)
799  {
800  $profile_fields[] = $k;
801  }
802 
803  return $profile_fields;
804  }
805 
806  function _writeNewAccountMail($a_lang, $a_subject, $a_sal_g, $a_sal_f, $a_sal_m, $a_body)
807  {
808  global $ilDB;
809 
810  if(self::_lookupNewAccountMail($a_lang))
811  {
812  $values = array(
813  'subject' => array('text',$a_subject),
814  'body' => array('clob',$a_body),
815  'sal_g' => array('text',$a_sal_g),
816  'sal_f' => array('text',$a_sal_f),
817  'sal_m' => array('text',$a_sal_m)
818  );
819  $ilDB->update('mail_template',
820  $values,
821  array('lang' => array('text',$a_lang), 'type' => array('text','nacc'))
822  );
823  }
824  else
825  {
826  $values = array(
827  'subject' => array('text',$a_subject),
828  'body' => array('clob',$a_body),
829  'sal_g' => array('text',$a_sal_g),
830  'sal_f' => array('text',$a_sal_f),
831  'sal_m' => array('text',$a_sal_m),
832  'lang' => array('text',$a_lang),
833  'type' => array('text','nacc')
834  );
835  $ilDB->insert('mail_template',$values);
836  }
837  }
838 
839  function _lookupNewAccountMail($a_lang)
840  {
841  global $ilDB;
842 
843  $set = $ilDB->query("SELECT * FROM mail_template ".
844  " WHERE type='nacc' AND lang = ".$ilDB->quote($a_lang,'text'));
845 
846  if ($rec = $set->fetchRow(DB_FETCHMODE_ASSOC))
847  {
848  return $rec;
849  }
850  return array();
851  }
852 
864  public static function _updateUserFolderAssignment($a_old_id,$a_new_id)
865  {
866  global $ilDB;
867 
868  $query = "UPDATE usr_data SET time_limit_owner = ".$ilDB->quote($a_new_id, "integer")." ".
869  "WHERE time_limit_owner = ".$ilDB->quote($a_old_id, "integer")." ";
870  $ilDB->manipulate($query);
871 
872  return true;
873  }
874 
875 
876 } // END class.ilObjUserFolder
877 ?>