Subversion Repositories wimsdev

Rev

Rev 11061 | Rev 13211 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
10133 bpr 1
# mkuserlist
4626 obado 2
# Constructs .userlist file in specified class (wims_class by default)
10133 bpr 3
# constructs .usernextlist and .userprevlist
4
# also constructs .userlist_external if needed
4626 obado 5
 
20 reyssat 6
uclass=$wims_read_parm
7
!default uclass=$wims_class
4626 obado 8
 
11060 obado 9
# What's the point of $wims_prefix ?
20 reyssat 10
!if user notwordof $wims_prefix
11060 obado 11
  wims_prefix=$wims_prefix user
20 reyssat 12
!endif
4626 obado 13
 
20 reyssat 14
:mkstart
15
supclass=!defof class_superclass in wimshome/log/classes/$uclass/.def
16
reset class_lvl
4626 obado 17
 
20 reyssat 18
!if $supclass!=$empty and $supclass!=$uclass
11060 obado 19
  supertype=!defof class_type in wimshome/log/classes/$supclass/.def
20
  typename=!defof class_typename in wimshome/log/classes/$uclass/.def
21
 
22
  !if $typename iswordof level program
23
    !exit
20 reyssat 24
  !endif
11060 obado 25
 
26
  !if $typename issametext course
27
    class_parent=!defof class_parent in wimshome/log/classes/$uclass/.def
28
    !if $class_parent!=$empty
29
      i=!defof class_ocourses in wimshome/log/classes/$class_parent/.def
30
      i=!makelist $wims_superclass/x for x in $i
31
      !if $uclass isitemof $i
32
        uclass=$class_parent
33
        !goto mkstart
34
      !endif
35
    !endif
36
    clist=$uclass
20 reyssat 37
  !else
11060 obado 38
    !if / isin $uclass
39
      class_lvl=!translate internal / to , in $uclass
40
      class_lvl=$(class_lvl[1])/$(class_lvl[2])
41
      !if $class_lvl=$uclass
42
        class_lvl=
43
        clist=$supclass,$uclass
44
      !else
45
        clist=$supclass,$class_lvl,$uclass
46
      !endif
47
    !else
48
      clist=!listuniq $supclass,$uclass
49
    !endif
20 reyssat 50
  !endif
51
!else
11060 obado 52
  typename=class
53
  clist=$uclass
54
  supclass=$uclass
20 reyssat 55
!endif
56
 
57
mul_userdir=wimshome/log/classes/$supclass/.users
58
mul_userdir2=$wims_home/log/classes/$supclass/.users
4626 obado 59
 
11038 obado 60
pack_size = 500
61
 
62
## On range la liste des utilisateurs par paquets de $pack_size (userlist_0, userlist_1, etc...)
20 reyssat 63
start=0
11038 obado 64
userlist_$start=!sh cd $mul_userdir2; ls 2>/dev/null | head -$pack_size
20 reyssat 65
userlist_$start=!words2items $(userlist_$start)
4626 obado 66
 
20 reyssat 67
userlist_lastcnt=!itemcnt $(userlist_$start)
4626 obado 68
 
11060 obado 69
!while $userlist_lastcnt>$[$pack_size-1]
11038 obado 70
  !advance start
11060 obado 71
  userlist_$start=!sh cd $mul_userdir2; ls 2>/dev/null | tail -n +$[$start*$pack_size+1] | head -$pack_size
11038 obado 72
  userlist_$start=!words2items $(userlist_$start)
73
  userlist_lastcnt=!itemcnt $(userlist_$start)
20 reyssat 74
!endwhile
75
 
10133 bpr 76
## On supprime une eventuelle liste temporaire "userlist*.raw" dans chaque classe
77
## just junk
20 reyssat 78
!for c in $clist
11060 obado 79
  !sh rm -f $wims_home/log/classes/$c/.userlist.raw 2>/dev/null\
11062 obado 80
      rm -f $wims_home/log/classes/$c/.userlist_external.raw 2>/dev/null
1605 bpr 81
!next
4626 obado 82
 
11038 obado 83
## On parcourt nos paquets de $pack_size users
20 reyssat 84
!for N=0 to $start
11060 obado 85
  !for u in $(userlist_$N)
86
    !reset user_firstname, user_lastname, user_supervisable,\
87
      user_class, user_participate, user_exists, user_external_auth
88
    !readdef $mul_userdir/$u
5295 bpr 89
 
11060 obado 90
    !!TODO  better to make a special list for user_supervisable who participates
91
    !!(suppress to add supervisor who are registered as participant to appear in userlist)
92
    !if $user_exists=yes and $user_supervisable!=yes
93
      userline=:$user_lastname,$user_firstname,$u
94
      !reset userline_external
95
      !if $user_external_auth!=$empty
96
        userline_external=$user_external_auth:$u
97
      !endif
98
      !if $typename=course
99
        !readdef wimshome/log/classes/$uclass/.users/$u
100
        !if $user_class!=$empty
101
          !appendfile wimshome/log/classes/$uclass/.userlist.raw $userline,$user_class
102
          !if $userline_external!=$empty
103
            !appendfile wimshome/log/classes/$uclass/.userlist_external.raw $userline_external
104
          !endif
105
        !endif
106
      !else
107
        !if $supclass=$uclass or $uclass isitemof $user_participate
108
          !appendfile wimshome/log/classes/$uclass/.userlist.raw $userline
109
          !if $userline_external!=$empty
110
            !appendfile wimshome/log/classes/$uclass/.userlist_external.raw $userline_external
111
          !endif
112
        !endif
113
        ### do it for the $supclass ? could be done many times if not in a group ?
114
        !if $supclass!=$uclass
115
          !appendfile wimshome/log/classes/$supclass/.userlist.raw $userline
116
          !if $userline_external!=$empty
117
            !appendfile wimshome/log/classes/$supclass/.userlist_external.raw $userline_external
118
          !endif
119
          !if $class_lvl!=$empty and $class_lvl/ isin $user_participate
120
            ## do it for the intermediaire class ? could be done many times
121
            !appendfile wimshome/log/classes/$class_lvl/.userlist.raw $userline
122
            !if $userline_external!=$empty
123
              !appendfile wimshome/log/classes/$class_lvl/.userlist_external.raw $userline_external
124
            !endif
125
          !endif
126
        !endif
127
      !endif
20 reyssat 128
    !endif
11060 obado 129
  !next u
20 reyssat 130
!next N
131
 
132
basedir=$wims_home/log/classes
6868 bpr 133
basedir2=wimshome/log/classes
10133 bpr 134
 
20 reyssat 135
!for c in $clist
11061 obado 136
  !sh sort -f $basedir/$c/.userlist.raw >$basedir/$c/.userlist 2>/dev/null\
137
  rm -f $basedir/$c/.userlist.raw 2>/dev/null\
138
  sort -f $basedir/$c/.userlist_external.raw > $basedir/$c/.userlist_external 2>/dev/null\
139
  rm -f $basedir/$c/.userlist_external.raw 2>/dev/null
10133 bpr 140
!next
141
## Now the files .userlist and .userlist_external are created in the classes of $clist,
142
## so in the sup classes of $uclass. Do we need to do that (it is done many times for
143
## the portal ...
144
 
145
## do now the .usernextlist and .userprevlist only in the class $uclass
146
## in fact, there is only one class in $uclass. Leave the loop for the moment
147
!for c in $uclass
11062 obado 148
  !sh rm -f $basedir/$c/.usernextlist.raw 2>/dev/null\
149
      rm -f $basedir/$c/.userprevlist.raw 2>/dev/null
10133 bpr 150
  !set nbuser_=!recordcnt $basedir2/$c/.userlist
151
  !if $nbuser_=0
152
    !break
153
  !endif
11062 obado 154
 
155
  record_start = 1
156
  remaining = $nbuser_ - 1
157
  ## On parcourt nos users par paquets de $pack_size
158
  !while $remaining > 0
159
    nb_processing = $[min($remaining, $pack_size)]
160
    record_end = $[$record_start+$nb_processing]
161
    list_n=!record $record_start to $record_end of $basedir2/$c/.userlist
162
    list_n=!column 3 of $list_n
163
    nextuser=!makelist $$(list_n[x]), $$(list_n[x+1]); for x=1 to $nb_processing
164
    nextuser=!nospace $nextuser
165
    nextuser=!replace internal ;, by ; in $nextuser
166
 
167
    prevuser=!nospace $(nextuser[;2,1])
168
 
169
    prevuser=!rows2lines $prevuser
170
    prevuser=!replace internal , by : in $prevuser
171
    nextuser=!rows2lines $nextuser
172
    nextuser=!replace internal , by : in $nextuser
173
 
174
    !appendfile $basedir2/$c/.usernextlist.raw $nextuser
175
    !appendfile $basedir2/$c/.userprevlist.raw $prevuser
176
    record_start = $record_start + $nb_processing
177
    remaining = $remaining - $nb_processing
178
  !endwhile
179
  first_user = !record 1 of $basedir2/$c/.userlist
180
  first_user = !item 3 of $first_user
181
  last_user = !record -1 of $basedir2/$c/.userlist
182
  last_user = !item 3 of $last_user
183
  !appendfile $basedir2/$c/.usernextlist.raw $last_user:$first_user
184
  !appendfile $basedir2/$c/.userprevlist.raw $first_user:$last_user
6868 bpr 185
  !sh mv $basedir/$c/.usernextlist.raw $basedir/$c/.usernextlist\
11062 obado 186
      mv $basedir/$c/.userprevlist.raw $basedir/$c/.userprevlist
20 reyssat 187
!next c