diff --git a/admin/quotarow.php b/admin/quotarow.php index 7da99056..6d04510d 100755 --- a/admin/quotarow.php +++ b/admin/quotarow.php @@ -274,14 +274,19 @@ if ($questionnaire_id != false) print "
" . T_("No labels defined for this question") ."
"; diff --git a/appointmentlist.php b/appointmentlist.php index 9249886d..9a353039 100644 --- a/appointmentlist.php +++ b/appointmentlist.php @@ -53,7 +53,7 @@ $js = false; if (AUTO_LOGOUT_MINUTES !== false) $js = array("include/jquery-ui/js/jquery-1.4.2.min.js","js/childnap.js"); -xhtml_head(T_("Appointment List"),true,array("css/table.css"),$js,false,15); +xhtml_head(T_("Appointment List"),true,array("css/table.css"),$js,false,60); //List the case appointment // display in respondent time so that the operator will be able to diff --git a/callhistory.php b/callhistory.php index 0c4b08e2..b39f30cf 100644 --- a/callhistory.php +++ b/callhistory.php @@ -53,7 +53,7 @@ $js = false; if (AUTO_LOGOUT_MINUTES !== false) $js = array("include/jquery-ui/js/jquery-1.4.2.min.js","js/childnap.js"); -xhtml_head(T_("Case History List"),true,array("css/table.css"),$js,false,15); +xhtml_head(T_("Case History List"),true,array("css/table.css"),$js,false,60); //List the case call history // display in respondent time so that the operator will be able to diff --git a/calllist.php b/calllist.php index 81c7e119..6b9158e9 100644 --- a/calllist.php +++ b/calllist.php @@ -53,7 +53,7 @@ $js = false; if (AUTO_LOGOUT_MINUTES !== false) $js = array("include/jquery-ui/js/jquery-1.4.2.min.js","js/childnap.js"); -xhtml_head(T_("Call List"),true,array("css/table.css"),$js,false,15); +xhtml_head(T_("Call List"),true,array("css/table.css"),$js,false,60); //List the case call history // display in respondent time so that the operator will be able to diff --git a/config.default.php b/config.default.php index 7ac71363..14f6d13c 100644 --- a/config.default.php +++ b/config.default.php @@ -161,7 +161,7 @@ if (!defined('PHP_EXEC')) define('PHP_EXEC', "php"); /** * Path to ADODB */ -if (!defined('ADODB_PATH')) define('ADODB_PATH',dirname(__FILE__).'/../adodb/'); +if (!defined('ADODB_PATH')) define('ADODB_PATH',dirname(__FILE__).'/include/limesurvey/classes/adodb/'); /** * Path to the HTPASSWD file read/writable by the web server user for htpasswd integration diff --git a/config.inc.local.php.example b/config.inc.local.php.example index 1bdb5b7b..ab524fcd 100644 --- a/config.inc.local.php.example +++ b/config.inc.local.php.example @@ -63,11 +63,6 @@ define('AUTO_POPUP',false); */ define('QUEXS_PATH', '/quexs/'); -/** - * Path to ADODB - */ -define('ADODB_PATH',dirname(__FILE__).'/../adodb/'); - /** * Database configuration for queXS */ diff --git a/database/quexs.sql b/database/quexs.sql index bf42a939..6ec54504 100644 --- a/database/quexs.sql +++ b/database/quexs.sql @@ -3,9 +3,9 @@ -- http://www.phpmyadmin.net -- -- Host: localhost --- Generation Time: Sep 07, 2011 at 02:42 PM +-- Generation Time: Nov 16, 2012 at 12:35 PM -- Server version: 5.0.51 --- PHP Version: 5.2.6-1+lenny13 +-- PHP Version: 5.2.6-1+lenny16 SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; @@ -18,7 +18,6 @@ SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; -- -- Database: `quexs` -- - -- -------------------------------------------------------- -- @@ -472,6 +471,31 @@ CREATE TABLE `lime_defaultvalues` ( -- +-- -------------------------------------------------------- + +-- +-- Table structure for table `lime_expression_errors` +-- + +CREATE TABLE `lime_expression_errors` ( + `id` int(9) NOT NULL auto_increment, + `errortime` varchar(50) collate utf8_unicode_ci default NULL, + `sid` int(11) default NULL, + `gid` int(11) default NULL, + `qid` int(11) default NULL, + `gseq` int(11) default NULL, + `qseq` int(11) default NULL, + `type` varchar(50) collate utf8_unicode_ci default NULL, + `eqn` text collate utf8_unicode_ci, + `prettyprint` text collate utf8_unicode_ci, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + +-- +-- Dumping data for table `lime_expression_errors` +-- + + -- -------------------------------------------------------- -- @@ -504,6 +528,8 @@ CREATE TABLE `lime_groups` ( `group_order` int(11) NOT NULL default '0', `description` text collate utf8_unicode_ci, `language` varchar(20) collate utf8_unicode_ci NOT NULL default 'en', + `randomization_group` varchar(20) collate utf8_unicode_ci NOT NULL default '', + `grelevance` text collate utf8_unicode_ci, PRIMARY KEY (`gid`,`language`), KEY `groups_idx2` (`sid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; @@ -553,6 +579,119 @@ CREATE TABLE `lime_labelsets` ( -- +-- -------------------------------------------------------- + +-- +-- Table structure for table `lime_participants` +-- + +CREATE TABLE `lime_participants` ( + `participant_id` varchar(50) collate utf8_unicode_ci NOT NULL, + `firstname` varchar(40) collate utf8_unicode_ci default NULL, + `lastname` varchar(40) collate utf8_unicode_ci default NULL, + `email` varchar(80) collate utf8_unicode_ci default NULL, + `language` varchar(40) collate utf8_unicode_ci default NULL, + `blacklisted` varchar(1) collate utf8_unicode_ci NOT NULL, + `owner_uid` int(20) NOT NULL, + PRIMARY KEY (`participant_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + +-- +-- Dumping data for table `lime_participants` +-- + + +-- -------------------------------------------------------- + +-- +-- Table structure for table `lime_participant_attribute` +-- + +CREATE TABLE `lime_participant_attribute` ( + `participant_id` varchar(50) collate utf8_unicode_ci NOT NULL, + `attribute_id` int(11) NOT NULL, + `value` varchar(50) collate utf8_unicode_ci NOT NULL, + PRIMARY KEY (`participant_id`,`attribute_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + +-- +-- Dumping data for table `lime_participant_attribute` +-- + + +-- -------------------------------------------------------- + +-- +-- Table structure for table `lime_participant_attribute_names` +-- + +CREATE TABLE `lime_participant_attribute_names` ( + `attribute_id` int(11) NOT NULL auto_increment, + `attribute_type` varchar(4) collate utf8_unicode_ci NOT NULL, + `visible` char(5) collate utf8_unicode_ci NOT NULL, + PRIMARY KEY (`attribute_id`,`attribute_type`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + +-- +-- Dumping data for table `lime_participant_attribute_names` +-- + + +-- -------------------------------------------------------- + +-- +-- Table structure for table `lime_participant_attribute_names_lang` +-- + +CREATE TABLE `lime_participant_attribute_names_lang` ( + `attribute_id` int(11) NOT NULL, + `attribute_name` varchar(30) collate utf8_unicode_ci NOT NULL, + `lang` varchar(20) collate utf8_unicode_ci NOT NULL, + PRIMARY KEY (`attribute_id`,`lang`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + +-- +-- Dumping data for table `lime_participant_attribute_names_lang` +-- + + +-- -------------------------------------------------------- + +-- +-- Table structure for table `lime_participant_attribute_values` +-- + +CREATE TABLE `lime_participant_attribute_values` ( + `value_id` int(11) NOT NULL auto_increment, + `attribute_id` int(11) NOT NULL, + `value` varchar(20) collate utf8_unicode_ci NOT NULL, + PRIMARY KEY (`value_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + +-- +-- Dumping data for table `lime_participant_attribute_values` +-- + + +-- -------------------------------------------------------- + +-- +-- Table structure for table `lime_participant_shares` +-- + +CREATE TABLE `lime_participant_shares` ( + `participant_id` varchar(50) collate utf8_unicode_ci NOT NULL, + `share_uid` int(11) NOT NULL, + `date_added` datetime NOT NULL, + `can_edit` varchar(5) collate utf8_unicode_ci NOT NULL, + PRIMARY KEY (`participant_id`,`share_uid`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + +-- +-- Dumping data for table `lime_participant_shares` +-- + + -- -------------------------------------------------------- -- @@ -575,6 +714,7 @@ CREATE TABLE `lime_questions` ( `language` varchar(20) collate utf8_unicode_ci NOT NULL default 'en', `scale_id` tinyint(4) NOT NULL default '0', `same_default` tinyint(4) NOT NULL default '0' COMMENT 'Saves if user set to use the same default value across languages in default options dialog', + `relevance` text collate utf8_unicode_ci, PRIMARY KEY (`qid`,`language`), KEY `questions_idx2` (`sid`), KEY `questions_idx3` (`gid`), @@ -598,8 +738,10 @@ CREATE TABLE `lime_question_attributes` ( `qid` int(11) NOT NULL default '0', `attribute` varchar(50) collate utf8_unicode_ci default NULL, `value` text collate utf8_unicode_ci, + `language` varchar(20) collate utf8_unicode_ci default NULL, PRIMARY KEY (`qaid`), - KEY `question_attributes_idx2` (`qid`) + KEY `question_attributes_idx2` (`qid`), + KEY `question_attributes_idx3` (`attribute`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; -- @@ -741,14 +883,9 @@ CREATE TABLE `lime_settings_global` ( -- Dumping data for table `lime_settings_global` -- -INSERT INTO `lime_settings_global` (`stg_name`, `stg_value`) VALUES('DBVersion', '146'); -INSERT INTO `lime_settings_global` (`stg_name`, `stg_value`) VALUES('force_ssl', ''); -INSERT INTO `lime_settings_global` (`stg_name`, `stg_value`) VALUES('SessionName', 'ls28629164789259281352'); -INSERT INTO `lime_settings_global` (`stg_name`, `stg_value`) VALUES('showgroupinfo', 'choose'); -INSERT INTO `lime_settings_global` (`stg_name`, `stg_value`) VALUES('showqnumcode', 'choose'); -INSERT INTO `lime_settings_global` (`stg_name`, `stg_value`) VALUES('showXquestions', 'choose'); -INSERT INTO `lime_settings_global` (`stg_name`, `stg_value`) VALUES('updateavailable', '0'); -INSERT INTO `lime_settings_global` (`stg_name`, `stg_value`) VALUES('updatelastcheck', '2011-09-07 14:38:57'); +INSERT INTO `lime_settings_global` (`stg_name`, `stg_value`) VALUES +('DBVersion', '155.6'), +('SessionName', 'ls28629164789259281352'); -- -------------------------------------------------------- @@ -795,7 +932,7 @@ CREATE TABLE `lime_surveys` ( `emailresponseto` text collate utf8_unicode_ci, `emailnotificationto` text collate utf8_unicode_ci, `tokenlength` tinyint(2) default '15', - `showXquestions` char(1) collate utf8_unicode_ci default 'Y', + `showxquestions` char(1) collate utf8_unicode_ci default 'Y', `showgroupinfo` char(1) collate utf8_unicode_ci default 'B', `shownoanswer` char(1) collate utf8_unicode_ci default 'Y', `showqnumcode` char(1) collate utf8_unicode_ci default 'X', @@ -812,6 +949,8 @@ CREATE TABLE `lime_surveys` ( `navigationdelay` tinyint(2) default '0', `nokeyboard` char(1) collate utf8_unicode_ci default 'N', `alloweditaftercompletion` char(1) collate utf8_unicode_ci default 'N', + `googleanalyticsstyle` char(1) collate utf8_unicode_ci default NULL, + `googleanalyticsapikey` varchar(25) collate utf8_unicode_ci default NULL, PRIMARY KEY (`sid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; @@ -827,7 +966,7 @@ CREATE TABLE `lime_surveys` ( -- CREATE TABLE `lime_surveys_languagesettings` ( - `surveyls_survey_id` int(10) unsigned NOT NULL default '0', + `surveyls_survey_id` int(11) NOT NULL default '0', `surveyls_language` varchar(45) collate utf8_unicode_ci NOT NULL default 'en', `surveyls_title` varchar(200) collate utf8_unicode_ci NOT NULL, `surveyls_description` text collate utf8_unicode_ci, @@ -844,11 +983,11 @@ CREATE TABLE `lime_surveys_languagesettings` ( `surveyls_email_confirm_subj` varchar(255) collate utf8_unicode_ci default NULL, `surveyls_email_confirm` text collate utf8_unicode_ci, `surveyls_dateformat` int(10) unsigned NOT NULL default '1', - `surveyls_numberformat` int(11) NOT NULL default '0', `email_admin_notification_subj` varchar(255) collate utf8_unicode_ci default NULL, `email_admin_notification` text collate utf8_unicode_ci, `email_admin_responses_subj` varchar(255) collate utf8_unicode_ci default NULL, `email_admin_responses` text collate utf8_unicode_ci, + `surveyls_numberformat` int(11) NOT NULL default '0', PRIMARY KEY (`surveyls_survey_id`,`surveyls_language`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; @@ -857,6 +996,25 @@ CREATE TABLE `lime_surveys_languagesettings` ( -- +-- -------------------------------------------------------- + +-- +-- Table structure for table `lime_survey_links` +-- + +CREATE TABLE `lime_survey_links` ( + `participant_id` varchar(50) collate utf8_unicode_ci NOT NULL, + `token_id` int(11) NOT NULL, + `survey_id` int(11) NOT NULL, + `date_created` datetime NOT NULL, + PRIMARY KEY (`participant_id`,`token_id`,`survey_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; + +-- +-- Dumping data for table `lime_survey_links` +-- + + -- -------------------------------------------------------- -- @@ -864,8 +1022,8 @@ CREATE TABLE `lime_surveys_languagesettings` ( -- CREATE TABLE `lime_survey_permissions` ( - `sid` int(10) unsigned NOT NULL, - `uid` int(10) unsigned NOT NULL, + `sid` int(11) NOT NULL, + `uid` int(11) NOT NULL, `permission` varchar(20) collate utf8_unicode_ci NOT NULL, `create_p` tinyint(1) NOT NULL default '0', `read_p` tinyint(1) NOT NULL default '0', @@ -927,19 +1085,22 @@ CREATE TABLE `lime_users` ( `users_name` varchar(64) collate utf8_unicode_ci NOT NULL default '', `password` blob NOT NULL, `full_name` varchar(50) collate utf8_unicode_ci NOT NULL, - `parent_id` int(10) unsigned NOT NULL, + `parent_id` int(11) NOT NULL, `lang` varchar(20) collate utf8_unicode_ci default NULL, `email` varchar(320) collate utf8_unicode_ci default NULL, `create_survey` tinyint(1) NOT NULL default '0', `create_user` tinyint(1) NOT NULL default '0', + `participant_panel` tinyint(1) NOT NULL default '0', `delete_user` tinyint(1) NOT NULL default '0', `superadmin` tinyint(1) NOT NULL default '0', `configurator` tinyint(1) NOT NULL default '0', `manage_template` tinyint(1) NOT NULL default '0', `manage_label` tinyint(1) NOT NULL default '0', `htmleditormode` varchar(7) collate utf8_unicode_ci default 'default', + `templateeditormode` varchar(7) collate utf8_unicode_ci default 'default', + `questionselectormode` varchar(7) collate utf8_unicode_ci default 'default', `one_time_pw` blob, - `dateformat` int(10) unsigned NOT NULL default '1', + `dateformat` int(11) NOT NULL default '1', PRIMARY KEY (`uid`), UNIQUE KEY `users_name` (`users_name`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; @@ -948,7 +1109,8 @@ CREATE TABLE `lime_users` ( -- Dumping data for table `lime_users` -- -INSERT INTO `lime_users` (`uid`, `users_name`, `password`, `full_name`, `parent_id`, `lang`, `email`, `create_survey`, `create_user`, `delete_user`, `superadmin`, `configurator`, `manage_template`, `manage_label`, `htmleditormode`, `one_time_pw`, `dateformat`) VALUES(1, 'admin', 0x35653838343839386461323830343731353164306535366638646336323932373733363033643064366161626264643632613131656637323164313534326438, 'Your Name', 0, 'en', 'your@email.org', 1, 1, 1, 1, 1, 1, 1, 'default', NULL, 1); +INSERT INTO `lime_users` (`uid`, `users_name`, `password`, `full_name`, `parent_id`, `lang`, `email`, `create_survey`, `create_user`, `participant_panel`, `delete_user`, `superadmin`, `configurator`, `manage_template`, `manage_label`, `htmleditormode`, `templateeditormode`, `questionselectormode`, `one_time_pw`, `dateformat`) VALUES +(1, 'admin', 0x35653838343839386461323830343731353164306535366638646336323932373733363033643064366161626264643632613131656637323164313534326438, 'Your Name', 0, 'en', 'your-email@example.net', 1, 1, 0, 1, 1, 1, 1, 1, 'default', 'default', 'default', NULL, 1); -- -------------------------------------------------------- @@ -957,10 +1119,10 @@ INSERT INTO `lime_users` (`uid`, `users_name`, `password`, `full_name`, `parent_ -- CREATE TABLE `lime_user_groups` ( - `ugid` int(10) unsigned NOT NULL auto_increment, + `ugid` int(11) NOT NULL auto_increment, `name` varchar(20) collate utf8_unicode_ci NOT NULL, `description` text collate utf8_unicode_ci NOT NULL, - `owner_id` int(10) unsigned NOT NULL, + `owner_id` int(11) NOT NULL, PRIMARY KEY (`ugid`), UNIQUE KEY `name` (`name`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; @@ -977,8 +1139,8 @@ CREATE TABLE `lime_user_groups` ( -- CREATE TABLE `lime_user_in_groups` ( - `ugid` int(10) unsigned NOT NULL, - `uid` int(10) unsigned NOT NULL, + `ugid` int(11) NOT NULL, + `uid` int(11) NOT NULL, PRIMARY KEY (`ugid`,`uid`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; diff --git a/include/limesurvey/.gitignore b/include/limesurvey/.gitignore new file mode 100644 index 00000000..8a57a94c --- /dev/null +++ b/include/limesurvey/.gitignore @@ -0,0 +1,2 @@ + +/upload/surveys/* diff --git a/include/limesurvey/admin/access_denied.php b/include/limesurvey/admin/access_denied.php index 1b054925..2b064cfb 100644 --- a/include/limesurvey/admin/access_denied.php +++ b/include/limesurvey/admin/access_denied.php @@ -10,15 +10,15 @@ * other free or open source software licenses. * See COPYRIGHT.php for copyright notices and details. * - * $Id: access_denied.php 10925 2011-09-02 14:12:02Z c_schmitz $ + * $Id: access_denied.php 11607 2011-12-06 23:19:52Z tmswhite $ */ -if (!isset($dbprefix) || isset($_REQUEST['dbprefix'])) {die("Cannot run this script directly (access_denied)");} +include_once("login_check.php"); //Login Check dies also if the script is started directly if (isset($_SESSION['loginID'])) { - + include('html.php'); // For showadminmenu $accesssummary = "".$clang->gT("Access denied!")."
\n";
$action=returnglobal('action');
diff --git a/include/limesurvey/admin/activate.php b/include/limesurvey/admin/activate.php
index 85c87ed8..bdd48c15 100644
--- a/include/limesurvey/admin/activate.php
+++ b/include/limesurvey/admin/activate.php
@@ -10,7 +10,7 @@
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*
- * $Id: activate.php 10925 2011-09-02 14:12:02Z c_schmitz $
+ * $Id: activate.php 11607 2011-12-06 23:19:52Z tmswhite $
*/
@@ -88,3 +88,4 @@ else
include('tokens.php');
}
}
+
diff --git a/include/limesurvey/admin/activate_functions.php b/include/limesurvey/admin/activate_functions.php
index 1038dea4..2d5bcfc1 100644
--- a/include/limesurvey/admin/activate_functions.php
+++ b/include/limesurvey/admin/activate_functions.php
@@ -1,530 +1,549 @@
- $fixnumbering
- */
-function fixNumbering($fixnumbering)
-{
-
- global $dbprefix, $connect, $clang;
- //Fix a question id - requires renumbering a question
- $oldqid = $fixnumbering;
- $query = "SELECT qid FROM {$dbprefix}questions ORDER BY qid DESC";
- $result = db_select_limit_assoc($query, 1) or safe_die($query."
".$connect->ErrorMsg());
- while ($row=$result->FetchRow()) {$lastqid=$row['qid'];}
- $newqid=$lastqid+1;
- $query = "UPDATE {$dbprefix}questions SET qid=$newqid WHERE qid=$oldqid";
- $result = $connect->Execute($query) or safe_die($query."
".$connect->ErrorMsg());
- // Update subquestions
- $query = "UPDATE {$dbprefix}questions SET parent_qid=$newqid WHERE parent_qid=$oldqid";
- $result = $connect->Execute($query) or safe_die($query."
".$connect->ErrorMsg());
- //Update conditions.. firstly conditions FOR this question
- $query = "UPDATE {$dbprefix}conditions SET qid=$newqid WHERE qid=$oldqid";
- $result = $connect->Execute($query) or safe_die($query."
".$connect->ErrorMsg());
- //Now conditions based upon this question
- $query = "SELECT cqid, cfieldname FROM {$dbprefix}conditions WHERE cqid=$oldqid";
- $result = db_execute_assoc($query) or safe_die($query."
".$connect->ErrorMsg());
- while ($row=$result->FetchRow())
- {
- $switcher[]=array("cqid"=>$row['cqid'], "cfieldname"=>$row['cfieldname']);
- }
- if (isset($switcher))
- {
- foreach ($switcher as $switch)
- {
- $query = "UPDATE {$dbprefix}conditions
- SET cqid=$newqid,
- cfieldname='".str_replace("X".$oldqid, "X".$newqid, $switch['cfieldname'])."'
- WHERE cqid=$oldqid";
- $result = $connect->Execute($query) or safe_die($query."
".$connect->ErrorMsg());
- }
- }
- //Now question_attributes
- $query = "UPDATE {$dbprefix}question_attributes SET qid=$newqid WHERE qid=$oldqid";
- $result = $connect->Execute($query) or safe_die($query."
".$connect->ErrorMsg());
- //Now answers
- $query = "UPDATE {$dbprefix}answers SET qid=$newqid WHERE qid=$oldqid";
- $result = $connect->Execute($query) or safe_die($query."
".$connect->ErrorMsg());
-}
-/**
- * checks consistency of groups
- * @global $dbprefix
- * @global $connect
- * @global $clang
- * @return
".$connect->ErrorMsg());
- while ($row=$groupresult->FetchRow())
- { //TIBO
- if ($row['count'] == 0)
- {
- $failedgroupcheck[]=array($row['gid'], $row['group_name'], ": ".$clang->gT("This group does not contain any question(s)."));
- }
- }
- if(isset($failedgroupcheck))
- return $failedgroupcheck;
- else
- return false;
-
-}
-/**
- * checks questions in a survey for consistency
- * @global
$chkquery
".$connect->ErrorMsg());
- while ($chkrow = $chkresult->FetchRow())
- {
- if ($qtypes[$chkrow['type']]['subquestions']>0)
- {
- $chaquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid = {$chkrow['qid']} ORDER BY question_order";
- $charesult=$connect->Execute($chaquery);
- $chacount=$charesult->RecordCount();
- if ($chacount == 0)
- {
- $failedcheck[]=array($chkrow['qid'], $chkrow['question'], ": ".$clang->gT("This question is a subquestion type question but has no configured subquestions."), $chkrow['gid']);
- }
- }
- if ($qtypes[$chkrow['type']]['answerscales']>0)
- {
- $chaquery = "SELECT * FROM {$dbprefix}answers WHERE qid = {$chkrow['qid']} ORDER BY sortorder, answer";
- $charesult=$connect->Execute($chaquery);
- $chacount=$charesult->RecordCount();
- if ($chacount == 0)
- {
- $failedcheck[]=array($chkrow['qid'], $chkrow['question'], ": ".$clang->gT("This question is a multiple answer type question but has no answers."), $chkrow['gid']);
- }
- }
- }
-
- //NOW CHECK THAT ALL QUESTIONS HAVE A 'QUESTION TYPE' FIELD SET
- $chkquery = "SELECT qid, question, gid FROM {$dbprefix}questions WHERE sid={$_GET['sid']} AND type = ''";
- $chkresult = db_execute_assoc($chkquery) or safe_die ("Couldn't check questions for missing types
$chkquery
".$connect->ErrorMsg());
- while ($chkrow = $chkresult->FetchRow())
- {
- $failedcheck[]=array($chkrow['qid'], $chkrow['question'], ": ".$clang->gT("This question does not have a question 'type' set."), $chkrow['gid']);
- }
-
-
-
-
- //ChECK THAT certain array question types have answers set
- $chkquery = "SELECT q.qid, question, gid FROM {$dbprefix}questions as q WHERE (select count(*) from {$dbprefix}answers as a where a.qid=q.qid and scale_id=0)=0 and sid={$_GET['sid']} AND type IN ('F', 'H', 'W', 'Z', '1') and q.parent_qid=0";
- $chkresult = db_execute_assoc($chkquery) or safe_die ("Couldn't check questions for missing answers
$chkquery
".$connect->ErrorMsg());
- while($chkrow = $chkresult->FetchRow()){
- $failedcheck[]=array($chkrow['qid'], $chkrow['question'], ": ".$clang->gT("This question requires answers, but none are set."), $chkrow['gid']);
- } // while
-
- //CHECK THAT DUAL Array has answers set
- $chkquery = "SELECT q.qid, question, gid FROM {$dbprefix}questions as q WHERE (select count(*) from {$dbprefix}answers as a where a.qid=q.qid and scale_id=1)=0 and sid={$_GET['sid']} AND type='1' and q.parent_qid=0";
- $chkresult = db_execute_assoc($chkquery) or safe_die ("Couldn't check questions for missing 2nd answer set
$chkquery
".$connect->ErrorMsg());
- while($chkrow = $chkresult->FetchRow()){
- $failedcheck[]=array($chkrow['qid'], $chkrow['question'], ": ".$clang->gT("This question requires a second answer set but none is set."), $chkrow['gid']);
- } // while
-
-
- //CHECK THAT ALL CONDITIONS SET ARE FOR QUESTIONS THAT PRECEED THE QUESTION CONDITION
- //A: Make an array of all the qids in order of appearance
- // $qorderquery="SELECT * FROM {$dbprefix}questions, {$dbprefix}groups WHERE {$dbprefix}questions.gid={$dbprefix}groups.gid AND {$dbprefix}questions.sid={$_GET['sid']} ORDER BY {$dbprefix}groups.sortorder, {$dbprefix}questions.title";
- // $qorderresult=$connect->Execute($qorderquery) or safe_die("Couldn't generate a list of questions in order
$qorderquery
".$connect->ErrorMsg());
- // $qordercount=$qorderresult->RecordCount();
- // $c=0;
- // while ($qorderrow=$qorderresult->FetchRow())
- // {
- // $qidorder[]=array($c, $qorderrow['qid']);
- // $c++;
- // }
- //TO AVOID NATURAL SORT ORDER ISSUES, FIRST GET ALL QUESTIONS IN NATURAL SORT ORDER, AND FIND OUT WHICH NUMBER IN THAT ORDER THIS QUESTION IS
- $qorderquery = "SELECT * FROM {$dbprefix}questions WHERE sid=$surveyid AND type not in ('S', 'D', 'T', 'Q')";
- $qorderresult = db_execute_assoc($qorderquery) or safe_die ("$qorderquery
".$connect->ErrorMsg());
- $qrows = array(); //Create an empty array in case FetchRow does not return any rows
- while ($qrow = $qorderresult->FetchRow()) {$qrows[] = $qrow;} // Get table output into array
- usort($qrows, 'GroupOrderThenQuestionOrder'); // Perform a case insensitive natural sort on group name then question title of a multidimensional array
- $c=0;
- foreach ($qrows as $qr)
- {
- $qidorder[]=array($c, $qrow['qid']);
- $c++;
- }
- $qordercount="";
- //1: Get each condition's question id
- $conquery= "SELECT {$dbprefix}conditions.qid, cqid, {$dbprefix}questions.question, "
- . "{$dbprefix}questions.gid "
- . "FROM {$dbprefix}conditions, {$dbprefix}questions, {$dbprefix}groups "
- . "WHERE {$dbprefix}conditions.qid={$dbprefix}questions.qid "
- . "AND {$dbprefix}questions.gid={$dbprefix}groups.gid ORDER BY {$dbprefix}conditions.qid";
- $conresult=db_execute_assoc($conquery) or safe_die("Couldn't check conditions for relative consistency
$conquery
".$connect->ErrorMsg());
- //2: Check each conditions cqid that it occurs later than the cqid
- while ($conrow=$conresult->FetchRow())
- {
- $cqidfound=0;
- $qidfound=0;
- $b=0;
- while ($b<$qordercount)
- {
- if ($conrow['cqid'] == $qidorder[$b][1])
- {
- $cqidfound = 1;
- $b=$qordercount;
- }
- if ($conrow['qid'] == $qidorder[$b][1])
- {
- $qidfound = 1;
- $b=$qordercount;
- }
- if ($qidfound == 1)
- {
- $failedcheck[]=array($conrow['qid'], $conrow['question'], ": ".$clang->gT("This question has a condition set, however the condition is based on a question that appears after it."), $conrow['gid']);
- }
- $b++;
- }
- }
- //CHECK THAT ALL THE CREATED FIELDS WILL BE UNIQUE
- $fieldmap=createFieldMap($surveyid, "full");
- if (isset($fieldmap))
- {
- foreach($fieldmap as $fielddata)
- {
- $fieldlist[]=$fielddata['fieldname'];
- }
- $fieldlist=array_reverse($fieldlist); //let's always change the later duplicate, not the earlier one
- }
- $checkKeysUniqueComparison = create_function('$value','if ($value > 1) return true;');
- @$duplicates = array_keys (array_filter (array_count_values($fieldlist), $checkKeysUniqueComparison));
- if (isset($duplicates))
- {
- foreach ($duplicates as $dup)
- {
- $badquestion=arraySearchByKey($dup, $fieldmap, "fieldname", 1);
- $fix = "[Click Here to Fix]";
- $failedcheck[]=array($badquestion['qid'], $badquestion['question'], ": Bad duplicate fieldname $fix", $badquestion['gid']);
- }
- }
- if(isset($failedcheck))
- return $failedcheck;
- else
- return false;
-}
-/**
- * Function to activate a survey
- * @global $dbprefix $dbprefix
- * @global $connect $connect
- * @global $clang $clang
- * @param int $postsid
- * @param int $surveyid
- * @return string
- */
-function activateSurvey($postsid,$surveyid, $scriptname='admin.php')
-{
- global $dbprefix, $connect, $clang, $databasetype,$databasetabletype, $uploaddir;
-
- $createsurvey='';
- $activateoutput='';
- $createsurveytimings='';
- $createsurveydirectory=false;
- //Check for any additional fields for this survey and create necessary fields (token and datestamp)
- $pquery = "SELECT anonymized, allowregister, datestamp, ipaddr, refurl, savetimings FROM {$dbprefix}surveys WHERE sid={$postsid}";
- $presult=db_execute_assoc($pquery);
- $prow=$presult->FetchRow();
- if ($prow['allowregister'] == "Y")
- {
- $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'].'`';
- switch($arow['type'])
- {
- case 'startlanguage':
- $createsurvey .= " C(20) NOTNULL";
- break;
- case 'id':
- $createsurvey .= " I NOTNULL AUTO PRIMARY";
- $createsurveytimings .= " `{$arow['fieldname']}` I NOTNULL PRIMARY,\n";
- break;
- case "startdate":
- case "datestamp":
- $createsurvey .= " T NOTNULL";
- break;
- case "submitdate":
- $createsurvey .= " T";
- break;
- case "lastpage":
- $createsurvey .= " I";
- break;
- case "N": //NUMERICAL
- $createsurvey .= " F";
- break;
- case "S": //SHORT TEXT
- if ($databasetype=='mysql' || $databasetype=='mysqli') {$createsurvey .= " X";}
- else {$createsurvey .= " C(255)";}
- break;
- case "L": //LIST (RADIO)
- case "!": //LIST (DROPDOWN)
- case "M": //Multiple choice
- case "P": //Multiple choice with comment
- case "O": //DROPDOWN LIST WITH COMMENT
- if ($arow['aid'] != 'other' && strpos($arow['aid'],'comment')===false && strpos($arow['aid'],'othercomment')===false)
- {
- $createsurvey .= " C(5)";
- }
- else
- {
- $createsurvey .= " X";
- }
- break;
- case "K": // Multiple Numerical
- $createsurvey .= " F";
- break;
- case "U": //Huge text
- case "Q": //Multiple short text
- case "T": //LONG TEXT
- case ";": //Multi Flexi
- case ":": //Multi Flexi
- $createsurvey .= " X";
- break;
- case "D": //DATE
- $createsurvey .= " D";
- break;
- case "5": //5 Point Choice
- case "G": //Gender
- case "Y": //YesNo
- case "X": //Boilerplate
- $createsurvey .= " C(1)";
- break;
- case "I": //Language switch
- $createsurvey .= " C(20)";
- break;
- case "|":
- $createsurveydirectory = true;
- if (strpos($arow['fieldname'], "_"))
- $createsurvey .= " I1";
- else
- $createsurvey .= " X";
- break;
- case "ipaddress":
- if ($prow['ipaddr'] == "Y")
- $createsurvey .= " X";
- break;
- case "url":
- if ($prow['refurl'] == "Y")
- $createsurvey .= " X";
- break;
- case "token":
- if ($prow['anonymized'] == "N")
- {
- $createsurvey .= " C(36)";
- }
- break;
- default:
- $createsurvey .= " C(5)";
- }
- }
- $timingsfieldmap = createTimingsFieldMap($surveyid);
- $createsurveytimings .= '`'.implode("` F DEFAULT '0',\n`",array_keys($timingsfieldmap)) . "` F DEFAULT '0'";
-
- // 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
-
- $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';
- $sqlarraytimings = $dict->CreateTableSQL($tabnametimings, $createsurveytimings, $taboptarray);
- }
-
- $execresult=$dict->ExecuteSQLArray($sqlarray,1);
- if ($execresult==0 || $execresult==1)
- {
- $activateoutput .= "
\n" ;
- }
- if ($execresult != 0 && $execresult !=1)
- {
- $anquery = "SELECT autonumber_start FROM {$dbprefix}surveys WHERE sid={$postsid}";
- if ($anresult=db_execute_assoc($anquery))
- {
- //if there is an autonumber_start field, start auto numbering here
- while($row=$anresult->FetchRow())
- {
- if ($row['autonumber_start'] > 0)
- {
- 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
- {
- $autonumberquery = "ALTER TABLE {$dbprefix}survey_{$postsid} AUTO_INCREMENT = ".$row['autonumber_start'];
- $result = @$connect->Execute($autonumberquery);
-
- }
- }
- }
- if (isset($savetimings) && $savetimings=="TRUE")
- {
- $dict->ExecuteSQLArray($sqlarraytimings,1); // create a timings table for this survey
- }
- }
-
- $activateoutput .= "
\n
\n";
- $lsrcOutput = true;
- }
-
- if($scriptname=='lsrc')
- {
- if($lsrcOutput==true)
- return true;
- else
- return $activateoutput;
- }
- else
- {
- 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();
- }
-}
+ $fixnumbering
+*/
+function fixNumbering($fixnumbering)
+{
+
+ global $dbprefix, $connect, $clang, $surveyid;
+
+ LimeExpressionManager::RevertUpgradeConditionsToRelevance($surveyid);
+ //Fix a question id - requires renumbering a question
+ $oldqid = sanitize_int($fixnumbering);
+ $query = "SELECT qid FROM {$dbprefix}questions ORDER BY qid DESC";
+ $result = db_select_limit_assoc($query, 1) or safe_die($query."
".$connect->ErrorMsg());
+ while ($row=$result->FetchRow()) {$lastqid=$row['qid'];}
+ $newqid=$lastqid+1;
+ $query = "UPDATE {$dbprefix}questions SET qid=$newqid WHERE qid=$oldqid";
+ $result = $connect->Execute($query) or safe_die($query."
".$connect->ErrorMsg());
+ // Update subquestions
+ $query = "UPDATE {$dbprefix}questions SET parent_qid=$newqid WHERE parent_qid=$oldqid";
+ $result = $connect->Execute($query) or safe_die($query."
".$connect->ErrorMsg());
+ //Update conditions.. firstly conditions FOR this question
+ $query = "UPDATE {$dbprefix}conditions SET qid=$newqid WHERE qid=$oldqid";
+ $result = $connect->Execute($query) or safe_die($query."
".$connect->ErrorMsg());
+ //Now conditions based upon this question
+ $query = "SELECT cqid, cfieldname FROM {$dbprefix}conditions WHERE cqid=$oldqid";
+ $result = db_execute_assoc($query) or safe_die($query."
".$connect->ErrorMsg());
+ while ($row=$result->FetchRow())
+ {
+ $switcher[]=array("cqid"=>$row['cqid'], "cfieldname"=>$row['cfieldname']);
+ }
+ if (isset($switcher))
+ {
+ foreach ($switcher as $switch)
+ {
+ $query = "UPDATE {$dbprefix}conditions
+ SET cqid=$newqid,
+ cfieldname='".str_replace("X".$oldqid, "X".$newqid, $switch['cfieldname'])."'
+ WHERE cqid=$oldqid";
+ $result = $connect->Execute($query) or safe_die($query."
".$connect->ErrorMsg());
+ }
+ }
+ //Now question_attributes
+ $query = "UPDATE {$dbprefix}question_attributes SET qid=$newqid WHERE qid=$oldqid";
+ $result = $connect->Execute($query) or safe_die($query."
".$connect->ErrorMsg());
+ //Now answers
+ $query = "UPDATE {$dbprefix}answers SET qid=$newqid WHERE qid=$oldqid";
+ $result = $connect->Execute($query) or safe_die($query."
".$connect->ErrorMsg());
+
+ LimeExpressionManager::UpgradeConditionsToRelevance($surveyid);
+}
+/**
+* checks consistency of groups
+* @global $dbprefix
+* @global $connect
+* @global $clang
+* @return
".$connect->ErrorMsg());
+ while ($row=$groupresult->FetchRow())
+ { //TIBO
+ if ($row['count'] == 0)
+ {
+ $failedgroupcheck[]=array($row['gid'], $row['group_name'], ": ".$clang->gT("This group does not contain any question(s)."));
+ }
+ }
+ if(isset($failedgroupcheck))
+ return $failedgroupcheck;
+ else
+ return false;
+
+}
+/**
+* checks questions in a survey for consistency
+* @global
$chkquery
".$connect->ErrorMsg());
+ while ($chkrow = $chkresult->FetchRow())
+ {
+ if ($qtypes[$chkrow['type']]['subquestions']>0)
+ {
+ $chaquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid = {$chkrow['qid']} ORDER BY question_order";
+ $charesult=$connect->Execute($chaquery);
+ $chacount=$charesult->RecordCount();
+ if ($chacount == 0)
+ {
+ $failedcheck[]=array($chkrow['qid'], $chkrow['question'], ": ".$clang->gT("This question is a subquestion type question but has no configured subquestions."), $chkrow['gid']);
+ }
+ }
+ if ($qtypes[$chkrow['type']]['answerscales']>0)
+ {
+ $chaquery = "SELECT * FROM {$dbprefix}answers WHERE qid = {$chkrow['qid']} ORDER BY sortorder, answer";
+ $charesult=$connect->Execute($chaquery);
+ $chacount=$charesult->RecordCount();
+ if ($chacount == 0)
+ {
+ $failedcheck[]=array($chkrow['qid'], $chkrow['question'], ": ".$clang->gT("This question is a multiple answer type question but has no answers."), $chkrow['gid']);
+ }
+ }
+ }
+
+ //NOW CHECK THAT ALL QUESTIONS HAVE A 'QUESTION TYPE' FIELD SET
+ $chkquery = "SELECT qid, question, gid FROM {$dbprefix}questions WHERE sid={$surveyid} AND type = ''";
+ $chkresult = db_execute_assoc($chkquery) or safe_die ("Couldn't check questions for missing types
$chkquery
".$connect->ErrorMsg());
+ while ($chkrow = $chkresult->FetchRow())
+ {
+ $failedcheck[]=array($chkrow['qid'], $chkrow['question'], ": ".$clang->gT("This question does not have a question 'type' set."), $chkrow['gid']);
+ }
+
+
+
+
+ //ChECK THAT certain array question types have answers set
+ $chkquery = "SELECT q.qid, question, gid FROM {$dbprefix}questions as q WHERE (select count(*) from {$dbprefix}answers as a where a.qid=q.qid and scale_id=0)=0 and sid={$surveyid} AND type IN ('F', 'H', 'W', 'Z', '1') and q.parent_qid=0";
+ $chkresult = db_execute_assoc($chkquery) or safe_die ("Couldn't check questions for missing answers
$chkquery
".$connect->ErrorMsg());
+ while($chkrow = $chkresult->FetchRow()){
+ $failedcheck[]=array($chkrow['qid'], $chkrow['question'], ": ".$clang->gT("This question requires answers, but none are set."), $chkrow['gid']);
+ } // while
+
+ //CHECK THAT DUAL Array has answers set
+ $chkquery = "SELECT q.qid, question, gid FROM {$dbprefix}questions as q WHERE (select count(*) from {$dbprefix}answers as a where a.qid=q.qid and scale_id=1)=0 and sid={$surveyid} AND type='1' and q.parent_qid=0";
+ $chkresult = db_execute_assoc($chkquery) or safe_die ("Couldn't check questions for missing 2nd answer set
$chkquery
".$connect->ErrorMsg());
+ while($chkrow = $chkresult->FetchRow()){
+ $failedcheck[]=array($chkrow['qid'], $chkrow['question'], ": ".$clang->gT("This question requires a second answer set but none is set."), $chkrow['gid']);
+ } // while
+
+
+ //CHECK THAT ALL CONDITIONS SET ARE FOR QUESTIONS THAT PRECEED THE QUESTION CONDITION
+ //A: Make an array of all the qids in order of appearance
+ // $qorderquery="SELECT * FROM {$dbprefix}questions, {$dbprefix}groups WHERE {$dbprefix}questions.gid={$dbprefix}groups.gid AND {$dbprefix}questions.sid={$surveyid} ORDER BY {$dbprefix}groups.sortorder, {$dbprefix}questions.title";
+ // $qorderresult=$connect->Execute($qorderquery) or safe_die("Couldn't generate a list of questions in order
$qorderquery
".$connect->ErrorMsg());
+ // $qordercount=$qorderresult->RecordCount();
+ // $c=0;
+ // while ($qorderrow=$qorderresult->FetchRow())
+ // {
+ // $qidorder[]=array($c, $qorderrow['qid']);
+ // $c++;
+ // }
+ //TO AVOID NATURAL SORT ORDER ISSUES, FIRST GET ALL QUESTIONS IN NATURAL SORT ORDER, AND FIND OUT WHICH NUMBER IN THAT ORDER THIS QUESTION IS
+ $qorderquery = "SELECT * FROM {$dbprefix}questions WHERE sid=$surveyid AND type not in ('S', 'D', 'T', 'Q')";
+ $qorderresult = db_execute_assoc($qorderquery) or safe_die ("$qorderquery
".$connect->ErrorMsg());
+ $qrows = array(); //Create an empty array in case FetchRow does not return any rows
+ while ($qrow = $qorderresult->FetchRow()) {$qrows[] = $qrow;} // Get table output into array
+ usort($qrows, 'GroupOrderThenQuestionOrder'); // Perform a case insensitive natural sort on group name then question title of a multidimensional array
+ $c=0;
+ foreach ($qrows as $qr)
+ {
+ $qidorder[]=array($c, $qrow['qid']);
+ $c++;
+ }
+ $qordercount="";
+ //1: Get each condition's question id
+ $conquery= "SELECT {$dbprefix}conditions.qid, cqid, {$dbprefix}questions.question, "
+ . "{$dbprefix}questions.gid "
+ . "FROM {$dbprefix}conditions, {$dbprefix}questions, {$dbprefix}groups "
+ . "WHERE {$dbprefix}conditions.qid={$dbprefix}questions.qid "
+ . "AND {$dbprefix}questions.gid={$dbprefix}groups.gid ORDER BY {$dbprefix}conditions.qid";
+ $conresult=db_execute_assoc($conquery) or safe_die("Couldn't check conditions for relative consistency
$conquery
".$connect->ErrorMsg());
+ //2: Check each conditions cqid that it occurs later than the cqid
+ while ($conrow=$conresult->FetchRow())
+ {
+ $cqidfound=0;
+ $qidfound=0;
+ $b=0;
+ while ($b<$qordercount)
+ {
+ if ($conrow['cqid'] == $qidorder[$b][1])
+ {
+ $cqidfound = 1;
+ $b=$qordercount;
+ }
+ if ($conrow['qid'] == $qidorder[$b][1])
+ {
+ $qidfound = 1;
+ $b=$qordercount;
+ }
+ if ($qidfound == 1)
+ {
+ $failedcheck[]=array($conrow['qid'], $conrow['question'], ": ".$clang->gT("This question has a condition set, however the condition is based on a question that appears after it."), $conrow['gid']);
+ }
+ $b++;
+ }
+ }
+ //CHECK THAT ALL THE CREATED FIELDS WILL BE UNIQUE
+ $fieldmap=createFieldMap($surveyid, 'full', true,false, GetBaseLanguageFromSurveyID($surveyid));// createFieldMap($surveyid, $styl, $force_refresh,$questionid, $sQuestionLanguage);
+ $clang = new limesurvey_lang($_SESSION['adminlang']);
+ if (isset($fieldmap))
+ {
+ foreach($fieldmap as $fielddata)
+ {
+ $fieldlist[]=$fielddata['fieldname'];
+ }
+ $fieldlist=array_reverse($fieldlist); //let's always change the later duplicate, not the earlier one
+ }
+ $checkKeysUniqueComparison = create_function('$value','if ($value > 1) return true;');
+ @$duplicates = array_keys (array_filter (array_count_values($fieldlist), $checkKeysUniqueComparison));
+ if (isset($duplicates))
+ {
+ foreach ($duplicates as $dup)
+ {
+ $badquestion=arraySearchByKey($dup, $fieldmap, "fieldname", 1);
+ $fix = "[Click Here to Fix]";
+ $failedcheck[]=array($badquestion['qid'], $badquestion['question'], ": Bad duplicate fieldname $fix", $badquestion['gid']);
+ }
+ }
+ if(isset($failedcheck))
+ return $failedcheck;
+ else
+ return false;
+}
+/**
+* Function to activate a survey
+* @global $dbprefix $dbprefix
+* @global $connect $connect
+* @global $clang $clang
+* @param int $postsid
+* @param int $surveyid
+* @return string
+*/
+function activateSurvey($postsid,$surveyid, $scriptname='admin.php')
+{
+ global $dbprefix, $connect, $clang, $databasetype,$databasetabletype, $uploaddir;
+
+ $createsurvey='';
+ $activateoutput='';
+ $createsurveytimings='';
+ $createsurveydirectory=false;
+ //Check for any additional fields for this survey and create necessary fields (token and datestamp)
+ $pquery = "SELECT anonymized, allowregister, datestamp, ipaddr, refurl, savetimings FROM {$dbprefix}surveys WHERE sid={$postsid}";
+ $presult=db_execute_assoc($pquery);
+ $prow=$presult->FetchRow();
+ if ($prow['allowregister'] == "Y")
+ {
+ $surveyallowsregistration="TRUE";
+ }
+ if ($prow['savetimings'] == "Y")
+ {
+ $savetimings="TRUE";
+ }
+
+ //Get list of questions for the base language
+ $fieldmap=createFieldMap($surveyid, 'full', true,false, GetBaseLanguageFromSurveyID($surveyid));// createFieldMap($surveyid, $styl, $force_refresh,$questionid, $sQuestionLanguage);
+ foreach ($fieldmap as $arow) //With each question, create the appropriate field(s)
+ {
+ 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 PRIMARY,\n";
+ break;
+ case "startdate":
+ case "datestamp":
+ $createsurvey .= " T NOTNULL";
+ break;
+ case "submitdate":
+ $createsurvey .= " T";
+ break;
+ case "lastpage":
+ $createsurvey .= " I";
+ break;
+ case "N": //NUMERICAL
+ $createsurvey .= " F";
+ break;
+ case "S": //SHORT TEXT
+ if ($databasetype=='mysql' || $databasetype=='mysqli') {$createsurvey .= " X";}
+ else {$createsurvey .= " C(255)";}
+ break;
+ case "L": //LIST (RADIO)
+ case "!": //LIST (DROPDOWN)
+ case "M": //Multiple choice
+ case "P": //Multiple choice with comment
+ case "O": //DROPDOWN LIST WITH COMMENT
+ if ($arow['aid'] != 'other' && strpos($arow['aid'],'comment')===false && strpos($arow['aid'],'othercomment')===false)
+ {
+ $createsurvey .= " C(5)";
+ }
+ else
+ {
+ $createsurvey .= " X";
+ }
+ break;
+ case "K": // Multiple Numerical
+ $createsurvey .= " F";
+ break;
+ case "U": //Huge text
+ case "Q": //Multiple short text
+ case "T": //LONG TEXT
+ case ";": //Multi Flexi
+ case ":": //Multi Flexi
+ $createsurvey .= " X";
+ break;
+ case "D": //DATE
+ if ($databasetype=='odbc_mssql' || $databasetype=='odbtp' || $databasetype=='mssql_n' || $databasetype=='mssqlnative') {
+ $createsurvey .= " T";
+ }
+ else
+ $createsurvey .= " D";
+ break;
+ case "5": //5 Point Choice
+ case "G": //Gender
+ case "Y": //YesNo
+ case "X": //Boilerplate
+ $createsurvey .= " C(1)";
+ break;
+ case "I": //Language switch
+ $createsurvey .= " C(20)";
+ break;
+ case "|":
+ $createsurveydirectory = true;
+ if (strpos($arow['fieldname'], "_"))
+ $createsurvey .= " I1";
+ else
+ $createsurvey .= " X";
+ break;
+ case "ipaddress":
+ if ($prow['ipaddr'] == "Y")
+ $createsurvey .= " X";
+ break;
+ case "url":
+ if ($prow['refurl'] == "Y")
+ $createsurvey .= " X";
+ break;
+ case "token":
+ if ($prow['anonymized'] == "N")
+ {
+ $createsurvey .= " C(36)";
+ }
+ break;
+ case '*': // Equation
+ $createsurvey .= " X"; // could be anything, from numeric to a long message, so default to text
+ break;
+ default:
+ $createsurvey .= " C(5)";
+ }
+ }
+ $timingsfieldmap = createTimingsFieldMap($surveyid);
+ $createsurveytimings .= '`'.implode("` F DEFAULT '0',\n`",array_keys($timingsfieldmap)) . "` F DEFAULT '0'";
+
+ // 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
+
+ $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';
+ $sqlarraytimings = $dict->CreateTableSQL($tabnametimings, $createsurveytimings, $taboptarray);
+ }
+
+ $execresult=$dict->ExecuteSQLArray($sqlarray,1);
+ if ($execresult==0 || $execresult==1)
+ {
+ $activateoutput .= "
\n" ;
+ }
+ if ($execresult != 0 && $execresult !=1)
+ {
+ $anquery = "SELECT autonumber_start FROM {$dbprefix}surveys WHERE sid={$postsid}";
+ if ($anresult=db_execute_assoc($anquery))
+ {
+ //if there is an autonumber_start field, start auto numbering here
+ while($row=$anresult->FetchRow())
+ {
+ if ($row['autonumber_start'] > 0)
+ {
+ 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
+ {
+ $autonumberquery = "ALTER TABLE {$dbprefix}survey_{$postsid} AUTO_INCREMENT = ".$row['autonumber_start'];
+ $result = @$connect->Execute($autonumberquery);
+
+ }
+ }
+ }
+ if (isset($savetimings) && $savetimings=="TRUE")
+ {
+ $dict->ExecuteSQLArray($sqlarraytimings,1); // create a timings table for this survey
+ }
+ }
+
+ $activateoutput .= "
\n
\n";
+ $lsrcOutput = true;
+ }
+
+ if($scriptname=='lsrc')
+ {
+ if($lsrcOutput==true)
+ return true;
+ else
+ return $activateoutput;
+ }
+ else
+ {
+ 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();
+ }
+}
diff --git a/include/limesurvey/admin/admin.php b/include/limesurvey/admin/admin.php
index 3198e8e5..fdc14f8b 100644
--- a/include/limesurvey/admin/admin.php
+++ b/include/limesurvey/admin/admin.php
@@ -1,31 +1,22 @@
=')&& !(function_exists('domxml_new_doc')))
-{
- require_once(dirname(__FILE__).'/classes/core/domxml-php4-to-php5.php');
-}
require_once(dirname(__FILE__).'/../config-defaults.php');
require_once(dirname(__FILE__).'/../common.php');
@@ -45,6 +36,19 @@ if (!isset($action)) {$action=returnglobal('action');} //Desired action
if (!isset($subaction)) {$subaction=returnglobal('subaction');} //Desired subaction
if (!isset($editedaction)) {$editedaction=returnglobal('editedaction');} // for html editor integration
+if (isset($_SERVER['HTTP_REFERER']))
+{
+ $refurl = $_SERVER['HTTP_REFERER']; //store referer. Can be used for other screens and not just GlobalSettings
+}
+else
+{
+ $refurl = "";
+}
+LimeExpressionManager::SetSurveyId($surveyid); // must be called early - it clears internal cache if a new survey is being used
+if (!is_null($surveyid)) {
+ $sinfo = getSurveyInfo($surveyid);
+ LimeExpressionManager::SetEMLanguage($sinfo['surveyls_language']);
+}
if ($action != 'showprintablesurvey' && substr($action,0,4)!= 'ajax')
{
@@ -85,15 +89,15 @@ if(isset($_SESSION['loginID']))
sendcacheheaders();
/* Check user right actions for validity
- Currently existing user rights:
- `configurator`
- `create_survey`
- `create_user`
- `delete_user`
- `manage_label`
- `manage_template`
- `superadmin`
- */
+ Currently existing user rights:
+ `configurator`
+ `create_survey`
+ `create_user`
+ `delete_user`
+ `manage_label`
+ `manage_template`
+ `superadmin`
+ */
if ($action == 'importsurvey' || $action == 'copysurvey')
{
@@ -102,7 +106,7 @@ if(isset($_SESSION['loginID']))
}
elseif ($action == 'dumpdb')
{
- if ($_SESSION['USER_RIGHT_CONFIGURATOR']==1) {include('dumpdb.php');}
+ if ($_SESSION['USER_RIGHT_SUPERADMIN']==1) {include('dumpdb.php');}
else { include('access_denied.php');}
}
elseif ($action == 'dumplabel')
@@ -149,14 +153,14 @@ if(isset($_SESSION['loginID']))
/* Check survey right actions for validity
- Currently existing survey rights:
- `edit_survey_property`
- `define_questions`
- `browse_response`
- `export`
- `delete_survey`
- `activate_survey`
- */
+ Currently existing survey rights:
+ `edit_survey_property`
+ `define_questions`
+ `browse_response`
+ `export`
+ `delete_survey`
+ `activate_survey`
+ */
if ($action == 'activate')
{
@@ -255,6 +259,25 @@ if(isset($_SESSION['loginID']))
exit;
}
+ elseif ($action == 'showlogicfile')
+ {
+ if(bHasSurveyPermission($surveyid,'translations','read'))
+ {
+ $surveyid = sanitize_int($surveyid);
+ $thissurvey = getSurveyInfo($surveyid);
+ $_POST['sid'] = $surveyid . '|N';
+ $_POST['LEM_PRETTY_PRINT_ALL_SYNTAX'] = 'Y';
+ $_POST['surveyMode'] = 'survey';
+ $_POST['LEMcalledFromAdmin'] = 'Y';
+ $_POST['assessments'] = $thissurvey['assessments'];
+ LimeExpressionManager::SetDirtyFlag();
+ if (isset($_GET['gid'])) { $_POST['gid'] = $_GET['gid']; }
+ if (isset($_GET['qid'])) { $_POST['qid'] = $_GET['qid']; }
+ include($rootdir . '/classes/expressions/test/survey_logic_file.php');
+ exit;
+ }
+ else { include('access_denied.php');}
+ }
elseif ($action=='addgroup' || $action=='editgroup' || $action=='ordergroups')
{
if(bHasSurveyPermission($surveyid,'surveycontent','read')) {$_SESSION['FileManagerContext']="edit:group:$surveyid"; include('questiongrouphandling.php');}
@@ -265,13 +288,13 @@ if(isset($_SESSION['loginID']))
if(bHasSurveyPermission($surveyid,'responses','read')) {include('saved.php');}
else { include('access_denied.php');}
}
-//