Skip to content

Commit

Permalink
Fixed bug #755: Question copy not working
Browse files Browse the repository at this point in the history
git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/phpsurveyor@2654 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
c-schmitz committed Mar 31, 2007
1 parent fcf9564 commit bfc41dc
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 40 deletions.
34 changes: 25 additions & 9 deletions admin/database.php
Expand Up @@ -60,15 +60,14 @@ function db_rename_table($oldtable, $newtable)
* Gets the maximum question_order field value for a group
* @gid: The id of the group
*/
function get_max_order($gid)
function get_max_question_order($gid)
{
global $connect ;
global $dbprefix ;
$query="SELECT MAX(question_order) as max FROM {$dbprefix}questions where gid=".$gid ;
//$query = "INSERT INTO {$dbprefix}questions (sid, gid, type, title, question, help, other, mandatory, lid) VALUES ('{$_POST['sid']}', '{$_POST['gid']}', '{$_POST['type']}', '{$_POST['title']}', '{$_POST['question']}', '{$_POST['help']}', '{$_POST['other']}', '{$_POST['mandatory']}', '{$_POST['lid']}')";
$result = $connect->Execute($query) or die($query);
$query="SELECT MAX(question_order) as maxorder FROM {$dbprefix}questions where gid=".$gid ;
$result = db_execute_assoc($query);
$gv = $result->FetchRow();
return $gv['max'];
return $gv['maxorder'];
}

$databaseoutput ='';
Expand Down Expand Up @@ -411,25 +410,42 @@ function get_max_order($gid)

elseif ($action == "copynewquestion" && $actsurrows['define_questions'])
{

if (!$_POST['title'])
{
$databaseoutput .= "<script type=\"text/javascript\">\n<!--\n alert(\"".$clang->gT("Answer could not be added. You must insert a code in the mandatory field","js")."\")\n //-->\n</script>\n";
$databaseoutput .= "<script type=\"text/javascript\">\n<!--\n alert(\"".$clang->gT("Question could not be added. You must insert a code in the mandatory field","js")."\")\n //-->\n</script>\n";
}
else
{
$_POST = array_map('db_quote', $_POST);
$questlangs = GetAdditionalLanguagesFromSurveyID($_POST['sid']);
$baselang = GetBaseLanguageFromSurveyID($_POST['sid']);

if (!isset($_POST['lid']) || $_POST['lid']=='') {$_POST['lid']=0;}
//Get maximum order from the question group
$max=get_max_order($_POST['gid'])+1 ;

$query = "INSERT INTO {$dbprefix}questions (sid, gid, type, title, question, help, other, mandatory, lid, question_order) VALUES ('{$_POST['sid']}', '{$_POST['gid']}', '{$_POST['type']}', '{$_POST['title']}', '{$_POST['question']}', '{$_POST['help']}', '{$_POST['other']}', '{$_POST['mandatory']}', '{$_POST['lid']}',$max)";
$max=get_max_question_order($_POST['gid'])+1 ;
// Insert the base language of the question
$query = "INSERT INTO {$dbprefix}questions (sid, gid, type, title, question, help, other, mandatory, lid, question_order, language)
VALUES ({$_POST['sid']}, {$_POST['gid']}, '{$_POST['type']}', '{$_POST['title']}', '".$_POST['question_'.$baselang]."', '".$_POST['help_'.$baselang]."', '{$_POST['other']}', '{$_POST['mandatory']}', '{$_POST['lid']}',$max,".db_quoteall($baselang).")";
$result = $connect->Execute($query) or die($connect->ErrorMsg());
$newqid = $connect->Insert_ID();
if (!$result)
{
$databaseoutput .= "<script type=\"text/javascript\">\n<!--\n alert(\"".$clang->gT("Question could not be created.","js")."\\n".htmlspecialchars($connect->ErrorMsg())."\")\n //-->\n</script>\n";

}

foreach ($questlangs as $qlanguage)
{
$query = "INSERT INTO {$dbprefix}questions (qid, sid, gid, type, title, question, help, other, mandatory, lid, question_order, language)
VALUES ($newqid,{$_POST['sid']}, {$_POST['gid']}, '{$_POST['type']}', '{$_POST['title']}', '".$_POST['question_'.$qlanguage]."', '".$_POST['help_'.$qlanguage]."', '{$_POST['other']}', '{$_POST['mandatory']}', '{$_POST['lid']}',$max,".db_quoteall($qlanguage).")";
$result = $connect->Execute($query) or die($connect->ErrorMsg());
}
if (!$result)
{
$databaseoutput .= "<script type=\"text/javascript\">\n<!--\n alert(\"".$clang->gT("Question could not be created.","js")."\\n".htmlspecialchars($connect->ErrorMsg())."\")\n //-->\n</script>\n";

}
if (returnglobal('copyanswers') == "Y")
{
$q1 = "SELECT * FROM {$dbprefix}answers WHERE qid="
Expand Down
4 changes: 2 additions & 2 deletions admin/dataentry.php
Expand Up @@ -1888,9 +1888,9 @@ function saveshow(value)
{
$width=sprintf("%0d", 100/$dcols);
$maxrows=ceil(100*($meacount/$dcols)/100); //Always rounds up to nearest whole number
$divider=" </td>\n <td valign='top' width='$width%' nowrap>";
$divider=" </td>\n <td valign='top' width='$width%' nowrap='nowrap'>";
$upto=0;
$dataentryoutput .= "<table class='question'><tr>\n <td valign='top' width='$width%' nowrap>";
$dataentryoutput .= "<table class='question'><tr>\n <td valign='top' width='$width%' nowrap='nowrap'>";
while ($mearow = $mearesult->FetchRow())
{
if ($upto == $maxrows)
Expand Down
2 changes: 1 addition & 1 deletion admin/html.php
Expand Up @@ -46,7 +46,7 @@
$listsurveys= "<br /><table align='center' bgcolor='#DDDDDD' style='border: 1px solid #555555' "
. "cellpadding='1' cellspacing='0' width='800'>
<tr bgcolor='#BBBBBB'>
<td height=\"22\" width='22'>&nbsp</strong></td>
<td height=\"22\" width='22'>&nbsp</td>
<td height=\"22\"><strong>".$clang->gT("Survey")."</strong></td>
<td><strong>".$clang->gT("Date Created")."</strong></td>
<td><strong>".$clang->gT("Visibility")."</strong></td>
Expand Down
12 changes: 6 additions & 6 deletions admin/printablesurvey.php
Expand Up @@ -301,9 +301,9 @@
{
$width=sprintf("%0d", 100/$dcols);
$maxrows=ceil(100*($meacount/$dcols)/100); //Always rounds up to nearest whole number
$divider="</td>\n <td valign='top' width='$width%' nowrap>";
$divider="</td>\n <td valign='top' width='$width%' nowrap='nowrap'>";
$upto=0;
$printablesurveyoutput .="<table class='question'><tr>\n <td valign='top' width='$width%' nowrap>";
$printablesurveyoutput .="<table class='question'><tr>\n <td valign='top' width='$width%' nowrap='nowrap'>";
while ($dearow = $dearesult->FetchRow())
{
if ($upto == $maxrows)
Expand Down Expand Up @@ -353,9 +353,9 @@
{
$width=sprintf("%0d", 100/$dcols);
$maxrows=ceil(100*($meacount/$dcols)/100); //Always rounds up to nearest whole number
$divider=" </td>\n <td valign='top' width='$width%' nowrap>";
$divider=" </td>\n <td valign='top' width='$width%' nowrap='nowrap'>";
$upto=0;
$printablesurveyoutput .="<table class='question'><tr>\n <td valign='top' width='$width%' nowrap>";
$printablesurveyoutput .="<table class='question'><tr>\n <td valign='top' width='$width%' nowrap='nowrap'>";
while ($dearow = $dearesult->FetchRow())
{
if ($upto == $maxrows)
Expand Down Expand Up @@ -433,9 +433,9 @@
{
$width=sprintf("%0d", 100/$dcols);
$maxrows=ceil(100*($meacount/$dcols)/100); //Always rounds up to nearest whole number
$divider=" </td>\n <td valign='top' width='$width%' nowrap>";
$divider=" </td>\n <td valign='top' width='$width%' nowrap='nowrap'>";
$upto=0;
$printablesurveyoutput .="<table class='question'><tr>\n <td valign='top' width='$width%' nowrap>";
$printablesurveyoutput .="<table class='question'><tr>\n <td valign='top' width='$width%' nowrap='nowrap'>";
while ($mearow = $mearesult->FetchRow())
{
if ($upto == $maxrows)
Expand Down
4 changes: 2 additions & 2 deletions admin/questionhandling.php
Expand Up @@ -163,7 +163,7 @@
. '<div class="tab-pane" id="tab-pane-1">';
foreach ($questlangs as $language)
{
$egquery = "SELECT * FROM ".db_table_name('questions')." WHERE sid=$surveyid AND gid=$gid AND qid=$qid and language=".db_quote($language);
$egquery = "SELECT * FROM ".db_table_name('questions')." WHERE sid=$surveyid AND gid=$gid AND qid=$qid and language=".db_quoteall($language);
$egresult = db_execute_assoc($egquery);
$eqrow = $egresult->FetchRow();
$eqrow = array_map('htmlspecialchars', $eqrow);
Expand Down Expand Up @@ -530,7 +530,7 @@
. "</td></tr></table>\n"
. "</form>\n</table>";
}
$editquestion .= "</table>";
$editquestion .= "</td></tr></table>";
$editquestion .= questionjavascript($eqrow['type'], $qattributes);
}

Expand Down
14 changes: 7 additions & 7 deletions admin/templates.php
Expand Up @@ -564,11 +564,11 @@
."<input type='hidden' name='screenname' value='".html_escape($screenname)."' />\n"
."<input type='hidden' name='templatename' value='$templatename' />\n"
."<input type='hidden' name='action' value='templatefiledelete' />\n"
."</td>\n"
."</td></tr>\n"
."</table></form></td></tr><tr><td></td><td align='right' valign='top'>"
."<form enctype='multipart/form-data' name='importsurvey' action='admin.php' method='post'>\n"
."<table><tr> <td align='right' valign='top' style='border: solid 1 #000080'>\n"
."<strong>".$clang->gT("Upload a File").":</strong><br /><input name=\"the_file\" type=\"file\" size=\"7\" /><br />"
."<strong>".$clang->gT("Upload a File").":</strong></td></tr><tr><td><input name=\"the_file\" type=\"file\" size=\"7\" /><br />"
."<input type='submit' value='".$clang->gT("Upload")."'";
if ($templatename == "default") {
$templatesoutput.= " disabled";
Expand All @@ -578,24 +578,24 @@
."<input type='hidden' name='screenname' value='".html_escape($screenname)."' />\n"
."<input type='hidden' name='templatename' value='$templatename' />\n"
."<input type='hidden' name='action' value='templateupload' />\n"
."</td></table></form>\n"
."</td></tr></table></form>\n"
."\t\t\t\t\t\t</td>\n"
."\t\t\t\t\t</tr>\n"
."\t\t\t\t</table>\n"
."\t\t\t</td>\n"
."\t</tr>"
."</table>"
."</table>";
."</td></tr></table>";

//SAMPLE ROW
$templatesoutput.= "\t\t\t<table class='menubar'>\n"
. "\t\t\t<tr bgcolor='#555555'>\n"
. "\t\t\t<tr>\n"
. "\t\t\t\t<td colspan='2' height='8'>\n"
. "\t\t\t\t\t$setfont<font size='1' color='white'><strong>".$clang->gT("Preview:")."</strong>\n"
. "\t\t\t\t</font></font></td>\n"
. "\t\t\t</tr>\n"
."\t<tr>\n"
."\t\t<td width='90%' align='center' bgcolor='#555555'>\n";
."\t\t<td width='90%' align='center' >\n";


unlink_wc($tempdir, "template_temp_*.html"); //Delete any older template files
Expand Down Expand Up @@ -764,7 +764,7 @@ function makeoptions($array, $value, $text, $selectedvalue) {
foreach ($array as $ar) {
$return .= "<option value='".$ar[$value]."'";
if ($ar[$value] == $selectedvalue) {
$return .= " selected";
$return .= " selected='selected'";
}
$return .= ">".$ar[$text]."</option>\n";
}
Expand Down
11 changes: 7 additions & 4 deletions admin/userrighthandling.php
Expand Up @@ -886,8 +886,11 @@
{
$grplangs = GetAdditionalLanguagesFromSurveyID($surveyid);
$baselang = GetBaseLanguageFromSurveyID($surveyid);
$grplangs[] = $baselang;

if (isset($grplangs)) {array_unshift($grplangs, $baselang);}
else {$grplangs[] = $baselang;}
$grplangs = array_flip($grplangs);


$egquery = "SELECT * FROM ".db_table_name('groups')." WHERE sid=$surveyid AND gid=$gid";
$egresult = db_execute_assoc($egquery);
Expand Down Expand Up @@ -918,19 +921,19 @@
$egresult = db_execute_assoc($egquery);
$editgroup ="<table width='100%' border='0'>\n\t<tr><td bgcolor='black' align='center'>"
. "\t\t<font class='settingcaption'><font color='white'>".$clang->gT("Edit Group")."</font></font></td></tr></table>\n"
. "<form name='editgroup' action='$scriptname' method='post'>\n"
. '<div class="tab-pane" id="tab-pane-1">';
while ($esrow = $egresult->FetchRow())
{
$editgroup .= '<div class="tab-page"> <h2 class="tab">'.getLanguageNameFromCode($esrow['language'],false);
if ($esrow['language']==GetBaseLanguageFromSurveyID($surveyid)) {$editgroup .= '('.$clang->gT("Base Language").')';}
$esrow = array_map('htmlspecialchars', $esrow);
$editgroup .= '</h2>';
$editgroup .= "<form name='editgroup' action='$scriptname' method='post'>\n";
$editgroup .= "\t<div class='settingrow'><span class='settingcaption'>".$clang->gT("Title").":</span>\n"
. "\t\t<span class='settingentry'><input type='text' size='50' name='group_name_{$esrow['language']}' value=\"{$esrow['group_name']}\" />\n"
. "\t\t<span class='settingentry'><input type='text' maxlength='100' size='80' name='group_name_{$esrow['language']}' value=\"{$esrow['group_name']}\" />\n"
. "\t</span></div>\n"
. "\t<div class='settingrow'><span class='settingcaption'>".$clang->gT("Description:")."</span>\n"
. "\t\t<span class='settingentry'><textarea cols='50' rows='4' name='description_{$esrow['language']}'>{$esrow['description']}</textarea>\n"
. "\t\t<span class='settingentry'><textarea cols='70' rows='8' name='description_{$esrow['language']}'>{$esrow['description']}</textarea>\n"
. "\t</span></div><div class='settingrow'></div></div>"; // THis empty div class is needed for forcing the tabpage border under the button
}
$editgroup .= '</div>';
Expand Down
6 changes: 3 additions & 3 deletions common.php
Expand Up @@ -3154,7 +3154,7 @@ function FixLanguageConsistency($sid, $availlangs)
$gresult = db_execute_assoc($query) or die($connect->ErrorMsg());
if ($gresult->RecordCount() < 1)
{
$query = "INSERT INTO ".db_table_name('groups')." (gid,sid,group_name,group_order,description,language) VALUES('{$group['gid']}','{$group['sid']}',".db_quote($group['group_name']).",'{$group['group_order']}',".db_quote($group['description']).",'{$lang}')";
$query = "INSERT INTO ".db_table_name('groups')." (gid,sid,group_name,group_order,description,language) VALUES('{$group['gid']}','{$group['sid']}',".db_quoteall($group['group_name']).",'{$group['group_order']}',".db_quoteall($group['description']).",'{$lang}')";
$connect->Execute($query) or die($connect->ErrorMsg());
}
}
Expand All @@ -3176,7 +3176,7 @@ function FixLanguageConsistency($sid, $availlangs)
$gresult = db_execute_assoc($query) or die($connect->ErrorMsg());
if ($gresult->RecordCount() < 1)
{
$query = "INSERT INTO ".db_table_name('questions')." (qid,sid,gid,type,title,question,preg,help,other,mandatory,lid,question_order,language) VALUES('{$question['qid']}','{$question['sid']}','{$question['gid']}','{$question['type']}',".db_quote($question['title']).",".db_quote($question['question']).",".db_quote($question['preg']).",".db_quote($question['help']).",'{$question['other']}','{$question['mandatory']}','{$question['lid']}','{$question['question_order']}','{$lang}')";
$query = "INSERT INTO ".db_table_name('questions')." (qid,sid,gid,type,title,question,preg,help,other,mandatory,lid,question_order,language) VALUES('{$question['qid']}','{$question['sid']}','{$question['gid']}','{$question['type']}',".db_quoteall($question['title']).",".db_quoteall($question['question']).",".db_quoteall($question['preg']).",".db_quoteall($question['help']).",'{$question['other']}','{$question['mandatory']}','{$question['lid']}','{$question['question_order']}','{$lang}')";
$connect->Execute($query) or die(print "$query\n: ".$connect->ErrorMsg());
}
}
Expand All @@ -3201,7 +3201,7 @@ function FixLanguageConsistency($sid, $availlangs)
$gresult = db_execute_assoc($query) or die($connect->ErrorMsg());
if ($gresult->RecordCount() < 1)
{
$query = "INSERT INTO ".db_table_name('answers')." (qid,code,answer,default_value,sortorder,language) VALUES('{$answer['qid']}',".db_quote($answer['code']).",".db_quote($answer['answer']).",".db_quote($answer['default_value']).",'{$answer['sortorder']}','{$lang}')";
$query = "INSERT INTO ".db_table_name('answers')." (qid,code,answer,default_value,sortorder,language) VALUES('{$answer['qid']}',".db_quoteall($answer['code']).",".db_quoteall($answer['answer']).",".db_quoteall($answer['default_value']).",'{$answer['sortorder']}','{$lang}')";
$connect->Execute($query) or die($connect->ErrorMsg());
}
}
Expand Down
12 changes: 6 additions & 6 deletions qanda.php
Expand Up @@ -786,8 +786,8 @@ function do_list_radio($ia)
$denominator=$dcols; //Change this to set the number of columns
$width=sprintf("%0d", 100/$denominator);
$maxrows=ceil(100*($anscount/$dcols)/100); //Always rounds up to nearest whole number
$answer .= "<table class='question'><tr>\n <td valign='top' width='$width%' nowrap>";
$divider=" </td>\n <td valign='top' width='$width%' nowrap>";
$answer .= "<table class='question'><tr>\n <td valign='top' width='$width%' nowrap='nowrap'>";
$divider=" </td>\n <td valign='top' width='$width%' nowrap='nowrap'>";
}
else
{
Expand Down Expand Up @@ -899,8 +899,8 @@ function do_list_flexible_radio($ia)
$denominator=$dcols; //Change this to set the number of columns
$width=sprintf("%0d", 100/$denominator);
$maxrows=ceil(100*($anscount/$dcols)/100); //Always rounds up to nearest whole number
$answer .= "<table class='question'><tr>\n <td valign='top' width='$width%' nowrap>";
$divider=" </td>\n <td valign='top' width='$width%' nowrap>";
$answer .= "<table class='question'><tr>\n <td valign='top' width='$width%' nowrap='nowrap'>";
$divider=" </td>\n <td valign='top' width='$width%' nowrap='nowrap'>";
}
else
{
Expand Down Expand Up @@ -1361,8 +1361,8 @@ function do_multiplechoice($ia)
{
$width=sprintf("%0d", 100/$dcols);
$maxrows=ceil(100*($anscount/$dcols)/100); //Always rounds up to nearest whole number
$answer .= "<table class='question'><tr>\n <td valign='top' width='$width%' nowrap>";
$divider=" </td>\n <td valign='top' width='$width%' nowrap>";
$answer .= "<table class='question'><tr>\n <td valign='top' width='$width%' nowrap='nowrap'>";
$divider=" </td>\n <td valign='top' width='$width%' nowrap='nowrap'>";
$closetable=true;
}
$fn = 1;
Expand Down

0 comments on commit bfc41dc

Please sign in to comment.