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