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

webservice/soap/classes/class.ilSoapUserAdministration.php

Go to the documentation of this file.
00001 <?php
00002   /*
00003    +-----------------------------------------------------------------------------+
00004    | ILIAS open source                                                           |
00005    +-----------------------------------------------------------------------------+
00006    | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007    |                                                                             |
00008    | This program is free software; you can redistribute it and/or               |
00009    | modify it under the terms of the GNU General Public License                 |
00010    | as published by the Free Software Foundation; either version 2              |
00011    | of the License, or (at your option) any later version.                      |
00012    |                                                                             |
00013    | This program is distributed in the hope that it will be useful,             |
00014    | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015    | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016    | GNU General Public License for more details.                                |
00017    |                                                                             |
00018    | You should have received a copy of the GNU General Public License           |
00019    | along with this program; if not, write to the Free Software                 |
00020    | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021    +-----------------------------------------------------------------------------+
00022   */
00023 
00024 
00033 include_once './webservice/soap/classes/class.ilSoapAdministration.php';
00034 
00035 class ilSoapUserAdministration extends ilSoapAdministration
00036 {
00037         function ilSoapUserAdministration()
00038         {
00039                 parent::ilSoapAdministration();
00040         }
00041                 
00042 
00043         // Service methods
00044         function login($client,$username,$password)
00045         {
00046                 $this->__initAuthenticationObject();
00047 
00048                 $this->sauth->setClient($client);
00049                 $this->sauth->setUsername($username);
00050                 $this->sauth->setPassword($password);
00051 
00052                 if(!$this->sauth->authenticate())
00053                 {
00054                         return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
00055                 }
00056                 return $this->sauth->getSid().'::'.$client;
00057         }
00058 
00059         function logout($sid)
00060         {
00061                 if(!$this->__checkSession($sid))
00062                 {
00063                         return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
00064                 }                       
00065 
00066                 if(!$this->sauth->logout())
00067                 {
00068                         return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
00069                 }
00070                 
00071                 return true;
00072         }
00073         
00074         function lookupUser($sid,$user_name)
00075         {
00076                 if(!$this->__checkSession($sid))
00077                 {
00078                         return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
00079                 }                       
00080 
00081                 if(!strlen($user_name))
00082                 {
00083                         return $this->__raiseError('No username given. Aborting','Client');
00084                 }
00085 
00086                 // Include main header
00087                 include_once './include/inc.header.php';
00088 
00089                 if(!$rbacsystem->checkAccess('read',USER_FOLDER_ID))
00090                 {
00091                         return $this->__raiseError('Check access failed.'.USER_FOLDER_ID,'Server');
00092                 }
00093 
00094                 $user_id = ilObjUser::getUserIdByLogin($user_name);
00095                 return $user_id ? $user_id : "0";
00096 
00097         }
00098 
00099         function getUser($sid,$user_id)
00100         {
00101                 if(!$this->__checkSession($sid))
00102                 {
00103                         return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
00104                 }                       
00105                 
00106                 // Include main header
00107                 include_once './include/inc.header.php';
00108 
00109                 if(!$rbacsystem->checkAccess('read',USER_FOLDER_ID))
00110                 {
00111                         return $this->__raiseError('Check access failed.','Server');
00112                 }
00113 
00114                 global $ilUser;
00115 
00116                 if($ilUser->getLoginByUserId($user_id))
00117                 {
00118                         $tmp_user =& ilObjectFactory::getInstanceByObjId($user_id);
00119                         $usr_data = $this->__readUserData($tmp_user);
00120 
00121                         return $usr_data;
00122                 }
00123                 return $this->__raiseError('User does not exist','Client');
00124         }               
00125 
00126         function updateUser($sid,$user_data)
00127         {
00128                 if(!$this->__checkSession($sid))
00129                 {
00130                         return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
00131                 }                       
00132 
00133                 // Include main header
00134                 include_once './include/inc.header.php';
00135 
00136                 if(!$rbacsystem->checkAccess('write',USER_FOLDER_ID))
00137                 {
00138                         return $this->__raiseError('Check access failed.','Server');
00139                 }
00140 
00141                 global $ilUser;
00142 
00143                 if(!$user_obj =& ilObjectFactory::getInstanceByObjId($user_data['usr_id'],false))
00144                 {
00145                         return $this->__raiseError('User with id '.$user_data['usr_id'].' does not exist.','Client');
00146                 }
00147 
00148                 $user_old = $this->__readUserData($user_obj);
00149                 $user_new = $this->__substituteUserData($user_old,$user_data);
00150 
00151                 if(!$this->__validateUserData($user_data,false))
00152                 {
00153                         return $this->__raiseError($this->__getMessage(),'Client');
00154                 }
00155 
00156                 if(strlen($user_data['passwd']) != 32)
00157                 {
00158                         $user_new['passwd_type'] = IL_PASSWD_PLAIN;
00159                 }
00160                 else
00161                 {
00162                         $user_new['passwd_type'] = IL_PASSWD_MD5;
00163                 }
00164                 $this->__setUserData($user_obj,$user_new);
00165 
00166                 $log->write('SOAP: updateUser()');
00167                 $user_obj->update();
00168 
00169                 if($user_data['accepted_agreement'] and !$user_obj->hasAcceptedUserAgreement())
00170                 {
00171                         $user_obj->writeAccepted();
00172                 }
00173 
00174                 return true;
00175         }
00176 
00177         function updatePassword($sid,$user_id,$new_password)
00178         {
00179                 if(!$this->__checkSession($sid))
00180                 {
00181                         return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
00182                 }
00183 
00184                 // Include main header
00185                 include_once './include/inc.header.php';
00186 
00187                 if(!$rbacsystem->checkAccess('write',USER_FOLDER_ID))
00188                 {
00189                         return $this->__raiseError('Check access failed.','Server');
00190                 }
00191 
00192                 if(!$tmp_user =& ilObjectFactory::getInstanceByObjId($user_id,false))
00193                 {
00194                         return $this->__raiseError('No valid user_id given.','Client');
00195                 }
00196 
00197                 $tmp_user->replacePassword($new_password);
00198 
00199                 return true;
00200         }
00201 
00202         function addUser($sid,$user_data,$global_role_id)
00203         {
00204                 if(!$this->__checkSession($sid))
00205                 {
00206                         return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
00207                 }                       
00208 
00209                 // Include main header
00210                 include_once './include/inc.header.php';
00211 
00212                 if(!$rbacsystem->checkAccess('create_user',USER_FOLDER_ID))
00213                 {
00214                         return $this->__raiseError('Check access failed.','Server');
00215                 }
00216 
00217                 // Validate user_data
00218                 if(!$this->__validateUserData($user_data))
00219                 {
00220                         return $this->__raiseError($this->__getMessage(),'Client');
00221                 }
00222                 // Validate global role
00223                 if(!$global_role_id)
00224                 {
00225                         return $this->__raiseError('No role id given','Client');
00226                 }
00227 
00228                 // Validate global role
00229                 global $rbacreview;
00230                 
00231                 $global_roles = $rbacreview->getGlobalRoles();
00232 
00233                 if(!in_array($global_role_id,$global_roles))
00234                 {
00235                         return $this->__raiseError('Role with id: '.$global_role_id.' is not a valid global role','Client');
00236                 }
00237 
00238                 $new_user =& new ilObjUser();
00239 
00240                 $user_data['passwd_type'] =  IL_PASSWD_PLAIN;
00241                 $this->__setUserData($new_user,$user_data);
00242 
00243 
00244                 $log->write('SOAP: addUser()');
00245 
00246                 // Need this for entry in object_data
00247                 $new_user->setTitle($new_user->getFullname());
00248                 $new_user->setDescription($new_user->getEmail());
00249                 
00250                 if ($user_data["import_id"] != "")
00251                 {
00252                         $new_user->setImportId($user_data["import_id"]);
00253                 }
00254 
00255                 $new_user->create();
00256                 
00257 
00258                 $new_user->saveAsNew();
00259 
00260                 // If agreement is given. Set user agreement accepted.
00261                 if($user_data['accepted_agreement'])
00262                 {
00263                         $new_user->writeAccepted();
00264                 }
00265 
00266                 // Assign role
00267                 $rbacadmin->assignUser($global_role_id,$new_user->getId());
00268 
00269                 // Assign user prefs
00270                 $new_user->setLanguage($user_data['user_language']);
00271                 $new_user->setPref('style',$user_data['user_style']);
00272                 $new_user->setPref('skin',$user_data['user_skin']);
00273                 $new_user->writePrefs();
00274 
00275                 return $new_user->getId();
00276         }
00277 
00278         function deleteUser($sid,$user_id)
00279         {
00280                 if(!$this->__checkSession($sid))
00281                 {
00282                         return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
00283                 }                       
00284                 
00285                 if(!isset($user_id))
00286                 {
00287                         return $this->__raiseError('No user_id given. Aborting','Client');
00288                 }
00289 
00290                 // Include main header
00291                 include_once './include/inc.header.php';
00292 
00293                 if(!$rbacsystem->checkAccess('delete',USER_FOLDER_ID))
00294                 {
00295                         return $this->__raiseError('Check access failed.','Server');
00296                 }
00297 
00298                 global $ilUser;
00299 
00300                 if(!$ilUser->getLoginByUserId($user_id))
00301                 {
00302                         return $this->__raiseError('User id: '.$user_id.' is not a valid identifier. Aborting','Client');
00303                 }
00304                 if($ilUser->getId() == $user_id)
00305                 {
00306                         return $this->__raiseError('Cannot delete myself. Aborting','Client');
00307                 }
00308                 if($user_id == SYSTEM_USER_ID)
00309                 {
00310                         return $this->__raiseError('Cannot delete root account. Aborting','Client');
00311                 }
00312                 // Delete him
00313                 $log->write('SOAP: deleteUser()');
00314                 $delete_user =& ilObjectFactory::getInstanceByObjId($user_id,false);
00315                 $delete_user->delete();
00316 
00317                 return true;
00318         }
00319 
00320 
00321                 
00322                 
00323         // PRIVATE
00324         function __validateUserData(&$user_data,$check_complete = true)
00325         {
00326                 global $lng,$styleDefinition;
00327 
00328                 $this->__setMessage('');
00329                 
00330                 if($check_complete)
00331                 {
00332                         if(!isset($user_data['login']))
00333                         {
00334                                 $this->__appendMessage('No login given.');
00335                         }
00336                         if(!isset($user_data['passwd']))
00337                         {
00338                                 $this->__appendMessage('No password given.');
00339                         }
00340                         if(!isset($user_data['email']))
00341                         {
00342                                 $this->__appendMessage('No email given');
00343                         }
00344                         if(!isset($user_data['user_language']))
00345                         {
00346                                 $user_data['user_language'] = 'en';
00347                         }
00348                 }
00349                 foreach($user_data as $field => $value)
00350                 {
00351                         switch($field)
00352                         {
00353                                 case 'login':
00354                                         if (!ilUtil::isLogin($value))
00355                                         {
00356                                                 $this->__appendMessage('Login invalid.');
00357                                         }
00358 
00359                                         // check loginname
00360                                         if($check_complete)
00361                                         {
00362                                                 if (loginExists($value))
00363                                                 {
00364                                                         $this->__appendMessage('Login already exists.');
00365                                                 }
00366                                         }
00367                                         break;
00368 
00369                                 case 'passwd':
00370                                         if (!ilUtil::isPassword($value))
00371                                         {
00372                                                 $this->__appendMessage('Password invalid.');
00373                                         }
00374                                         break;
00375 
00376                                 case 'email':
00377                                         if(!ilUtil::is_email($value))
00378                                         {
00379                                                 $this->__appendMessage('Email invalid.');
00380                                         }
00381                                         break;
00382 
00383                                 case 'time_limit_unlimited':
00384                                         if($value != 1)
00385                                         {
00386                                                 if($user_data['time_limit_from'] >= $user_data['time_limit_until'])
00387                                                 {
00388                                                         $this->__appendMessage('Time limit invalid');
00389                                                 }
00390                                         }
00391                                         break;
00392 
00393                                 case 'user_language':
00394                                         $lang_inst = $lng->getInstalledLanguages();
00395 
00396                                         if(!in_array($user_data['user_language'],$lang_inst))
00397                                         {
00398                                                 $this->__appendMessage('Language: '.$user_data['user_language'].' is not installed');
00399                                         }
00400                                         break;
00401 
00402 
00403                                 case 'user_skin':
00404                                 case 'user_style':
00405                                         if(($user_data['user_skin'] and !$user_data['user_style']) or
00406                                            (!$user_data['user_skin'] and $user_data['user_style']))
00407                                         {
00408                                                 $this->__appendMessage('user_skin, user_style not valid.');
00409                                         }
00410                                         elseif($user_data['user_skin'] and $user_data['user_style'])
00411                                         {
00412                                                 $ok = false;
00413                                                 foreach($styleDefinition->getAllTemplates() as $template)
00414                                                 {
00415                                                         $styleDef =& new ilStyleDefinition($template["id"]);
00416                                                         $styleDef->startParsing();
00417                                                         $styles = $styleDef->getStyles();
00418                                                         foreach ($styles as $style)
00419                                                         {
00420                                                                 if ($user_data['user_skin'] == $template["id"] &&
00421                                                                         $user_data['user_style'] == $style["id"])
00422                                                                 {
00423                                                                         $ok = true;
00424                                                                 }
00425                                                         }
00426                                                 }
00427                                                 if(!$ok)
00428                                                 {
00429                                                         $this->__appendMessage('user_skin, user_style not valid.');
00430                                                 }
00431                                         }
00432                                         break;
00433 
00434                                 case 'time_limit_owner':
00435                                         $type = ilObject::_lookupType($user_data['time_limit_owner'],true);
00436                                         if($type != 'cat' and $type != 'usrf')
00437                                         {
00438                                                 $this->__appendMessage('time_limit_owner must be ref_id of category or user folder'.$type);
00439                                         }
00440                                         break;
00441 
00442                                         
00443 
00444                                 default:
00445                                         continue;
00446                         }
00447                 }
00448                 return strlen($this->__getMessage()) ? false : true;
00449         }
00450 
00451         function __setUserData(&$user_obj,&$user_data)
00452         {
00453                 // Default to unlimited if no access period is given
00454                 if(!$user_data['time_limit_from'] and 
00455                    !$user_data['time_limit_until'] and
00456                    !$user_data['time_limit_unlimited'])
00457                 {
00458                         $user_data['time_limit_unlimited'] = 1;
00459                 }
00460                 if(!$user_data['time_limit_owner'])
00461                 {
00462                         $user_data['time_limit_owner'] = USER_FOLDER_ID;
00463                 }
00464 
00465                 $user_obj->assignData($user_data);
00466 
00467                 if(isset($user_data['user_language']))
00468                 {
00469                         $user_obj->setLanguage($user_data['user_language']);
00470                 }
00471                 if(isset($user_data['user_skin']) and isset($user_data['user_style']))
00472                 {
00473                         $user_obj->setPref('skin',$user_data['user_skin']);
00474                         $user_obj->setPref('style',$user_data['user_style']);
00475                 }
00476                 return true;
00477         }
00478         
00479         function __readUserData(&$usr_obj)
00480         {
00481                 $usr_data['usr_id'] = $usr_obj->getId();
00482                 $usr_data['login'] = $usr_obj->getLogin();
00483                 $usr_data['passwd'] = $usr_obj->getPasswd();
00484                 $usr_data['passwd_type'] = $usr_obj->getPasswdType();
00485                 $usr_data['firstname'] = $usr_obj->getFirstname();
00486                 $usr_data['lastname'] = $usr_obj->getLastname();
00487                 $usr_data['title'] = $usr_obj->getUTitle();
00488                 $usr_data['gender'] = $usr_obj->getGender();
00489                 $usr_data['email'] = $usr_obj->getEmail();
00490                 $usr_data['institution'] = $usr_obj->getInstitution();
00491                 $usr_data['street'] = $usr_obj->getStreet();
00492                 $usr_data['city'] = $usr_obj->getCity();
00493                 $usr_data['zipcode'] = $usr_obj->getZipcode();
00494                 $usr_data['country'] = $usr_obj->getCountry();
00495                 $usr_data['phone_office'] = $usr_obj->getPhoneOffice();
00496                 $usr_data['last_login'] = $usr_obj->getLastLogin();
00497                 $usr_data['last_update'] = $usr_obj->getLastUpdate();
00498                 $usr_data['create_date'] = $usr_obj->getCreateDate();
00499                 $usr_data['hobby'] = $usr_obj->getHobby();
00500                 $usr_data['department'] = $usr_obj->getDepartment();
00501                 $usr_data['phone_home'] = $usr_obj->getPhoneHome();
00502                 $usr_data['phone_mobile'] = $usr_obj->getPhoneMobile();
00503                 $usr_data['fax'] = $usr_obj->getFax();
00504                 $usr_data['time_limit_owner'] = $usr_obj->getTimeLimitOwner();
00505                 $usr_data['time_limit_unlimited'] = $usr_obj->getTimeLimitUnlimited();
00506                 $usr_data['time_limit_from'] = $usr_obj->getTimeLimitFrom();
00507                 $usr_data['time_limit_until'] = $usr_obj->getTimeLimitUntil();
00508                 $usr_data['time_limit_message'] = $usr_obj->getTimeLimitMessage();
00509                 $usr_data['referral_commment'] = $usr_obj->getComment();
00510                 $usr_data['matriculation'] = $usr_obj->getMatriculation();
00511                 $usr_data['active'] = $usr_obj->getActive();
00512                 $usr_data['approve_date'] = $usr_obj->getApproveDate();
00513                 $usr_data['user_skin'] = $usr_obj->getPref('skin');
00514                 $usr_data['user_style'] = $usr_obj->getPref('style');
00515                 $usr_data['user_language'] = $usr_obj->getLanguage();
00516 
00517                 $usr_data['accepted_agreement'] = $usr_obj->hasAcceptedUserAgreement();
00518                 
00519                 return $usr_data;
00520         }
00521 
00522         function __substituteUserData($user_old,$user_new)
00523         {
00524                 foreach($user_new as $key => $value)
00525                 {
00526                         $user_old[$key] = $value;
00527                 }
00528                 return $user_old ? $user_old : array();
00529         }
00530 }
00531 ?>

Generated on Fri Dec 13 2013 11:58:04 for ILIAS Release_3_6_x_branch .rev 46809 by  doxygen 1.7.1