ILIAS  Release_4_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilUserXMLWriter.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  +-----------------------------------------------------------------------------+
5  | ILIAS open source |
6  +-----------------------------------------------------------------------------+
7  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
8  | |
9  | This program is free software; you can redistribute it and/or |
10  | modify it under the terms of the GNU General Public License |
11  | as published by the Free Software Foundation; either version 2 |
12  | of the License, or (at your option) any later version. |
13  | |
14  | This program is distributed in the hope that it will be useful, |
15  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
16  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17  | GNU General Public License for more details. |
18  | |
19  | You should have received a copy of the GNU General Public License |
20  | along with this program; if not, write to the Free Software |
21  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
22  +-----------------------------------------------------------------------------+
23 */
24 
38 include_once "./classes/class.ilXmlWriter.php";
39 include_once './Services/User/classes/class.ilObjUserFolder.php';
40 
42 {
43  var $ilias;
44  var $xml;
45  var $users;
46  var $user_id = 0;
47  var $attachRoles = false;
48  var $attachPreferences = false;
49  private static $exportablePrefs;
50 
56  private $settings;
57 
65  function ilUserXMLWriter()
66  {
67  global $ilias,$ilUser;
68 
70 
71  $this->ilias =& $ilias;
72  $this->user_id = $ilUser->getId();
73  $this->attachRoles = false;
74 
75 /* $this->exportablePrefs = array(
76  "priv_feed_pass", "language", "style", "skin", 'ilPageEditor_HTMLMode',
77  'ilPageEditor_JavaScript', 'ilPageEditor_MediaMode', 'tst_javascript',
78  'tst_lastquestiontype', 'tst_multiline_answers', 'tst_use_previous_answers',
79  'graphicalAnswerSetting', "weekstart"
80  );*/
81  }
82 
83  function setAttachRoles ($value)
84  {
85  $this->attachRoles = $value == 1? true : false;
86  }
87 
88  function setObjects(& $users)
89  {
90  $this->users = & $users;
91  }
92 
93 
94  function start()
95  {
96  if (!is_array($this->users))
97  return false;
98 
99  $this->__buildHeader();
100 
101 
102  include_once ("./Services/User/classes/class.ilUserDefinedFields.php");
103  $udf_data = & ilUserDefinedFields::_getInstance();
104  $udf_data->addToXML($this);
105 
106  foreach ($this->users as $user)
107  {
108 
109  $this->__handleUser ($user);
110 
111  }
112 
113  $this->__buildFooter();
114 
115  return true;
116  }
117 
118  function getXML()
119  {
120  return $this->xmlDumpMem(FALSE);
121  }
122 
123 
124  function __buildHeader()
125  {
126  $this->xmlSetDtdDef("<!DOCTYPE Users PUBLIC \"-//ILIAS//DTD UserImport//EN\" \"".ILIAS_HTTP_PATH."/xml/ilias_user_4_0.dtd\">");
127  $this->xmlSetGenCmt("User of ilias system");
128  $this->xmlHeader();
129 
130  $this->xmlStartTag('Users');
131 
132  return true;
133  }
134 
135  function __buildFooter()
136  {
137  $this->xmlEndTag('Users');
138  }
139 
140  function __handleUser ($row)
141  {
142  global $ilDB,$lng;
143  if (!is_array ($this->settings)) {
144  include_once ('./Services/User/classes/class.ilObjUserFolder.php');
146  }
147 
148  $prefs = ilObjUser::_getPreferences($row["usr_id"]);
149 
150  if (strlen($row["language"]) == 0)
151  {
152  $row["language"] = $lng->getDefaultLanguage();
153 
154  }
155 
156  $attrs = array (
157  'Id' => "il_".IL_INST_ID."_usr_".$row["usr_id"],
158  'Language' => $row["language"],
159  'Action' => "Update"
160  );
161 
162  $this->xmlStartTag("User", $attrs);
163 
164  $this->xmlElement("Login", null, $row["login"]);
165 
166  if ($this->attachRoles == TRUE)
167  {
168  include_once './Services/AccessControl/classes/class.ilObjRole.php';
169 
170  $query = sprintf("SELECT object_data.title, object_data.description, rbac_fa.* ".
171  "FROM object_data, rbac_ua, rbac_fa WHERE rbac_ua.usr_id = %s ".
172  "AND rbac_ua.rol_id = rbac_fa.rol_id AND object_data.obj_id = rbac_fa.rol_id",
173  $ilDB->quote($row["usr_id"],'integer')
174  );
175  $rbacresult = $ilDB->query($query);
176 
177  while ($rbacrow = $rbacresult->fetchRow(DB_FETCHMODE_ASSOC))
178  {
179  if ($rbacrow["assign"] != "y")
180  continue;
181 
182  $type = "";
183 
184  if ($rbacrow["parent"] == ROLE_FOLDER_ID)
185  {
186  $type = "Global";
187  }
188  else
189  {
190  $type = "Local";
191  }
192  if (strlen($type))
193  {
194  $this->xmlElement("Role",
195  array ("Id" =>
196  "il_".IL_INST_ID."_role_".$rbacrow["rol_id"], "Type" => $type),
197  $rbacrow["title"]);
198  }
199 
200  }
201  }
202 
206  $i2passwd = FALSE;
207  if ($this->canExport("i2passwd","i2passwd") && strlen($row["i2passwd"]) > 0)
208  {
209  $i2passwd = TRUE;
210  $this->__addElement("Password",$row["i2passwd"], array("Type" => "ILIAS2"),"i2passwd");
211  }
212  if (!$i2passwd && strlen($row["passwd"]) > 0)
213  {
214  $this->__addElement("Password",$row["passwd"], array("Type" => "ILIAS3"),"passwd");
215  }
216 
217 
218  $this->__addElement ("Firstname", $row["firstname"]);
219  $this->__addElement ("Lastname", $row["lastname"]);
220  $this->__addElement ("Title", $row["title"]);
221 
222  if ($this->canExport("PersonalPicture", "upload"))
223  {
224  $imageData = $this->getPictureValue($row["usr_id"]);
225  if ($imageData)
226  {
227  $value = array_shift($imageData); //$imageData["value"];
228  $this->__addElement ("PersonalPicture", $value, $imageData, "upload");
229  }
230  }
231 
232 
233  $this->__addElement ("Gender", $row["gender"]);
234  $this->__addElement ("Email", $row["email"]);
235  $this->__addElement ("Birthday", $row["birthday"]);
236  $this->__addElement ("Institution", $row["institution"]);
237  $this->__addElement ("Street", $row["street"]);
238  $this->__addElement ("City", $row["city"]);
239  $this->__addElement ("PostalCode", $row["zipcode"], null, "zipcode");
240  $this->__addElement ("Country", $row["country"]);
241  $this->__addElement ("PhoneOffice", $row["phone_office"], null, "phone_office");
242  $this->__addElement ("PhoneHome", $row["phone_home"], null, "phone_home");
243  $this->__addElement ("PhoneMobile", $row["phone_mobile"], null, "phone_mobile");
244  $this->__addElement ("Fax", $row["fax"]);
245  $this->__addElement ("Hobby", $row["hobby"]);
246  $this->__addElement ("Department", $row["department"]);
247  $this->__addElement ("Comment", $row["referral_comment"], null, "referral_comment");
248  $this->__addElement ("Matriculation", $row["matriculation"]);
249  $this->__addElement ("Active", $row["active"] ? "true":"false" );
250  $this->__addElement ("ClientIP", $row["client_ip"], null, "client_ip");
251  $this->__addElement ("TimeLimitOwner", $row["time_limit_owner"], null, "time_limit_owner");
252  $this->__addElement ("TimeLimitUnlimited", $row["time_limit_unlimited"], null, "time_limit_unlimited");
253  $this->__addElement ("TimeLimitFrom", $row["time_limit_from"], null, "time_limit_from");
254  $this->__addElement ("TimeLimitUntil", $row["time_limit_until"], null, "time_limit_until");
255  $this->__addElement ("TimeLimitMessage", $row["time_limit_message"], null, "time_limit_message");
256  $this->__addElement ("ApproveDate", $row["approve_date"], null, "approve_date");
257  $this->__addElement ("AgreeDate", $row["agree_date"], null, "agree_date");
258 
259  if ((int) $row["ilinc_id"] !=0) {
260  $this->__addElement ("iLincID", $row["ilinc_id"], "ilinc_id");
261  $this->__addElement ("iLincUser", $row["ilinc_user"], "ilinc_user");
262  $this->__addElement ("iLincPasswd", $row["ilinc_passwd"], "ilinc_passwd");
263  }
264 
265  if (strlen($row["auth_mode"])>0)
266  {
267  $this->__addElement ("AuthMode", null, array ("type" => $row["auth_mode"]),"auth_mode", true);
268  }
269 
270  if (strlen($row["ext_account"])>0)
271  {
272  $this->__addElement ("ExternalAccount", $row["ext_account"], null, "ext_account", true);
273  }
274 
275  if ($this->canExport("Look","skin_style"))
276  {
277  $this->__addElement("Look", null, array(
278  "Skin" => $prefs["skin"], "Style" => $prefs["style"]
279  ), "skin_style", true);
280 
281  }
282 
283 
284  $this->__addElement ("LastUpdate", $row["last_update"], null, "last_update");
285  $this->__addElement ("LastLogin", $row["last_login"], null, "last_login");
286 
287  include_once ("./Services/User/classes/class.ilUserDefinedData.php");
288  $udf_data = new ilUserDefinedData($row['usr_id']);
289  $udf_data->addToXML($this, $this->settings);
290 
291  $msgrs = array ("skype" => "im_skype", "yahoo" => "im_yahoo", "msn"=>"im_msn", "aim"=>"im_aim", "icq"=>"im_icq", "delicious" => "delicious", "external" => "ext_account", "jabber" => "im_jabber", "voip" => "im_voip");
292  foreach ($msgrs as $type => $fieldname) {
293  $this->__addElement("AccountInfo", $row[$fieldname], array("Type" => $type), "instant_messengers");
294  }
295 
296  $this->__addElement("GMapsInfo", null, array (
297  "longitude" => $row["longitude"],
298  "latitude" => $row["latitude"],
299  "zoom" => $row["loc_zoom"]));
300 
301  $this->__addElement("Feedhash", $row["feed_hash"]);
302 
303  if ($this->attachPreferences || $this->canExport("prefs", "preferences"))
304  $this->__handlePreferences ($prefs, $row);
305 
306  $this->xmlEndTag('User');
307  }
308 
309 
310  private function __handlePreferences ($prefs, $row)
311  {
312 
313  include_once ("Services/Mail/classes/class.ilMailOptions.php");
314  $mailOptions = new ilMailOptions($row["usr_id"]);
315  $prefs["mail_incoming_type"] = $mailOptions->getIncomingType();
316  $prefs["mail_signature"] = $mailOptions->getSignature();
317  $prefs["mail_linebreak"] = $mailOptions->getLinebreak();
318  if (count($prefs))
319  {
320  $this->xmlStartTag("Prefs");
321  foreach ($prefs as $key => $value)
322  {
324  $this->xmlElement("Pref", array("key" => $key), $value);
325  }
326  $this->xmlEndTag("Prefs");
327  }
328  }
329 
330 
331  function __addElement ($tagname, $value, $attrs = null, $settingsname = null, $requiredTag = false)
332  {
333  if ($this->canExport($tagname, $settingsname))
334  if (strlen($value) > 0 || $requiredTag || (is_array($attrs) && count($attrs) > 0))
335  $this->xmlElement ($tagname, $attrs, $value);
336 
337  }
338 
339  private function canExport ($tagname, $settingsname = null)
340  {
341  return !is_array($this->settings) ||
342  in_array(strtolower($tagname), $this->settings) !== FALSE ||
343  in_array($settingsname, $this->settings) !== FALSE;
344  }
345 
351  function setSettings ($settings) {
352  $this->settings = $settings;
353  }
354 
360  private function getPictureValue ($usr_id) {
361  global $ilDB;
362  // personal picture
363  $q = sprintf("SELECT value FROM usr_pref WHERE usr_id = %s AND keyword = %s",
364  $ilDB->quote($usr_id, "integer"), $ilDB->quote('profile_image', "text"));
365  $r = $ilDB->query($q);
366  if ($ilDB->numRows($r) == 1)
367  {
368  $personal_picture_data = $r->fetchRow(DB_FETCHMODE_ASSOC);
369  $personal_picture = $personal_picture_data["value"];
370  $webspace_dir = ilUtil::getWebspaceDir();
371  $image_file = $webspace_dir."/usr_images/".$personal_picture;
372  if (@is_file($image_file))
373  {
374  $fh = fopen($image_file, "rb");
375  if ($fh)
376  {
377  $image_data = fread($fh, filesize($image_file));
378  fclose($fh);
379  $base64 = base64_encode($image_data);
380  $imagetype = "image/jpeg";
381  if (preg_match("/.*\.(png|gif)$/", $personal_picture, $matches))
382  {
383  $imagetype = "image/".$matches[1];
384  }
385  return array (
386  "value" => $base64,
387  "encoding" => "Base64",
388  "imagetype" => $imagetype
389  );
390  }
391  }
392  }
393  return false;
394  }
395 
396 
403  public function setAttachPreferences ($attachPrefs)
404  {
405  $this->attachPreferences = $attachPrefs;
406  }
407 
413  public static function getExportablePreferences() {
414  return array (
415  'hits_per_page',
416  'public_city',
417  'public_country',
418  'public_department',
419  'public_email',
420  'public_fax',
421  'public_hobby',
422  'public_institution',
423  'public_matriculation',
424  'public_phone',
425  'public_phone_home',
426  'public_phone_mobile',
427  'public_phone_office',
428  'public_profile',
429  'public_street',
430  'public_upload',
431  'public_zip',
432  'send_info_mails',
433  'show_users_online',
434  'hide_own_online_status',
435  'user_tz',
436  'weekstart',
437  'mail_incoming_type',
438  'mail_signature',
439  'mail_linebreak'
440  );
441  }
442 
449  public static function isPrefExportable($key) {
451  }
452 
453 }
454 
455 
456 ?>