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

Generated on Fri Dec 13 2013 10:18:34 for ILIAS Release_3_5_x_branch .rev 46805 by  doxygen 1.7.1