You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

admin_controller.rb 40 kB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
10 years ago
​
​
10 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
10 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
10 years ago
​
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2013 Jean-Philippe Lang
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; either version 2
  7. # of the License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. class AdminController < ApplicationController
  18. layout 'admin'
  19. menu_item :projects, :only => :projects
  20. menu_item :plugins, :only => :plugins
  21. menu_item :info, :only => :info
  22. before_filter :require_admin
  23. helper :sort
  24. helper :Users
  25. helper :Settings,SchoolHelper
  26. include SortHelper
  27. def index
  28. @no_configuration_data = Redmine::DefaultData::Loader::no_data?
  29. end
  30. def export_rep_static_users
  31. rev = params[:rev]
  32. cycle = params[:cycle]
  33. cycle_name = (params[:cycle] == "admin_week" ? l(:label_per_week) : (params[:cycle] == "admin_month" ? l(:label_per_month) : l(:label_per_all)))
  34. respond_to do |format|
  35. format.html
  36. format.xls{
  37. filename = "#{l(:label_user_rep_xls)}_#{cycle_name}.xls"
  38. send_data(admin_export_rep_xls(:rev => rev, :cycle => "1"), :type => 'application/octet-stream', :filename => filename_for_content_disposition(filename))
  39. }
  40. end
  41. end
  42. # 管理员界面导出所有项目代码、提交次数统计
  43. def admin_export_rep_xls (options = {})
  44. cycle = params[:cycle]
  45. g = Gitlab.client
  46. users_results = []
  47. User.all.each do |user|
  48. unless user.mail.nil?
  49. user_mail = user.mail
  50. user.projects.where("gpid is not null").each do |project|
  51. begin
  52. g.branches(project.gpid).each do |branch|
  53. if cycle == "admin_week"
  54. statics = g.admin_rep_stats_week(project.gpid, :rev => branch.name, :user_mail => user_mail)
  55. elsif cycle == "admin_month"
  56. statics = g.admin_rep_stats_month(project.gpid, :rev => branch.name, :user_mail => user_mail)
  57. elsif cycle == "admin_all"
  58. statics = g.admin_rep_stats_all(project.gpid, :rev => branch.name, :user_mail => user_mail)
  59. end
  60. unless statics.first.commits_num == "0"
  61. user_details = {:user_id => user.id, :user_name => user.show_name, :project_id => project.id, :project_name => project.name,
  62. :commits_num => statics.first.commits_num, :add => statics.first.add, :del => statics.first.del, :changes => statics.first.changes, :branch => branch.name}
  63. users_results << user_details
  64. end
  65. end
  66. rescue Exception => e
  67. puts e
  68. end
  69. end
  70. end
  71. end
  72. xls_report = StringIO.new
  73. book = Spreadsheet::Workbook.new
  74. sheet1 = book.create_worksheet :name => l(:project_module_repository)
  75. blue = Spreadsheet::Format.new :color => :blue, :weight => :bold, :size => 10
  76. sheet1.row(0).default_format = blue
  77. sheet1.row(0).concat([l(:label_rep_user_id),l(:label_rep_user_name),l(:label_rep_project_id),l(:label_rep_project_name),l(:rep_branch),l(:rep_changeset),l(:rep_code_add),l(:rep_code_delete),l(:rep_code_modified),l(:rep_sode_time)])
  78. count_row = 1
  79. users_results.each do |static|
  80. sheet1[count_row,0] = static[:user_id]
  81. sheet1[count_row,1] = static[:user_name]
  82. sheet1[count_row,2] = static[:project_id]
  83. sheet1[count_row,3] = static[:project_name]
  84. sheet1[count_row,4] = static[:branch]
  85. sheet1[count_row,5] = static[:commits_num]
  86. sheet1[count_row,6] = static[:add]
  87. sheet1[count_row,7] = static[:del]
  88. sheet1[count_row,8] = static[:changes]
  89. sheet1[count_row,9] = Time.now.strftime('%Y-%m-%d %H:%M:%S')
  90. count_row += 1
  91. end
  92. book.write xls_report
  93. xls_report.string
  94. end
  95. # 管理员界面 项目列表
  96. def projects
  97. =begin
  98. @status = params[:status] || 1
  99. scope = Project.status(@status)
  100. scope = scope.like(params[:name]) if params[:name].present?
  101. @projects = scope.where(project_type: Project::ProjectType_project).reorder("created_on desc").all
  102. =end
  103. # 搜索功能
  104. @name = params[:name] || ""
  105. condition = "#{@name.strip}".gsub(" ","")
  106. @status = params[:status] || ""
  107. unless @status.empty?
  108. @projects = Project.where(:status=>@status).like(condition).order('created_on desc')
  109. else
  110. @projects = Project.like(condition).order('created_on desc')
  111. end
  112. # 分页
  113. @projects = paginateHelper @projects,30
  114. @page = (params['page'] || 1).to_i - 1
  115. render :action => "projects", :layout => false if request.xhr?
  116. end
  117. def contests
  118. @name = params[:name]
  119. @contests = Contest.where("id >= 780 and name like '%#{@name}%'").order('created_at desc')
  120. @contests = paginateHelper @contests,30
  121. @page = (params['page'] || 1).to_i - 1
  122. respond_to do |format|
  123. format.html
  124. end
  125. end
  126. def syllabuses
  127. @name = params[:name]
  128. @syllabuses = Syllabus.like(@name).order('created_at desc')
  129. @syllabuses = paginateHelper @syllabuses,30
  130. @page = (params['page'] || 1).to_i - 1
  131. respond_to do |format|
  132. format.html
  133. end
  134. end
  135. #为班级选择课程
  136. def select_course_syllabus
  137. @flag = false
  138. if params[:syllabus_id] && params[:course_id]
  139. course = Course.where("id = #{params[:course_id].to_i}").first
  140. unless course.nil?
  141. course.update_attribute(:syllabus_id, params[:syllabus_id].to_i)
  142. @flag = true
  143. end
  144. end
  145. if @flag
  146. render :text=> "succ"
  147. else
  148. render :text=>'fail'
  149. end
  150. end
  151. #新建课程
  152. def create_syllabus
  153. if params[:course_id]
  154. course = Course.where("id = #{params[:course_id]}").first
  155. if course
  156. @user = course.teacher
  157. syllabus = Syllabus.new
  158. syllabus.update_attributes(:title => params[:title], :eng_name => params[:eng_name], :user_id => @user.id)
  159. syllabus.description = Message.where("id = 19412").first.nil? ? nil : Message.where("id = 19412").first.content
  160. if syllabus.save
  161. course.update_attribute(:syllabus_id, params[:syllabus_id].to_i)
  162. @flag = params[:flag].to_i
  163. @course = course
  164. respond_to do |format|
  165. format.js
  166. end
  167. end
  168. end
  169. end
  170. end
  171. def courses
  172. @name = params[:name].to_s.strip.downcase
  173. if @name && @name != ""
  174. all_user_ids = Course.all.map{|course| course.tea_id}
  175. user_str_ids = search_user_by_name all_user_ids, @name
  176. user_ids = user_str_ids.empty? ? "(-1)" : "(" + user_str_ids.join(",") + ")"
  177. @courses = Course.where("tea_id in #{user_ids} or name like '%#{@name}%'").reorder("created_at desc")
  178. else
  179. @courses = Course.order('created_at desc')
  180. end
  181. @courses = paginateHelper @courses,30
  182. @page = (params['page'] || 1).to_i - 1
  183. respond_to do |format|
  184. format.html
  185. end
  186. end
  187. #未配置班级列表
  188. def non_syllabus_courses
  189. @name = params[:name].to_s.strip.downcase
  190. if @name && @name != ""
  191. @courses = Course.where("syllabus_id is null and is_delete = 0").select{ |course| (course.teacher[:lastname].to_s.downcase + course.teacher[:firstname].to_s.downcase).include?(@name) || course.name.include?(@name)}
  192. @courses = @courses.sort{|x, y| y.created_at <=> x.created_at}
  193. else
  194. @courses = Course.where("syllabus_id is null and is_delete = 0").order('created_at desc')
  195. end
  196. @courses = paginateHelper @courses,30
  197. @page = (params['page'] || 1).to_i - 1
  198. respond_to do |format|
  199. format.html
  200. end
  201. end
  202. #修改班级名称
  203. def update_course_name
  204. @course = Course.where("id = #{params[:course_id].to_i}").first
  205. unless @course.nil?
  206. @course.update_column("name", params[:name])
  207. respond_to do |format|
  208. format.js
  209. end
  210. end
  211. end
  212. #修改课程名称
  213. def update_syllabus_title
  214. @syllabus = Syllabus.where("id = #{params[:syllabus_id].to_i}").first
  215. unless @syllabus.nil?
  216. @syllabus.update_column("title", params[:name])
  217. respond_to do |format|
  218. format.js
  219. end
  220. end
  221. end
  222. #管理员界面精品课程列表
  223. def excellent_courses
  224. @courses = Course.where("is_excellent =? or excellent_option =?", 1, 1 )
  225. respond_to do |format|
  226. format.html
  227. end
  228. end
  229. # 单位名称列表下的已审批按照名字排序
  230. def apply_shcool_sort
  231. @order = ""
  232. @sort = ""
  233. if params[:sort] && (params[:order] == 'name')
  234. # courses = School.find_by_sql("SELECT c.*,count(c.id) FROM courses c,course_activities ca WHERE c.id = ca.course_id AND c.name like '%#{name}%' GROUP BY c.id ORDER BY count(c.id) #{params[:sort]}, c.id desc")
  235. school = School.find_by_sql(" SELECT aas.name FROM apply_add_schools aas where aas.status = '0' ORDER BY CONVERT(aas.name USING gbk) #{params[:sort]}, aas.id asc ")
  236. @order = params[:order]
  237. @sort = params[:sort]
  238. end
  239. redirect_to unapplied_schools_url
  240. end
  241. #精品课程下的全部课程
  242. def excellent_all_courses
  243. name = params[:name]
  244. @order = ""
  245. @sort = ""
  246. if params[:sort] && (params[:order] == 'act')
  247. courses = Course.find_by_sql("SELECT c.*,count(c.id) FROM courses c,course_activities ca WHERE c.id = ca.course_id AND c.name like '%#{name}%' GROUP BY c.id ORDER BY count(c.id) #{params[:sort]}, c.id desc")
  248. @order = params[:order]
  249. @sort = params[:sort]
  250. elsif params[:sort] && (params[:order] == 'time')
  251. courses = Course.find_by_sql("SELECT * FROM courses WHERE name like '%#{name}%' ORDER BY time #{params[:sort]}, id desc")
  252. @order = params[:order]
  253. @sort = params[:sort]
  254. elsif params[:sort] && (params[:order] == 'post')
  255. courses = Course.find_by_sql("SELECT c.*, count(m.id) count FROM boards b, courses c, messages m WHERE m.board_id = b.id AND b.course_id = c.id AND c.name like '%#{name}%' GROUP BY c.id ORDER BY count #{params[:sort]}, c.id desc")
  256. @order = params[:order]
  257. @sort = params[:sort]
  258. elsif params[:sort] && (params[:order] == 'res')
  259. courses = Course.find_by_sql("SELECT c.*, count(at.container_id) cat FROM attachments at, courses c WHERE at.container_type = 'Course' AND at.container_id = c.id AND c.name like '%#{name}%' GROUP BY c.id ORDER BY cat #{params[:sort]}, id desc")
  260. @order = params[:order]
  261. @sort = params[:sort]
  262. elsif params[:sort] && (params[:order] == 'works')
  263. courses = Course.find_by_sql("SELECT c.*, count(hc.id) chc FROM courses c, homework_commons hc,student_works sw WHERE c.id = hc.course_id AND sw.homework_common_id = hc.id AND c.name like '%#{name}%' GROUP BY c.id ORDER BY chc #{params[:sort]}, id desc")
  264. @order = params[:order]
  265. @sort = params[:sort]
  266. elsif params[:sort] && (params[:order] == 'homework')
  267. courses = Course.find_by_sql("SELECT c.*, count(sw.id) csw FROM student_works sw, courses c, homework_commons hc WHERE c.id = hc.course_id AND sw.id = c.id AND c.name like '%#{name}%' GROUP BY c.id ORDER BY csw #{params[:sort]}, id desc")
  268. @order = params[:order]
  269. @sort = params[:sort]
  270. elsif params[:sort] && (params[:order] == 'std')
  271. courses = Course.find_by_sql("SELECT c.*, count(sfc.id) sfc FROM courses c, students_for_courses sfc WHERE sfc.course_id = c.id AND c.name like '%#{name}%' GROUP BY c.id ORDER BY sfc #{params[:sort]}, id desc")
  272. @order = params[:order]
  273. @sort = params[:sort]
  274. elsif params[:sort] && (params[:order] == 'open')
  275. courses = Course.find_by_sql("SELECT * FROM courses WHERE name like '%#{name}%' ORDER BY is_public #{params[:sort]},id desc")
  276. @order = params[:order]
  277. @sort = params[:sort]
  278. else
  279. courses = Course.like(name).order('created_at desc')
  280. end
  281. @courses = paginateHelper courses,30
  282. @page = (params['page'] || 1).to_i - 1
  283. respond_to do |format|
  284. format.html
  285. end
  286. end
  287. #设为精品
  288. def set_excellent_course
  289. @course = Course.find params[:id]
  290. unless @course.nil?
  291. if @course.is_excellent == 1 || @course.excellent_option == 1
  292. @course.update_column('is_excellent', 0)
  293. @course.update_column('excellent_option', 0)
  294. else
  295. @course.update_column('is_excellent', 1)
  296. end
  297. respond_to do |format|
  298. format.js
  299. end
  300. end
  301. end
  302. #取消精品
  303. def cancel_excellent_course
  304. @course = Course.find params[:id]
  305. unless @course.nil?
  306. if @course.is_excellent == 1 || @course.excellent_option == 1
  307. @course.update_column('is_excellent', 0)
  308. @course.update_column('excellent_option', 0)
  309. end
  310. end
  311. respond_to do |format|
  312. format.html{
  313. redirect_to excellent_courses_url
  314. }
  315. end
  316. end
  317. #管理员界面课程资源列表
  318. def course_resource_list
  319. if params[:sort] == 'file_size'
  320. @resource = Attachment.where(:container_type => 'Course').order("filesize desc")
  321. elsif params[:sort] == 'file_upload'
  322. @resource = Attachment.where(:container_type => 'Course').order("created_on desc")
  323. elsif params[:sort] == 'file_download_times'
  324. @resource = Attachment.where(:container_type => 'Course').order("downloads desc")
  325. else
  326. @resource = Attachment.where(:container_type => 'Course').order("created_on desc")
  327. end
  328. @resource = paginateHelper @resource,30
  329. @page = (params['page'] || 1).to_i - 1
  330. respond_to do |format|
  331. format.html
  332. end
  333. end
  334. #管理员界面項目资源列表
  335. def project_resource_list
  336. if params[:sort] == 'file_size'
  337. @pro_resource = Attachment.where(:container_type => 'Project').order("filesize desc")
  338. elsif params[:sort] == 'file_upload'
  339. @pro_resource = Attachment.where(:container_type => 'Project').order("created_on desc")
  340. elsif params[:sort] == 'file_download_times'
  341. @pro_resource = Attachment.where(:container_type => 'Project').order("downloads desc")
  342. else
  343. @pro_resource = Attachment.where(:container_type => 'Project').order("created_on desc")
  344. end
  345. @pro_resource = paginateHelper @pro_resource,30
  346. @page = (params['page'] || 1).to_i - 1
  347. respond_to do |format|
  348. format.html
  349. end
  350. end
  351. def users
  352. sort_init 'login', 'asc'
  353. sort_update %w(login firstname lastname mail admin created_on last_login_on)
  354. case params[:format]
  355. when 'xml', 'json'
  356. @offset, @limit = api_offset_and_limit({:limit => 50})
  357. else
  358. @limit = 50 #per_page_option
  359. end
  360. @status = params[:status] || 1
  361. scope = User.logged.status(@status)
  362. scope = User.like(params[:name]) if params[:name].present?
  363. scope = scope.in_group(params[:group_id]) if params[:group_id].present?
  364. @user_count = scope.count
  365. @user_pages = Paginator.new @user_count, @limit, params['page']
  366. @offset ||= @user_pages.offset
  367. @users = scope.order(sort_clause).limit(@limit).offset(@offset).all
  368. respond_to do |format|
  369. format.html {
  370. @groups = Group.all.sort
  371. }
  372. format.api
  373. end
  374. end
  375. # 系统消息
  376. def messages
  377. @admin_messages = SystemMessage.new
  378. end
  379. def plugins
  380. @plugins = Redmine::Plugin.all
  381. end
  382. # Loads the default configuration
  383. # (roles, trackers, statuses, workflow, enumerations)
  384. def default_configuration
  385. if request.post?
  386. begin
  387. Redmine::DefaultData::Loader::load(params[:lang])
  388. flash[:notice] = l(:notice_default_data_loaded)
  389. rescue Exception => e
  390. flash[:error] = l(:error_can_t_load_default_data, e.message)
  391. end
  392. end
  393. redirect_to admin_url
  394. end
  395. def test_email
  396. raise_delivery_errors = ActionMailer::Base.raise_delivery_errors
  397. # Force ActionMailer to raise delivery errors so we can catch it
  398. ActionMailer::Base.raise_delivery_errors = true
  399. begin
  400. @test = Mailer.test_email(User.current).deliver
  401. flash[:notice] = l(:notice_email_sent, User.current.mail)
  402. rescue Exception => e
  403. flash[:error] = l(:notice_email_error, e.message)
  404. end
  405. ActionMailer::Base.raise_delivery_errors = raise_delivery_errors
  406. redirect_to settings_url(:tab => 'notifications')
  407. end
  408. def info
  409. @db_adapter_name = ActiveRecord::Base.connection.adapter_name
  410. @checklist = [
  411. [:text_default_administrator_account_changed, User.default_admin_account_changed?],
  412. [:text_file_repository_writable, File.writable?(Attachment.storage_path)],
  413. [:text_plugin_assets_writable, File.writable?(Redmine::Plugin.public_directory)],
  414. [:text_rmagick_available, Object.const_defined?(:Magick)]
  415. ]
  416. end
  417. #管理功能用户列表的搜索
  418. def search
  419. sort_init 'login', 'asc'
  420. sort_update %w(login firstname lastname mail admin created_on last_login_on)
  421. case params[:format]
  422. when 'xml', 'json'
  423. @offset, @limit = api_offset_and_limit({:limit => 15})
  424. else
  425. @limit = 15#per_page_option
  426. end
  427. @status = params[:status] || 1
  428. scope = User.logged.status(@status)
  429. scope = scope.like(params[:name],params[:search_by][:id]) if params[:name].present?
  430. @user_count = scope.count
  431. @user_pages = Paginator.new @user_count, @limit, params['page']
  432. @user_base_tag = params[:id] ? 'base_users':'base'
  433. @users = scope.order(sort_clause).offset(@user_pages.offset).limit(@user_pages.per_page).all
  434. respond_to do |format|
  435. format.html {
  436. @groups = Group.all.sort
  437. }
  438. format.api
  439. end
  440. end
  441. #首页定制
  442. def first_page_made
  443. if request.get?
  444. @first_page = FirstPage.find_by_page_type('project')
  445. elsif request.post?
  446. @first_page = FirstPage.find_by_page_type('project')
  447. @first_page.web_title = params[:web_title]
  448. @first_page.description = params[:first_page][:description]
  449. #@first_page.title = params[:title]
  450. @first_page.image_width = params[:image_width]
  451. @first_page.image_height = params[:image_height]
  452. @first_page.sort_type = params[:sort_type]
  453. @first_page.show_course = params[:show_course]
  454. @first_page.show_contest = params[:show_contest]
  455. if @first_page.save
  456. respond_to do |format|
  457. flash[:notice] = l(:notice_successful_update)
  458. format.html {
  459. redirect_to first_page_made_url
  460. }
  461. format.api { render_api_ok }
  462. #format.json { render json: @first_page, status: :created, location: @first_page }
  463. end
  464. else
  465. respond_to do |format|
  466. flash.now[:error] = "#{l :label_first_page_create_fail}: #{@first_page.errors.full_messages[0]}"
  467. format.html {
  468. render :action => 'first_page_made'
  469. }
  470. format.api { render_validation_errors(@first_page) }
  471. #format.json { render json: @first_page.errors, status: :unprocessable_entity }
  472. end
  473. end
  474. end
  475. end
  476. def course_page_made
  477. if request.get?
  478. @course_page = FirstPage.find_by_page_type('course')
  479. @first_page = FirstPage.find_by_page_type('project')
  480. elsif request.post?
  481. @first_page = FirstPage.find_by_page_type('project')
  482. @course_page = FirstPage.find_by_page_type('course')
  483. @first_page.web_title = params[:web_title]
  484. @course_page.web_title = params[:web_title]
  485. @course_page.title = params[:course_title]
  486. @course_page.image_width = params[:image_width]
  487. @course_page.image_height = params[:image_height]
  488. @course_page.description = params[:course_description]
  489. if @first_page.save && @course_page.save
  490. respond_to do |format|
  491. format.html {
  492. flash[:notice] = l(:notice_successful_update)
  493. redirect_to course_page_made_url
  494. }
  495. format.api { render_api_ok }
  496. end
  497. else
  498. respond_to do |format|
  499. flash.now[:error] = "#{l :label_first_page_create_fail}: #{@first_page.errors.full_messages[0]}\n\t#{@course_page.errors.full_messages[0]}"
  500. #flash.now[:error] = "#{l :label_first_page_create_fail}: #{@course_page.errors.full_messages[0]}"
  501. format.html {
  502. render :action => 'course_page_made'
  503. }
  504. format.api { render_validation_errors(@first_page) }
  505. format.api { render_validation_errors(@course_page) }
  506. end
  507. end
  508. end
  509. end
  510. def contest_page_made
  511. if request.get?
  512. @contest_page = FirstPage.find_by_page_type('contest')
  513. @first_page = FirstPage.find_by_page_type('project')
  514. elsif request.post?
  515. @first_page = FirstPage.find_by_page_type('project')
  516. @contest_page = FirstPage.find_by_page_type('contest')
  517. @first_page.web_title = params[:web_title]
  518. @contest_page.web_title = params[:web_title]
  519. @contest_page.title = params[:contest_title]
  520. @contest_page.image_width = params[:image_width]
  521. @contest_page.image_height = params[:image_height]
  522. @contest_page.description = params[:contest_description]
  523. if @first_page.save && @contest_page.save
  524. respond_to do |format|
  525. format.html {
  526. flash[:notice] = l(:notice_successful_update)
  527. redirect_to contest_page_made_url
  528. }
  529. format.api { render_api_ok }
  530. end
  531. else
  532. respond_to do |format|
  533. flash.now[:error] = "#{l :label_first_page_create_fail}: #{@first_page.errors.full_messages[0]}\n\t#{@contest_page.errors.full_messages[0]}\n\t#{@notification.errors.full_messages[0]}"
  534. format.html {
  535. render :action => 'contest_page_made'
  536. }
  537. format.api { render_validation_errors(@first_page) }
  538. format.api { render_validation_errors(@contest_page) }
  539. end
  540. end
  541. end
  542. end
  543. def web_footer_made
  544. if request.get?
  545. @organizer = WebFooterOranizer.first
  546. @first_page = FirstPage.find_by_page_type('project')
  547. #@notification = ContestNotification.all.first;
  548. elsif request.post?
  549. @first_page = FirstPage.find_by_page_type('project')
  550. @first_page.web_title = params[:web_title]
  551. @organizer = WebFooterOranizer.first
  552. if @organizer.nil?
  553. @organizer = WebFooterOranizer.new
  554. end
  555. @organizer.name = params[:organizer_name]
  556. @organizer.description = params[:web_footer_oranizer][:description]
  557. if @first_page.save && @organizer.save
  558. respond_to do |format|
  559. format.html {
  560. flash[:notice] = l(:notice_successful_update)
  561. redirect_to web_footer_made_url
  562. }
  563. format.api { render_api_ok }
  564. end
  565. else
  566. respond_to do |format|
  567. flash.now[:error] = "#{l :label_first_page_create_fail}: #{@first_page.errors.full_messages[0]}\n\t#{@organizer.errors.full_messages[0]}}"
  568. format.html {
  569. render :action => 'web_footer_made'
  570. }
  571. format.api { render_validation_errors(@first_page) }
  572. format.api { render_validation_errors(@contest_page) }
  573. end
  574. end
  575. end
  576. end
  577. #企业主页定制
  578. def enterprise_page_made
  579. @enterprise_page = FirstPage.find_by_page_type('enterprise')
  580. if @enterprise_page.nil?
  581. @enterprise_page = FirstPage.new
  582. @enterprise_page.page_type = 'enterprise'
  583. end
  584. if request.get?
  585. @first_page = FirstPage.find_by_page_type('project')
  586. elsif request.post?
  587. @first_page = FirstPage.find_by_page_type('project')
  588. @first_page.web_title = params[:web_title]
  589. @enterprise_page.web_title = params[:web_title]
  590. @enterprise_page.title = params[:course_title]
  591. @enterprise_page.image_width = params[:image_width]
  592. @enterprise_page.image_height = params[:image_height]
  593. @enterprise_page.description = params[:course_description]
  594. if @first_page.save && @enterprise_page.save
  595. respond_to do |format|
  596. format.html {
  597. flash[:notice] = l(:notice_successful_update)
  598. redirect_to enterprise_page_made_url
  599. }
  600. format.api { render_api_ok }
  601. end
  602. else
  603. respond_to do |format|
  604. flash.now[:error] = "#{l :label_first_page_create_fail}: #{@first_page.errors.full_messages[0]}\n\t#{@enterprise_page.errors.full_messages[0]}"
  605. #flash.now[:error] = "#{l :label_first_page_create_fail}: #{@course_page.errors.full_messages[0]}"
  606. format.html {
  607. render :action => 'enterprise_page_made'
  608. }
  609. format.api { render_validation_errors(@first_page) }
  610. format.api { render_validation_errors(@enterprise_page) }
  611. end
  612. end
  613. end
  614. end
  615. #组织
  616. def organization
  617. @organizations = Organization.find_by_sql("SELECT * FROM organizations ORDER BY created_at DESC")
  618. #@organizations = Organization.all.order("created_at desc")
  619. @organization_count = @organizations.count
  620. @organization_pages = Paginator.new @organization_count, 30, params['page'] || 1
  621. @organizations = paginateHelper @organizations,30
  622. @page = (params['page'] || 1).to_i - 1
  623. respond_to do |format|
  624. format.html
  625. end
  626. end
  627. #学校列表
  628. def schools
  629. @order = ""
  630. @sort = ""
  631. @schools = School.find_by_sql("SELECT * FROM schools ORDER BY created_at DESC")
  632. if params[:sort] && (params[:order] == 'num')
  633. @order = params[:order]
  634. @sort = params[:sort]
  635. @schools.each do |school|
  636. count = UserExtensions.where("school_id = #{school.id} or occupation = '#{school.name}'").count
  637. school[:infocount] = count.to_i
  638. end
  639. @sort == 'asc' ? (@schools = @schools.sort{|x,y| x[:infocount] <=> y[:infocount] }) : (@schools = @schools.sort{|x,y| y[:infocount] <=> x[:infocount]})
  640. end
  641. @school_count = @schools.count
  642. @school_pages = Paginator.new @school_count, 30, params['page'] || 1
  643. @schools = paginateHelper @schools,30
  644. @page = (params['page'] || 1).to_i - 1
  645. respond_to do |format|
  646. format.html
  647. end
  648. end
  649. # 单位审核
  650. # 未审批tab页
  651. # status: 0 未审批; 1 已批阅; 2已更改; 3拒绝;
  652. def applied_schools
  653. # 更新消息状态
  654. if params[:flag]
  655. applied_message = AppliedMessage.where(:id => params[:applied_message_id]).first
  656. applied_message.update_attribute(:viewed, true)
  657. end
  658. @name = params[:name] || ""
  659. condition = "#{@name.strip}".gsub(" ","")
  660. @apply_status = ApplyAddSchools.where("status = 0 and name like '%#{condition}%'").order('created_at desc')
  661. @apply_count = @apply_status.count
  662. @apply_pages = Paginator.new @apply_count, 30, params['page'] || 1
  663. @apply_status = paginateHelper @apply_status, 30
  664. @page = (params['page'] || 1).to_i - 1
  665. respond_to do |format|
  666. format.html
  667. end
  668. end
  669. # 单位审核
  670. # 已审批tab页
  671. def has_applied_schools
  672. @name = params[:name] || ""
  673. condition = "#{@name.strip}".gsub(" ","")
  674. @has_apply_status = ApplyAddSchools.where("(status = 1 or status = 2) and name like '%#{condition}%'").order('created_at desc')
  675. @has_apply_count = @has_apply_status.count
  676. @has_apply_pages = Paginator.new @has_apply_count, 30, params['page'] || 1
  677. @has_apply_status = paginateHelper @has_apply_status, 30
  678. @page = (params['page'] || 1).to_i - 1
  679. respond_to do |format|
  680. format.html
  681. end
  682. end
  683. # 单位审核:批准
  684. # 消息发送,发送对象为申请人
  685. # status: 0表示未批准; status:1表示已批准; status: 2表示已更改; status: 3表示已拒绝; status: 4表示已更改后废除的高校
  686. def approve_applied_schools
  687. applied_school = ApplyAddSchools.find params[:id]
  688. applied_message_id = applied_school.school_id
  689. applied_message = AppliedMessage.where(:applied_id => applied_message_id, :applied_type => "ApplyAddSchools")
  690. applied_message.update_all(:status => 1)
  691. applied_school.update_column('status', 1) unless applied_school.nil?
  692. school = applied_school.school
  693. school.update_attribute("province", applied_school.province)
  694. AppliedMessage.create(:user_id => applied_school.user_id, :status => 1, :viewed => 0, :applied_id => applied_school.id, :applied_type => "ApplyAddSchools", :name => applied_school.name )
  695. # School.create(:user_id => applied_school.user_id, :status => 1, :viewed => true, :applied_id => applied_school.id, :applied_type => "ApplyAddSchools", :name => applied_school.name )
  696. respond_to do |format|
  697. format.html{ redirect_to unapplied_schools_url }
  698. end
  699. end
  700. # 单位审核:更改
  701. # 修改该字段
  702. # 同步修改使用了改名称的用户单位
  703. def edit_applied_schools
  704. aas = ApplyAddSchools.find(params[:applied_id])
  705. # aas.update_attribute(:name, params[:name])
  706. #applied_add_school = ApplyAddSchools.where(:name => aas.name)
  707. school = School.find params[:school_id]
  708. begin
  709. #更新消息表的status
  710. applied_message_id = aas.school_id
  711. applied_message = AppliedMessage.where(:applied_id => applied_message_id, :applied_type => "ApplyAddSchools")
  712. applied_message.update_all(:status => 4)
  713. aas.update_attribute(:status, 2)
  714. AppliedMessage.create(:user_id => aas.user_id, :status => 2, :viewed => 0, :applied_id => aas.id, :applied_type => "ApplyAddSchools", :name => school[0].name )
  715. users = UserExtensions.where("school_id = #{aas.school_id}")
  716. users.update_all(:school_id => school[0].id)
  717. if aas.school_id != school[0].id.to_i
  718. aas.school.destroy
  719. end
  720. aas.update_attribute(:school_id, school[0].id)
  721. rescue Exception => e
  722. puts e
  723. end
  724. # applied_schools = ApplyAddSchools.find params[:applied_id]
  725. # applied_schools.update_column('name', params[:name])
  726. redirect_to unapplied_schools_url
  727. end
  728. # 单位审核:更改功能搜索合法学校弹框
  729. def all_schools
  730. apply_schools = ApplyAddSchools.where("status = 0")
  731. apply_school_ids = apply_schools.empty? ? "(-1)" : "(" + apply_schools.map{|sc| sc.school_id}.join(',') + ")"
  732. if !params[:search].nil?
  733. search = "%#{params[:search].to_s.strip.downcase}%"
  734. @schools = School.where("id not in #{apply_school_ids} and #{School.table_name}.name like :p", :p => search)
  735. #@schools = School.all
  736. else
  737. #@course = @user.courses.where("is_delete = 0 and #{Course.table_name}.id != #{homework.course_id}").select { |course| @user.allowed_to?(:as_teacher,course)}
  738. @schools = School.where("id not in #{apply_school_ids}")
  739. end
  740. @edit_id = params[:school_id]
  741. @search = params[:search]
  742. respond_to do |format|
  743. format.js
  744. end
  745. end
  746. # 单位审核:删除
  747. def delete_applied_schools
  748. applied_school = ApplyAddSchools.find(params[:id])
  749. applied_message_id = applied_school.school_id
  750. applied_message = AppliedMessage.where(:applied_id => applied_message_id, :applied_type => "ApplyAddSchools")
  751. applied_message.update_all(:status => 3)
  752. applied_school.update_attribute(:status, 3)
  753. # 未审批删除
  754. if params[:tip] == "unapplied"
  755. AppliedMessage.create(:user_id => applied_school.user_id, :status => 3, :viewed => 0, :applied_id => applied_school.id, :applied_type => "ApplyAddSchools", :name => applied_school.name )
  756. # 删除学校的用户
  757. users = UserExtensions.where("school_id = #{applied_school.school_id}")
  758. users.update_all(:school_id => nil)
  759. applied_school.school.destroy
  760. redirect_to unapplied_schools_url
  761. # 已审批删除
  762. elsif params[:tip] == "applied"
  763. applied_school.destroy
  764. redirect_to applied_schools_url
  765. end
  766. end
  767. #移动端版本管理
  768. def mobile_version
  769. @versions = PhoneAppVersion.reorder('created_at desc')
  770. @new_version = PhoneAppVersion.new
  771. end
  772. def create_version
  773. @versions = PhoneAppVersion.reorder('created_at desc')
  774. @new_version = PhoneAppVersion.new
  775. @new_version.version = params[:version]
  776. @new_version.description = params[:description]
  777. if params[:attachments][:dummy][:file].nil? || params[:attachments][:dummy][:file] == ""
  778. respond_to do |format|
  779. flash.now[:error] = "#{l :label_version_create_fail}: #{l(:label_client_need)}"
  780. #flash.now[:error] = "#{l :label_first_page_create_fail}: #{@course_page.errors.full_messages[0]}"
  781. format.html {
  782. render :action => 'mobile_version'
  783. }
  784. format.api { render_validation_errors(@new_version) }
  785. end
  786. else
  787. @new_version.save_attachments(params[:attachments] || (params[:version] && params[:version][:uploads]))
  788. if @new_version.save
  789. respond_to do |format|
  790. format.html {
  791. flash[:notice] = l(:notice_successful_create)
  792. redirect_to mobile_version_url
  793. }
  794. format.api { render_api_ok }
  795. end
  796. else
  797. respond_to do |format|
  798. flash.now[:error] = "#{l :label_version_create_fail}: #{@new_version.errors.full_messages[0]}"
  799. #flash.now[:error] = "#{l :label_first_page_create_fail}: #{@course_page.errors.full_messages[0]}"
  800. format.html {
  801. render :action => 'mobile_version'
  802. }
  803. format.api { render_validation_errors(@new_version) }
  804. end
  805. end
  806. end
  807. end
  808. #留言列表
  809. def leave_messages
  810. notes1, notes2, notes3 = '', '', ''
  811. begin
  812. notes1 = Message.find(19292).content
  813. notes2 = Message.find(19291).content
  814. notes3 = Message.find(19504).content
  815. rescue => e
  816. end
  817. @jour = JournalsForMessage.find_by_sql("SELECT * FROM journals_for_messages AS j1
  818. WHERE j1.jour_type IN ('Course','Principal') AND (j1.m_parent_id IS NULL OR (j1.m_parent_id IN (SELECT id FROM journals_for_messages WHERE jour_type IN ('Course','Principal')))) AND j1.notes !='#{notes1}' AND j1.notes !='#{notes2}' AND j1.notes !='#{notes3}' order by created_on desc")
  819. @jour = paginateHelper @jour,30
  820. @page = (params['page'] || 1).to_i - 1
  821. respond_to do |format|
  822. format.html
  823. end
  824. end
  825. #帖子
  826. def messages_list
  827. @memo = Memo.reorder("created_at desc")
  828. @memo = paginateHelper @memo,30
  829. @page = (params['page'] || 1).to_i - 1
  830. respond_to do |format|
  831. format.html
  832. end
  833. end
  834. #课程讨论区的帖子
  835. def course_messages
  836. @course_ms=Message.joins("join boards on messages.board_id=boards.id where boards.course_id is not NULL").reorder('created_on desc')
  837. @course_ms = paginateHelper @course_ms,30
  838. @page = (params['page'] || 1).to_i - 1
  839. respond_to do |format|
  840. format.html
  841. end
  842. end
  843. #项目讨论区的帖子
  844. def project_messages
  845. @project_ms=Message.joins("join boards on messages.board_id=boards.id where boards.project_id != -1").reorder('created_on desc')
  846. @project_ms = paginateHelper @project_ms,30
  847. @page = (params['page'] || 1).to_i - 1
  848. respond_to do |format|
  849. format.html
  850. end
  851. end
  852. #通知
  853. def notices
  854. @news = News.where('course_id is not NULL').order('created_on desc')
  855. @news = paginateHelper @news,30
  856. @page = (params['page'] || 1).to_i - 1
  857. respond_to do |format|
  858. format.html
  859. end
  860. end
  861. #最近登录用户列表
  862. def latest_login_users
  863. scope = User.order('last_login_on desc')
  864. scope = scope.where("last_login_on>= '#{params[:startdate]} 00:00:00'") if params[:startdate].present?
  865. scope =scope.where("last_login_on <= '#{params[:enddate]} 23:59:59'") if params[:enddate].present?
  866. @users = scope
  867. @users = paginateHelper @users,30
  868. @page = (params['page'] || 1).to_i - 1
  869. respond_to do |format|
  870. format.html
  871. end
  872. end
  873. #最近登录老师列表
  874. def latest_login_teachers
  875. scope = User.find_by_sql("SELECT * FROM users,user_extensions WHERE users.id = user_extensions.user_id AND user_extensions.identity=0 ORDER BY last_login_on DESC")
  876. if params[:startdate].present?
  877. scope = User.find_by_sql("SELECT * FROM users,user_extensions WHERE users.id = user_extensions.user_id AND user_extensions.identity=0 and last_login_on>= '#{params[:startdate]} 00:00:00' ORDER BY last_login_on DESC")
  878. end
  879. if params[:enddate].present?
  880. scope = User.find_by_sql("SELECT * FROM users,user_extensions WHERE users.id = user_extensions.user_id AND user_extensions.identity=0 and last_login_on <= '#{params[:enddate]} 23:59:59' ORDER BY last_login_on DESC")
  881. end
  882. @teachers = scope
  883. @teachers = paginateHelper @teachers,30
  884. @page = (params['page'] || 1).to_i - 1
  885. respond_to do |format|
  886. format.html
  887. end
  888. end
  889. #作业
  890. def homework
  891. #@homework = HomeworkCommon.order('end_time desc')
  892. if params[:type] == "2"
  893. @homework = HomeworkCommon.where(:homework_type => 2).order( 'created_at desc ')
  894. else
  895. @homework = HomeworkCommon.order( 'created_at desc ')
  896. end
  897. @homework = paginateHelper @homework,30
  898. @page = (params['page'] || 1).to_i - 1
  899. respond_to do |format|
  900. format.html
  901. end
  902. end
  903. #代码测试列表
  904. def code_work_tests
  905. #求出所有条数
  906. tCount = CodeTests.count()
  907. #设置个空的数组 以便paginateHelper来分页
  908. @code_work_tests = []
  909. if tCount >= 1
  910. @code_work_tests[tCount-1] = {}
  911. end
  912. @code_work_tests = paginateHelper @code_work_tests,30
  913. @page = (params['page'] || 1).to_i - 1
  914. #取出需要的那一页数据
  915. tStart = @page*30
  916. @code_work_tests = CodeTests.find_by_sql("select * from code_tests order by id desc limit #{tStart},30 ")
  917. #取出各个作品是否是模拟答题的
  918. is_test = {}
  919. #作品是否存在
  920. link_swork = {}
  921. #作业是否存在
  922. link_hwork = {}
  923. @code_work_tests.each do |test|
  924. #作品是否存在
  925. if is_test[test['student_work_id']] != nil
  926. test['link_swork'] = link_swork[test['student_work_id']]
  927. test['is_test'] = is_test[test['student_work_id']]
  928. else
  929. work = StudentWork.where("id=?",test['student_work_id']).first
  930. test['link_swork'] = !work.nil?
  931. test['is_test'] = work.nil? ? false : work.is_test
  932. #test['is_test'] = CodeTests.find_by_sql("select is_test from student_works where id = #{test['student_work_id']}").first['is_test']
  933. is_test[test['student_work_id']] = test['is_test']
  934. link_swork[test['student_work_id']] = test['link_swork']
  935. end
  936. #作业是否存在
  937. if link_hwork[test['homework_id']] != nil
  938. test['link_hwork'] = link_hwork[test['homework_id']]
  939. else
  940. hwork = HomeworkCommon.where("id=?",test['homework_id']).first
  941. test['link_hwork'] = !hwork.nil?
  942. link_hwork[test['homework_id']] = test['link_hwork']
  943. end
  944. end
  945. respond_to do |format|
  946. format.html
  947. end
  948. end
  949. #分享作业申请
  950. def apply_for_homework
  951. homeworks = ApplyHomework.where("user_id != 0")
  952. @homework = paginateHelper homeworks,30
  953. @page = (params['page'] || 1).to_i - 1
  954. respond_to do |format|
  955. format.html
  956. end
  957. end
  958. end

软件技术创新是当今国家整体创新能力的重要基础和发展引擎。近年来,大众参与的软件创新与创业活动已经成为网络时代软件开发和应用的新形态,正在快速改变着全球软件创新模式和软件产业格局。 ...