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 require_once("classes/class.ilSaxParser.php");
00025 require_once("classes/class.ilObjUser.php");
00026
00027
00037 class ilGroupImportParser extends ilSaxParser
00038 {
00039 var $group_data;
00040 var $group_obj;
00041
00042 var $parent;
00043 var $counter;
00044
00053 function ilGroupImportParser($a_xml,$a_parent_id)
00054 {
00055 define('EXPORT_VERSION',2);
00056
00057 parent::ilSaxParser();
00058 $this->setXMLContent($a_xml);
00059
00060
00061 $this->__pushParentId($a_parent_id);
00062
00063
00064 }
00065
00066 function __pushParentId($a_id)
00067 {
00068 $this->parent[] = $a_id;
00069 }
00070 function __popParentId()
00071 {
00072 array_pop($this->parent);
00073
00074 return true;
00075 }
00076 function __getParentId()
00077 {
00078 return $this->parent[count($this->parent) - 1];
00079 }
00080
00086 function setHandlers($a_xml_parser)
00087 {
00088 xml_set_object($a_xml_parser,$this);
00089 xml_set_element_handler($a_xml_parser,'handlerBeginTag','handlerEndTag');
00090 xml_set_character_data_handler($a_xml_parser,'handlerCharacterData');
00091 }
00092
00096 function startParsing()
00097 {
00098 parent::startParsing();
00099
00100 return is_object($this->group_obj) ? $this->group_obj->getRefId() : false;
00101 }
00102
00103
00107 function handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
00108 {
00109 global $ilErr;
00110
00111 switch($a_name)
00112 {
00113
00114 case "group":
00115 #if($a_attribs["exportVersion"] < EXPORT_VERSION)
00116 #{
00117 # $ilErr->raiseError("!!! This export Version isn't supported, update your ILIAS 2 installation"
00118 # ,$ilErr->WARNING);
00119 #}
00120
00121 $this->group_data["admin"] = array();
00122 $this->group_data["member"] = array();
00123
00124 $this->group_data["type"] = $a_attribs["type"];
00125 $this->group_data["id"] = $a_attribs["id"];
00126
00127 break;
00128
00129 case 'title':
00130 break;
00131
00132 case "owner":
00133 $this->group_data["owner"] = $a_attribs["id"];
00134 break;
00135
00136 case 'registration':
00137 $this->group_data['registration_type'] = $a_attribs['type'];
00138 break;
00139
00140 case "admin":
00141 $this->group_data["admin"][] = $a_attribs["id"];
00142 break;
00143
00144 case "member":
00145 $this->group_data["member"][] = $a_attribs["id"];
00146
00147 break;
00148
00149 case "folder":
00150
00151 $this->__save();
00152 break;
00153
00154 case "file":
00155
00156 $this->__save();
00157
00158 $this->file["fileName"] = $a_attribs["fileName"];
00159 $this->file["id"] = $a_attribs["id"];
00160
00161
00162 $this->__saveFile();
00163 break;
00164 }
00165 }
00166
00167
00168 function handlerEndTag($a_xml_parser, $a_name)
00169 {
00170 switch($a_name)
00171 {
00172 case "title":
00173 $this->group_data["title"] = trim($this->cdata);
00174 break;
00175
00176 case "description":
00177 $this->group_data["description"] = trim($this->cdata);
00178 break;
00179
00180 case 'password':
00181 $this->group_data['password'] = trim($this->cdata);
00182 break;
00183
00184 case 'expiration':
00185 $this->group_data['expiration'] = trim($this->cdata);
00186 break;
00187
00188 case "folder":
00189 $this->__popParentId();
00190 break;
00191
00192 case "folderTitle":
00193 $this->folder = trim($this->cdata);
00194 $this->__saveFolder();
00195 break;
00196
00197 case "group":
00198
00199 $this->__save();
00200 break;
00201 }
00202 $this->cdata = '';
00203 }
00204
00205
00209 function handlerCharacterData($a_xml_parser, $a_data)
00210 {
00211
00212
00213
00214
00215 $a_data = str_replace("<","<",$a_data);
00216 $a_data = str_replace(">",">",$a_data);
00217
00218 if(!empty($a_data))
00219 {
00220 $this->cdata .= $a_data;
00221 }
00222 }
00223
00224
00225 function __save()
00226 {
00227 if($this->group_imported)
00228 {
00229 return true;
00230 }
00231
00232 $this->__initGroupObject();
00233
00234 $this->group_obj->setImportId($this->group_data["id"]);
00235 $this->group_obj->setTitle($this->group_data["title"]);
00236 $this->group_obj->setDescription($this->group_data["description"]);
00237
00238 switch($this->group_data['registration_type'])
00239 {
00240 case 'disabled':
00241 $flag = 0;
00242 break;
00243
00244 case 'enabled':
00245 $flag = 1;
00246 break;
00247
00248 case 'password':
00249 $flag = 2;
00250 break;
00251
00252 default:
00253 $flag = 0;
00254 }
00255 $this->group_obj->setRegistrationFlag($flag);
00256
00257 $this->group_obj->create();
00258 $this->group_obj->createReference();
00259 $this->group_obj->putInTree($this->__getParentId());
00260 $this->group_obj->initDefaultRoles();
00261
00262
00263
00264 switch($this->group_data['registration_type'])
00265 {
00266 case 'disabled':
00267 $flag = 0;
00268 break;
00269
00270 case 'enabled':
00271 $flag = 1;
00272 break;
00273
00274 case 'password':
00275 $flag = 2;
00276 break;
00277
00278 default:
00279 $flag = 0;
00280 }
00281 $this->group_obj->setRegistrationFlag($flag);
00282 if($this->group_data['expiration'])
00283 {
00284 $this->group_obj->setExpirationDateTime(date('Y.m.d H:i:s',$this->group_data['expiration']));
00285 }
00286 $this->group_obj->setPassword($this->group_data['password']);
00287 $this->group_obj->__setGroupStatus($this->group_data["type"] == "open" ? 0 : 1);
00288
00289
00290 $this->__assignMembers();
00291
00292 $this->__pushParentId($this->group_obj->getRefId());
00293
00294
00295 $this->group_imported = true;
00296
00297 return true;
00298 }
00299
00300 function __saveFolder()
00301 {
00302 $this->__initFolderObject();
00303
00304 $this->folder_obj->setTitle($this->folder);
00305 $this->folder_obj->create();
00306 $this->folder_obj->createReference();
00307 $this->folder_obj->putInTree($this->__getParentId());
00308 $this->folder_obj->initDefaultRoles();
00309
00310 $this->__pushParentId($this->folder_obj->getRefId());
00311
00312 $this->__destroyFolderObject();
00313
00314 return true;
00315 }
00316
00317 function __saveFile()
00318 {
00319 $this->__initFileObject();
00320
00321 $this->file_obj->setType("file");
00322 $this->file_obj->setTitle($this->file["fileName"]);
00323 $this->file_obj->setFileName($this->file["fileName"]);
00324 $this->file_obj->create();
00325 $this->file_obj->createReference();
00326 $this->file_obj->putInTree($this->__getParentId());
00327 $this->file_obj->setPermissions($this->__getParentId());
00328
00329
00330 $this->file_obj->createDirectory();
00331
00332 $this->__initImportFileObject();
00333
00334 if($this->import_file_obj->findObjectFile($this->file["id"]))
00335 {
00336 $this->file_obj->copy($this->import_file_obj->getObjectFile(),$this->file["fileName"]);
00337 }
00338
00339 unset($this->file_obj);
00340 unset($this->import_file_obj);
00341
00342 return true;
00343 }
00344
00345 function __assignMembers()
00346 {
00347 global $ilias,$ilUser;
00348
00349
00350 $this->group_obj->addMember($ilUser->getId(),$this->group_obj->getDefaultAdminRole());
00351
00352
00353 foreach($this->group_data["admin"] as $user)
00354 {
00355 if($id_data = $this->__parseId($user))
00356 {
00357 if($id_data['local'] or $id_data['imported'])
00358 {
00359 $this->group_obj->addMember($id_data['usr_id'],$this->group_obj->getDefaultAdminRole());
00360 }
00361 }
00362 }
00363
00364
00365 foreach($this->group_data["member"] as $user)
00366 {
00367 if($id_data = $this->__parseId($user))
00368 {
00369 if($id_data['local'] or $id_data['imported'])
00370 {
00371 $this->group_obj->addMember($id_data['usr_id'],$this->group_obj->getDefaultMemberRole());
00372 }
00373 }
00374 }
00375 return true;
00376 }
00377
00378 function __initGroupObject()
00379 {
00380 include_once "classes/class.ilObjGroup.php";
00381
00382 $this->group_obj =& new ilObjGroup();
00383
00384 return true;
00385 }
00386
00387 function __initFolderObject()
00388 {
00389 include_once "classes/class.ilObjFolder.php";
00390
00391 $this->folder_obj =& new ilObjFolder();
00392
00393 return true;
00394 }
00395
00396 function __initImportFileObject()
00397 {
00398 include_once "classes/class.ilFileDataImportGroup.php";
00399
00400 $this->import_file_obj =& new ilFileDataImportGroup();
00401
00402 return true;
00403 }
00404
00405 function __initFileObject()
00406 {
00407 include_once "classes/class.ilObjFile.php";
00408
00409 $this->file_obj =& new ilObjFile();
00410
00411 return true;
00412 }
00413
00414 function __destroyFolderObject()
00415 {
00416 unset($this->folder_obj);
00417 }
00418
00419 function __parseId($a_id)
00420 {
00421 global $ilias;
00422
00423 $fields = explode('_',$a_id);
00424
00425 if(!is_array($fields) or
00426 $fields[0] != 'il' or
00427 !is_numeric($fields[1]) or
00428 $fields[2] != 'usr' or
00429 !is_numeric($fields[3]))
00430 {
00431 return false;
00432 }
00433 if($id = ilObjUser::_getImportedUserId($a_id))
00434 {
00435 return array('imported' => true,
00436 'local' => false,
00437 'usr_id' => $id);
00438 }
00439 if(($fields[1] == $ilias->getSetting('inst_id',0)) and strlen(ilObjUser::_lookupName($fields[3])))
00440 {
00441 return array('imported' => false,
00442 'local' => true,
00443 'usr_id' => $fields[3]);
00444 }
00445 return false;
00446 }
00447
00448 }
00449 ?>