33 include_once
'./webservice/soap/classes/class.ilSoapAdministration.php';
44 function login(
$client,$username,$password)
52 $_POST[
'username'] = $username;
53 $_POST[
'password'] = $password;
58 include_once
'./include/inc.header.php';
67 if($ilUser->hasToAcceptTermsOfService())
69 return $this->
__raiseError(
'User agreement not accepted',
'Server');
72 return (session_id().
'::'.
$client);
79 $this->sauth->setClient(
$client);
80 $this->sauth->setUsername($username);
81 $this->sauth->setPT($PT);
82 $authenticated =
true;
85 if(!$this->sauth->authenticate())
87 $authenticated =
false;
91 return $this->
__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
93 return $this->sauth->getSid().
'::'.
$client;
99 return $this->login(
$client, $username, $password);
107 if(!$this->__checkSession($sid))
132 if(!$this->__checkSession($sid))
137 if(!strlen($user_name))
139 return $this->
__raiseError(
'No username given. Aborting',
'Client');
144 if(strcasecmp($ilUser->getLogin(), $user_name) != 0 && !$rbacsystem->checkAccess(
'read',
USER_FOLDER_ID))
152 return $user_id ? $user_id :
"0";
161 if(!$this->__checkSession($sid))
170 return $this->
__raiseError(
'Check access failed.',
'Server');
173 if($ilUser->getLoginByUserId($user_id))
180 return $this->
__raiseError(
'User does not exist',
'Client');
186 function updateUser($sid,$user_data)
194 if(!$this->__checkSession($sid))
203 return $this->
__raiseError(
'Check access failed.',
'Server');
208 return $this->
__raiseError(
'User with id '.$user_data[
'usr_id'].
' does not exist.',
'Client');
219 if(strlen($user_data[
'passwd']) != 32)
229 $log->write(
'SOAP: updateUser()');
232 if($user_data[
'accepted_agreement'] && $user_obj->hasToAcceptTermsOfService())
234 $user_obj->writeAccepted();
248 if(!$this->__checkSession($sid))
257 return $this->
__raiseError(
'Check access failed.',
'Server');
262 return $this->
__raiseError(
'No valid user_id given.',
'Client');
265 $tmp_user->replacePassword($new_password);
273 function addUser($sid,$user_data,$global_role_id)
278 if(!$this->__checkSession($sid))
287 return $this->
__raiseError(
'Check access failed.',
'Server');
298 return $this->
__raiseError(
'No role id given',
'Client');
303 $global_roles = $rbacreview->getGlobalRoles();
305 if(!in_array($global_role_id,$global_roles))
307 return $this->
__raiseError(
'Role with id: '.$global_role_id.
' is not a valid global role',
'Client');
312 if(strlen($user_data[
'passwd']) != 32)
322 $ilLog->write(
'SOAP: addUser()');
328 if ($user_data[
"import_id"] !=
"")
330 $new_user->setImportId($user_data[
"import_id"]);
339 if($user_data[
'accepted_agreement'])
345 $rbacadmin->assignUser($global_role_id,
$new_user->getId());
348 $new_user->setLanguage($user_data[
'user_language']);
349 $new_user->setPref(
'style',$user_data[
'user_style']);
350 $new_user->setPref(
'skin',$user_data[
'user_skin']);
351 $new_user->setPref(
'hits_per_page',$ilSetting->get(
'hits_per_page'));
352 $new_user->setPref(
'show_users_online',$ilSetting->get(
'show_users_online'));
366 if(!$this->__checkSession($sid))
373 return $this->
__raiseError(
'No user_id given. Aborting',
'Client');
380 return $this->
__raiseError(
'Check access failed.',
'Server');
383 if(!$ilUser->getLoginByUserId($user_id))
385 return $this->
__raiseError(
'User id: '.$user_id.
' is not a valid identifier. Aborting',
'Client');
387 if($ilUser->getId() == $user_id)
389 return $this->
__raiseError(
'Cannot delete myself. Aborting',
'Client');
391 if($user_id == SYSTEM_USER_ID)
393 return $this->
__raiseError(
'Cannot delete root account. Aborting',
'Client');
396 $log->write(
'SOAP: deleteUser()');
398 $delete_user->delete();
413 include_once(
'./Services/Authentication/classes/class.ilAuthUtils.php');
419 if(!isset($user_data[
'login']))
423 if(!isset($user_data[
'passwd']) and !$allow_empty_password)
427 if(!isset($user_data[
'email']))
431 if(!isset($user_data[
'user_language']))
433 $user_data[
'user_language'] = $lng->getDefaultLanguage();
436 foreach($user_data as $field => $value)
457 if(!strlen($value) and $allow_empty_password)
474 case 'time_limit_unlimited':
477 if($user_data[
'time_limit_from'] >= $user_data[
'time_limit_until'])
484 case 'user_language':
485 $lang_inst = $lng->getInstalledLanguages();
487 if(!in_array($user_data[
'user_language'],$lang_inst))
489 $this->
__appendMessage(
'Language: '.$user_data[
'user_language'].
' is not installed');
496 if(($user_data[
'user_skin'] and !$user_data[
'user_style']) or
497 (!$user_data[
'user_skin'] and $user_data[
'user_style']))
501 elseif($user_data[
'user_skin'] and $user_data[
'user_style'])
504 $templates = $styleDefinition->getAllTemplates();
505 if (count($templates) > 0 && is_array($templates))
507 foreach($templates as $template)
510 $styleDef->startParsing();
511 $styles = $styleDef->getStyles();
512 foreach ($styles as $style)
514 if ($user_data[
'user_skin'] == $template[
"id"] &&
515 $user_data[
'user_style'] == $style[
"id"])
529 case 'time_limit_owner':
531 if($type !=
'cat' and $type !=
'usrf')
533 $this->
__appendMessage(
'time_limit_owner must be ref_id of category or user folder'.$type);
549 if(!$user_data[
'time_limit_from'] and
550 !$user_data[
'time_limit_until'] and
551 !$user_data[
'time_limit_unlimited'])
553 $user_data[
'time_limit_unlimited'] = 1;
555 if(!$user_data[
'time_limit_owner'])
562 $user_data[
'im_icq'] = $user_obj->getInstantMessengerId(
'icq');
563 $user_data[
'im_yahoo'] = $user_obj->getInstantMessengerId(
'yahoo');
564 $user_data[
'im_msn'] = $user_obj->getInstantMessengerId(
'msn');
565 $user_data[
'im_aim'] = $user_obj->getInstantMessengerId(
'aim');
566 $user_data[
'im_skype'] = $user_obj->getInstantMessengerId(
'skype');
567 $user_data[
'im_jabber'] = $user_obj->getInstantMessengerId(
'jabber');
568 $user_data[
'im_voip'] = $user_obj->getInstantMessengerId(
'voip');
570 $user_data[
'delicious'] = $user_obj->getDelicious();
571 $user_data[
'latitude'] = $user_obj->getLatitude();
572 $user_data[
'longitude'] = $user_obj->getLongitude();
573 $user_data[
'loc_zoom'] = $user_obj->getLocationZoom();
576 $user_data[
'auth_mode'] = $user_obj->getAuthMode();
577 $user_data[
'ext_account'] = $user_obj->getExternalAccount();
578 $user_obj->assignData($user_data);
580 if(isset($user_data[
'user_language']))
582 $user_obj->setLanguage($user_data[
'user_language']);
584 if(isset($user_data[
'user_skin']) and isset($user_data[
'user_style']))
586 $user_obj->setPref(
'skin',$user_data[
'user_skin']);
587 $user_obj->setPref(
'style',$user_data[
'user_style']);
594 $usr_data[
'usr_id'] = $usr_obj->getId();
595 $usr_data[
'login'] = $usr_obj->getLogin();
596 $usr_data[
'passwd'] = $usr_obj->getPasswd();
597 $usr_data[
'passwd_type'] = $usr_obj->getPasswdType();
598 $usr_data[
'firstname'] = $usr_obj->getFirstname();
599 $usr_data[
'lastname'] = $usr_obj->getLastname();
600 $usr_data[
'title'] = $usr_obj->getUTitle();
601 $usr_data[
'gender'] = $usr_obj->getGender();
602 $usr_data[
'email'] = $usr_obj->getEmail();
603 $usr_data[
'institution'] = $usr_obj->getInstitution();
604 $usr_data[
'street'] = $usr_obj->getStreet();
605 $usr_data[
'city'] = $usr_obj->getCity();
606 $usr_data[
'zipcode'] = $usr_obj->getZipcode();
607 $usr_data[
'country'] = $usr_obj->getCountry();
608 $usr_data[
'phone_office'] = $usr_obj->getPhoneOffice();
609 $usr_data[
'last_login'] = $usr_obj->getLastLogin();
610 $usr_data[
'last_update'] = $usr_obj->getLastUpdate();
611 $usr_data[
'create_date'] = $usr_obj->getCreateDate();
612 $usr_data[
'hobby'] = $usr_obj->getHobby();
613 $usr_data[
'department'] = $usr_obj->getDepartment();
614 $usr_data[
'phone_home'] = $usr_obj->getPhoneHome();
615 $usr_data[
'phone_mobile'] = $usr_obj->getPhoneMobile();
616 $usr_data[
'fax'] = $usr_obj->getFax();
617 $usr_data[
'time_limit_owner'] = $usr_obj->getTimeLimitOwner();
618 $usr_data[
'time_limit_unlimited'] = $usr_obj->getTimeLimitUnlimited();
619 $usr_data[
'time_limit_from'] = $usr_obj->getTimeLimitFrom();
620 $usr_data[
'time_limit_until'] = $usr_obj->getTimeLimitUntil();
621 $usr_data[
'time_limit_message'] = $usr_obj->getTimeLimitMessage();
622 $usr_data[
'referral_comment'] = $usr_obj->getComment();
623 $usr_data[
'matriculation'] = $usr_obj->getMatriculation();
624 $usr_data[
'active'] = $usr_obj->getActive();
625 $usr_data[
'approve_date'] = $usr_obj->getApproveDate();
626 $usr_data[
'user_skin'] = $usr_obj->getPref(
'skin');
627 $usr_data[
'user_style'] = $usr_obj->getPref(
'style');
628 $usr_data[
'user_language'] = $usr_obj->getLanguage();
629 $usr_data[
'auth_mode'] = $usr_obj->getAuthMode();
630 $usr_data[
'accepted_agreement'] = !$usr_obj->hasToAcceptTermsOfService();
631 $usr_data[
'import_id'] = $usr_obj->getImportId();
638 foreach($user_new as $key => $value)
640 $user_old[$key] = $value;
642 return $user_old ? $user_old : array();
651 function importUsers ($sid, $folder_id, $usr_xml, $conflict_rule, $send_account_mail)
656 if(!$this->__checkSession($sid))
662 include_once
'./Services/User/classes/class.ilUserImportParser.php';
663 include_once
'./Services/AccessControl/classes/class.ilObjRole.php';
664 include_once
'./Services/Object/classes/class.ilObjectFactory.php';
676 if (is_array($error))
678 foreach ($error as $err) {
679 $msg []=
"(".$err[
"line"].
",".$err[
"col"].
"): ".$err[
"errormessage"];
686 $msg = join(
"\n",$msg);
691 switch ($conflict_rule)
709 if ($folder_id == -1)
716 return $this->
__raiseError(
'Wrong reference id.',
'Server');
719 if ($import_folder->getType() !=
"usrf" && $import_folder->getType() !=
"cat")
720 return $this->
__raiseError(
'Folder must be a usr folder or a category.',
'Server');
723 if(!$rbacsystem->checkAccess(
'create_usr',$folder_id))
725 return $this->
__raiseError(
'Missing permission for creating users within '.$import_folder->getTitle(),
'Server');
734 $importParser->setXMLContent($usr_xml);
735 $importParser->startParsing();
737 switch ($importParser->getErrorLevel())
751 $importParser->setXMLContent($usr_xml);
753 $importParser->startParsing();
755 $roles = $importParser->getCollectedRoles();
762 $permitted_roles = array();
763 foreach ($roles as $role_id => $role)
765 if (!is_numeric ($role_id))
770 if (is_numeric($internalId))
772 $role_id = $internalId;
773 $role_name = $role_id;
785 $permitted_roles[$role_id] = $role_id;
790 return $this->
__raiseError(
"Could not find role ".$role_name.
". Either you use an invalid/deleted role ".
791 "or you try to assign a local role into the non-standard user folder and this role is not in its subtree.",
'Server');
795 $global_roles = $rbacreview->getGlobalRoles();
801 foreach ($permitted_roles as $role_id => $role_name)
805 if (in_array($role_id, $global_roles))
807 if ($role_id == SYSTEM_ROLE_ID && ! in_array(SYSTEM_ROLE_ID,$rbacreview->assignedRoles($ilUser->getId()))
811 return $this->
__raiseError($lng->txt(
"usrimport_with_specified_role_not_permitted").
" $role_name ($role_id)",
'Server');
816 $rolf = $rbacreview->getFoldersAssignedToRole($role_id,
true);
817 if ($rbacreview->isDeleted($rolf[0])
818 || ! $rbacsystem->checkAccess(
'write',$rolf[0]))
821 return $this->
__raiseError($lng->txt(
"usrimport_with_specified_role_not_permitted").
" $role_name ($role_id)",
"Server");
830 $importParser->setSendMail($send_account_mail);
832 $importParser->setFolderId($folder_id);
833 $importParser->setXMLContent($usr_xml);
835 $importParser->setRoleAssignment($permitted_roles);
837 $importParser->startParsing();
856 static $checked_roles = array();
857 static $global_roles = null;
860 if(isset($checked_roles[$a_role]))
862 return $checked_roles[$a_role];
867 $locations = $rbacreview->getFoldersAssignedToRole($a_role,
true);
873 $ilLog->write(__METHOD__.
': Check global role');
879 $ilLog->write(__METHOD__.
': '.$a_folder);
880 include_once
'./Services/AccessControl/classes/class.ilObjRole.php';
883 $ilLog->write(__METHOD__.
': No assignment allowed');
884 $checked_roles[$a_role] =
false;
889 if ($a_role == ANONYMOUS_ROLE_ID)
891 $ilLog->write(__METHOD__.
': Anonymous role chosen.');
892 $checked_roles[$a_role] =
false;
896 if($a_role == SYSTEM_ROLE_ID and !in_array(SYSTEM_ROLE_ID,$rbacreview->assignedRoles($ilUser->getId())))
898 $ilLog->write(__METHOD__.
': System role assignment forbidden.');
899 $checked_roles[$a_role] =
false;
904 $ilLog->write(__METHOD__.
': Assignment allowed.');
905 $checked_roles[$a_role] =
true;
910 $ilLog->write(__METHOD__.
': Check local role.');
913 $rolfs = $rbacreview->getFoldersAssignedToRole($a_role,
true);
921 if($rbacreview->isDeleted($rolf)
922 || !$rbacsystem->checkAccess(
'edit_permission',$rolf))
924 $ilLog->write(__METHOD__.
': Role deleted or no permission.');
925 $checked_roles[$a_role] =
false;
936 if($a_folder !=
USER_FOLDER_ID and $a_folder != 0 and !$tree->isGrandChild($a_folder,$rolf))
938 $ilLog->write(__METHOD__.
': Not in path of category.');
939 $checked_roles[$a_role] =
false;
942 $ilLog->write(__METHOD__.
': Assignment allowed.');
943 $checked_roles[$a_role] =
true;
957 if(!$this->__checkSession($sid))
962 global
$ilDB, $tree, $rbacreview, $rbacsystem;
972 switch ($object->getType()) {
982 $roles = $object->__getLocalRoles();
984 foreach($roles as $role_id)
986 $data = array_merge($rbacreview->assignedUsers($role_id, array()),$data);
992 $member_ids = $object->getGroupMemberIds();
996 $course_ref_id = $tree->checkForParentType(
$ref_id,
'crs');
999 return $this->
__raiseError(
"No course for session",
"Client");
1003 include_once
'Modules/Session/classes/class.ilEventParticipants.php';
1005 $member_ids = array_keys($event_part->getParticipants());
1010 if (is_array($data))
1012 include_once
'./Services/User/classes/class.ilUserXMLWriter.php';
1015 $xmlWriter->setObjects($data);
1016 $xmlWriter->setAttachRoles ($attachRoles);
1018 if($xmlWriter->start())
1020 return $xmlWriter->getXML();
1023 return $this->
__raiseError(
'Error in processing information. This is likely a bug.',
'Server');
1035 if(!$this->__checkSession($sid))
1040 include_once
'./Services/AccessControl/classes/class.ilObjRole.php';
1044 $global_roles = $rbacreview->getGlobalRoles();
1047 if (in_array($role_id, $global_roles))
1049 if ($role_id == SYSTEM_ROLE_ID && ! in_array(SYSTEM_ROLE_ID, $rbacreview->assignedRoles($ilUser->getId()))
1052 return $this->
__raiseError(
"Role access not permitted. ($role_id)",
"Server");
1057 $rolf = $rbacreview->getFoldersAssignedToRole($role_id,
true);
1058 if ($rbacreview->isDeleted($rolf[0])
1059 || ! $rbacsystem->checkAccess(
'write',$rolf[0]))
1061 return $this->
__raiseError(
"Role access not permitted. ($role_id)",
"Server");
1063 include_once(
'Services/PrivacySecurity/classes/class.ilPrivacySettings.php');
1065 if(!$rbacsystem->checkAccess(
'read',SYSTEM_USER_ID) and
1066 !$rbacsystem->checkAccess(
'export_member_data',$privacy->getPrivacySettingsRefId())) {
1067 return $this->
__raiseError(
"Export of local role members not permitted. ($role_id)",
"Server");
1074 include_once
'./Services/User/classes/class.ilUserXMLWriter.php';
1077 $xmlWriter->setAttachRoles($attachRoles);
1079 $xmlWriter->setObjects($data);
1081 if($xmlWriter->start())
1083 return $xmlWriter->getXML();
1085 return $this->
__raiseError(
'Error in getUsersForRole',
'Server');
1096 include_once
'./webservice/soap/classes/class.ilXMLResultSet.php';
1097 include_once
'./webservice/soap/classes/class.ilXMLResultSetWriter.php';
1100 $xmlResultSet->addColumn (
"userid");
1101 $xmlResultSet->addColumn (
"login");
1102 $xmlResultSet->addColumn (
"action");
1103 $xmlResultSet->addColumn (
"message");
1105 foreach ($a_array as $username =>
$messages)
1111 $xmlRow->setValue (0, 0);
1112 $xmlRow->setValue (1, $username);
1113 $xmlRow->setValue (2,
"");
1114 $xmlRow->setValue (3, $message);
1116 $xmlResultSet->addRow ($xmlRow);
1122 if ($xml_writer->start ())
1123 return $xml_writer->getXML();
1125 return $this->
__raiseError(
'Error in __getImportProtocolAsXML',
'Server');
1136 include_once
'./webservice/soap/classes/class.ilXMLResultSet.php';
1137 include_once
'./webservice/soap/classes/class.ilXMLResultSetWriter.php';
1140 $xmlResultSet->addColumn (
"userid");
1141 $xmlResultSet->addColumn (
"login");
1142 $xmlResultSet->addColumn (
"action");
1143 $xmlResultSet->addColumn (
"message");
1145 if (count($a_array))
1146 foreach ($a_array as $username => $message)
1149 $xmlRow->setValue (0, $username);
1150 $xmlRow->setValue (1, $message[
"login"]);
1151 $xmlRow->setValue (2, $message[
"action"]);
1152 $xmlRow->setValue (3, $message[
"message"]);
1154 $xmlResultSet->addRow ($xmlRow);
1159 if ($xml_writer->start ())
1160 return $xml_writer->getXML();
1162 return $this->
__raiseError(
'Error in __getUserMappingAsXML',
'Server');
1174 function searchUser ($sid, $a_keyfields, $query_operator, $a_keyvalues, $attach_roles, $active) {
1179 if(!$this->__checkSession($sid))
1184 global
$ilDB, $rbacsystem;
1188 return $this->
__raiseError(
'Check access failed.',
'Server');
1192 if (!count($a_keyfields))
1193 $this->
__raiseError(
'At least one keyfield is needed',
'Client');
1195 if (!count ($a_keyvalues))
1196 $this->
__raiseError(
'At least one keyvalue is needed',
'Client');
1198 if (!strcasecmp($query_operator,
"and")==0 || !strcasecmp($query_operator,
"or") == 0)
1199 $this->
__raiseError(
'Query operator must be either \'and\' or \'or\'',
'Client');
1204 $query =
"SELECT usr_data.*, usr_pref.value AS language
1207 ON usr_pref.usr_id = usr_data.usr_id AND usr_pref.keyword = ".
1208 $ilDB->quote(
"language",
"text").
1210 WHERE 1 = 1 ".$query;
1212 if (is_numeric($active) && $active > -1)
1213 $query .=
" AND active = ". $ilDB->quote($active);
1215 $query .=
" ORDER BY usr_data.lastname, usr_data.firstname ";
1219 $r = $ilDB->query(
$query);
1223 while(
$row = $ilDB->fetchAssoc($r))
1228 include_once
'./Services/User/classes/class.ilUserXMLWriter.php';
1231 $xmlWriter->setAttachRoles($attach_roles);
1233 $xmlWriter->setObjects($data);
1235 if($xmlWriter->start())
1237 return $xmlWriter->getXML();
1239 return $this->
__raiseError(
'Error in searchUser',
'Server');
1254 $allowed_fields = array (
"firstname",
"lastname",
"email",
"login",
"matriculation",
"institution",
"department",
"title",
"ext_account");
1256 foreach ($a_keyfields as $keyfield)
1258 $keyfield = strtolower($keyfield);
1260 if (!in_array($keyfield, $allowed_fields))
1263 $field_query = array ();
1264 foreach ($a_keyvalues as $keyvalue)
1266 if (strlen($keyvalue) >= 3) {
1267 $field_query []= $keyfield.
" like '%".$keyvalue.
"%'";
1271 if (count($field_query))
1272 $query [] = join(
" ".strtoupper($queryOperator).
" ", $field_query);
1276 return count (
$query) ?
" AND ((". join(
") OR (",
$query) .
"))" :
"AND 0";
1292 if(!$this->__checkSession($sid))
1301 if(is_array($a_user_ids) and count($a_user_ids) == 1)
1303 if(end($a_user_ids) == $ilUser->getId())
1308 elseif(is_numeric($a_user_ids))
1310 if($a_user_ids == $ilUser->getId())
1316 if(!$rbacsystem->checkAccess(
'read',
USER_FOLDER_ID) and !$is_self)
1318 return $this->
__raiseError(
'Check access failed.',
'Server');
1325 include_once
'./Services/User/classes/class.ilUserXMLWriter.php';
1327 $xmlWriter->setAttachRoles($attach_roles);
1328 $xmlWriter->setObjects($data);
1330 if($xmlWriter->start())
1332 return $xmlWriter->getXML();
1335 return $this->
__raiseError(
'User does not exist',
'Client');
1345 if(!$this->__checkSession($sid))
1352 include_once
'Services/Mail/classes/class.ilMailGlobalServices.php';
1368 if(!$this->__checkSession($sid))
1375 $parts = explode(
'::', $sid);
1376 $query =
"SELECT usr_id FROM usr_session "
1377 .
"INNER JOIN usr_data ON usr_id = user_id WHERE session_id = %s";
1378 $res = $ilDB->queryF(
$query, array(
'text'), array($parts[0]));
1379 $data = $ilDB->fetchAssoc(
$res);
1381 if(!(
int)$data[
'usr_id'])
1386 return (
int)$data[
'usr_id'];