ILIAS  Release_3_10_x_branch Revision 61812
 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_3_10.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;
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) $row["language"] = "en";
151 
152  $attrs = array (
153  'Id' => "il_".IL_INST_ID."_usr_".$row["usr_id"],
154  'Language' => $row["language"],
155  'Action' => "Update"
156  );
157 
158  $this->xmlStartTag("User", $attrs);
159 
160  $this->xmlElement("Login", null, $row["login"]);
161 
162  if ($this->attachRoles == TRUE)
163  {
164  include_once './Services/AccessControl/classes/class.ilObjRole.php';
165 
166  $query = sprintf("SELECT object_data.title, object_data.description, rbac_fa.*
167  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",
168  $ilDB->quote($row["usr_id"])
169  );
170  $rbacresult = $ilDB->query($query);
171 
172  while ($rbacrow = $rbacresult->fetchRow(DB_FETCHMODE_ASSOC))
173  {
174  if ($rbacrow["assign"] != "y")
175  continue;
176 
177  $type = "";
178 
179  if ($rbacrow["parent"] == ROLE_FOLDER_ID)
180  {
181  $type = "Global";
182  }
183  else
184  {
185  $type = "Local";
186  }
187  if (strlen($type))
188  {
189  $this->xmlElement("Role",
190  array ("Id" =>
191  "il_".IL_INST_ID."_role_".$rbacrow["rol_id"], "Type" => $type),
192  $rbacrow["title"]);
193  }
194 
195  }
196  }
197 
201  $i2passwd = FALSE;
202  if ($this->canExport("i2passwd","i2passwd") && strlen($row["i2passwd"]) > 0)
203  {
204  $i2passwd = TRUE;
205  $this->__addElement("Password",$row["i2passwd"], array("Type" => "ILIAS2"),"i2passwd");
206  }
207  if (!$i2passwd && strlen($row["passwd"]) > 0)
208  {
209  $this->__addElement("Password",$row["passwd"], array("Type" => "ILIAS3"),"passwd");
210  }
211 
212 
213  $this->__addElement ("Firstname", $row["firstname"]);
214  $this->__addElement ("Lastname", $row["lastname"]);
215  $this->__addElement ("Title", $row["title"]);
216 
217  if ($this->canExport("PersonalPicture", "upload"))
218  {
219  $imageData = $this->getPictureValue($row["usr_id"]);
220  if ($imageData)
221  {
222  $value = array_shift($imageData); //$imageData["value"];
223  $this->__addElement ("PersonalPicture", $value, $imageData, "upload");
224  }
225  }
226 
227 
228  $this->__addElement ("Gender", $row["gender"]);
229  $this->__addElement ("Email", $row["email"]);
230  $this->__addElement ("Institution", $row["institution"]);
231  $this->__addElement ("Street", $row["street"]);
232  $this->__addElement ("City", $row["city"]);
233  $this->__addElement ("PostalCode", $row["zipcode"], null, "zipcode");
234  $this->__addElement ("Country", $row["country"]);
235  $this->__addElement ("PhoneOffice", $row["phone_office"], null, "phone_office");
236  $this->__addElement ("PhoneHome", $row["phone_home"], null, "phone_home");
237  $this->__addElement ("PhoneMobile", $row["phone_mobile"], null, "phone_mobile");
238  $this->__addElement ("Fax", $row["fax"]);
239  $this->__addElement ("Hobby", $row["hobby"]);
240  $this->__addElement ("Department", $row["department"]);
241  $this->__addElement ("Comment", $row["referral_comment"], null, "referral_comment");
242  $this->__addElement ("Matriculation", $row["matriculation"]);
243  $this->__addElement ("Active", $row["active"] ? "true":"false" );
244  $this->__addElement ("ClientIP", $row["client_ip"], null, "client_ip");
245  $this->__addElement ("TimeLimitOwner", $row["time_limit_owner"], null, "time_limit_owner");
246  $this->__addElement ("TimeLimitUnlimited", $row["time_limit_unlimited"], null, "time_limit_unlimited");
247  $this->__addElement ("TimeLimitFrom", $row["time_limit_from"], null, "time_limit_from");
248  $this->__addElement ("TimeLimitUntil", $row["time_limit_until"], null, "time_limit_until");
249  $this->__addElement ("TimeLimitMessage", $row["time_limit_message"], null, "time_limit_message");
250  $this->__addElement ("ApproveDate", $row["approve_date"], null, "approve_date");
251  $this->__addElement ("AgreeDate", $row["agree_date"], null, "agree_date");
252 
253  if ((int) $row["ilinc_id"] !=0) {
254  $this->__addElement ("iLincID", $row["ilinc_id"], "ilinc_id");
255  $this->__addElement ("iLincUser", $row["ilinc_user"], "ilinc_user");
256  $this->__addElement ("iLincPasswd", $row["ilinc_passwd"], "ilinc_passwd");
257  }
258 
259  if (strlen($row["auth_mode"])>0)
260  {
261  $this->__addElement ("AuthMode", null, array ("type" => $row["auth_mode"]),"auth_mode", true);
262  }
263 
264  if (strlen($row["ext_account"])>0)
265  {
266  $this->__addElement ("ExternalAccount", $row["ext_account"], null, "ext_account", true);
267  }
268 
269  if ($this->canExport("Look","skin_style"))
270  {
271  $this->__addElement("Look", null, array(
272  "Skin" => $prefs["skin"], "Style" => $prefs["style"]
273  ), "skin_style", true);
274 
275  }
276 
277 
278  $this->__addElement ("LastUpdate", $row["last_update"], null, "last_update");
279  $this->__addElement ("LastLogin", $row["last_login"], null, "last_login");
280 
281  include_once ("./Services/User/classes/class.ilUserDefinedData.php");
282  $udf_data = new ilUserDefinedData($row['usr_id']);
283  $udf_data->addToXML($this, $this->settings);
284 
285  $msgrs = array ("skype" => "im_skype", "yahoo" => "im_yahoo", "msn"=>"im_msn", "aim"=>"im_aim", "icq"=>"im_icq", "delicious" => "delicious", "external" => "ext_account");
286  foreach ($msgrs as $type => $fieldname) {
287  $this->__addElement("AccountInfo", $row[$fieldname], array("Type" => $type), "instant_messengers");
288  }
289 
290  $this->__addElement("GMapsInfo", null, array (
291  "longitude" => $row["longitude"],
292  "latitude" => $row["latitude"],
293  "zoom" => $row["loc_zoom"]));
294 
295  $this->__addElement("Feedhash", $row["feed_hash"]);
296 
297  if ($this->attachPreferences || $this->canExport("prefs", "preferences"))
298  $this->__handlePreferences ($prefs, $row);
299 
300  $this->xmlEndTag('User');
301  }
302 
303 
304  private function __handlePreferences ($prefs, $row)
305  {
306 
307  include_once ("Services/Mail/classes/class.ilMailOptions.php");
308  $mailOptions = new ilMailOptions($row["usr_id"]);
309  $prefs["mail_incoming_type"] = $mailOptions->getIncomingType();
310  $prefs["mail_signature"] = $mailOptions->getSignature();
311  $prefs["mail_linebreak"] = $mailOptions->getLinebreak();
312  if (count($prefs))
313  {
314  $this->xmlStartTag("Prefs");
315  foreach ($prefs as $key => $value)
316  {
318  $this->xmlElement("Pref", array("key" => $key), $value);
319  }
320  $this->xmlEndTag("Prefs");
321  }
322  }
323 
324 
325  function __addElement ($tagname, $value, $attrs = null, $settingsname = null, $requiredTag = false)
326  {
327  if ($this->canExport($tagname, $settingsname))
328  if (strlen($value) > 0 || $requiredTag || (is_array($attrs) && count($attrs) > 0))
329  $this->xmlElement ($tagname, $attrs, $value);
330 
331  }
332 
333  private function canExport ($tagname, $settingsname = null)
334  {
335  return !is_array($this->settings) ||
336  in_array(strtolower($tagname), $this->settings) !== FALSE ||
337  in_array($settingsname, $this->settings) !== FALSE;
338  }
339 
345  function setSettings ($settings) {
346  $this->settings = $settings;
347  }
348 
354  private function getPictureValue ($usr_id) {
355  global $ilDB;
356  // personal picture
357  $q = sprintf("SELECT value FROM usr_pref WHERE usr_id=%s AND keyword='profile_image'", $ilDB->quote($usr_id . ""));
358  $r = $ilDB->query($q);
359  if ($r->numRows() == 1)
360  {
361  $personal_picture_data = $r->fetchRow(DB_FETCHMODE_ASSOC);
362  $personal_picture = $personal_picture_data["value"];
363  $webspace_dir = ilUtil::getWebspaceDir();
364  $image_file = $webspace_dir."/usr_images/".$personal_picture;
365  if (@is_file($image_file))
366  {
367  $fh = fopen($image_file, "rb");
368  if ($fh)
369  {
370  $image_data = fread($fh, filesize($image_file));
371  fclose($fh);
372  $base64 = base64_encode($image_data);
373  $imagetype = "image/jpeg";
374  if (preg_match("/.*\.(png|gif)$/", $personal_picture, $matches))
375  {
376  $imagetype = "image/".$matches[1];
377  }
378  return array (
379  "value" => $base64,
380  "encoding" => "Base64",
381  "imagetype" => $imagetype
382  );
383  }
384  }
385  }
386  return false;
387  }
388 
389 
396  public function setAttachPreferences ($attachPrefs)
397  {
398  $this->attachPreferences = $attachPrefs;
399  }
400 
406  public static function getExportablePreferences() {
407  return array (
408  'hits_per_page',
409  'public_city',
410  'public_country',
411  'public_department',
412  'public_email',
413  'public_fax',
414  'public_hobby',
415  'public_institution',
416  'public_matriculation',
417  'public_phone',
418  'public_phone_home',
419  'public_phone_mobile',
420  'public_phone_office',
421  'public_profile',
422  'public_street',
423  'public_upload',
424  'public_zip',
425  'send_info_mails',
426  'show_users_online',
427  'hide_own_online_status',
428  'user_tz',
429  'weekstart',
430  'mail_incoming_type',
431  'mail_signature',
432  'mail_linebreak'
433  );
434  }
435 
442  public static function isPrefExportable($key) {
443  return in_array($key, ilUserXMLWriter::getExportablePreferences());
444  }
445 
446 }
447 
448 
449 ?>