Newer
Older
Digital_Repository / Repositories / Misc / cgi / users / home_local
nstanger on 30 Nov 2005 13 KB - Added local copy of review script.
  1. ######################################################################
  2. #
  3. # EPrints Author Home
  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::User;
  28. use EPrints::Database;
  29. use EPrints::Session;
  30. use EPrints::EPrint;
  31.  
  32. use strict;
  33.  
  34.  
  35. ######################################################################
  36. #
  37. # Session initialisation
  38. #
  39. ######################################################################
  40.  
  41. my $session = new EPrints::Session;
  42. exit( 0 ) unless( defined $session );
  43.  
  44. # Any user can view this page, but most BE a user.
  45. if( !$session->auth_check )
  46. {
  47. $session->terminate();
  48. exit( 0 );
  49. }
  50.  
  51. # If we were sent here by change_user then we have an icky url
  52. # eg .../home/username rather than .../home
  53. # let's clean it up...
  54. if( $ENV{PATH_INFO} ne "" )
  55. {
  56. $session->redirect( $session->get_archive()->get_conf( "userhome" ) );
  57. $session->terminate();
  58. exit;
  59. }
  60. my $user = $session->current_user;
  61.  
  62. my $fullname = $user->render_description();
  63.  
  64. my $probs = $user->validate();
  65. my $valid_user = ( scalar @{$probs} == 0 );
  66.  
  67. # If not a valid user then redirect them to the user-info page.
  68. # This'll give us info like "name".
  69. unless( $valid_user )
  70. {
  71. $session->redirect( "record" );
  72. $session->terminate();
  73. exit;
  74. }
  75.  
  76. ######################################################################
  77. #
  78. # Render page
  79. #
  80. ######################################################################
  81.  
  82. my( $page, $dt, $dd, $a );
  83. my( $table, $tr, $td );
  84.  
  85.  
  86.  
  87. my $changeuserpath = "/change_user/".($user->get_value( "username" ));
  88. my $securehost = $session->get_archive->get_conf( "securehost" );
  89. my $securepath = $session->get_archive->get_conf( "securepath" );
  90. if( EPrints::Utils::is_set( $securehost ) )
  91. {
  92. $changeuserpath = $securepath.$changeuserpath;
  93. }
  94.  
  95. my $tools = [
  96. ### Create New Item
  97. {
  98. location=>"create",
  99. code=>"new_item",
  100. page=>"submit?_action_new=1",
  101. priv=>"deposit"
  102. },
  103. ### Change User Info
  104. {
  105. location=>"user",
  106. code=>"change",
  107. page=>"record",
  108. invpriv=>"no_edit_own_record"
  109. },
  110. ### Change subscription options
  111. {
  112. location=>"user",
  113. code=>"subscribe",
  114. page=>"subscribe",
  115. priv=>"subscription"
  116. },
  117. ### View the archive status page
  118. {
  119. location=>"staff",
  120. code=>"status",
  121. page=>"status",
  122. priv=>"view-status"
  123. },
  124. ### Review items we've got in archive
  125. {
  126. location=>"review",
  127. code=>"review",
  128. page=>"review_local",
  129. priv=>"deposit"
  130. },
  131. ### View the Editor submission buffer
  132. {
  133. location=>"staff",
  134. code=>"staff_buffer",
  135. page=>"staff/buffer_local",
  136. priv=>"editor"
  137. },
  138. ### Staff EPrints Search
  139. {
  140. location=>"staff",
  141. code=>"staff_eprint_search",
  142. page=>"search",
  143. priv=>"staff-view"
  144. },
  145. ### Staff User Search
  146. {
  147. location=>"staff",
  148. code=>"staff_user_search",
  149. page=>"search/users",
  150. priv=>"staff-view"
  151. },
  152. ### Add New User
  153. {
  154. location=>"staff",
  155. code=>"staff_add_user",
  156. page=>"staff/add_user",
  157. priv=>"edit-user"
  158. },
  159. ### Change Email
  160. {
  161. location=>"user",
  162. code=>"change_email",
  163. page=>"change_email",
  164. priv=>"change-email"
  165. },
  166. ### Use the Subject Edit Tool
  167. {
  168. location=>"staff",
  169. code=>"staff_edit_subject",
  170. page=>"staff/edit_subject",
  171. priv=>"edit-subject"
  172. },
  173. ### Change the current login user
  174. {
  175. location=>"user",
  176. code=>"change_user",
  177. page=>$changeuserpath,
  178. priv=>"change-user"
  179. }
  180. ];
  181.  
  182.  
  183.  
  184.  
  185. my $sb = $session->get_archive()->get_conf( "skip_buffer" );
  186. my $dls = {};
  187. my $tool;
  188. foreach $tool (@{$tools})
  189. {
  190. # disable buffer option if skip_buffer is in effect:
  191. if( $tool->{code} eq 'staff_buffer' && defined $sb && $sb == 1 )
  192. {
  193. next;
  194. }
  195.  
  196.  
  197. if( defined $tool->{priv} )
  198. {
  199. next unless $user->has_priv( $tool->{priv} );
  200. }
  201. if( defined $tool->{invpriv} )
  202. {
  203. next if $user->has_priv( $tool->{invpriv} );
  204. }
  205. if( !defined $dls->{$tool->{location}} )
  206. {
  207. $dls->{$tool->{location}} = $session->make_element( "div" );
  208. }
  209. my $dl = $dls->{$tool->{location}};
  210. $dt = $session->make_element( "p", style=>"font-weight: bold;" );
  211. $a = $session->render_link( $tool->{page} );
  212. $a->appendChild( $session->html_phrase( "cgi/users/home:".$tool->{code}."_link" ) );
  213. $dt->appendChild( $a );
  214. $dl->appendChild( $dt );
  215.  
  216. $dd = $session->make_element( "div", style=>"padding: 0em 2em 0em 2em;" );
  217. $dd->appendChild( $session->html_phrase( "cgi/users/home:".$tool->{code}."_info" ) );
  218. $dl->appendChild( $dd );
  219. }
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228. $page = $session->make_doc_fragment();
  229.  
  230. ### Welcome author blurb
  231. $page->appendChild( $session->html_phrase( "cgi/users/home:intro" ) );
  232.  
  233.  
  234. ### User workspace
  235. if( $user->has_priv( "deposit" ) )
  236. {
  237. $page->appendChild( $session->html_phrase( "cgi/users/home:workspace" ) );
  238. $table = $session->make_element("table",style=>"padding-bottom:2em; margin-top:-0.5em;",width=>"100%");
  239. $tr = $session->make_element("tr");
  240. $table->appendChild( $tr );
  241. $page->appendChild( $table );
  242.  
  243. $td = $session->make_element("td",valign=>"top",width=>"50%", style=>"padding-right: 1.5em;");
  244. $tr->appendChild( $td );
  245.  
  246.  
  247. ### Begin new item
  248. $td->appendChild( $dls->{create} );
  249.  
  250. $td = $session->make_element("td",valign=>"top",width=>"50%", style=>"padding-left: 1.5em;");
  251. $tr->appendChild( $td );
  252.  
  253.  
  254. ### Review items in repository
  255. $td->appendChild( $dls->{review} );
  256.  
  257. $tr = $session->make_element("tr");
  258. $table->appendChild( $tr );
  259.  
  260. $td = $session->make_element("td",valign=>"top",width=>"50%",style=>"padding-right:1em;");
  261. $tr->appendChild( $td );
  262.  
  263.  
  264. ### Workspace
  265. $td->appendChild( &render_workspace( $session, $user ) );
  266.  
  267.  
  268. ### Pending
  269. $td->appendChild( &render_pending( $session, $user ) );
  270.  
  271. $td = $session->make_element("td",valign=>"top",width=>"50%",style=>"padding-left:1em;");
  272. $tr->appendChild( $td );
  273.  
  274.  
  275. ### Recent Additions
  276. $td->appendChild( &render_recent( $session, $user, 10 ) );
  277. }
  278.  
  279.  
  280. ### User options
  281. $page->appendChild( $session->html_phrase( "cgi/users/home:options" ) );
  282.  
  283. $table = $session->make_element("table", style=>"margin-top:-1.5em;");
  284. $tr = $session->make_element("tr");
  285. $table->appendChild( $tr );
  286. $page->appendChild( $table );
  287.  
  288. if( defined $dls->{user} )
  289. {
  290. if ( defined $dls->{staff} )
  291. {
  292. $td = $session->make_element("td",valign=>"top", width=>"50%", style=>"padding-right: 1.5em;");
  293. $td->appendChild( $session->html_phrase( "cgi/users/home:basic_options" ) );
  294. }
  295. else
  296. {
  297. $td = $session->make_element("td",valign=>"top");
  298. }
  299. $tr->appendChild( $td );
  300. $td->appendChild( $dls->{user} );
  301. }
  302.  
  303.  
  304. if( defined $dls->{staff} )
  305. {
  306. if ( defined $dls->{user} )
  307. {
  308. $td = $session->make_element("td",valign=>"top", style=>"padding-left: 1.5em;");
  309. $td->appendChild( $session->html_phrase( "cgi/users/home:staff_options" ) );
  310. }
  311. else
  312. {
  313. $td = $session->make_element("td",valign=>"top");
  314. }
  315. $tr->appendChild( $td );
  316. $td->appendChild( $dls->{staff} );
  317. }
  318.  
  319.  
  320.  
  321. $session->build_page(
  322. $session->html_phrase(
  323. "cgi/users/home:user_home",
  324. name => $fullname ),
  325. $page,
  326. "user_home" );
  327. $session->send_page();
  328.  
  329. $session->terminate();
  330. exit;
  331.  
  332.  
  333.  
  334. ######################################################################
  335. #
  336. # render_workspace( $session, $user )
  337. #
  338. # This puts all of the user's items in the inbox table in a form.
  339. # The buttons will POST stuff to the submit script, with the possible
  340. # actions:
  341. #
  342. # New (Create a new EPrint)
  343. # Edit (Edit a selected EPrint)
  344. # Clone (Clone the selected EPrint)
  345. # Delete (Delete the selected EPrint)
  346. # Deposit (Submit the selected EPrint to the archive)
  347. #
  348. #
  349. # If the user has no items in the inbox, a single button is drawn,
  350. # Allowing them to start the upload process.
  351. #
  352. ######################################################################
  353.  
  354. sub render_workspace
  355. {
  356. my( $session, $user ) = @_;
  357.  
  358. ### Get the actual items in the workspace
  359. my $ds = $session->get_archive()->get_dataset( "inbox" );
  360. my @eprints = $user->get_owned_eprints( $ds );
  361.  
  362. my( $html, $form, $div );
  363.  
  364. $html = $session->make_doc_fragment();
  365. $html->appendChild( $session->html_phrase( "cgi/users/home:docs" ));
  366.  
  367. if( scalar @eprints == 0)
  368. {
  369. # No items, oh well.
  370. $html->appendChild( $session->html_phrase( "cgi/users/home:no_depositing" ));
  371. return $html;
  372. }
  373.  
  374. # One or more items in workspace.
  375. # Render a form to let the user fiddle with them.
  376.  
  377. my( $table, $tr, $td );
  378.  
  379. $table = $session->make_element( "table",
  380. cellpadding=>3,
  381. cellspacing=>0,
  382. border=>0,
  383. width=>"100%",
  384. class=>"compact" );
  385. my $e;
  386. my $cnt = 0;
  387. my $row = 0;
  388. foreach $e (@eprints)
  389. {
  390. $tr = $session->make_element( "tr", class=>"row_".($row?"b":"a") );
  391. $table->appendChild( $tr );
  392. $td = $session->make_element( "td", class=>'first_col userpage_table_emph', width=>"40%" );
  393. $tr->appendChild( $td );
  394. $td->appendChild( $e->render_description() );
  395. $td = $session->make_element( "td", class=>'last_col', width=>"60%", align=>"right" );
  396. $tr->appendChild( $td );
  397. # $td->appendChild( $session->html_phrase(
  398. # "cgi/users/home:accepted_at",
  399. # time=>$e->render_value( "datestamp" ) ) );
  400. my $a;
  401.  
  402. $a = $session->render_link( "submit?eprintid=".$e->get_id."&_action_edit=1" );
  403. $a->appendChild( $session->html_phrase("cgi/users/home:action_edit") );
  404. $td->appendChild( $a );
  405.  
  406. $td->appendChild( $session->make_text( ", " ) );
  407.  
  408. $a = $session->render_link( "submit?eprintid=".$e->get_id."&_action_submit=1" );
  409. $a->appendChild( $session->html_phrase("cgi/users/home:action_submit") );
  410. $td->appendChild( $a );
  411.  
  412. $td->appendChild( $session->make_text( ", " ) );
  413.  
  414. $a = $session->render_link( "submit?eprintid=".$e->get_id."&_action_copy=1" );
  415. $a->appendChild( $session->html_phrase("cgi/users/home:action_copy") );
  416. $td->appendChild( $a );
  417.  
  418. $td->appendChild( $session->make_text( ", " ) );
  419.  
  420. $a = $session->render_link( "submit?eprintid=".$e->get_id."&_action_delete=1" );
  421. $a->appendChild( $session->html_phrase("cgi/users/home:action_delete") );
  422. $td->appendChild( $a );
  423. $row=!$row;
  424. }
  425.  
  426. $html->appendChild( $session->html_phrase( "cgi/users/home:depositing" ) );
  427. $html->appendChild( $table );
  428.  
  429. return $html;
  430. }
  431.  
  432.  
  433.  
  434. ######################################################################
  435. #
  436. # render_pending( $session, $user)
  437. #
  438. # Render any items that are in the submissions buffer, if any
  439. #
  440. ######################################################################
  441.  
  442. sub render_pending
  443. {
  444. my( $session, $user ) = @_;
  445.  
  446. ### Get the items in the buffer
  447. my $ds = $session->get_archive()->get_dataset( "buffer" );
  448. my @eprints = $user->get_owned_eprints( $ds );
  449.  
  450. my $html = $session->make_doc_fragment();
  451.  
  452. $html->appendChild( $session->html_phrase( "cgi/users/home:pending_title" ) );
  453.  
  454. if( scalar @eprints == 0 )
  455. {
  456. $html->appendChild( $session->html_phrase( "cgi/users/home:no_pending" ) );
  457. }
  458. else
  459. {
  460. my( $table, $tr, $td );
  461.  
  462. $table = $session->make_element( "table",
  463. cellpadding=>3,
  464. cellspacing=>0,
  465. border=>0,
  466. width=>"100%",
  467. class=>"compact" );
  468. $html->appendChild( $table );
  469. my $row = 0;
  470. foreach my $e (@eprints)
  471. {
  472. $tr = $session->make_element( "tr", class=>"row_".($row?"b":"a") );
  473. $table->appendChild( $tr );
  474. $td = $session->make_element( "td", class=>"first_col userpage_table_emph", width=>"50%" );
  475. $tr->appendChild( $td );
  476. $td->appendChild( $e->render_description() );
  477. $td = $session->make_element( "td", class=>"last_col", width=>"50%", align=>"right" );
  478. $tr->appendChild( $td );
  479. $td->appendChild( $session->html_phrase(
  480. "cgi/users/home:deposited_at",
  481. time=>$e->render_value( "datestamp" ) ) );
  482. $row=!$row;
  483. }
  484. }
  485. return $html;
  486. }
  487.  
  488. ######################################################################
  489. #
  490. # render_recent( $session, $user, $max, $review )
  491. #
  492. # Render any items that have been recently accepted into the main
  493. # archive.
  494. #
  495. ######################################################################
  496.  
  497. sub render_recent
  498. {
  499. my( $session, $user, $max ) = @_;
  500. ### Get the items in the buffer
  501. my $ds = $session->get_archive()->get_dataset( "archive" );
  502. my @eprints = $user->get_owned_eprints( $ds );
  503.  
  504. my $html = $session->make_doc_fragment();
  505.  
  506. $html->appendChild( $session->html_phrase( "cgi/users/home:recent_title" ) );
  507.  
  508. if( scalar @eprints == 0 )
  509. {
  510. $html->appendChild( $session->html_phrase( "cgi/users/home:no_recent" ) );
  511. }
  512. else
  513. {
  514. my( $table, $tr, $td );
  515. $table = $session->make_element( "table",
  516. cellpadding=>3,
  517. cellspacing=>0,
  518. border=>0,
  519. width=>"100%",
  520. class=>"compact" );
  521. $html->appendChild( $table );
  522. my $e;
  523. my $cnt = 0;
  524. my $row = 0;
  525. foreach $e (reverse @eprints)
  526. #cjg not exactly the right way!
  527. #cjg should really do it by deposit date
  528. {
  529. last if( $cnt++ == $max );
  530. $tr = $session->make_element( "tr", class=>"row_".($row?"b":"a") );
  531. $table->appendChild( $tr );
  532. $td = $session->make_element( "td", class=>"first_col userpage_table_emph", width=>"50%" );
  533. $tr->appendChild( $td );
  534. my $a = $session->render_link( $e->get_url() );
  535. $a->appendChild( $e->render_description() );
  536. $td->appendChild( $a );
  537. $td = $session->make_element( "td", class=>"last_col", width=>"50%", align=>"right" );
  538. $tr->appendChild( $td );
  539. $td->appendChild( $session->html_phrase(
  540. "cgi/users/home:accepted_at",
  541. time=>$e->render_value( "datestamp" ) ) );
  542. $row=!$row;
  543. }
  544. }
  545.  
  546. return $html;
  547. }
  548.