Skip to content

Commit

Permalink
Fixed issue #6025: Error when attemping to create a label set
Browse files Browse the repository at this point in the history
  • Loading branch information
c-schmitz committed Apr 20, 2012
1 parent 347148f commit e0db8a9
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 181 deletions.
6 changes: 2 additions & 4 deletions application/controllers/admin/labels.php
Expand Up @@ -274,6 +274,7 @@ public function view($lid = 0)
$criteria->addCondition('lid = :lid');
$criteria->addCondition('language = :language');
$criteria->params = array(':lid' => $lid, ':language' => $lslanguages[0]);
$criteria->group = 'sortorder';
$maxresult = Label::model()->find($criteria);
$maxsortorder = 1;
if (!empty($maxresult))
Expand Down Expand Up @@ -305,7 +306,7 @@ public function view($lid = 0)
'clang' => $clang,
'lid' => $lid,
'maxsortorder' => $maxsortorder,
'msorow' => $maxresult->attributes,
// 'msorow' => $maxresult->sortorder,
'action' => $action,
);
}
Expand All @@ -324,9 +325,6 @@ public function process()
{
if (Yii::app()->session['USER_RIGHT_SUPERADMIN'] == 1 || Yii::app()->session['USER_RIGHT_MANAGE_LABEL'] == 1)
{
if (isset($_POST['sortorder']))
$postsortorder = sanitize_int($_POST['sortorder']);

if (isset($_POST['method']) && get_magic_quotes_gpc())
$_POST['method'] = stripslashes($_POST['method']);

Expand Down
59 changes: 30 additions & 29 deletions application/helpers/admin/label_helper.php
@@ -1,17 +1,17 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
* LimeSurvey
* Copyright (C) 2007-2011 The LimeSurvey Project Team / Carsten Schmitz
* All rights reserved.
* License: GNU/GPL License v2 or later, see LICENSE.php
* LimeSurvey is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*
* $Id$
*/
* LimeSurvey
* Copyright (C) 2007-2011 The LimeSurvey Project Team / Carsten Schmitz
* All rights reserved.
* License: GNU/GPL License v2 or later, see LICENSE.php
* LimeSurvey is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*
* $Id$
*/

//include_once("login_check.php");
//Security Checked: POST/GET/SESSION/DB/returnGlobal
Expand Down Expand Up @@ -105,18 +105,19 @@ function insertlabelset()
//postlabel_name = dbQuoteAll($postlabel_name,true);
//$postlanguageids = dbQuoteAll($postlanguageids,true);
$data = array(
'label_name' => $postlabel_name,
'languages' => $postlanguageids
'label_name' => $postlabel_name,
'languages' => $postlanguageids
);

//$query = "INSERT INTO ".db_table_name('labelsets')." (label_name,languages) VALUES ({$postlabel_name},{$postlanguageids})";
if (!$result = Yii::app()->db->createCommand()->insert('{{labelsets}}', $data))
$result=Labelsets::model()->insertRecords($data);
if (!$result)
{
safeDie("Inserting the label set failed:<br />".$query."<br />");
}
else
{
return Yii::app()->db->getLastInsertID();
return $result;
}

}
Expand All @@ -136,21 +137,21 @@ function modlabelsetanswers($lid)
if (!isset($_POST['method'])) {
$_POST['method'] = $clang->gT("Save");
}

//unescape single quotes
$labeldata = CHttpRequest::getPost('dataToSend');
$labeldata = str_replace("\'","'",$labeldata);


$data = json_decode($labeldata);

if ($ajax)
$lid = insertlabelset();

if (count(array_unique($data->{'codelist'})) == count($data->{'codelist'}))
{

$query = "DELETE FROM {{labels}} WHERE `lid` = '$lid'";
$query = "DELETE FROM {{labels}} WHERE lid = '$lid'";

$result = Yii::app()->db->createCommand($query)->execute();

Expand All @@ -168,7 +169,7 @@ function modlabelsetanswers($lid)
$strTemp = 'text_'.$lang;
$title = $codeObj->$strTemp;

$p = new CHtmlPurifier();
$p = new CHtmlPurifier();

if (Yii::app()->getConfig('filterxsshtml'))
$title = $p->purify($title);
Expand All @@ -181,18 +182,18 @@ function modlabelsetanswers($lid)
$sort_order = $index;

$insertdata = array(
'lid' => $lid,
'code' => $actualcode,
'title' => $title,
'sortorder' => $sort_order,
'assessment_value' => $assessmentvalue,
'language' => $lang
'lid' => $lid,
'code' => $actualcode,
'title' => $title,
'sortorder' => $sort_order,
'assessment_value' => $assessmentvalue,
'language' => $lang
);

//$query = "INSERT INTO ".db_table_name('labels')." (`lid`,`code`,`title`,`sortorder`, `assessment_value`, `language`)
// VALUES('$lid',$actualcode,$title,$sort_order,$assessmentvalue,$lang)";

$result = Yii::app()->db->createCommand()->insert('{{labels}}', $insertdata);
$result = Yii::app()->db->createCommand()->insert('{{labels}}', $insertdata);
}
}

Expand Down
6 changes: 5 additions & 1 deletion application/models/Labelsets.php
Expand Up @@ -75,6 +75,10 @@ function insertRecords($data)
$lblset = new self;
foreach ($data as $k => $v)
$lblset->$k = $v;
$lblset->save();
if ($lblset->save())
{
return $lblset->lid;
}
return false;
}
}

0 comments on commit e0db8a9

Please sign in to comment.