/**
  * Add Advanced Meta Data Information to the Info Screen
  *
  * @param ilInfoScreenGUI $info
  */
 protected function parseInfoScreen(ilInfoScreenGUI $info)
 {
     include_once 'Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php';
     include_once 'Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php';
     include_once 'Services/ADT/classes/class.ilADTFactory.php';
     $type = $this->object->getOrgUnitType();
     if (!$type) {
         return;
     }
     $assigned_record_ids = $type->getAssignedAdvancedMDRecordIds();
     foreach (ilAdvancedMDValues::getInstancesForObjectId($this->object->getId(), 'orgu') as $record_id => $a_values) {
         // Skip record ids not assigned to the type
         if (!in_array($record_id, $assigned_record_ids)) {
             continue;
         }
         // Note that we have to do this because with the instances above the sub-type and sub-id are missing...
         $a_values = new ilAdvancedMDValues($record_id, $this->object->getId(), 'orgu_type', $this->object->getOrgUnitTypeId());
         // this correctly binds group and definitions
         $a_values->read();
         $info->addSection(ilAdvancedMDRecord::_lookupTitle($record_id));
         $defs = $a_values->getDefinitions();
         foreach ($a_values->getADTGroup()->getElements() as $element_id => $element) {
             if (!$element->isNull()) {
                 $info->addProperty($defs[$element_id]->getTitle(), ilADTFactory::getInstance()->getPresentationBridgeForInstance($element)->getHTML());
             }
         }
     }
 }
 /**
  * Save title and translations
  */
 function saveTranslations()
 {
     // default language set?
     if (!isset($_POST["default"])) {
         ilUtil::sendFailure($this->lng->txt("msg_no_default_language"));
         return $this->editTranslations(true);
     }
     // all languages set?
     if (array_key_exists("", $_POST["lang"])) {
         ilUtil::sendFailure($this->lng->txt("msg_no_language_selected"));
         return $this->editTranslations(true);
     }
     // no single language is selected more than once?
     if (count(array_unique($_POST["lang"])) < count($_POST["lang"])) {
         ilUtil::sendFailure($this->lng->txt("msg_multi_language_selected"));
         return $this->editTranslations(true);
     }
     // save the stuff
     $this->ilObjectOrgUnit->removeTranslations();
     foreach ($_POST["title"] as $k => $v) {
         // update object data if default
         $is_default = $_POST["default"] == $k;
         if ($is_default) {
             $this->ilObjectOrgUnit->setTitle(ilUtil::stripSlashes($v));
             $this->ilObjectOrgUnit->setDescription(ilUtil::stripSlashes($_POST["desc"][$k]));
             $this->ilObjectOrgUnit->update();
         }
         $this->ilObjectOrgUnit->addTranslation(ilUtil::stripSlashes($v), ilUtil::stripSlashes($_POST["desc"][$k]), ilUtil::stripSlashes($_POST["lang"][$k]), $is_default);
     }
     ilUtil::sendSuccess($this->lng->txt("msg_obj_modified"), true);
     $this->ctrl->redirect($this, "editTranslations");
 }
 /**
  * @param $id
  * @param $type
  *
  * @return bool|int
  */
 protected function buildRef($id, $type)
 {
     if ($type == 'reference_id') {
         if (!ilObjOrgUnit::_exists($id, true)) {
             return false;
         }
         return $id;
     } elseif ($type == 'external_id') {
         $obj_id = ilObject::_lookupObjIdByImportId($id);
         if (!ilObject::_hasUntrashedReference($obj_id)) {
             return false;
         }
         $ref_ids = ilObject::_getAllReferences($obj_id);
         if (!count($ref_ids)) {
             return false;
         }
         foreach ($ref_ids as $ref_id) {
             if (!ilObject::_isInTrash($ref_id)) {
                 return $ref_id;
             }
         }
         return false;
     } else {
         return false;
     }
 }
 function __showRolesTable($a_result_set, $a_from = "")
 {
     if (!$this->ilAccess->checkAccess("cat_administrate_users", "", $_GET["ref_id"])) {
         ilUtil::sendFailure($this->lng->txt("permission_denied"), true);
         $this->ctrl->redirect($this, "");
     }
     $tbl =& $this->parent_gui->__initTableGUI();
     $tpl =& $tbl->getTemplateObject();
     // SET FORMAACTION
     $tpl->setCurrentBlock("tbl_form_header");
     $this->ctrl->setParameter($this, 'obj_id', $_GET['obj_id']);
     $tpl->setVariable("FORMACTION", $this->ctrl->getFormAction($this));
     $tpl->parseCurrentBlock();
     // SET FOOTER BUTTONS
     $tpl->setVariable("COLUMN_COUNTS", 4);
     $tpl->setVariable("IMG_ARROW", ilUtil::getImagePath("arrow_downright.svg"));
     $tpl->setCurrentBlock("tbl_action_button");
     $tpl->setVariable("BTN_NAME", "assignSave");
     $tpl->setVariable("BTN_VALUE", $this->lng->txt("change_assignment"));
     $tpl->parseCurrentBlock();
     $tpl->setCurrentBlock("tbl_action_row");
     $tpl->setVariable("TPLPATH", $this->tpl->tplPath);
     $tpl->parseCurrentBlock();
     $tmp_obj =& ilObjectFactory::getInstanceByObjId($_GET['obj_id']);
     $title = $this->lng->txt('role_assignment') . ' (' . $tmp_obj->getFullname() . ')';
     $tbl->setTitle($title, "icon_role.svg", $this->lng->txt("role_assignment"));
     $tbl->setHeaderNames(array('', $this->lng->txt("title"), $this->lng->txt('description'), $this->lng->txt("type")));
     $tbl->setHeaderVars(array("", "title", "description", "type"), array("ref_id" => $this->object->getRefId(), "cmd" => "assignRoles", "obj_id" => $_GET['obj_id'], "cmdClass" => "ilobjcategorygui", "cmdNode" => $_GET["cmdNode"]));
     $tbl->setColumnWidth(array("4%", "35%", "45%", "16%"));
     $this->set_unlimited = true;
     $this->parent_gui->__setTableGUIBasicData($tbl, $a_result_set, $a_from, true);
     $tbl->render();
     $this->tpl->setVariable("ROLES_TABLE", $tbl->tpl->get());
     return true;
 }
 private static function loadRootOrgRefIdAndId()
 {
     if (self::$root_ref_id === Null || self::$root_id === null) {
         global $ilDB;
         $q = "SELECT o.obj_id, r.ref_id FROM object_data o\n\t\t\tINNER JOIN object_reference r ON r.obj_id = o.obj_id\n\t\t\tWHERE title = " . $ilDB->quote('__OrgUnitAdministration', 'text') . "";
         $set = $ilDB->query($q);
         $res = $ilDB->fetchAssoc($set);
         self::$root_id = $res["obj_id"];
         self::$root_ref_id = $res["ref_id"];
     }
 }
 /**
  * Get node icon
  * Return custom icon of OrgUnit type if existing
  *
  * @param array $a_node
  *
  * @return string
  */
 public function getNodeIcon($a_node)
 {
     global $ilias;
     if ($ilias->getSetting('custom_icons')) {
         $icons_cache = ilObjOrgUnit::getIconsCache();
         $obj_id = ilObject::_lookupObjId($a_node["child"]);
         if (isset($icons_cache[$obj_id])) {
             return $icons_cache[$obj_id];
         }
     }
     return ilObject::_getIcon($obj_id, "tiny", $a_node["type"]);
 }
 /**
  * Update title and description for the default language of translation
  */
 protected function updateTranslation()
 {
     $translations = $this->obj_orgu->getTranslations();
     $lang_code_default = '';
     $lang_codes = array();
     foreach ($translations['Fobject'] as $translation) {
         if ($translation['lang_default']) {
             $lang_code_default = $translation['lang'];
         }
         $lang_codes[] = $translation['lang'];
     }
     $lang_code = in_array($this->user->getLanguage(), $lang_codes) ? $this->user->getLanguage() : $lang_code_default;
     $this->obj_orgu->updateTranslation($this->getInput('title'), $this->getInput('description'), $lang_code, 0);
 }
 /**
  * @param SimpleXMLElement $a
  */
 public function simpleUserImportElement(SimpleXMLElement $a)
 {
     global $rbacadmin;
     $attributes = $a->attributes();
     $action = $attributes->action;
     $user_id_type = $a->User->attributes()->id_type;
     $user_id = (string) $a->User;
     $org_unit_id_type = $a->OrgUnit->attributes()->id_type;
     $org_unit_id = (string) $a->OrgUnit;
     $role = (string) $a->Role;
     if (!($user_id = $this->buildUserId($user_id, $user_id_type))) {
         $this->addError('user_not_found', $a->User);
         return;
     }
     if (!($org_unit_id = $this->buildRef($org_unit_id, $org_unit_id_type))) {
         $this->addError('org_unit_not_found', $a->OrgUnit);
         return;
     }
     $org_unit = new ilObjOrgUnit($org_unit_id);
     if ($role == 'employee') {
         $role_id = $org_unit->getEmployeeRole();
     } elseif ($role == 'superior') {
         $role_id = $org_unit->getSuperiorRole();
     } else {
         $this->addError('not_a_valid_role', $user_id);
         return;
     }
     if ($action == 'add') {
         $rbacadmin->assignUser($role_id, $user_id);
         $this->stats['created']++;
     } elseif ($action == 'remove') {
         $rbacadmin->deassignUser($role_id, $user_id);
         $this->stats['removed']++;
     } else {
         $this->addError('not_a_valid_action', $user_id);
     }
 }
 protected function buildRef($id, $type)
 {
     if ($type == "reference_id") {
         if (!ilObjOrgUnit::_exists($id, true)) {
             return false;
         }
         return $id;
     } elseif ($type == "external_id") {
         $obj_id = ilObject::_lookupObjIdByImportId($id);
         $ref_ids = ilObject::_getAllReferences($obj_id);
         if (!count($ref_ids)) {
             return false;
         }
         return array_shift($ref_ids);
     } else {
         return false;
     }
 }
 public function getTabs(&$tabs_gui)
 {
     if ($this->ilAccess->checkAccess('read', '', $this->object->getRefId())) {
         $this->tabs_gui->addTab("view_content", $this->lng->txt("content"), $this->ctrl->getLinkTarget($this, ""));
         $this->tabs_gui->addTab("info_short", "Info", $this->ctrl->getLinkTargetByClass("ilinfoscreengui", "showSummary"));
     }
     //Tabs for OrgUnits exclusive root!
     if ($this->object->getRefId() != ilObjOrgUnit::getRootOrgRefId()) {
         if (ilObjOrgUnitAccess::_checkAccessStaff($this->object->getRefId())) {
             $this->tabs_gui->addTab("orgu_staff", $this->lng->txt("orgu_staff"), $this->ctrl->getLinkTargetByClass("ilOrgUnitStaffGUI", "showStaff"));
         }
         if ($this->ilAccess->checkAccess('write', '', $this->object->getRefId())) {
             $this->tabs_gui->addTab("settings", $this->lng->txt("settings"), $this->ctrl->getLinkTargetByClass("ilTranslationGUI", "editTranslations"));
         }
         if (ilObjOrgUnitAccess::_checkAccessAdministrateUsers($this->object->getRefId())) {
             $this->tabs_gui->addTab("administrate_users", $this->lng->txt("administrate_users"), $this->ctrl->getLinkTargetByClass("ilLocalUserGUI", "index"));
         }
     }
     if ($this->ilAccess->checkAccess('write', '', $this->object->getRefId())) {
         $this->tabs_gui->addTarget('export', $this->ctrl->getLinkTargetByClass('ilorgunitexportgui', ''), 'export', 'ilorgunitexportgui');
     }
     parent::getTabs($tabs_gui);
 }
 public function insertIconsAndCheckboxes()
 {
     global $lng, $ilias;
     // FSX removed $this->getCheckboxStatus() in if-Statement: 0014726
     if (!$ilias->getSetting('custom_icons')) {
         parent::insertIconsAndCheckboxes();
         return;
     }
     $icons_cache = ilObjOrgUnit::getIconsCache();
     if (isset($icons_cache[$this->obj_id])) {
         $icon_file = $icons_cache[$this->obj_id];
         // icon link
         if (!$this->default_command or !$this->getCommandsStatus() and !$this->restrict_to_goto) {
         } else {
             $this->tpl->setCurrentBlock("icon_link_s");
             if ($this->default_command["frame"] != "") {
                 $this->tpl->setVariable("ICON_TAR", "target='" . $this->default_command["frame"] . "'");
             }
             $this->tpl->setVariable("ICON_HREF", $this->default_command["link"]);
             $this->tpl->parseCurrentBlock();
             $this->tpl->touchBlock("icon_link_e");
         }
         $this->enableIcon(false);
         if ($this->getContainerObject()->isActiveAdministrationPanel() && !$_SESSION['clipboard']) {
             $this->tpl->touchBlock("i_1");
             // indent main div  }
             $this->tpl->touchBlock("d_2");
             // indent main div  } #0014913
         } else {
             $this->tpl->touchBlock("d_1");
         }
         parent::insertIconsAndCheckboxes();
         $this->tpl->setCurrentBlock("icon");
         $this->tpl->setVariable("ALT_ICON", $lng->txt("icon") . " " . $lng->txt("obj_" . $this->getIconImageType()));
         $this->tpl->setVariable("SRC_ICON", $icon_file);
         $this->tpl->parseCurrentBlock();
         $this->enableIcon(true);
     } else {
         parent::insertIconsAndCheckboxes();
     }
 }
 public function simpleExportExcel()
 {
     $ilOrgUnitExporter = new ilOrgUnitExporter();
     $ilOrgUnitExporter->simpleExportExcel(ilObjOrgUnit::getRootOrgRefId());
 }
 /**
  * @param $orgu ilObjOrgUnit
  * @return array
  */
 private function getAttrForOrgu($orgu)
 {
     global $tree;
     $parent_ref = $tree->getParentId($orgu->getRefId());
     if ($parent_ref != ilObjOrgUnit::getRootOrgRefId()) {
         $parent = new ilObjOrgUnit($parent_ref);
         $ou_parent_id = $parent->getRefId();
     } else {
         $ou_parent_id = "__ILIAS";
     }
     // Only the ref id is guaranteed to be unique.
     $ou_id = $orgu->getRefId();
     $attr = array("ou_id" => $ou_id, "ou_id_type" => "reference_id", "ou_parent_id" => $ou_parent_id, "ou_parent_id_type" => "reference_id", "action" => "create");
     return $attr;
 }
 /**
  * @return bool
  */
 protected function assignOrgunits()
 {
     global $ilDB, $rbacadmin;
     if (!count($this->getAssignedOrgus())) {
         return false;
     }
     foreach ($this->getAssignedOrgus() as $orgu_obj_id) {
         if (ilObject2::_lookupType($orgu_obj_id) != 'orgu') {
             continue;
         }
         $usr_id = $this->getUsrObject()->getId();
         $orgu_ref_ids = ilObjOrgUnit::_getAllReferences($orgu_obj_id);
         $orgu_ref_id = array_shift(array_values($orgu_ref_ids));
         if (!$orgu_ref_id) {
             continue;
         }
         $q = "SELECT obj_id, title FROM object_data WHERE title LIKE 'il_orgu_employee_" . $ilDB->quote($orgu_ref_id, "integer") . "'";
         $set = $ilDB->query($q);
         $row = $set->fetchRow(DB_FETCHMODE_OBJECT);
         $employee_role = $row->obj_id;
         $rbacadmin->assignUser($employee_role, $usr_id);
     }
     return true;
 }
 public function getRootNode()
 {
     return $this->getTree()->getNodeData(ilObjOrgUnit::getRootOrgRefId());
 }
 /**
  * Get an array of ilObjOrgUnit objects using this type
  *
  * @param bool $include_deleted True if also deleted OrgUnits are returned
  *
  * @return array
  */
 public function getOrgUnits($include_deleted = true)
 {
     $cache_key = $include_deleted ? 1 : 0;
     if (is_array($this->orgus[$cache_key])) {
         return $this->orgus[$cache_key];
     }
     $this->orgus[$cache_key] = array();
     $ids = $this->getOrgUnitIds($include_deleted);
     foreach ($ids as $id) {
         $orgu = new ilObjOrgUnit($id, false);
         if (!$include_deleted) {
             // Check if OrgUnit is in trash (each OrgUnit does only have one reference)
             $ref_ids = ilObject::_getAllReferences($id);
             $ref_ids = array_values($ref_ids);
             $ref_id = $ref_ids[0];
             if ($orgu->_isInTrash($ref_id)) {
                 continue;
             }
         }
         $this->orgus[$cache_key][] = $orgu;
     }
     return $this->orgus[$cache_key];
 }
 /**
  * @param $orgu ilObjOrgUnit
  * @return array
  */
 private function getAttributesForOrgu($orgu)
 {
     global $tree;
     $parent_ref = $tree->getParentId($orgu->getRefId());
     if ($parent_ref != ilObjOrgUnit::getRootOrgRefId()) {
         $ou_parent_id = $this->buildExternalId($parent_ref);
     } else {
         $ou_parent_id = "__ILIAS";
     }
     // Only the ref id is guaranteed to be unique.
     $ref_id = $orgu->getRefId();
     $attr = array("ou_id" => $this->buildExternalId($ref_id), "ou_id_type" => "external_id", "ou_parent_id" => $ou_parent_id, "ou_parent_id_type" => "external_id", "action" => "create");
     return $attr;
 }
 /**
  * Specify eg. level 1 and it will return on which orgunit on the first level after the root node the specified orgu_ref is a subunit of.
  * eg:
  *    0
  * -    -
  * 1    2
  * -   -  -
  * 3   4  5
  * -
  * 6
  *
  * (6, 1) = 1; (4, 1) = 2; (6, 2) = 3;
  * @param $orgu_ref
  * @param $level
  * @throws Exception in case there's a thread of an infinite loop or if you try to fetch the third level but there are only two (e.g. you want to fetch lvl 1 but give the root node as reference).
  * @return int|bool ref_id of the orgu or false if not found.
  */
 public function getLevelXOfTreenode($orgu_ref, $level)
 {
     $line = array($orgu_ref);
     $current_ref = $orgu_ref;
     while ($current_ref != ilObjOrgUnit::getRootOrgRefId()) {
         $current_ref = $this->getParent($current_ref);
         if ($current_ref) {
             $line[] = $current_ref;
         } else {
             break;
         }
         if (count($line) > 100) {
             throw new Exception("There's either a non valid call of the getLevelXOfTreenode in ilObjOrgUnitTree or your nesting of orgunits is higher than 100 units, which isn't encouraged");
         }
     }
     $line = array_reverse($line);
     if (count($line) > $level) {
         return $line[$level];
     } else {
         throw new Exception("you want to fetch level " . $level . " but the line to the length of the line is only " . count($line) . ". The line of the given org unit is: " . print_r($line, true));
     }
 }
 public function simpleImportElement(SimpleXMLElement $o)
 {
     global $tree, $tpl, $ilUser;
     $title = $o->title;
     $description = $o->description;
     $external_id = $o->external_id;
     $create_mode = true;
     $attributes = $o->attributes();
     $action = (string) $attributes->action;
     $ou_id = (string) $attributes->ou_id;
     $ou_id_type = (string) $attributes->ou_id_type;
     $ou_parent_id = (string) $attributes->ou_parent_id;
     $ou_parent_id_type = (string) $attributes->ou_parent_id_type;
     if ($ou_id == ilObjOrgUnit::getRootOrgRefId()) {
         $this->addWarning("cannot_change_root_node", $ou_id ? $ou_id : $external_id, $action);
         return;
     }
     if ($ou_parent_id == "__ILIAS") {
         $ou_parent_id = ilObjOrgUnit::getRootOrgRefId();
         $ou_parent_id_type = "reference_id";
     }
     $ref_id = $this->buildRef($ou_id, $ou_id_type);
     $parent_ref_id = $this->buildRef($ou_parent_id, $ou_parent_id_type);
     if ($action == "delete") {
         if (!$parent_ref_id) {
             $this->addError("ou_parent_id_not_valid", $ou_id ? $ou_id : $external_id, $action);
             return;
         }
         if (!$ref_id) {
             $this->addError("ou_id_not_valid", $ou_id ? $ou_id : $external_id, $action);
             return;
         }
         include_once "./Services/Repository/classes/class.ilRepUtil.php";
         $ru = new ilRepUtil($this);
         try {
             $ru->deleteObjects($parent_ref_id, array($ref_id)) !== false;
             $this->stats["deleted"]++;
         } catch (Excpetion $e) {
             $this->addWarning("orgu_already_deleted", $ou_id ? $ou_id : $external_id, $action);
         }
         return;
     } elseif ($action == "update") {
         if (!$parent_ref_id) {
             $this->addError("ou_parent_id_not_valid", $ou_id ? $ou_id : $external_id, $action);
             return;
         }
         if (!$ref_id) {
             $this->addError("ou_id_not_valid", $ou_id ? $ou_id : $external_id, $action);
             return;
         }
         $object = new ilObjOrgUnit($ref_id);
         $object->setTitle($title);
         $arrTranslations = $object->getTranslations();
         $object->updateTranslation($title, $description, $ilUser->getLanguage(), "");
         $object->setDescription($description);
         $object->update();
         $object->setImportId($external_id);
         if ($parent_ref_id != $tree->getParentId($ref_id)) {
             try {
                 $tree->moveTree($ref_id, $parent_ref_id);
             } catch (Exception $e) {
                 global $ilLog;
                 $this->addWarning("not_movable", $ou_id ? $ou_id : $external_id, $action);
                 $ilLog->write($e->getMessage() . "\\n" . $e->getTraceAsString());
             }
         }
         $this->stats["updated"]++;
     } elseif ($action == "create") {
         if (!$parent_ref_id) {
             $this->addError("ou_parent_id_not_valid", $ou_id ? $ou_id : $external_id, $action);
             return;
         }
         if ($external_id) {
             $obj_id = ilObject::_lookupObjIdByImportId($external_id);
             if (ilObject::_hasUntrashedReference($obj_id)) {
                 $this->addError("ou_external_id_exists", $ou_id ? $ou_id : $external_id, $action);
                 return;
             }
         }
         $object = new ilObjOrgUnit();
         $object->setTitle($title);
         $object->setDescription($description);
         $object->setImportId($external_id);
         $object->create();
         $object->createReference();
         $object->putInTree($parent_ref_id);
         $object->setPermissions($ou_parent_id);
         $this->stats["created"]++;
     } else {
         $this->addError("no_valid_action_given", $ou_id, $action);
     }
 }