ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilUserXMLWriter.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 include_once "./Services/Xml/classes/class.ilXmlWriter.php";
6 include_once './Services/User/classes/class.ilObjUserFolder.php';
7 
21 {
22  var $ilias;
23  var $xml;
24  var $users;
25  var $user_id = 0;
26  var $attachRoles = false;
27  var $attachPreferences = false;
28  private static $exportablePrefs;
29 
35  private $settings;
36 
44  function __construct()
45  {
46  global $ilias,$ilUser;
47 
48  parent::__construct();
49 
50  $this->ilias = $ilias;
51  $this->user_id = $ilUser->getId();
52  $this->attachRoles = false;
53 
54 /* $this->exportablePrefs = array(
55  "priv_feed_pass", "language", "style", "skin", 'ilPageEditor_HTMLMode',
56  'ilPageEditor_JavaScript', 'ilPageEditor_MediaMode', 'tst_javascript',
57  'tst_lastquestiontype', 'tst_multiline_answers', 'tst_use_previous_answers',
58  'graphicalAnswerSetting', "weekstart"
59  );*/
60  }
61 
62  function setAttachRoles ($value)
63  {
64  $this->attachRoles = $value == 1? true : false;
65  }
66 
67  function setObjects(& $users)
68  {
69  $this->users = & $users;
70  }
71 
72 
73  function start()
74  {
75  if (!is_array($this->users))
76  return false;
77 
78  $this->__buildHeader();
79 
80 
81  include_once ("./Services/User/classes/class.ilUserDefinedFields.php");
82  $udf_data = & ilUserDefinedFields::_getInstance();
83  $udf_data->addToXML($this);
84 
85  foreach ($this->users as $user)
86  {
87 
88  $this->__handleUser ($user);
89 
90  }
91 
92  $this->__buildFooter();
93 
94  return true;
95  }
96 
97  function getXML()
98  {
99  return $this->xmlDumpMem(FALSE);
100  }
101 
102 
103  function __buildHeader()
104  {
105  $this->xmlSetDtdDef("<!DOCTYPE Users PUBLIC \"-//ILIAS//DTD UserImport//EN\" \"".ILIAS_HTTP_PATH."/xml/ilias_user_5_1.dtd\">");
106  $this->xmlSetGenCmt("User of ilias system");
107  $this->xmlHeader();
108 
109  $this->xmlStartTag('Users');
110 
111  return true;
112  }
113 
114  function __buildFooter()
115  {
116  $this->xmlEndTag('Users');
117  }
118 
119  function __handleUser ($row)
120  {
121  global $ilDB,$lng;
122  if (!is_array ($this->settings)) {
123  include_once ('./Services/User/classes/class.ilObjUserFolder.php');
125  }
126 
127  $prefs = ilObjUser::_getPreferences($row["usr_id"]);
128 
129  if (strlen($row["language"]) == 0)
130  {
131  $row["language"] = $lng->getDefaultLanguage();
132 
133  }
134 
135  $attrs = array (
136  'Id' => "il_".IL_INST_ID."_usr_".$row["usr_id"],
137  'Language' => $row["language"],
138  'Action' => "Update"
139  );
140 
141  $this->xmlStartTag("User", $attrs);
142 
143  $this->xmlElement("Login", null, $row["login"]);
144 
145  if ($this->attachRoles == TRUE)
146  {
147  include_once './Services/AccessControl/classes/class.ilObjRole.php';
148 
149  $query = sprintf("SELECT object_data.title, object_data.description, rbac_fa.* ".
150  "FROM object_data, rbac_ua, rbac_fa WHERE rbac_ua.usr_id = %s ".
151  "AND rbac_ua.rol_id = rbac_fa.rol_id AND object_data.obj_id = rbac_fa.rol_id",
152  $ilDB->quote($row["usr_id"],'integer')
153  );
154  $rbacresult = $ilDB->query($query);
155 
156  while ($rbacrow = $rbacresult->fetchRow(ilDBConstants::FETCHMODE_ASSOC))
157  {
158  if ($rbacrow["assign"] != "y")
159  continue;
160 
161  $type = "";
162 
163  if ($rbacrow["parent"] == ROLE_FOLDER_ID)
164  {
165  $type = "Global";
166  }
167  else
168  {
169  $type = "Local";
170  }
171  if (strlen($type))
172  {
173  $this->xmlElement("Role",
174  array ("Id" =>
175  "il_".IL_INST_ID."_role_".$rbacrow["rol_id"], "Type" => $type),
176  $rbacrow["title"]);
177  }
178 
179  }
180  }
181 
182  $this->__addElement ("Firstname", $row["firstname"]);
183  $this->__addElement ("Lastname", $row["lastname"]);
184  $this->__addElement ("Title", $row["title"]);
185 
186  if ($this->canExport("PersonalPicture", "upload"))
187  {
188  $imageData = $this->getPictureValue($row["usr_id"]);
189  if ($imageData)
190  {
191  $value = array_shift($imageData); //$imageData["value"];
192  $this->__addElement ("PersonalPicture", $value, $imageData, "upload");
193  }
194  }
195 
196 
197  $this->__addElement ("Gender", $row["gender"]);
198  $this->__addElement ("Email", $row["email"]);
199  $this->__addElement ("Birthday", $row["birthday"]);
200  $this->__addElement ("Institution", $row["institution"]);
201  $this->__addElement ("Street", $row["street"]);
202  $this->__addElement ("City", $row["city"]);
203  $this->__addElement ("PostalCode", $row["zipcode"], null, "zipcode");
204  $this->__addElement ("Country", $row["country"]);
205  $this->__addElement ("SelCountry", $row["sel_country"], null, "sel_country");
206  $this->__addElement ("PhoneOffice", $row["phone_office"], null, "phone_office");
207  $this->__addElement ("PhoneHome", $row["phone_home"], null, "phone_home");
208  $this->__addElement ("PhoneMobile", $row["phone_mobile"], null, "phone_mobile");
209  $this->__addElement ("Fax", $row["fax"]);
210  $this->__addElement ("Hobby", $row["hobby"]);
211 
212  $this->__addElementMulti ("GeneralInterest", $row["interests_general"], null, "interests_general");
213  $this->__addElementMulti ("OfferingHelp", $row["interests_help_offered"], null, "interests_help_offered");
214  $this->__addElementMulti ("LookingForHelp", $row["interests_help_looking"], null, "interests_help_looking");
215 
216  $this->__addElement ("Department", $row["department"]);
217  $this->__addElement ("Comment", $row["referral_comment"], null, "referral_comment");
218  $this->__addElement ("Matriculation", $row["matriculation"]);
219  $this->__addElement ("Active", $row["active"] ? "true":"false" );
220  $this->__addElement ("ClientIP", $row["client_ip"], null, "client_ip");
221  $this->__addElement ("TimeLimitOwner", $row["time_limit_owner"], null, "time_limit_owner");
222  $this->__addElement ("TimeLimitUnlimited", $row["time_limit_unlimited"], null, "time_limit_unlimited");
223  $this->__addElement ("TimeLimitFrom", $row["time_limit_from"], null, "time_limit_from");
224  $this->__addElement ("TimeLimitUntil", $row["time_limit_until"], null, "time_limit_until");
225  $this->__addElement ("TimeLimitMessage", $row["time_limit_message"], null, "time_limit_message");
226  $this->__addElement ("ApproveDate", $row["approve_date"], null, "approve_date");
227  $this->__addElement ("AgreeDate", $row["agree_date"], null, "agree_date");
228 
229  if (strlen($row["auth_mode"])>0)
230  {
231  $this->__addElement ("AuthMode", null, array ("type" => $row["auth_mode"]),"auth_mode", true);
232  }
233 
234  if (strlen($row["ext_account"])>0)
235  {
236  $this->__addElement ("ExternalAccount", $row["ext_account"], null, "ext_account", true);
237  }
238 
239  if ($this->canExport("Look","skin_style"))
240  {
241  $this->__addElement("Look", null, array(
242  "Skin" => $prefs["skin"], "Style" => $prefs["style"]
243  ), "skin_style", true);
244 
245  }
246 
247 
248  $this->__addElement ("LastUpdate", $row["last_update"], null, "last_update");
249  $this->__addElement ("LastLogin", $row["last_login"], null, "last_login");
250 
251  include_once ("./Services/User/classes/class.ilUserDefinedData.php");
252  $udf_data = new ilUserDefinedData($row['usr_id']);
253  $udf_data->addToXML($this, $this->settings);
254 
255  $this->__addElement("AccountInfo", $row["ext_account"], array("Type" => "external"));
256 
257  $this->__addElement("GMapsInfo", null, array (
258  "longitude" => $row["longitude"],
259  "latitude" => $row["latitude"],
260  "zoom" => $row["loc_zoom"]));
261 
262  $this->__addElement("Feedhash", $row["feed_hash"]);
263 
264  if ($this->attachPreferences || $this->canExport("prefs", "preferences"))
265  $this->__handlePreferences ($prefs, $row);
266 
267  $this->xmlEndTag('User');
268  }
269 
270 
271  private function __handlePreferences ($prefs, $row)
272  {
273 
274  include_once ("Services/Mail/classes/class.ilMailOptions.php");
275  $mailOptions = new ilMailOptions($row["usr_id"]);
276  $prefs["mail_incoming_type"] = $mailOptions->getIncomingType();
277  $prefs["mail_signature"] = $mailOptions->getSignature();
278  $prefs["mail_linebreak"] = $mailOptions->getLinebreak();
279  if (count($prefs))
280  {
281  $this->xmlStartTag("Prefs");
282  foreach ($prefs as $key => $value)
283  {
285  $this->xmlElement("Pref", array("key" => $key), $value);
286  }
287  $this->xmlEndTag("Prefs");
288  }
289  }
290 
291  function __addElementMulti ($tagname, $value, $attrs = null, $settingsname = null, $requiredTag = false)
292  {
293  if(is_array($value) && sizeof($value))
294  {
295  foreach($value as $idx => $item)
296  {
297  $this->__addElement ($tagname, $item, $attrs, $settingsname, $requiredTag);
298  }
299  }
300  }
301 
302  function __addElement ($tagname, $value, $attrs = null, $settingsname = null, $requiredTag = false)
303  {
304  if ($this->canExport($tagname, $settingsname))
305  {
306  if (strlen($value) > 0 || $requiredTag || (is_array($attrs) && count($attrs) > 0))
307  {
308  $this->xmlElement ($tagname, $attrs, $value);
309  }
310  }
311  }
312 
313  private function canExport ($tagname, $settingsname = null)
314  {
315  return !is_array($this->settings) ||
316  in_array(strtolower($tagname), $this->settings) !== FALSE ||
317  in_array($settingsname, $this->settings) !== FALSE;
318  }
319 
325  function setSettings ($settings) {
326  $this->settings = $settings;
327  }
328 
334  private function getPictureValue ($usr_id) {
335  global $ilDB;
336  // personal picture
337  $q = sprintf("SELECT value FROM usr_pref WHERE usr_id = %s AND keyword = %s",
338  $ilDB->quote($usr_id, "integer"), $ilDB->quote('profile_image', "text"));
339  $r = $ilDB->query($q);
340  if ($ilDB->numRows($r) == 1)
341  {
342  $personal_picture_data = $r->fetchRow(ilDBConstants::FETCHMODE_ASSOC);
343  $personal_picture = $personal_picture_data["value"];
344  $webspace_dir = ilUtil::getWebspaceDir();
345  $image_file = $webspace_dir."/usr_images/".$personal_picture;
346  if (@is_file($image_file))
347  {
348  $fh = fopen($image_file, "rb");
349  if ($fh)
350  {
351  $image_data = fread($fh, filesize($image_file));
352  fclose($fh);
353  $base64 = base64_encode($image_data);
354  $imagetype = "image/jpeg";
355  if (preg_match("/.*\.(png|gif)$/", $personal_picture, $matches))
356  {
357  $imagetype = "image/".$matches[1];
358  }
359  return array (
360  "value" => $base64,
361  "encoding" => "Base64",
362  "imagetype" => $imagetype
363  );
364  }
365  }
366  }
367  return false;
368  }
369 
370 
377  public function setAttachPreferences ($attachPrefs)
378  {
379  $this->attachPreferences = $attachPrefs;
380  }
381 
387  public static function getExportablePreferences() {
388  return array (
389  'hits_per_page',
390  'public_city',
391  'public_country',
392  'public_department',
393  'public_email',
394  'public_fax',
395  'public_hobby',
396  'public_institution',
397  'public_matriculation',
398  'public_phone',
399  'public_phone_home',
400  'public_phone_mobile',
401  'public_phone_office',
402  'public_profile',
403  'public_street',
404  'public_upload',
405  'public_zip',
406  'send_info_mails',
407  /*'show_users_online',*/
408  'hide_own_online_status',
409  'bs_allow_to_contact_me',
410  'chat_osc_accept_msg',
411  'user_tz',
412  'weekstart',
413  'mail_incoming_type',
414  'mail_signature',
415  'mail_linebreak',
416  'public_interests_general',
417  'public_interests_help_offered',
418  'public_interests_help_looking'
419  );
420  }
421 
428  public static function isPrefExportable($key) {
429  return in_array($key, ilUserXMLWriter::getExportablePreferences());
430  }
431 
432 }
433 
434 
435 ?>
getPictureValue($usr_id)
return array with baseencoded picture data as key value, encoding type as encoding, and image type as key type.
Class UserMail this class handles user mails.
xmlSetGenCmt($genCmt)
Sets generated comment.
static _getInstance()
Get instance.
Class ilUserDefinedData.
__handlePreferences($prefs, $row)
__addElement($tagname, $value, $attrs=null, $settingsname=null, $requiredTag=false)
xmlSetDtdDef($dtdDef)
Sets dtd definition.
xmlStartTag($tag, $attrs=NULL, $empty=FALSE, $encode=TRUE, $escape=TRUE)
Writes a starttag.
setSettings($settings)
write access to settings
XML writer class.
xmlElement($tag, $attrs=NULL, $data=Null, $encode=TRUE, $escape=TRUE)
Writes a basic element (no children, just textual content)
static isPrefExportable($key)
returns wether a key from db is exportable or not
canExport($tagname, $settingsname=null)
xmlEndTag($tag)
Writes an endtag.
static getExportSettings()
getExport Settings
$r
Definition: example_031.php:79
setAttachPreferences($attachPrefs)
if set to true, all preferences of a user will be set
XML writer class.
$ilUser
Definition: imgupload.php:18
redirection script todo: (a better solution should control the processing via a xml file) ...
xmlHeader()
Writes xml header public.
Create styles array
The data for the language used.
__addElementMulti($tagname, $value, $attrs=null, $settingsname=null, $requiredTag=false)
settings()
Definition: settings.php:2
global $lng
Definition: privfeed.php:17
global $ilDB
static getExportablePreferences()
return exportable preference keys as found in db
static _getPreferences($user_id)
get preferences for user
static getWebspaceDir($mode="filesystem")
get webspace directory
__construct()
constructor
xmlDumpMem($format=TRUE)
Returns xml document from memory.