Newer
Older
Digital_Repository / Repositories / Misc / cgi / users / review_local
  1. ######################################################################
  2. #
  3. # Review Author's Documents in the Archive
  4. #
  5. ######################################################################
  6. #
  7. # This file is part of GNU EPrints 2.
  8. #
  9. # Copyright (c) 2000-2004 University of Southampton, UK. SO17 1BJ.
  10. #
  11. # EPrints 2 is free software; you can redistribute it and/or modify
  12. # it under the terms of the GNU General Public License as published by
  13. # the Free Software Foundation; either version 2 of the License, or
  14. # (at your option) any later version.
  15. #
  16. # EPrints 2 is distributed in the hope that it will be useful,
  17. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. # GNU General Public License for more details.
  20. #
  21. # You should have received a copy of the GNU General Public License
  22. # along with EPrints 2; if not, write to the Free Software
  23. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  24. #
  25. ######################################################################
  26.  
  27. use EPrints::Database;
  28. use EPrints::EPrint;
  29. use EPrints::MetaField;
  30. use EPrints::Session;
  31. use EPrints::User;
  32.  
  33. use strict;
  34.  
  35. my $session = new EPrints::Session;
  36. exit( 0 ) unless( defined $session );
  37.  
  38. # Check we have privs
  39. if( !$session->auth_check( "deposit" ) )
  40. {
  41. $session->terminate();
  42. exit( 0 );
  43. }
  44.  
  45. my $page;
  46. my $action = $session->get_action_button();
  47. if( !defined $action )
  48. {
  49. $page = make_form( $session );
  50. }
  51. else
  52. {
  53. $page = process_form( $session, $action );
  54. }
  55.  
  56. $session->terminate();
  57.  
  58. #############################################################
  59.  
  60. sub make_form
  61. {
  62. my( $session ) = @_;
  63.  
  64. my $user = $session->current_user;
  65.  
  66. # cjg. This should maybe extract stuff you can edit
  67. # not just stuff you deposited.
  68.  
  69. my $ds = $session->get_archive()->get_dataset( "archive" );
  70. my @eprints = $user->get_owned_eprints( $ds );
  71.  
  72. my $user = $session->current_user;
  73. my $fullname = $user->render_description();
  74. my $page = $session->make_doc_fragment();
  75. my $title = $session->html_phrase( "cgi/users/review:title", name=>$fullname );
  76.  
  77. if( scalar @eprints == 0 )
  78. {
  79. $page->appendChild( $session->html_phrase(
  80. "cgi/users/review:no_docs" ) );
  81.  
  82. $page->appendChild( $session->html_phrase(
  83. "general:userhome_link" ) );
  84.  
  85. $session->build_page( $title, $page, "review_none" );
  86. $session->send_page();
  87. return;
  88. }
  89. my $r_req = $session->get_archive()->get_conf(
  90. "allow_user_removal_request" );
  91. my $checkout = $session->get_archive()->get_conf(
  92. "allow_user_checkout_eprint" );
  93.  
  94. $page->appendChild( $session->html_phrase( "cgi/users/review:blurb" ) );
  95.  
  96. if( $checkout )
  97. {
  98. $page->appendChild( $session->html_phrase(
  99. "cgi/users/review:checkout_info" ) );
  100. }
  101. if( $r_req )
  102. {
  103. $page->appendChild( $session->html_phrase(
  104. "cgi/users/review:remove_info" ) );
  105. }
  106.  
  107.  
  108.  
  109. my( $form, $table, $tr, $td, $th );
  110.  
  111. $form = $session->render_form( "post", "review" );
  112. $page->appendChild( $form );
  113. $table = $session->make_element( "table", class=>"compact", border=>0, cellspacing=>0, cellpadding=>3 );
  114. $form->appendChild( $table );
  115.  
  116. my $row = 0;
  117. foreach my $eprint ( @eprints )
  118. {
  119. $tr = $session->make_element( "tr", class=>"row_".($row?"b":"a") );
  120. $table->appendChild( $tr );
  121.  
  122. $td = $session->make_element( "td", class=>"first_col", width=>"63%" );
  123. $tr->appendChild( $td );
  124. $td->appendChild( $eprint->render_citation_link() );
  125.  
  126. $td = $session->make_element( "td", class=>"last_col", align=>"right" );
  127. $tr->appendChild( $td );
  128.  
  129.  
  130. my $a;
  131.  
  132. $a = $session->render_link( "review?_action_clone_".$eprint->get_id."=1" );
  133. $a->appendChild( $session->html_phrase("cgi/users/review:clone") );
  134. $td->appendChild( $a );
  135.  
  136. $td->appendChild( $session->make_text( ", " ) );
  137.  
  138. $a = $session->render_link( "review?_action_copy_".$eprint->get_id."=1" );
  139. $a->appendChild( $session->html_phrase("cgi/users/review:copy") );
  140. $td->appendChild( $a );
  141.  
  142. if( $checkout )
  143. {
  144. $td->appendChild( $session->make_text( ", " ) );
  145.  
  146. $a = $session->render_link( "review?_action_checkout_".$eprint->get_id."=1" );
  147. $a->appendChild( $session->html_phrase("cgi/users/review:checkout") );
  148. $td->appendChild( $a );
  149. }
  150.  
  151. if( $r_req )
  152. {
  153. $td->appendChild( $session->make_text( ", " ) );
  154.  
  155. $a = $session->render_link( "review?_action_remove_".$eprint->get_id."=1" );
  156. $a->appendChild( $session->html_phrase("cgi/users/review:req_remove") );
  157. $td->appendChild( $a );
  158. }
  159. $row=!$row;
  160. }
  161. $session->build_page( $title, $page, "review_list" );
  162. $session->send_page();
  163. return;
  164.  
  165. }
  166.  
  167. sub process_form
  168. {
  169. my( $session, $action ) = @_;
  170.  
  171. my $user = $session->current_user;
  172. my $ds = $session->get_archive()->get_dataset( "archive" );
  173.  
  174. if( $action =~ m/^(clone|copy|remove|checkout)_(.+)$/ )
  175. {
  176. my( $act, $eprintid ) = ( $1, $2 );
  177.  
  178. my $r_req = $session->get_archive()->get_conf( "allow_user_removal_request" );
  179. my $checkout = $session->get_archive()->get_conf( "allow_user_checkout_eprint" );
  180. my $eprint = EPrints::EPrint->new( $session, $eprintid, $ds );
  181. if( !defined $eprint )
  182. {
  183. $session->render_error(
  184. $session->html_phrase( "cgi/users/review:cant_find_it" ) );
  185. return;
  186. }
  187.  
  188. if( $act eq "clone" || $act eq "copy" )
  189. {
  190. my $inbox_ds = $session->get_archive()->get_dataset( "inbox" );
  191. my $copy;
  192. if( $act eq "clone" )
  193. {
  194. $copy = $eprint->clone( $inbox_ds, 1 );
  195. }
  196. else
  197. {
  198. # nofiles, no link
  199. $copy = $eprint->clone( $inbox_ds, 0, 1 );
  200. }
  201. if( defined $copy )
  202. {
  203. # Copied OK, redirect to workspace
  204. $session->redirect( 'submit?eprintid='.$copy->get_id.'&_action_edit=1' );
  205. return;
  206. }
  207. }
  208.  
  209. if( $act eq "remove" && $r_req)
  210. {
  211. unless( $user->is_owner( $eprint ) )
  212. {
  213. $session->render_error(
  214. $session->html_phrase( "cgi/users/review:cant_remove" ) );
  215. return;
  216. }
  217. &removal_request_form( $session, $eprint );
  218. return;
  219. }
  220.  
  221. if( $act eq "checkout" && $checkout)
  222. {
  223. unless( $user->is_owner( $eprint ) )
  224. {
  225. $session->render_error(
  226. $session->html_phrase( "cgi/users/review:cant_checkout" ) );
  227. return;
  228. }
  229. $eprint->move_to_inbox;
  230. $session->redirect( 'submit?eprintid='.$eprint->get_id.'&_action_edit=1' );
  231. return;
  232. }
  233. }
  234.  
  235. # If submit is defined, must have been a removal request form that was
  236. # filled out.
  237. if( $action eq "send" )
  238. {
  239. &handle_removal_request( $session, $user );
  240. return;
  241. }
  242. # no valid action or "cancel" from the remove request.
  243. &make_form( $session );
  244. }
  245.  
  246.  
  247.  
  248. ##
  249. ## remove_request_form( $session, $eprint )
  250. ##
  251. ## Display a removal request form.
  252. ##
  253.  
  254. sub removal_request_form
  255. {
  256. my( $session, $eprint ) = @_;
  257.  
  258. my $title = $session->html_phrase( "cgi/users/review:remove_title" );
  259. my $page = $session->make_doc_fragment();
  260.  
  261. $page->appendChild( $session->html_phrase( "cgi/users/review:remove_blurb",
  262. citation=>$eprint->render_citation_link() ) );
  263.  
  264. my( $form, $table, $tr, $td, $th );
  265.  
  266.  
  267. my $reason_field = EPrints::MetaField->new(
  268. archive=> $session->get_archive(),
  269. confid=>'remove_request',
  270. name=>'reason',
  271. type=>'longtext',
  272. input_rows=>15 );
  273.  
  274. $page->appendChild(
  275. $session->render_input_form(
  276. fields=>[ $reason_field ],
  277. show_help=>1,
  278. default_action=>"send",
  279. buttons=>{
  280. _order=> [ "send","cancel" ],
  281. send => $session->phrase( "cgi/users/review:send" ),
  282. cancel => $session->phrase( "cgi/users/review:cancel" )
  283. },
  284. hidden_fields=>{
  285. eprintid => $eprint->get_value( "eprintid" )
  286. },
  287. dest=>"review" ) );
  288.  
  289. $session->build_page( $title, $page, "review_remove_form" );
  290. $session->send_page();
  291. return;
  292. }
  293.  
  294.  
  295. ##
  296. ## $wrote_page = handle_removal_request( $session, $user )
  297. ##
  298. ## Handle the POSTed information from a removal request form.
  299. ##
  300.  
  301. sub handle_removal_request
  302. {
  303. my( $session, $user ) = @_;
  304. # Get the EPrint we're dealing with
  305. my $ds = $session->get_archive()->get_dataset( "archive" );
  306.  
  307. my $eprint = EPrints::EPrint->new(
  308. $session,
  309. $session->param( "eprintid" ),
  310. $ds );
  311. if( !defined $eprint )
  312. {
  313. $session->render_error(
  314. $session->html_phrase( "cgi/users/review:cant_find_it" ) );
  315. return;
  316. }
  317. if( !$user->is_owner( $eprint ) )
  318. {
  319. $session->render_error(
  320. $session->html_phrase( "cgi/users/review:cant_remove" ) );
  321. return;
  322. }
  323.  
  324. my $reason = $session->param( "reason" );
  325. my $url = $session->get_archive()->get_conf( "perl_url" ).
  326. "/users/staff/edit_eprint?eprintid=".$eprint->get_value( "eprintid" );
  327. my $rc = $session->mail_administrator(
  328. "cgi/users/review:remove_mail_subject",
  329. "cgi/users/review:remove_mail",
  330. citation=>$eprint->render_citation(),
  331. user=>$user->render_description(),
  332. email=>$user->render_value( "email" ),
  333. reason=>( EPrints::Utils::is_set( $reason ) ? $session->make_text( $reason )
  334. : $session->html_phrase( "cgi/users/review:no_reason" ) ),
  335. url=>$session->make_text( $url ) );
  336. if( !$rc )
  337. {
  338. $session->render_error(
  339. $session->html_phrase( "general:email_failed" ) );
  340. return;
  341. }
  342.  
  343. my $title = $session->html_phrase( "cgi/users/review:remove_title" );
  344. my $page = $session->make_doc_fragment();
  345. $page->appendChild( $session->html_phrase( "cgi/users/review:done" ) );
  346. $page->appendChild( $session->html_phrase( "general:userhome_link" ) );
  347. $session->build_page( $title, $page, "review_remove_done" );
  348. $session->send_page();
  349. return;
  350. }
  351.