2013-09-18 01:38:36 +02:00
< ? php
2014-12-19 22:41:55 +01:00
2015-08-15 23:36:38 +02:00
function Shift_editor_info_render ( $shift ) {
$info = [];
2016-09-29 11:18:17 +02:00
if ( $shift [ 'created_by_user_id' ] != null ) {
2015-08-15 23:36:38 +02:00
$info [] = sprintf ( glyph ( 'plus' ) . _ ( " created at %s by %s " ), date ( 'Y-m-d H:i' , $shift [ 'created_at_timestamp' ]), User_Nick_render ( User ( $shift [ 'created_by_user_id' ])));
2016-09-29 11:18:17 +02:00
}
if ( $shift [ 'edited_by_user_id' ] != null ) {
2015-08-15 23:36:38 +02:00
$info [] = sprintf ( glyph ( 'pencil' ) . _ ( " edited at %s by %s " ), date ( 'Y-m-d H:i' , $shift [ 'edited_at_timestamp' ]), User_Nick_render ( User ( $shift [ 'edited_by_user_id' ])));
2016-09-29 11:18:17 +02:00
}
2015-08-15 23:36:38 +02:00
return join ( '<br />' , $info );
}
2014-12-25 22:23:18 +01:00
function Shift_signup_button_render ( $shift , $angeltype , $user_angeltype = null , $user_shifts = null ) {
global $user ;
if ( $user_angeltype == null ) {
$user_angeltype = UserAngelType_by_User_and_AngelType ( $user , $angeltype );
2016-09-29 11:18:17 +02:00
if ( $user_angeltype === false ) {
2014-12-25 22:23:18 +01:00
engelsystem_error ( 'Unable to load user angeltype.' );
2016-09-29 11:18:17 +02:00
}
2014-12-25 22:23:18 +01:00
}
2016-09-29 11:18:17 +02:00
if ( Shift_signup_allowed ( $shift , $angeltype , $user_angeltype , $user_shifts )) {
2014-12-25 22:23:18 +01:00
return button ( page_link_to ( 'user_shifts' ) . '&shift_id=' . $shift [ 'SID' ] . '&type_id=' . $angeltype [ 'id' ], _ ( 'Sign up' ));
2016-09-29 11:18:17 +02:00
} elseif ( $user_angeltype == null ) {
2014-12-26 18:51:06 +01:00
return button ( page_link_to ( 'angeltypes' ) . '&action=view&angeltype_id=' . $angeltype [ 'id' ], sprintf ( _ ( 'Become %s' ), $angeltype [ 'name' ]));
2016-09-29 11:18:17 +02:00
}
return '' ;
2014-12-25 22:23:18 +01:00
}
function Shift_view ( $shift , $shifttype , $room , $shift_admin , $angeltypes_source , $user_shift_admin , $admin_rooms , $admin_shifttypes , $user_shifts , $signed_up ) {
2014-12-19 22:41:55 +01:00
$parsedown = new Parsedown ();
$angeltypes = [];
2016-09-29 11:18:17 +02:00
foreach ( $angeltypes_source as $angeltype ) {
2014-12-19 22:41:55 +01:00
$angeltypes [ $angeltype [ 'id' ]] = $angeltype ;
2016-09-29 11:18:17 +02:00
}
2014-12-19 22:41:55 +01:00
$needed_angels = '' ;
foreach ( $shift [ 'NeedAngels' ] as $needed_angeltype ) {
$class = 'progress-bar-warning' ;
2016-09-29 11:18:17 +02:00
if ( $needed_angeltype [ 'taken' ] == 0 ) {
2014-12-19 22:41:55 +01:00
$class = 'progress-bar-danger' ;
2016-09-29 11:18:17 +02:00
}
if ( $needed_angeltype [ 'taken' ] >= $needed_angeltype [ 'count' ]) {
2014-12-19 22:41:55 +01:00
$class = 'progress-bar-success' ;
2016-09-29 11:18:17 +02:00
}
2014-12-19 22:41:55 +01:00
$needed_angels .= '<div class="list-group-item">' ;
2014-12-25 22:23:18 +01:00
$needed_angels .= '<div class="pull-right">' . Shift_signup_button_render ( $shift , $angeltypes [ $needed_angeltype [ 'TID' ]]) . '</div>' ;
2014-12-19 22:59:18 +01:00
$needed_angels .= '<h3>' . AngelType_name_render ( $angeltypes [ $needed_angeltype [ 'TID' ]]) . '</h3>' ;
2014-12-28 01:35:36 +01:00
$needed_angels .= progress_bar ( 0 , $needed_angeltype [ 'count' ], min ( $needed_angeltype [ 'taken' ], $needed_angeltype [ 'count' ]), $class , $needed_angeltype [ 'taken' ] . ' / ' . $needed_angeltype [ 'count' ]);
2014-12-19 22:41:55 +01:00
$angels = [];
foreach ( $shift [ 'ShiftEntry' ] as $shift_entry ) {
if ( $shift_entry [ 'TID' ] == $needed_angeltype [ 'TID' ]) {
$entry = User_Nick_render ( User ( $shift_entry [ 'UID' ]));
2016-09-29 11:18:17 +02:00
if ( $shift_entry [ 'freeloaded' ]) {
2014-12-19 22:41:55 +01:00
$entry = '<strike>' . $entry . '</strike>' ;
2016-09-29 11:18:17 +02:00
}
2014-12-19 22:41:55 +01:00
if ( $user_shift_admin ) {
$entry .= ' <div class="btn-group">' ;
2015-08-13 09:13:13 +02:00
$entry .= button_glyph ( page_link_to ( 'user_myshifts' ) . '&edit=' . $shift_entry [ 'id' ] . '&id=' . $shift_entry [ 'UID' ], 'pencil' , 'btn-xs' );
2014-12-19 22:41:55 +01:00
$entry .= button_glyph ( page_link_to ( 'user_shifts' ) . '&entry_id=' . $shift_entry [ 'id' ], 'trash' , 'btn-xs' );
$entry .= '</div>' ;
}
$angels [] = $entry ;
}
}
$needed_angels .= join ( ', ' , $angels );
$needed_angels .= '</div>' ;
}
return page_with_title ( $shift [ 'name' ] . ' <small class="moment-countdown" data-timestamp="' . $shift [ 'start' ] . '">%c</small>' , [
msg (),
2014-12-25 22:23:18 +01:00
Shift_collides ( $shift , $user_shifts ) ? info ( _ ( 'This shift collides with one of your shifts.' ), true ) : '' ,
$signed_up ? info ( _ ( 'You are signed up for this shift.' ), true ) : '' ,
2014-12-22 18:22:54 +01:00
( $shift_admin || $admin_shifttypes || $admin_rooms ) ? buttons ([
$shift_admin ? button ( shift_edit_link ( $shift ), glyph ( 'pencil' ) . _ ( 'edit' )) : '' ,
$shift_admin ? button ( shift_delete_link ( $shift ), glyph ( 'trash' ) . _ ( 'delete' )) : '' ,
$admin_shifttypes ? button ( shifttype_link ( $shifttype ), $shifttype [ 'name' ]) : '' ,
$admin_rooms ? button ( room_link ( $room ), glyph ( 'map-marker' ) . $room [ 'Name' ]) : ''
2014-12-19 22:41:55 +01:00
]) : '' ,
div ( 'row' , [
2014-12-22 18:06:58 +01:00
div ( 'col-sm-3 col-xs-6' , [
'<h4>' . _ ( 'Title' ) . '</h4>' ,
'<p class="lead">' . ( $shift [ 'URL' ] != '' ? '<a href="' . $shift [ 'URL' ] . '">' . $shift [ 'title' ] . '</a>' : $shift [ 'title' ]) . '</p>'
]),
2014-12-19 22:59:18 +01:00
div ( 'col-sm-3 col-xs-6' , [
2014-12-19 22:41:55 +01:00
'<h4>' . _ ( 'Start' ) . '</h4>' ,
2014-12-25 22:23:18 +01:00
'<p class="lead' . ( time () >= $shift [ 'start' ] ? ' text-success' : '' ) . '">' ,
2015-08-26 15:00:10 +02:00
glyph ( 'calendar' ) . date ( 'Y-m-d' , $shift [ 'start' ]),
2014-12-19 22:41:55 +01:00
'<br />' ,
2014-12-22 18:22:54 +01:00
glyph ( 'time' ) . date ( 'H:i' , $shift [ 'start' ]),
2014-12-19 22:41:55 +01:00
'</p>'
]),
2014-12-19 22:59:18 +01:00
div ( 'col-sm-3 col-xs-6' , [
2014-12-19 22:41:55 +01:00
'<h4>' . _ ( 'End' ) . '</h4>' ,
2014-12-25 22:23:18 +01:00
'<p class="lead' . ( time () >= $shift [ 'end' ] ? ' text-success' : '' ) . '">' ,
2015-08-26 15:00:10 +02:00
glyph ( 'calendar' ) . date ( 'Y-m-d' , $shift [ 'end' ]),
2014-12-19 22:41:55 +01:00
'<br />' ,
2014-12-22 18:22:54 +01:00
glyph ( 'time' ) . date ( 'H:i' , $shift [ 'end' ]),
2014-12-19 22:41:55 +01:00
'</p>'
]),
2014-12-19 22:59:18 +01:00
div ( 'col-sm-3 col-xs-6' , [
2014-12-19 22:41:55 +01:00
'<h4>' . _ ( 'Location' ) . '</h4>' ,
2014-12-22 18:22:54 +01:00
'<p class="lead">' . glyph ( 'map-marker' ) . $room [ 'Name' ] . '</p>'
2014-12-19 22:41:55 +01:00
])
]),
div ( 'row' , [
div ( 'col-sm-6' , [
'<h2>' . _ ( 'Needed angels' ) . '</h2>' ,
'<div class="list-group">' . $needed_angels . '</div>'
]),
div ( 'col-sm-6' , [
'<h2>' . _ ( 'Description' ) . '</h2>' ,
$parsedown -> parse ( $shifttype [ 'description' ])
])
2015-08-15 23:36:38 +02:00
]),
$shift_admin ? Shift_editor_info_render ( $shift ) : ''
2014-12-19 22:41:55 +01:00
]);
}
2013-09-18 01:38:36 +02:00
/**
* Calc shift length in format 12 : 23 h .
2014-12-19 22:41:55 +01:00
*
* @ param Shift $shift
2013-09-18 01:38:36 +02:00
*/
function shift_length ( $shift ) {
2014-11-03 19:28:43 +01:00
$length = floor (( $shift [ 'end' ] - $shift [ 'start' ]) / ( 60 * 60 )) . " : " ;
2013-09-18 01:38:36 +02:00
$length .= str_pad ((( $shift [ 'end' ] - $shift [ 'start' ]) % ( 60 * 60 )) / 60 , 2 , " 0 " , STR_PAD_LEFT ) . " h " ;
return $length ;
}
2014-11-03 19:28:43 +01:00
?>