From 9e2b514e82b03a042ad47bc49a71353c4a096bcd Mon Sep 17 00:00:00 2001 From: Carsten Schmitz Date: Fri, 23 Mar 2012 10:24:56 +0100 Subject: [PATCH] Fixed issue #5944: Cannot grant "Survey security" permission to another user --- admin/html.php | 4639 ++++++++++++++++++++++++------------------------ 1 file changed, 2324 insertions(+), 2315 deletions(-) diff --git a/admin/html.php b/admin/html.php index 34461eb5331..87edd4a6f5f 100644 --- a/admin/html.php +++ b/admin/html.php @@ -1,2315 +1,2324 @@ -" - . "".$clang->gT("Your personal settings")."\n" - . "\n" - . "
\n" - . "
" - . "
    \n"; - - $sSavedLanguage=$connect->GetOne("select lang from ".db_table_name('users')." where uid={$_SESSION['loginID']}"); - - // Current language - $cssummary .= "
  • \n" - . "\n" - . "\n" - . "
  • \n"; - - // Current htmleditormode - $cssummary .= "
  • \n" - . "\n" - . "\n" - . "
  • \n"; - - // Current questionselectormode - $cssummary .= "
  • \n" - . "\n" - . "\n" - . "
  • \n"; - - // Current templateeditormode - $cssummary .= "
  • \n" - . "\n" - . "\n" - . "
  • \n"; - - // Date format - $cssummary .= "
  • \n" - . "\n" - . "\n" - . "
  • \n" - . "
\n" - . "

"; -} - - - -if (isset($surveyid) && $surveyid && -$action!='dataentry' && $action!='browse' && $action!='exportspss' && -$action!='statistics' && $action!='importoldresponses' && $action!='exportr' && -$action!='vvimport' && $action!='vvexport' && $action!='exportresults') -{ - if(bHasSurveyPermission($surveyid,'survey','read')) - { - $js_admin_includes[]='../scripts/jquery/jquery.coookie.js'; - $js_admin_includes[]='../scripts/jquery/superfish.js'; - $js_admin_includes[]='../scripts/jquery/hoverIntent.js'; - $js_admin_includes[]='scripts/surveytoolbar.js'; - $css_admin_includes[]= $homeurl."/styles/default/superfish.css"; - $baselang = GetBaseLanguageFromSurveyID($surveyid); - $sumquery3 = "SELECT * FROM ".db_table_name('questions')." WHERE sid={$surveyid} AND parent_qid=0 AND language='".$baselang."'"; //Getting a count of questions for this survey - $sumresult3 = $connect->Execute($sumquery3); //Checked - $sumcount3 = $sumresult3->RecordCount(); - $sumquery6 = "SELECT count(*) FROM ".db_table_name('conditions')." as c, ".db_table_name('questions')." as q WHERE c.qid = q.qid AND q.sid=$surveyid"; //Getting a count of conditions for this survey - $sumcount6 = $connect->GetOne($sumquery6); //Checked - $sumquery2 = "SELECT * FROM ".db_table_name('groups')." WHERE sid={$surveyid} AND language='".$baselang."'"; //Getting a count of groups for this survey - $sumresult2 = $connect->Execute($sumquery2); //Checked - $sumcount2 = $sumresult2->RecordCount(); - $sumquery1 = "SELECT * FROM ".db_table_name('surveys')." inner join ".db_table_name('surveys_languagesettings')." on (surveyls_survey_id=sid and surveyls_language=language) WHERE sid=$surveyid"; //Getting data for this survey - $sumresult1 = db_select_limit_assoc($sumquery1, 1) ; //Checked - if ($sumresult1->RecordCount()==0){die('Invalid survey id');} // if surveyid is invalid then die to prevent errors at a later time - // Output starts here... - $surveysummary = ""; - - $surveyinfo = $sumresult1->FetchRow(); - - $surveyinfo = array_map('FlattenText', $surveyinfo); - //$surveyinfo = array_map('htmlspecialchars', $surveyinfo); - $activated = $surveyinfo['active']; - - //////////////////////////////////////////////////////////////////////// - // SURVEY MENU BAR - //////////////////////////////////////////////////////////////////////// - - $surveysummary .= "" //"\n" - . "\n" - . "\n"; - - //SURVEY SUMMARY - if ($gid || $qid || $action=="deactivate"|| $action=="activate" || $action=="surveysecurity" - || $action=="surveyrights" || $action=="addsurveysecurity" || $action=="addusergroupsurveysecurity" - || $action=="setsurveysecurity" || $action=="setusergroupsurveysecurity" || $action=="delsurveysecurity" - || $action=="editsurveysettings"|| $action=="editsurveylocalesettings" || $action=="updatesurveysettingsandeditlocalesettings" || $action=="addgroup" || $action=="importgroup" - || $action=="ordergroups" || $action=="deletesurvey" || $action=="resetsurveylogic" - || $action=="importsurveyresources" || $action=="translate" || $action=="emailtemplates" - || $action=="exportstructure" || $action=="quotas" || $action=="copysurvey") {$showstyle="style='display: none'";} - if (!isset($showstyle)) {$showstyle="";} - $aAdditionalLanguages = GetAdditionalLanguagesFromSurveyID($surveyid); - $surveysummary .= "\n" - . "\n"; - $surveysummary2 = ""; - if ($surveyinfo['anonymized'] != "N") {$surveysummary2 .= $clang->gT("Answers to this survey are anonymized.")."
\n";} - else {$surveysummary2 .= $clang->gT("This survey is NOT anonymous.")."
\n";} - if ($surveyinfo['format'] == "S") {$surveysummary2 .= $clang->gT("It is presented question by question.")."
\n";} - elseif ($surveyinfo['format'] == "G") {$surveysummary2 .= $clang->gT("It is presented group by group.")."
\n";} - else {$surveysummary2 .= $clang->gT("It is presented on one single page.")."
\n";} - if ($surveyinfo['allowjumps'] == "Y") - { - if ($surveyinfo['format'] == 'A') {$surveysummary2 .= $clang->gT("No question index will be shown with this format.")."
\n";} - else {$surveysummary2 .= $clang->gT("A question index will be shown; participants will be able to jump between viewed questions.")."
\n";} - } - if ($surveyinfo['datestamp'] == "Y") {$surveysummary2 .= $clang->gT("Responses will be date stamped.")."
\n";} - if ($surveyinfo['ipaddr'] == "Y") {$surveysummary2 .= $clang->gT("IP Addresses will be logged")."
\n";} - if ($surveyinfo['refurl'] == "Y") {$surveysummary2 .= $clang->gT("Referrer URL will be saved.")."
\n";} - if ($surveyinfo['usecookie'] == "Y") {$surveysummary2 .= $clang->gT("It uses cookies for access control.")."
\n";} - if ($surveyinfo['allowregister'] == "Y") {$surveysummary2 .= $clang->gT("If tokens are used, the public may register for this survey")."
\n";} - if ($surveyinfo['allowsave'] == "Y" && $surveyinfo['tokenanswerspersistence'] == 'N') {$surveysummary2 .= $clang->gT("Participants can save partially finished surveys")."
\n";} - if ($surveyinfo['emailnotificationto'] != '') - { - $surveysummary2 .= $clang->gT("Basic email notification is sent to:")." {$surveyinfo['emailnotificationto']}
\n"; - } - if ($surveyinfo['emailresponseto'] != '') - { - $surveysummary2 .= $clang->gT("Detailed email notification with response data is sent to:")." {$surveyinfo['emailresponseto']}
\n"; - } - - if(bHasSurveyPermission($surveyid,'surveycontent','update')) - { - $surveysummary2 .= $clang->gT("Regenerate question codes:") - . " [gT("Are you sure you want to regenerate the question codes?\n\nWARNING:\nThis is safe if you only use the Conditions editor.\n\nHOWEVER, if you manually specified any relevance equations, regenerating the question codes will break all of that survey logic.","js")."')) {".get2post("$scriptname?action=renumberquestions&sid=$surveyid&style=straight")."}\" " - . ">".$clang->gT("Straight")."] " - . " [gT("Are you sure you want to regenerate the question codes?\n\nWARNING:\nThis is safe if you only use the Conditions editor.\n\nHOWEVER, if you manually specified any relevance equations, regenerating the question codes will break all of that survey logic.","js")."')) {".get2post("$scriptname?action=renumberquestions&sid=$surveyid&style=bygroup")."}\" " - . ">".$clang->gT("By Group")."]"; - $surveysummary2 .= "\n"; - } - $surveysummary .= "" - . "\n"; - if ( $modrewrite ) { - $tmp_url = $GLOBALS['publicurl'] . '/' . $surveyinfo['sid']; - $surveysummary .= "\n" - . "\n\n" - . "\n" - . "\n" - . "\n" - . "\n" - . "\n"; - if (trim($surveyinfo['faxto'])!='') - { - $surveysummary .="\n\n"; - } - $surveysummary .= "\n"; - $dateformatdetails=getDateFormatData($_SESSION['dateformat']); - if (trim($surveyinfo['startdate'])!= '') - { - $datetimeobj = new Date_Time_Converter($surveyinfo['startdate'] , "Y-m-d H:i:s"); - $startdate=$datetimeobj->convert($dateformatdetails['phpdate'].' H:i'); - } - else - { - $startdate="-"; - } - $surveysummary .= "\n" - . "\n"; - if (trim($surveyinfo['expires'])!= '') - { - $datetimeobj = new Date_Time_Converter($surveyinfo['expires'] , "Y-m-d H:i:s"); - $expdate=$datetimeobj->convert($dateformatdetails['phpdate'].' H:i'); - } - else - { - $expdate="-"; - } - $surveysummary .= "\n" - . "\n" - . "\n" - - . "\n"; - if (!$surveyinfo['language']) {$language=getLanguageNameFromCode($currentadminlang,false);} else {$language=getLanguageNameFromCode($surveyinfo['language'],false);} - $surveysummary .= "\n"; - - // get the rowspan of the Additionnal languages row - // is at least 1 even if no additionnal language is present - $additionnalLanguagesCount = count($aAdditionalLanguages); - $surveysummary .= "\n"; - $first=true; - if ($additionnalLanguagesCount == 0) - { - $surveysummary .= "\n"; - } - else - { - foreach ($aAdditionalLanguages as $langname) - { - if ($langname) - { - if (!$first) {$surveysummary .= "";} - $first=false; - $surveysummary .= "\n"; - } - } - } - if ($first) $surveysummary .= ""; - - if ($surveyinfo['surveyls_urldescription']==""){$surveyinfo['surveyls_urldescription']=htmlspecialchars($surveyinfo['surveyls_url']);} - $surveysummary .= "\n" - . "\n"; - $surveysummary .= "\n"; - $surveysummary .= "\n"; - - if ($activated == "Y") - { - $surveysummary .= "\n"; - } - $surveysummary .= "
" - . "".$clang->gT("Title").":{$surveyinfo['surveyls_title']} " - . "(".$clang->gT("ID")." {$surveyinfo['sid']})
" - . $clang->gT("Survey URL") ." (".getLanguageNameFromCode($surveyinfo['language'],false)."): $tmp_url/lang-".$surveyinfo['language'].""; - foreach ($aAdditionalLanguages as $langname) - { - $surveysummary .= " ".getLanguageNameFromCode($langname,false)." ".$clang->gT("Flag").""; - } - } else { - $tmp_url = $GLOBALS['publicurl'] . '/index.php?sid=' . $surveyinfo['sid']; - $surveysummary .= " $tmp_url&lang=".$surveyinfo['language'].""; - foreach ($aAdditionalLanguages as $langname) - { - $surveysummary .= " ".getLanguageNameFromCode($langname,false)." ".$clang->gT("Flag").""; - } - } - - $surveysummary .= "
" - . $clang->gT("Description:").""; - - LimeExpressionManager::StartProcessingPage(false,$rooturl,true); // so can click on syntax highlighting to edit questions - - if (trim($surveyinfo['surveyls_description'])!='') - { - templatereplace($surveyinfo['surveyls_description']); - $surveysummary .= LimeExpressionManager::GetLastPrettyPrintExpression(); - } - $surveysummary .= "
" - . $clang->gT("Welcome:").""; - - templatereplace($surveyinfo['surveyls_welcometext']); - $surveysummary .= LimeExpressionManager::GetLastPrettyPrintExpression(); - - $surveysummary .= "
" - . $clang->gT("Administrator:")." {$surveyinfo['admin']} ({$surveyinfo['adminemail']})
" - . $clang->gT("Fax to:")."{$surveyinfo['faxto']}"; - $surveysummary .= "
" - . $clang->gT("Start date/time:")."$startdate
" - . $clang->gT("Expiry date/time:")."$expdate
" - . $clang->gT("Template:")." {$surveyinfo['template']}
" - . $clang->gT("Base language:")."$language
" - . $clang->gT("Additional Languages").":-
 ".getLanguageNameFromCode($langname,false)."
" - . $clang->gT("End URL").":"; - if ($surveyinfo['surveyls_url']!="") - { - $surveysummary .=" {$surveyinfo['surveyls_urldescription']}"; - } - else - { - $surveysummary .="-"; - } - $surveysummary .="
" - . $clang->gT("Number of questions/groups").":$sumcount3/$sumcount2
" - . $clang->gT("Survey currently active").":"; - if ($activated == "N") - { - $surveysummary .= $clang->gT("No"); - } - else - { - $surveysummary .= $clang->gT("Yes"); - } - $surveysummary .="
" - . $clang->gT("Survey table name").":".$dbprefix."survey_$surveyid
" - . $clang->gT("Hints").":\n"; - - if ($activated == "N" && $sumcount3 == 0) - { - $surveysummary .= $clang->gT("Survey cannot be activated yet.")."
\n"; - if ($sumcount2 == 0 && bHasSurveyPermission($surveyid,'surveycontent','create')) - { - $surveysummary .= "[".$clang->gT("You need to add question groups")."]
"; - } - if ($sumcount3 == 0 && bHasSurveyPermission($surveyid,'surveycontent','create')) - { - $surveysummary .= "[".$clang->gT("You need to add questions")."]
"; - } - } - $surveysummary .= $surveysummary2 - . "
\n"; - } - else - { - include("access_denied.php"); - } -} - - -if (isset($surveyid) && $surveyid && $gid ) // Show the group toolbar -{ - // TODO: check that surveyid and thus baselang are always set here - $sumquery4 = "SELECT * FROM ".db_table_name('questions')." WHERE sid=$surveyid AND - gid=$gid AND language='".$baselang."'"; //Getting a count of questions for this survey - $sumresult4 = $connect->Execute($sumquery4); //Checked - $sumcount4 = $sumresult4->RecordCount(); - $grpquery ="SELECT * FROM ".db_table_name('groups')." WHERE gid=$gid AND - language='".$baselang."' ORDER BY ".db_table_name('groups').".group_order"; - $grpresult = db_execute_assoc($grpquery); //Checked - - // Check if other questions/groups are dependent upon this group -// $condarray=GetGroupDepsForConditions($surveyid,"all",$gid,"by-targgid"); - - $groupsummary = "\n"; - // $groupsummary .= "

 

"; //CSS Firefox 2 transition fix - - if ($qid || $action=='editgroup'|| $action=='addquestion') {$gshowstyle="style='display: none'";} - else {$gshowstyle="";} - - $groupsummary .= "\n" - . "\n" - . "\n\n\n"; - -// if (!is_null($condarray)) -// { -// $groupsummary .= "\n" -// . ""; -// } - } - $groupsummary .= "\n
" - . $clang->gT("Title").":" - . "{$grow['group_name']} ({$grow['gid']})
" - . $clang->gT("Description:").""; - if (trim($grow['description'])!='') - { - templatereplace($grow['description']); - $groupsummary .= LimeExpressionManager::GetLastPrettyPrintExpression(); - } - if (trim($grow['grelevance'])!='') - { - $groupsummary .= "
"; - $groupsummary .= $clang->gT("Relevance:").""; - templatereplace('{' . $grow['grelevance'] . '}'); - $groupsummary .= LimeExpressionManager::GetLastPrettyPrintExpression(); - } - $groupsummary .= "
" -// . $clang->gT("Questions with conditions to this group").":"; -// foreach ($condarray[$gid] as $depgid => $deprow) -// { -// foreach ($deprow['conditions'] as $depqid => $depcid) -// { -// //$groupsummary .= "[QID: ".$depqid."]"; -// $listcid=implode("-",$depcid); -// $groupsummary .= " [QID: ".$depqid."]"; -// } -// } -// $groupsummary .= "
\n"; -} - -//////////////////////////////////////////////////////////////////////////////// -// Question toolbar -//////////////////////////////////////////////////////////////////////////////// - - -if (isset($surveyid) && $surveyid && $gid && $qid) // Show the question toolbar -{ - // TODO: check that surveyid is set and that so is $baselang - //Show Question Details - //Count answer-options for this question - $qrq = "SELECT * FROM ".db_table_name('answers')." WHERE qid=$qid AND language='".$baselang."' ORDER BY sortorder, answer"; - $qrr = $connect->Execute($qrq); //Checked - $qct = $qrr->RecordCount(); - //Count sub-questions for this question - $sqrq= "SELECT * FROM ".db_table_name('questions')." WHERE parent_qid=$qid AND language='".$baselang."'"; - $sqrr= $connect->Execute($sqrq); //Checked - $sqct = $sqrr->RecordCount(); - - $qrquery = "SELECT * FROM ".db_table_name('questions')." WHERE gid=$gid AND sid=$surveyid AND qid=$qid AND language='".$baselang."'"; - $qrresult = db_execute_assoc($qrquery) or safe_die($qrquery."
".$connect->ErrorMsg()); //Checked - $questionsummary = "\n"; - $questionsummary .= "

 

"; //CSS Firefox 2 transition fix - - if ($action=='editansweroptions' || $action =="editsubquestions" || $action =="editquestion" || $action =="editdefaultvalues" || $action =="copyquestion") - { - $qshowstyle = "style='display: none'"; - } - else - { - $qshowstyle = ""; - } - $questionsummary .= "\n" - . "\n" - . "\n\n" - . "\n\n"; - if ($qrrow['preg']) - { - $questionsummary .= "\n\n"; - } - $qtypes = getqtypelist("", "array"); //qtypes = array(type code=>type description) - $questionsummary .= "\n\n"; - if ($qct == 0 && $qtypes[$qrrow['type']]['answerscales'] >0) - { - $questionsummary .= "\n"; - } - - // EDIT SUBQUESTIONS FOR THIS QUESTION BUTTON - if($sqct == 0 && $qtypes[$qrrow['type']]['subquestions'] >0) - { - $questionsummary .= "\n"; - } - - if ($qrrow['type'] == "M" or $qrrow['type'] == "P") - { - $questionsummary .= "" - . "\n" - . "\n"; - } - if (isset($qrrow['mandatory']) and ($qrrow['type'] != "X") and ($qrrow['type'] != "|")) - { - $questionsummary .= "" - . "\n" - . "\n"; - } -// if (!is_null($condarray)) -// { -// $questionsummary .= "" -// . "\n"; -// } - if (is_null($qrrow['relevance']) || trim($qrrow['relevance']) == '') - { - $rel2show = 1; - } - else - { - LimeExpressionManager::ProcessString("{" . $qrrow['relevance'] . "}", $qid); // tests Relevance equation so can pretty-print it - $rel2show = LimeExpressionManager::GetLastPrettyPrintExpression(); - $questionsummary .= "" - . "\n" - . "\n"; - } - $questionsummary .= "
" - . $clang->gT("Code:")."{$qrrow['title']}"; - if ($qrrow['type'] != "X") - { - if ($qrrow['mandatory'] == "Y") {$questionsummary .= ": (".$clang->gT("Mandatory Question").")";} - else {$questionsummary .= ": (".$clang->gT("Optional Question").")";} - } - $questionsummary .= "
"; - $questionsummary .= $clang->gT("Question:") . ""; - - // Color code the question, help, and relevance - - templatereplace($qrrow['question'],false,false,$qid); - $questionsummary .= FlattenText(LimeExpressionManager::GetLastPrettyPrintExpression(), false, 'UTF-8', true, true); - - $questionsummary .= "
" - . $clang->gT("Help:").""; - if (trim($qrrow['help'])!='') - { - templatereplace($qrrow['help'],false,false,$qid); - $questionsummary .= FlattenText(LimeExpressionManager::GetLastPrettyPrintExpression(), false, 'UTF-8', true, true); - } - $questionsummary .= "
" - . $clang->gT("Validation:")."{$qrrow['preg']}" - . "
" - .$clang->gT("Type:")."{$qtypes[$qrrow['type']]['description']}"; - $questionsummary .="
" - . "" - . $clang->gT("Warning").": ". $clang->gT("You need to add answer options to this question")." " - . "
" - . "" - . $clang->gT("Warning").": ". $clang->gT("You need to add subquestions to this question")." " - . "
" - . $clang->gT("Option 'Other':").""; - $questionsummary .= ($qrrow['other'] == "Y") ? ($clang->gT("Yes")) : ($clang->gT("No")) ; - $questionsummary .= "
" - . $clang->gT("Mandatory:").""; - $questionsummary .= ($qrrow['mandatory'] == "Y") ? ($clang->gT("Yes")) : ($clang->gT("No")) ; - $questionsummary .= "
" -// . $clang->gT("Other questions having conditions on this question:") -// . "\n"; -// foreach ($condarray[$qid] as $depqid => $depcid) -// { -// $listcid=implode("-",$depcid); -// $questionsummary .= " [QID: ".$depqid."]"; -// } -// $questionsummary .= "
" - . $clang->gT("Relevance:").""; - $questionsummary .= $rel2show; - $questionsummary .= "
"; - } -} -LimeExpressionManager::FinishProcessingPage(); - -// ============= EDIT ANSWER OPTIONS===================================== - - -if ($action=='editansweroptions') -{ - include("editansweroptions.php"); -} - - -// ============= EDIT SUBQUESTIONS ====================================== - -if ($action=='editsubquestions') -{ - include("editsubquestions.php"); -} - - - -// ************************************************* -// Survey Rights Start **************************** -// ************************************************* - -if($action == "addsurveysecurity") -{ - $addsummary = "
".$clang->gT("Add User")."
\n"; - $addsummary .= "
\n"; - - $query = "SELECT sid, owner_id FROM ".db_table_name('surveys')." WHERE sid = {$surveyid} AND owner_id = ".$_SESSION['loginID']." AND owner_id != ".$postuserid; - $result = db_execute_assoc($query); //Checked - if( ($result->RecordCount() > 0 && in_array($postuserid,getuserlist('onlyuidarray'))) || - $_SESSION['USER_RIGHT_SUPERADMIN'] == 1) - { - - if($postuserid > 0){ - - $isrquery = "INSERT INTO {$dbprefix}survey_permissions (sid,uid,permission,read_p) VALUES ({$surveyid},{$postuserid},'survey',1)"; - $isrresult = $connect->Execute($isrquery); //Checked - - if($isrresult) - { - $addsummary .= "
".$clang->gT("User added.")."
\n"; - $addsummary .= "
" - ."" - ."" - ."" - ."
\n"; - } - else - { - // Username already exists. - $addsummary .= "
".$clang->gT("Failed to add user.")."
\n" - . "
" . $clang->gT("Username already exists.")."
\n"; - $addsummary .= "
gT("Continue")."\"/>\n"; - } - } - else - { - $addsummary .= "
".$clang->gT("Failed to add user.")."
\n" - . "
" . $clang->gT("No Username selected.")."
\n"; - $addsummary .= "
gT("Continue")."\"/>\n"; - } - } - else - { - include("access_denied.php"); - } - $addsummary .= "
\n"; -} - - -if($action == "addusergroupsurveysecurity") -{ - $addsummary = "
".$clang->gT("Add user group")."
\n"; - $addsummary .= "
\n"; - - $query = "SELECT sid, owner_id FROM ".db_table_name('surveys')." WHERE sid = {$surveyid} AND owner_id = ".$_SESSION['loginID']; - $result = db_execute_assoc($query); //Checked - if( ($result->RecordCount() > 0 && in_array($postusergroupid,getsurveyusergrouplist('simpleugidarray'))) || $_SESSION['USER_RIGHT_SUPERADMIN'] == 1) - { - if($postusergroupid > 0){ - $query2 = "SELECT b.uid FROM (SELECT uid FROM ".db_table_name('survey_permissions')." WHERE sid = {$surveyid}) AS c RIGHT JOIN ".db_table_name('user_in_groups')." AS b ON b.uid = c.uid WHERE c.uid IS NULL AND b.ugid = {$postusergroupid}"; - $result2 = db_execute_assoc($query2); //Checked - if($result2->RecordCount() > 0) - { - while ($row2 = $result2->FetchRow()) - { - $uid_arr[] = $row2['uid']; - $isrquery = "INSERT INTO {$dbprefix}survey_permissions (sid,uid,permission,read_p) VALUES ({$surveyid}, {$row2['uid']},'survey',1) "; - $isrresult = $connect->Execute($isrquery); //Checked - if (!$isrresult) break; - } - - if($isrresult) - { - $addsummary .= "
".$clang->gT("User Group added.")."
\n"; - $_SESSION['uids'] = $uid_arr; - $addsummary .= "
" - ."" - ."" - ."" - ."
\n"; - } - else - { - // Error while adding user to the database - $addsummary .= "
".$clang->gT("Failed to add User Group.")."
\n"; - $addsummary .= "
gT("Continue")."\"/>\n"; - } - } - else - { - // no user to add - $addsummary .= "
".$clang->gT("Failed to add User Group.")."
\n"; - $addsummary .= "
gT("Continue")."\"/>\n"; - } - } - else - { - $addsummary .= "
".$clang->gT("Failed to add user.")."
\n" - . "
" . $clang->gT("No Username selected.")."
\n"; - $addsummary .= "
gT("Continue")."\"/>\n"; - } - } - else - { - include("access_denied.php"); - } - $addsummary .= "
\n"; -} - -if($action == "delsurveysecurity") -{ - $addsummary = "
".$clang->gT("Deleting User")."
\n"; - $addsummary .= "
\n"; - - $query = "SELECT sid, owner_id FROM ".db_table_name('surveys')." WHERE sid = {$surveyid} AND owner_id = ".$_SESSION['loginID']." AND owner_id != ".$postuserid; - $result = db_execute_assoc($query); //Checked - if($result->RecordCount() > 0 || $_SESSION['USER_RIGHT_SUPERADMIN'] == 1) - { - if (isset($postuserid)) - { - $dquery="DELETE FROM".db_table_name('survey_permissions')." WHERE uid={$postuserid} AND sid={$surveyid}"; // added by Dennis - $dresult=$connect->Execute($dquery); //Checked - - $addsummary .= "
".$clang->gT("Username").": ".sanitize_xss_string($_POST['user'])."

\n"; - $addsummary .= "
".$clang->gT("Success!")."
\n"; - } - else - { - $addsummary .= "
".$clang->gT("Could not delete user. User was not supplied.")."
\n"; - } - $addsummary .= "
gT("Continue")."\"/>\n"; - } - else - { - include("access_denied.php"); - } - $addsummary .= "
\n"; -} - -if($action == "setsurveysecurity" || $action == "setusergroupsurveysecurity") -{ - $query = "SELECT sid, owner_id FROM ".db_table_name('surveys')." WHERE sid = {$surveyid} AND owner_id = ".$_SESSION['loginID']; - if ($action == "setsurveysecurity") - { - $query.= " AND owner_id != ".$postuserid; - } - $result = db_execute_assoc($query); //Checked - if($result->RecordCount() > 0 || $_SESSION['USER_RIGHT_SUPERADMIN'] == 1) - { - $js_admin_includes[]='../scripts/jquery/jquery.tablesorter.min.js'; - $js_admin_includes[]='scripts/surveysecurity.js'; - if ($action == "setsurveysecurity") - { - $sUsername=$connect->GetOne("select users_name from ".db_table_name('users')." where uid={$postuserid}"); - $usersummary = "
".sprintf($clang->gT("Edit survey permissions for user %s"),"".$sUsername."")."
"; - } - else - { - $sUsergroupName=$connect->GetOne("select name from ".db_table_name('user_groups')." where ugid={$postusergroupid}"); - $usersummary = "
".sprintf($clang->gT("Edit survey permissions for group %s"),"".$sUsergroupName."")."
"; - } - $usersummary .= "
\n" - . "\n"; - - $usersummary .= "" - . "\n" - . "\n" - . "\n" - . "\n" - . "\n" - . "\n" - . "\n" - . "\n" - . "\n"; - - //content - - $aBasePermissions=aGetBaseSurveyPermissions(); - $oddcolumn=false; - foreach($aBasePermissions as $sPermissionKey=>$aCRUDPermissions) - { - $oddcolumn=!$oddcolumn; - $usersummary .= ""; - $usersummary .= ""; - $usersummary .= ""; - foreach ($aCRUDPermissions as $sCRUDKey=>$CRUDValue) - { - if (!in_array($sCRUDKey,array('create','read','update','delete','import','export'))) continue; - $usersummary .= "
".$clang->gT("Permission")."".$clang->gT("Create")."".$clang->gT("View/read")."".$clang->gT("Update")."".$clang->gT("Delete")."".$clang->gT("Import")."".$clang->gT("Export")."
{$aCRUDPermissions['title']}"; - - if ($CRUDValue) - { - if (!($sPermissionKey=='survey' && $sCRUDKey=='read')) - { - $usersummary .= "" - ."" - .""; - - if ($action=='setsurveysecurity') - { - $usersummary .=""; - } - else - { - $usersummary .=""; - } - $usersummary .= "\n"; - } - else - { - include("access_denied.php"); - } -} - -// This is the action to export the structure of a complete survey -if($action == "exportstructure") -{ - if(bHasSurveyPermission($surveyid,'surveycontent','export')) - { - $exportstructure = "
\n" - ."
" - .$clang->gT("Export Survey Structure")."\n

\n" - ."
    \n" - ."
  • " - .$clang->gT("LimeSurvey XML survey file (*.lss)")."
  • \n"; - - $exportstructure.="
  • " - .str_replace('queXML','queXML',$clang->gT("queXML Survey XML Format (*.xml)"))." " - ."
  • \n"; - - // XXX - //include("../config.php"); - - //echo $export4lsrc; - if($export4lsrc) - { - $exportstructure.="
  • " - ."
  • "; - } - $exportstructure.="
\n"; - - $exportstructure.="

\n" - ."\n" - ."\n"; - $exportstructure.="

\n"; - } -} - -// This is the action to export the structure of a group -if($action == "exportstructureGroup") -{ - if($export4lsrc === true && bHasSurveyPermission($surveyid,'survey','export')) - { - $exportstructure = "
\n" - ."
".$clang->gT("Export group structure")."\n
\n" - ."
    \n" - ."
  • \n"; - $exportstructure.="" - ."
  • \n"; - - // $exportstructure.="" - // ."\n"; - - // XXX - //include("../config.php"); - - //echo $export4lsrc; - if($export4lsrc) - { - $exportstructure.="
  • " - ."
  • \n"; - } - - $exportstructure.="
\n" - ."

\n" - ."\n" - ."\n" - ."\n" - ."\n"; - $exportstructure.="

\n"; - } - else - { - include('dumpgroup.php'); - } -} - -// This is the action to export the structure of a question -if($action == "exportstructureQuestion") -{ - if($export4lsrc === true && bHasSurveyPermission($surveyid,'survey','export')) - { - $exportstructure = "
\n" - ."
".$clang->gT("Export question structure")."\n
\n" - ."
    \n" - ."
  • \n"; - $exportstructure.="" - ."
  • \n"; - - // $exportstructure.="" - // ."\n"; - - // XXX - //include("../config.php"); - - //echo $export4lsrc; - if($export4lsrc) - { - $exportstructure.="
  • " - ."
  • \n"; - } - - $exportstructure.="
\n" - ."

\n" - ."\n" - ."\n" - ."\n" - ."\n" - ."\n"; - $exportstructure.="

\n"; - } - else - { - include('dumpquestion.php'); - } -} - -if($action == "surveysecurity") -{ - if(bHasSurveyPermission($surveyid,'survey','read')) - { - $aBaseSurveyPermissions=aGetBaseSurveyPermissions(); - $js_admin_includes[]='../scripts/jquery/jquery.tablesorter.min.js'; - $js_admin_includes[]='scripts/surveysecurity.js'; - - $query2 = "SELECT p.sid, p.uid, u.users_name, u.full_name FROM ".db_table_name('survey_permissions')." AS p INNER JOIN ".db_table_name('users')." AS u ON p.uid = u.uid - WHERE p.sid = {$surveyid} AND u.uid != ".$_SESSION['loginID'] ." - GROUP BY p.sid, p.uid, u.users_name, u.full_name - ORDER BY u.users_name"; - $result2 = db_execute_assoc($query2); //Checked - - $surveysecurity ="
".$clang->gT("Survey permissions")."
\n" - . "" - . "\n" - . "\n" - . "\n" - . "\n" - . "\n"; - foreach ($aBaseSurveyPermissions as $sPermission=>$aSubPermissions ) - { - $surveysecurity.="\n"; - } - $surveysecurity .= "\n"; - - // Foot first - - if (isset($usercontrolSameGroupPolicy) && - $usercontrolSameGroupPolicy == true) - { - $authorizedGroupsList=getusergrouplist('simplegidarray'); - } - - $surveysecurity .= "\n"; - if($result2->RecordCount() > 0) - { - // output users - $row = 0; - while ($PermissionRow = $result2->FetchRow()) - { - - $query3 = "SELECT a.ugid FROM ".db_table_name('user_in_groups')." AS a RIGHT OUTER JOIN ".db_table_name('users')." AS b ON a.uid = b.uid WHERE b.uid = ".$PermissionRow['uid']; - $result3 = db_execute_assoc($query3); //Checked - while ($resul3row = $result3->FetchRow()) - { - if (!isset($usercontrolSameGroupPolicy) || - $usercontrolSameGroupPolicy == false || - in_array($resul3row['ugid'],$authorizedGroupsList)) - { - $group_ids[] = $resul3row['ugid']; - } - } - - if(isset($group_ids) && $group_ids[0] != NULL) - { - $group_ids_query = implode(" OR ugid=", $group_ids); - unset($group_ids); - - $query4 = "SELECT name FROM ".db_table_name('user_groups')." WHERE ugid = ".$group_ids_query; - $result4 = db_execute_assoc($query4); //Checked - - while ($resul4row = $result4->FetchRow()) - { - $group_names[] = $resul4row['name']; - } - if(count($group_names) > 0) - $group_names_query = implode(", ", $group_names); - } - // else {break;} //TODO Commented by lemeur - $surveysecurity .= "\n"; - - $surveysecurity .= "\n"; - $surveysecurity .= "\n" - . "\n" - . "\n"; - - //Now show the permissions - foreach ($aBaseSurveyPermissions as $sPKey=>$aPDetails) { - unset($aPDetails['img']); - unset($aPDetails['description']); - unset($aPDetails['title']); - $iCount=0; - $iPermissionCount=0; - foreach ($aPDetails as $sPDetailKey=>$sPDetailValue) - { - if ($sPDetailValue && bHasSurveyPermission($surveyid,$sPKey,$sPDetailKey,$PermissionRow['uid']) && !($sPKey=='survey' && $sPDetailKey=='read')) $iCount++; - if ($sPDetailValue) $iPermissionCount++; - } - if ($sPKey=='survey') $iPermissionCount--; - if ($iCount==$iPermissionCount) { - $insert = "
 
"; - } - elseif ($iCount>0){ - $insert = "
 
"; - } - else - { - $insert = "
 
"; - } - $surveysecurity .= "\n"; - } - - $surveysecurity .= "\n"; - $row++; - } - } else { - $surveysecurity .= ""; //fix error on empty table - } - $surveysecurity .= "\n" - . "
".$clang->gT("Action")."".$clang->gT("Username")."".$clang->gT("User Group")."".$clang->gT("Full name")."\"<span".$aSubPermissions['title']."
".$aSubPermissions['description']."\" />
\n"; - $surveysecurity .= "
" - ."" - ."" - ."" - ."" - ."
\n"; - $surveysecurity .= "
" - ."" - ."" - ."" - ."" - ."
"; - - - $surveysecurity .= "
{$PermissionRow['users_name']}"; - - if(isset($group_names) > 0) - { - $surveysecurity .= $group_names_query; - } - else - { - $surveysecurity .= "---"; - } - unset($group_names); - - $surveysecurity .= "\n{$PermissionRow['full_name']}\n$insert\n
\n" - . "
    \n" - . "
  • \n" - . "gT("Please select a user first","js")."'); return false;}\"/>" - . "" - . "
\n" - . "
  • \n" - . "\n" - . "gT("Please select a user group first","js")."'); return false;}\" />" - . "\n" - . "
"; - - } - else - { - include("access_denied.php"); - } -} - -elseif ($action == "surveyrights") -{ - $addsummary = "
".$clang->gT("Edit survey permissions")."
\n"; - $addsummary .= "
\n"; - - if(isset($postuserid)){ - $query = "SELECT sid, owner_id FROM ".db_table_name('surveys')." WHERE sid = {$surveyid}"; - if ($_SESSION['USER_RIGHT_SUPERADMIN'] != 1) - { - $query.=" AND owner_id != {$postuserid} AND owner_id = ".$_SESSION['loginID']; - } - } - else{ - $sQuery = "SELECT owner_id FROM ".db_table_name('surveys')." WHERE sid = {$surveyid}"; - if ($_SESSION['USER_RIGHT_SUPERADMIN'] != 1) - { - $query.=" AND owner_id = ".$_SESSION['loginID']; - } - $iOwnerID=$connect->GetOne($sQuery); - } - - $aBaseSurveyPermissions=aGetBaseSurveyPermissions(); - $aPermissions=array(); - foreach ($aBaseSurveyPermissions as $sPermissionKey=>$aCRUDPermissions) - { - foreach ($aCRUDPermissions as $sCRUDKey=>$CRUDValue) - { - if (!in_array($sCRUDKey,array('create','read','update','delete','import','export'))) continue; - - if ($CRUDValue) - { - if(isset($_POST["perm_{$sPermissionKey}_{$sCRUDKey}"])){ - $aPermissions[$sPermissionKey][$sCRUDKey]=1; - } - else - { - $aPermissions[$sPermissionKey][$sCRUDKey]=0; - } - } - } - } - if (isset($postusergroupid) && $postusergroupid>0) - { - $sQuery = "SELECT uid from ".db_table_name('user_in_groups')." where ugid = {$postusergroupid} and uid<>{$_SESSION['loginID']} AND uid<>{$iOwnerID}"; - $oResult = db_execute_assoc($sQuery); //Checked - if($oResult->RecordCount() > 0) - { - while ($aRow = $oResult->FetchRow()) - { - SetSurveyPermissions($aRow['uid'], $surveyid, $aPermissions); - } - $addsummary .= "
".$clang->gT("Survey permissions for all users in this group were successfully updated.")."
\n"; - } - } - else - { - if(SetSurveyPermissions($postuserid, $surveyid, $aPermissions)) - { - $addsummary .= "
".$clang->gT("Survey permissions were successfully updated.")."
\n"; - } - else - { - $addsummary .= "
".$clang->gT("Failed to update survey permissions!")."
\n"; - } - - } - $addsummary .= "
gT("Continue")."\"/>\n"; - $addsummary .= "
\n"; -} - -// ************************************************* -// Survey Rights End **************************** -// ************************************************* - -// Edit survey general settings - -if ($action == "editsurveysettings" || $action == "newsurvey") -{ - include("editsurveysettings.php"); -} - - - - -// Edit survey text elements - -if ($action == "updatesurveysettingsandeditlocalesettings" || $action == "editsurveylocalesettings") // Edit survey step 2 - editing language dependent settings -{ - include("editsurveytextelements.php"); -} - -if ($action == "translate") // Translate survey -{ - if(bHasSurveyPermission($surveyid,'translation','read')) - { - $translateoutput .="
".$clang->gT("Quick-translate survey")."
\n"; - } - else - { - include("access_denied.php"); - } - -} - -if ($action == "emailtemplates") -{ - include("editemailtemplates.php"); -} - - - - -if($action == "quotas") - { - include("quota.php"); - } - -function replacenewline ($texttoreplace) -{ - $texttoreplace = str_replace( "\n", '
', $texttoreplace); - // $texttoreplace = htmlentities( $texttoreplace, ENT_QUOTES, UTF-8); - $new_str = ''; - - for($i = 0; $i < strlen($texttoreplace); $i++) { - $new_str .= '\x' . dechex(ord(substr($texttoreplace, $i, 1))); - } - - return $new_str; -} - -/** - * showadminmenu() function returns html text for the administration button bar - * - * @global string $homedir - * @global string $scriptname - * @global string $surveyid - * @global string $setfont - * @global string $imageurl - * @return string $adminmenu - */ -function showadminmenu() -{ - global $homedir, $scriptname, $surveyid, $setfont, $imageurl, $clang, $debug, $action, $updateavailable, $updatebuild, $updateversion, $updatelastcheck, $databasetype; - - $adminmenu = "\n"; - // $adminmenu .= "

 

"; //CSS Firefox 2 transition fix - if (!isset($action) && !isset($surveyid) && count(getsurveylist(true))==0) - { - $adminmenu.= '
' - .'

'.sprintf($clang->gT("Welcome to %s!"),'LimeSurvey').'

' - .'

'.$clang->gT("Some piece-of-cake steps to create your very own first survey:").'
' - .'

    ' - .'
  1. '.sprintf($clang->gT('Create a new survey clicking on the %s icon in the upper right.'),"". $clang->gT("Add survey")."").'
  2. ' - .'
  3. '.$clang->gT('Create a new question group inside your survey.').'
  4. ' - .'
  5. '.$clang->gT('Create one or more questions inside the new question group.').'
  6. ' - .'
  7. '.sprintf($clang->gT('Done. Test your survey using the %s icon.'),"". $clang->gT("Test survey")."").'
  8. ' - .'


 
'; - } - - } - return $adminmenu; -} +" + . "".$clang->gT("Your personal settings")."\n" + . "\n" + . "
\n" + . "
" + . "
    \n"; + + $sSavedLanguage=$connect->GetOne("select lang from ".db_table_name('users')." where uid={$_SESSION['loginID']}"); + + // Current language + $cssummary .= "
  • \n" + . "\n" + . "\n" + . "
  • \n"; + + // Current htmleditormode + $cssummary .= "
  • \n" + . "\n" + . "\n" + . "
  • \n"; + + // Current questionselectormode + $cssummary .= "
  • \n" + . "\n" + . "\n" + . "
  • \n"; + + // Current templateeditormode + $cssummary .= "
  • \n" + . "\n" + . "\n" + . "
  • \n"; + + // Date format + $cssummary .= "
  • \n" + . "\n" + . "\n" + . "
  • \n" + . "
\n" + . "

"; +} + + + +if (isset($surveyid) && $surveyid && +$action!='dataentry' && $action!='browse' && $action!='exportspss' && +$action!='statistics' && $action!='importoldresponses' && $action!='exportr' && +$action!='vvimport' && $action!='vvexport' && $action!='exportresults') +{ + if(bHasSurveyPermission($surveyid,'survey','read')) + { + $js_admin_includes[]='../scripts/jquery/jquery.coookie.js'; + $js_admin_includes[]='../scripts/jquery/superfish.js'; + $js_admin_includes[]='../scripts/jquery/hoverIntent.js'; + $js_admin_includes[]='scripts/surveytoolbar.js'; + $css_admin_includes[]= $homeurl."/styles/default/superfish.css"; + $baselang = GetBaseLanguageFromSurveyID($surveyid); + $sumquery3 = "SELECT * FROM ".db_table_name('questions')." WHERE sid={$surveyid} AND parent_qid=0 AND language='".$baselang."'"; //Getting a count of questions for this survey + $sumresult3 = $connect->Execute($sumquery3); //Checked + $sumcount3 = $sumresult3->RecordCount(); + $sumquery6 = "SELECT count(*) FROM ".db_table_name('conditions')." as c, ".db_table_name('questions')." as q WHERE c.qid = q.qid AND q.sid=$surveyid"; //Getting a count of conditions for this survey + $sumcount6 = $connect->GetOne($sumquery6); //Checked + $sumquery2 = "SELECT * FROM ".db_table_name('groups')." WHERE sid={$surveyid} AND language='".$baselang."'"; //Getting a count of groups for this survey + $sumresult2 = $connect->Execute($sumquery2); //Checked + $sumcount2 = $sumresult2->RecordCount(); + $sumquery1 = "SELECT * FROM ".db_table_name('surveys')." inner join ".db_table_name('surveys_languagesettings')." on (surveyls_survey_id=sid and surveyls_language=language) WHERE sid=$surveyid"; //Getting data for this survey + $sumresult1 = db_select_limit_assoc($sumquery1, 1) ; //Checked + if ($sumresult1->RecordCount()==0){die('Invalid survey id');} // if surveyid is invalid then die to prevent errors at a later time + // Output starts here... + $surveysummary = ""; + + $surveyinfo = $sumresult1->FetchRow(); + + $surveyinfo = array_map('FlattenText', $surveyinfo); + //$surveyinfo = array_map('htmlspecialchars', $surveyinfo); + $activated = $surveyinfo['active']; + + //////////////////////////////////////////////////////////////////////// + // SURVEY MENU BAR + //////////////////////////////////////////////////////////////////////// + + $surveysummary .= "" //"
\n" + . "\n" + . "\n"; + + //SURVEY SUMMARY + if ($gid || $qid || $action=="deactivate"|| $action=="activate" || $action=="surveysecurity" + || $action=="surveyrights" || $action=="addsurveysecurity" || $action=="addusergroupsurveysecurity" + || $action=="setsurveysecurity" || $action=="setusergroupsurveysecurity" || $action=="delsurveysecurity" + || $action=="editsurveysettings"|| $action=="editsurveylocalesettings" || $action=="updatesurveysettingsandeditlocalesettings" || $action=="addgroup" || $action=="importgroup" + || $action=="ordergroups" || $action=="deletesurvey" || $action=="resetsurveylogic" + || $action=="importsurveyresources" || $action=="translate" || $action=="emailtemplates" + || $action=="exportstructure" || $action=="quotas" || $action=="copysurvey") {$showstyle="style='display: none'";} + if (!isset($showstyle)) {$showstyle="";} + $aAdditionalLanguages = GetAdditionalLanguagesFromSurveyID($surveyid); + $surveysummary .= "\n" + . "\n"; + $surveysummary2 = ""; + if ($surveyinfo['anonymized'] != "N") {$surveysummary2 .= $clang->gT("Answers to this survey are anonymized.")."
\n";} + else {$surveysummary2 .= $clang->gT("This survey is NOT anonymous.")."
\n";} + if ($surveyinfo['format'] == "S") {$surveysummary2 .= $clang->gT("It is presented question by question.")."
\n";} + elseif ($surveyinfo['format'] == "G") {$surveysummary2 .= $clang->gT("It is presented group by group.")."
\n";} + else {$surveysummary2 .= $clang->gT("It is presented on one single page.")."
\n";} + if ($surveyinfo['allowjumps'] == "Y") + { + if ($surveyinfo['format'] == 'A') {$surveysummary2 .= $clang->gT("No question index will be shown with this format.")."
\n";} + else {$surveysummary2 .= $clang->gT("A question index will be shown; participants will be able to jump between viewed questions.")."
\n";} + } + if ($surveyinfo['datestamp'] == "Y") {$surveysummary2 .= $clang->gT("Responses will be date stamped.")."
\n";} + if ($surveyinfo['ipaddr'] == "Y") {$surveysummary2 .= $clang->gT("IP Addresses will be logged")."
\n";} + if ($surveyinfo['refurl'] == "Y") {$surveysummary2 .= $clang->gT("Referrer URL will be saved.")."
\n";} + if ($surveyinfo['usecookie'] == "Y") {$surveysummary2 .= $clang->gT("It uses cookies for access control.")."
\n";} + if ($surveyinfo['allowregister'] == "Y") {$surveysummary2 .= $clang->gT("If tokens are used, the public may register for this survey")."
\n";} + if ($surveyinfo['allowsave'] == "Y" && $surveyinfo['tokenanswerspersistence'] == 'N') {$surveysummary2 .= $clang->gT("Participants can save partially finished surveys")."
\n";} + if ($surveyinfo['emailnotificationto'] != '') + { + $surveysummary2 .= $clang->gT("Basic email notification is sent to:")." {$surveyinfo['emailnotificationto']}
\n"; + } + if ($surveyinfo['emailresponseto'] != '') + { + $surveysummary2 .= $clang->gT("Detailed email notification with response data is sent to:")." {$surveyinfo['emailresponseto']}
\n"; + } + + if(bHasSurveyPermission($surveyid,'surveycontent','update')) + { + $surveysummary2 .= $clang->gT("Regenerate question codes:") + . " [gT("Are you sure you want to regenerate the question codes?\n\nWARNING:\nThis is safe if you only use the Conditions editor.\n\nHOWEVER, if you manually specified any relevance equations, regenerating the question codes will break all of that survey logic.","js")."')) {".get2post("$scriptname?action=renumberquestions&sid=$surveyid&style=straight")."}\" " + . ">".$clang->gT("Straight")."] " + . " [gT("Are you sure you want to regenerate the question codes?\n\nWARNING:\nThis is safe if you only use the Conditions editor.\n\nHOWEVER, if you manually specified any relevance equations, regenerating the question codes will break all of that survey logic.","js")."')) {".get2post("$scriptname?action=renumberquestions&sid=$surveyid&style=bygroup")."}\" " + . ">".$clang->gT("By Group")."]"; + $surveysummary2 .= "\n"; + } + $surveysummary .= "" + . "\n"; + if ( $modrewrite ) { + $tmp_url = $GLOBALS['publicurl'] . '/' . $surveyinfo['sid']; + $surveysummary .= "\n" + . "\n\n" + . "\n" + . "\n" + . "\n" + . "\n" + . "\n"; + if (trim($surveyinfo['faxto'])!='') + { + $surveysummary .="\n\n"; + } + $surveysummary .= "\n"; + $dateformatdetails=getDateFormatData($_SESSION['dateformat']); + if (trim($surveyinfo['startdate'])!= '') + { + $datetimeobj = new Date_Time_Converter($surveyinfo['startdate'] , "Y-m-d H:i:s"); + $startdate=$datetimeobj->convert($dateformatdetails['phpdate'].' H:i'); + } + else + { + $startdate="-"; + } + $surveysummary .= "\n" + . "\n"; + if (trim($surveyinfo['expires'])!= '') + { + $datetimeobj = new Date_Time_Converter($surveyinfo['expires'] , "Y-m-d H:i:s"); + $expdate=$datetimeobj->convert($dateformatdetails['phpdate'].' H:i'); + } + else + { + $expdate="-"; + } + $surveysummary .= "\n" + . "\n" + . "\n" + + . "\n"; + if (!$surveyinfo['language']) {$language=getLanguageNameFromCode($currentadminlang,false);} else {$language=getLanguageNameFromCode($surveyinfo['language'],false);} + $surveysummary .= "\n"; + + // get the rowspan of the Additionnal languages row + // is at least 1 even if no additionnal language is present + $additionnalLanguagesCount = count($aAdditionalLanguages); + $surveysummary .= "\n"; + $first=true; + if ($additionnalLanguagesCount == 0) + { + $surveysummary .= "\n"; + } + else + { + foreach ($aAdditionalLanguages as $langname) + { + if ($langname) + { + if (!$first) {$surveysummary .= "";} + $first=false; + $surveysummary .= "\n"; + } + } + } + if ($first) $surveysummary .= ""; + + if ($surveyinfo['surveyls_urldescription']==""){$surveyinfo['surveyls_urldescription']=htmlspecialchars($surveyinfo['surveyls_url']);} + $surveysummary .= "\n" + . "\n"; + $surveysummary .= "\n"; + $surveysummary .= "\n"; + + if ($activated == "Y") + { + $surveysummary .= "\n"; + } + $surveysummary .= "
" + . "".$clang->gT("Title").":{$surveyinfo['surveyls_title']} " + . "(".$clang->gT("ID")." {$surveyinfo['sid']})
" + . $clang->gT("Survey URL") ." (".getLanguageNameFromCode($surveyinfo['language'],false)."): $tmp_url/lang-".$surveyinfo['language'].""; + foreach ($aAdditionalLanguages as $langname) + { + $surveysummary .= " ".getLanguageNameFromCode($langname,false)." ".$clang->gT("Flag").""; + } + } else { + $tmp_url = $GLOBALS['publicurl'] . '/index.php?sid=' . $surveyinfo['sid']; + $surveysummary .= " $tmp_url&lang=".$surveyinfo['language'].""; + foreach ($aAdditionalLanguages as $langname) + { + $surveysummary .= " ".getLanguageNameFromCode($langname,false)." ".$clang->gT("Flag").""; + } + } + + $surveysummary .= "
" + . $clang->gT("Description:").""; + + LimeExpressionManager::StartProcessingPage(false,$rooturl,true); // so can click on syntax highlighting to edit questions + + if (trim($surveyinfo['surveyls_description'])!='') + { + templatereplace($surveyinfo['surveyls_description']); + $surveysummary .= LimeExpressionManager::GetLastPrettyPrintExpression(); + } + $surveysummary .= "
" + . $clang->gT("Welcome:").""; + + templatereplace($surveyinfo['surveyls_welcometext']); + $surveysummary .= LimeExpressionManager::GetLastPrettyPrintExpression(); + + $surveysummary .= "
" + . $clang->gT("Administrator:")." {$surveyinfo['admin']} ({$surveyinfo['adminemail']})
" + . $clang->gT("Fax to:")."{$surveyinfo['faxto']}"; + $surveysummary .= "
" + . $clang->gT("Start date/time:")."$startdate
" + . $clang->gT("Expiry date/time:")."$expdate
" + . $clang->gT("Template:")." {$surveyinfo['template']}
" + . $clang->gT("Base language:")."$language
" + . $clang->gT("Additional Languages").":-
 ".getLanguageNameFromCode($langname,false)."
" + . $clang->gT("End URL").":"; + if ($surveyinfo['surveyls_url']!="") + { + $surveysummary .=" {$surveyinfo['surveyls_urldescription']}"; + } + else + { + $surveysummary .="-"; + } + $surveysummary .="
" + . $clang->gT("Number of questions/groups").":$sumcount3/$sumcount2
" + . $clang->gT("Survey currently active").":"; + if ($activated == "N") + { + $surveysummary .= $clang->gT("No"); + } + else + { + $surveysummary .= $clang->gT("Yes"); + } + $surveysummary .="
" + . $clang->gT("Survey table name").":".$dbprefix."survey_$surveyid
" + . $clang->gT("Hints").":\n"; + + if ($activated == "N" && $sumcount3 == 0) + { + $surveysummary .= $clang->gT("Survey cannot be activated yet.")."
\n"; + if ($sumcount2 == 0 && bHasSurveyPermission($surveyid,'surveycontent','create')) + { + $surveysummary .= "[".$clang->gT("You need to add question groups")."]
"; + } + if ($sumcount3 == 0 && bHasSurveyPermission($surveyid,'surveycontent','create')) + { + $surveysummary .= "[".$clang->gT("You need to add questions")."]
"; + } + } + $surveysummary .= $surveysummary2 + . "
\n"; + } + else + { + include("access_denied.php"); + } +} + + +if (isset($surveyid) && $surveyid && $gid ) // Show the group toolbar +{ + // TODO: check that surveyid and thus baselang are always set here + $sumquery4 = "SELECT * FROM ".db_table_name('questions')." WHERE sid=$surveyid AND + gid=$gid AND language='".$baselang."'"; //Getting a count of questions for this survey + $sumresult4 = $connect->Execute($sumquery4); //Checked + $sumcount4 = $sumresult4->RecordCount(); + $grpquery ="SELECT * FROM ".db_table_name('groups')." WHERE gid=$gid AND + language='".$baselang."' ORDER BY ".db_table_name('groups').".group_order"; + $grpresult = db_execute_assoc($grpquery); //Checked + + // Check if other questions/groups are dependent upon this group +// $condarray=GetGroupDepsForConditions($surveyid,"all",$gid,"by-targgid"); + + $groupsummary = "\n"; + // $groupsummary .= "

 

"; //CSS Firefox 2 transition fix + + if ($qid || $action=='editgroup'|| $action=='addquestion') {$gshowstyle="style='display: none'";} + else {$gshowstyle="";} + + $groupsummary .= "\n" + . "\n" + . "\n\n\n"; + +// if (!is_null($condarray)) +// { +// $groupsummary .= "\n" +// . ""; +// } + } + $groupsummary .= "\n
" + . $clang->gT("Title").":" + . "{$grow['group_name']} ({$grow['gid']})
" + . $clang->gT("Description:").""; + if (trim($grow['description'])!='') + { + templatereplace($grow['description']); + $groupsummary .= LimeExpressionManager::GetLastPrettyPrintExpression(); + } + if (trim($grow['grelevance'])!='') + { + $groupsummary .= "
"; + $groupsummary .= $clang->gT("Relevance:").""; + templatereplace('{' . $grow['grelevance'] . '}'); + $groupsummary .= LimeExpressionManager::GetLastPrettyPrintExpression(); + } + $groupsummary .= "
" +// . $clang->gT("Questions with conditions to this group").":"; +// foreach ($condarray[$gid] as $depgid => $deprow) +// { +// foreach ($deprow['conditions'] as $depqid => $depcid) +// { +// //$groupsummary .= "[QID: ".$depqid."]"; +// $listcid=implode("-",$depcid); +// $groupsummary .= " [QID: ".$depqid."]"; +// } +// } +// $groupsummary .= "
\n"; +} + +//////////////////////////////////////////////////////////////////////////////// +// Question toolbar +//////////////////////////////////////////////////////////////////////////////// + + +if (isset($surveyid) && $surveyid && $gid && $qid) // Show the question toolbar +{ + // TODO: check that surveyid is set and that so is $baselang + //Show Question Details + //Count answer-options for this question + $qrq = "SELECT * FROM ".db_table_name('answers')." WHERE qid=$qid AND language='".$baselang."' ORDER BY sortorder, answer"; + $qrr = $connect->Execute($qrq); //Checked + $qct = $qrr->RecordCount(); + //Count sub-questions for this question + $sqrq= "SELECT * FROM ".db_table_name('questions')." WHERE parent_qid=$qid AND language='".$baselang."'"; + $sqrr= $connect->Execute($sqrq); //Checked + $sqct = $sqrr->RecordCount(); + + $qrquery = "SELECT * FROM ".db_table_name('questions')." WHERE gid=$gid AND sid=$surveyid AND qid=$qid AND language='".$baselang."'"; + $qrresult = db_execute_assoc($qrquery) or safe_die($qrquery."
".$connect->ErrorMsg()); //Checked + $questionsummary = "\n"; + $questionsummary .= "

 

"; //CSS Firefox 2 transition fix + + if ($action=='editansweroptions' || $action =="editsubquestions" || $action =="editquestion" || $action =="editdefaultvalues" || $action =="copyquestion") + { + $qshowstyle = "style='display: none'"; + } + else + { + $qshowstyle = ""; + } + $questionsummary .= "\n" + . "\n" + . "\n\n" + . "\n\n"; + if ($qrrow['preg']) + { + $questionsummary .= "\n\n"; + } + $qtypes = getqtypelist("", "array"); //qtypes = array(type code=>type description) + $questionsummary .= "\n\n"; + if ($qct == 0 && $qtypes[$qrrow['type']]['answerscales'] >0) + { + $questionsummary .= "\n"; + } + + // EDIT SUBQUESTIONS FOR THIS QUESTION BUTTON + if($sqct == 0 && $qtypes[$qrrow['type']]['subquestions'] >0) + { + $questionsummary .= "\n"; + } + + if ($qrrow['type'] == "M" or $qrrow['type'] == "P") + { + $questionsummary .= "" + . "\n" + . "\n"; + } + if (isset($qrrow['mandatory']) and ($qrrow['type'] != "X") and ($qrrow['type'] != "|")) + { + $questionsummary .= "" + . "\n" + . "\n"; + } +// if (!is_null($condarray)) +// { +// $questionsummary .= "" +// . "\n"; +// } + if (is_null($qrrow['relevance']) || trim($qrrow['relevance']) == '') + { + $rel2show = 1; + } + else + { + LimeExpressionManager::ProcessString("{" . $qrrow['relevance'] . "}", $qid); // tests Relevance equation so can pretty-print it + $rel2show = LimeExpressionManager::GetLastPrettyPrintExpression(); + $questionsummary .= "" + . "\n" + . "\n"; + } + $questionsummary .= "
" + . $clang->gT("Code:")."{$qrrow['title']}"; + if ($qrrow['type'] != "X") + { + if ($qrrow['mandatory'] == "Y") {$questionsummary .= ": (".$clang->gT("Mandatory Question").")";} + else {$questionsummary .= ": (".$clang->gT("Optional Question").")";} + } + $questionsummary .= "
"; + $questionsummary .= $clang->gT("Question:") . ""; + + // Color code the question, help, and relevance + + templatereplace($qrrow['question'],false,false,$qid); + $questionsummary .= FlattenText(LimeExpressionManager::GetLastPrettyPrintExpression(), false, 'UTF-8', true, true); + + $questionsummary .= "
" + . $clang->gT("Help:").""; + if (trim($qrrow['help'])!='') + { + templatereplace($qrrow['help'],false,false,$qid); + $questionsummary .= FlattenText(LimeExpressionManager::GetLastPrettyPrintExpression(), false, 'UTF-8', true, true); + } + $questionsummary .= "
" + . $clang->gT("Validation:")."{$qrrow['preg']}" + . "
" + .$clang->gT("Type:")."{$qtypes[$qrrow['type']]['description']}"; + $questionsummary .="
" + . "" + . $clang->gT("Warning").": ". $clang->gT("You need to add answer options to this question")." " + . "
" + . "" + . $clang->gT("Warning").": ". $clang->gT("You need to add subquestions to this question")." " + . "
" + . $clang->gT("Option 'Other':").""; + $questionsummary .= ($qrrow['other'] == "Y") ? ($clang->gT("Yes")) : ($clang->gT("No")) ; + $questionsummary .= "
" + . $clang->gT("Mandatory:").""; + $questionsummary .= ($qrrow['mandatory'] == "Y") ? ($clang->gT("Yes")) : ($clang->gT("No")) ; + $questionsummary .= "
" +// . $clang->gT("Other questions having conditions on this question:") +// . "\n"; +// foreach ($condarray[$qid] as $depqid => $depcid) +// { +// $listcid=implode("-",$depcid); +// $questionsummary .= " [QID: ".$depqid."]"; +// } +// $questionsummary .= "
" + . $clang->gT("Relevance:").""; + $questionsummary .= $rel2show; + $questionsummary .= "
"; + } +} +LimeExpressionManager::FinishProcessingPage(); + +// ============= EDIT ANSWER OPTIONS===================================== + + +if ($action=='editansweroptions') +{ + include("editansweroptions.php"); +} + + +// ============= EDIT SUBQUESTIONS ====================================== + +if ($action=='editsubquestions') +{ + include("editsubquestions.php"); +} + + + +// ************************************************* +// Survey Rights Start **************************** +// ************************************************* + +if($action == "addsurveysecurity") +{ + $addsummary = "
".$clang->gT("Add User")."
\n"; + $addsummary .= "
\n"; + + $query = "SELECT sid, owner_id FROM ".db_table_name('surveys')." WHERE sid = {$surveyid} AND owner_id = ".$_SESSION['loginID']." AND owner_id != ".$postuserid; + $result = db_execute_assoc($query); //Checked + if( ($result->RecordCount() > 0 && in_array($postuserid,getuserlist('onlyuidarray'))) || + $_SESSION['USER_RIGHT_SUPERADMIN'] == 1) + { + + if($postuserid > 0){ + + $isrquery = "INSERT INTO {$dbprefix}survey_permissions (sid,uid,permission,read_p) VALUES ({$surveyid},{$postuserid},'survey',1)"; + $isrresult = $connect->Execute($isrquery); //Checked + + if($isrresult) + { + $addsummary .= "
".$clang->gT("User added.")."
\n"; + $addsummary .= "
" + ."" + ."" + ."" + ."
\n"; + } + else + { + // Username already exists. + $addsummary .= "
".$clang->gT("Failed to add user.")."
\n" + . "
" . $clang->gT("Username already exists.")."
\n"; + $addsummary .= "
gT("Continue")."\"/>\n"; + } + } + else + { + $addsummary .= "
".$clang->gT("Failed to add user.")."
\n" + . "
" . $clang->gT("No Username selected.")."
\n"; + $addsummary .= "
gT("Continue")."\"/>\n"; + } + } + else + { + include("access_denied.php"); + } + $addsummary .= "
\n"; +} + + +if($action == "addusergroupsurveysecurity") +{ + $addsummary = "
".$clang->gT("Add user group")."
\n"; + $addsummary .= "
\n"; + + $query = "SELECT sid, owner_id FROM ".db_table_name('surveys')." WHERE sid = {$surveyid} AND owner_id = ".$_SESSION['loginID']; + $result = db_execute_assoc($query); //Checked + if( ($result->RecordCount() > 0 && in_array($postusergroupid,getsurveyusergrouplist('simpleugidarray'))) || $_SESSION['USER_RIGHT_SUPERADMIN'] == 1) + { + if($postusergroupid > 0){ + $query2 = "SELECT b.uid FROM (SELECT uid FROM ".db_table_name('survey_permissions')." WHERE sid = {$surveyid}) AS c RIGHT JOIN ".db_table_name('user_in_groups')." AS b ON b.uid = c.uid WHERE c.uid IS NULL AND b.ugid = {$postusergroupid}"; + $result2 = db_execute_assoc($query2); //Checked + if($result2->RecordCount() > 0) + { + while ($row2 = $result2->FetchRow()) + { + $uid_arr[] = $row2['uid']; + $isrquery = "INSERT INTO {$dbprefix}survey_permissions (sid,uid,permission,read_p) VALUES ({$surveyid}, {$row2['uid']},'survey',1) "; + $isrresult = $connect->Execute($isrquery); //Checked + if (!$isrresult) break; + } + + if($isrresult) + { + $addsummary .= "
".$clang->gT("User Group added.")."
\n"; + $_SESSION['uids'] = $uid_arr; + $addsummary .= "
" + ."" + ."" + ."" + ."
\n"; + } + else + { + // Error while adding user to the database + $addsummary .= "
".$clang->gT("Failed to add User Group.")."
\n"; + $addsummary .= "
gT("Continue")."\"/>\n"; + } + } + else + { + // no user to add + $addsummary .= "
".$clang->gT("Failed to add User Group.")."
\n"; + $addsummary .= "
gT("Continue")."\"/>\n"; + } + } + else + { + $addsummary .= "
".$clang->gT("Failed to add user.")."
\n" + . "
" . $clang->gT("No Username selected.")."
\n"; + $addsummary .= "
gT("Continue")."\"/>\n"; + } + } + else + { + include("access_denied.php"); + } + $addsummary .= "
\n"; +} + +if($action == "delsurveysecurity") +{ + $addsummary = "
".$clang->gT("Deleting User")."
\n"; + $addsummary .= "
\n"; + + $query = "SELECT sid, owner_id FROM ".db_table_name('surveys')." WHERE sid = {$surveyid} AND owner_id = ".$_SESSION['loginID']." AND owner_id != ".$postuserid; + $result = db_execute_assoc($query); //Checked + if($result->RecordCount() > 0 || $_SESSION['USER_RIGHT_SUPERADMIN'] == 1) + { + if (isset($postuserid)) + { + $dquery="DELETE FROM".db_table_name('survey_permissions')." WHERE uid={$postuserid} AND sid={$surveyid}"; // added by Dennis + $dresult=$connect->Execute($dquery); //Checked + + $addsummary .= "
".$clang->gT("Username").": ".sanitize_xss_string($_POST['user'])."

\n"; + $addsummary .= "
".$clang->gT("Success!")."
\n"; + } + else + { + $addsummary .= "
".$clang->gT("Could not delete user. User was not supplied.")."
\n"; + } + $addsummary .= "
gT("Continue")."\"/>\n"; + } + else + { + include("access_denied.php"); + } + $addsummary .= "
\n"; +} + +if($action == "setsurveysecurity" || $action == "setusergroupsurveysecurity") +{ + $query = "SELECT sid, owner_id FROM ".db_table_name('surveys')." WHERE sid = {$surveyid} AND owner_id = ".$_SESSION['loginID']; + if ($action == "setsurveysecurity") + { + $query.= " AND owner_id != ".$postuserid; + } + $result = db_execute_assoc($query); //Checked + if($result->RecordCount() > 0 || $_SESSION['USER_RIGHT_SUPERADMIN'] == 1) + { + $js_admin_includes[]='../scripts/jquery/jquery.tablesorter.min.js'; + $js_admin_includes[]='scripts/surveysecurity.js'; + if ($action == "setsurveysecurity") + { + $sUsername=$connect->GetOne("select users_name from ".db_table_name('users')." where uid={$postuserid}"); + $usersummary = "
".sprintf($clang->gT("Edit survey permissions for user %s"),"".$sUsername."")."
"; + } + else + { + $sUsergroupName=$connect->GetOne("select name from ".db_table_name('user_groups')." where ugid={$postusergroupid}"); + $usersummary = "
".sprintf($clang->gT("Edit survey permissions for group %s"),"".$sUsergroupName."")."
"; + } + $usersummary .= "
\n" + . "\n"; + + $usersummary .= "" + . "\n" + . "\n" + . "\n" + . "\n" + . "\n" + . "\n" + . "\n" + . "\n" + . "\n"; + + //content + + $aBasePermissions=aGetBaseSurveyPermissions(); + $oddcolumn=false; + foreach($aBasePermissions as $sPermissionKey=>$aCRUDPermissions) + { + $oddcolumn=!$oddcolumn; + $usersummary .= ""; + $usersummary .= ""; + $usersummary .= ""; + foreach ($aCRUDPermissions as $sCRUDKey=>$CRUDValue) + { + if (!in_array($sCRUDKey,array('create','read','update','delete','import','export'))) continue; + $usersummary .= "
".$clang->gT("Permission")."".$clang->gT("Create")."".$clang->gT("View/read")."".$clang->gT("Update")."".$clang->gT("Delete")."".$clang->gT("Import")."".$clang->gT("Export")."
{$aCRUDPermissions['title']}"; + + if ($CRUDValue) + { + if (!($sPermissionKey=='survey' && $sCRUDKey=='read')) + { + $usersummary .= "" + ."" + .""; + + if ($action=='setsurveysecurity') + { + $usersummary .=""; + } + else + { + $usersummary .=""; + } + $usersummary .= "\n"; + } + else + { + include("access_denied.php"); + } +} + +// This is the action to export the structure of a complete survey +if($action == "exportstructure") +{ + if(bHasSurveyPermission($surveyid,'surveycontent','export')) + { + $exportstructure = "
\n" + ."
" + .$clang->gT("Export Survey Structure")."\n

\n" + ."
    \n" + ."
  • " + .$clang->gT("LimeSurvey XML survey file (*.lss)")."
  • \n"; + + $exportstructure.="
  • " + .str_replace('queXML','queXML',$clang->gT("queXML Survey XML Format (*.xml)"))." " + ."
  • \n"; + + // XXX + //include("../config.php"); + + //echo $export4lsrc; + if($export4lsrc) + { + $exportstructure.="
  • " + ."
  • "; + } + $exportstructure.="
\n"; + + $exportstructure.="

\n" + ."\n" + ."\n"; + $exportstructure.="

\n"; + } +} + +// This is the action to export the structure of a group +if($action == "exportstructureGroup") +{ + if($export4lsrc === true && bHasSurveyPermission($surveyid,'survey','export')) + { + $exportstructure = "
\n" + ."
".$clang->gT("Export group structure")."\n
\n" + ."
    \n" + ."
  • \n"; + $exportstructure.="" + ."
  • \n"; + + // $exportstructure.="" + // ."\n"; + + // XXX + //include("../config.php"); + + //echo $export4lsrc; + if($export4lsrc) + { + $exportstructure.="
  • " + ."
  • \n"; + } + + $exportstructure.="
\n" + ."

\n" + ."\n" + ."\n" + ."\n" + ."\n"; + $exportstructure.="

\n"; + } + else + { + include('dumpgroup.php'); + } +} + +// This is the action to export the structure of a question +if($action == "exportstructureQuestion") +{ + if($export4lsrc === true && bHasSurveyPermission($surveyid,'survey','export')) + { + $exportstructure = "
\n" + ."
".$clang->gT("Export question structure")."\n
\n" + ."
    \n" + ."
  • \n"; + $exportstructure.="" + ."
  • \n"; + + // $exportstructure.="" + // ."\n"; + + // XXX + //include("../config.php"); + + //echo $export4lsrc; + if($export4lsrc) + { + $exportstructure.="
  • " + ."
  • \n"; + } + + $exportstructure.="
\n" + ."

\n" + ."\n" + ."\n" + ."\n" + ."\n" + ."\n"; + $exportstructure.="

\n"; + } + else + { + include('dumpquestion.php'); + } +} + +if($action == "surveysecurity") +{ + if(bHasSurveyPermission($surveyid,'survey','read')) + { + $aBaseSurveyPermissions=aGetBaseSurveyPermissions(); + $js_admin_includes[]='../scripts/jquery/jquery.tablesorter.min.js'; + $js_admin_includes[]='scripts/surveysecurity.js'; + + $query2 = "SELECT p.sid, p.uid, u.users_name, u.full_name FROM ".db_table_name('survey_permissions')." AS p INNER JOIN ".db_table_name('users')." AS u ON p.uid = u.uid + WHERE p.sid = {$surveyid} AND u.uid != ".$_SESSION['loginID'] ." + GROUP BY p.sid, p.uid, u.users_name, u.full_name + ORDER BY u.users_name"; + $result2 = db_execute_assoc($query2); //Checked + + $surveysecurity ="
".$clang->gT("Survey permissions")."
\n" + . "" + . "\n" + . "\n" + . "\n" + . "\n" + . "\n"; + foreach ($aBaseSurveyPermissions as $sPermission=>$aSubPermissions ) + { + $surveysecurity.="\n"; + } + $surveysecurity .= "\n"; + + // Foot first + + if (isset($usercontrolSameGroupPolicy) && + $usercontrolSameGroupPolicy == true) + { + $authorizedGroupsList=getusergrouplist('simplegidarray'); + } + + $surveysecurity .= "\n"; + if($result2->RecordCount() > 0) + { + // output users + $row = 0; + while ($PermissionRow = $result2->FetchRow()) + { + + $query3 = "SELECT a.ugid FROM ".db_table_name('user_in_groups')." AS a RIGHT OUTER JOIN ".db_table_name('users')." AS b ON a.uid = b.uid WHERE b.uid = ".$PermissionRow['uid']; + $result3 = db_execute_assoc($query3); //Checked + while ($resul3row = $result3->FetchRow()) + { + if (!isset($usercontrolSameGroupPolicy) || + $usercontrolSameGroupPolicy == false || + in_array($resul3row['ugid'],$authorizedGroupsList)) + { + $group_ids[] = $resul3row['ugid']; + } + } + + if(isset($group_ids) && $group_ids[0] != NULL) + { + $group_ids_query = implode(" OR ugid=", $group_ids); + unset($group_ids); + + $query4 = "SELECT name FROM ".db_table_name('user_groups')." WHERE ugid = ".$group_ids_query; + $result4 = db_execute_assoc($query4); //Checked + + while ($resul4row = $result4->FetchRow()) + { + $group_names[] = $resul4row['name']; + } + if(count($group_names) > 0) + $group_names_query = implode(", ", $group_names); + } + // else {break;} //TODO Commented by lemeur + $surveysecurity .= "\n"; + + $surveysecurity .= "\n"; + $surveysecurity .= "\n" + . "\n" + . "\n"; + + //Now show the permissions + foreach ($aBaseSurveyPermissions as $sPKey=>$aPDetails) { + unset($aPDetails['img']); + unset($aPDetails['description']); + unset($aPDetails['title']); + $iCount=0; + $iPermissionCount=0; + foreach ($aPDetails as $sPDetailKey=>$sPDetailValue) + { + if ($sPDetailValue && bHasSurveyPermission($surveyid,$sPKey,$sPDetailKey,$PermissionRow['uid']) && !($sPKey=='survey' && $sPDetailKey=='read')) $iCount++; + if ($sPDetailValue) $iPermissionCount++; + } + if ($sPKey=='survey') $iPermissionCount--; + if ($iCount==$iPermissionCount) { + $insert = "
 
"; + } + elseif ($iCount>0){ + $insert = "
 
"; + } + else + { + $insert = "
 
"; + } + $surveysecurity .= "\n"; + } + + $surveysecurity .= "\n"; + $row++; + } + } else { + $surveysecurity .= ""; //fix error on empty table + } + $surveysecurity .= "\n" + . "
".$clang->gT("Action")."".$clang->gT("Username")."".$clang->gT("User Group")."".$clang->gT("Full name")."\"<span".$aSubPermissions['title']."
".$aSubPermissions['description']."\" />
\n"; + if (bHasSurveyPermission($surveyid, 'surveysecurity', 'update')) + { + $surveysecurity .= "
" + ."" + ."" + ."" + ."" + ."
\n"; + } + if (bHasSurveyPermission($surveyid, 'surveysecurity', 'delete')) + { + $surveysecurity .= "
" + ."" + ."" + ."" + ."" + ."
"; + } + + + $surveysecurity .= "
{$PermissionRow['users_name']}"; + + if(isset($group_names) > 0) + { + $surveysecurity .= $group_names_query; + } + else + { + $surveysecurity .= "---"; + } + unset($group_names); + + $surveysecurity .= "\n{$PermissionRow['full_name']}\n$insert\n
\n"; + if (bHasSurveyPermission($surveyid, 'surveysecurity', 'delete')) + { + $surveysecurity.= "
    \n" + . "
  • \n" + . "gT("Please select a user first","js")."'); return false;}\"/>" + . "" + . "
\n" + . "
  • \n" + . "\n" + . "gT("Please select a user group first","js")."'); return false;}\" />" + . "\n" + . "
"; + } + + } + else + { + include("access_denied.php"); + } +} + +elseif ($action == "surveyrights") +{ + $addsummary = "
".$clang->gT("Edit survey permissions")."
\n"; + $addsummary .= "
\n"; + + if(isset($postuserid)){ + $query = "SELECT sid, owner_id FROM ".db_table_name('surveys')." WHERE sid = {$surveyid}"; + if ($_SESSION['USER_RIGHT_SUPERADMIN'] != 1) + { + $query.=" AND owner_id != {$postuserid} AND owner_id = ".$_SESSION['loginID']; + } + } + else{ + $sQuery = "SELECT owner_id FROM ".db_table_name('surveys')." WHERE sid = {$surveyid}"; + if ($_SESSION['USER_RIGHT_SUPERADMIN'] != 1) + { + $query.=" AND owner_id = ".$_SESSION['loginID']; + } + $iOwnerID=$connect->GetOne($sQuery); + } + + $aBaseSurveyPermissions=aGetBaseSurveyPermissions(); + $aPermissions=array(); + foreach ($aBaseSurveyPermissions as $sPermissionKey=>$aCRUDPermissions) + { + foreach ($aCRUDPermissions as $sCRUDKey=>$CRUDValue) + { + if (!in_array($sCRUDKey,array('create','read','update','delete','import','export'))) continue; + + if ($CRUDValue) + { + if(isset($_POST["perm_{$sPermissionKey}_{$sCRUDKey}"])){ + $aPermissions[$sPermissionKey][$sCRUDKey]=1; + } + else + { + $aPermissions[$sPermissionKey][$sCRUDKey]=0; + } + } + } + } + if (isset($postusergroupid) && $postusergroupid>0) + { + $sQuery = "SELECT uid from ".db_table_name('user_in_groups')." where ugid = {$postusergroupid} and uid<>{$_SESSION['loginID']} AND uid<>{$iOwnerID}"; + $oResult = db_execute_assoc($sQuery); //Checked + if($oResult->RecordCount() > 0) + { + while ($aRow = $oResult->FetchRow()) + { + SetSurveyPermissions($aRow['uid'], $surveyid, $aPermissions); + } + $addsummary .= "
".$clang->gT("Survey permissions for all users in this group were successfully updated.")."
\n"; + } + } + else + { + if(SetSurveyPermissions($postuserid, $surveyid, $aPermissions)) + { + $addsummary .= "
".$clang->gT("Survey permissions were successfully updated.")."
\n"; + } + else + { + $addsummary .= "
".$clang->gT("Failed to update survey permissions!")."
\n"; + } + + } + $addsummary .= "
gT("Continue")."\"/>\n"; + $addsummary .= "
\n"; +} + +// ************************************************* +// Survey Rights End **************************** +// ************************************************* + +// Edit survey general settings + +if ($action == "editsurveysettings" || $action == "newsurvey") +{ + include("editsurveysettings.php"); +} + + + + +// Edit survey text elements + +if ($action == "updatesurveysettingsandeditlocalesettings" || $action == "editsurveylocalesettings") // Edit survey step 2 - editing language dependent settings +{ + include("editsurveytextelements.php"); +} + +if ($action == "translate") // Translate survey +{ + if(bHasSurveyPermission($surveyid,'translation','read')) + { + $translateoutput .="
".$clang->gT("Quick-translate survey")."
\n"; + } + else + { + include("access_denied.php"); + } + +} + +if ($action == "emailtemplates") +{ + include("editemailtemplates.php"); +} + + + + +if($action == "quotas") + { + include("quota.php"); + } + +function replacenewline ($texttoreplace) +{ + $texttoreplace = str_replace( "\n", '
', $texttoreplace); + // $texttoreplace = htmlentities( $texttoreplace, ENT_QUOTES, UTF-8); + $new_str = ''; + + for($i = 0; $i < strlen($texttoreplace); $i++) { + $new_str .= '\x' . dechex(ord(substr($texttoreplace, $i, 1))); + } + + return $new_str; +} + +/** + * showadminmenu() function returns html text for the administration button bar + * + * @global string $homedir + * @global string $scriptname + * @global string $surveyid + * @global string $setfont + * @global string $imageurl + * @return string $adminmenu + */ +function showadminmenu() +{ + global $homedir, $scriptname, $surveyid, $setfont, $imageurl, $clang, $debug, $action, $updateavailable, $updatebuild, $updateversion, $updatelastcheck, $databasetype; + + $adminmenu = "\n"; + // $adminmenu .= "

 

"; //CSS Firefox 2 transition fix + if (!isset($action) && !isset($surveyid) && count(getsurveylist(true))==0) + { + $adminmenu.= '
' + .'

'.sprintf($clang->gT("Welcome to %s!"),'LimeSurvey').'

' + .'

'.$clang->gT("Some piece-of-cake steps to create your very own first survey:").'
' + .'

    ' + .'
  1. '.sprintf($clang->gT('Create a new survey clicking on the %s icon in the upper right.'),"". $clang->gT("Add survey")."").'
  2. ' + .'
  3. '.$clang->gT('Create a new question group inside your survey.').'
  4. ' + .'
  5. '.$clang->gT('Create one or more questions inside the new question group.').'
  6. ' + .'
  7. '.sprintf($clang->gT('Done. Test your survey using the %s icon.'),"". $clang->gT("Test survey")."").'
  8. ' + .'


 
'; + } + + } + return $adminmenu; +}