gestion 1.9.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (233) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +48 -0
  3. data/.project +14 -0
  4. data/Binaries/adduser_to_buzz +15 -0
  5. data/Binaries/backup +7 -0
  6. data/Binaries/check_gestion +8 -0
  7. data/Binaries/gestion.gnumail +22 -0
  8. data/Binaries/gestion.logrotate +34 -0
  9. data/Binaries/gestion.service +12 -0
  10. data/Binaries/gestion_update.rb +183 -0
  11. data/Binaries/gestion_update.service +10 -0
  12. data/Binaries/get_compta +11 -0
  13. data/Binaries/kill_gestion +16 -0
  14. data/Binaries/ldap/add_indexes +51 -0
  15. data/Binaries/ldap/backup +2 -0
  16. data/Binaries/ldap/install_ldap +92 -0
  17. data/Binaries/ldap/restore +7 -0
  18. data/Binaries/lib_backup +5 -0
  19. data/Binaries/log_scan_errors +8 -0
  20. data/Binaries/loop_gestion +64 -0
  21. data/Binaries/onetimers/sync_courses_from_compta.rb +74 -0
  22. data/Binaries/onetimers/transfer_cash_from_ldap_to_csv +26 -0
  23. data/Binaries/reboot +5 -0
  24. data/Binaries/restore +3 -0
  25. data/Binaries/restore_do +22 -0
  26. data/Binaries/sort_events +31 -0
  27. data/Binaries/start_gestion +18 -0
  28. data/Binaries/swipe_gestion +18 -0
  29. data/Binaries/update_africompta +21 -0
  30. data/Binaries/update_users +3 -0
  31. data/Diplomas.src/accredited.odg +0 -0
  32. data/Diplomas.src/diploma.odg +0 -0
  33. data/Diplomas.src/label.odg +0 -0
  34. data/Diplomas.src/presence_sheet.ods +0 -0
  35. data/Diplomas.src/presence_sheet_small.ods +0 -0
  36. data/Diplomas.src/student_card.odg +0 -0
  37. data/Doc/130514-it-ideas.odt +0 -0
  38. data/Doc/Compta-cash.mm +179 -0
  39. data/Doc/General.odt +0 -0
  40. data/Entities/AccessGroups.rb +117 -0
  41. data/Entities/Activity.rb +178 -0
  42. data/Entities/ChatMsg.rb +142 -0
  43. data/Entities/Classroom.rb +11 -0
  44. data/Entities/Client.rb +19 -0
  45. data/Entities/Computer.rb +21 -0
  46. data/Entities/ConfigBase.rb +280 -0
  47. data/Entities/Course.rb +1588 -0
  48. data/Entities/CourseType.rb +171 -0
  49. data/Entities/DFiles.rb +466 -0
  50. data/Entities/FilesManage.rb +226 -0
  51. data/Entities/Grade.rb +186 -0
  52. data/Entities/Internet.rb +300 -0
  53. data/Entities/Netdev.rb +10 -0
  54. data/Entities/Person.rb +1175 -0
  55. data/Entities/Plug.rb +98 -0
  56. data/Entities/Quiz.rb +33 -0
  57. data/Entities/Recharges.rb +37 -0
  58. data/Entities/Report.rb +136 -0
  59. data/Entities/Room.rb +12 -0
  60. data/Entities/SMS.rb +30 -0
  61. data/Entities/ScheduleType.rb +33 -0
  62. data/Entities/Share.rb +120 -0
  63. data/Entities/Task.rb +51 -0
  64. data/Entities/Ticket.rb +72 -0
  65. data/Entities/Usage.rb +143 -0
  66. data/Entities/Worker.rb +29 -0
  67. data/Files/apache-profeda.conf +36 -0
  68. data/Files/label.erb +121 -0
  69. data/Files/label_notfound.erb +64 -0
  70. data/Files/label_notpassed.erb +84 -0
  71. data/Files/mobileinfo.erb +115 -0
  72. data/Files/smb.conf +333 -0
  73. data/Files/timetable.html +36 -0
  74. data/Files/timetable.js +239 -0
  75. data/Gemfile +12 -0
  76. data/Gemfile.dev +12 -0
  77. data/Gemfile.dev.lock +127 -0
  78. data/Gemfile.lock +127 -0
  79. data/Gemfile.prod +8 -0
  80. data/Gestion +35 -0
  81. data/Gestion.rb +220 -0
  82. data/INSTALL +40 -0
  83. data/Images/connection.xcf +0 -0
  84. data/Images/connection_no.png +0 -0
  85. data/Images/connection_wait.png +0 -0
  86. data/Images/connection_yes.png +0 -0
  87. data/Paths/Exas.rb +13 -0
  88. data/Paths/Files.rb +19 -0
  89. data/Paths/GetDiplomas.rb +20 -0
  90. data/Paths/Info.rb +114 -0
  91. data/Paths/Label.rb +187 -0
  92. data/Paths/MobileInfo.rb +19 -0
  93. data/Paths/internetCash.rb +34 -0
  94. data/Paths/internetWifi.rb +54 -0
  95. data/README.md +60 -0
  96. data/Rakefile +13 -0
  97. data/TODO +1391 -0
  98. data/Test/.gitignore +3 -0
  99. data/Test/Diplomas/base_gestion.odt +0 -0
  100. data/Test/Diplomas/base_report.odt +0 -0
  101. data/Test/Diplomas/carte_etudiant.odg +0 -0
  102. data/Test/Diplomas/exam_language.odt +0 -0
  103. data/Test/Diplomas/label.odg +0 -0
  104. data/Test/Diplomas/presence_sheet.ods +0 -0
  105. data/Test/Diplomas/presence_sheet_small.ods +0 -0
  106. data/Test/Diplomas/student_card.odg +0 -0
  107. data/Test/Manual/testMerge +18 -0
  108. data/Test/config_test.yaml +26 -0
  109. data/Test/db.testGestion +0 -0
  110. data/Test/dfiles/descs/avg-rescue.desc +10 -0
  111. data/Test/dfiles/descs/avg.desc +8 -0
  112. data/Test/dfiles/descs/driver.desc +8 -0
  113. data/Test/dfiles/descs/linuxmint.desc +7 -0
  114. data/Test/dfiles/files/avg-160203.exe +1 -0
  115. data/Test/dfiles/files/avg.iso +1 -0
  116. data/Test/dfiles/files/driver.exe +1 -0
  117. data/Test/dfiles/index_post.html +3 -0
  118. data/Test/dfiles/index_pre.html +8 -0
  119. data/Test/dfiles/priorities +5 -0
  120. data/Test/ge_activity.rb +124 -0
  121. data/Test/ge_chat.rb +106 -0
  122. data/Test/ge_compta.rb +67 -0
  123. data/Test/ge_configbase.rb +54 -0
  124. data/Test/ge_course.rb +1114 -0
  125. data/Test/ge_dfiles.rb +121 -0
  126. data/Test/ge_filesmanage.rb +180 -0
  127. data/Test/ge_info.rb +27 -0
  128. data/Test/ge_internet.rb +246 -0
  129. data/Test/ge_login.rb +55 -0
  130. data/Test/ge_person.rb +373 -0
  131. data/Test/ge_qvinfo.rb +28 -0
  132. data/Test/ge_report.rb +97 -0
  133. data/Test/ge_share.rb +27 -0
  134. data/Test/ge_sms.rb +34 -0
  135. data/Test/ge_tasks.rb +19 -0
  136. data/Test/ge_usage.rb +168 -0
  137. data/Test/ge_view.rb +46 -0
  138. data/Test/multiconf-captive +29 -0
  139. data/Test/test.conf +7 -0
  140. data/Test/test.rb +49 -0
  141. data/Test/test_bytes.png +0 -0
  142. data/VERSION +140 -0
  143. data/Views/Admin/Backup.rb +91 -0
  144. data/Views/Admin/Configuration.rb +44 -0
  145. data/Views/Admin/Credit.rb +32 -0
  146. data/Views/Admin/FilesManage.rb +219 -0
  147. data/Views/Admin/Function.rb +39 -0
  148. data/Views/Admin/Power.rb +49 -0
  149. data/Views/Admin/Printer.rb +37 -0
  150. data/Views/Admin/Server.rb +252 -0
  151. data/Views/Admin/Tabs.rb +5 -0
  152. data/Views/Admin/Update.rb +73 -0
  153. data/Views/Admin/UpdateSystem.rb +26 -0
  154. data/Views/Cashbox/Activity.rb +191 -0
  155. data/Views/Cashbox/Course.rb +141 -0
  156. data/Views/Cashbox/Credit.rb +79 -0
  157. data/Views/Cashbox/Report.rb +115 -0
  158. data/Views/Cashbox/Service.rb +105 -0
  159. data/Views/Cashbox/Tabs.rb +10 -0
  160. data/Views/Compta/Accounts.rb +36 -0
  161. data/Views/Compta/Course.rb +96 -0
  162. data/Views/Compta/Show.rb +6 -0
  163. data/Views/Compta/Transfer.rb +66 -0
  164. data/Views/Course/Diploma.rb +203 -0
  165. data/Views/Course/Grade.rb +401 -0
  166. data/Views/Course/Modify.rb +447 -0
  167. data/Views/Course/Print.rb +94 -0
  168. data/Views/Course/Responsible.rb +44 -0
  169. data/Views/Course/Stats.rb +76 -0
  170. data/Views/Course/Students.rb +92 -0
  171. data/Views/Course/Tabs.rb +220 -0
  172. data/Views/Internet/Access.rb +134 -0
  173. data/Views/Internet/ClassEdit.rb +24 -0
  174. data/Views/Internet/ClassUsers.rb +81 -0
  175. data/Views/Internet/Config.rb +32 -0
  176. data/Views/Internet/Mobile.rb +213 -0
  177. data/Views/Internet/Recharges.rb +49 -0
  178. data/Views/Internet/Tabs.rb +6 -0
  179. data/Views/Inventory/Computer.rb +24 -0
  180. data/Views/Inventory/Room.rb +18 -0
  181. data/Views/Inventory/Tabs.rb +9 -0
  182. data/Views/Inventory/TicketClosed.rb +7 -0
  183. data/Views/Inventory/TicketOpen.rb +23 -0
  184. data/Views/Library/Person.rb +36 -0
  185. data/Views/Library/Tabs.rb +7 -0
  186. data/Views/Network/Block.rb +87 -0
  187. data/Views/Network/Netdevs.rb +21 -0
  188. data/Views/Network/Restriction.rb +37 -0
  189. data/Views/Network/Share.rb +167 -0
  190. data/Views/Network/Tables.rb +28 -0
  191. data/Views/Network/Tabs.rb +6 -0
  192. data/Views/Person/Admin.rb +99 -0
  193. data/Views/Person/Center.rb +48 -0
  194. data/Views/Person/Course.rb +72 -0
  195. data/Views/Person/Modify.rb +153 -0
  196. data/Views/Person/Tabs.rb +162 -0
  197. data/Views/Report/ComptaExecutive.rb +221 -0
  198. data/Views/Report/ComptaFlat.rb +79 -0
  199. data/Views/Report/ReportCourse.rb +47 -0
  200. data/Views/Report/Tabs.rb +8 -0
  201. data/Views/Report/Usage.rb +52 -0
  202. data/Views/Report/UsageCases.rb +59 -0
  203. data/Views/Self/Cash.rb +67 -0
  204. data/Views/Self/Chat.rb +55 -0
  205. data/Views/Self/Concours.rb +109 -0
  206. data/Views/Self/Email.rb +34 -0
  207. data/Views/Self/Internet.rb +255 -0
  208. data/Views/Self/Results.rb +17 -0
  209. data/Views/Self/Services.rb +85 -0
  210. data/Views/Self/Show.rb +47 -0
  211. data/Views/Self/Tabs.rb +5 -0
  212. data/Views/Special/DFileEdit.rb +13 -0
  213. data/Views/Special/PlugEdit.rb +56 -0
  214. data/Views/Special/Tabs.rb +6 -0
  215. data/Views/Special/Vnc.rb +39 -0
  216. data/Views/Task/Client.rb +21 -0
  217. data/Views/Task/Edit.rb +33 -0
  218. data/Views/Task/List.rb +55 -0
  219. data/Views/Task/Tabs.rb +9 -0
  220. data/Views/Task/Worker.rb +30 -0
  221. data/Views/Template/Activity.rb +33 -0
  222. data/Views/Template/CourseType.rb +63 -0
  223. data/Views/Template/ScheduleType.rb +29 -0
  224. data/Views/Template/Tabs.rb +5 -0
  225. data/Views/Welcome.rb +121 -0
  226. data/config.yaml.default +36 -0
  227. data/po/Gestion-ar.po +2356 -0
  228. data/po/Gestion-en.mo +0 -0
  229. data/po/Gestion-en.po +4363 -0
  230. data/po/Gestion-fr.mo +0 -0
  231. data/po/Gestion-fr.po +4345 -0
  232. data/po/traduction-ar.rtf +76 -0
  233. metadata +381 -0
@@ -0,0 +1,401 @@
1
+ # Manages grades of a course
2
+ # - Add or change grades
3
+ # - Print out grades
4
+
5
+ class CourseGrade < View
6
+ def layout
7
+ set_data_class :Courses
8
+
9
+ @update = true
10
+ @order = 20
11
+
12
+ # gui_vboxgl do
13
+ gui_hboxg do
14
+ gui_vboxg :nogroup do
15
+ show_table :students, headings: %w(Name Grade Files Status),
16
+ widths: [250, 40, 40, 50], callback: :click,
17
+ height: 350, width: 390, single: true
18
+ #show_list_single :students, :width => 300, :callback => true, :flexheight => 1
19
+ show_str_ro :last_synched
20
+ show_button :prepare_files, :fetch_files, :transfer_files, :sync_server
21
+ end
22
+ gui_vbox :nogroup do
23
+ gui_vbox :nogroup do
24
+ show_str :first_name, :width => 150
25
+ show_str :family_name
26
+ show_list_drop :gender, '%w( male female n/a )'
27
+ show_int_ro :files_saved
28
+ show_str :remark
29
+ show_table :grades, :headings => %w(Label grade), :widths => [150, 50],
30
+ :columns => %w(0 align_right), :callback => :edit,
31
+ :edit => [1], :height => 200
32
+ end
33
+ gui_vbox :nogroup do
34
+ show_html :name_file_direct
35
+ show_upload :upload_direct, :callback => true
36
+ show_button :save, :upload
37
+ end
38
+ end
39
+ gui_window :transfer do
40
+ show_html :txt
41
+ show_upload :files
42
+ show_button :close
43
+ end
44
+
45
+ gui_window :sync do
46
+ show_html :synching
47
+ show_button :close
48
+ end
49
+
50
+ gui_window :upload_files do
51
+ show_html :name_file_1
52
+ show_upload :upload_file_1, :callback => true
53
+ show_html :name_file_2
54
+ show_upload :upload_file_2, :callback => true
55
+ show_html :name_file_3
56
+ show_upload :upload_file_3, :callback => true
57
+ show_html :name_file_4
58
+ show_upload :upload_file_4, :callback => true
59
+ show_html :name_file_5
60
+ show_upload :upload_file_5, :callback => true
61
+ show_button :close
62
+ end
63
+ end
64
+ end
65
+
66
+ def rpc_update(session)
67
+ super(session) +
68
+ reply(:empty_nonlists, [:students]) +
69
+ [:prepare_files, :fetch_files, :transfer_files,
70
+ :last_synched, :sync_server, :upload, :files_saved,
71
+ :upload_direct, :name_file_direct, :remark].collect { |b|
72
+ reply(:hide, b)
73
+ }.flatten
74
+ end
75
+
76
+ def update_files_saved(course, student)
77
+ reply(:update, :files_saved =>
78
+ "#{course.exam_files(student).count}/#{course.ctype.files_nbr}")
79
+ end
80
+
81
+ def get_grades(ct, grades)
82
+ means = grades ? grades.means : [''] * ct.tests_nbr.to_i
83
+ i = 0
84
+ ct.tests_arr.zip(means).collect { |t, m|
85
+ [i += 1, [t, m.to_s]]
86
+ }
87
+ end
88
+
89
+ def update_grade(data)
90
+ c_id, p_name = data._courses[0], data._students[0]
91
+ if p_name and c_id
92
+ person = Persons.match_by_login_name(p_name)
93
+ course = Courses.match_by_course_id(c_id)
94
+ grade = Entities.Grades.match_by_course_person(c_id, p_name)
95
+ reply(:update, :grades => get_grades(course.ctype, grade)) +
96
+ reply(:empty_update, :remark => (grade ? grade.remark : ''))+
97
+ update_form_data(person) +
98
+ update_files_saved(course, p_name)
99
+ else
100
+ []
101
+ end
102
+ end
103
+
104
+ def update_students_table(course)
105
+ reply_table_columns_visible(course.ctype.files_nbr.to_i > 0, students: [2]) +
106
+ reply_table_columns_visible(course.ctype.diploma_type == %w(accredited),
107
+ students: [3]) +
108
+ reply(:update,
109
+ students:
110
+ course.students.collect { |s|
111
+ if person = Persons.match_by_login_name(s)
112
+ mean, random = if grade = Grades.match_by_course_person(course, person)
113
+ [grade.mean, grade.random]
114
+ else
115
+ ['--', nil]
116
+ end
117
+ [s, [person.full_name, mean, course.exam_files(person).length,
118
+ random ? 'OK' : 'do_sync']]
119
+ end
120
+ }.compact.sort_by { |a, b| b[0] })
121
+ end
122
+
123
+ def rpc_list_choice(session, name, data)
124
+ dputs(3) { "rpc_list_choice with #{name} - #{data.inspect}" }
125
+ ret = []
126
+ course_id = data._courses[0]
127
+ course = Courses.match_by_course_id(course_id)
128
+ case name
129
+ when 'courses'
130
+ if course
131
+ dputs(3) { 'replying' }
132
+ ret = rpc_update(session) +
133
+ reply(:empty_nonlists, :students) +
134
+ reply(:update, courses: [course_id]) +
135
+ update_students_table(course)
136
+
137
+ dputs(3) { "CType is #{course.ctype.inspect} - #{course.ctype.files_nbr.inspect}" }
138
+ buttons = []
139
+ if (nbr = course.ctype.files_nbr.to_i) > 0
140
+ dputs(3) { 'Putting buttons' }
141
+ buttons.push :transfer_files, :files_saved
142
+ buttons.push(if nbr > 1
143
+ :upload
144
+ else
145
+ ret += reply(:update,
146
+ upload_direct: course.ctype.files_arr.first) +
147
+ reply(:update, name_file_direct: 'chose student')
148
+ [:upload_direct, :name_file_direct]
149
+ end)
150
+ if Shares.match_by_name('CourseFiles')
151
+ buttons.push :prepare_files, :fetch_files
152
+ end
153
+ end
154
+ if course.students.size > 0 && course.list_students.size > 0
155
+ first = course.list_students[0][0]
156
+ ret += reply(:select, students: [first]) +
157
+ rpc_table_students(session, data.merge(students: [first]))
158
+ end
159
+ if course.ctype.diploma_type[0] == 'accredited' and
160
+ ConfigBase.has_function?(:course_client)
161
+ buttons.push :sync_server
162
+ end
163
+ buttons.each { |b|
164
+ ret += reply(:unhide, b)
165
+ }
166
+ ret += reply_visible(course.ctype.remark.to_s == '[true]', :remark)
167
+
168
+ dputs(4) { "Course is #{course} - ret is #{ret.inspect}" }
169
+ end
170
+ end
171
+
172
+ ret
173
+ end
174
+
175
+ def rpc_button_save(session, data)
176
+ dputs(3) { "Data is #{data.inspect}" }
177
+ c_id, p_name = data._courses.first, data._students.first
178
+ course = Courses.match_by_course_id(c_id)
179
+ student = Entities.Persons.match_by_login_name(p_name)
180
+ grade = Entities.Grades.match_by_course_person(c_id, p_name)
181
+ if course and student
182
+ means = new_grades(course.ctype, grade, data._grades.first)
183
+ Entities.Grades.save_data({:course => course,
184
+ :student => student,
185
+ :means => means,
186
+ :remark => data._remark})
187
+ log_msg :grades, "#{session.owner.login_name} added grades #{means.inspect} " +
188
+ "to #{student.login_name} from #{course.name} with remark -#{data._remark}-"
189
+ if data._first_name
190
+ Entities.Persons.save_data({:person_id => student.person_id,
191
+ :first_name => data._first_name,
192
+ :family_name => data._family_name,
193
+ :gender => data._gender})
194
+ end
195
+
196
+ grades = data._grades.first
197
+ element = grades ? grades._element_id.to_i : 0
198
+
199
+ update_students_table(course) +
200
+ if element >= course.ctype.tests_nbr.to_i
201
+ # Find next student
202
+ course = course.to_hash
203
+ if saved = course[:students].index { |i|
204
+ i[0] == data._students[0]
205
+ }
206
+ dputs(3) { "Found student at #{saved}" }
207
+ data._students = course[:students][(saved + 1) % course[:students].size]
208
+ dputs(3) { "Next student is #{data._students.inspect}" }
209
+ reply(:select, students: [data._students[0]]) +
210
+ rpc_table_students(session, data)
211
+ else
212
+ []
213
+ end
214
+ else
215
+ update_grade(data) +
216
+ reply(:focus, {table: 'grades', row: element, col: 1}) +
217
+ reply(:select, students: [data._students[0]])
218
+ end
219
+ end
220
+ end
221
+
222
+ def rpc_button_transfer_files(session, data)
223
+ ret = reply(:update, :txt => 'no students') +
224
+ reply(:hide, :upload)
225
+ if course = Courses.match_by_course_id(data._courses[0])
226
+ if file = course.zip_create
227
+ ret = reply(:update, :txt => 'Download skeleton: ' +
228
+ "<a target='other' href='/tmp/#{file}'>#{file}</a>") +
229
+ reply(:unhide, :upload)
230
+ end
231
+ end
232
+ reply(:window_show, :transfer) +
233
+ ret
234
+ end
235
+
236
+ def rpc_button_prepare_files(session, data)
237
+ if course = Courses.match_by_course_id(data._courses[0])
238
+ course.exas_prepare_files
239
+ end
240
+ update_grade(data)
241
+ end
242
+
243
+ def rpc_button_fetch_files(session, data)
244
+ if course = Courses.match_by_course_id(data._courses[0])
245
+ course.exas_fetch_files
246
+ end
247
+ update_grade(data)
248
+ end
249
+
250
+ def rpc_button_close(session, data)
251
+ if course = Courses.match_by_course_id(data._courses[0])
252
+ course.zip_read
253
+ reply(:window_hide) +
254
+ update_grade(data) +
255
+ reply(:auto_update, 0)
256
+ end
257
+ end
258
+
259
+ def rpc_update_with_values(session, data)
260
+ ret = []
261
+ if course = Courses.match_by_course_id(data._courses[0])
262
+ ret = reply(:update, :synching => 'Sync-state:<ul>' + course.sync_state)
263
+ if course.sync_state =~ /(finished|Error:)/
264
+ ret += reply(:auto_update, 0) +
265
+ update_students_table(course)
266
+ end
267
+ end
268
+ ret
269
+ end
270
+
271
+ def rpc_button_sync_server(session, data)
272
+ log_msg :grade, 'Syncing with server'
273
+ if course = Courses.match_by_course_id(data._courses[0])
274
+ course.sync_start
275
+
276
+ reply(:window_show, :sync) +
277
+ reply(:auto_update, -1) +
278
+ rpc_update_with_values(session, data)
279
+ else
280
+ reply(:window_show, :sync) +
281
+ reply(:update, :synching => 'Please chose a course first')
282
+ end
283
+ end
284
+
285
+ def rpc_button_upload(session, data, window_show = true)
286
+ data.to_sym!
287
+ course = Courses.match_by_course_id(data._courses[0])
288
+ student = Persons.match_by_login_name(data._students[0])
289
+ ctype = course.ctype
290
+ files_nbr = ctype.files_nbr.to_i
291
+ exam_files = course.exam_files(student)
292
+ dputs(3) { "Exam-files = #{exam_files.inspect}" }
293
+ ret = window_show ? reply(:window_show, :upload_files) : []
294
+ ret + (1..5).collect { |i|
295
+ show = :hide
296
+ ret = []
297
+ if i <= files_nbr
298
+ show = :unhide
299
+ file_nb = exam_files.index { |f| f =~ /^#{i}-/ }
300
+ file = file_nb ? exam_files[file_nb] : ''
301
+ ret += reply(:update, "name_file_#{i}" =>
302
+ "file ##{i}: #{exam_file_to_href(course, student, file)}") +
303
+ reply(:update, "upload_file_#{i}" => ctype.files_arr[i-1])
304
+ end
305
+ dputs(3) { "Return is #{ret.inspect}" }
306
+ ret +
307
+ reply(show, "name_file_#{i}") +
308
+ reply(show, "upload_file_#{i}")
309
+ }.flatten
310
+ end
311
+
312
+ def rpc_button(session, name, data)
313
+ if name =~ /^upload_file_/
314
+ number = name.sub(/.*_/, '').to_i
315
+
316
+ data.to_sym!
317
+ course = Courses.match_by_course_id(data._courses[0])
318
+ student = data._students[0]
319
+ dputs(4) { "Course is #{course} - filename is #{data._filename} " +
320
+ "student is #{student}" }
321
+ if course and student and data._filename
322
+ files_nbr = course.ctype.files_nbr.to_i
323
+
324
+ course.check_students_dir
325
+ filename = UploadFiles.escape_chars(data._filename)
326
+ src = "/tmp/#{filename}"
327
+ dst = "#{Courses.dir_exams}/#{course.name}/#{student}"
328
+ dputs(3) { "Moving #{src} to #{dst}" }
329
+ FileUtils.rm Dir.glob("#{dst}/#{number}-*")
330
+ FileUtils.mv src, "#{dst}/#{number}-#{filename}"
331
+
332
+ ret = rpc_button_upload(session, data, false) +
333
+ update_files_saved(course, student)
334
+ if (number == files_nbr) and
335
+ (files_nbr == course.exam_files(student).count)
336
+ ret += reply(:window_hide) + rpc_button_save(session, data)
337
+ end
338
+ dputs(3) { "Return is #{ret.inspect}" }
339
+ return ret
340
+ end
341
+ else
342
+ return super(session, name, data)
343
+ end
344
+ end
345
+
346
+ def new_grades(ct, grade, new_grades)
347
+ return [] unless new_grades
348
+ means = grade ? grade.means : []
349
+ i = 0
350
+ ct.tests_arr.zip(means).collect { |t, m|
351
+ i+= 1
352
+ if i == new_grades._element_id.to_i then
353
+ new_grades._grade.sub(/,/, '.').to_f
354
+ else
355
+ m ? m : 0
356
+ end
357
+ }
358
+ end
359
+
360
+ def rpc_table_grades(session, data)
361
+ c_id, p_name = data._courses.first, data._students.first
362
+ course = Courses.match_by_course_id(c_id)
363
+ student = Entities.Persons.match_by_login_name(p_name)
364
+ grade = Entities.Grades.match_by_course_person(c_id, p_name)
365
+ return unless grades = data._grades.first
366
+ return unless element = grades._element_id.to_i
367
+
368
+ if course and student
369
+ means = new_grades(course.ctype, grade, grades)
370
+ Entities.Grades.save_data({:course => course,
371
+ :student => student,
372
+ :means => means,
373
+ :remark => data._remark})
374
+ end
375
+ if element == course.ctype.tests_nbr.to_i
376
+ rpc_button_save(session, data)
377
+ else
378
+ reply(:focus, {table: 'grades', row: element, col: 1})
379
+ end
380
+ end
381
+
382
+ def rpc_table_students(session, data)
383
+ course_id = data._courses[0]
384
+ course = Courses.match_by_course_id(course_id)
385
+ student = Entities.Persons.match_by_login_name(data._students.first)
386
+ file = course.exam_files(student).first
387
+ reply(:update, name_file_direct: exam_file_to_href(course, student, file)) +
388
+ update_grade(data) +
389
+ reply(:focus, {table: 'grades', col: 1, row: 0})
390
+ end
391
+
392
+ def rpc_button_upload_direct(session, data)
393
+ rpc_button(session, 'upload_file_1', data)
394
+ end
395
+
396
+
397
+ def exam_file_to_href(course, student, file)
398
+ dst = "#{course.name}/#{student.login_name}"
399
+ file ? "<a href='/exas/#{dst}/#{file}' target='_blank'>#{file}</a>" : 'Upload file'
400
+ end
401
+ end