Skip to content

Commit

Permalink
Port part of frontend helper (I'm getting some weird JS errors curren…
Browse files Browse the repository at this point in the history
…tly, but everything works).

Bugfixes.
  • Loading branch information
aaronschmitz committed Jun 4, 2012
1 parent f038cbf commit a0353d1
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 137 deletions.
10 changes: 5 additions & 5 deletions application/controllers/survey/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -531,10 +531,10 @@ function sendreq(surveyid)
$fieldmap = createFieldMap($surveyid,'short',false,false,$s_lang);
foreach ($fieldmap as $field)
{
if ($field['type'] == "|" && !strpos($field['fieldname'], "_filecount"))
$q = $field['q'];
if ($q->fileUpload() && !strpos($q->fieldname, "_filecount"))
{
if (!isset($qid)) { $qid = array(); }
$qid[] = $field['fieldname'];
$questions[] = $q;
}
}

Expand All @@ -545,9 +545,9 @@ function sendreq(surveyid)
$result = dbExecuteAssoc($query);
foreach($result->readAll() as $row)
{
foreach ($qid as $question)
foreach ($questions as $q)
{
$json = $row[$question];
$json = $row[$q->fieldname];
if ($json == "" || $json == NULL)
continue;

Expand Down
25 changes: 23 additions & 2 deletions application/helpers/common_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1903,6 +1903,19 @@ function validateTemplateDir($templatename)
* @param int $questionid Limit to a certain qid only (for question preview) - default is false
* @return array
*/
function array2Object($array)
{
$object->fieldname=$array['fieldname'];
$object->surveyid=$array['sid'];
$object->gid=$array['gid'];
$object->id=$array['qid'];
$object->aid=$array['aid'];
$object->title=$array['title'];
$object->text=$array['question'];
$object->groupname=$array['group_name'];
return $object;
}

function createFieldMap($surveyid, $style='short', $force_refresh=false, $questionid=false, $sLanguage) {
$sLanguage = sanitize_languagecode($sLanguage);
$surveyid = sanitize_int($surveyid);
Expand All @@ -1919,6 +1932,7 @@ function createFieldMap($surveyid, $style='short', $force_refresh=false, $questi
$fieldmap["id"]['title']="";
$fieldmap["id"]['question']=$clang->gT("Response ID");
$fieldmap["id"]['group_name']="";
$fieldmap["id"]['q']=array2Object($fieldmap["id"]);
}

$fieldmap["submitdate"]=array("fieldname"=>"submitdate", 'type'=>"submitdate", 'sid'=>$surveyid, "gid"=>"", "qid"=>"", "aid"=>"");
Expand All @@ -1927,6 +1941,7 @@ function createFieldMap($surveyid, $style='short', $force_refresh=false, $questi
$fieldmap["submitdate"]['title']="";
$fieldmap["submitdate"]['question']=$clang->gT("Date submitted");
$fieldmap["submitdate"]['group_name']="";
$fieldmap["submitdate"]['q']=array2Object($fieldmap["submitdate"]);
}

$fieldmap["lastpage"]=array("fieldname"=>"lastpage", 'sid'=>$surveyid, 'type'=>"lastpage", "gid"=>"", "qid"=>"", "aid"=>"");
Expand All @@ -1935,6 +1950,7 @@ function createFieldMap($surveyid, $style='short', $force_refresh=false, $questi
$fieldmap["lastpage"]['title']="";
$fieldmap["lastpage"]['question']=$clang->gT("Last page");
$fieldmap["lastpage"]['group_name']="";
$fieldmap["lastpage"]['q']=array2Object($fieldmap["lastpage"]);
}

$fieldmap["startlanguage"]=array("fieldname"=>"startlanguage", 'sid'=>$surveyid, 'type'=>"startlanguage", "gid"=>"", "qid"=>"", "aid"=>"");
Expand All @@ -1943,6 +1959,7 @@ function createFieldMap($surveyid, $style='short', $force_refresh=false, $questi
$fieldmap["startlanguage"]['title']="";
$fieldmap["startlanguage"]['question']=$clang->gT("Start language");
$fieldmap["startlanguage"]['group_name']="";
$fieldmap["startlanguage"]['q']=array2Object($fieldmap["startlanguage"]);
}

//Check for any additional fields for this survey and create necessary fields (token and datestamp and ipaddr)
Expand All @@ -1957,6 +1974,7 @@ function createFieldMap($surveyid, $style='short', $force_refresh=false, $questi
$fieldmap["token"]['question']=$clang->gT("Token");
$fieldmap["token"]['group_name']="";
}
$fieldmap["token"]['q']=array2Object($fieldmap["token"]);
}
if ($prow['datestamp'] == "Y")
{
Expand All @@ -1972,6 +1990,7 @@ function createFieldMap($surveyid, $style='short', $force_refresh=false, $questi
$fieldmap["startdate"]['question']=$clang->gT("Date started");
$fieldmap["startdate"]['group_name']="";
}
$fieldmap["startdate"]['q']=array2Object($fieldmap["startdate"]);

$fieldmap["datestamp"]=array("fieldname"=>"datestamp",
'type'=>"datestamp",
Expand All @@ -1985,7 +2004,7 @@ function createFieldMap($surveyid, $style='short', $force_refresh=false, $questi
$fieldmap["datestamp"]['question']=$clang->gT("Date last action");
$fieldmap["datestamp"]['group_name']="";
}

$fieldmap["datestamp"]['q']=array2Object($fieldmap["datestamp"]);
}
if ($prow['ipaddr'] == "Y")
{
Expand All @@ -2001,6 +2020,7 @@ function createFieldMap($surveyid, $style='short', $force_refresh=false, $questi
$fieldmap["ipaddr"]['question']=$clang->gT("IP address");
$fieldmap["ipaddr"]['group_name']="";
}
$fieldmap["ipaddr"]['q']=array2Object($fieldmap["ipaddr"]);
}
// Add 'refurl' to fieldmap.
if ($prow['refurl'] == "Y")
Expand All @@ -2012,6 +2032,7 @@ function createFieldMap($surveyid, $style='short', $force_refresh=false, $questi
$fieldmap["refurl"]['question']=$clang->gT("Referrer URL");
$fieldmap["refurl"]['group_name']="";
}
$fieldmap["refurl"]['q']=array2Object($fieldmap["refurl"]);
}

// Collect all default values once so don't need separate query for each question with defaults
Expand Down Expand Up @@ -2079,7 +2100,7 @@ function createFieldMap($surveyid, $style='short', $force_refresh=false, $questi
$pq->groupname = $arow->groups['group_name'];
$pq->groupcount = $groupSeq;
$add = $pq->createFieldmap($arow['type']);

if (count($add))
{
$tmp=array_values($add);
Expand Down
44 changes: 26 additions & 18 deletions application/helpers/expressions/em_manager_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4042,25 +4042,33 @@ private function _UpdateValuesInDatabase($updatedValues, $finished=false)
foreach ($updatedValues as $key=>$value)
{
$val = (is_null($value) ? NULL : $value['value']);
$type = (is_null($value) ? NULL : $value['type']);

// Clean up the values to cope with database storage requirements
switch($type)
if(isset($value['q']))
{
case 'D': //DATE
if (trim($val)=='') {
$val=NULL; // since some databases can't store blanks in date fields
}
// otherwise will already be in yyyy-mm-dd format after ProcessCurrentResponses()
break;
case 'N': //NUMERICAL QUESTION TYPE
case 'K': //MULTIPLE NUMERICAL QUESTION
if (trim($val)=='') {
$val=NULL; // since some databases can't store blanks in numerical inputs
}
break;
default:
break;
$q = $value['q'];
$val = $q->prepareValue($val);
}
else //AJS
{
$type = (is_null($value) ? NULL : $value['type']);

// Clean up the values to cope with database storage requirements
switch($type)
{
case 'D': //DATE
if (trim($val)=='') {
$val=NULL; // since some databases can't store blanks in date fields
}
// otherwise will already be in yyyy-mm-dd format after ProcessCurrentResponses()
break;
case 'N': //NUMERICAL QUESTION TYPE
case 'K': //MULTIPLE NUMERICAL QUESTION
if (trim($val)=='') {
$val=NULL; // since some databases can't store blanks in numerical inputs
}
break;
default:
break;
}
}

if (is_null($val))
Expand Down

0 comments on commit a0353d1

Please sign in to comment.