diff --git a/main/inc/lib/gradebook.lib.php b/main/inc/lib/gradebook.lib.php index 1f6236e958..1b972088aa 100644 --- a/main/inc/lib/gradebook.lib.php +++ b/main/inc/lib/gradebook.lib.php @@ -3,33 +3,20 @@ /** * This class provides methods for the notebook management. * Include/require it in your code to use its features. - * @package chamilo.library + * @package chamilo.library */ /** * Code */ - class Gradebook extends Model { - - public $columns = array( - 'id', - 'name', - 'description', - 'course_code', - 'parent_id', - 'grade_model_id', - 'session_id', - 'weight', - 'user_id' - ); - + public $columns = array('id', 'name', 'description', 'course_code', 'parent_id', 'grade_model_id', 'session_id', 'weight', 'user_id'); public function __construct() { - $this->table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); - $this->table_skill = Database::get_main_table(TABLE_MAIN_SKILL); - $this->table_skill_rel_gradebook = Database::get_main_table(TABLE_MAIN_SKILL_REL_GRADEBOOK); + $this->table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); + $this->table_skill = Database::get_main_table(TABLE_MAIN_SKILL); + $this->table_skill_rel_gradebook = Database::get_main_table(TABLE_MAIN_SKILL_REL_GRADEBOOK); } /** @@ -41,24 +28,28 @@ class Gradebook extends Model */ public static function is_active($c_id = null) { - $name = 'gradebook'; - $table = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT); - $sql = "SELECT * from $table WHERE variable='course_hide_tools' AND subkey='$name'"; - $setting = ResultSet::create($sql)->first(); - $setting = $setting ? $setting : array(); + $name = 'gradebook'; + $table = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT); + $sql = "SELECT * from $table WHERE variable='course_hide_tools' AND subkey='$name' LIMIT 1"; + $result = Database::query($sql); + $setting = Database::store_result($result); + $setting = isset($setting[0]) ? $setting[0] : null; + $setting = $setting ? $setting : array(); $inactive = isset($setting['selected_value']) && $setting['selected_value'] == 'true'; if ($inactive) { return false; } - $c_id = $c_id ? intval($c_id) : api_get_course_int_id(); - $table = Database::get_course_table(TABLE_TOOL_LIST); - $sql = "SELECT * from $table WHERE c_id = $c_id and name='$name'"; - $item = ResultSet::create($sql)->first(); + + $c_id = $c_id ? intval($c_id) : api_get_course_int_id(); + $table = Database::get_course_table(TABLE_TOOL_LIST); + $sql = "SELECT * from $table WHERE c_id = $c_id and name='$name' LIMIT 1"; + $result = Database::query($sql); + $item = Database::store_result($result, 'ASSOC'); + $item = isset($item[0]) ? $item[0] : null; if (empty($item)) { return true; } - return $item['visibility'] == '1'; } @@ -69,8 +60,8 @@ class Gradebook extends Model if (empty($gradebook['name'])) { $gradebook['name'] = $gradebook['course_code']; } + //$gradebook['name'] = $gradebook['course_code'] .' > '.$gradebook['name']; } - return $gradebooks; } @@ -85,16 +76,14 @@ class Gradebook extends Model if (!empty($skill_list)) { //Cleaning skills - $skill_list = array_map('intval', $skill_list); - $skill_list = array_filter($skill_list); - $skill_gradebook = new SkillRelGradebook(); - $skill_gradebooks_source = $skill_gradebook->get_all( - array('where' => array('gradebook_id = ?' => $gradebook_id)) - ); - $clean_gradebook = array(); + $skill_list = array_map('intval', $skill_list); + $skill_list = array_filter($skill_list); + $skill_gradebook = new SkillRelGradebook(); + $skill_gradebooks_source = $skill_gradebook->get_all(array('where'=>array('gradebook_id = ?' =>$gradebook_id))); + $clean_gradebook = array(); if (!empty($skill_gradebooks_source)) { - foreach ($skill_gradebooks_source as $source) { - $clean_gradebook[] = $source['skill_id']; + foreach($skill_gradebooks_source as $source) { + $clean_gradebook[]= $source['skill_id']; } } if (!empty($clean_gradebook)) { @@ -102,7 +91,7 @@ class Gradebook extends Model } foreach ($skill_list as $skill_id) { - $params = array(); + $params = array(); $params['gradebook_id'] = $gradebook_id; $params['skill_id'] = $skill_id; if (!$skill_gradebook->exists_gradebook_skill($gradebook_id, $skill_id)) { @@ -111,15 +100,13 @@ class Gradebook extends Model } if (!empty($skill_to_remove)) { - foreach ($skill_to_remove as $remove) { + foreach($skill_to_remove as $remove) { $skill_item = $skill_gradebook->get_skill_info($remove, $gradebook_id); $skill_gradebook->delete($skill_item['id']); } } - return true; } - return false; } @@ -132,9 +119,8 @@ class Gradebook extends Model */ public function show_skill_form($gradebook_id, $url, $header = null) { - $form = new FormValidator('gradebook_add_skill', 'POST', $url); - // Settting the form elements + // Setting the form elements if (!isset($header)) { $header = get_lang('Add'); } @@ -142,44 +128,40 @@ class Gradebook extends Model $id = isset($_GET['id']) ? intval($_GET['id']) : ''; $form->addElement('hidden', 'id', $id); - $skill = new Skill(); - $skills = $skill->get_all(); + $skill = new Skill(); + $skills = $skill->get_all(); $clean_skill_list = array(); foreach ($skills as $skill) { $clean_skill_list[$skill['id']] = $skill['name']; } - $form->addElement( - 'select', - 'skill', - get_lang('Skills'), - $clean_skill_list, - array('width' => '450px', 'class' => 'chzn-select', 'multiple' => 'multiple') - ); - - $selected_skills = self::get_skills_by_gradebook($gradebook_id); + $form->addElement('select', 'skill', get_lang('Skills'), $clean_skill_list, array('width'=>'450px', 'class'=>'chzn-select','multiple' => 'multiple')); + + $selected_skills = self::get_skills_by_gradebook($gradebook_id); $clean_selected_skills = array(); if (!empty($selected_skills)) { - foreach ($selected_skills as $skill) { + foreach($selected_skills as $skill) { $clean_selected_skills[] = $skill['id']; } } $form->addElement('style_submit_button', 'submit', get_lang('Add'), 'class="save"'); - $form->setDefaults(array('skill' => $clean_selected_skills)); - + $form->setDefaults(array('skill'=>$clean_selected_skills)); return $form; } + /** + * @param int $gradebook_id + * @return array|resource + */ function get_skills_by_gradebook($gradebook_id) { $gradebook_id = intval($gradebook_id); - $sql = "SELECT skill.id, skill.name FROM {$this->table_skill} skill INNER JOIN {$this->table_skill_rel_gradebook} skill_rel_gradebook + $sql = "SELECT skill.id, skill.name FROM {$this->table_skill} skill INNER JOIN {$this->table_skill_rel_gradebook} skill_rel_gradebook ON skill.id = skill_rel_gradebook.skill_id WHERE skill_rel_gradebook.gradebook_id = $gradebook_id"; - $result = Database::query($sql); - $result = Database::store_result($result, 'ASSOC'); - + $result = Database::query($sql); + $result = Database::store_result($result,'ASSOC'); return $result; } diff --git a/main/survey/create_new_survey.php b/main/survey/create_new_survey.php index 059006fc23..cb764b8c52 100644 --- a/main/survey/create_new_survey.php +++ b/main/survey/create_new_survey.php @@ -1,15 +1,14 @@ , Ghent University: cleanup, refactoring and rewriting large parts (if not all) of the code - * @author Julio Montoya Armas , Chamilo: Personality Test modification and rewriting large parts of the code - * @version $Id: create_new_survey.php 22297 2009-07-22 22:08:30Z cfasanando $ + * @package chamilo.survey + * @author unknown, the initial survey that did not make it in 1.8 because of bad code + * @author Patrick Cool , Ghent University: cleanup, refactoring and rewriting large parts (if not all) of the code + * @author Julio Montoya Armas , Chamilo: Personality Test modification and rewriting large parts of the code + * @version $Id: create_new_survey.php 22297 2009-07-22 22:08:30Z cfasanando $ * - * @todo only the available platform languages should be used => need an api get_languages and and api_get_available_languages (or a parameter) + * @todo only the available platform languages should be used => need an api get_languages and and api_get_available_languages (or a parameter) */ // Language file that needs to be included $language_file = 'survey'; @@ -24,12 +23,24 @@ $this_section = SECTION_COURSES; /** @todo check if the starting / is needed. api_get_path probably ends with an / */ //require_once api_get_path(LIBRARY_PATH).'survey.lib.php'; require_once 'survey.lib.php'; +//require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php'; require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc.php'; $htmlHeadXtra[] = ''; +} ); '; /** @todo this has to be moved to a more appropriate place (after the display_header of the code)*/ if (!api_is_allowed_to_edit(false, true)) { @@ -35,7 +34,6 @@ if (!api_is_allowed_to_edit(false, true)) { // Is valid request $is_valid_request = isset($_REQUEST['is_executable']) ? $_REQUEST['is_executable'] : null; - if ($request_index != $is_valid_request) { if ($request_index == 'save_question') { unset($_POST[$request_index]); @@ -72,17 +70,20 @@ if (api_strlen(strip_tags($survey_data['title'])) > 40) { } if ($survey_data['survey_type'] == 1) { - $sql = 'SELECT id FROM '.Database :: get_course_table(TABLE_SURVEY_QUESTION_GROUP).' WHERE c_id = '.$course_id.' AND survey_id = '.(int)$_GET['survey_id'].' LIMIT 1'; + $sql = 'SELECT id FROM '.Database :: get_course_table(TABLE_SURVEY_QUESTION_GROUP).' + WHERE + c_id = '.$course_id.' AND + survey_id = '.(int)$_GET['survey_id'].' LIMIT 1'; $rs = Database::query($sql); if(Database::num_rows($rs)===0) { - header('Location: survey.php?survey_id='.(int)$_GET['survey_id'].'&message='.'YouNeedToCreateGroups'); + header('Location: '.api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.(int)$_GET['survey_id'].'&message='.'YouNeedToCreateGroups'); exit; } } // Breadcrumbs -$interbreadcrumb[] = array ('url' => 'survey_list.php', 'name' => get_lang('SurveyList')); -$interbreadcrumb[] = array ('url' => 'survey.php?survey_id='.Security::remove_XSS($_GET['survey_id']), 'name' => strip_tags($urlname)); +$interbreadcrumb[] = array ('url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php', 'name' => get_lang('SurveyList')); +$interbreadcrumb[] = array ('url' => api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.Security::remove_XSS($_GET['survey_id']), 'name' => strip_tags($urlname)); // Tool name if ($_GET['action'] == 'add') { @@ -97,7 +98,7 @@ $possible_types = array('personality', 'yesno', 'multiplechoice', 'multiplerespo // Actions $actions = ''; // Checking if it is a valid type if (!in_array($_GET['type'], $possible_types)) { @@ -118,7 +119,11 @@ if (empty($_POST['save_question']) && in_array($_GET['type'], $possible_types)) if (isset($_SESSION['temp_sys_message'])) { $error_message=$_SESSION['temp_sys_message']; unset($_SESSION['temp_sys_message']); - if ($error_message == 'PleaseEnterAQuestion' || $error_message == 'PleasFillAllAnswer'|| $error_message == 'PleaseChooseACondition'|| $error_message == 'ChooseDifferentCategories') { + if ($error_message == 'PleaseEnterAQuestion' || + $error_message == 'PleasFillAllAnswer'|| + $error_message == 'PleaseChooseACondition'|| + $error_message == 'ChooseDifferentCategories' + ) { Display::display_error_message(get_lang($error_message), true); } } @@ -156,7 +161,10 @@ if (empty($_POST['save_question']) && in_array($_GET['type'], $possible_types)) // An action has been performed (for instance adding a possible answer, moving an answer, ...) if ($_POST) { $form_content = $_POST; - $form_content = $form->handle_action($form_content); + $form_content = $form->handle_action( + $survey_data, + $form_content + ); } if ($error_message != '') { @@ -171,12 +179,12 @@ if (empty($_POST['save_question']) && in_array($_GET['type'], $possible_types)) unset($_SESSION['temp_horizontalvertical']); } - $form->create_form($form_content); + $form->create_form($survey_data, $form_content); $form->render_form(); } else { $form_content = $_POST; $form = new survey_question(); - $form->handle_action($form_content); + $form->handle_action($survey_data, $form_content); } // Footer diff --git a/main/survey/reporting.php b/main/survey/reporting.php index c1a82ff1d1..6d9e9fe1da 100644 --- a/main/survey/reporting.php +++ b/main/survey/reporting.php @@ -17,7 +17,6 @@ $language_file = 'survey'; require_once '../inc/global.inc.php'; require_once 'survey.lib.php'; $this_section = SECTION_COURSES; - $survey_id = intval($_GET['survey_id']); // Export @@ -25,17 +24,17 @@ $survey_id = intval($_GET['survey_id']); * @todo use export_table_csv($data, $filename = 'export') */ if (isset($_POST['export_report']) && $_POST['export_report']) { - switch($_POST['export_format']) { + switch ($_POST['export_format']) { case 'xls': $survey_data = survey_manager::get_survey($survey_id); $filename = 'survey_results_'.$survey_id.'.xls'; - $data = SurveyUtil::export_complete_report_xls($filename, $_GET['user_id']); + $data = SurveyUtil::export_complete_report_xls($survey_data, $filename, $_GET['user_id']); exit; break; case 'csv': default: $survey_data = survey_manager::get_survey($survey_id); - $data = SurveyUtil::export_complete_report($_GET['user_id']); + $data = SurveyUtil::export_complete_report($survey_data, $_GET['user_id']); //$filename = 'fileexport.csv'; $filename = 'survey_results_'.$survey_id.'.csv'; @@ -61,8 +60,19 @@ if (isset($_POST['export_report']) && $_POST['export_report']) { } } +if ($survey_data['anonymous'] == 0) { + $people_filled_full_data = true; +} else { + $people_filled_full_data = false; +} +$people_filled = survey_manager::get_people_who_filled_survey( + $_GET['survey_id'], + $people_filled_full_data +); + // Checking the parameters -SurveyUtil::check_parameters(); +SurveyUtil::check_parameters($people_filled); + /** @todo this has to be moved to a more appropriate place (after the display_header of the code)*/ if (!api_is_allowed_to_edit(false, true)) { @@ -92,12 +102,15 @@ if (api_strlen(strip_tags($survey_data['title'])) > 40) { } // Breadcrumbs -$interbreadcrumb[] = array('url' => 'survey_list.php', 'name' => get_lang('SurveyList')); -$interbreadcrumb[] = array('url' => 'survey.php?survey_id='.$survey_id, 'name' => $urlname); +$interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'survey/survey_list.php', 'name' => get_lang('SurveyList')); +$interbreadcrumb[] = array('url' => api_get_path(WEB_CODE_PATH).'survey/survey.php?survey_id='.$survey_id, 'name' => $urlname); if (!$_GET['action'] OR $_GET['action'] == 'overview') { $tool_name = get_lang('Reporting'); } else { - $interbreadcrumb[] = array('url' => 'reporting.php?survey_id='.$survey_id, 'name' => get_lang('Reporting')); + $interbreadcrumb[] = array( + 'url' => api_get_path(WEB_CODE_PATH).'survey/reporting.php?survey_id='.$survey_id, + 'name' => get_lang('Reporting') + ); switch ($_GET['action']) { case 'questionreport': $tool_name = get_lang('DetailedReportByQuestion'); @@ -118,19 +131,20 @@ if (!$_GET['action'] OR $_GET['action'] == 'overview') { Display::display_header($tool_name, 'Survey'); // Action handling -SurveyUtil::handle_reporting_actions(); +SurveyUtil::handle_reporting_actions($people_filled); // Actions bar echo ''; // Content if (!$_GET['action'] || $_GET['action'] == 'overview') { $myweb_survey_id = $survey_id; - echo '
'.get_lang('DetailedReportByQuestionDetail').'
'; - echo '
'.get_lang('DetailedReportByUserDetail').'.
'; - echo '
'.get_lang('ComparativeReportDetail').'.
'; + echo '
'.get_lang('DetailedReportByQuestionDetail').'
'; + echo '
'.get_lang('DetailedReportByUserDetail').'.
'; + echo '
'.get_lang('ComparativeReportDetail').'.
'; echo '
'.get_lang('CompleteReportDetail').'
'; } diff --git a/main/survey/survey.download.inc.php b/main/survey/survey.download.inc.php index 89e1d4944d..53960f55b7 100644 --- a/main/survey/survey.download.inc.php +++ b/main/survey/survey.download.inc.php @@ -26,7 +26,10 @@ function check_download_survey($course, $invitation, $doc_url) { $table_survey_invitation = Database :: get_course_table(TABLE_SURVEY_INVITATION); // Now we check if the invitationcode is valid - $sql = "SELECT * FROM $table_survey_invitation WHERE c_id = $course_id AND invitation_code = '".Database::escape_string($invitation)."'"; + $sql = "SELECT * FROM $table_survey_invitation + WHERE + c_id = $course_id AND + invitation_code = '".Database::escape_string($invitation)."'"; $result = Database::query($sql); if (Database::num_rows($result) < 1) { Display :: display_error_message(get_lang('WrongInvitationCode'), false); @@ -47,13 +50,16 @@ function check_download_survey($course, $invitation, $doc_url) { // Fetch survey ID // If this is the case there will be a language choice - $sql = "SELECT * FROM $table_survey WHERE c_id = $course_id AND code='".Database::escape_string($survey_invitation['survey_code'])."'"; + $sql = "SELECT * FROM $table_survey + WHERE + c_id = $course_id AND + code='".Database::escape_string($survey_invitation['survey_code'])."'"; $result = Database::query($sql); if (Database::num_rows($result) > 1) { if ($_POST['language']) { $survey_invitation['survey_id'] = $_POST['language']; } else { - echo '
'; + echo ''; echo ' '; - $this->html .= ' '; - $this->html .= ' '; - $this->html .= ' '; - - // question field - $this->html .= '
'; - $this->html .= ' '; - $this->html .= '
'; - $this->html .= api_return_html_area( - 'question', - Security::remove_XSS($form_content['question'], STUDENT), - '', - '', - null, - array('ToolbarSet' => 'Survey', 'Width' => '100%', 'Height' => '120') - ); - $this->html .= '
'; - $this->html .= '
'; - - if ($survey_data['survey_type'] == 1) { - $table_survey_question_group = Database::get_course_table(TABLE_SURVEY_QUESTION_GROUP); - $sql = 'SELECT id,name FROM '.$table_survey_question_group.' WHERE survey_id = '.(int)$_GET['survey_id'].' ORDER BY name'; - $rs = Database::query($sql); - $glist = null; - while ($row = Database::fetch_array($rs, 'NUM')) { - $glist .= ''; - } - $grouplist = $grouplist1 = $grouplist2 = $glist; - - if (!empty($form_content['assigned'])) { - $grouplist = str_replace( - ''; + } + + $grouplist = $grouplist1 = $grouplist2 = $glist; + + if (!empty($form_content['assigned'])) { + $grouplist = str_replace('