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

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

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