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 39 kB

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

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