/**
  * get results of test
  *
  * @param string $sid
  * @param int $test_ref_id
  * @param boolean $sum_only
  *
  * @return XMLResultSet with columns 
  * 	sum only = true: user_id, login, firstname, lastname, matriculation, maximum points, received points
  *  sum only = false: user_id, login, firstname, lastname, matriculation, question id, question title, question points, received points
  */
 function getTestResults($sid, $test_ref_id, $sum_only)
 {
     $this->initAuth($sid);
     $this->initIlias();
     if (!$this->__checkSession($sid)) {
         return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
     }
     if (!strlen($test_ref_id)) {
         return $this->__raiseError('No test id given. Aborting!', 'Client');
     }
     global $rbacsystem, $tree, $ilLog;
     if (ilObject::_isInTrash($test_ref_id)) {
         return $this->__raiseError('Test is trashed. Aborting!', 'Client');
     }
     // get obj_id
     if (!($obj_id = ilObject::_lookupObjectId($test_ref_id))) {
         return $this->__raiseError('No test found for id: ' . $test_ref_id, 'Client');
     }
     // Check access
     $permission_ok = false;
     foreach ($ref_ids = ilObject::_getAllReferences($obj_id) as $ref_id) {
         if ($rbacsystem->checkAccess('write', $ref_id)) {
             $permission_ok = true;
             break;
         }
     }
     if (!$permission_ok) {
         return $this->__raiseError('No permission to edit the object with id: ' . $test_ref_id, 'Server');
     }
     // store into xml result set
     include_once './webservice/soap/classes/class.ilXMLResultSet.php';
     include_once './webservice/soap/classes/class.ilXMLResultSetWriter.php';
     $xmlResultSet = new ilXMLResultSet();
     $xmlResultSet->addColumn("user_id");
     $xmlResultSet->addColumn("login");
     $xmlResultSet->addColumn("firstname");
     $xmlResultSet->addColumn("lastname");
     $xmlResultSet->addColumn("matriculation");
     include_once './Modules/Test/classes/class.ilObjTest.php';
     $test_obj = new ilObjTest($obj_id, false);
     $participants = $test_obj->getTestParticipants();
     if ($sum_only) {
         $data = $test_obj->getAllTestResults($participants, false);
         // create xml
         $xmlResultSet->addColumn("maximum_points");
         $xmlResultSet->addColumn("received_points");
         // skip titles
         $titles = array_shift($data);
         foreach ($data as $row) {
             $xmlRow = new ilXMLResultSetRow();
             $xmlRow->setValue(0, $row["user_id"]);
             $xmlRow->setValue(1, $row["login"]);
             $xmlRow->setValue(2, $row["firstname"]);
             $xmlRow->setValue(3, $row["lastname"]);
             $xmlRow->setValue(4, $row["matriculation"]);
             $xmlRow->setValue(5, $row["max_points"]);
             $xmlRow->setValue(6, $row["reached_points"]);
             $xmlResultSet->addRow($xmlRow);
         }
     } else {
         $data = $test_obj->getDetailedTestResults($participants);
         // create xml
         $xmlResultSet->addColumn("question_id");
         $xmlResultSet->addColumn("question_title");
         $xmlResultSet->addColumn("maximum_points");
         $xmlResultSet->addColumn("received_points");
         foreach ($data as $row) {
             $xmlRow = new ilXMLResultSetRow();
             $xmlRow->setValue(0, $row["user_id"]);
             $xmlRow->setValue(1, $row["login"]);
             $xmlRow->setValue(2, $row["firstname"]);
             $xmlRow->setValue(3, $row["lastname"]);
             $xmlRow->setValue(4, $row["matriculation"]);
             $xmlRow->setValue(5, $row["question_id"]);
             $xmlRow->setValue(6, $row["question_title"]);
             $xmlRow->setValue(7, $row["max_points"]);
             $xmlRow->setValue(8, $row["reached_points"]);
             $xmlResultSet->addRow($xmlRow);
         }
     }
     // create writer
     $xmlWriter = new ilXMLResultSetWriter($xmlResultSet);
     $xmlWriter->start();
     return $xmlWriter->getXML();
 }
 function getPathForRefId($sid, $ref_id)
 {
     $this->initAuth($sid);
     $this->initIlias();
     if (!$this->__checkSession($sid)) {
         return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
     }
     global $ilAccess, $objDefinition, $rbacsystem, $lng, $ilUser;
     if (!$rbacsystem->checkAccess('read', $ref_id)) {
         return $this->__raiseError("Missing read permissions for object with reference id " . $ref_id, 'Client');
     }
     if (ilObject::_isInTrash($ref_id)) {
         return $this->__raiseError("Object is in Trash", 'Client');
     }
     global $tree, $lng;
     $items = $tree->getPathFull($ref_id);
     include_once 'webservice/soap/classes/class.ilXMLResultSet.php';
     include_once 'webservice/soap/classes/class.ilXMLResultSetWriter.php';
     include_once 'Modules/Course/classes/class.ilCourseXMLWriter.php';
     $xmlResultSet = new ilXMLResultSet();
     $xmlResultSet->addColumn("ref_id");
     $xmlResultSet->addColumn("type");
     $xmlResultSet->addColumn("title");
     $writer = new ilXMLResultSetWriter($xmlResultSet);
     foreach ($items as $item) {
         if ($item["ref_id"] == $ref_id) {
             continue;
         }
         if ($item["title"] == "ILIAS" && $item["type"] == "root") {
             $item["title"] = $lng->txt("repository");
         }
         $row = new ilXMLResultSetRow();
         $xmlResultSet->addRow($row);
         $row->setValue("ref_id", $item["ref_id"]);
         $row->setValue("type", $item["type"]);
         $row->setValue("title", $item["title"]);
     }
     $writer->start();
     return $writer->getXML();
 }
 /**
  * return user  mapping as xml
  *
  * @param array (user_id => login) $a_array
  * @return XML String, following resultset.dtd
  */
 function __getUserMappingAsXML($a_array)
 {
     include_once './webservice/soap/classes/class.ilXMLResultSet.php';
     include_once './webservice/soap/classes/class.ilXMLResultSetWriter.php';
     $xmlResultSet = new ilXMLResultSet();
     $xmlResultSet->addColumn("userid");
     $xmlResultSet->addColumn("login");
     $xmlResultSet->addColumn("action");
     $xmlResultSet->addColumn("message");
     if (count($a_array)) {
         foreach ($a_array as $username => $message) {
             $xmlRow = new ilXMLResultSetRow();
             $xmlRow->setValue(0, $username);
             $xmlRow->setValue(1, $message["login"]);
             $xmlRow->setValue(2, $message["action"]);
             $xmlRow->setValue(3, $message["message"]);
             $xmlResultSet->addRow($xmlRow);
         }
     }
     $xml_writer = new ilXMLResultSetWriter($xmlResultSet);
     if ($xml_writer->start()) {
         return $xml_writer->getXML();
     }
     return $this->__raiseError('Error in __getUserMappingAsXML', 'Server');
 }
 /**
  * get groups which belong to a specific user, fullilling the status
  *
  * @param string $sid
  * @param string $parameters following xmlresultset, columns (user_id, status with values  1 = "MEMBER", 2 = "TUTOR", 4 = "ADMIN", 8 = "OWNER" and any xor operation e.g.  1 + 4 = 5 = ADMIN and TUTOR, 7 = ADMIN and TUTOR and MEMBER)
  * @param string XMLResultSet, columns (ref_id, xml, parent_ref_id) 
  */
 function getGroupsForUser($sid, $parameters)
 {
     $this->initAuth($sid);
     $this->initIlias();
     if (!$this->__checkSession($sid)) {
         return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
     }
     global $rbacreview, $ilObjDataCache, $tree;
     include_once 'webservice/soap/classes/class.ilXMLResultSetParser.php';
     $parser = new ilXMLResultSetParser($parameters);
     try {
         $parser->startParsing();
     } catch (ilSaxParserException $exception) {
         return $this->__raiseError($exception->getMessage(), "Client");
     }
     $xmlResultSet = $parser->getXMLResultSet();
     if (!$xmlResultSet->hasColumn("user_id")) {
         return $this->__raiseError("parameter user_id is missing", "Client");
     }
     if (!$xmlResultSet->hasColumn("status")) {
         return $this->__raiseError("parameter status is missing", "Client");
     }
     $user_id = (int) $xmlResultSet->getValue(0, "user_id");
     $status = (int) $xmlResultSet->getValue(0, "status");
     $ref_ids = array();
     // get roles
     #var_dump($xmlResultSet);
     #echo "uid:".$user_id;
     #echo "status:".$status;
     if (ilSoapGroupAdministration::MEMBER == ($status & ilSoapGroupAdministration::MEMBER) || ilSoapGroupAdministration::ADMIN == ($status & ilSoapGroupAdministration::ADMIN)) {
         foreach ($rbacreview->assignedRoles($user_id) as $role_id) {
             if ($role = ilObjectFactory::getInstanceByObjId($role_id, false)) {
                 #echo $role->getType();
                 if ($role->getType() != "role") {
                     continue;
                 }
                 if ($role->getParent() == ROLE_FOLDER_ID) {
                     continue;
                 }
                 $role_title = $role->getTitle();
                 if ($ref_id = ilUtil::__extractRefId($role_title)) {
                     if (!ilObject::_exists($ref_id, true) || ilObject::_isInTrash($ref_id)) {
                         continue;
                     }
                     #echo $role_title;
                     if (ilSoapGroupAdministration::MEMBER == ($status & ilSoapGroupAdministration::MEMBER) && strpos($role_title, "member") !== false) {
                         $ref_ids[] = $ref_id;
                     } elseif (ilSoapGroupAdministration::ADMIN == ($status & ilSoapGroupAdministration::ADMIN) && strpos($role_title, "admin") !== false) {
                         $ref_ids[] = $ref_id;
                     }
                 }
             }
         }
     }
     if (($status & ilSoapGroupAdministration::OWNER) == ilSoapGroupAdministration::OWNER) {
         $owned_objects = ilObjectFactory::getObjectsForOwner("grp", $user_id);
         foreach ($owned_objects as $obj_id) {
             $allrefs = ilObject::_getAllReferences($obj_id);
             $refs = array();
             foreach ($allrefs as $r) {
                 if ($tree->isDeleted($r)) {
                     continue;
                 }
                 if ($tree->isInTree($r)) {
                     $refs[] = $r;
                 }
             }
             if (count($refs) > 0) {
                 $ref_ids[] = array_pop($refs);
             }
         }
     }
     $ref_ids = array_unique($ref_ids);
     #print_r($ref_ids);
     include_once 'webservice/soap/classes/class.ilXMLResultSetWriter.php';
     include_once 'Modules/Group/classes/class.ilObjGroup.php';
     include_once 'Modules/Group/classes/class.ilGroupXMLWriter.php';
     $xmlResultSet = new ilXMLResultSet();
     $xmlResultSet->addColumn("ref_id");
     $xmlResultSet->addColumn("xml");
     $xmlResultSet->addColumn("parent_ref_id");
     foreach ($ref_ids as $group_id) {
         $group_obj = $this->checkObjectAccess($group_id, "grp", "write", true);
         if ($group_obj instanceof ilObjGroup) {
             $row = new ilXMLResultSetRow();
             $row->setValue("ref_id", $group_id);
             $xmlWriter = new ilGroupXMLWriter($group_obj);
             $xmlWriter->setAttachUsers(false);
             $xmlWriter->start();
             $row->setValue("xml", $xmlWriter->getXML());
             $row->setValue("parent_ref_id", $tree->getParentId($group_id));
             $xmlResultSet->addRow($row);
         }
     }
     $xmlResultSetWriter = new ilXMLResultSetWriter($xmlResultSet);
     $xmlResultSetWriter->start();
     return $xmlResultSetWriter->getXML();
 }
 /**
  * get client information from current as xml result set
  *
  * @param string $sid  current session id
  *
  * @return XMLResultSet containing columns installation_id, installation_version, installation_url, installation_description, installation_default_language
  */
 function getNIC($sid)
 {
     $this->initAuth($sid);
     $this->initIlias();
     if (!$this->__checkSession($sid)) {
         return $this->__raiseError($this->__getMessage(), $this->__getMessageCode());
     }
     global $rbacsystem, $rbacreview, $ilLog, $rbacadmin, $ilSetting, $ilClientIniFile;
     if (!is_object($ilClientIniFile)) {
         return $this->__raiseError("Client ini is not initialized", "Server");
     }
     $auth_modes = ilAuthUtils::_getActiveAuthModes();
     $auth_mode_default = strtoupper(ilAuthUtils::_getAuthModeName(array_shift($auth_modes)));
     $auth_mode_names = array();
     foreach ($auth_modes as $mode) {
         $auth_mode_names[] = strtoupper(ilAuthUtils::_getAuthModeName($mode));
     }
     include_once 'Services/AdvancedMetaData/classes/class.ilAdvancedMDRecord.php';
     include_once 'Services/AdvancedMetaData/classes/class.ilAdvancedMDRecordXMLWriter.php';
     // create advanced meta data record xml
     $record_ids = array();
     $record_types = ilAdvancedMDRecord::_getAssignableObjectTypes();
     foreach ($record_types as $type) {
         $records = ilAdvancedMDRecord::_getActivatedRecordsByObjectType($type);
         foreach ($records as $record) {
             $record_ids[] = $record->getRecordId();
         }
     }
     $record_ids = array_unique($record_ids);
     $advmwriter = new ilAdvancedMDRecordXMLWriter($record_ids);
     $advmwriter->write();
     // create user defined fields record xml, simulate empty user records
     include_once "./Services/User/classes/class.ilUserXMLWriter.php";
     $udfWriter = new ilUserXMLWriter();
     $users = array();
     $udfWriter->setObjects($users);
     $udfWriter->start();
     // todo: get information from client id, read from ini file specificied
     $client_details[] = array("installation_id" => IL_INST_ID, "installation_version" => ILIAS_VERSION, "installation_url" => ILIAS_HTTP_PATH, "installation_description" => $ilClientIniFile->readVariable("client", "description"), "installation_language_default" => $ilClientIniFile->readVariable("language", "default"), "installation_session_expire" => $ilClientIniFile->readVariable("session", "expire"), "installation_php_postmaxsize" => $this->return_bytes(ini_get("post_max_size")), "authentication_methods" => join(",", $auth_mode_names), "authentication_default_method" => $auth_mode_default, "installation_udf_xml" => $udfWriter->getXML(), "installation_advmd_xml" => $advmwriter->xmlDumpMem(false));
     // store into xml result set
     include_once './webservice/soap/classes/class.ilXMLResultSet.php';
     $xmlResult = new ilXMLResultSet();
     $xmlResult->addArray($client_details, true);
     // create writer and return xml
     include_once './webservice/soap/classes/class.ilXMLResultSetWriter.php';
     $xmlResultWriter = new ilXMLResultSetWriter($xmlResult);
     $xmlResultWriter->start();
     return $xmlResultWriter->getXML();
 }