﻿<?xml version="1.0" encoding="utf-8"?>
<ReportsExport>
  <Reports>
    <Report id="58602916-0a41-48e5-8a21-cffef211ea7d" codekey="ERGODirekt_Teilnahmeübersicht_Tests_für_Zielgruppe" categoryCodekey="TestsAndQuestions" name="Teilnahmeübersicht Tests für Zielgruppen" description="">
      <MetaData created="2015-06-26T16:20:55" createdBy="Administrator TestAllFeatures (Administrator)" createdBy_user_id="12" modified="2015-06-29T13:38:02" modifiedBy="Administrator TestAllFeatures" />
      <ExecutionDetails format="TableResult" commandType="SqlCommandOrQuery" exportHandler="" adminControl="" exportMultipleTablesToSheets="False" datesWithTime="False" extraParams="" />
      <Mandators mandatorMode="OnlyOwner" mandator_id="c5fd8bcc-2b1a-4f1d-b30d-9063c3f768cc" mandatorName="ERGODirekt" isStandard="False" isUsedByMenu="False" />
      <Parameters>
        <Parameter id="22d867d1-0fa2-483a-92be-17d91508ea87" isRequired="True" allowMultiSelect="False" name="Modul" contextName="Modul" defaultValue="" renderHint="Undefined" disableParameter="DontDisable" />
        <Parameter id="7d0bbe99-5e63-4e35-95e5-c83061dfa8ec" isRequired="False" allowMultiSelect="True" name="Zielgruppe abhängig vom Modul" contextName="Zielgruppe abhängig vom Modul" defaultValue="" renderHint="Undefined" disableParameter="DontDisable" />
        <Parameter id="4b782129-559e-40e3-a670-aa737d213949" isRequired="False" allowMultiSelect="True" name="Test abhängig vom Modul" contextName="Test abhängig vom Modul" defaultValue="" renderHint="Undefined" disableParameter="DontDisable" />
      </Parameters>
      <Roles>
        <Role id="90" />
      </Roles>
      <command>        DECLARE @curTGs CURSOR
        SET @curTGs = CURSOR FAST_FORWARD FOR
        SELECT value FROM @targerGroup_id
        DECLARE @tg_id INT
        OPEN @curTGs 
        FETCH NEXT FROM @curTGs INTO @tg_id
        WHILE (@@FETCH_STATUS=0)
        BEGIN
             SELECT title as 'Zielgruppe' from tblTargetGroups where id=@tg_id
             SELECT title as 'Test',

             CASE WHEN EXISTS(select * from tblUsersTargetGroups where targetGroup_id=@tg_id) THEN

             cast(cast(round((select count(userCn) from tblUsersTargetGroups where targetGroup_id=@tg_id 
                              and exists(select * from v_TblTasStatsTestSessions where user_id=userCn and test_id=tblItems.id)
                              )*100/(select count(userCn) from tblUsersTargetGroups where targetGroup_id=@tg_id),0) as int)
             as varchar(10))+' %' 
             
             ELSE '0%' END as 'Prozent'
             FROM tblItems inner join (select value as id from @test_id) SelectedTests on SelectedTests.id = tblItems.id

             FETCH NEXT FROM @curTGs INTO @tg_id
        END
        CLOSE @curTGs 
        DEALLOCATE @curTGs 
</command>
    </Report>
  </Reports>
  <Parameters>
    <Parameter id="22d867d1-0fa2-483a-92be-17d91508ea87" isSystem="True" name="Modul" reportParameterType_id="b141d3d7-0284-490f-8497-0345ae800ede" queryParameterName="@module_id" />
    <Parameter id="7d0bbe99-5e63-4e35-95e5-c83061dfa8ec" isSystem="False" name="Zielgruppe abhängig vom Modul" reportParameterType_id="d662f696-0487-48ac-a9cf-85f70256dc87" queryParameterName="@targerGroup_id" />
    <Parameter id="4b782129-559e-40e3-a670-aa737d213949" isSystem="False" name="Test abhängig vom Modul" reportParameterType_id="66284a2a-e928-4dcf-9ac7-ad81d7847fd9" queryParameterName="@test_id" />
    <Parameter id="986256a7-b816-470b-9802-a61d24e0d1e3" isSystem="False" name="Modul abhängig von Zielgruppen" reportParameterType_id="99630598-5924-4e25-8f4e-6c2751444ab1" queryParameterName="@module_id" />
    <Parameter id="a5485539-67e0-4912-8255-8081a54efb3c" isSystem="False" name="Zielgruppe" reportParameterType_id="4123c2c2-d408-476a-82bf-ca77f9ecf944" queryParameterName="@targetGroup_id" />
  </Parameters>
  <ParameterTypes>
    <ParameterType id="b141d3d7-0284-490f-8497-0345ae800ede" isSystem="True" name="Module" datatype="Module" dataValueField="" dataTextField="" />
    <ParameterType id="d662f696-0487-48ac-a9cf-85f70256dc87" isSystem="False" name="Zielgruppe abhängig von Modul Typ" datatype="IntegerDDL" dataValueField="id" dataTextField="title">
      <query>
        SELECT DISTINCT tblTargetGroups.title, tblTargetGroups.id
        FROM tblTargetGroups
          INNER JOIN tblEduOffersTargetGroups ON tblTargetGroups.id = tblEduOffersTargetGroups.targetGroup_id
          INNER JOIN tblEduOffersModules ON tblEduOffersTargetGroups.eduOffer_id = tblEduOffersModules.eduOffer_id
        WHERE tblEduOffersModules.module_id = @module_id
          AND (tblTargetGroups.mandator_id = @current_mandator_id)
          AND (EXISTS (SELECT * FROM v_Users WHERE intUserCn = @current_user_id AND securityId = 100)
            OR EXISTS(SELECT * FROM tblTargetGroupManagers WHERE tblTargetGroupManagers.user_id = @current_user_id AND
                      tblTargetGroupManagers.targetGroup_id = tblTargetGroups.id)
            OR EXISTS(SELECT * FROM tblRolesFunctions
                  JOIN tblRoles ON tblRoles.id = tblRolesFunctions.role_id
                  JOIN tblFunctions ON tblFunctions.id = tblRolesFunctions.function_id
                  JOIN v_Users ON v_Users.intUserCn = @current_user_id
                  WHERE tblFunctions.shortcut = 'FcnIsAuthorizedForAllTGs' AND tblRoles.id = v_Users.SecurityID))
          AND defaultforlibrary = 0
        ORDER BY title
      </query>
      <Parameters>
        <Parameter id="22d867d1-0fa2-483a-92be-17d91508ea87" isRequired="False" allowMultiSelect="False" name="Modul" contextName="Modul" defaultValue="" renderHint="Undefined" disableParameter="DontDisable" />
      </Parameters>
    </ParameterType>
    <ParameterType id="66284a2a-e928-4dcf-9ac7-ad81d7847fd9" isSystem="False" name="Test abhängig vom Modul Typ" datatype="GuidDDL" dataValueField="id" dataTextField="title">
      <query> SELECT DISTINCT tblItems.id, 
                tblItems.title
  FROM tblItems
       JOIN tblModuleItems ON tblModuleItems.item_id = tblItems.id AND tblItems.itemType_id = 0 --test
 WHERE tblModuleItems.module_id = @module_id</query>
      <Parameters>
        <Parameter id="986256a7-b816-470b-9802-a61d24e0d1e3" isRequired="False" allowMultiSelect="False" name="Modul abhängig von Zielgruppen" contextName="Modul abhängig von Zielgruppen" defaultValue="" renderHint="Undefined" disableParameter="DontDisable" />
      </Parameters>
    </ParameterType>
    <ParameterType id="99630598-5924-4e25-8f4e-6c2751444ab1" isSystem="False" name="Modul abhängig von Zielgruppen Typ" datatype="GuidDDL" dataValueField="id" dataTextField="title">
      <query>SELECT DISTINCT tblItems.id, 
                tblItems.title
  FROM tblItems
       JOIN tblEduOffersModules ON tblEduOffersModules.module_id = tblItems.id
       JOIN tblEduOffersTargetGroups ON tblEduOffersModules.eduOffer_id = tblEduOffersTargetGroups.eduOffer_id
 WHERE itemType_id = 1001
   AND mandator_id = @current_mandator_id
   AND tblEduOffersTargetGroups.targetGroup_id IN(
       SELECT * FROM @targetGroup_id)
 ORDER BY title</query>
      <Parameters>
        <Parameter id="a5485539-67e0-4912-8255-8081a54efb3c" isRequired="False" allowMultiSelect="True" name="Zielgruppe" contextName="Zielgruppe" defaultValue="" renderHint="Undefined" disableParameter="DontDisable" />
      </Parameters>
    </ParameterType>
    <ParameterType id="4123c2c2-d408-476a-82bf-ca77f9ecf944" isSystem="False" name="TargetGroup" datatype="IntegerDDL" dataValueField="id" dataTextField="title">
      <query>
        SELECT id, title
        FROM tblTargetGroups
        WHERE(mandator_id = @current_mandator_id)
        AND (EXISTS(SELECT * FROM v_Users WHERE intUserCn = @current_user_id AND securityId = 100)
        OR EXISTS(SELECT * FROM tblTargetGroupManagers WHERE tblTargetGroupManagers.user_id = @current_user_id
        AND tblTargetGroupManagers.targetGroup_id = tblTargetGroups.id)
        OR EXISTS(SELECT *
        FROM tblRolesFunctions
        JOIN tblRoles ON tblRoles.id = tblRolesFunctions.role_id
        JOIN tblFunctions ON tblFunctions.id = tblRolesFunctions.function_id
        JOIN v_Users ON v_Users.intUserCn = @current_user_id
        WHERE tblFunctions.shortcut = 'FcnIsAuthorizedForAllTGs' AND tblRoles.id = v_Users.SecurityID))
        AND defaultforlibrary = 0
        ORDER BY title
      </query>
    </ParameterType>
  </ParameterTypes>
</ReportsExport>