\n" . "\t\n" . "\t\t\n" . "\t\t\t\n" . "\t\t\t\n" . "\t\t\t\t\n" ."\n" ."\t\n" ."\t\n" ."\n" ."\t\n"; if ($action!='labels' || isset($lid)) {$labelsoutput.="
\n";} //NEW SET if ($action == "newlabelset" || $action == "editlabelset") { if ($action == "editlabelset") { $query = "SELECT label_name,".db_table_name('labelsets').".lid, languages FROM ".db_table_name('labelsets')." WHERE lid=".$lid; $result=db_execute_assoc($query); while ($row=$result->FetchRow()) {$lbname=$row['label_name']; $lblid=$row['lid']; $langids=$row['languages'];} } $labelsoutput.= "
gT("Error: You have to enter a name for this label set.","js")."')\">\n" ."\n" ."\t\n" ."
\n" ."\n"; if ($action == "newlabelset") {$labelsoutput.= $clang->gT("Create or Import New Label Set"); $langids="en"; $tabitem=$clang->gT("Create New Label Set");} else {$labelsoutput.= $clang->gT("Edit Label Set"); $tabitem=$clang->gT("Edit Label Set");} $langidsarray=explode(" ",trim($langids)); //Make an array of it $labelsoutput.= "\n\t
\n"; $labelsoutput.= "
\n"; $labelsoutput.= "

".$tabitem."

\n"; $labelsoutput.= "\n" ."\t\n" ."\n" ."\n" ."\t\n" // Additional languages listbox . "\t\n" . "" . "\n" // Available languages listbox . "\n" ."\n" ."\n" ."\t\n"; $labelsoutput.= "
".$clang->gT("Set Name").":\n" ."\t" ."\t\n" ."
".$clang->gT("Languages").":gT("Add")."\" onclick=\"DoAdd()\" id=\"AddBtn\" />
gT("Remove")." >>\" onclick=\"DoRemove(1,'".$clang->gT("You cannot remove this item since you need at least one language in a labelset.", "js")."')\" id=\"RemoveBtn\" />
\n" ."
\n" ."\n"; if ($action == "editlabelset") { $labelsoutput.= "\n"; } $labelsoutput.= "
\n"; if ($action == "newlabelset") { $labelsoutput.= "

".$clang->gT("Import Label Set")."

\n"; $labelsoutput.= "" ."
\n" ."\n" ."\t\n" ."\n" ."\t\n" ."\t\n" ."\n" ."\n" ."\n" ."\n" ."\t\n" ."\t
\n" .$clang->gT("Import Label Set")."\n" ."
" .$clang->gT("Select CSV File:")."" ."\t
" .$clang->gT("Convert Resources links ?")."\n" ."
\n" ."\t
\n"; } $labelsoutput.= "
\n"; } //SET SELECTED if (isset($lid) && ($action != "editlabelset") && $lid) { //CHECK TO SEE IF ANY ACTIVE SURVEYS ARE USING THIS LABELSET (Don't let it be changed if this is the case) $query = "SELECT ".db_table_name('surveys_languagesettings').".surveyls_title FROM ".db_table_name('questions').", ".db_table_name('surveys')." , ".db_table_name('surveys_languagesettings')." WHERE ".db_table_name('questions').".sid=".db_table_name('surveys').".sid AND ".db_table_name('surveys').".sid=".db_table_name('surveys_languagesettings').".surveyls_survey_id AND ".db_table_name('questions').".lid=$lid AND ".db_table_name('surveys').".active='Y'"; $result = db_execute_assoc($query); $activeuse=$result->RecordCount(); while ($row=$result->FetchRow()) {$activesurveys[]=$row['surveyls_title'];} //NOW ALSO COUNT UP HOW MANY QUESTIONS ARE USING THIS LABELSET, TO GIVE WARNING ABOUT CHANGES //$query = "SELECT * FROM ".db_table_name('questions')." WHERE type IN ('F','H','Z','W') AND lid='$lid' GROUP BY qid"; //NOTE: OK, we're back to "what the hell is Tom up to?". SQL Server complains if the selected columns aren't either aggregated // part of the GROUP BY clause. This should work for both databases. $query = "SELECT qid, sid, gid FROM ".db_table_name('questions')." WHERE type IN ('F','H','Z','W') AND lid='$lid' GROUP BY qid, sid, gid"; $result = db_execute_assoc($query); $totaluse=$result->RecordCount(); while($row=$result->FetchRow()) { $qidarray[]=array("url"=>"$scriptname?sid=".$row['sid']."&gid=".$row['gid']."&qid=".$row['qid'], "title"=>"QID: ".$row['qid']); } //NOW GET THE ANSWERS AND DISPLAY THEM $query = "SELECT * FROM ".db_table_name('labelsets')." WHERE lid=$lid"; $result = db_execute_assoc($query); while ($row=$result->FetchRow()) { $labelsoutput.= "\t\n" ."\n" ."\n" ."\t\n" ."\n" ."\t\n"; } //LABEL ANSWERS - SHOW THE MASK FOR EDITING THE LABELS $qulabelset = "SELECT * FROM ".db_table_name('labelsets')." WHERE lid=$lid"; $rslabelset = db_execute_assoc($qulabelset) or safe_die($connect->ErrorMsg()); $rwlabelset=$rslabelset->FetchRow(); $lslanguages=explode(" ", trim($rwlabelset['languages'])); $labelsoutput.= PrepareEditorScript("editlabel"); $labelsoutput.= "\t\n" ."\n" ."\t\n" ."\n" ."\t\n"; if ($totaluse > 0 && $activeuse == 0) //If there are surveys using this labelset, but none are active warn about modifying { $labelsoutput.= "\n" ."\t\n" ."\n"; } $labelsoutput.= "\t
\n" .$clang->gT("Labels") ."\t
\n" ."
\n" ."\n" ."\n" ."\n"; $labelsoutput.= "
"; $first=true; $sortorderids=''; $codeids=''; foreach ($lslanguages as $lslanguage) { $position=0; $query = "SELECT * FROM ".db_table_name('labels')." WHERE lid=$lid and language='$lslanguage' ORDER BY sortorder, code"; $result = db_execute_assoc($query) or safe_die($connect->ErrorMsg()); $labelcount = $result->RecordCount(); $labelsoutput.= "
" ."

".getLanguageNameFromCode($lslanguage)."

" ."\t\n" ."" ."\n" ."\t\n" // ."\t\n" // ."\t\n" // ."\t\n" ."" .""; while ($row=$result->FetchRow()) { $sortorderids=$sortorderids.' '.$row['language'].'_'.$row['sortorder']; if ($first) {$codeids=$codeids.' '.$row['sortorder'];} $labelsoutput.= "\n" ."\t\n" ."\t\n" ."\t\n"; $position++; } if ($labelcount>0) { $labelsoutput.= "\t\n"; } $position=sprintf("%05d", $position); if ($activeuse == 0 && $first) { $labelsoutput.= "\n" ."\t\n" ."\t\n" ."\t\n" ."\n"; } elseif ($activeuse == 0 && !$first) { $labelsoutput.= "\n" ."\t\n" ."\n"; } else { $labelsoutput .= "\n" ."\t\n" ."\n"; } $first=false; $labelsoutput.="
\n" .$clang->gT("Code") ."\t\n" ."\t\n" .$clang->gT("Title") ."\t\n" ."\t\n" .$clang->gT("Action") ."\t\n" ."\t\n" .$clang->gT("Order") ."\t
\n"; if ($activeuse > 0) { $labelsoutput.= "\t{$row['code']}" ."\n"; } elseif (!$first) { $labelsoutput.= "\t{$row['code']}"; } else { $labelsoutput.= "\t\n"; $labelsoutput.= "\t\n"; } $labelsoutput.= "\t\n" ."\t\n" . getEditor("editlabel", "title_{$row['language']}_{$row['sortorder']}", "[".$clang->gT("Label:", "js")."](".$row['language'].")",'','','',$action) ."\t\n"; if ($activeuse == 0) { $labelsoutput.= "\t\n"; } $labelsoutput.= "\t\n"; if ($position > 0) { $labelsoutput.= "\t\n"; }; if ($position < $labelcount-1) { // Fill the sortorder hiddenfield so we now what field is moved down $labelsoutput.= "\t\n"; } $labelsoutput.= "\t
" ."

" ."".$clang->gT("New label").": \n" ."\t\n" ."\t\n" . getEditor("addlabel", "inserttitle", "[".$clang->gT("Label:", "js")."](".$lslanguage.")",'','','',$action) ."\t\n" ."\t\n" ."\t\n" ."gT('Fix Order')."\">\n" ."\n" ."\t
\n" ."" .$clang->gT("Warning").": ".$clang->gT("Inserting New labels must be done on the first language folder.")."\n" ."\t
\n" ."" .$clang->gT("Warning").": ".$clang->gT("You cannot change codes, add or delete entries in this label set because it is being used by an active survey.")."
\n"; if ($totaluse > 0) { foreach ($qidarray as $qd) {$labelsoutput.= "[".$qd['title']."] ";} } $labelsoutput .= "\t
\n"; $labelsoutput.=("
"); } // Let's close the form for First Languages TABs $labelsoutput.= "\n"; $labelsoutput.= "\n"; $labelsoutput.= ""; // End First TABs form // TAB for resources management $ZIPimportAction = " onclick='if (validatefilename(this.form,\"".$clang->gT('Please select a file to import!','js')."\")) {this.form.submit();}'"; if (!function_exists("zip_open")) { $ZIPimportAction = " onclick='alert(\"".$clang->gT("zip library not supported by PHP, Import ZIP Disabled","js")."\");'"; } $disabledIfNoResources = ''; if (hasResources($lid,'label') === false) { $disabledIfNoResources = " disabled='disabled'"; } $labelsoutput.= "

".$clang->gT("Uploaded Resources Management")."

\n" . "\t
\n" . "\t\n" . "\t\n" . "\t\n" . "\t" . "\t\t\n" . "\t\t\n" . "\t\t \n" . "\t\t\n" . "\t\t\n" . "\t\t\n" . "\t
\n" . "\t\tgT("Browse Uploaded Resources")."\" $disabledIfNoResources>
gT("Export Resources As ZIP Archive")."\" $disabledIfNoResources>
".$clang->gT("Select ZIP File:")."
\n"; // End TAB Uploaded Resources Management $labelsoutput.= "
"; $labelsoutput.= "
"; // End Tab pane // Here starts the hidden Fix Sort order form $labelsoutput.= "
" ."
" ."\n" ."\t" // ."\n" ."
" ."\t\n" ."\t\n" ."
\n" ."" .$clang->gT("Warning").": ".$clang->gT("Some surveys currently use this label set. Modifying the codes, adding or deleting entries to this label set may produce undesired results in other surveys.")."
"; foreach ($qidarray as $qd) {$labelsoutput.= "[".$qd['title']."] ";} $labelsoutput.= "
\n" ."\t
\n"; } $labelsoutput.=""; } else { $action = "labels"; include("access_denied.php"); include("admin.php"); } //************************FUNCTIONS******************************** function updateset($lid) { global $dbprefix, $connect, $labelsoutput, $databasetype; // Get added and deleted languagesid arrays if (isset($_POST['languageids'])) { $postlanguageids=sanitize_languagecodeS($_POST['languageids']); } if (isset($_POST['label_name'])) { $postlabel_name=sanitize_labelname($_POST['label_name']); } $newlanidarray=explode(" ",trim($postlanguageids)); $postlanguageids = db_quoteall($postlanguageids,true); $postlabel_name = db_quoteall($postlabel_name,true); $oldlangidsarray=array(); $query = "SELECT languages FROM ".db_table_name('labelsets')." WHERE lid=".$lid; $result=db_execute_assoc($query); if ($result) { while ($row=$result->FetchRow()) {$oldlangids=$row['languages'];} $oldlangidsarray=explode(" ",trim($oldlangids)); } $addlangidsarray=array_diff($newlanidarray,$oldlangidsarray); $dellangidsarray=array_diff($oldlangidsarray,$newlanidarray); // If new languages are added, create labels' codes and sortorder for the new languages $query = "SELECT code,sortorder FROM ".db_table_name('labels')." WHERE lid=".$lid." GROUP BY code,sortorder"; $result=db_execute_assoc($query); if ($result) { while ($row=$result->FetchRow()) {$oldcodesarray[$row['code']]=$row['sortorder'];} } if (isset($oldcodesarray) && count($oldcodesarray) > 0 ) { foreach ($addlangidsarray as $addedlangid) { foreach ($oldcodesarray as $oldcode => $oldsortorder) { $sqlvalues[]= " ($lid, '$oldcode', '$oldsortorder', '$addedlangid')"; } } } if (isset($sqlvalues)) { if ($databasetype=='odbc_mssql') {@$connect->Execute("SET IDENTITY_INSERT ".db_table_name('labels')." ON");} foreach ($sqlvalues as $sqlline) { $query = "INSERT INTO ".db_table_name('labels')." (lid,code,sortorder,language) VALUES ".($sqlline); $result=db_execute_assoc($query); if (!$result) { $labelsoutput.= "\n"; } } if ($databasetype=='odbc_mssql') {@$connect->Execute("SET IDENTITY_INSERT ".db_table_name('labels')." OFF");} } // If languages are removed, delete labels for these languages $sqlwherelang=''; foreach ($dellangidsarray as $dellangid) { $sqlwherelang .= " OR language='".$dellangid."'"; } if ($sqlwherelang) { $query = "DELETE FROM ".db_table_name('labels')." WHERE lid=$lid AND (".trim($sqlwherelang, ' OR').")"; $result=db_execute_assoc($query); if (!$result) { $labelsoutput.= "\n"; } } // Update the labelset itself $query = "UPDATE ".db_table_name('labelsets')." SET label_name={$postlabel_name}, languages={$postlanguageids} WHERE lid=$lid"; if (!$result = $connect->Execute($query)) { $labelsoutput.= "\n"; } } function deletelabelset($lid) // language proof { global $dbprefix, $connect, $clang, $labelsoutput; //CHECK THAT THERE ARE NO QUESTIONS THAT RELY ON THIS LID $query = "SELECT qid FROM ".db_table_name('questions')." WHERE type IN ('F','H','W','Z') AND lid=$lid"; $result = $connect->Execute($query) or safe_die("Error"); $count = $result->RecordCount(); if ($count > 0) { $labelsoutput.= "\n"; return false; } else //There are no dependencies. We can delete this safely { $query = "DELETE FROM ".db_table_name('labels')." WHERE lid=$lid"; $result = $connect->Execute($query); $query = "DELETE FROM ".db_table_name('labelsets')." WHERE lid=$lid"; $result = $connect->Execute($query); return true; } } function insertlabelset() { global $dbprefix, $connect, $clang, $labelsoutput; // $labelsoutput.= $_POST['languageids']; For debug purposes if (isset($_POST['languageids'])) { $postlanguageids=sanitize_languagecodeS($_POST['languageids']); } if (isset($_POST['label_name'])) { $postlabel_name=sanitize_labelname($_POST['label_name']); } $postlabel_name = db_quoteall($postlabel_name,true); $postlanguageids = db_quoteall($postlanguageids,true); $query = "INSERT INTO ".db_table_name('labelsets')." (label_name,languages) VALUES ({$postlabel_name},{$postlanguageids})"; if (!$result = $connect->Execute($query)) { $labelsoutput.= "\n"; } else { return $connect->Insert_ID(db_table_name_nq('labelsets'),"lid"); } } function modlabelsetanswers($lid) { global $dbprefix, $connect, $clang, $labelsoutput, $databasetype, $filterxsshtml,$postsortorder; $qulabelset = "SELECT * FROM ".db_table_name('labelsets')." WHERE lid='$lid'"; $rslabelset = db_execute_assoc($qulabelset) or safe_die($connect->ErrorMsg()); $rwlabelset=$rslabelset->FetchRow(); $lslanguages=explode(" ", trim($rwlabelset['languages'])); if (!isset($_POST['method'])) { $_POST['method'] = $clang->gT("Save"); } switch($_POST['method']) { case $clang->gT("Add new label", "unescaped"): if (isset($_POST['insertcode']) && $_POST['insertcode']!='') { $_POST['insertcode'] = db_quoteall($_POST['insertcode'],true); // check that the code doesn't exist yet $query = "SELECT code FROM ".db_table_name('labels')." WHERE lid='$lid' AND code=".$_POST['insertcode']; $result = $connect->Execute($query); $codeoccurences=$result->RecordCount(); if ($codeoccurences == 0) { $query = "select max(sortorder) as maxorder from ".db_table_name('labels')." where lid='$lid'"; $result = $connect->Execute($query); $newsortorder=sprintf("%05d", $result->fields['maxorder']+1); if ($filterxsshtml) { require_once("../classes/inputfilter/class.inputfilter_clean.php"); $myFilter = new InputFilter('','',1,1,1); $_POST['inserttitle']=$myFilter->process($_POST['inserttitle']); } else { $_POST['inserttitle'] = html_entity_decode_php4($_POST['inserttitle'], ENT_QUOTES, "UTF-8"); } // Fix bug with FCKEditor saving strange BR types $_POST['inserttitle']=str_replace('
','',$_POST['inserttitle']); if ($_POST['inserttitle'] == "
") { $_POST['inserttitle']=''; } $_POST['inserttitle'] = db_quoteall($_POST['inserttitle'],true); foreach ($lslanguages as $lslanguage) { if ($databasetype=='odbc_mssql') {@$connect->Execute("SET IDENTITY_INSERT ".db_table_name('labels')." ON");} $query = "INSERT INTO ".db_table_name('labels')." (lid, code, title, sortorder,language) VALUES ($lid, {$_POST['insertcode']}, {$_POST['inserttitle']}, '$newsortorder','$lslanguage')"; if (!$result = $connect->Execute($query)) { $labelsoutput.= "\n"; } if ($databasetype=='odbc_mssql') {@$connect->Execute("SET IDENTITY_INSERT ".db_table_name('labels')." OFF");} } } else { $labelsoutput.= "\n"; } } break; // Save all labels with one button case $clang->gT("Save All", "unescaped"): //Determine autoids by evaluating the hidden field $sortorderids=explode(' ', trim($_POST['sortorderids'])); $codeids=explode(' ', trim($_POST['codeids'])); $count=0; // Quote each code_codeid first foreach ($codeids as $codeid) { $_POST['code_'.$codeid] = db_quoteall($_POST['code_'.$codeid],true); $_POST['oldcode_'.$codeid] = db_quoteall($_POST['oldcode_'.$codeid],true); // Get the code values to check for duplicates $codevalues[] = $_POST['code_'.$codeid]; } // Check that there is no code duplicate if (count(array_unique($codevalues)) == count($codevalues)) { if ($filterxsshtml) { require_once("../classes/inputfilter/class.inputfilter_clean.php"); $myFilter = new InputFilter('','',1,1,1); } foreach ($sortorderids as $sortorderid) { $langid=substr($sortorderid,0,strrpos($sortorderid,'_')); $orderid=substr($sortorderid,strrpos($sortorderid,'_')+1,20); if ($filterxsshtml) { $_POST['title_'.$sortorderid]=$myFilter->process($_POST['title_'.$sortorderid]); } else { $_POST['title_'.$sortorderid] = html_entity_decode_php4($_POST['title_'.$sortorderid], ENT_QUOTES, "UTF-8"); } // Fix bug with FCKEditor saving strange BR types $_POST['title_'.$sortorderid]=str_replace('
','',$_POST['title_'.$sortorderid]); if ($_POST['title_'.$sortorderid] == "
") { $_POST['title_'.$sortorderid]=''; } $_POST['title_'.$sortorderid] = db_quoteall($_POST['title_'.$sortorderid],true); $query = "UPDATE ".db_table_name('labels')." SET code=".$_POST['code_'.$codeids[$count]].", title={$_POST['title_'.$sortorderid]} WHERE lid=$lid AND sortorder=$orderid AND language='$langid'"; if (!$result = $connect->Execute($query)) // if update didn't work we assume the label does not exist and insert it { $query = "insert into ".db_table_name('labels')." (code,title,lid,sortorder,language) VALUES (".$_POST['code_'.$codeids[$count]].", {$_POST['title_'.$sortorderid]}, $lid , $orderid , '$langid')"; if (!$result = $connect->Execute($query)) { $labelsoutput.= "\n"; } } update_labelcodes_in_conditions($lid,$_POST['oldcode_'.$codeids[$count]],$_POST['code_'.$codeids[$count]]); $count++; if ($count>count($codeids)-1) {$count=0;} } } else { $labelsoutput.= "\n"; } break; // Pressing the Up button case $clang->gT("Up", "unescaped"): $newsortorder=$postsortorder-1; $oldsortorder=$postsortorder; $cdquery = "UPDATE ".db_table_name('labels')." SET sortorder=-1 WHERE lid=$lid AND sortorder=$newsortorder"; $cdresult=$connect->Execute($cdquery) or safe_die($connect->ErrorMsg()); $cdquery = "UPDATE ".db_table_name('labels')." SET sortorder=$newsortorder WHERE lid=$lid AND sortorder=$oldsortorder"; $cdresult=$connect->Execute($cdquery) or safe_die($connect->ErrorMsg()); $cdquery = "UPDATE ".db_table_name('labels')." SET sortorder='$oldsortorder' WHERE lid=$lid AND sortorder=-1"; $cdresult=$connect->Execute($cdquery) or safe_die($connect->ErrorMsg()); break; // Pressing the Down button case $clang->gT("Dn", "unescaped"): $newsortorder=$postsortorder+1; $oldsortorder=$postsortorder; $cdquery = "UPDATE ".db_table_name('labels')." SET sortorder=-1 WHERE lid=$lid AND sortorder='$newsortorder'"; $cdresult=$connect->Execute($cdquery) or safe_die($connect->ErrorMsg()); $cdquery = "UPDATE ".db_table_name('labels')." SET sortorder='$newsortorder' WHERE lid=$lid AND sortorder=$oldsortorder"; $cdresult=$connect->Execute($cdquery) or safe_die($connect->ErrorMsg()); $cdquery = "UPDATE ".db_table_name('labels')." SET sortorder=$oldsortorder WHERE lid=$lid AND sortorder=-1"; $cdresult=$connect->Execute($cdquery) or safe_die($connect->ErrorMsg()); break; // Delete Button case $clang->gT("Del", "unescaped"): $query = "DELETE FROM ".db_table_name('labels')." WHERE lid=$lid AND sortorder='{$postsortorder}'"; if (!$result = $connect->Execute($query)) { $labelsoutput.= "\n"; } break; // Fix Sortorder button case $clang->gT("Fix Sort", "unescaped"): fixorder($lid); break; } } function fixorder($lid) //Function rewrites the sortorder for a group of answers { global $dbprefix, $connect, $labelsoutput; $qulabelset = "SELECT * FROM ".db_table_name('labelsets')." WHERE lid=$lid"; $rslabelset = db_execute_assoc($qulabelset) or safe_die($connect->ErrorMsg()); $rwlabelset=$rslabelset->FetchRow(); $lslanguages=explode(" ", trim($rwlabelset['languages'])); foreach ($lslanguages as $lslanguage) { $query = "SELECT lid, code, title FROM ".db_table_name('labels')." WHERE lid=? and language='$lslanguage' ORDER BY sortorder, code"; $result = db_execute_num($query, array($lid)); $position=0; while ($row=$result->FetchRow()) { $position=sprintf("%05d", $position); $query2="UPDATE ".db_table_name('labels')." SET sortorder='$position' WHERE lid=? AND code=? AND title=? AND language='$lslanguage' "; $result2=$connect->Execute($query2, array ($row[0], $row[1], $row[2])) or safe_die ("Couldn't update sortorder
$query2
".$connect->ErrorMsg()); $position++; } } } function update_labelcodes_in_conditions($labelid,$oldcode,$newcode) { global $dbprefix, $connect; if ($oldcode != $newcode) { // If question type is not dual scale, then update only if: value is old label code AND question uses the modified label // If question is Dualscale then check if it uses the modified label as lid or lid1 and check $query = "UPDATE ".db_table_name('conditions')." AS c INNER JOIN ".db_table_name('questions')." AS q ON c.cqid=q.qid SET value=$newcode WHERE c.value=$oldcode AND ( (q.type <> 1 AND q.lid=$labelid) OR (q.type = 1 AND q.lid=$labelid AND c.cfieldname like '%#0') OR (q.type = 1 AND q.lid1=$labelid AND c.cfieldname like '%#1') )"; $result=$connect->Execute($query) or safe_die($connect->ErrorMsg()); //error_log("TIBO=$query"); } } ?>