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
00035 class ilCategoryImportParser extends ilSaxParser
00036 {
00037 var $parent;
00038 var $withrol;
00039
00040
00048 function ilCategoryImportParser($a_xml_file, $a_parent,$withrol)
00049
00050 {
00051 $this->parent_cnt = 0;
00052 $this->parent[$this->parent_cnt] = $a_parent;
00053 $this->parent_cnt++;
00054 $this->withrol = $withrol;
00055 parent::ilSaxParser($a_xml_file);
00056 }
00057
00058
00064 function setHandlers($a_xml_parser)
00065 {
00066 xml_set_object($a_xml_parser,$this);
00067 xml_set_element_handler($a_xml_parser,'handlerBeginTag','handlerEndTag');
00068 xml_set_character_data_handler($a_xml_parser,'handlerCharacterData');
00069 }
00070
00074 function startParsing()
00075 {
00076 parent::startParsing();
00077 }
00078
00086 function buildTag ($type, $name, $attr="")
00087 {
00088 $tag = "<";
00089
00090 if ($type == "end")
00091 $tag.= "/";
00092
00093 $tag.= $name;
00094
00095 if (is_array($attr))
00096 {
00097 while (list($k,$v) = each($attr))
00098 $tag.= " ".$k."=\"$v\"";
00099 }
00100
00101 $tag.= ">";
00102
00103 return $tag;
00104 }
00105
00109 function handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
00110
00111 {
00112
00113 global $rbacadmin, $rbacreview, $rbacsystem;
00114
00115 switch($a_name)
00116 {
00117 case "Category":
00118 $cur_parent = $this->parent[$this->parent_cnt - 1];
00119 require_once("classes/class.ilObjCategory.php");
00120 $this->category = new ilObjCategory;
00121 $this->category->setImportId($a_attribs["Id"]." (#".$cur_parent.")");
00122 $this->default_language = $a_attribs["DefaultLanguage"];
00123 $this->category->setTitle($a_attribs["Id"]);
00124 $this->category->create();
00125 $this->category->createReference();
00126 $this->category->putInTree($cur_parent);
00127 $this->parent[$this->parent_cnt++] = $this->category->getRefId();
00128
00129
00130 if ($this->withrol) {
00131
00132
00133 if (!$rbacsystem->checkAccess('create',$this->category->getRefId(),'rolf')) {
00134 $this->ilias->raiseError($this->lng->txt("msg_no_perm_create_rolf"),$this->ilias->error_obj->WARNING);
00135 }
00136
00137 include_once ("classes/class.ilObject.php");
00138 include_once ("classes/class.ilObjRole.php");
00139
00140
00141 $rolfObj = $this->category->createRoleFolder("Local roles","Role Folder of category obj_no. ".$this->category->getRefId());
00142 $parentRoles = $rbacreview->getParentRoleIds($rolfObj->getRefId(),true);
00143
00144
00145 foreach($_POST["adopt"] as $postadopt) {
00146
00147 $desc = $a_attribs["Id"]. " ".$parentRoles[$postadopt]["title"];
00148 $roleObj = $rolfObj->createRole($desc,"Local rol for category ".$desc);
00149
00150 $rbacadmin->copyRolePermission($postadopt,$parentRoles[$postadopt]["parent"],$rolfObj->getRefId(),$roleObj->getId());
00151 unset($roleObj);
00152 }
00153
00154 unset($rolfObj);
00155 unset($parentRoles);
00156
00157
00158 }
00159 break;
00160
00161 case "CategorySpec":
00162 $this->cur_spec_lang = $a_attribs["Language"];
00163 break;
00164
00165 }
00166
00167 }
00168
00169
00173 function handlerEndTag($a_xml_parser, $a_name)
00174 {
00175 global $ilias, $rbacadmin;
00176
00177 switch($a_name)
00178 {
00179 case "Category":
00180 unset($this->category);
00181 unset($this->parent[$this->parent_cnt - 1]);
00182 $this->parent_cnt--;
00183 break;
00184
00185 case "CategorySpec":
00186 $is_def = 0;
00187 if ($this->cur_spec_lang == $this->default_language)
00188 {
00189 $this->category->setTitle($this->cur_title);
00190 $this->category->setDescription($this->cur_description);
00191 $this->category->update();
00192 $is_def = 1;
00193 }
00194 $this->category->addTranslation($this->cur_title,
00195 $this->cur_description, $this->cur_spec_lang, $is_def);
00196 break;
00197
00198 case "Title":
00199 $this->cur_title = $this->cdata;
00200 break;
00201
00202 case "Description":
00203 $this->cur_description = $this->cdata;
00204 break;
00205 }
00206
00207 $this->cdata = "";
00208 }
00209
00213 function handlerCharacterData($a_xml_parser, $a_data)
00214 {
00215
00216
00217
00218
00219 $a_data = str_replace("<","<",$a_data);
00220 $a_data = str_replace(">",">",$a_data);
00221
00222
00223 $a_data = preg_replace("/\n/","",$a_data);
00224 $a_data = preg_replace("/\t+/","",$a_data);
00225 if(!empty($a_data))
00226 {
00227 $this->cdata .= $a_data;
00228 }
00229 }
00230
00231 }
00232 ?>