[svn r15880] Improvements to code syntax

skala
Yannick Warnier 17 years ago
parent f201e4ebd2
commit ac10d14d6f
  1. 4
      main/inc/lib/database.lib.php
  2. 4
      main/survey/question.php
  3. 16
      main/survey/survey.lib.php
  4. 42
      main/survey/survey.php

@ -1,4 +1,4 @@
<?php // $Id: database.lib.php 15839 2008-07-23 22:58:07Z dperales $ <?php // $Id: database.lib.php 15880 2008-07-31 19:58:31Z yannoo $
/* See license terms in /dokeos_license.txt */ /* See license terms in /dokeos_license.txt */
/** /**
============================================================================== ==============================================================================
@ -169,7 +169,7 @@ define('TABLE_SURVEY_QUESTION', 'survey_question');
define('TABLE_SURVEY_QUESTION_OPTION', 'survey_question_option'); define('TABLE_SURVEY_QUESTION_OPTION', 'survey_question_option');
define('TABLE_SURVEY_INVITATION', 'survey_invitation'); define('TABLE_SURVEY_INVITATION', 'survey_invitation');
define('TABLE_SURVEY_ANSWER', 'survey_answer'); define('TABLE_SURVEY_ANSWER', 'survey_answer');
define('TABLE_SURVEY_GROUP','survey_group'); define('TABLE_SURVEY_QUESTION_GROUP','survey_group');
/* /*
============================================================================== ==============================================================================

@ -23,7 +23,7 @@
* @package dokeos.survey * @package dokeos.survey
* @author unknown, the initial survey that did not make it in 1.8 because of bad code * @author unknown, the initial survey that did not make it in 1.8 because of bad code
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: cleanup, refactoring and rewriting large parts of the code * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: cleanup, refactoring and rewriting large parts of the code
* @version $Id: question.php 15875 2008-07-30 23:21:03Z juliomontoya $ * @version $Id: question.php 15880 2008-07-31 19:58:31Z yannoo $
*/ */
// name of the language file that needs to be included // name of the language file that needs to be included
@ -65,7 +65,7 @@ if (strlen(strip_tags($survey_data['title'])) > 40)
if($survey_data['survey_type']==1) if($survey_data['survey_type']==1)
{ {
$sql = 'SELECT id FROM '.Database :: get_course_table(TABLE_SURVEY_GROUP).' WHERE survey_id = '.(int)$_GET['survey_id'].' LIMIT 1'; $sql = 'SELECT id FROM '.Database :: get_course_table(TABLE_SURVEY_QUESTION_GROUP).' WHERE survey_id = '.(int)$_GET['survey_id'].' LIMIT 1';
$rs = api_sql_query($sql,__FILE__,__LINE__); $rs = api_sql_query($sql,__FILE__,__LINE__);
if(Database::num_rows($rs)===0) { if(Database::num_rows($rs)===0) {
header('Location: survey.php?survey_id='.(int)$_GET['survey_id'].'&message='.'YouNeedToCreateGroups'); header('Location: survey.php?survey_id='.(int)$_GET['survey_id'].'&message='.'YouNeedToCreateGroups');

@ -24,7 +24,7 @@
* @package dokeos.survey * @package dokeos.survey
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: cleanup, refactoring and rewriting large parts (if not all) of the code * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: cleanup, refactoring and rewriting large parts (if not all) of the code
@author Julio Montoya Armas <gugli100@gmail.com>, Dokeos: Personality Test modification and rewriting large parts of the code @author Julio Montoya Armas <gugli100@gmail.com>, Dokeos: Personality Test modification and rewriting large parts of the code
* @version $Id: survey.lib.php 15878 2008-07-31 12:58:51Z elixir_inter $ * @version $Id: survey.lib.php 15880 2008-07-31 19:58:31Z yannoo $
* *
* @todo move this file to inc/lib * @todo move this file to inc/lib
* @todo use consistent naming for the functions (save vs store for instance) * @todo use consistent naming for the functions (save vs store for instance)
@ -305,7 +305,7 @@ class survey_manager
{ {
// Database table definitions // Database table definitions
$table_survey = Database :: get_course_table(TABLE_SURVEY); $table_survey = Database :: get_course_table(TABLE_SURVEY);
$table_survey_group = Database :: get_course_table(TABLE_SURVEY_GROUP); $table_survey_question_group = Database :: get_course_table(TABLE_SURVEY_QUESTION_GROUP);
if ($shared) if ($shared)
{ {
$table_survey = Database :: get_main_table(TABLE_MAIN_SHARED_SURVEY); $table_survey = Database :: get_main_table(TABLE_MAIN_SHARED_SURVEY);
@ -316,7 +316,7 @@ class survey_manager
$res = api_sql_query($sql, __FILE__, __LINE__); $res = api_sql_query($sql, __FILE__, __LINE__);
// deleting groups of this survey // deleting groups of this survey
$sql = "DELETE from $table_survey_group WHERE survey_id='".Database::escape_string($survey_id)."'"; $sql = "DELETE from $table_survey_question_group WHERE survey_id='".Database::escape_string($survey_id)."'";
$res = api_sql_query($sql, __FILE__, __LINE__); $res = api_sql_query($sql, __FILE__, __LINE__);
// deleting the questions of the survey // deleting the questions of the survey
@ -329,17 +329,17 @@ class survey_manager
{ {
// Database table definitions // Database table definitions
$table_survey = Database :: get_course_table(TABLE_SURVEY); $table_survey = Database :: get_course_table(TABLE_SURVEY);
$table_survey_group = Database :: get_course_table(TABLE_SURVEY_GROUP); $table_survey_question_group = Database :: get_course_table(TABLE_SURVEY_QUESTION_GROUP);
$table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION); $table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
$table_survey_options = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION); $table_survey_options = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
//get groups //get groups
$sql = "SELECT * from $table_survey_group WHERE survey_id='".$parent_survey."'"; $sql = "SELECT * from $table_survey_question_group WHERE survey_id='".$parent_survey."'";
$res = api_sql_query($sql, __FILE__, __LINE__); $res = api_sql_query($sql, __FILE__, __LINE__);
if(Database::num_rows($res)===0) return true; if(Database::num_rows($res)===0) return true;
while($row = Database::fetch_array($res,ASSOC)){ while($row = Database::fetch_array($res,ASSOC)){
$sql1 = 'INSERT INTO '.$table_survey_group.' (name,description,survey_id) VALUES (\''.Database::escape_string($row['name']).'\',\''.Database::escape_string($row['description']).'\',\''.$new_survey_id.'\')'; $sql1 = 'INSERT INTO '.$table_survey_question_group.' (name,description,survey_id) VALUES (\''.Database::escape_string($row['name']).'\',\''.Database::escape_string($row['description']).'\',\''.$new_survey_id.'\')';
$res1 = api_sql_query($sql1, __FILE__, __LINE__); $res1 = api_sql_query($sql1, __FILE__, __LINE__);
$group_id[$row['id']] = Database::insert_id(); $group_id[$row['id']] = Database::insert_id();
} }
@ -1249,8 +1249,8 @@ class question
if($survey_data['survey_type']==1) if($survey_data['survey_type']==1)
{ {
$table_surve_group = Database::get_course_table(TABLE_SURVEY_GROUP); $table_survey_question_group = Database::get_course_table(TABLE_SURVEY_QUESTION_GROUP);
$sql = 'SELECT id,name FROM '.$table_surve_group.' WHERE survey_id = '.(int)$_GET['survey_id'].' ORDER BY name'; $sql = 'SELECT id,name FROM '.$table_survey_question_group.' WHERE survey_id = '.(int)$_GET['survey_id'].' ORDER BY name';
$rs = api_sql_query($sql,__FILE__,__LINE__); $rs = api_sql_query($sql,__FILE__,__LINE__);
while($row = Database::fetch_array($rs,NUM)) while($row = Database::fetch_array($rs,NUM))

@ -24,7 +24,7 @@
* @package dokeos.survey * @package dokeos.survey
* @author unknown * @author unknown
* @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: cleanup, refactoring and rewriting large parts of the code * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University: cleanup, refactoring and rewriting large parts of the code
* @version $Id: survey.php 15875 2008-07-30 23:21:03Z juliomontoya $ * @version $Id: survey.php 15880 2008-07-31 19:58:31Z yannoo $
* *
* @todo use quickforms for the forms * @todo use quickforms for the forms
*/ */
@ -53,10 +53,10 @@ if (!api_is_allowed_to_edit())
$table_survey = Database :: get_course_table(TABLE_SURVEY); $table_survey = Database :: get_course_table(TABLE_SURVEY);
$table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION); $table_survey_question = Database :: get_course_table(TABLE_SURVEY_QUESTION);
$table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION); $table_survey_question_option = Database :: get_course_table(TABLE_SURVEY_QUESTION_OPTION);
$table_survey_question_group = Database :: get_course_table(TABLE_SURVEY_QUESTION_GROUP);
$table_course = Database :: get_main_table(TABLE_MAIN_COURSE); $table_course = Database :: get_main_table(TABLE_MAIN_COURSE);
$table_user = Database :: get_main_table(TABLE_MAIN_USER); $table_user = Database :: get_main_table(TABLE_MAIN_USER);
$user_info = Database :: get_main_table(TABLE_MAIN_SURVEY_REMINDER); $user_info = Database :: get_main_table(TABLE_MAIN_SURVEY_REMINDER);
$table_survey_question_group = Database :: get_main_table(TABLE_SURVEY_QUESTION_GROUP);
// breadcrumbs // breadcrumbs
$interbreadcrumb[] = array ("url" => "survey_list.php", "name" => get_lang('SurveyList')); $interbreadcrumb[] = array ("url" => "survey_list.php", "name" => get_lang('SurveyList'));
@ -72,19 +72,18 @@ if (strlen(strip_tags($survey_data['title'])) > 40)
if($is_survey_type_1 && ($_GET['action']=='addgroup')||($_GET['action']=='deletegroup')) if($is_survey_type_1 && ($_GET['action']=='addgroup')||($_GET['action']=='deletegroup'))
{ {
$table_survey_group = Database::get_course_table(TABLE_SURVEY_GROUP);
$_POST['name'] = trim($_POST['name']); $_POST['name'] = trim($_POST['name']);
if(($_GET['action']=='addgroup')) if(($_GET['action']=='addgroup'))
{ {
if(!empty($_POST['group_id'])) if(!empty($_POST['group_id']))
{ {
api_sql_query('UPDATE '.$table_survey_group.' SET description = \''.Database::escape_string($_POST['description']).'\' WHERE id = \''.Database::escape_string($_POST['group_id']).'\''); api_sql_query('UPDATE '.$table_survey_question_group.' SET description = \''.Database::escape_string($_POST['description']).'\' WHERE id = \''.Database::escape_string($_POST['group_id']).'\'');
$sendmsg = 'GroupUpdatedSuccessfully'; $sendmsg = 'GroupUpdatedSuccessfully';
} }
elseif(!empty($_POST['name'])) elseif(!empty($_POST['name']))
{ {
api_sql_query('INSERT INTO '.$table_survey_group.' (name,description,survey_id) values (\''.Database::escape_string($_POST['name']).'\',\''.Database::escape_string($_POST['description']).'\',\''.Database::escape_string($_GET['survey_id']).'\') '); api_sql_query('INSERT INTO '.$table_survey_question_group.' (name,description,survey_id) values (\''.Database::escape_string($_POST['name']).'\',\''.Database::escape_string($_POST['description']).'\',\''.Database::escape_string($_GET['survey_id']).'\') ');
$sendmsg = 'GroupCreatedSuccessfully'; $sendmsg = 'GroupCreatedSuccessfully';
} else { } else {
$sendmsg = 'GroupNeedName'; $sendmsg = 'GroupNeedName';
@ -92,7 +91,7 @@ if($is_survey_type_1 && ($_GET['action']=='addgroup')||($_GET['action']=='delete
} }
if($_GET['action']=='deletegroup'){ if($_GET['action']=='deletegroup'){
api_sql_query('DELETE FROM '.$table_survey_group.' WHERE id = '.Database::escape_string($_GET['gid']).' and survey_id = '.Database::escape_string($_GET['survey_id'])); api_sql_query('DELETE FROM '.$table_survey_question_group.' WHERE id = '.Database::escape_string($_GET['gid']).' and survey_id = '.Database::escape_string($_GET['survey_id']));
$sendmsg = 'GroupDeletedSuccessfully'; $sendmsg = 'GroupDeletedSuccessfully';
} }
@ -187,10 +186,21 @@ echo ' <th>'.get_lang('Title').'</th>';
echo ' <th>'.get_lang('Type').'</th>'; echo ' <th>'.get_lang('Type').'</th>';
echo ' <th>'.get_lang('NumberOfOptions').'</th>'; echo ' <th>'.get_lang('NumberOfOptions').'</th>';
echo ' <th width="100">'.get_lang('Modify').'</th>'; echo ' <th width="100">'.get_lang('Modify').'</th>';
if($is_survey_type_1) echo '<th width="100">'.get_lang('Condition').'</th>'; if($is_survey_type_1)
{
echo '<th width="100">'.get_lang('Condition').'</th>';
echo '<th width="40">'.get_lang('Group').'</th>';
}
echo ' </tr>'; echo ' </tr>';
// Displaying the table contents with all the questions // Displaying the table contents with all the questions
$question_counter = 1; $question_counter = 1;
$sql = "SELECT * FROM $table_survey_question_group WHERE survey_id = '".(int)$_GET['survey_id']."' ORDER BY id";
$result = api_sql_query($sql, __FILE__, __LINE__);
$groups = array();
while($row = Database::fetch_array($result))
{
$groups[$row['id']] = $row['name'];
}
$sql = "SELECT survey_question.*, count(survey_question_option.question_option_id) as number_of_options $sql = "SELECT survey_question.*, count(survey_question_option.question_option_id) as number_of_options
FROM $table_survey_question survey_question FROM $table_survey_question survey_question
LEFT JOIN $table_survey_question_option survey_question_option LEFT JOIN $table_survey_question_option survey_question_option
@ -199,8 +209,8 @@ $sql = "SELECT survey_question.*, count(survey_question_option.question_option_i
GROUP BY survey_question.question_id GROUP BY survey_question.question_id
ORDER BY survey_question.sort ASC"; ORDER BY survey_question.sort ASC";
$result = api_sql_query($sql, __FILE__, __LINE__); $result = api_sql_query($sql, __FILE__, __LINE__);
$question_counter_max = mysql_num_rows($result); $question_counter_max = Database::num_rows($result);
while ($row = mysql_fetch_assoc($result)) while ($row = Database::fetch_array($result,'ASSOC'))
{ {
echo '<tr>'; echo '<tr>';
echo ' <td>'.$question_counter.'</td>'; echo ' <td>'.$question_counter.'</td>';
@ -234,7 +244,11 @@ while ($row = mysql_fetch_assoc($result))
echo ' </td>'; echo ' </td>';
$question_counter++; $question_counter++;
if($is_survey_type_1) echo '<td>'.(($row['survey_group_pri']==0)?get_lang('Secondary'):get_lang('Primary')).'</td>'; if($is_survey_type_1)
{
echo '<td>'.(($row['survey_group_pri']==0)?get_lang('Secondary'):get_lang('Primary')).'</td>';
echo '<td>'.(($row['survey_group_pri']==0)?$groups[$row['survey_group_sec1']].'-'.$groups[$row['survey_group_sec2']]:$groups[$row['survey_group_pri']]).'</td>';
}
echo '</tr>'; echo '</tr>';
} }
echo '</table>'; echo '</table>';
@ -253,14 +267,12 @@ if($is_survey_type_1)
echo '<table border="0"><tr><td width="100">'.get_lang('Name').'</td><td>'.get_lang('Description').'</td></tr></table>'; echo '<table border="0"><tr><td width="100">'.get_lang('Name').'</td><td>'.get_lang('Description').'</td></tr></table>';
$table_surve_group = Database::get_course_table(TABLE_SURVEY_GROUP);
echo '<form action="survey.php?action=addgroup&survey_id='.(int)$_GET['survey_id'].'" method="post">'; echo '<form action="survey.php?action=addgroup&survey_id='.(int)$_GET['survey_id'].'" method="post">';
if($_GET['action']=='editgroup') if($_GET['action']=='editgroup')
{ {
$sql = 'SELECT name,description FROM '.$table_surve_group.' WHERE id = '.(int)$_GET['gid'].' AND survey_id = '.Database::escape_string($_GET['survey_id']).' limit 1'; $sql = 'SELECT name,description FROM '.$table_survey_question_group.' WHERE id = '.(int)$_GET['gid'].' AND survey_id = '.Database::escape_string($_GET['survey_id']).' limit 1';
$rs = api_sql_query($sql,__FILE__,__LINE__); $rs = api_sql_query($sql,__FILE__,__LINE__);
$editedrow = Database::fetch_array($rs,ASSOC); $editedrow = Database::fetch_array($rs,'ASSOC');
echo '<input type="text" maxlength="20" name="name" value="'.$editedrow['name'].'" size="10" disabled>'; echo '<input type="text" maxlength="20" name="name" value="'.$editedrow['name'].'" size="10" disabled>';
echo '<input type="text" maxlength="150" name="description" value="'.$editedrow['description'].'" size="40">'; echo '<input type="text" maxlength="150" name="description" value="'.$editedrow['description'].'" size="40">';
@ -282,7 +294,7 @@ if($is_survey_type_1)
echo ' <th width="100">'.get_lang('Modify').'</th>'; echo ' <th width="100">'.get_lang('Modify').'</th>';
echo ' </tr>'; echo ' </tr>';
$sql = 'SELECT id,name,description FROM '.$table_surve_group.' WHERE survey_id = '.Database::escape_string($_GET['survey_id']).' ORDER BY name'; $sql = 'SELECT id,name,description FROM '.$table_survey_question_group.' WHERE survey_id = '.Database::escape_string($_GET['survey_id']).' ORDER BY name';
$rs = api_sql_query($sql,__FILE__,__LINE__); $rs = api_sql_query($sql,__FILE__,__LINE__);
while($row = Database::fetch_array($rs,ASSOC)){ while($row = Database::fetch_array($rs,ASSOC)){

Loading…
Cancel
Save