ILIAS  Release_4_4_x_branch Revision 61816
 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 "./Services/Object/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  if($value == 'ext_account')
543  {
544  $value = 'user_ext_account';
545  }
546  $worksheet->write($row, $col, ilExcelUtils::_convert_text($this->lng->txt($value), $a_mode), $format_title);
547  $col++;
548  }
549  foreach ($udf_ex_fields as $f) // custom fields
550  {
551  $worksheet->write($row, $col, ilExcelUtils::_convert_text($f["name"], $a_mode), $format_title);
552  $col++;
553  }
554 
555  $this->lng->loadLanguageModule("meta");
556  foreach ($data as $index => $rowdata)
557  {
558  $row++;
559  $col = 0;
560 
561  // standard fields
562  foreach ($settings as $fieldname)
563  {
564  $value = $rowdata[$fieldname];
565  switch ($fieldname)
566  {
567  case "language":
568  $worksheet->write($row, $col, ilExcelUtils::_convert_text($this->lng->txt("meta_l_".$value), $a_mode));
569  break;
570  case "time_limit_from":
571  case "time_limit_until":
572  $date = strftime("%Y-%m-%d %H:%M:%S", $value);
573  if (preg_match("/(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})/", $date, $matches))
574  {
575  $worksheet->write($row, $col, ilUtil::excelTime($matches[1],$matches[2],$matches[3],$matches[4],$matches[5],$matches[6]), $format_datetime);
576  }
577  break;
578  case "last_login":
579  case "last_update":
580  case "create_date":
581  case "approve_date":
582  case "agree_date":
583  if (preg_match("/(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})/", $value, $matches))
584  {
585  $worksheet->write($row, $col, ilUtil::excelTime($matches[1],$matches[2],$matches[3],$matches[4],$matches[5],$matches[6]), $format_datetime);
586  }
587  break;
588  default:
589  $worksheet->write($row, $col, ilExcelUtils::_convert_text($value, $a_mode));
590  break;
591  }
592  $col++;
593  }
594 
595  // custom fields
596  reset($udf_ex_fields);
597  if (count($udf_ex_fields) > 0)
598  {
599  include_once("./Services/User/classes/class.ilUserDefinedData.php");
600  $udf = new ilUserDefinedData($rowdata["usr_id"]);
601  foreach ($udf_ex_fields as $f) // custom fields
602  {
603  $worksheet->write($row, $col, ilExcelUtils::_convert_text($udf->get("f_".$f["id"]), $a_mode));
604  $col++;
605  }
606  }
607  }
608  $workbook->close();
609  }
610 
616  static function getExportSettings()
617  {
618  global $ilDB;
619 
620  $db_settings = array();
621 
622  include_once("./Services/User/classes/class.ilUserProfile.php");
623  $up = new ilUserProfile();
624  $up->skipField("roles");
625  $profile_fields = $up->getStandardFields();
626 
627  /*$profile_fields =& ilObjUserFolder::getProfileFields();
628  $profile_fields[] = "preferences";*/
629 
630  $query = "SELECT * FROM settings WHERE ".
631  $ilDB->like("keyword", "text", '%usr_settings_export_%');
632  $result = $ilDB->query($query);
633  while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
634  {
635  if ($row["value"] == "1")
636  {
637  if (preg_match("/usr_settings_export_(.*)/", $row["keyword"], $setting))
638  {
639  array_push($db_settings, $setting[1]);
640  }
641  }
642  }
643  $export_settings = array();
644  foreach ($profile_fields as $key => $value)
645  {
646  if (in_array($key, $db_settings))
647  {
648  if (strcmp($key, "password") == 0)
649  {
650  array_push($export_settings, "passwd");
651  }
652  else
653  {
654  array_push($export_settings, $key);
655  }
656  }
657  }
658  array_push($export_settings, "login");
659  array_push($export_settings, "last_login");
660  array_push($export_settings, "last_update");
661  array_push($export_settings, "create_date");
662  array_push($export_settings, "i2passwd");
663  array_push($export_settings, "time_limit_owner");
664  array_push($export_settings, "time_limit_unlimited");
665  array_push($export_settings, "time_limit_from");
666  array_push($export_settings, "time_limit_until");
667  array_push($export_settings, "time_limit_message");
668  array_push($export_settings, "active");
669  array_push($export_settings, "approve_date");
670  array_push($export_settings, "agree_date");
671  array_push($export_settings, "ilinc_id");
672  array_push($export_settings, "ilinc_login");
673  array_push($export_settings, "ilinc_passwd");
674  array_push($export_settings, "client_ip");
675  array_push($export_settings, "auth_mode");
676  array_push($export_settings, "ext_account");
677  array_push($export_settings, "feedhash");
678 
679  return $export_settings;
680  }
681 
685  function buildExportFile($a_mode = "userfolder_export_excel_x86", $user_data_filter = FALSE)
686  {
687  global $ilBench;
688  global $log;
689  global $ilDB;
690  global $ilias;
691  global $lng;
692 
693  //get Log File
694  $expDir = $this->getExportDirectory();
695  //$expLog = &$log;
696  //$expLog->delete();
697  //$expLog->setLogFormat("");
698  //$expLog->write(date("[y-m-d H:i:s] ")."Start export of user data");
699 
700  // create export directory if needed
701  $this->createExportDirectory();
702 
703  //get data
704  //$expLog->write(date("[y-m-d H:i:s] ")."User data export: build an array of all user data entries");
705  $settings =& $this->getExportSettings();
706 
707  // user languages
708  $query = "SELECT * FROM usr_pref WHERE keyword = ".$ilDB->quote('language','text');
709  $res = $ilDB->query($query);
710  $languages = array();
711  while($row = $res->fetchRow(DB_FETCHMODE_ASSOC))
712  {
713  $languages[$row['usr_id']] = $row['value'];
714  }
715 
716 
717  $data = array();
718  $query = "SELECT usr_data.* FROM usr_data ".
719  " ORDER BY usr_data.lastname, usr_data.firstname";
720  $result = $ilDB->query($query);
721  while ($row = $ilDB->fetchAssoc($result))
722  {
723  if(isset($languages[$row['usr_id']]))
724  {
725  $row['language'] = $languages[$row['usr_id']];
726  }
727  else
728  {
729  $row['language'] = $lng->getDefaultLanguage();
730  }
731 
732  if (is_array($user_data_filter))
733  {
734  if (in_array($row["usr_id"], $user_data_filter)) array_push($data, $row);
735  }
736  else
737  {
738  array_push($data, $row);
739  }
740  }
741  //$expLog->write(date("[y-m-d H:i:s] ")."User data export: build an array of all user data entries");
742 
743  $fullname = $expDir."/".$this->getExportFilename($a_mode);
744  switch ($a_mode)
745  {
746  case "userfolder_export_excel_x86":
747  $this->createExcelExport($settings, $data, $fullname, "latin1");
748  break;
749  case "userfolder_export_csv":
750  $this->createCSVExport($settings, $data, $fullname);
751  break;
752  case "userfolder_export_xml":
753  $this->createXMLExport($settings, $data, $fullname);
754  break;
755  }
756  //$expLog->write(date("[y-m-d H:i:s] ")."Finished export of user data");
757 
758  return $fullname;
759  }
760 
761 
768  {
769  if (!@is_dir($this->getExportDirectory()))
770  {
771  $usrf_data_dir = ilUtil::getDataDir()."/usrf_data";
772  ilUtil::makeDir($usrf_data_dir);
773  if(!is_writable($usrf_data_dir))
774  {
775  $this->ilias->raiseError("Userfolder data directory (".$usrf_data_dir
776  .") not writeable.",$this->ilias->error_obj->MESSAGE);
777  }
778 
779  // create Export subdirectory (data_dir/lm_data/lm_<id>/Export)
780  $export_dir = $usrf_data_dir."/export";
781  ilUtil::makeDir($export_dir);
782  if(!@is_dir($export_dir))
783  {
784  $this->ilias->raiseError("Creation of Userfolder Export Directory failed.",$this->ilias->error_obj->MESSAGE);
785  }
786  }
787  }
788 
789 
795  static function &getProfileFields()
796  {
797  include_once("./Services/User/classes/class.ilUserProfile.php");
798  $up = new ilUserProfile();
799  $up->skipField("username");
800  $up->skipField("roles");
801  $up->skipGroup("preferences");
802  $fds = $up->getStandardFields();
803  foreach ($fds as $k => $f)
804  {
805  $profile_fields[] = $k;
806  }
807 
808  return $profile_fields;
809  }
810 
811  function _writeNewAccountMail($a_lang, $a_subject, $a_sal_g, $a_sal_f, $a_sal_m, $a_body)
812  {
813  global $ilDB;
814 
815  if(self::_lookupNewAccountMail($a_lang))
816  {
817  $values = array(
818  'subject' => array('text',$a_subject),
819  'body' => array('clob',$a_body),
820  'sal_g' => array('text',$a_sal_g),
821  'sal_f' => array('text',$a_sal_f),
822  'sal_m' => array('text',$a_sal_m)
823  );
824  $ilDB->update('mail_template',
825  $values,
826  array('lang' => array('text',$a_lang), 'type' => array('text','nacc'))
827  );
828  }
829  else
830  {
831  $values = array(
832  'subject' => array('text',$a_subject),
833  'body' => array('clob',$a_body),
834  'sal_g' => array('text',$a_sal_g),
835  'sal_f' => array('text',$a_sal_f),
836  'sal_m' => array('text',$a_sal_m),
837  'lang' => array('text',$a_lang),
838  'type' => array('text','nacc')
839  );
840  $ilDB->insert('mail_template',$values);
841  }
842  }
843 
844  function _updateAccountMailAttachment($a_lang, $a_tmp_name, $a_name)
845  {
846  global $ilDB;
847 
848  include_once "Services/User/classes/class.ilFSStorageUserFolder.php";
849  $fs = new ilFSStorageUserFolder($this->getId());
850  $fs->create();
851  $path = $fs->getAbsolutePath()."/";
852 
853  move_uploaded_file($a_tmp_name, $path.$a_lang);
854 
855  $ilDB->update('mail_template',
856  array('att_file' => array('text', $a_name)),
857  array('lang' => array('text',$a_lang), 'type' => array('text','nacc')));
858  }
859 
861  {
862  global $ilDB;
863 
864  include_once "Services/User/classes/class.ilFSStorageUserFolder.php";
865  $fs = new ilFSStorageUserFolder($this->getId());
866  $path = $fs->getAbsolutePath()."/";
867 
868  @unlink($path.$a_lang);
869 
870  $ilDB->update('mail_template',
871  array('att_file' => array('text', '')),
872  array('lang' => array('text',$a_lang), 'type' => array('text','nacc')));
873  }
874 
875  function _lookupNewAccountMail($a_lang)
876  {
877  global $ilDB;
878 
879  $set = $ilDB->query("SELECT * FROM mail_template ".
880  " WHERE type='nacc' AND lang = ".$ilDB->quote($a_lang,'text'));
881 
882  if ($rec = $set->fetchRow(DB_FETCHMODE_ASSOC))
883  {
884  return $rec;
885  }
886  return array();
887  }
888 
900  public static function _updateUserFolderAssignment($a_old_id,$a_new_id)
901  {
902  global $ilDB;
903 
904  $query = "UPDATE usr_data SET time_limit_owner = ".$ilDB->quote($a_new_id, "integer")." ".
905  "WHERE time_limit_owner = ".$ilDB->quote($a_old_id, "integer")." ";
906  $ilDB->manipulate($query);
907 
908  return true;
909  }
910 
911 
912 } // END class.ilObjUserFolder
913 ?>