/reason_4.0/lib/core/classes/admin/modules/sharing.php

https://github.com/luthercollege/reason_package · PHP · 111 lines · 81 code · 10 blank · 20 comment · 8 complexity · d0b5b98270ccb6e81f67335a4b7b9d29 MD5 · raw file

  1. <?php
  2. /**
  3. * @package reason
  4. * @subpackage admin
  5. */
  6. /**
  7. * Include the default module
  8. */
  9. reason_include_once('classes/admin/modules/associator.php');
  10. /**
  11. * An administrative module that provides an interface to borrow entities from another site
  12. *
  13. * You'd think this would be called BorrowModule, but you would be incorrect.
  14. */
  15. class SharingModule extends AssociatorModule // {{{
  16. {
  17. function SharingModule( &$page ) // {{{
  18. {
  19. $this->admin_page =& $page;
  20. } // }}}
  21. function should_run()
  22. {
  23. return true;
  24. }
  25. function init() // {{{
  26. {
  27. $this->head_items->add_stylesheet(REASON_ADMIN_CSS_DIRECTORY.'sharing.css');
  28. reason_include_once( 'classes/sharing_filter.php' );
  29. reason_include_once( 'content_listers/sharing.php' );
  30. $type = new entity( $this->admin_page->type_id );
  31. // save the type entity in an object scope
  32. $this->rel_type = $type;
  33. $this->get_views( $type->id() );
  34. if( empty( $this->views ) )//add generic lister if not already present
  35. $this->views = array();
  36. else
  37. {
  38. reset( $this->views );
  39. $c = current( $this->views );
  40. if( $c )
  41. {
  42. $lister = $c->id();
  43. $this->admin_page->request[ 'lister' ] = $lister;
  44. }
  45. else
  46. $lister = '';
  47. }
  48. $this->admin_page->title = ( $type->get_value( 'plural_name' ) ? $type->get_value( 'plural_name' ) : $type->get_value('name') );
  49. if($icon_url = reason_get_type_icon_url($type,false))
  50. {
  51. $this->admin_page->title = '<img src="'.$icon_url.'" alt="" /> '.$this->admin_page->title;
  52. }
  53. if( $this->admin_page->is_second_level() )
  54. $this->admin_page->set_show( 'leftbar' , false );
  55. $this->viewer = new sharing_viewer;
  56. $this->viewer->set_page( $this->admin_page );
  57. if( !isset( $lister ) ) $lister = '';
  58. $this->viewer->init( $this->admin_page->site_id, $type->id(), $lister );
  59. $this->filter = new sharing_filter;
  60. $this->filter->set_page( $this->admin_page );
  61. $this->filter->grab_fields( $this->viewer->filters );
  62. } // }}}
  63. function run() {
  64. echo $this->_produce_borrowing_nav();
  65. parent::run();
  66. }
  67. function _produce_borrowing_nav()
  68. {
  69. $ret = '';
  70. $nes = new entity_selector( );
  71. $nes->add_type( id_of('type') );
  72. $nes->add_right_relationship( $this->admin_page->site_id, relationship_id_of( 'site_cannot_edit_type' ) );
  73. $nes->add_relation('`entity`.`id` = "'.addslashes($this->admin_page->type_id).'"');
  74. $nes->set_num(1);
  75. $nes->limit_tables();
  76. $nes->limit_fields();
  77. $ns = $nes->run_one();
  78. $show_edit = reason_user_has_privs($this->admin_page->user_id,'edit') && !$this->admin_page->is_second_level() && empty($ns) ? true : false;
  79. /* $type = new entity($this->admin_page->type_id);
  80. $name = $type->get_value('plural_name') ? $type->get_value('plural_name') : $type->get_value('name');
  81. if(function_exists('mb_strtolower'))
  82. $name = mb_strtolower($name);
  83. else
  84. $name = strtolower($name); */
  85. $ret .= '<div class="borrowNav">'."\n";
  86. $ret .= '<ul>';
  87. if($show_edit)
  88. $ret .= '<li><a href="'.$this->admin_page->get_owned_list_link($this->admin_page->type_id).'"><img src="'.REASON_HTTP_BASE_PATH.'silk_icons/bullet_edit.png" alt="" /> Add &amp; edit</a></li>';
  89. $ret .= '<li class="current"><strong><img src="'.REASON_HTTP_BASE_PATH.'silk_icons/car.png" alt="" /> Borrow</strong></li>';
  90. $ret .= '</ul>'."\n";
  91. $ret .= '</div>'."\n";
  92. // if(reason_user_has_privs($this->admin_page->user_id,'edit'))
  93. return $ret;
  94. }
  95. function show_next_nodes() // {{{
  96. {
  97. $finish_link = $this->admin_page->make_link( array( 'cur_module' => 'Lister' ) );
  98. echo '<a href="'.$finish_link.'">Back to Lister</a><br />';
  99. } // }}}
  100. } // }}}
  101. ?>