/**
  * returns wether a key from db is exportable or not
  *
  * @param string $key
  * @return boolean
  */
 public static function isPrefExportable($key)
 {
     return in_array($key, ilUserXMLWriter::getExportablePreferences());
 }
 function createXMLExport(&$settings, &$data, $filename)
 {
     include_once './Services/User/classes/class.ilUserDefinedData.php';
     include_once './Services/User/classes/class.ilObjUser.php';
     global $rbacreview;
     global $ilDB;
     global $log;
     $file = fopen($filename, "w");
     if (is_array($data)) {
         include_once './Services/User/classes/class.ilUserXMLWriter.php';
         $xmlWriter = new ilUserXMLWriter();
         $xmlWriter->setObjects($data);
         $xmlWriter->setSettings($settings);
         $xmlWriter->setAttachRoles(true);
         if ($xmlWriter->start()) {
             fwrite($file, $xmlWriter->getXML());
         }
     }
 }
 private function verifyPref($key, $value)
 {
     switch ($key) {
         case 'mail_linebreak':
         case 'hits_per_page':
             if (!is_numeric($value) || $value < 0) {
                 $this->logFailure("---", "Wrong value '{$value}': Positiv numeric value expected for preference {$key}.");
             }
             break;
         case 'language':
         case 'skin':
         case 'style':
         case 'ilPageEditor_HTMLMode':
         case 'ilPageEditor_JavaScript':
         case 'ilPageEditor_MediaMode':
         case 'tst_javascript':
         case 'tst_lastquestiontype':
         case 'tst_multiline_answers':
         case 'tst_use_previous_answers':
         case 'graphicalAnswerSetting':
         case 'priv_feed_pass':
             $this->logFailure("---", "Preference {$key} is not supported.");
             break;
         case 'public_city':
         case 'public_country':
         case 'public_department':
         case 'public_email':
         case 'public_fax':
         case 'public_hobby':
         case 'public_institution':
         case 'public_matriculation':
         case 'public_phone':
         case 'public_phone_home':
         case 'public_phone_mobile':
         case 'public_phone_office':
         case 'public_street':
         case 'public_upload':
         case 'public_zip':
         case 'send_info_mails':
         case 'hide_own_online_status':
             if (!in_array($value, array('y', 'n'))) {
                 $this->logFailure("---", "Wrong value '{$value}': Value 'y' or 'n' expected for preference {$key}.");
             }
             break;
         case 'public_profile':
             if (!in_array($value, array('y', 'n', 'g'))) {
                 $this->logFailure("---", "Wrong value '{$value}': Value 'y', 'g' or 'n' expected for preference {$key}.");
             }
             break;
         case 'show_users_online':
             if (!in_array($value, array('y', 'n', 'associated'))) {
                 $this->logFailure("---", "Wrong value '{$value}': Value 'y' or 'n' or 'associated' expected for preference {$key}.");
             }
             break;
         case 'mail_incoming_type':
             if (!in_array((int) $value, array("0", "1", "2"))) {
                 $this->logFailure("---", "Wrong value '{$value}': Value \"0\" (LOCAL),\"1\" (EMAIL) or \"2\" (BOTH) expected for preference {$key}.");
             }
             break;
         case 'weekstart':
             if (!in_array($value, array("0", "1"))) {
                 $this->logFailure("---", "Wrong value '{$value}': Value \"0\" (Sunday) or \"1\" (Monday) expected for preference {$key}.");
             }
             break;
         case 'mail_signature':
             break;
         case 'user_tz':
             include_once 'Services/Calendar/classes/class.ilTimeZone.php';
             try {
                 $tz = ilTimeZone::_getInstance($value);
                 return true;
             } catch (ilTimeZoneException $tze) {
                 $this->logFailure("---", "Wrong value '{$value}': Invalid timezone {$value} detected for preference {$key}.");
             }
             break;
         default:
             if (!ilUserXMLWriter::isPrefExportable($key)) {
                 $this->logFailure("---", "Preference {$key} is not supported.");
             }
             break;
     }
 }
 /**
  *	return user xmls for given user ids (csv separated ids) as xml based on usr dtd.
  *	@param string sid	session id
  *	@param string a_userids array of user ids, may be numeric or ilias ids
  *	@param boolean attachRoles	if true, role assignments will be attached, nothing will be done otherwise
  *	@return	string	xml string based on usr dtd
  */
 function getUserXML($sid, $a_user_ids, $attach_roles)
 {
     $this->initAuth($sid);
     $this->initIlias();
     if (!$this->__checkSession($sid)) {
         return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
     }
     global $rbacsystem, $ilUser, $ilDB;
     // check if own account
     $is_self = false;
     if (is_array($a_user_ids) and count($a_user_ids) == 1) {
         if (end($a_user_ids) == $ilUser->getId()) {
             $is_self = true;
         }
     } elseif (is_numeric($a_user_ids)) {
         if ($a_user_ids == $ilUser->getId()) {
             $is_self = true;
         }
     }
     if (!$rbacsystem->checkAccess('read', USER_FOLDER_ID) and !$is_self) {
         return $this->__raiseError('Check access failed.', 'Server');
     }
     // begin-patch filemanager
     $data = ilObjUser::_getUserData((array) $a_user_ids);
     // end-patch filemanager
     include_once './Services/User/classes/class.ilUserXMLWriter.php';
     $xmlWriter = new ilUserXMLWriter();
     $xmlWriter->setAttachRoles($attach_roles);
     $xmlWriter->setObjects($data);
     if ($xmlWriter->start()) {
         return $xmlWriter->getXML();
     }
     return $this->__raiseError('User does not exist', 'Client');
 }
 /**
  * get client information from current as xml result set
  *
  * @param string $sid  current session id
  *
  * @return XMLResultSet containing columns installation_id, installation_version, installation_url, installation_description, installation_default_language
  */
 function getNIC($sid)
 {
     $this->initAuth($sid);
     $this->initIlias();
     if (!$this->__checkSession($sid)) {
         return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
     }
     global $rbacsystem, $rbacreview, $ilLog, $rbacadmin, $ilSetting, $ilClientIniFile;
     if (!is_object($ilClientIniFile)) {
         return $this->__raiseError("Client ini is not initialized", "Server");
     }
     $auth_modes = ilAuthUtils::_getActiveAuthModes();
     $auth_mode_default = strtoupper(ilAuthUtils::_getAuthModeName(array_shift($auth_modes)));
     $auth_mode_names = array();
     foreach ($auth_modes as $mode) {
         $auth_mode_names[] = strtoupper(ilAuthUtils::_getAuthModeName($mode));
     }
     include_once 'Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php';
     include_once 'Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordXMLWriter.php';
     // create advanced meta data record xml
     $record_ids = array();
     $record_types = ilAdvancedMDRecord::_getAssignableObjectTypes();
     foreach ($record_types as $type) {
         $records = ilAdvancedMDRecord::_getActivatedRecordsByObjectType($type);
         foreach ($records as $record) {
             $record_ids[] = $record->getRecordId();
         }
     }
     $record_ids = array_unique($record_ids);
     $advmwriter = new ilAdvancedMDRecordXMLWriter($record_ids);
     $advmwriter->write();
     // create user defined fields record xml, simulate empty user records
     include_once "./Services/User/classes/class.ilUserXMLWriter.php";
     $udfWriter = new ilUserXMLWriter();
     $users = array();
     $udfWriter->setObjects($users);
     $udfWriter->start();
     // todo: get information from client id, read from ini file specificied
     $client_details[] = array("installation_id" => IL_INST_ID, "installation_version" => ILIAS_VERSION, "installation_url" => ILIAS_HTTP_PATH, "installation_description" => $ilClientIniFile->readVariable("client", "description"), "installation_language_default" => $ilClientIniFile->readVariable("language", "default"), "installation_session_expire" => $ilClientIniFile->readVariable("session", "expire"), "installation_php_postmaxsize" => $this->return_bytes(ini_get("post_max_size")), "authentication_methods" => join(",", $auth_mode_names), "authentication_default_method" => $auth_mode_default, "installation_udf_xml" => $udfWriter->getXML(), "installation_advmd_xml" => $advmwriter->xmlDumpMem(false));
     // store into xml result set
     include_once './webservice/soap/classes/class.ilXMLResultSet.php';
     $xmlResult = new ilXMLResultSet();
     $xmlResult->addArray($client_details, true);
     // create writer and return xml
     include_once './webservice/soap/classes/class.ilXMLResultSetWriter.php';
     $xmlResultWriter = new ilXMLResultSetWriter($xmlResult);
     $xmlResultWriter->start();
     return $xmlResultWriter->getXML();
 }
 function createXMLExport(&$settings, &$data, $filename)
 {
     include_once './Services/User/classes/class.ilUserDefinedData.php';
     include_once './Services/User/classes/class.ilObjUser.php';
     global $rbacreview;
     global $ilDB;
     global $log;
     $file = fopen($filename, "w");
     if (is_array($data)) {
         include_once './Services/User/classes/class.ilUserXMLWriter.php';
         $xmlWriter = new ilUserXMLWriter();
         $xmlWriter->setObjects($data);
         $xmlWriter->setSettings($settings);
         $xmlWriter->setAttachRoles(true);
         if ($xmlWriter->start()) {
             fwrite($file, $xmlWriter->getXML());
         }
     }
     /*
     		fwrite($file, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
     		fwrite($file, "<!DOCTYPE Users SYSTEM \"".ILIAS_HTTP_PATH."/xml/ilias_user_3_8.dtd\">\n");
     		fwrite($file, "<Users>");
     		foreach ($data as $row)
     		{
     //$log->write(date("[y-m-d H:i:s] ")."User data export: processing user " . $row["login"]);
     foreach ($row as $key => $value)
     {
     	$row[$key] = $this->escapeXML($value);
     }
     $userline = "";
     // TODO: Define combobox for "Action" ???
     if (strlen($row["language"]) == 0) $row["language"] = "en";
     $userline .= "<User Id=\"il_".IL_INST_ID."_usr_".$row["usr_id"]."\" Language=\"".$row["language"]."\" Action=\"Insert\">";
     if (array_search("login", $settings) !== FALSE)
     {
     	$userline .= "<Login>".$row["login"]."</Login>";
     }
     // Alternative way to get the roles of a user?
     $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",
     	$ilDB->quote($row["usr_id"])
     );
     $rbacresult = $ilDB->query($query);
     while ($rbacrow = $rbacresult->fetchRow(DB_FETCHMODE_ASSOC))
     {
     	$type = "";
     	if ($rbacrow["assign"] == "y")
     	{
     		if ($rbacrow["parent"] == ROLE_FOLDER_ID)
     		{
     			$type = "Global";
     		}
     		else
     		{
     			$type = "Local";
     		}
     		if (strlen($type))
     		{
     			$userline .= "<Role Id=\"il_".IL_INST_ID."_role_".$rbacrow["rol_id"]."\" Type=\"".$type."\">".$rbacrow["title"]."</Role>";
     		}
     	}
     }
     //$log->write(date("[y-m-d H:i:s] ")."User data export: get all roles");
     /* the export of roles is to expensive. on a system with 6000 users the following
        section needs 37 seconds
     
     $roles = $rbacreview->getRolesByFilter(1, $row["usr_id"]);
     $ass_roles = $rbacreview->assignedRoles($row["usr_id"]);
     foreach ($roles as $role)
     {
     	if (array_search($role["obj_id"], $ass_roles) !== FALSE)
     	{
     		$type = "";
     		switch ($role["role_type"])
     		{
     			case "global":
     				$type = "Global";
     				break;
     			case "local":
     				$type = "Local";
     				break;
     		}
     		if (strlen($type))
     		{
     			$userline .= "<Role Id=\"".$role["obj_id"]."\" Type=\"".$type."\">".$role["title"]."</Role>";
     		}
     	}
     }
     */
     /*			//$log->write(date("[y-m-d H:i:s] ")."User data export: got all roles");
     			$i2passwd = FALSE;
     			if (array_search("i2passwd", $settings) !== FALSE)
     			{
     				if (strlen($row["i2passwd"])) $i2passwd = TRUE;
     				if ($i2passwd) $userline .= "<Password Type=\"ILIAS2\">".$row["i2passwd"]."</Password>";
     			}
     			if ((!$i2passwd) && (array_search("passwd", $settings) !== FALSE))
     			{
     				if (strlen($row["passwd"])) $userline .= "<Password Type=\"ILIAS3\">".$row["passwd"]."</Password>";
     			}
     			if (array_search("firstname", $settings) !== FALSE)
     			{
     				if (strlen($row["firstname"])) $userline .= "<Firstname>".$row["firstname"]."</Firstname>";
     			}
     			if (array_search("lastname", $settings) !== FALSE)
     			{
     				if (strlen($row["lastname"])) $userline .= "<Lastname>".$row["lastname"]."</Lastname>";
     			}
     			if (array_search("title", $settings) !== FALSE)
     			{
     				if (strlen($row["title"])) $userline .= "<Title>".$row["title"]."</Title>";
     			}
     			if (array_search("upload", $settings) !== FALSE)
     			{
     				// personal picture
     				$q = sprintf("SELECT value FROM usr_pref WHERE usr_id=%s AND keyword='profile_image'", $ilDB->quote($row["usr_id"] . ""));
     				$r = $ilDB->query($q);
     				if ($r->numRows() == 1)
     				{
     					$personal_picture_data = $r->fetchRow(DB_FETCHMODE_ASSOC);
     					$personal_picture = $personal_picture_data["value"];
     					$webspace_dir = ilUtil::getWebspaceDir();
     					$image_file = $webspace_dir."/usr_images/".$personal_picture;
     					if (@is_file($image_file))
     					{
     						$fh = fopen($image_file, "rb");
     						if ($fh)
     						{
     							$image_data = fread($fh, filesize($image_file));
     							fclose($fh);
     							$base64 = base64_encode($image_data);
     							$imagetype = "image/jpeg";
     							if (preg_match("/.*\.(png|gif)$/", $personal_picture, $matches))
     							{
     								$imagetype = "image/".$matches[1];
     							}
     							$userline .= "<PersonalPicture imagetype=\"$imagetype\" encoding=\"Base64\">$base64</PersonalPicture>";
     						}
     					}
     				}
     			}
     			if (array_search("gender", $settings) !== FALSE)
     			{
     				if (strlen($row["gender"])) $userline .= "<Gender>".$row["gender"]."</Gender>";
     			}
     			if (array_search("email", $settings) !== FALSE)
     			{
     				if (strlen($row["email"])) $userline .= "<Email>".$row["email"]."</Email>";
     			}
     			if (array_search("institution", $settings) !== FALSE)
     			{
     				if (strlen($row["institution"])) $userline .= "<Institution>".$row["institution"]."</Institution>";
     			}
     			if (array_search("street", $settings) !== FALSE)
     			{
     				if (strlen($row["street"])) $userline .= "<Street>".$row["street"]."</Street>";
     			}
     			if (array_search("city", $settings) !== FALSE)
     			{
     				if (strlen($row["city"])) $userline .= "<City>".$row["city"]."</City>";
     			}
     			if (array_search("zipcode", $settings) !== FALSE)
     			{
     				if (strlen($row["zipcode"])) $userline .= "<PostalCode>".$row["zipcode"]."</PostalCode>";
     			}
     			if (array_search("country", $settings) !== FALSE)
     			{
     				if (strlen($row["country"])) $userline .= "<Country>".$row["country"]."</Country>";
     			}
     			if (array_search("phone_office", $settings) !== FALSE)
     			{
     				if (strlen($row["phone_office"])) $userline .= "<PhoneOffice>".$row["phone_office"]."</PhoneOffice>";
     			}
     			if (array_search("phone_home", $settings) !== FALSE)
     			{
     				if (strlen($row["phone_home"])) $userline .= "<PhoneHome>".$row["phone_home"]."</PhoneHome>";
     			}
     			if (array_search("phone_mobile", $settings) !== FALSE)
     			{
     				if (strlen($row["phone_mobile"])) $userline .= "<PhoneMobile>".$row["phone_mobile"]."</PhoneMobile>";
     			}
     			if (array_search("fax", $settings) !== FALSE)
     			{
     				if (strlen($row["fax"])) $userline .= "<Fax>".$row["fax"]."</Fax>";
     			}
     			if (strlen($row["hobby"])) if (array_search("hobby", $settings) !== FALSE)
     			{
     				$userline .= "<Hobby>".$row["hobby"]."</Hobby>";
     			}
     			if (array_search("department", $settings) !== FALSE)
     			{
     				if (strlen($row["department"])) $userline .= "<Department>".$row["department"]."</Department>";
     			}
     			if (array_search("referral_comment", $settings) !== FALSE)
     			{
     				if (strlen($row["referral_comment"])) $userline .= "<Comment>".$row["referral_comment"]."</Comment>";
     			}
     			if (array_search("matriculation", $settings) !== FALSE)
     			{
     				if (strlen($row["matriculation"])) $userline .= "<Matriculation>".$row["matriculation"]."</Matriculation>";
     			}
     			if (array_search("active", $settings) !== FALSE)
     			{
     				if ($row["active"])
     				{
     					$userline .= "<Active>true</Active>";
     				}
     				else
     				{
     					$userline .= "<Active>false</Active>";
     				}
     			}
     			if (array_search("client_ip", $settings) !== FALSE)
     			{
     				if (strlen($row["client_ip"])) $userline .= "<ClientIP>".$row["client_ip"]."</ClientIP>";
     			}
     			if (array_search("time_limit_owner", $settings) !== FALSE)
     			{
     				if (strlen($row["time_limit_owner"])) $userline .= "<TimeLimitOwner>".$row["time_limit_owner"]."</TimeLimitOwner>";
     			}
     			if (array_search("time_limit_unlimited", $settings) !== FALSE)
     			{
     				if (strlen($row["time_limit_unlimited"])) $userline .= "<TimeLimitUnlimited>".$row["time_limit_unlimited"]."</TimeLimitUnlimited>";
     			}
     			if (array_search("time_limit_from", $settings) !== FALSE)
     			{
     				if (strlen($row["time_limit_from"])) $userline .= "<TimeLimitFrom>".$row["time_limit_from"]."</TimeLimitFrom>";
     			}
     			if (array_search("time_limit_until", $settings) !== FALSE)
     			{
     				if (strlen($row["time_limit_until"])) $userline .= "<TimeLimitUntil>".$row["time_limit_until"]."</TimeLimitUntil>";
     			}
     			if (array_search("time_limit_message", $settings) !== FALSE)
     			{
     				if (strlen($row["time_limit_message"])) $userline .= "<TimeLimitMessage>".$row["time_limit_message"]."</TimeLimitMessage>";
     			}
     			if (array_search("approve_date", $settings) !== FALSE)
     			{
     				if (strlen($row["approve_date"])) $userline .= "<ApproveDate>".$row["approve_date"]."</ApproveDate>";
     			}
     			if (array_search("agree_date", $settings) !== FALSE)
     			{
     				if (strlen($row["agree_date"])) $userline .= "<AgreeDate>".$row["agree_date"]."</AgreeDate>";
     			}
     			if ((int) $row["ilinc_id"] !=0) {
     					if (array_search("ilinc_id", $settings) !== FALSE)
     					{
     						if (strlen($row["ilinc_id"])) $userline .= "<iLincID>".$row["ilinc_id"]."</iLincID>";
     					}
     					if (array_search("ilinc_login", $settings) !== FALSE)
     					{
     						if (strlen($row["ilinc_login"])) $userline .= "<iLincLogin>".$row["ilinc_login"]."</iLincLogin>";
     					}
     					if (array_search("ilinc_passwd", $settings) !== FALSE)
     					{
     						if (strlen($row["ilinc_passwd"])) $userline .= "<iLincPasswd>".$row["ilinc_passwd"]."</iLincPasswd>";
     					}
     			}
     			if (array_search("auth_mode", $settings) !== FALSE)
     			{
     				if (strlen($row["auth_mode"])) $userline .= "<AuthMode type=\"".$row["auth_mode"]."\"></AuthMode>";
     			}
     			if (array_search("skin_style", $settings) !== FALSE)
     			{
     				$userline .=
     					"<Look Skin=\"" . ilObjUser::_lookupPref($row["usr_id"], "skin") . "\" " .
     					"Style=\"" . ilObjUser::_lookupPref($row["usr_id"], "style") . "\"></Look>";
     			}
     
     			if (array_search("last_update", $settings) !== FALSE)
     			{
     				if (strlen($row["last_update"])) $userline .= "<LastUpdate>".$row["last_update"]."</LastUpdate>";
     			}
     
     			if (array_search("last_login", $settings) !== FALSE)
     			{
     				if (strlen($row["last_login"])) $userline .= "<LastLogin>".$row["last_login"]."</LastLogin>";
     			}
     
     			// Append User defined field data
     			$udf_data = new ilUserDefinedData($row['usr_id']);
     			$userline .= $udf_data->toXML();
     
     			$userline .= "</User>";
     			fwrite($file, $userline);
     		}
     		fwrite($file, "</Users>");
     		fclose($file);*/
 }