Skip to content

Commit

Permalink
New feature #4652: Keyboard-less operation through JS keypad for tabl…
Browse files Browse the repository at this point in the history
…et PCs or other devices without keyboard - patch provided by Yuri D'Elia (wavexx) - thank you!

Dev Please re-install database because a new field was added to the surveys table

git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey_dev@9558 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
c-schmitz committed Nov 30, 2010
1 parent a05856f commit 40d2864
Show file tree
Hide file tree
Showing 22 changed files with 467 additions and 13 deletions.
2 changes: 2 additions & 0 deletions admin/database.php
Expand Up @@ -1075,6 +1075,7 @@ function get_max_question_order($gid)
'showwelcome'=>$_POST['showwelcome'],
'allowprev'=>$_POST['allowprev'],
'allowjumps'=>$_POST['allowjumps'],
'nokeyboard'=>$_POST['nokeyboard'],
'showprogress'=>$_POST['showprogress'],
'listpublic'=>$_POST['public'],
'htmlemail'=>$_POST['htmlemail'],
Expand Down Expand Up @@ -1366,6 +1367,7 @@ function get_max_question_order($gid)
'showwelcome'=>$_POST['showwelcome'],
'allowprev'=>$_POST['allowprev'],
'allowjumps'=>$_POST['allowjumps'],
'nokeyboard'=>$_POST['nokeyboard'],
'showprogress'=>$_POST['showprogress'],
'printanswers'=>$_POST['printanswers'],
// 'usetokens'=>$_POST['usetokens'],
Expand Down
11 changes: 11 additions & 0 deletions admin/editsurveysettings.php
Expand Up @@ -332,6 +332,17 @@
$editsurvey .= ">".$clang->gT("No")."</option>\n"
. "</select></li>\n";

//No Keyboard
$editsurvey .= "<li><label for='nokeyboard'>".$clang->gT("Keyboard-less operation")."</label>\n"
. "<select id='nokeyboard' name='nokeyboard'>\n"
. "<option value='Y'";
if (!isset($esrow['nokeyboard']) || !$esrow['nokeyboard'] || $esrow['nokeyboard'] == "Y") {$editsurvey .= " selected='selected'";}
$editsurvey .= ">".$clang->gT("Yes")."</option>\n"
. "<option value='N'";
if (isset($esrow['nokeyboard']) && $esrow['nokeyboard'] == "N") {$editsurvey .= " selected='selected'";}
$editsurvey .= ">".$clang->gT("No")."</option>\n"
. "</select></li>\n";

//Show Progress
$editsurvey .= "<li><label for='showprogress'>".$clang->gT("Show progress bar")."</label>\n"
. "<select id='showprogress' name='showprogress'>\n"
Expand Down
1 change: 1 addition & 0 deletions admin/install/create-mssql.sql
Expand Up @@ -291,6 +291,7 @@ CREATE TABLE [prefix_surveys] (
[showprogress] char(1) default 'N',
[allowjumps] char(1) default 'N',
[navigationdelay] tinyint default '0',
[nokeyboard] char(1) default 'N',

PRIMARY KEY ([sid])
)
Expand Down
1 change: 1 addition & 0 deletions admin/install/create-mssqlnative.sql
Expand Up @@ -300,6 +300,7 @@ CREATE TABLE [prefix_surveys] (
[showprogress] char(1) default 'N',
[allowjumps] char(1) default 'N',
[navigationdelay] tinyint default '0',
[nokeyboard] char(1) default 'N',

PRIMARY KEY ([sid])
)
Expand Down
1 change: 1 addition & 0 deletions admin/install/create-mysql.sql
Expand Up @@ -280,6 +280,7 @@ CREATE TABLE `prefix_surveys` (
`showprogress` char(1) default 'Y',
`allowjumps` char(1) default 'N',
`navigationdelay` tinyint(2) default '0',
`nokeyboard` char(1) default 'N',
PRIMARY KEY(`sid`)
) ENGINE=$databasetabletype CHARACTER SET utf8 COLLATE utf8_unicode_ci;

Expand Down
3 changes: 2 additions & 1 deletion admin/install/create-postgres.sql
Expand Up @@ -304,7 +304,8 @@ CREATE TABLE prefix_surveys (
tokenlength smallint DEFAULT '15',
showprogress character(1) DEFAULT 'N'::bpchar,
allowjumps character(1) DEFAULT 'N'::bpchar,
navigationdelay smallint DEFAULT '0'
navigationdelay smallint DEFAULT '0',
nokeyboard character(1) DEFAULT 'N'::bpchar
);

ALTER TABLE ONLY prefix_surveys ADD CONSTRAINT prefix_surveys_pkey PRIMARY KEY (sid);
Expand Down
1 change: 1 addition & 0 deletions admin/update/upgrade-mssql.php
Expand Up @@ -425,6 +425,7 @@ function db_upgrade($oldversion) {
modify_database("", "ALTER TABLE [prefix_surveys] ADD showprogress CHAR(1) NULL default 'Y'"); echo $modifyoutput; flush();
modify_database("", "ALTER TABLE [prefix_surveys] ADD allowjumps CHAR(1) NULL default 'N'"); echo $modifyoutput; flush();
modify_database("", "ALTER TABLE [prefix_surveys] ADD navigationdelay tinyint default '0'"); echo $modifyoutput; flush();
modify_database("", "ALTER TABLE [prefix_surveys] ADD nokeyboard CHAR(1) NULL default 'N'"); echo $modifyoutput; flush();
modify_database("", "CREATE TABLE [prefix_survey_permissions] (
[sid] INT NOT NULL,
[uid] INT NOT NULL,
Expand Down
1 change: 1 addition & 0 deletions admin/update/upgrade-mssqlnative.php
Expand Up @@ -422,6 +422,7 @@ function db_upgrade($oldversion) {
modify_database("", "ALTER TABLE [prefix_surveys] ADD showprogress CHAR(1) NULL default 'Y'"); echo $modifyoutput; flush();
modify_database("", "ALTER TABLE [prefix_surveys] ADD allowjumps CHAR(1) NULL default 'N'"); echo $modifyoutput; flush();
modify_database("", "ALTER TABLE [prefix_surveys] ADD navigationdelay tinyint NOT NULL default '0'"); echo $modifyoutput; flush();
modify_database("", "ALTER TABLE [prefix_surveys] ADD nokeyboard CHAR(1) NULL default 'N'"); echo $modifyoutput; flush();
modify_database("", "CREATE TABLE [prefix_survey_permissions] (
[sid] INT NOT NULL,
[uid] INT NOT NULL,
Expand Down
1 change: 1 addition & 0 deletions admin/update/upgrade-mysql.php
Expand Up @@ -407,6 +407,7 @@ function db_upgrade($oldversion) {
modify_database("", "ALTER TABLE `prefix_surveys` ADD `showprogress` char(1) default 'Y'"); echo $modifyoutput; flush();
modify_database("", "ALTER TABLE `prefix_surveys` ADD `allowjumps` char(1) default 'N'"); echo $modifyoutput; flush();
modify_database("", "ALTER TABLE `prefix_surveys` ADD `navigationdelay` tinyint(2) default '0'"); echo $modifyoutput; flush();
modify_database("", "ALTER TABLE `prefix_surveys` ADD `nokeyboard` char(1) default 'N'"); echo $modifyoutput; flush();
modify_database("", "CREATE TABLE `prefix_survey_permissions` (
`sid` int(10) unsigned NOT NULL,
`uid` int(10) unsigned NOT NULL,
Expand Down
1 change: 1 addition & 0 deletions admin/update/upgrade-postgres.php
Expand Up @@ -249,6 +249,7 @@ function db_upgrade($oldversion) {
modify_database("", "ALTER TABLE prefix_surveys ADD showprogress CHAR(1) NULL default 'Y'"); echo $modifyoutput; flush();
modify_database("", "ALTER TABLE prefix_surveys ADD allowjumps CHAR(1) NULL default 'N'"); echo $modifyoutput; flush();
modify_database("", "ALTER TABLE prefix_surveys ADD navigationdelay smallint NOT NULL default '0'"); echo $modifyoutput; flush();
modify_database("", "ALTER TABLE prefix_surveys ADD nokeyboard char(1) default 'N'"); echo $modifyoutput; flush();
modify_database("", "CREATE TABLE prefix_survey_permissions (
sid integer DEFAULT 0 NOT NULL,
uid integer DEFAULT 0 NOT NULL,
Expand Down
17 changes: 16 additions & 1 deletion common_functions.php
Expand Up @@ -7956,4 +7956,19 @@ function bCheckQuestionForAnswer($q, $aFieldnamesInfoInv)
return $bAnsw;
}

// Closing PHP tag intentionally left out - yes, it is okay
/**
* Include Keypad headers
*/
function vIncludeKeypad()
{
global $js_header_includes, $css_header_includes, $clang;

$js_header_includes[] = '/scripts/jquery/jquery.keypad.min.js';
if ($clang->langcode !== 'en')
{
$js_header_includes[] = '/scripts/jquery/locale/ui.keypad-'.$clang->langcode.'.js';
}
$css_header_includes[] = '/scripts/jquery/css/jquery.keypad.alt.css';
}

// Closing PHP tag intentionally omitted - yes, it is okay
12 changes: 11 additions & 1 deletion index.php
Expand Up @@ -2320,6 +2320,16 @@ function buildsurveysession()
// TOKEN REQUIRED BUT NO TOKEN PROVIDED
if ($tokensexist == 1 && !returnglobal('token'))
{
if ($thissurvey['nokeyboard']=='Y')
{
vIncludeKeypad();
$kpclass = "text-keypad";
}
else
{
$kpclass = "";
}

// DISPLAY REGISTER-PAGE if needed
// DISPLAY CAPTCHA if needed
sendcacheheaders();
Expand All @@ -2341,7 +2351,7 @@ function buildsurveysession()
<form id='tokenform' method='get' action='{$publicurl}/index.php'>
<ul>
<li>
<label for='token'>".$clang->gT("Token")."</label><input class='text' id='token' type='text' name='token' />";
<label for='token'>".$clang->gT("Token")."</label><input class='text $kpclass' id='token' type='text' name='token' />";

echo "<input type='hidden' name='sid' value='".$surveyid."' id='sid' />
<input type='hidden' name='lang' value='".$templang."' id='lang' />";
Expand Down
59 changes: 49 additions & 10 deletions qanda.php
Expand Up @@ -3926,7 +3926,7 @@ function hideBasic() {
// ---------------------------------------------------------------
function do_multipleshorttext($ia)
{
global $dbprefix, $clang;
global $dbprefix, $clang, $thissurvey;

if ($ia[8] == 'Y')
{
Expand Down Expand Up @@ -3980,6 +3980,16 @@ function do_multipleshorttext($ia)
$suffix = '';
}

if ($thissurvey['nokeyboard']=='Y')
{
vIncludeKeypad();
$kpclass = "text-keypad";
}
else
{
$kpclass = "";
}

if ($qidattributes['random_order']==1) {
$ansquery = "SELECT * FROM {$dbprefix}questions WHERE parent_qid=$ia[0] AND language='".$_SESSION['s_lang']."' ORDER BY ".db_random();
}
Expand Down Expand Up @@ -4039,7 +4049,7 @@ function textLimit(field, maxlen) {
$answer_main .= "\t<li>\n"
. "<label for=\"answer$myfname\">{$ansrow['question']}</label>\n"
. "\t<span>\n".$prefix."\n".'
<textarea class="textarea" name="'.$myfname.'" id="answer'.$myfname.'"
<textarea class="textarea '.$kpclass.'" name="'.$myfname.'" id="answer'.$myfname.'"
rows="'.$drows.'" cols="'.$tiwidth.'" onkeyup="textLimit(\'answer'.$ia[1].'\', '.$maxsize.'); '.$checkconditionFunction.'(this.value, this.name, this.type);" '.$numbersonly.'>';

if($label_width < strlen(trim(strip_tags($ansrow['question']))))
Expand Down Expand Up @@ -4068,7 +4078,7 @@ function textLimit(field, maxlen) {
if ($ansrow['question'] == "") {$ansrow['question'] = "&nbsp;";}
$answer_main .= "\t<li>\n"
. "<label for=\"answer$myfname\">{$ansrow['question']}</label>\n"
. "\t<span>\n".$prefix."\n".'<input class="text" type="text" size="'.$tiwidth.'" name="'.$myfname.'" id="answer'.$myfname.'" value="';
. "\t<span>\n".$prefix."\n".'<input class="text '.$kpclass.'" type="text" size="'.$tiwidth.'" name="'.$myfname.'" id="answer'.$myfname.'" value="';

if($label_width < strlen(trim(strip_tags($ansrow['question']))))
{
Expand Down Expand Up @@ -4102,7 +4112,7 @@ function textLimit(field, maxlen) {
// ---------------------------------------------------------------
function do_multiplenumeric($ia)
{
global $dbprefix, $clang, $js_header_includes, $css_header_includes;
global $dbprefix, $clang, $js_header_includes, $css_header_includes, $thissurvey;

if ($ia[8] == 'Y')
{
Expand Down Expand Up @@ -4190,6 +4200,16 @@ function do_multiplenumeric($ia)
$suffix = '';
}

if ($thissurvey['nokeyboard']=='Y')
{
vIncludeKeypad();
$kpclass = "num-keypad";
}
else
{
$kpclass = "";
}

if(!empty($numbersonlyonblur))
{
$numbersonly .= ' onblur="'.implode(';', $numbersonlyonblur).'"';
Expand Down Expand Up @@ -4356,7 +4376,7 @@ function do_multiplenumeric($ia)

if ($slider_layout === false)
{
$answer_main .= "<span class=\"input\">\n\t".$prefix."\n\t<input class=\"text\" type=\"text\" size=\"".$tiwidth.'" name="'.$myfname.'" id="answer'.$myfname.'" value="';
$answer_main .= "<span class=\"input\">\n\t".$prefix."\n\t<input class=\"text $kpclass\" type=\"text\" size=\"".$tiwidth.'" name="'.$myfname.'" id="answer'.$myfname.'" value="';
if (isset($_SESSION[$myfname]))
{
$answer_main .= $_SESSION[$myfname];
Expand Down Expand Up @@ -4587,7 +4607,7 @@ function do_multiplenumeric($ia)
// ---------------------------------------------------------------
function do_numerical($ia)
{
global $clang;
global $clang, $thissurvey;

if ($ia[8] == 'Y')
{
Expand Down Expand Up @@ -4642,8 +4662,18 @@ function do_numerical($ia)
$acomma=".,";
}

if ($thissurvey['nokeyboard']=='Y')
{
vIncludeKeypad();
$kpclass = "num-keypad";
}
else
{
$kpclass = "";
}

// --> START NEW FEATURE - SAVE
$answer = "<p class=\"question\">\n\t$prefix\n\t<input class=\"text\" type=\"text\" size=\"$tiwidth\" name=\"$ia[1]\" "
$answer = "<p class=\"question\">\n\t$prefix\n\t<input class=\"text $kpclass\" type=\"text\" size=\"$tiwidth\" name=\"$ia[1]\" "
. "id=\"answer{$ia[1]}\" value=\"{$_SESSION[$ia[1]]}\" alt=\"".$clang->gT('Answer')."\" onkeypress=\"return goodchars(event,'-0123456789{$acomma}')\" onchange='$checkconditionFunction(this.value, this.name, this.type)'"
. "maxlength=\"{$maxsize}\" />\n\t{$suffix}\n</p>\n";
if ($qidattributes['hide_tip']==0)
Expand All @@ -4664,7 +4694,7 @@ function do_numerical($ia)
// ---------------------------------------------------------------
function do_shortfreetext($ia)
{
global $clang, $js_header_includes;
global $clang, $js_header_includes, $thissurvey;

if ($ia[8] == 'Y')
{
Expand Down Expand Up @@ -4715,6 +4745,15 @@ function do_shortfreetext($ia)
{
$suffix = '';
}
if ($thissurvey['nokeyboard']=='Y')
{
vIncludeKeypad();
$kpclass = "text-keypad";
}
else
{
$kpclass = "";
}
if (trim($qidattributes['display_rows'])!='')
{
//question attribute "display_rows" is set -> we need a textarea to be able to show several rows
Expand Down Expand Up @@ -4747,7 +4786,7 @@ function textLimit(field, maxlen) {
//NEW: textarea instead of input=text field

// --> START NEW FEATURE - SAVE
$answer .= '<textarea class="textarea" name="'.$ia[1].'" id="answer'.$ia[1].'" '
$answer .= '<textarea class="textarea '.$kpclass.'" name="'.$ia[1].'" id="answer'.$ia[1].'" '
.'rows="'.$drows.'" cols="'.$tiwidth.'" onkeyup="textLimit(\'answer'.$ia[1].'\', '.$maxsize.'); '.$checkconditionFunction.'(this.value, this.name, this.type);" '.$numbersonly.'>';
// --> END NEW FEATURE - SAVE

Expand All @@ -4758,7 +4797,7 @@ function textLimit(field, maxlen) {
else
{
//no question attribute set, use common input text field
$answer = "<p class=\"question\">\n\t$prefix\n\t<input class=\"text\" type=\"text\" size=\"$tiwidth\" name=\"$ia[1]\" id=\"answer$ia[1]\" value=\""
$answer = "<p class=\"question\">\n\t$prefix\n\t<input class=\"text $kpclass\" type=\"text\" size=\"$tiwidth\" name=\"$ia[1]\" id=\"answer$ia[1]\" value=\""
.htmlspecialchars($_SESSION[$ia[1]],ENT_QUOTES,'UTF-8')
."\" maxlength=\"$maxsize\" onkeyup=\"$checkconditionFunction(this.value, this.name, this.type)\" $numbersonly />\n\t$suffix\n</p>\n";
}
Expand Down

0 comments on commit 40d2864

Please sign in to comment.