Skip to content

Commit

Permalink
New feature: Extended condition editor
Browse files Browse the repository at this point in the history
New feature: Dynamic texts 
New feature: Dynamic answers 
New feature: Emoticon slider
New feature: Group tokens

git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey_dev@9218 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
c-schmitz committed Oct 12, 2010
1 parent d9398aa commit 22f492e
Show file tree
Hide file tree
Showing 65 changed files with 10,902 additions and 109 deletions.
115 changes: 94 additions & 21 deletions admin/activate_functions.php
Expand Up @@ -268,6 +268,7 @@ function activateSurvey($postsid,$surveyid, $scriptname='admin.php')

$createsurvey='';
$activateoutput='';
$createsurveytimings='';
$createsurveydirectory=false;
//Check for any additional fields for this survey and create necessary fields (token and datestamp)
$pquery = "SELECT private, allowregister, datestamp, ipaddr, refurl FROM {$dbprefix}surveys WHERE sid={$postsid}";
Expand All @@ -277,23 +278,34 @@ function activateSurvey($postsid,$surveyid, $scriptname='admin.php')
{
$surveyallowsregistration="TRUE";
}
if ($prow['savetimings'] == "Y")
{
$savetimings="TRUE";
}
//strip trailing comma and new line feed (if any)
$createsurvey = rtrim($createsurvey, ",\n");
//strip trailing comma and new line feed (if any)
$createsurvey = rtrim($createsurvey, ",\n");

//Get list of questions for the base language
$fieldmap=createFieldMap($surveyid);

foreach ($fieldmap as $arow) //With each question, create the appropriate field(s)
{
if ($createsurvey!='') {$createsurvey .= ",\n";}
$createsurvey .= " `{$arow['fieldname']}`";
// don't include time fields
if ($arow['type'] != "answer_time" && $arow['type'] != "page_time" && $arow['type'] != "interview_time")
{
if ($createsurvey!='') {$createsurvey .= ",\n";}
$createsurvey .= " `{$arow['fieldname']}`";
}

switch($arow['type'])
{
case 'startlanguage':
$createsurvey .= " C(20) NOTNULL";
break;
case 'id':
$createsurvey .= " I NOTNULL AUTO PRIMARY";
$createsurveytimings .= " `{$arow['fieldname']}` I NOTNULL AUTO PRIMARY,\n";
break;
case "startdate":
case "datestamp":
Expand All @@ -309,7 +321,7 @@ function activateSurvey($postsid,$surveyid, $scriptname='admin.php')
$createsurvey .= " F";
break;
case "S": //SHORT TEXT
if ($databasetype=='mysql' || $databasetype=='mysqli') {$createsurvey .= " X";}
if ($databasetype=='mysql' || $databasetype=='mysqli') {$createsurvey .= " X";}
else {$createsurvey .= " C(255)";}
break;
case "L": //LIST (RADIO)
Expand Down Expand Up @@ -370,30 +382,47 @@ function activateSurvey($postsid,$surveyid, $scriptname='admin.php')
$surveynotprivate="TRUE";
}
break;
case "grouptoken":
$createsurvey .= " C(36)";
break;
case "page_time":
case "answer_time":
case "interview_time":
$createsurveytimings .= " `{$arow['fieldname']}` I(11) DEFAULT '0',\n";
break;
default:
$createsurvey .= " C(5)";
}
}

// If last question is of type MCABCEFHP^QKJR let's get rid of the ending coma in createsurvey
$createsurvey = rtrim($createsurvey, ",\n")."\n"; // Does nothing if not ending with a comma
$createsurveytimings = rtrim($createsurveytimings, ",\n")."\n"; // Does nothing if not ending with a comma

$tabname = "{$dbprefix}survey_{$postsid}"; # not using db_table_name as it quotes the table name (as does CreateTableSQL)

$taboptarray = array('mysql' => 'ENGINE='.$databasetabletype.' CHARACTER SET utf8 COLLATE utf8_unicode_ci',
'mysqli'=> 'ENGINE='.$databasetabletype.' CHARACTER SET utf8 COLLATE utf8_unicode_ci');
$dict = NewDataDictionary($connect);
$sqlarray = $dict->CreateTableSQL($tabname, $createsurvey, $taboptarray);

if (isset($savetimings) && $savetimings=="TRUE")
{
$tabnametimings = $tabname .'_timings';
$dicttimings = NewDataDictionary($connect);
$sqlarraytimings = $dicttimings->CreateTableSQL($tabnametimings, $createsurveytimings, $taboptarray);
}

$execresult=$dict->ExecuteSQLArray($sqlarray,1);
if ($execresult==0 || $execresult==1)
{
$activateoutput .= "<br />\n<div class='messagebox'>\n" .
"<div class='header'>".$clang->gT("Activate Survey")." ($surveyid)</div>\n" .
"<div class='warningheader'>".$clang->gT("Survey could not be actived.")."</div>\n" .
"<p>" .
"<div class='header'>".$clang->gT("Activate Survey")." ($surveyid)</div>\n" .
"<div class='warningheader'>".$clang->gT("Survey could not be actived.")."</div>\n" .
"<p>" .
$clang->gT("Database error:")."\n <font color='red'>" . $connect->ErrorMsg() . "</font>\n" .
"<pre>$createsurvey</pre>\n
"<pre>$createsurvey</pre>\n
<a href='$scriptname?sid={$postsid}'>".$clang->gT("Main Admin Screen")."</a>\n</div>" ;
$lsrcOutput = false;
}
if ($execresult != 0 && $execresult !=1)
{
Expand All @@ -405,17 +434,26 @@ function activateSurvey($postsid,$surveyid, $scriptname='admin.php')
{
if ($row['autonumber_start'] > 0)
{
$autonumberquery = "ALTER TABLE {$dbprefix}survey_{$postsid} AUTO_INCREMENT = ".$row['autonumber_start'];
if ($result = $connect->Execute($autonumberquery))
{
//We're happy it worked!
if ($databasetype=='odbc_mssql' || $databasetype=='odbtp' || $databasetype=='mssql_n' || $databasetype=='mssqlnative') {
mssql_drop_primary_index('survey_'.$postsid);
mssql_drop_constraint('id','survey_'.$postsid);
$autonumberquery = "alter table {$dbprefix}survey_{$postsid} drop column id ";
$connect->Execute($autonumberquery);
$autonumberquery = "alter table {$dbprefix}survey_{$postsid} add [id] int identity({$row['autonumber_start']},1)";
$connect->Execute($autonumberquery);
}
else
{
//Continue regardless - it's not the end of the world
$autonumberquery = "ALTER TABLE {$dbprefix}survey_{$postsid} AUTO_INCREMENT = ".$row['autonumber_start'];
$result = @$connect->Execute($autonumberquery);

}
}
}
if (isset($savetimings) && $savetimings=="TRUE")
{
$dicttimings->ExecuteSQLArray($sqlarraytimings,1); // create a timings table for this survey
}
}

$activateoutput .= "<br />\n<div class='messagebox'>\n";
Expand All @@ -432,12 +470,12 @@ function activateSurvey($postsid,$surveyid, $scriptname='admin.php')
$acresult = $connect->Execute($acquery);

// Private means data privacy, not closed access survey
// if (isset($surveynotprivate) && $surveynotprivate) //This survey is tracked, and therefore a tokens table MUST exist
// {
// $activateoutput .= $clang->gT("This is not an anonymous survey. A token table must also be created.")."<br /><br />\n";
// $activateoutput .= "<input type='submit' value='".$clang->gT("Initialise Tokens")."' onclick=\"window.open('$scriptname?action=tokens&amp;sid={$_GET['sid']}&amp;createtable=Y', '_top')\" />\n";
// }
// elseif (isset($surveyallowsregistration) && $surveyallowsregistration == "TRUE")
// if (isset($surveynotprivate) && $surveynotprivate) //This survey is tracked, and therefore a tokens table MUST exist
// {
// $activateoutput .= $clang->gT("This is not an anonymous survey. A token table must also be created.")."<br /><br />\n";
// $activateoutput .= "<input type='submit' value='".$clang->gT("Initialise Tokens")."' onclick=\"window.open('$scriptname?action=tokens&amp;sid={$_GET['sid']}&amp;createtable=Y', '_top')\" />\n";
// }
// elseif (isset($surveyallowsregistration) && $surveyallowsregistration == "TRUE")
if (isset($surveyallowsregistration) && $surveyallowsregistration == "TRUE")
{
$activateoutput .= $clang->gT("This survey allows public registration. A token table must also be created.")."<br /><br />\n";
Expand All @@ -453,6 +491,7 @@ function activateSurvey($postsid,$surveyid, $scriptname='admin.php')
$activateoutput .= "</div><br />&nbsp;\n";
$lsrcOutput = true;
}

if($scriptname=='lsrc')
{
if($lsrcOutput==true)
Expand All @@ -465,3 +504,37 @@ function activateSurvey($postsid,$surveyid, $scriptname='admin.php')
return $activateoutput;
}
}

function mssql_drop_constraint($fieldname, $tablename)
{
global $dbprefix, $connect, $modifyoutput;
// find out the name of the default constraint
// Did I already mention that this is the most suckiest thing I have ever seen in MSSQL database?
$dfquery ="SELECT c_obj.name AS constraint_name
FROM sys.sysobjects AS c_obj INNER JOIN
sys.sysobjects AS t_obj ON c_obj.parent_obj = t_obj.id INNER JOIN
sys.sysconstraints AS con ON c_obj.id = con.constid INNER JOIN
sys.syscolumns AS col ON t_obj.id = col.id AND con.colid = col.colid
WHERE (c_obj.xtype = 'D') AND (col.name = '$fieldname') AND (t_obj.name='{$dbprefix}{$tablename}')";
$defaultname=$connect->GetRow($dfquery);
if ($defaultname!=false)
{
modify_database("","ALTER TABLE [prefix_$tablename] DROP CONSTRAINT {$defaultname[0]}"); echo $modifyoutput; flush();
}
}


function mssql_drop_primary_index($tablename)
{
global $dbprefix, $connect, $modifyoutput;
// find out the constraint name of the old primary key
$pkquery = "SELECT CONSTRAINT_NAME "
."FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS "
."WHERE (TABLE_NAME = '{$dbprefix}{$tablename}') AND (CONSTRAINT_TYPE = 'PRIMARY KEY')";

$primarykey=$connect->GetOne($pkquery);
if ($primarykey!=false)
{
modify_database("","ALTER TABLE [prefix_{$tablename}] DROP CONSTRAINT {$primarykey}"); echo $modifyoutput; flush();
}
}
10 changes: 8 additions & 2 deletions admin/admin.php
Expand Up @@ -177,6 +177,11 @@
if(bHasRight($surveyid,'define_questions')) {include('conditionshandling.php');}
else { include('access_denied.php');}
}
elseif ($action == 'extendedconditions')
{
if(bHasRight($surveyid,'define_questions')) {include('extendedconditionshandling.php');}
else { include('access_denied.php');}
}
elseif ($action == 'importsurveyresources')
{
if (bHasRight($surveyid,'define_questions')) {$_SESSION['FileManagerContext']="edit:survey:$surveyid";include('import_resources_zip.php');}
Expand Down Expand Up @@ -409,7 +414,7 @@
}
}
if (!isset($assessmentsoutput) && !isset($statisticsoutput) && !isset($browseoutput) &&
!isset($savedsurveyoutput) && !isset($listcolumnoutput) && !isset($conditionsoutput) &&
!isset($savedsurveyoutput) && !isset($listcolumnoutput) && !isset($conditionsoutput) && !isset($extendedconditionsoutput) &&
!isset($importoldresponsesoutput) && !isset($exportroutput) && !isset($vvoutput) &&
!isset($tokenoutput) && !isset($exportoutput) && !isset($templatesoutput) &&
!isset($iteratesurveyoutput) && (substr($action,0,4)!= 'ajax') && ($action!='update') &&
Expand Down Expand Up @@ -516,7 +521,7 @@
if (!isset($labelsoutput) && !isset($templatesoutput) && !isset($printablesurveyoutput) &&
!isset($assessmentsoutput) && !isset($tokenoutput) && !isset($browseoutput) && !isset($exportspssoutput) && !isset($exportroutput) &&
!isset($dataentryoutput) && !isset($statisticsoutput)&& !isset($savedsurveyoutput) &&
!isset($exportoutput) && !isset($importoldresponsesoutput) && !isset($conditionsoutput) &&
!isset($exportoutput) && !isset($importoldresponsesoutput) && !isset($conditionsoutput) && !isset($extendedconditionsoutput) &&
!isset($vvoutput) && !isset($listcolumnoutput) && !isset($importlabelresources) && !isset($iteratesurveyoutput) &&
(substr($action,0,4)!= 'ajax') && $action!='update' && $action!='showphpinfo')
{
Expand Down Expand Up @@ -575,6 +580,7 @@
if (isset($savedsurveyoutput)) {$adminoutput.= $savedsurveyoutput;}
if (isset($importoldresponsesoutput)) {$adminoutput.= $importoldresponsesoutput;}
if (isset($conditionsoutput)) {$adminoutput.= $conditionsoutput;}
if (isset($extendedconditionsoutput)) {$adminoutput.= $extendedconditionsoutput;}
if (isset($deletesurveyoutput)) {$adminoutput.= $deletesurveyoutput;}
if (isset($resetsurveylogicoutput)) {$adminoutput.= $resetsurveylogicoutput;}
if (isset($vvoutput)) {$adminoutput.= $vvoutput;}
Expand Down

0 comments on commit 22f492e

Please sign in to comment.