Rev 11095 | Rev 16427 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 11095 | Rev 16031 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | # AddClass |
1 | # AddClass |
2 | # Let you create a new |
2 | # Let you create a new class, or a group of classes, or a subclass in a group |
- | 3 | ||
- | 4 | !read adm/class/limits |
|
3 | 5 | ||
4 | !if $qclass!=$empty |
6 | !if $qclass!=$empty |
5 | qclass=$[$qclass] |
7 | qclass=$[$qclass] |
6 | !if NaN isin $qclass or $qclass<11111 or $qclass>10^9 |
8 | !if NaN isin $qclass or $qclass<11111 or $qclass>10^9 |
7 | error=bad class id |
9 | error=bad class id |
8 | !exit |
10 | !exit |
9 | !endif |
11 | !endif |
10 | !endif |
12 | !endif |
11 | 13 | ||
12 | !if $qclass=$empty |
14 | !if $qclass=$empty |
13 | :recode |
15 | :recode |
14 | cd=!randint 10^6,10^7-1 |
16 | cd=!randint 10^6,10^7-1 |
15 | test=!defof class_defined in wimshome/log/classes/$cd/.def |
17 | test=!defof class_defined in wimshome/log/classes/$cd/.def |
16 | !if $test=yes |
18 | !if $test=yes |
17 | !goto recode |
19 | !goto recode |
18 | !endif |
20 | !endif |
19 | !else |
21 | !else |
20 | test=!defof class_defined in wimshome/log/classes/$qclass/.def |
22 | test=!defof class_defined in wimshome/log/classes/$qclass/.def |
21 |
|
23 | # Si la classe existe : |
22 | !if $test=yes |
24 | !if $test=yes |
23 | - | ||
24 | !read scripts/check.class |
25 | !read scripts/check.class |
25 | !if $error!=$empty |
26 | !if $error!=$empty |
26 | !exit |
27 | !exit |
27 | !endif |
28 | !endif |
28 | 29 | ||
29 | !readdef $classdeffile |
30 | !readdef $classdeffile |
30 | 31 | ||
31 | !if $class_type<2 |
32 | !if $class_type<2 |
32 | # You can't add a subclass inside an independent class |
33 | # You can't add a subclass inside an independent class |
33 |
|
34 | error=class $qclass already exists |
34 |
|
35 | !exit |
35 | !endif |
36 | !endif |
36 | 37 | ||
37 | class_nbsubclasses=!recordcnt wimshome/log/classes/$qclass/.subclasses |
38 | class_nbsubclasses=!recordcnt wimshome/log/classes/$qclass/.subclasses |
38 | 39 | ||
39 | :new_sub_id |
40 | :new_sub_id |
40 | !advance class_nbsubclasses |
41 | !advance class_nbsubclasses |
41 | 42 | ||
42 |
|
43 | # If $qclass exists and is a group, we add a subclass inside it. |
43 | cd=$qclass/$class_nbsubclasses |
44 | cd=$qclass/$class_nbsubclasses |
44 | 45 | ||
45 | classdeffile=wimshome/log/classes/$cd/.def |
46 | classdeffile=wimshome/log/classes/$cd/.def |
46 | test=!defof class_defined in $classdeffile |
47 | test=!defof class_defined in $classdeffile |
47 | !if $test=yes |
48 | !if $test=yes |
48 |
|
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. |
49 | !goto new_sub_id |
50 | !goto new_sub_id |
50 | !endif |
51 | !endif |
51 | 52 | ||
52 | !else |
53 | !else |
53 |
|
54 | # Si la classe n'existe pas, on la cree. |
54 | cd=$qclass |
55 | cd=$qclass |
55 | !endif |
56 | !endif |
56 | 57 | ||
57 | !endif |
58 | !endif |
58 | 59 | ||
59 | data1=!nonempty lines $data1 |
60 | data1=!nonempty lines $data1 |
60 | data2=!nonempty lines $data2 |
61 | data2=!nonempty lines $data2 |
61 | n1=!linecnt $data1 |
62 | n1=!linecnt $data1 |
62 | n2=!linecnt $data2 |
63 | n2=!linecnt $data2 |
63 | !for i=1 to $n1 |
64 | !for i=1 to $n1 |
64 | l=!line $i of $data1 |
65 | l=!line $i of $data1 |
65 | l=!translate = to $\ |
66 | l=!translate = to $\ |
66 | $ in $l |
67 | $ in $l |
67 | !distribute lines $l into n_,v_ |
68 | !distribute lines $l into n_,v_ |
68 | cl_$n_=$v_ |
69 | cl_$n_=$v_ |
69 | !next i |
70 | !next i |
70 | !for i=1 to $n2 |
71 | !for i=1 to $n2 |
71 | l=!line $i of $data2 |
72 | l=!line $i of $data2 |
72 | l=!translate = to $\ |
73 | l=!translate = to $\ |
73 | $ in $l |
74 | $ in $l |
74 | !distribute lines $l into n_,v_ |
75 | !distribute lines $l into n_,v_ |
75 | su_$n_=$v_ |
76 | su_$n_=$v_ |
76 | !next i |
77 | !next i |
77 | 78 | ||
78 | !for |
79 | !for field in cl_description, cl_institution, cl_supervisor, cl_email, cl_password,\ |
79 |
|
80 | su_lastname, su_firstname, su_password |
- | 81 | ||
- | 82 | # Remove unwanted chars |
|
- | 83 | $field=!translate ,!$$"< to $ $ in $($field) |
|
- | 84 | $field=!singlespace $($field) |
|
- | 85 | $field=!trim $($field) |
|
- | 86 | ||
80 | !if $( |
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 | ||
81 |
|
114 | !! fields with a pattern |
- | 115 | !if $fname isitemof email and @ notin $($field) |
|
- | 116 | error=data $field must be a valid email |
|
82 | !exit |
117 | !exit |
83 | !endif |
118 | !endif |
- | 119 | ||
84 | !next |
120 | !next field |
85 | 121 | ||
86 | # Ici il me semble redondant d'enregistrer a la fois type et typename. est-ce vraiment utile ? |
122 | # Ici il me semble redondant d'enregistrer a la fois type et typename. est-ce vraiment utile ? |
87 | !bound cl_type between integer 0 and 4 default 0 |
123 | !bound cl_type between integer 0 and 4 default 0 |
88 | cl_typename = !item ($cl_type+1) of $classtypes |
124 | cl_typename = !item ($cl_type+1) of $classtypes |
89 | 125 | ||
Line 96... | Line 132... | ||
96 | cl_parent=$qclass |
132 | cl_parent=$qclass |
97 | !endif |
133 | !endif |
98 | !endif |
134 | !endif |
99 | 135 | ||
100 | log = !sh cd $wims_home/log/classes\ |
136 | log = !sh cd $wims_home/log/classes\ |
101 |
|
137 | mkdir -p $cd\ |
102 |
|
138 | cd $cd\ |
103 |
|
139 | mkdir -p .users sheets exams score noscore\ |
104 |
|
140 | echo 4 >version |
105 | 141 | ||
106 | # la date de creation de la classe est automatiquement la date du jour. |
142 | # la date de creation de la classe est automatiquement la date du jour. |
107 | cl_creation=!char 1 to 8 of $wims_now |
143 | cl_creation=!char 1 to 8 of $wims_now |
108 | cl_creation=!eval $cl_creation |
144 | cl_creation=!eval $cl_creation |
109 | 145 |