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

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

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