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

Generated on Fri Dec 13 2013 17:56:49 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1