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

ilinc/classes/class.ilObjiLincUser.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2006 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 
00036 class ilObjiLincUser
00037 {
00043         function ilObjiLincUser(&$a_user_obj,$a_from_ilinc = 'false')
00044         {
00045                 global $ilias,$lng;
00046 
00047                 $this->ilias =& $ilias;
00048                 $this->lng =& $lng;
00049                 $this->user =& $a_user_obj;
00050                 
00051                 $this->__init($a_from_ilinc);
00052         }
00053         
00054         function __init(&$a_from_ilinc)
00055         {
00056                 global $ilErr, $ilDB;
00057                 
00058                 $q = "SELECT ilinc_id,ilinc_login,ilinc_passwd FROM usr_data ".
00059                          "WHERE usr_data.usr_id = ".$ilDB->quote($this->user->getId());
00060                 $r = $ilDB->query($q);
00061                 
00062                 if ($r->numRows() > 0)
00063                 {
00064                         $data = $r->fetchRow(DB_FETCHMODE_ASSOC);
00065                         
00066                         $this->id = $data['ilinc_id'];
00067                         $this->login = $data['ilinc_login'];
00068                         $this->passwd = $data['ilinc_passwd'];
00069                 }
00070                 else
00071                 {
00072                         $ilErr->raiseError("<b>Error: There is no dataset with id ".
00073                                                            $this->id."!</b><br />class: ".get_class($this)."<br />Script: ".__FILE__.
00074                                                            "<br />Line: ".__LINE__, $ilErr->FATAL);
00075                 }
00076         }
00077         
00082         function update()
00083         {
00084                 global $ilDB;
00085 
00086                 $q = "UPDATE usr_data SET ".
00087             "last_update=now(), ".
00088             "ilinc_id = ".$ilDB->quote(ilUtil::prepareDBString($this->id)).", ".
00089             "ilinc_login = ".$ilDB->quote(ilUtil::prepareDBString($this->login)).", ".
00090             "ilinc_passwd = ".$ilDB->quote(ilUtil::prepareDBString($this->passwd))." ".
00091             "WHERE usr_id = ".$ilDB->quote($this->user->getId());
00092 
00093                 $ilDB->query($q);
00094                 
00095                 return true;
00096         }
00097         
00098         function syncILIAS2iLinc()
00099         {
00100                 // for future use
00101         }
00102         
00103         function synciLinc2ILIAS()
00104         {
00105                 // for future use
00106         }
00107         
00108         function getErrorMsg()
00109         {
00110                 $err_msg = $this->error_msg;
00111                 $this->error_msg = "";
00112 
00113                 return $err_msg;
00114         }
00115         
00123         function __createLoginData($a_user_id,$a_user_login,$a_inst_id)
00124         {
00125                 if (!$a_inst_id)
00126                 {
00127                         $a_inst_id = "0";
00128                 }
00129                 
00130                 $chars = preg_split('//', substr($a_user_login,0,3), -1, PREG_SPLIT_NO_EMPTY);
00131                 //$chars = str_split(substr($a_user_login,0,3)); // PHP5 only
00132                 
00133                 // convert non-allowed chars in login to <underscore>
00134                 // not allowed: ~!@#$%^&*()`-=+[]{};:'\|/?<>,
00135                 $result = preg_replace('@[^a-zA-Z0-9_]@','_',$chars);
00136         
00137                 $data["login"] = $result."_".$a_user_id."_".$a_inst_id."_".time();
00138                 $data["passwd"] = md5(microtime().$a_user_login.rand(10000, 32000));
00139 
00140                 $this->id = '';
00141                 $this->login = $data['login'];
00142                 $this->passwd = $data['passwd'];
00143                 
00144                 return $data;
00145         }
00146         
00147         // create user account on iLinc server
00148         function add()
00149         {
00150                 include_once ('class.ilnetucateXMLAPI.php');
00151 
00152                 $this->ilincAPI = new ilnetucateXMLAPI();
00153 
00154                 // create login and passwd for iLinc account
00155                 $login_data = $this->__createLoginData($this->user->getId(),$this->user->getLogin(),$this->ilias->getSetting($inst_id));
00156                 
00157                 //$this->ilincAPI->addUser($login_data,$this->user);
00158                 $this->ilincAPI->addUser($this);
00159                 $response = $this->ilincAPI->sendRequest();
00160 
00161                 if ($response->isError())
00162                 {
00163                         if (!$response->getErrorMsg())
00164                         {
00165                                 $this->error_msg = "err_add_user";
00166                         }
00167                         else
00168                         {
00169                                 $this->error_msg = $response->getErrorMsg();
00170                         }
00171                         
00172                         return false;
00173                 }
00174                 
00175                 $this->id = $response->getFirstID();
00176                 $this->login = $login_data["login"];
00177                 $this->passwd = $login_data["passwd"];
00178 
00179                 $this->update();
00180                 
00181                 return true;
00182         }
00183         
00184         // edit user account on iLinc server
00185         function edit()
00186         {
00187                 include_once ('class.ilnetucateXMLAPI.php');
00188 
00189                 $this->ilincAPI = new ilnetucateXMLAPI();
00190 
00191                 //$this->ilincAPI->addUser($login_data,$this->user);
00192                 $this->ilincAPI->editUser($this);
00193                 $response = $this->ilincAPI->sendRequest();
00194 
00195                 if ($response->isError())
00196                 {
00197                         if (!$response->getErrorMsg())
00198                         {
00199                                 $this->error_msg = "err_edit_user";
00200                         }
00201                         else
00202                         {
00203                                 $this->error_msg = $response->getErrorMsg();
00204                         }
00205                         
00206                         return false;
00207                 }
00208                 
00209                 return true;
00210         }
00211         
00225         function find($a_id = '',$a_login = '', $a_fullname = '')
00226         {
00227                 include_once ('class.ilnetucateXMLAPI.php');
00228 
00229                 $this->ilincAPI = new ilnetucateXMLAPI();
00230 
00231                 $this->ilincAPI->findUser($a_id,$a_login,$a_fullname);
00232                 $response = $this->ilincAPI->sendRequest();
00233 
00234                 if ($response->isError())
00235                 {
00236                         if (!$response->getErrorMsg())
00237                         {
00238                                 $this->error_msg = "err_find_user";
00239                         }
00240                         else
00241                         {
00242                                 $this->error_msg = $response->getErrorMsg();
00243                         }
00244                         
00245                         return false;
00246                 }
00247                 
00248                 return $response->data;
00249         }
00250         
00251         function setVar($a_varname, $a_value)
00252         {
00253                 $this->$a_varname = $a_value;
00254         }
00255 } // END class.ilObjiLincUser
00256 ?>

Generated on Fri Dec 13 2013 13:52:11 for ILIAS Release_3_7_x_branch .rev 46817 by  doxygen 1.7.1