Rev 11095 | Rev 16427 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
9425 | obado | 1 | # AddClass |
16031 | obado | 2 | # Let you create a new class, or a group of classes, or a subclass in a group |
4118 | obado | 3 | |
16031 | obado | 4 | !read adm/class/limits |
5 | |||
23 | reyssat | 6 | !if $qclass!=$empty |
16031 | obado | 7 | qclass=$[$qclass] |
8 | !if NaN isin $qclass or $qclass<11111 or $qclass>10^9 |
||
9 | error=bad class id |
||
10 | !exit |
||
11 | !endif |
||
23 | reyssat | 12 | !endif |
13 | |||
14 | !if $qclass=$empty |
||
16031 | obado | 15 | :recode |
16 | cd=!randint 10^6,10^7-1 |
||
17 | test=!defof class_defined in wimshome/log/classes/$cd/.def |
||
18 | !if $test=yes |
||
19 | !goto recode |
||
20 | !endif |
||
23 | reyssat | 21 | !else |
16031 | obado | 22 | test=!defof class_defined in wimshome/log/classes/$qclass/.def |
23 | # Si la classe existe : |
||
24 | !if $test=yes |
||
25 | !read scripts/check.class |
||
26 | !if $error!=$empty |
||
27 | !exit |
||
28 | !endif |
||
9425 | obado | 29 | |
16031 | obado | 30 | !readdef $classdeffile |
9425 | obado | 31 | |
16031 | obado | 32 | !if $class_type<2 |
33 | # You can't add a subclass inside an independent class |
||
34 | error=class $qclass already exists |
||
35 | !exit |
||
36 | !endif |
||
9425 | obado | 37 | |
16031 | obado | 38 | class_nbsubclasses=!recordcnt wimshome/log/classes/$qclass/.subclasses |
9425 | obado | 39 | |
16031 | obado | 40 | :new_sub_id |
41 | !advance class_nbsubclasses |
||
9425 | obado | 42 | |
16031 | obado | 43 | # If $qclass exists and is a group, we add a subclass inside it. |
44 | cd=$qclass/$class_nbsubclasses |
||
9425 | obado | 45 | |
16031 | obado | 46 | classdeffile=wimshome/log/classes/$cd/.def |
47 | test=!defof class_defined in $classdeffile |
||
48 | !if $test=yes |
||
49 | # If a subclass has been deleted before, nb_subclass may not correspond to the next available subclass. So we use the next free ID. |
||
50 | !goto new_sub_id |
||
51 | !endif |
||
9425 | obado | 52 | |
16031 | obado | 53 | !else |
54 | # Si la classe n'existe pas, on la cree. |
||
55 | cd=$qclass |
||
4176 | obado | 56 | !endif |
9425 | obado | 57 | |
23 | reyssat | 58 | !endif |
59 | |||
60 | data1=!nonempty lines $data1 |
||
61 | data2=!nonempty lines $data2 |
||
62 | n1=!linecnt $data1 |
||
63 | n2=!linecnt $data2 |
||
64 | !for i=1 to $n1 |
||
16031 | obado | 65 | l=!line $i of $data1 |
66 | l=!translate = to $\ |
||
23 | reyssat | 67 | $ in $l |
16031 | obado | 68 | !distribute lines $l into n_,v_ |
69 | cl_$n_=$v_ |
||
23 | reyssat | 70 | !next i |
71 | !for i=1 to $n2 |
||
16031 | obado | 72 | l=!line $i of $data2 |
73 | l=!translate = to $\ |
||
23 | reyssat | 74 | $ in $l |
16031 | obado | 75 | !distribute lines $l into n_,v_ |
76 | su_$n_=$v_ |
||
23 | reyssat | 77 | !next i |
78 | |||
16031 | obado | 79 | !for field in cl_description, cl_institution, cl_supervisor, cl_email, cl_password,\ |
80 | su_lastname, su_firstname, su_password |
||
23 | reyssat | 81 | |
16031 | obado | 82 | # Remove unwanted chars |
83 | $field=!translate ,!$$"< to $ $ in $($field) |
||
84 | $field=!singlespace $($field) |
||
85 | $field=!trim $($field) |
||
86 | |||
87 | !if $($field) = $empty |
||
88 | error=incomplete (or forbidden chars) in data $field ($($field)) |
||
89 | !exit |
||
90 | !endif |
||
91 | |||
92 | !! Remove cl_ or su_ in front of field name |
||
93 | fname = !char 4 to -1 of $field |
||
94 | n=!charcnt $($field) |
||
95 | |||
96 | !! Avoid fields with a minimun length |
||
97 | !if $n<$(min_$fname) and $fname notitemof location |
||
98 | error=data $field too short (<$(min_$fname)) |
||
99 | !exit |
||
100 | !endif |
||
101 | |||
102 | !! fields with a maximum length |
||
103 | !if $n>$(max_$fname) |
||
104 | !if $fname isitemof password |
||
105 | error=data $field too long (>$(max_$fname)) |
||
106 | !exit |
||
107 | !else |
||
108 | !! truncate |
||
109 | $field=!char 1 to $(max_$fname) of $($field) |
||
110 | !endif |
||
111 | !endif |
||
112 | |||
113 | |||
114 | !! fields with a pattern |
||
115 | !if $fname isitemof email and @ notin $($field) |
||
116 | error=data $field must be a valid email |
||
117 | !exit |
||
118 | !endif |
||
119 | |||
120 | !next field |
||
121 | |||
4061 | obado | 122 | # Ici il me semble redondant d'enregistrer a la fois type et typename. est-ce vraiment utile ? |
123 | !bound cl_type between integer 0 and 4 default 0 |
||
4365 | obado | 124 | cl_typename = !item ($cl_type+1) of $classtypes |
4061 | obado | 125 | |
8051 | czzmrn | 126 | !if $cl_type > 1 and / isin $cd |
4061 | obado | 127 | error=superclass $qclass already exists |
128 | !exit |
||
129 | !else |
||
5591 | obado | 130 | !if / isin $cd |
131 | cl_superclass=$qclass |
||
132 | cl_parent=$qclass |
||
133 | !endif |
||
4061 | obado | 134 | !endif |
135 | |||
4176 | obado | 136 | log = !sh cd $wims_home/log/classes\ |
16031 | obado | 137 | mkdir -p $cd\ |
138 | cd $cd\ |
||
139 | mkdir -p .users sheets exams score noscore\ |
||
140 | echo 4 >version |
||
23 | reyssat | 141 | |
4058 | obado | 142 | # la date de creation de la classe est automatiquement la date du jour. |
23 | reyssat | 143 | cl_creation=!char 1 to 8 of $wims_now |
391 | obado | 144 | cl_creation=!eval $cl_creation |
145 | |||
4058 | obado | 146 | |
391 | obado | 147 | !default cl_expiration=$[$cl_creation+10000] |
148 | |||
23 | reyssat | 149 | !bound cl_limit between integer 1 and 500 default 30 |
150 | langs=!words2items $wims_site_languages |
||
151 | !bound cl_lang within $langs default en |
||
152 | !default cl_level=H4 |
||
4118 | obado | 153 | !default cl_theme=standard |
4058 | obado | 154 | !default cl_css=-theme- |
4118 | obado | 155 | !default cl_creator=$httpd_REMOTE_ADDR |
8051 | czzmrn | 156 | !default cl_scorecolor=#ffffff, #ff0000, #ff0000, #ff0000, #ffa500, #ffa500, #fff500, #d2ff00, #b9ff00, #2fc42f, #259425 |
23 | reyssat | 157 | |
3319 | obado | 158 | !writefile wimshome/log/classes/$cd/.def !set class_connections=+$ident/$rclass+ $(cl_connections) \ |
4058 | obado | 159 | !set class_defined=yes\ |
160 | !set class_creation=$cl_creation |
||
3261 | obado | 161 | |
162 | !for t in $classdefs |
||
23 | reyssat | 163 | !appendfile wimshome/log/classes/$cd/.def !set class_$t=$(cl_$t) |
164 | !next t |
||
165 | |||
166 | !writefile wimshome/log/classes/$cd/supervisor !set user_lastname=$su_lastname\ |
||
167 | !set user_firstname=$su_firstname\ |
||
168 | !set user_password=$su_password\ |
||
169 | !set user_email=$cl_email\ |
||
170 | !set user_exists=yes |
||
171 | |||
391 | obado | 172 | !if $cssfile!=$empty |
173 | !writefile wimshome/log/classes/$cd/css $cssfile |
||
174 | !endif |
||
23 | reyssat | 175 | |
391 | obado | 176 | !if $logofile!=$empty |
177 | !writefile wimshome/log/classes/$cd/logo $logofile |
||
178 | !endif |
||
179 | |||
10778 | obado | 180 | log = !sh cd $wims_home/log/classes; ./.build-index $qclass |