Skip to content

Commit

Permalink
Merge pull request #13 from LimeSurvey/master
Browse files Browse the repository at this point in the history
Synch with upstream
  • Loading branch information
apmuthu committed Jul 6, 2014
2 parents 313a6ba + 2bef7de commit 6225e0f
Show file tree
Hide file tree
Showing 32 changed files with 372 additions and 379 deletions.
4 changes: 2 additions & 2 deletions application/controllers/admin/labels.php
Expand Up @@ -372,9 +372,9 @@ public function getAllSets()

foreach($results as $row)
{
$output[$row->lid] = $row->getAttribute('label_name');
$output[$row->lid] = flattenText($row->getAttribute('label_name'));
}

header('Content-type: application/json');
echo ls_json_encode($output);
}

Expand Down
13 changes: 7 additions & 6 deletions application/controllers/admin/participantsaction.php
Expand Up @@ -763,9 +763,9 @@ function getParticipantsResults_json()
*/
function getParticipants_json($search = null)
{
$page = Yii::app()->request->getPost('page');
$limit = Yii::app()->request->getPost('rows');
$limit = isset($limit) ? $limit : 50; //Stop division by zero errors
$page = (int) Yii::app()->request->getPost('page');
$limit = (int) Yii::app()->request->getPost('rows');
$limit = empty($limit) ? $limit : 50; //Stop division by zero errors

$attid = ParticipantAttributeName::model()->getVisibleAttributes();
$participantfields = array('participant_id', 'can_edit', 'firstname', 'lastname', 'email', 'blacklisted', 'survey', 'language', 'owner_uid');
Expand All @@ -774,10 +774,11 @@ function getParticipants_json($search = null)
array_push($participantfields, $value['attribute_id']);
}
$sidx = Yii::app()->request->getPost('sidx');
$sidx = !empty($sidx) ? $sidx : "lastname";
$sidx = in_array($sidx,$participantfields) ? $sidx : "lastname";
$sord = Yii::app()->request->getPost('sord');
$sord = !empty($sord) ? $sord : "asc";
$sord = ($sord=='desc') ? 'desc' : 'asc';
$order = $sidx. " ". $sord;


$aData = new stdClass;

Expand Down Expand Up @@ -834,7 +835,7 @@ function getParticipants_json($search = null)
*/
function getAttribute_json()
{
$iParticipantId = Yii::app()->request->getQuery('pid');
$iParticipantId = strip_tags(Yii::app()->request->getQuery('pid'));
$records = ParticipantAttributeName::model()->getParticipantVisibleAttribute($iParticipantId);
$records = subval_sort($records, "attribute_name", "asc");

Expand Down
5 changes: 5 additions & 0 deletions application/controllers/admin/questions.php
Expand Up @@ -1020,6 +1020,11 @@ public function ajaxlabelsetpicker()
$language=null;
}
$resultdata=getlabelsets($language);
// Label set title really don't need HTML
foreach($resultdata as &$aResult)
{
$aResult = array_map('flattenText', $aResult);
}
header('Content-type: application/json');
echo ls_json_encode($resultdata);
}
Expand Down
26 changes: 26 additions & 0 deletions application/extensions/SettingsWidget/SettingsWidget.php
Expand Up @@ -266,6 +266,17 @@ public function renderHtml($name, array $metaData, $form = null)
);
return $out;
}

public function renderInfo($name, array $metaData, $form = null)
{
$out = '';
$id = $name;
$value = isset($metaData['content']) ? $metaData['content'] : '';
if (is_array($value)) { throw new CException('wrong type' . $name); }
$out .= CHtml::encode($value);

return $out;
}

public function renderInt($name, array $metaData, $form = null)
{
Expand Down Expand Up @@ -313,6 +324,21 @@ public function renderLogo($name, array $metaData)
{
return CHtml::image($metaData['path']);
}

public function renderRadio($name, array $metaData, $form = null)
{
$out = '';
$id = $name;
$value = isset($metaData['current']) ? $metaData['current'] : (isset($metaData['default']) ? $metaData['default'] : null);
if (isset($metaData['label']))
{
$out .= CHtml::label($metaData['label'], $id);
}

$out .= CHtml::radioButtonList($name, $value, $metaData['options']);
return $out;
}

public function renderRelevance($name, array $metaData, $form = null)
{
$out = '';
Expand Down
Expand Up @@ -8,8 +8,7 @@ div.row {
}

.settingswidget input[type^='button'], .settingswidget label{
height: 30px;
line-height: 30px;
line-height: normal;
margin-top: 0px;
}

Expand Down Expand Up @@ -69,6 +68,7 @@ div.row {
padding-right: 10px;
width: 40%;
display: inline-block;
vertical-align: top;
}
.settingswidget .setting > label:after{
content: ':';
Expand Down
126 changes: 58 additions & 68 deletions application/helpers/common_helper.php
Expand Up @@ -3799,7 +3799,6 @@ function questionAttributes($returnByName=false)
'category'=>$clang->gT('Other'),
'sortorder'=>130,
"inputtype"=>"text",
'default'=>'1',
"help"=>$clang->gT("Maximum number of files that the participant can upload for this question"),
"caption"=>$clang->gT("Max number of files"));

Expand Down Expand Up @@ -3883,14 +3882,6 @@ function categorySort($a, $b)
return $result;
}

// make sure the given string (which comes from a POST or GET variable)
// is safe to use in MySQL. This does nothing if gpc_magic_quotes is on.
function autoEscape($str) {
if (!get_magic_quotes_gpc()) {
return addslashes ($str);
}
return $str;
}

// the opposite of the above: takes a POST or GET variable which may or
// may not have been 'auto-quoted', and return the *unquoted* version.
Expand Down Expand Up @@ -5494,10 +5485,10 @@ function getQuotaCompletedCount($iSurveyId, $quotaid)
$result = "N/A";
if(!tableExists("survey_{$iSurveyId}")) // Yii::app()->db->schema->getTable('{{survey_' . $iSurveyId . '}}' are not updated even after Yii::app()->db->schema->refresh();
return $result;
$aColumnName=SurveyDynamic::model($iSurveyId)->getTableSchema()->getColumnNames();
$quota_info = getQuotaInformation($iSurveyId, Survey::model()->findByPk($iSurveyId)->language, $quotaid);
$quota = $quota_info[0];
if (Yii::app()->db->schema->getTable('{{survey_' . $iSurveyId . '}}') &&
count($quota['members']) > 0)
if (count($quota['members']) > 0) // Existence of table already tested
{
// Keep a list of fields for easy reference
$fields_list = array();
Expand All @@ -5507,25 +5498,30 @@ function getQuotaCompletedCount($iSurveyId, $quotaid)

foreach ($quota['members'] as $member)
{
$criteria = new CDbCriteria;
if(in_array($member['fieldname'],$aColumnName))
$fields_list[$member['fieldname']][] = $member['value'];
else
return $result;// We return N/A even for activated survey
}

foreach ($member['fieldnames'] as $fieldname)
$criteria = new CDbCriteria;
$criteria->condition="submitdate IS NOT NULL";
$aParams=array();
foreach ($fields_list as $fieldname=>$aValue)
{
if(count($aValue)==1)
{
if (!in_array($fieldname, $fields_list))
$fields_list[] = $fieldname;

// Yii does not quote column names (duh!) so we have to do it.
$criteria->addColumnCondition(array(Yii::app()->db->quoteColumnName($fieldname) => $member['value']), 'OR');
$criteria->addCondition("{$fieldname} = :{$fieldname}");
$aParams[":{$fieldname}"]=$aValue[0];
}

$fields_query[$fieldname] = $criteria;
else
{
$criteria->addInCondition($fieldname,$aValue); // NO need params : addInCondition bind automatically
}
// We can use directly addInCondition, but don't know what is speediest.
}

$criteria = new CDbCriteria;

foreach ($fields_list as $fieldname)
$criteria->mergeWith($fields_query[$fieldname]);
$criteria->mergeWith(array('condition'=>"submitdate IS NOT NULL"));
if(!empty($aParams))
$criteria->params=$aParams;
$result = SurveyDynamic::model($iSurveyId)->count($criteria);
}

Expand Down Expand Up @@ -5664,7 +5660,6 @@ function includeKeypad()
function getQuotaInformation($surveyid,$language,$iQuotaID='all')
{
Yii::log('getQuotaInformation');
global $clienttoken;
$baselang = Survey::model()->findByPk($surveyid)->language;
$aAttributes=array('sid' => $surveyid);
if ($iQuotaID != 'all')
Expand All @@ -5687,61 +5682,56 @@ function getQuotaInformation($surveyid,$language,$iQuotaID='all')
foreach ($result as $_survey_quotas)
{
$survey_quotas = array_merge($_survey_quotas->attributes,$_survey_quotas->languagesettings[0]->attributes);// We have only one language, then we can use first only
// !!! Doubting this
# foreach ($_survey_quotas->defaultlanguage as $k => $v)
# $survey_quotas[$k] = $v;

array_push($quota_info,array('Name' => $survey_quotas['name'],
'Limit' => $survey_quotas['qlimit'],
'Action' => $survey_quotas['action'],
'Message' => $survey_quotas['quotals_message'],
'Url' => $survey_quotas['quotals_url'],
'UrlDescrip' => $survey_quotas['quotals_urldescrip'],
'AutoloadUrl' => $survey_quotas['autoload_url']));

array_push($quota_info,$survey_quotas);
$result_qe = QuotaMember::model()->findAllByAttributes(array('quota_id'=>$survey_quotas['id']));
$quota_info[$x]['members'] = array();
if (count($result_qe) > 0)
{
foreach ($result_qe as $quota_entry)
{
$quota_entry = $quota_entry->attributes;
$result_quest=Question::model()->findByAttributes(array('qid'=>$quota_entry['qid'], 'language'=>$baselang));
$qtype=$result_quest->attributes;
$oMemberQuestion=Question::model()->findByAttributes(array('qid'=>$quota_entry['qid'], 'language'=>$baselang));
if($oMemberQuestion)
{
$fieldname = "0";

$fieldnames = "0";
if ($oMemberQuestion->type == "I" || $oMemberQuestion->type == "G" || $oMemberQuestion->type == "Y")
{
$fieldname= $surveyid.'X'.$oMemberQuestion->gid.'X'.$quota_entry['qid'];
$value = $quota_entry['code'];
}

if ($qtype['type'] == "I" || $qtype['type'] == "G" || $qtype['type'] == "Y")
{
$fieldnames=array(0 => $surveyid.'X'.$qtype['gid'].'X'.$quota_entry['qid']);
$value = $quota_entry['code'];
}
if($oMemberQuestion->type == "L" || $oMemberQuestion->type == "O" || $oMemberQuestion->type =="!")
{
$fieldname=$surveyid.'X'.$oMemberQuestion->gid.'X'.$quota_entry['qid'];
$value = $quota_entry['code'];
}

if($qtype['type'] == "L" || $qtype['type'] == "O" || $qtype['type'] =="!")
{
$fieldnames=array(0 => $surveyid.'X'.$qtype['gid'].'X'.$quota_entry['qid']);
$value = $quota_entry['code'];
}
if($oMemberQuestion->type == "M")
{
// Need to remove invalid $quota_entry['code']
$fieldname=$surveyid.'X'.$oMemberQuestion->gid.'X'.$quota_entry['qid'].$quota_entry['code'];
$value = "Y";
}

if($qtype['type'] == "M")
{
$fieldnames=array(0 => $surveyid.'X'.$qtype['gid'].'X'.$quota_entry['qid'].$quota_entry['code']);
$value = "Y";
}
if($oMemberQuestion->type == "A" || $oMemberQuestion->type == "B")
{
$temp = explode('-',$quota_entry['code']);
$fieldname=$surveyid.'X'.$oMemberQuestion->gid.'X'.$quota_entry['qid'].$temp[0];
$value = $temp[1];
}

if($qtype['type'] == "A" || $qtype['type'] == "B")
{
$temp = explode('-',$quota_entry['code']);
$fieldnames=array(0 => $surveyid.'X'.$qtype['gid'].'X'.$quota_entry['qid'].$temp[0]);
$value = $temp[1];
array_push($quota_info[$x]['members'],array(
'Title' => $oMemberQuestion->title,
'type' => $oMemberQuestion->type,
'code' => $quota_entry['code'],
'value' => $value,
'qid' => $quota_entry['qid'],
'fieldname' => $fieldname
)
);
}

array_push($quota_info[$x]['members'],array('Title' => $qtype['title'],
'type' => $qtype['type'],
'code' => $quota_entry['code'],
'value' => $value,
'qid' => $quota_entry['qid'],
'fieldnames' => $fieldnames));
}
}
$x++;
Expand Down
19 changes: 3 additions & 16 deletions application/helpers/expressions/em_manager_helper.php
Expand Up @@ -5324,23 +5324,10 @@ private function _UpdateValuesInDatabase($updatedValues, $finished=false)
SavedControl::model()->updateByPk($_SESSION[$this->sessid]['scid'], array('saved_thisstep'=>$thisstep));
}
// Check Quotas
$bQuotaMatched = false;
$aQuotas = checkQuota('return', $this->sid);
if ($aQuotas !== false)
$aQuotas = checkCompletedQuota($this->sid,'return');
if ($aQuotas && !empty($aQuotas))
{
if ($aQuotas != false)
{
foreach ($aQuotas as $aQuota)
{
if (isset($aQuota['status']) && $aQuota['status'] == 'matched') {
$bQuotaMatched = true;
}
}
}
}
if ($bQuotaMatched)
{
checkQuota('enforce',$this->sid); // will create a page and quit.
checkCompletedQuota($this->sid); // will create a page and quit: why not use it directly ?
}
else
{
Expand Down

0 comments on commit 6225e0f

Please sign in to comment.