• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

Services/User/classes/class.ilUserXMLWriter.php

Go to the documentation of this file.
00001 <?php
00002 
00003 /*
00004     +-----------------------------------------------------------------------------+
00005     | ILIAS open source                                                           |
00006         +-----------------------------------------------------------------------------+
00007     | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00008     |                                                                             |
00009     | This program is free software; you can redistribute it and/or               |
00010     | modify it under the terms of the GNU General Public License                 |
00011     | as published by the Free Software Foundation; either version 2              |
00012     | of the License, or (at your option) any later version.                      |
00013     |                                                                             |
00014     | This program is distributed in the hope that it will be useful,             |
00015     | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00016     | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00017     | GNU General Public License for more details.                                |
00018     |                                                                             |
00019     | You should have received a copy of the GNU General Public License           |
00020     | along with this program; if not, write to the Free Software                 |
00021     | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00022     +-----------------------------------------------------------------------------+
00023 */
00024 
00038 include_once "./classes/class.ilXmlWriter.php";
00039 include_once './Services/User/classes/class.ilObjUserFolder.php';
00040 
00041 class ilUserXMLWriter extends ilXmlWriter
00042 {
00043         var $ilias;
00044         var $xml;
00045         var $users;
00046         var $user_id = 0;
00047         var $attachRoles = false;
00048 
00054         private $settings;
00055 
00063         function ilUserXMLWriter()
00064         {
00065                 global $ilias,$ilUser;
00066 
00067                 parent::ilXmlWriter();
00068 
00069                 $this->ilias =& $ilias;
00070                 $this->user_id = $ilUser->getId();
00071                 $this->attachRoles = false;
00072         }
00073 
00074         function setAttachRoles ($value)
00075         {
00076                 $this->attachRoles = $value == 1? true : false;
00077         }
00078 
00079         function setObjects(&  $users)
00080         {
00081                 $this->users = & $users;
00082         }
00083 
00084 
00085         function start()
00086         {
00087                 if (!is_array($this->users))
00088                         return false;
00089 
00090                 $this->__buildHeader();
00091 
00092 
00093             include_once ("./Services/User/classes/class.ilUserDefinedFields.php");
00094                 $udf_data = & ilUserDefinedFields::_getInstance();
00095                 $udf_data->addToXML($this);
00096 
00097                 foreach ($this->users as $user)
00098                 {
00099 
00100                         $this->__handleUser ($user);
00101 
00102                 }
00103 
00104                 $this->__buildFooter();
00105 
00106                 return true;
00107         }
00108 
00109         function getXML()
00110         {
00111                 return $this->xmlDumpMem(FALSE);
00112         }
00113 
00114 
00115         function __buildHeader()
00116         {
00117                 $this->xmlSetDtdDef("<!DOCTYPE Users PUBLIC \"-//ILIAS//DTD UserImport//EN\" \"".ILIAS_HTTP_PATH."/xml/ilias_user_3_8.dtd\">");
00118                 $this->xmlSetGenCmt("User of ilias system");
00119                 $this->xmlHeader();
00120 
00121                 $this->xmlStartTag('Users');
00122 
00123                 return true;
00124         }
00125 
00126         function __buildFooter()
00127         {
00128                 $this->xmlEndTag('Users');
00129         }
00130 
00131         function __handleUser ($row)
00132         {
00133                 global $ilDB;
00134                 if (!is_array ($this->settings))  {
00135                         include_once ('./Services/User/classes/class.ilObjUserFolder.php');
00136                         $this->setSettings(ilObjUserFolder::getExportSettings());
00137                 }
00138                 
00139                 if (strlen($row["language"]) == 0) $row["language"] = "en";
00140 
00141                 $attrs = array (
00142                         'Id' => "il_".IL_INST_ID."_usr_".$row["usr_id"],
00143                         'Language' => $row["language"],
00144                         'Action' => "Update");
00145 
00146                 $this->xmlStartTag("User", $attrs);
00147 
00148                 $this->xmlElement("Login", null, $row["login"]);
00149 
00150                 if ($this->attachRoles == TRUE)
00151                 {
00152                         include_once './classes/class.ilObjRole.php';
00153 
00154                         $query = sprintf("SELECT object_data.title, object_data.description,  rbac_fa.*
00155                                           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",
00156                                         $ilDB->quote($row["usr_id"])
00157                         );
00158                         $rbacresult = $ilDB->query($query);
00159 
00160                         while ($rbacrow = $rbacresult->fetchRow(DB_FETCHMODE_ASSOC))
00161                         {
00162                                         if ($rbacrow["assign"] != "y")
00163                                                 continue;
00164 
00165                                         $type = "";
00166 
00167                                         if ($rbacrow["parent"] == ROLE_FOLDER_ID)
00168                                         {
00169                                                 $type = "Global";
00170                                         }
00171                                         else
00172                                         {
00173                                                 $type = "Local";
00174                                         }
00175                                         if (strlen($type))
00176                                         {
00177                                                 $this->xmlElement("Role",
00178                                                         array ("Id" =>
00179                                                                 "il_".IL_INST_ID."_role_".$rbacrow["rol_id"], "Type" => $type),
00180                                                         $rbacrow["title"]);
00181                                         }
00182 
00183                         }
00184                 }
00185 
00189                 $i2passwd = FALSE;
00190                 if ($this->canExport("i2passwd","i2passwd") && strlen($row["i2passwd"]) > 0)
00191                 {
00192                         $i2passwd = TRUE;
00193                         $this->__addElement("Password",$row["i2passwd"], array("Type" => "ILIAS2"),"i2passwd");
00194                 }
00195                 if (!$i2passwd && strlen($row["passwd"]) > 0)
00196                 {
00197                         $this->__addElement("Password",$row["passwd"], array("Type" => "ILIAS3"),"passwd");
00198                 }
00199 
00200 
00201                 $this->__addElement ("Firstname", $row["firstname"]);
00202                 $this->__addElement ("Lastname", $row["lastname"]);
00203                 $this->__addElement ("Title", $row["title"]);
00204 
00205                 if ($this->canExport("PersonalPicture", "upload"))
00206                 {
00207                         $imageData = $this->getPictureValue($row["usr_id"]);
00208                         if ($imageData)
00209                         {
00210                                 $value = array_shift($imageData); //$imageData["value"];
00211                                 $this->__addElement ("PersonalPicture", $value, $imageData, "upload");
00212                         }
00213                 }
00214 
00215 
00216                 $this->__addElement ("Gender", $row["gender"]);
00217                 $this->__addElement ("Email", $row["email"]);
00218                 $this->__addElement ("Institution", $row["institution"]);
00219                 $this->__addElement ("Street", $row["street"]);
00220                 $this->__addElement ("City", $row["city"]);
00221                 $this->__addElement ("PostalCode", $row["zipcode"], null, "zipcode");
00222                 $this->__addElement ("Country", $row["country"]);
00223                 $this->__addElement ("PhoneOffice", $row["phone_office"], null, "phone_office");
00224                 $this->__addElement ("PhoneHome", $row["phone_home"], null, "phone_home");
00225                 $this->__addElement ("PhoneMobile", $row["phone_mobile"],  null, "phone_mobile");
00226                 $this->__addElement ("Fax", $row["fax"]);
00227                 $this->__addElement ("Hobby", $row["hobby"]);
00228                 $this->__addElement ("Department", $row["department"]);
00229                 $this->__addElement ("Comment", $row["referral_comment"], null, "referral_comment");
00230                 $this->__addElement ("Matriculation", $row["matriculation"]);
00231                 $this->__addElement ("Active", $row["active"] ? "true":"false" );
00232                 $this->__addElement ("ClientIP", $row["client_ip"], null, "client_ip");
00233                 $this->__addElement ("TimeLimitOwner", $row["time_limit_owner"], null, "time_limit_owner");
00234                 $this->__addElement ("TimeLimitUnlimited", $row["time_limit_unlimited"], null, "time_limit_unlimited");
00235                 $this->__addElement ("TimeLimitFrom", $row["time_limit_from"], null, "time_limit_from");
00236                 $this->__addElement ("TimeLimitUntil", $row["time_limit_until"], null, "time_limit_until");
00237                 $this->__addElement ("TimeLimitMessage", $row["time_limit_message"], null, "time_limit_message");
00238                 $this->__addElement ("ApproveDate", $row["approve_date"], null, "client_ip");
00239                 $this->__addElement ("AgreeDate", $row["agree_date"], null, "agree_date");
00240 
00241                 if ((int) $row["ilinc_id"] !=0) {
00242                                 $this->__addElement ("iLincID", $row["ilinc_id"], "ilinc_id");
00243                                 $this->__addElement ("iLincUser", $row["ilinc_user"], "ilinc_user");
00244                                 $this->__addElement ("iLincPasswd", $row["ilinc_passwd"], "ilinc_passwd");
00245                 }
00246 
00247                 if (strlen($row["auth_mode"])>0)
00248                 {
00249                         $this->__addElement ("AuthMode", null, array ("type" => $row["auth_mode"]),"auth_mode");
00250                 }
00251 
00252                 if (strlen($row["ext_account"])>0)
00253                 {
00254                         $this->__addElement ("ExternalAccount", $row["ext_account"], null, "ext_account");
00255                 }
00256 
00257             if ($this->canExport("skin_style"))
00258             {
00259 
00260                 $this->__addElement("Look",null,array(
00261                         "Skin"  =>      ilObjUser::_lookupPref($row["usr_id"], "skin") ,
00262                         "Style" =>      ilObjUser::_lookupPref($row["usr_id"], "style")
00263                 ),"skin_style");
00264 
00265             }
00266 
00267 
00268                 $this->__addElement ("LastUpdate", $row["last_update"], null, "last_update");
00269                 $this->__addElement ("LastLogin", $row["last_login"], null, "last_login");
00270 
00271                 include_once ("./Services/User/classes/class.ilUserDefinedData.php");
00272                 $udf_data = new ilUserDefinedData($row['usr_id']);
00273                 $udf_data->addToXML($this, $this->settings);
00274 
00275                 $msgrs = array ("skype" => "im_skype", "yahoo" => "im_yahoo", "msn"=>"im_msn", "aim"=>"im_aim", "icq"=>"im_icq", "delicious" => "delicious", "external" => "ext_account");
00276                 foreach ($msgrs as $type => $fieldname) {
00277                         $this->__addElement("AccountInfo", $row[$fieldname], array("Type" => $type), "instant_messengers");
00278                 }
00279 
00280                 $this->__addElement("GMapsInfo", null, array (
00281                         "longitude" => $row["longitude"],
00282                         "latitude" => $row["latitude"],
00283                         "zoom" => $row["loc_zoom"]));
00284 
00285 
00286                 $this->xmlEndTag('User');
00287         }
00288 
00289 
00290         function __addElement ($tagname, $value, $attrs = null, $settingsname = null)
00291         {
00292                 if ($this->canExport($tagname, $settingsname))
00293                         $this->xmlElement ($tagname, $attrs, $value);
00294 
00295         }
00296 
00297         private function canExport ($tagname, $settingsname = null)
00298         {
00299                 return !is_array($this->settings) ||
00300                            in_array(strtolower($tagname), $this->settings) !== FALSE ||
00301                            in_array($settingsname, $this->settings) !== FALSE;
00302         }
00303 
00309         function setSettings ($settings) {
00310                 $this->settings = $settings;
00311         }
00312 
00318         private function getPictureValue ($usr_id) {
00319                 global $ilDB;
00320                 // personal picture
00321                 $q = sprintf("SELECT value FROM usr_pref WHERE usr_id=%s AND keyword='profile_image'", $ilDB->quote($usr_id . ""));
00322                 $r = $ilDB->query($q);
00323                 if ($r->numRows() == 1)
00324                 {
00325                         $personal_picture_data = $r->fetchRow(DB_FETCHMODE_ASSOC);
00326                         $personal_picture = $personal_picture_data["value"];
00327                         $webspace_dir = ilUtil::getWebspaceDir();
00328                         $image_file = $webspace_dir."/usr_images/".$personal_picture;
00329                         if (@is_file($image_file))
00330                         {
00331                                 $fh = fopen($image_file, "rb");
00332                                 if ($fh)
00333                                 {
00334                                         $image_data = fread($fh, filesize($image_file));
00335                                         fclose($fh);
00336                                         $base64 = base64_encode($image_data);
00337                                         $imagetype = "image/jpeg";
00338                                         if (preg_match("/.*\.(png|gif)$/", $personal_picture, $matches))
00339                                         {
00340                                                 $imagetype = "image/".$matches[1];
00341                                         }
00342                                         return array (
00343                                                 "value" => $base64,
00344                                                 "encoding" => "Base64",
00345                                                 "imagetype" => $imagetype
00346                                         );
00347                                 }
00348                         }
00349                 }
00350                 return false;
00351         }
00352 
00353 }
00354 
00355 
00356 ?>

Generated on Fri Dec 13 2013 17:57:02 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1