123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432 |
- <?php
- $language_file = 'survey';
- require ('../inc/global.inc.php');
- require_once('survey.lib.php');
- require_once (api_get_path(LIBRARY_PATH)."/course.lib.php");
- if (!api_is_allowed_to_edit())
- {
- Display :: display_header();
- Display :: display_error_message(get_lang('NotAllowedHere'));
- Display :: display_footer();
- exit;
- }
- $table_survey = Database :: get_course_table(TABLE_SURVEY);
- $table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
- $table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
- $table_user = Database :: get_main_table(TABLE_MAIN_USER);
- if (isset ($_GET['search']) && $_GET['search'] == 'advanced')
- {
- $tool_name = get_lang('SearchASurvey');
- }
- else
- {
- $tool_name = get_lang('SurveyList');
- }
- Display :: display_header($tool_name);
- if (isset ($_GET['search']) AND $_GET['search'] == 'advanced')
- {
- display_survey_search_form();
- }
- if (isset($_GET['action']) AND $_GET['action'] == 'delete' AND isset($_GET['survey_id']) AND is_numeric($_GET['survey_id']))
- {
- $return = survey_manager :: delete_survey($_GET['survey_id']);
- if ($return)
- {
- Display :: display_confirmation_message(get_lang('SurveyDeleted'));
- }
- else
- {
- Display :: display_error_message(get_lang('ErrorOccurred'));
- }
- }
- if ($_POST['action'])
- {
- if (is_array($_POST['id']))
- {
- foreach ($_POST['id'] as $key=>$value)
- {
- delete_survey($value);
- }
- Display :: display_confirmation_message(get_lang('SurveyDeleted'));
- }
- else
- {
- Display :: display_error_message(get_lang('NoSurveysSelected'));
- }
- }
- echo '<a href="create_new_survey.php?action=add">'.get_lang('CreateNewSurvey').'</a> | ';
- echo '<a href="'.$_SERVER['PHP_SELF'].'?search=advanced">'.get_lang('Search').'</a>';
- display_survey_list();
- Display :: display_footer();
- function display_survey_search_form()
- {
- echo '<form method="get" action="survey_list.php?search=advanced">';
- echo '<table>
- <tr>
- <td>'.get_lang('Title').'</td>
- <td><input type="text" name="keyword_title"/></td>
- </tr>
- <tr>
- <td>'.get_lang('Code').'</td>
- <td><input type="text" name="keyword_code"/></td>
- </tr>
- <tr>
- <td>'.get_lang('Language').'</td>
- <td>
- <select name="keyword_language"><option value="%">'.get_lang('All').'</option>';
- $languages = api_get_languages();
- foreach ($languages['name'] as $index => $name)
- {
- echo '<option value="'.$languages['folder'][$index].'">'.$name.'</option>';
- }
- echo ' </select>
- </td>
- </tr>
- <tr>
- <td> </td>
- <td><input type="submit" name="do_search" value="'.get_lang('Ok').'"/></td>
- </tr>
- </table>
- </form>';
- }
- function display_survey_list()
- {
- if ($_GET['do_search'])
- {
- $message = get_lang('DisplaySearchResults').'<br />';
- $message .= '<a href="'.$_SERVER['PHP_SELF'].'">'.get_lang('DisplayAll').'</a>';
- Display::display_normal_message($message);
- }
-
- $table = new SortableTable('surveys', 'get_number_of_surveys', 'get_survey_data',2);
- $table->set_additional_parameters($parameters);
- $table->set_header(0, '', false);
- $table->set_header(1, get_lang('SurveyName'));
- $table->set_header(2, get_lang('SurveyCode'));
- $table->set_header(3, get_lang('NumberOfQuestions'));
- $table->set_header(4, get_lang('Author'));
- $table->set_header(5, get_lang('Language'));
- $table->set_header(6, get_lang('AvailableFrom'));
- $table->set_header(7, get_lang('AvailableUntill'));
- $table->set_header(8, get_lang('Invite'));
- $table->set_header(9, get_lang('Modify'), false);
- $table->set_column_filter(9, 'modify_filter');
- $table->set_form_actions(array ('delete' => get_lang('DeleteSurvey')));
- $table->display();
- }
- function get_number_of_surveys()
- {
- global $table_survey;
- $search_restriction = survey_search_restriction();
- if ($search_restriction)
- {
- $search_restriction = 'WHERE '.$search_restriction;
- }
- $sql = "SELECT count(survey_id) AS total_number_of_items FROM ".$table_survey.' '.$search_restriction;
- $res = api_sql_query($sql, __FILE__, __LINE__);
- $obj = mysql_fetch_object($res);
- return $obj->total_number_of_items;
- }
- function get_survey_data($from, $number_of_items, $column, $direction)
- {
- global $table_survey;
- global $table_user;
- global $table_survey_question;
-
- $search_restriction = survey_search_restriction();
- if ($search_restriction)
- {
- $search_restriction = ' AND '.$search_restriction;
- }
- $sql = "SELECT
- survey.survey_id AS col0,
- CONCAT('<a href=\"survey.php?survey_id=',survey.survey_id,'\">',survey.title,'</a>') AS col1,
- survey.code AS col2,
- count(survey_question.question_id) AS col3,
- CONCAT(user.firstname, ' ', user.lastname) AS col4,
- survey.lang AS col5,
- survey.avail_from AS col6,
- survey.avail_till AS col7,
- CONCAT('<a href=\"survey_invitation.php?view=answered&survey_id=',survey.survey_id,'\">',survey.answered,'</a> / <a href=\"survey_invitation.php?view=invited&survey_id=',survey.survey_id,'\">',survey.invited, '</a>') AS col8,
- survey.survey_id AS col9
- FROM $table_survey survey
- LEFT JOIN $table_survey_question survey_question ON survey.survey_id = survey_question.survey_id
- , $table_user user
- WHERE survey.author = user.user_id
- $search_restriction
- ";
- $sql .= " GROUP BY survey.survey_id";
- $sql .= " ORDER BY col$column $direction ";
- $sql .= " LIMIT $from,$number_of_items";
- $res = api_sql_query($sql, __FILE__, __LINE__);
- $surveys = array ();
- while ($survey = mysql_fetch_row($res))
- {
- $surveys[] = $survey;
- }
- return $surveys;
- }
- function modify_filter($survey_id)
- {
- $return = '<a href="create_new_survey.php?action=edit&survey_id='.$survey_id.'">'.Display::return_icon('edit.gif').'</a>';
- $return .= '<a href="survey_list.php?action=delete&survey_id='.$survey_id.'">'.Display::return_icon('delete.gif').'</a>';
-
-
- $return .= '<a href="preview.php?survey_id='.$survey_id.'">'.Display::return_icon('preview.gif').'</a>';
- $return .= '<a href="survey_invite.php?survey_id='.$survey_id.'">'.Display::return_icon('survey_publish.gif').'</a>';
- $return .= '<a href="reporting.php?survey_id='.$survey_id.'">'.Display::return_icon('surveyreporting.gif').'</a>';
- return $return;
- }
- function survey_search_restriction()
- {
- if ($_GET['do_search'])
- {
- if ($_GET['keyword_title']<>'')
- {
- $search_term[] = 'title =\''.mysql_real_escape_string($_GET['keyword_title']).'\'';
- }
- if ($_GET['keyword_code']<>'')
- {
- $search_term[] = 'code =\''.mysql_real_escape_string($_GET['keyword_code']).'\'';
- }
- if ($_GET['keyword_language']<>'%')
- {
- $search_term[] = 'lang =\''.mysql_real_escape_string($_GET['keyword_language']).'\'';
- }
- $search_restriction = implode(' AND ', $search_term);
- return $search_restriction;
- }
- else
- {
- return false;
- }
- }
- ?>
|