Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
00101 }
00102
00103 function synciLinc2ILIAS()
00104 {
00105
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
00132
00133
00134
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
00148 function add()
00149 {
00150 include_once ('class.ilnetucateXMLAPI.php');
00151
00152 $this->ilincAPI = new ilnetucateXMLAPI();
00153
00154
00155 $login_data = $this->__createLoginData($this->user->getId(),$this->user->getLogin(),$this->ilias->getSetting($inst_id));
00156
00157
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
00185 function edit()
00186 {
00187 include_once ('class.ilnetucateXMLAPI.php');
00188
00189 $this->ilincAPI = new ilnetucateXMLAPI();
00190
00191
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 }
00256 ?>