2011-12-17 16:25:54 +01:00
< ? php
2013-11-25 21:04:58 +01:00
function admin_free_title () {
return _ ( " Free angels " );
}
2011-12-17 16:25:54 +01:00
function admin_free () {
2012-12-30 17:58:23 +01:00
global $privileges ;
2014-08-22 22:34:13 +02:00
2012-12-30 17:58:23 +01:00
$search = " " ;
2014-08-22 22:34:13 +02:00
if ( isset ( $_REQUEST [ 'search' ]))
2012-12-30 17:58:23 +01:00
$search = strip_request_item ( 'search' );
2014-08-22 22:34:13 +02:00
2012-12-30 17:58:23 +01:00
$angeltypesearch = " " ;
2014-08-22 22:34:13 +02:00
if ( empty ( $_REQUEST [ 'angeltype' ]))
2012-12-30 17:58:23 +01:00
$_REQUEST [ 'angeltype' ] = '' ;
else {
$angeltypesearch = " INNER JOIN `UserAngelTypes` ON (`UserAngelTypes`.`angeltype_id` = ' " . sql_escape ( $_REQUEST [ 'angeltype' ]) . " ' AND `UserAngelTypes`.`user_id` = `User`.`UID` " ;
2014-08-22 22:34:13 +02:00
if ( isset ( $_REQUEST [ 'confirmed_only' ]))
2012-12-30 17:58:23 +01:00
$angeltypesearch .= " AND `UserAngelTypes`.`confirm_user_id` " ;
$angeltypesearch .= " ) " ;
}
2014-08-22 22:34:13 +02:00
2012-12-30 17:58:23 +01:00
$angel_types_source = sql_select ( " SELECT `id`, `name` FROM `AngelTypes` ORDER BY `name` " );
2014-08-22 22:34:13 +02:00
$angel_types = array (
'' => 'alle Typen'
);
2012-12-30 17:58:23 +01:00
foreach ( $angel_types_source as $angel_type )
$angel_types [ $angel_type [ 'id' ]] = $angel_type [ 'name' ];
2014-08-22 22:34:13 +02:00
2012-12-30 17:58:23 +01:00
$users = sql_select ( " SELECT `User`.* FROM `User` ${ angeltypesearch } LEFT JOIN `ShiftEntry` ON `User`.`UID` = `ShiftEntry`.`UID` LEFT JOIN `Shifts` ON (`ShiftEntry`.`SID` = `Shifts`.`SID` AND `Shifts`.`start` < " . sql_escape ( time ()) . " AND `Shifts`.`end` > " . sql_escape ( time ()) . " ) WHERE `User`.`Gekommen` = 1 AND `Shifts`.`SID` IS NULL GROUP BY `User`.`UID` ORDER BY `Nick` " );
2014-08-22 22:34:13 +02:00
2012-12-30 17:58:23 +01:00
$table = " " ;
if ( $search == " " )
2014-08-22 22:34:13 +02:00
$tokens = array ();
2012-12-30 17:58:23 +01:00
else
$tokens = explode ( " " , $search );
foreach ( $users as $usr ) {
if ( count ( $tokens ) > 0 ) {
$match = false ;
$index = join ( " " , $usr );
foreach ( $tokens as $t )
if ( stristr ( $index , trim ( $t ))) {
2014-08-22 22:34:13 +02:00
$match = true ;
break ;
}
if ( ! $match )
2012-12-30 17:58:23 +01:00
continue ;
}
$table .= '<tr>' ;
$table .= '<td>' . User_Nick_render ( $usr ) . '</td>' ;
$table .= '<td>' . $usr [ 'DECT' ] . '</td>' ;
$table .= '<td>' . $usr [ 'jabber' ] . '</td>' ;
if ( in_array ( 'admin_user' , $privileges ))
$table .= '<td><a href="' . page_link_to ( 'admin_user' ) . '&id=' . $usr [ 'UID' ] . '">edit</a></td>' ;
else
$table .= '<td>' . User_Nick_render ( $usr ) . '</td>' ;
2014-08-22 22:34:13 +02:00
2012-12-30 17:58:23 +01:00
$table .= '</tr>' ;
}
2014-08-22 22:34:13 +02:00
return template_render ( '../templates/admin_free.html' , array (
'title' => admin_free_title (),
'search' => $search ,
'angeltypes' => html_select_key ( 'angeltype' , 'angeltype' , $angel_types , $_REQUEST [ 'angeltype' ]),
'confirmed_only' => isset ( $_REQUEST [ 'confirmed_only' ]) ? 'checked' : '' ,
'table' => $table ,
'link' => page_link_to ( 'admin_free' )
2012-12-30 17:58:23 +01:00
));
2011-12-17 16:25:54 +01:00
}
2012-12-26 18:14:23 +01:00
?>