usesSurvey()) {
exit_disabled();
}
if ($is_admin_page && $group_id) {
$params['submenu'] = $HTML->subMenu(
array(
_('Add Survey'),
_('Add Question'),
_('Show Results'),
_('Administration')
),
array(
'/survey/admin/survey.php?group_id='.$group_id,
'/survey/admin/question.php?group_id='.$group_id,
'/survey/admin/show_results.php?group_id='.$group_id,
'/survey/admin/?group_id='.$group_id
)
);
} else {
$labels[] = _('Views Surveys');
$links[] = '/survey/?group_id='.$group_id;
if (forge_check_perm ('project_admin', $group_id)) {
$labels[] = _('Administration');
$links[] = '/survey/admin/?group_id='.$group_id;
}
$params['submenu'] = $HTML->subMenu($labels,$links);
}
site_project_header($params);
}// end if (valid group id)
}
/**
* Show Survey footer
*/
function footer($params) {
site_project_footer($params);
}
/**
* Show Add/Modify Question Forums
* @param Survey Question Question Object
* Return string
*/
function showAddQuestionForm( &$q ) {
global $group_id;
/* Default is add */
$question_button = _('Add this Question');
/* If we have a question object, it is a Modify */
if ($q && is_object($q) && !$q->isError() && $q->getID()) {
$warning_msg = '
'.
_('WARNING! It is a bad idea to change a question after responses to it have been submitted').
'
';
$question_id = $q->getID();
$question = $q->getQuestion();
$question_type = $q->getQuestionType();
$question_button = _('Submit Changes');
} else {
$warning_msg = '';
$question = '';
$question_id = '';
$question_type = '';
}
$ret = $warning_msg;
$ret.='';
return $ret;
}
/**
* Show Add/Modify Question Forums
* @param Survey Question Question Object
* Return string
*/
function showAddSurveyForm( &$s) {
global $group_id;
global $survey_id;
/* If no question is available */
if (! $survey_id && ! count($s->getAddableQuestionInstances())) {
$ret = '' . sprintf(_('Please %1$s create a question %2$s before creating a survey'),
'',
'') .
'
';
return $ret;
}
/* Default is add */
$survey_button = _('Add this Survey');
$active = ' checked="checked" ';
$inactive = '';
/* If we have a survey object, it is a Modify */
if ($s && is_object($s) && !$s->isError() && $s->getID()) {
$warning_msg = ''.
_('WARNING! It is a bad idea to edit a survey after responses have been posted').'
';
$survey_id = $s->getID();
$survey_title = $s->getTitle();
$survey_questions = $s->getQuestionString();
$survey_button = _('Submit Changes');
if (!$s->isActive()) {
$inactive = 'checked ="checked" ';
$active ='';
}
} else {
$warning_msg = '';
$survey_questions = '';
$survey_title = '';
}
$ret = $warning_msg;
$ret.='';
return $ret;
}
/**
* Show list of questions
*/
function ShowQuestions(&$questions) {
global $group_id;
$n = count($questions);
$ret = "" . sprintf(ngettext("%d question found", "%d questions found", $n), $n)."
";
/* Head information */
$title_arr = array ('Question ID', 'Question', 'Type', 'Edit/Delete');
$ret.=$GLOBALS['HTML']->listTableTop ($title_arr);
for($i = 0; $i < count($questions); $i++) {
if ($questions[$i]->isError()) {
echo $questions[$i]->getErrorMessage();
continue;
}
$ret.= "boxGetAltRowStyle($i) .">\n";
$ret.= "getID()."\">".$questions[$i]->getID()." | \n";
$ret.= ''.$questions[$i]->getQuestion().' | ';
$ret.= ''.$questions[$i]->getQuestionStringType().' | ';
/* Edit/Delete Link */
$ret.= "[getID().'">';
$ret.= _('Edit').'] ';
$ret.= "[getID().'">';
$ret.= _('Delete').'] | ';
$ret.= "
";
}
$ret.= $GLOBALS['HTML']->listTableBottom();
return $ret;
}
/**
* Show list of surveys
*
* Show surveys with many options
* have to set $user_id to get the right show_vote option
*
*
*/
function ShowSurveys(&$surveys, $show_id=0, $show_questions=0,
$show_number_questions=0, $show_number_votes=0,
$show_vote=0, $show_edit=0, $show_result=0,
$show_result_graph=0, $show_result_comment=0,
$show_inactive=0 ) {
global $user_id;
global $group_id;
$ret = ''. ngettext('Existing Survey', 'Existing Surveys', count($surveys)). '
';
/* Head information */
if ($show_id) {
$title_arr[] = _('Survey ID');
}
$title_arr[] = _('Survey Title');
if ($show_questions) {
$title_arr[] = _('Questions');
}
if ($show_number_questions) {
$title_arr[] = _('Number of Questions');
}
if ($show_number_votes) {
$title_arr[] = _('Number of Votes');
}
if ($show_vote && $user_id) {
$title_arr[] = _('Did I Vote?');
}
if ($show_edit) {
$title_arr[] = _('Edit');
}
if ($show_result) {
$title_arr[] = _('Result');
}
if ($show_result_graph) {
$title_arr[] = _('Result with Graph');
}
if ($show_result_comment) {
$title_arr[] = _('Result with Graph and Comments');
}
$ret.=$GLOBALS['HTML']->listTableTop ($title_arr);
/* Color index for table */
$color_index=0;
for($i = 0; $i < count($surveys); $i++) {
if ($surveys[$i]->isError()) {
echo $surveys[$i]->getErrorMessage();
continue;
}
if (!$surveys[$i]->isActive()) {
if ($show_inactive) {
$strike_open="";
$strike_close="";
} else {
continue;
}
} else {
$strike_open="";
$strike_close="";
}
$ret.= "boxGetAltRowStyle($color_index++) .">\n";
if ($show_id) {
$ret.= ''.$surveys[$i]->getID().' | ';
}
$ret.= ''.$strike_open.util_make_link ('/survey/survey.php?group_id='.$group_id.'&survey_id='. $surveys[$i]->getID(), $surveys[$i]->getTitle()). $strike_close.' | ';
if ($show_questions) {
// add a space after comma
$ret.= ''.str_replace(",", ", ", $surveys[$i]->getQuestionString()).' | ';
}
if ($show_number_questions) {
$ret.= ''.$surveys[$i]->getNumberOfQuestions().' | ';
}
if ($show_number_votes) {
$ret.= ''.$surveys[$i]->getNumberOfVotes().' | ';
}
if ($show_vote && $user_id) {
if ($surveys[$i]->isUserVote($user_id)) {
$ret.=''. _('Yes') . ' | ';
} else {
$ret.=''. _('No') . ' | ';
}
}
if ($show_edit) {
/* Edit/Delete Link */
$ret.= '['.util_make_link ('/survey/admin/survey.php?group_id='.$group_id.'&survey_id='. $surveys[$i]->getID(),_('Edit')).'] ';
/* We don't support delete yet. Need to delete all results as well */
/*
$ret.= '['.util_make_link ('/survey/admin/survey.php?delete=Y&group_id='.$group_id.'&survey_id='. $surveys[$i]->getID(),_('Delete')).']';
*/
$ret.=' | ';
}
if ($show_result) {
/* Edit/Delete Link */
$ret.= '['.util_make_link ('/survey/admin/show_results.php?group_id='.$group_id.'&survey_id='. $surveys[$i]->getID(),_('Result')).'] | ';
}
if ($show_result_graph) {
/* Edit/Delete Link */
$ret.= '['.util_make_link ('/survey/admin/show_results.php?graph=yes&group_id='.$group_id.'&survey_id='. $surveys[$i]->getID(),_('Result with Graph')).'] | ';
}
if ($show_result_comment) {
/* Edit/Delete Link */
$ret.= '['.util_make_link ('/survey/admin/show_results.php?graph=yes&show_comment=yes&group_id='.$group_id.'&survey_id='.$surveys[$i]->getID(),_('Result with Graph and Comments')).'] | ';
}
$ret.= "
\n";
}
$ret.= $GLOBALS['HTML']->listTableBottom();
return $ret;
}
/**
* Show survey form - Show all forums of Survey
*/
function ShowSurveyForm( &$s ) {
global $group_id;
global $survey_id;
if (!$s->isActive()) {
return ''. _('Error - you can\'t vote for inactive survey').'
';
}
/* Get questions of this survey */
$questions = & $s->getQuestionInstances();
$ret="";
if ($s->isUserVote(user_getid())) {
$ret.= ''. _('Warning - you are about to vote a second time on this survey.').'
';
}
$ret.= '