2008-04-23 09:33:54 +00:00
< ? php // $Id$
/**
* print the single entries
*
* @ version $Id $
* @ author Andreas Grabs
* @ license http :// www . gnu . org / copyleft / gpl . html GNU Public License
* @ package feedback
*/
require_once ( " ../../config.php " );
require_once ( " lib.php " );
////////////////////////////////////////////////////////
//get the params
////////////////////////////////////////////////////////
$id = required_param ( 'id' , PARAM_INT );
$userid = optional_param ( 'userid' , false , PARAM_INT );
$lstgroupid = optional_param ( 'lstgroupid' , - 2 , PARAM_INT ); //groupid (choosen from dropdownlist)
$do_show = required_param ( 'do_show' , PARAM_ALPHA );
// $SESSION->feedback->current_tab = $do_show;
$current_tab = $do_show ;
//check, whether a group is selected
if ( $lstgroupid == - 1 ) {
$SESSION -> feedback -> lstgroupid = false ;
} else {
if (( ! isset ( $SESSION -> feedback -> lstgroupid )) || $lstgroupid != - 2 )
$SESSION -> feedback -> lstgroupid = $lstgroupid ;
}
////////////////////////////////////////////////////////
//get the objects
////////////////////////////////////////////////////////
if ( $userid ) {
$formdata -> userid = intval ( $userid );
}
if ( $id ) {
if ( ! $cm = get_coursemodule_from_id ( 'feedback' , $id )) {
error ( " Course Module ID was incorrect " );
}
2008-06-07 22:22:06 +00:00
if ( ! $course = $DB -> get_record ( " course " , array ( " id " => $cm -> course ))) {
2008-04-23 09:33:54 +00:00
error ( " Course is misconfigured " );
}
2008-06-07 22:22:06 +00:00
if ( ! $feedback = $DB -> get_record ( " feedback " , array ( " id " => $cm -> instance ))) {
2008-04-23 09:33:54 +00:00
error ( " Course module is incorrect " );
}
}
if ( isset ( $SESSION -> feedback -> lstgroupid )) {
if ( $tmpgroup = groups_get_group ( $SESSION -> feedback -> lstgroupid )) {
if ( $tmpgroup -> courseid != $course -> id ) {
$SESSION -> feedback -> lstgroupid = false ;
}
} else {
$SESSION -> feedback -> lstgroupid = false ;
}
}
$capabilities = feedback_load_capabilities ( $cm -> id );
2008-04-28 21:19:27 +00:00
require_login ( $course -> id , true , $cm );
2008-04-23 09:33:54 +00:00
2008-06-09 16:53:30 +00:00
if (( $formdata = data_submitted ()) AND ! confirm_sesskey ()) {
2008-04-23 09:33:54 +00:00
error ( 'no sesskey defined' );
}
if ( ! $capabilities -> viewreports ){
error ( get_string ( 'error' ));
}
////////////////////////////////////////////////////////
//get the responses of given user
////////////////////////////////////////////////////////
if ( $do_show == 'showoneentry' ) {
//get the feedbackitems
2008-06-07 22:22:06 +00:00
$feedbackitems = $DB -> get_records ( 'feedback_item' , array ( 'feedback' => $feedback -> id ), 'position' );
$feedbackcompleted = $DB -> get_record ( 'feedback_completed' , array ( 'feedback' => $feedback -> id , 'userid' => $formdata -> userid , 'anonymous_response' => FEEDBACK_ANONYMOUS_NO )); //arb
2008-04-23 09:33:54 +00:00
}
/// Print the page header
$strfeedbacks = get_string ( " modulenameplural " , " feedback " );
$strfeedback = get_string ( " modulename " , " feedback " );
$buttontext = update_module_button ( $cm -> id , $course -> id , $strfeedback );
$navlinks = array ();
$navlinks [] = array ( 'name' => $strfeedbacks , 'link' => " index.php?id= $course->id " , 'type' => 'activity' );
$navlinks [] = array ( 'name' => format_string ( $feedback -> name ), 'link' => " " , 'type' => 'activityinstance' );
$navigation = build_navigation ( $navlinks );
print_header_simple ( format_string ( $feedback -> name ), " " ,
$navigation , " " , " " , true , $buttontext , navmenu ( $course , $cm ));
include ( 'tabs.php' );
/// Print the main part of the page
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
/// Print the links to get responses and analysis
////////////////////////////////////////////////////////
if ( $do_show == 'showentries' ){
//print the link to analysis
if ( $capabilities -> viewreports ) {
//get the effective groupmode of this course and module
$groupmode = groupmode ( $course , $cm );
//get students in conjunction with groupmode
if ( $groupmode > 0 ) {
if ( $SESSION -> feedback -> lstgroupid == - 2 ) {
2008-05-25 10:08:05 +00:00
if ( has_capability ( 'moodle/site:doanything' , get_context_instance ( CONTEXT_SYSTEM ))) {
2008-04-23 09:33:54 +00:00
$mygroupid = false ;
$SESSION -> feedback -> lstgroupid = false ;
} else {
if ( $mygroupid = mygroupid ( $course -> id )) {
$mygroupid = $mygroupid [ 0 ]; //get the first groupid
}
}
} else {
$mygroupid = $SESSION -> feedback -> lstgroupid ;
}
if ( $mygroupid ) {
$students = feedback_get_complete_users ( $cm -> id , $mygroupid );
} else {
$students = feedback_get_complete_users ( $cm -> id );
}
} else {
$students = feedback_get_complete_users ( $cm -> id );
}
$mygroupid = isset ( $mygroupid ) ? $mygroupid : NULL ;
$completedFeedbackCount = feedback_get_completeds_group_count ( $feedback , $mygroupid );
if ( $feedback -> course == SITEID ){
echo '<div align="center"><a href="' . htmlspecialchars ( 'analysis_course.php?id=' . $id . '&courseid=' . $courseid ) . '">' ;
echo get_string ( 'course' ) . ' ' . get_string ( 'analysis' , 'feedback' ) . ' (' . get_string ( 'completed_feedbacks' , 'feedback' ) . ': ' . intval ( $completedFeedbackCount ) . ')</a>' ;
helpbutton ( 'viewcompleted' , '' , 'feedback' , true , true );
echo '</div>' ;
} else {
echo '<div align="center"><a href="' . htmlspecialchars ( 'analysis.php?id=' . $id . '&courseid=' . $courseid ) . '">' ;
echo get_string ( 'analysis' , 'feedback' ) . ' (' . get_string ( 'completed_feedbacks' , 'feedback' ) . ': ' . intval ( $completedFeedbackCount ) . ')</a>' ;
echo '</div>' ;
}
}
//####### viewreports-start
if ( $capabilities -> viewreports ) {
//print the list of students
// print_simple_box_start('center', '80%');
print_box_start ( 'generalbox boxaligncenter boxwidthwide' );
//available group modes (NOGROUPS, SEPARATEGROUPS or VISIBLEGROUPS)
2008-05-01 22:30:28 +00:00
$feedbackgroups = groups_get_all_groups ( $course -> id );
2008-04-23 09:33:54 +00:00
//if(is_array($feedbackgroups) && $groupmode != SEPARATEGROUPS){
if ( is_array ( $feedbackgroups ) && $groupmode > 0 ){
require_once ( 'choose_group_form.php' );
//the use_template-form
$choose_group_form = new feedback_choose_group_form ();
$choose_group_form -> set_feedbackdata ( array ( 'groups' => $feedbackgroups , 'mygroupid' => $mygroupid ));
$choose_group_form -> set_form_elements ();
$choose_group_form -> set_data ( array ( 'id' => $id , 'lstgroupid' => $SESSION -> feedback -> lstgroupid , 'do_show' => $do_show ));
$choose_group_form -> display ();
}
echo '<div align="center"><table><tr><td width="400">' ;
if ( ! $students ) {
if ( $courseid != SITEID ){
notify ( get_string ( 'noexistingstudents' ));
}
} else {
echo print_string ( 'non_anonymous_entries' , 'feedback' );
2008-06-07 22:22:06 +00:00
echo ' (' . $DB -> count_records ( 'feedback_completed' , array ( 'feedback' => $feedback -> id , 'anonymous_response' => FEEDBACK_ANONYMOUS_NO )) . ')<hr />' ;
2008-04-23 09:33:54 +00:00
foreach ( $students as $student ){
2008-06-07 22:22:06 +00:00
$completedCount = $DB -> count_records ( 'feedback_completed' , array ( 'userid' => $student -> id , 'feedback' => $feedback -> id , 'anonymous_response' => FEEDBACK_ANONYMOUS_NO ));
2008-04-23 09:33:54 +00:00
if ( $completedCount > 0 ) {
// Are we assuming that there is only one response per user? Should westep through a feedbackcompleteds? I added the addition anonymous check to the select so that only non-anonymous submissions are retrieved.
2008-06-07 22:22:06 +00:00
$feedbackcompleted = $DB -> get_record ( 'feedback_completed' , array ( 'feedback' => $feedback -> id , ' userid' => $student -> id , 'anonymous_response' => FEEDBACK_ANONYMOUS_NO ));
2008-04-23 09:33:54 +00:00
?>
< table width = " 100% " >
< tr >
< td align = " left " >
< ? php echo print_user_picture ( $student -> id , $course -> id , $student -> picture , false , true ); ?>
</ td >
< td align = " left " >
< ? php echo fullname ( $student ); ?>
</ td >
< td align = " right " >
< ? php
$show_button_link = $ME ;
$show_button_options = array ( 'sesskey' => $USER -> sesskey , 'userid' => $student -> id , 'do_show' => 'showoneentry' , 'id' => $id );
$show_button_label = get_string ( 'show_entries' , 'feedback' );
print_single_button ( $show_button_link , $show_button_options , $show_button_label , 'post' );
?>
</ td >
< ? php
if ( $capabilities -> deletesubmissions ) {
?>
< td align = " right " >
< ? php
$delete_button_link = 'delete_completed.php' ;
$delete_button_options = array ( 'sesskey' => $USER -> sesskey , 'completedid' => $feedbackcompleted -> id , 'do_show' => 'showoneentry' , 'id' => $id );
$delete_button_label = get_string ( 'delete_entry' , 'feedback' );
print_single_button ( $delete_button_link , $delete_button_options , $delete_button_label , 'post' );
?>
</ td >
< ? php
}
?>
</ tr >
</ table >
< ? php
}
}
}
?>
< hr />
< table width = " 100% " >
< tr >
< td align = " left " colspan = " 2 " >
2008-06-07 22:22:06 +00:00
< ? php print_string ( 'anonymous_entries' , 'feedback' ); ?> (<?php echo $DB->count_records('feedback_completed', array('feedback'=>$feedback->id, 'anonymous_response'=>FEEDBACK_ANONYMOUS_YES));?>)
2008-04-23 09:33:54 +00:00
</ td >
< td align = " right " >
< ? php
$show_anon_button_link = 'show_entries_anonym.php' ;
$show_anon_button_options = array ( 'sesskey' => $USER -> sesskey , 'userid' => 0 , 'do_show' => 'showoneentry' , 'id' => $id );
$show_anon_button_label = get_string ( 'show_entries' , 'feedback' );
print_single_button ( $show_anon_button_link , $show_anon_button_options , $show_anon_button_label , 'post' );
?>
</ td >
</ tr >
</ table >
< ? php
echo '</td></tr></table></div>' ;
// print_simple_box_end();
print_box_end ();
}
}
////////////////////////////////////////////////////////
/// Print the responses of the given user
////////////////////////////////////////////////////////
if ( $do_show == 'showoneentry' ) {
print_heading ( format_text ( $feedback -> name ));
//print the items
if ( is_array ( $feedbackitems )){
2008-06-07 22:22:06 +00:00
$usr = $DB -> get_record ( 'user' , array ( 'id' => $formdata -> userid ));
2008-04-23 09:33:54 +00:00
if ( $feedbackcompleted ) {
echo '<p align="center">' . UserDate ( $feedbackcompleted -> timemodified ) . '<br />(' . fullname ( $usr ) . ')</p>' ;
} else {
echo '<p align="center">' . get_string ( 'not_completed_yet' , 'feedback' ) . '</p>' ;
}
// print_simple_box_start("center", '50%');
print_box_start ( 'generalbox boxaligncenter boxwidthnormal' );
echo '<form>' ;
echo '<input type="hidden" name="sesskey" value="' . $USER -> sesskey . '" />' ;
echo '<table width="100%">' ;
$itemnr = 0 ;
foreach ( $feedbackitems as $feedbackitem ){
//get the values
2008-06-07 22:22:06 +00:00
$value = $DB -> get_record ( 'feedback_value' , array ( 'completed' => $feedbackcompleted -> id , 'item' => $feedbackitem -> id ));
2008-04-23 09:33:54 +00:00
echo '<tr>' ;
2008-04-30 22:17:04 +00:00
if ( $feedbackitem -> hasvalue == 1 AND $feedback -> autonumbering ) {
2008-04-23 09:33:54 +00:00
$itemnr ++ ;
2008-04-30 22:17:04 +00:00
echo '<td valign="top">' . $itemnr . '. </td>' ;
2008-04-23 09:33:54 +00:00
} else {
echo '<td> </td>' ;
}
if ( $feedbackitem -> typ != 'pagebreak' ) {
if ( isset ( $value -> value )) {
feedback_print_item ( $feedbackitem , $value -> value , true );
} else {
feedback_print_item ( $feedbackitem , false , true );
}
} else {
echo '<td><hr /></td>' ;
}
echo '</tr>' ;
}
echo '<tr><td colspan="2" align="center">' ;
echo '</td></tr>' ;
echo '</table>' ;
echo '</form>' ;
// print_simple_box_end();
print_box_end ();
}
print_continue ( htmlspecialchars ( 'show_entries.php?id=' . $id . '&do_show=showentries' ));
}
/// Finish the page
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
print_footer ( $course );
?>