Subversion Repositories wimsdev

Rev

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