• 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/lib/nusoap.php';
00034 
00035 // These functions are wrappers for nusoap, since it cannot register methods inside classes
00036 function login($client,$username,$password)
00037 {
00038         $sua =& new ilSoapUserAdministration();
00039         
00040         return $sua->login($client,$username,$password);
00041 }
00042 
00043 function logout($sid)
00044 {
00045         $sua =& new ilSoapUserAdministration();
00046 
00047         return $sua->logout($sid);
00048 }
00049 function lookupUser($sid,$user_name)
00050 {
00051         $sua =& new ilSoapUserAdministration();
00052 
00053         return $sua->lookupUser($sid,$user_name);
00054 }
00055 
00056 function getUser($sid,$user_id)
00057 {
00058         $sua =& new ilSoapUserAdministration();
00059 
00060         return $sua->getUser($sid,$user_id);
00061 }
00062 
00063 function updateUser($sid,$user_data)
00064 {
00065         $sua =& new ilSoapUserAdministration();
00066 
00067         return $sua->updateUser($sid,$user_data);
00068 }
00069 function addUser($sid,$user_data,$global_role_id)
00070 {
00071         $sua =& new ilSoapUserAdministration();
00072 
00073         return $sua->addUser($sid,$user_data,$global_role_id);
00074 }
00075 function deleteUser($sid,$user_id)
00076 {
00077         $sua =& new ilSoapUserAdministration();
00078 
00079         return $sua->deleteUser($sid,$user_id);
00080 }
00081 
00082 class ilSoapUserAdministration
00083 {
00084         /*
00085          * object which handles php's authentication
00086          * @var object
00087          */
00088         var $sauth = null;
00089 
00090         /*
00091          * Defines type of error handling (PHP5 || NUSOAP)
00092          * @var object
00093          */
00094         var $error_method = null;
00095 
00096 
00097         function ilSoapUserAdministration($use_nusoap = true)
00098         {
00099                 define('USER_FOLDER_ID',7);
00100                 define('NUSOAP',1);
00101                 define('PHP5',2);
00102 
00103                 if($use_nusoap)
00104                 {
00105                         $this->error_method = NUSOAP;
00106                 }
00107         }
00108                 
00109 
00110         // Service methods
00111         function login($client,$username,$password)
00112         {
00113                 $this->__initAuthenticationObject();
00114 
00115                 $this->sauth->setClient($client);
00116                 $this->sauth->setUsername($username);
00117                 $this->sauth->setPassword($password);
00118 
00119                 if(!$this->sauth->authenticate())
00120                 {
00121                         return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
00122                 }
00123                 return $this->sauth->getSid().'::'.$client;
00124         }
00125 
00126         function logout($sid)
00127         {
00128                 list($sid,$client) = $this->__explodeSid($sid);
00129 
00130                 $this->__initAuthenticationObject();
00131 
00132                 $this->sauth->setClient($client);
00133                 $this->sauth->setSid($sid);
00134 
00135 
00136                 if(!$this->sauth->logout())
00137                 {
00138                         return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
00139                 }
00140                 
00141                 return true;
00142         }
00143         
00144         function lookupUser($sid,$user_name)
00145         {
00146                 list($sid,$client) = $this->__explodeSid($sid);
00147 
00148                 $this->__initAuthenticationObject();
00149 
00150                 $this->sauth->setClient($client);
00151                 $this->sauth->setSid($sid);
00152 
00153                 if(!$this->sauth->validateSession())
00154                 {
00155                         return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
00156                 }                       
00157 
00158                 if(!strlen($user_name))
00159                 {
00160                         return $this->__raiseError('No username given. Aborting','Client');
00161                 }
00162 
00163                 // Include main header
00164                 include_once './include/inc.header.php';
00165 
00166                 if(!$rbacsystem->checkAccess('read',USER_FOLDER_ID))
00167                 {
00168                         return $this->__raiseError('Check access failed.'.USER_FOLDER_ID,'Server');
00169                 }
00170 
00171                 return (int) ilObjUser::getUserIdByLogin($user_name);
00172         }
00173 
00174         function getUser($sid,$user_id)
00175         {
00176                 list($sid,$client) = $this->__explodeSid($sid);
00177 
00178                 $this->__initAuthenticationObject();
00179 
00180                 $this->sauth->setClient($client);
00181                 $this->sauth->setSid($sid);
00182 
00183                 if(!$this->sauth->validateSession())
00184                 {
00185                         return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
00186                 }                       
00187                 
00188                 // Include main header
00189                 include_once './include/inc.header.php';
00190 
00191                 if(!$rbacsystem->checkAccess('read',USER_FOLDER_ID))
00192                 {
00193                         return $this->__raiseError('Check access failed.','Server');
00194                 }
00195 
00196                 global $ilUser;
00197 
00198                 if($ilUser->getLoginByUserId($user_id))
00199                 {
00200                         $tmp_user =& ilObjectFactory::getInstanceByObjId($user_id);
00201                         $usr_data = $this->__readUserData($tmp_user);
00202 
00203                         return $usr_data;
00204                 }
00205                 return $this->__raiseError('User does not exist','Client');
00206         }               
00207 
00208         function updateUser($sid,$user_data)
00209         {
00210                 list($sid,$client) = $this->__explodeSid($sid);
00211 
00212 
00213                 $this->__initAuthenticationObject();
00214 
00215                 $this->sauth->setClient($client);
00216                 $this->sauth->setSid($sid);
00217 
00218                 if(!$this->sauth->validateSession())
00219                 {
00220                         return $this->__raiseError($this->sauth->getMessage(),$this->sauth->getMessageCode());
00221                 }                       
00222                 
00223                 // Include main header
00224                 include_once './include/inc.header.php';
00225 
00226                 if(!$rbacsystem->checkAccess('write',USER_FOLDER_ID))
00227                 {
00228                         return $this->__raiseError('Check access failed.','Server');
00229                 }
00230 
00231                 global $ilUser;
00232 
00233                 if(!$user_obj =& ilObjectFactory::getInstanceByObjId($user_data['usr_id'],false))
00234                 {
00235                         return $this->__raiseError('User with id '.$user_data['usr_id'].' does not exist.','Client');
00236                 }
00237 
00238                 $user_old = $this->__readUserData($user_obj);
00239                 $user_new = $this->__substituteUserData($user_old,$user_data);
00240 
00241                 if(!$this->__validateUserData($user_data,false))
00242                 {
00243                         return $this->__raiseError($this->__getMessage(),'Client');
00244                 }
00245                 $this->__setUserData($user_obj,$user_new);
00246 
00247                 $log->write('SOAP: updateUser()');
00248                 $user_obj->update();
00249 
00250                 return true;
00251         }               
00252 
00253 
00254         function addUser($sid,$user_data,$global_role_id)
00255         {
00256                 list($sid,$client) = $this->__explodeSid($sid);
00257 
00258                 $this->__initAuthenticationObject();
00259 
00260                 $this->sauth->setClient($client);
00261                 $this->sauth->setSid($sid);
00262                 if(!$this->sauth->validateSession())
00263                 {
00264                         return $this->__raiseError($this->sauth->getMessage(),'Client');
00265                 }
00266 
00267                 // Include main header
00268                 include_once './include/inc.header.php';
00269 
00270                 if(!$rbacsystem->checkAccess('create_user',USER_FOLDER_ID))
00271                 {
00272                         return $this->__raiseError('Check access failed.','Server');
00273                 }
00274 
00275                 // Validate user_data
00276                 if(!$this->__validateUserData($user_data))
00277                 {
00278                         return $this->__raiseError($this->__getMessage(),'Client');
00279                 }
00280                 // Validate global role
00281                 if(!$global_role_id)
00282                 {
00283                         return $this->__raiseError('No role id given','Client');
00284                 }
00285 
00286                 // Validate global role
00287                 global $rbacreview;
00288                 
00289                 $global_roles = $rbacreview->getGlobalRoles();
00290 
00291                 if(!in_array($global_role_id,$global_roles))
00292                 {
00293                         return $this->__raiseError('Role with id: '.$global_role_id.' is not a valid global role','Client');
00294                 }
00295 
00296                 $new_user =& new ilObjUser();
00297                 $this->__setUserData($new_user,$user_data);
00298 
00299 
00300                 $log->write('SOAP: addUser()');
00301                 $new_user->create();
00302                 $new_user->saveAsNew();
00303 
00304                 // Assign role
00305                 $rbacadmin->assignUser($global_role_id,$new_user->getId());
00306 
00307                 // Assign user prefs
00308                 $new_user->setLanguage($user_data['user_language']);
00309                 $new_user->setPref('style',$user_data['style']);
00310                 $new_user->setPref('skin',$user_data['skin']);
00311                 $new_user->writePrefs();
00312 
00313                 return $new_user->getId();
00314         }
00315 
00316         function deleteUser($sid,$user_id)
00317         {
00318                 list($sid,$client) = $this->__explodeSid($sid);
00319 
00320                 $this->__initAuthenticationObject();
00321 
00322                 $this->sauth->setClient($client);
00323                 $this->sauth->setSid($sid);
00324                 if(!$this->sauth->validateSession())
00325                 {
00326                         return $this->__raiseError($this->sauth->getMessage(),'Client');
00327                 }
00328                 
00329                 if(!isset($user_id))
00330                 {
00331                         return $this->__raiseError('No user_id given. Aborting','Client');
00332                 }
00333 
00334                 // Include main header
00335                 include_once './include/inc.header.php';
00336 
00337                 if(!$rbacsystem->checkAccess('delete',USER_FOLDER_ID))
00338                 {
00339                         return $this->__raiseError('Check access failed.','Server');
00340                 }
00341 
00342                 global $ilUser;
00343 
00344                 if(!$ilUser->getLoginByUserId($user_id))
00345                 {
00346                         return $this->__raiseError('User id: '.$user_id.' is not a valid identifier. Aborting','Client');
00347                 }
00348                 if($ilUser->getId() == $user_id)
00349                 {
00350                         return $this->__raiseError('Cannot delete myself. Aborting','Client');
00351                 }
00352                 if($user_id == SYSTEM_USER_ID)
00353                 {
00354                         return $this->__raiseError('Cannot delete root account. Aborting','Client');
00355                 }
00356                 // Delete him
00357                 $log->write('SOAP: deleteUser()');
00358                 $delete_user =& ilObjectFactory::getInstanceByObjId($user_id,false);
00359                 $delete_user->delete();
00360 
00361                 return true;
00362         }
00363                 
00364                 
00365         // PRIVATE
00366         function __explodeSid($sid)
00367         {
00368                 $exploded = explode('::',$sid);
00369 
00370                 return is_array($exploded) ? $exploded : array('sid' => '','client' => '');
00371         }
00372 
00373 
00374         function __setMessage($a_str)
00375         {
00376                 $this->message = $a_str;
00377         }
00378         function __getMessage()
00379         {
00380                 return $this->message;
00381         }
00382         function __appendMessage($a_str)
00383         {
00384                 $this->message .= isset($this->message) ? ' ' : '';
00385                 $this->message .= $a_str;
00386         }
00387 
00388         function __validateUserData(&$user_data,$check_complete = true)
00389         {
00390                 global $lng,$styleDefinition;
00391 
00392                 $this->__setMessage('');
00393                 
00394                 if($check_complete)
00395                 {
00396                         if(!isset($user_data['login']))
00397                         {
00398                                 $this->__appendMessage('No login given.');
00399                         }
00400                         if(!isset($user_data['passwd']))
00401                         {
00402                                 $this->__appendMessage('No password given.');
00403                         }
00404                         if(!isset($user_data['email']))
00405                         {
00406                                 $this->__appendMessage('No email given');
00407                         }
00408                         if(!isset($user_data['user_language']))
00409                         {
00410                                 $user_data['user_language'] = 'en';
00411                         }
00412                 }
00413                 foreach($user_data as $field => $value)
00414                 {
00415                         switch($field)
00416                         {
00417                                 case 'login':
00418                                         if (!ilUtil::isLogin($value))
00419                                         {
00420                                                 $this->__appendMessage('Login invalid.');
00421                                         }
00422 
00423                                         // check loginname
00424                                         if($check_complete)
00425                                         {
00426                                                 if (loginExists($value))
00427                                                 {
00428                                                         $this->__appendMessage('Login already exists.');
00429                                                 }
00430                                         }
00431                                         break;
00432 
00433                                 case 'passwd':
00434                                         if (!ilUtil::isPassword($value))
00435                                         {
00436                                                 $this->__appendMessage('Password invalid.');
00437                                         }
00438                                         break;
00439 
00440                                 case 'email':
00441                                         if(!ilUtil::is_email($value))
00442                                         {
00443                                                 $this->__appendMessage('Email invalid.');
00444                                         }
00445                                         break;
00446 
00447                                 case 'time_limit_unlimited':
00448                                         if($value != 1)
00449                                         {
00450                                                 if($user_data['time_limit_from'] >= $user_data['time_limit_until'])
00451                                                 {
00452                                                         $this->__appendMessage('Time limit invalid');
00453                                                 }
00454                                         }
00455                                         break;
00456 
00457                                 case 'user_language':
00458                                         $lang_inst = $lng->getInstalledLanguages();
00459 
00460                                         if(!in_array($user_data['user_language'],$lang_inst))
00461                                         {
00462                                                 $this->__appendMessage('Language: '.$user_data['user_language'].' is not installed');
00463                                         }
00464                                         break;
00465 
00466 
00467                                 case 'user_skin':
00468                                 case 'user_style':
00469                                         if(($user_data['user_skin'] and !$user_data['user_style']) or
00470                                            (!$user_data['user_skin'] and $user_data['user_style']))
00471                                         {
00472                                                 $this->__appendMessage('user_skin, user_style not valid.');
00473                                         }
00474                                         elseif($user_data['user_skin'] and $user_data['user_style'])
00475                                         {
00476                                                 $ok = false;
00477                                                 foreach($styleDefinition->getAllTemplates() as $template)
00478                                                 {
00479                                                         $styleDef =& new ilStyleDefinition($template["id"]);
00480                                                         $styleDef->startParsing();
00481                                                         $styles = $styleDef->getStyles();
00482                                                         foreach ($styles as $style)
00483                                                         {
00484                                                                 if ($user_data['user_skin'] == $template["id"] &&
00485                                                                         $user_data['user_style'] == $style["id"])
00486                                                                 {
00487                                                                         $ok = true;
00488                                                                 }
00489                                                         }
00490                                                 }
00491                                                 if(!$ok)
00492                                                 {
00493                                                         $this->__appendMessage('user_skin, user_style not valid.');
00494                                                 }
00495                                         }
00496                                         break;
00497 
00498                                 case 'time_limit_owner':
00499                                         $type = ilObject::_lookupType($user_data['time_limit_owner'],true);
00500                                         if($type != 'cat' and $type != 'usrf')
00501                                         {
00502                                                 $this->__appendMessage('time_limit_owner must be ref_id of category or user folder'.$type);
00503                                         }
00504                                         break;
00505 
00506                                         
00507 
00508                                 default:
00509                                         continue;
00510                         }
00511                 }
00512                 return strlen($this->__getMessage()) ? false : true;
00513         }
00514 
00515         function __setUserData(&$user_obj,&$user_data)
00516         {
00517                 // Default to unlimited if no access period is given
00518                 if(!$user_data['time_limit_from'] and 
00519                    !$user_data['time_limit_until'] and
00520                    !$user_data['time_limit_unlimited'])
00521                 {
00522                         $user_data['time_limit_unlimited'] = 1;
00523                 }
00524                 if(!$user_data['time_limit_owner'])
00525                 {
00526                         $user_data['time_limit_owner'] = USER_FOLDER_ID;
00527                 }
00528 
00529                 $user_obj->assignData($user_data);
00530 
00531                 if(isset($user_data['user_language']))
00532                 {
00533                         $user_obj->setLanguage($user_data['user_language']);
00534                 }
00535                 if(isset($user_data['user_skin']) and isset($user_data['user_style']))
00536                 {
00537                         $user_obj->setPref('skin',$user_data['skin']);
00538                         $user_obj->setPref('style',$user_data['style']);
00539                 }
00540                 return true;
00541         }
00542 
00543 
00544 
00545         function __initAuthenticationObject()
00546         {
00547                 include_once './webservice/soap/classes/class.ilSoapAuthentication.php';
00548                 
00549                 return $this->sauth = new ilSoapAuthentication();
00550         }
00551                 
00552 
00553         function __raiseError($a_message,$a_code)
00554         {
00555                 switch($this->error_method)
00556                 {
00557                         case NUSOAP:
00558 
00559                                 return new soap_fault($a_code,'',$a_message);
00560                 }
00561         }
00562 
00563         
00564         function __readUserData(&$usr_obj)
00565         {
00566                 $usr_data['usr_id'] = $usr_obj->getId();
00567                 $usr_data['login'] = $usr_obj->getLogin();
00568                 $usr_data['passwd'] = $usr_obj->getPasswd();
00569                 $usr_data['firstname'] = $usr_obj->getFirstname();
00570                 $usr_data['lastname'] = $usr_obj->getLastname();
00571                 $usr_data['title'] = $usr_obj->getUTitle();
00572                 $usr_data['gender'] = $usr_obj->getGender();
00573                 $usr_data['email'] = $usr_obj->getEmail();
00574                 $usr_data['institution'] = $usr_obj->getInstitution();
00575                 $usr_data['street'] = $usr_obj->getStreet();
00576                 $usr_data['city'] = $usr_obj->getCity();
00577                 $usr_data['zipcode'] = $usr_obj->getZipcode();
00578                 $usr_data['country'] = $usr_obj->getCountry();
00579                 $usr_data['phone_office'] = $usr_obj->getPhoneOffice();
00580                 $usr_data['last_login'] = $usr_obj->getLastLogin();
00581                 $usr_data['last_update'] = $usr_obj->getLastUpdate();
00582                 $usr_data['create_date'] = $usr_obj->getCreateDate();
00583                 $usr_data['hobby'] = $usr_obj->getHobby();
00584                 $usr_data['department'] = $usr_obj->getDepartment();
00585                 $usr_data['phone_home'] = $usr_obj->getPhoneHome();
00586                 $usr_data['phone_mobile'] = $usr_obj->getPhoneMobile();
00587                 $usr_data['fax'] = $usr_obj->getFax();
00588                 $usr_data['time_limit_owner'] = $usr_obj->getTimeLimitOwner();
00589                 $usr_data['time_limit_unlimited'] = $usr_obj->getTimeLimitUnlimited();
00590                 $usr_data['time_limit_from'] = $usr_obj->getTimeLimitFrom();
00591                 $usr_data['time_limit_until'] = $usr_obj->getTimeLimitUntil();
00592                 $usr_data['time_limit_message'] = $usr_obj->getTimeLimitMessage();
00593                 $usr_data['referral_commment'] = $usr_obj->getComment();
00594                 $usr_data['matriculation'] = $usr_obj->getMatriculation();
00595                 $usr_data['active'] = $usr_obj->getActive();
00596                 $usr_data['approve_date'] = $usr_obj->getApproveDate();
00597                 $usr_data['user_skin'] = $usr_obj->getPref('skin');
00598                 $usr_data['user_style'] = $usr_obj->getPref('style');
00599                 $usr_data['user_language'] = $usr_obj->getLanguage();
00600                 
00601                 return $usr_data;
00602         }
00603 
00604         function __substituteUserData($user_old,$user_new)
00605         {
00606                 foreach($user_new as $key => $value)
00607                 {
00608                         $user_old[$key] = $value;
00609                 }
00610                 return $user_old ? $user_old : array();
00611         }
00612 }
00613 ?>

Generated on Fri Dec 13 2013 08:00:20 for ILIAS Release_3_3_x_branch .rev 46803 by  doxygen 1.7.1