From fc8a2c55ca97879ee6cc6a21a52627365a91ee75 Mon Sep 17 00:00:00 2001 From: Jason Cleeland Date: Sun, 5 Dec 2004 22:36:59 +0000 Subject: [PATCH] New Administration Front end... including related classes for "tree navigator" and "drop down menus". This front end runs in parallel with the old frontend "admin.php", but will eventually replace it. git-svn-id: file:///Users/Shitiz/Downloads/lssvn/trunk/unstable@1273 b72ed6b6-b9f8-46b5-92b4-906544132732 --- admin/dbedit.php | 429 +++++++++ admin/index.php | 463 ++++++++++ admin/navigator.php | 2028 +++++++++++++++++++++++++++++++++++++++++ admin/phpsurveyor.css | 245 +++++ admin/results.php | 550 +++++++++++ 5 files changed, 3715 insertions(+) create mode 100644 admin/dbedit.php create mode 100644 admin/index.php create mode 100644 admin/navigator.php create mode 100644 admin/phpsurveyor.css create mode 100644 admin/results.php diff --git a/admin/dbedit.php b/admin/dbedit.php new file mode 100644 index 00000000000..3bd7b30c1ce --- /dev/null +++ b/admin/dbedit.php @@ -0,0 +1,429 @@ +>> PHP Surveyor # + ############################################################# + # > Author: Jason Cleeland # + # > E-mail: jason@cleeland.org # + # > Mail: Box 99, Trades Hall, 54 Victoria St, # + # > CARLTON SOUTH 3053, AUSTRALIA + # > Date: 20 February 2003 # + # # + # This set of scripts allows you to develop, publish and # + # perform data-entry on surveys. # + ############################################################# + # # + # Copyright (C) 2003 Jason Cleeland # + # # + # This program is free software; you can redistribute # + # it and/or modify it under the terms of the GNU General # + # Public License as published by the Free Software # + # Foundation; either version 2 of the License, or (at your # + # option) any later version. # + # # + # This program is distributed in the hope that it will be # + # useful, but WITHOUT ANY WARRANTY; without even the # + # implied warranty of MERCHANTABILITY or FITNESS FOR A # + # PARTICULAR PURPOSE. See the GNU General Public License # + # for more details. # + # # + # You should have received a copy of the GNU General # + # Public License along with this program; if not, write to # + # the Free Software Foundation, Inc., 59 Temple Place - # + # Suite 330, Boston, MA 02111-1307, USA. # + ############################################################# +*/ +if (call_user_func($auth_function)) { + switch($dbaction){ + case "addlabelset": + $lid=addLabel($dbprefix); + break; + case "addattribute": + addAttribute($qid, $dbprefix); + break; + case "editattribute": + updateAttribute($qid, $dbprefix); + break; + case "deleteattribute": + delAttribute($qid, $dbprefix); + break; + case "deleteassessment": + delAssessment($sid, $dbprefix); + break; + case "addassessment": + addAssessment($sid, $dbprefix); + break; + case "editassessment": + updateAssessment($sid, $dbprefix); + break; + case "addanswer": + addAnswer($qid, $dbprefix); + break; + case "deleteanswer": + delAnswer($qid, $dbprefix); + break; + case "updateanswers": + updateAnswer($qid, $dbprefix); + break; + case "moveanswer": + moveAnswer($qid, $dbprefix); + break; + case "editsurvey": + case "addsurvey": + $sid=editSurvey($sid, $dbprefix, $dbaction); + break; + case "editgroup": + case "addgroup": + $gid=editGroup($sid, $gid, $dbprefix, $dbaction); + break; + case "editquestion": + case "addquestion": + $qid=editQuestion($sid, $gid, $qid, $dbprefix, $dbaction); + break; + case "renumbergroup": + case "renumbersurvey": + renumber($sid, $gid, $dbprefix); + break; + } // switch +} + +function renumber($sid, $gid=null, $dbprefix) { + $question_number=1; + $gselect="SELECT * + FROM {$dbprefix}questions, {$dbprefix}groups + WHERE {$dbprefix}questions.gid={$dbprefix}groups.gid + AND {$dbprefix}questions.sid=$sid\n"; + if (!empty($gid)) { + $gselect .= "AND {$dbprefix}questions.gid=$gid\n"; + } + $gselect .= "ORDER BY group_name, title"; + $gresult=mysql_query($gselect) or die (mysql_error()); + $grows = array(); //Create an empty array in case mysql_fetch_array does not return any rows + while ($grow = mysql_fetch_array($gresult)) {$grows[] = $grow;} // Get table output into array + usort($grows, 'CompareGroupThenTitle'); + $count=count($grows); + $len=strlen($count); + foreach($grows as $grow) { + $sortednumber=sprintf("%0{$len}d", $question_number); + $usql="UPDATE {$dbprefix}questions\n" + ."SET title='".$sortednumber."'\n" + ."WHERE qid=".$grow['qid']; + //echo "[$usql]"; + $uresult=mysql_query($usql) or die("Error:".mysql_error()); + $question_number++; + } +} + +function addLabel($dbprefix) { + $query = "INSERT INTO {$dbprefix}labelsets + (`label_name`) + VALUES ('".auto_escape($_POST['label_name'])."')"; + $result=mysql_query($query); + return mysql_insert_id(); +} + +function editSurvey($sid, $dbprefix, $dbaction) { + $tablefields=array("short_title", + "description", + "admin", + "active", + "welcome", + "expires", + "adminemail", + "private", + "faxto", + "format", + "template", + "url", + "urldescrip", + "language", + "datestamp", + "usecookie", + "notification", + "allowregister", + "attribute1", + "attribute2", + "email_invite_subj", + "email_invite", + "email_remind_subj", + "email_remind", + "email_register_subj", + "email_register", + "email_confirm_subj", + "email_confirm", + "allowsave", + "autonumber_start", + "autoredirect", + "allowprev"); + switch ($dbaction) { + case "editsurvey": + $query = "UPDATE {$dbprefix}surveys + SET "; + foreach ($tablefields as $tf) { + if (isset($_POST[$tf])) { + $querys[] = "$tf = '".auto_escape($_POST[$tf])."'"; + } + } + $query .= implode(",\n", $querys); + $query .= "\nWHERE sid=$sid"; + $result = mysql_query($query); + break; + case "addsurvey": + $query = "INSERT INTO {$dbprefix}surveys\n"; + foreach ($tablefields as $tf) { + if (isset($_POST[$tf])) { + $fields[]=$tf; + $values[]=mysql_escape_string($_POST[$tf]); + } + } + $query .= "(".implode(",\n", $fields).")"; + $query .= "\nVALUES ('"; + $query .= implode("',\n'", $values)."')"; + if ($result = mysql_query($query)) { + $sid = mysql_insert_id(); + } else { + echo $query."
".mysql_error(); + } + break; + } + return $sid; +} + +function editGroup($sid, $gid, $dbprefix, $dbaction) { + $tablefields=array("sid", + "group_name", + "description"); + switch($dbaction) { + case "editgroup": + $query = "UPDATE {$dbprefix}groups + SET "; + foreach($tablefields as $tf) { + if (isset($_POST[$tf])) { + $querys[]="$tf = '".auto_escape($_POST[$tf])."'"; + } + } + $query .= implode(",\n", $querys); + $query .= "\nWHERE gid=$gid"; + $result = mysql_query($query); + + break; + case "addgroup": + $query = "INSERT INTO {$dbprefix}groups\n"; + foreach ($tablefields as $tf) { + if (isset($_POST[$tf])) { + $fields[]=$tf; + $values[]=auto_escape($_POST[$tf]); + } + } + $query .= "(".implode(",\n", $fields).")"; + $query .= "\nVALUES ('"; + $query .= implode("',\n'", $values)."')"; +// echo $query; + if ($result = mysql_query($query)) { + $gid = mysql_insert_id(); + } else { + echo $query."
".mysql_error(); + } + break; + } + return $gid; +} + +function editQuestion($sid, $gid, $qid, $dbprefix, $dbaction) { + $tablefields=array("sid", + "gid", + "type", + "title", + "question", + "help", + "other", + "mandatory", + "lid", + "preg"); + switch($dbaction) { + case "editquestion": + $query = "UPDATE {$dbprefix}questions + SET "; + foreach($tablefields as $tf) { + if (isset($_POST[$tf])) { + $querys[]="$tf = '".auto_escape($_POST[$tf])."'"; + } + } + $query .= implode(",\n", $querys); + $query .= "\nWHERE qid=$qid"; +// echo $query; + $result = mysql_query($query); + + break; + case "addquestion": + $query = "INSERT INTO {$dbprefix}questions\n"; + foreach ($tablefields as $tf) { + if (isset($_POST[$tf])) { + $fields[]=$tf; + $values[]=auto_escape($_POST[$tf]); + } + } + $query .= "(".implode(",\n", $fields).")"; + $query .= "\nVALUES ('"; + $query .= implode("',\n'", $values)."')"; +// echo $query; + if ($result = mysql_query($query)) { + $qid = mysql_insert_id(); + } else { + echo $query."
".mysql_error(); + } + break; + } + return $qid; +} + +function addAttribute($qid, $dbprefix) { + $query = "INSERT INTO {$dbprefix}question_attributes + (qid, attribute, value) + VALUES ($qid, + '".$_POST['attribute']."', + '".$_POST['value']."')"; + $result = mysql_query($query); +} + +function delAttribute($qid, $dbprefix) { + $query = "DELETE FROM {$dbprefix}question_attributes + WHERE qid=$qid + AND qaid=".$_GET['qaid']; + $result = mysql_query($query); +} + +function updateAttribute($qid, $dbprefix) { + $query = "UPDATE {$dbprefix}question_attributes + SET value='".$_POST['value']."' + WHERE qaid=".$_POST['qaid']; + $result = mysql_query($query); +} + +function addAnswer($qid, $dbprefix) { + $where=array("qid"=>$qid, + "code"=>$_POST['code']); + + if (matchExists("{$dbprefix}answers", $where) !== true) { + $query = "INSERT INTO {$dbprefix}answers + (qid, code, answer, default_value, sortorder) + VALUES ($qid, + '".$_POST['code']."', + '".mysql_escape_string($_POST['answer'])."', + '".$_POST['default_value']."', + '".sprintf("%05d", $_POST['sortorder'])."')"; + $result = mysql_query($query); + } else { + echo "\n"; + } +} + +function delAssessment($sid, $dbprefix) { + $query = "DELETE FROM {$dbprefix}assessments + WHERE id=".$_POST['id']." + AND sid=$sid"; + $result = mysql_query($query); +} + +function updateAssessment($sid, $dbprefix) { + $query = "UPDATE {$dbprefix}assessments + SET scope='".$_POST['scope']."', + gid=".$_POST['assessment_gid'].", + name='".auto_escape($_POST['name'])."', + minimum='".$_POST['minimum']."', + maximum='".$_POST['maximum']."', + message='".auto_escape($_POST['message'])."', + link='".auto_escape($_POST['link'])."' + WHERE id=".$_POST['id']; + $result=mysql_query($query); +} + +function addAssessment($sid, $dbprefix) { + $query = "INSERT INTO {$dbprefix}assessments + (sid, scope, gid, name, minimum, maximum, message, link) + VALUES + ($sid, + '".$_POST['scope']."', + ".$_POST['assessment_gid'].", + '".auto_escape($_POST['name'])."', + '".$_POST['minimum']."', + '".$_POST['maximum']."', + '".auto_escape($_POST['message'])."', + '".auto_escape($_POST['link'])."')"; + $result = mysql_query($query); +} + +function delAnswer($qid, $dbprefix) { + $query = "DELETE FROM {$dbprefix}answers + WHERE qid=$qid + AND code='".returnglobal('code')."'"; + $result = mysql_query($query); +} + +function updateAnswer($qid, $dbprefix) { + //echo "Hi"; + //echo "
";print_r($_POST); echo "
"; + //FIRST: Renumber all the existing answers (we can fix if a problem occurs) + $query = "UPDATE {$dbprefix}answers SET qid=99999999 WHERE qid=$qid"; + $result = mysql_query($query) or die(mysql_error()); + foreach($_POST['code'] as $key=>$code) { + $where=array("qid"=>$qid, + "code"=>$code); + if (matchExists("{$dbprefix}answers", $where) !== true) { + $insert="INSERT INTO {$dbprefix}answers + (qid, code, answer, default_value, sortorder) + VALUES + ($qid, '$code', '".auto_escape($_POST['answer'][$key])."', '".$_POST['default_value'][$key]."', '".$_POST['sortorder'][$key]."')"; + $result = mysql_query($insert) or die(mysql_error()); + } else { + $query = "DELETE FROM {$dbprefix}answers WHERE qid=$qid"; + $result = mysql_query($query) or die(mysql_error()); + $query = "UPDATE {$dbprefix}answers SET qid=$qid WHERE qid=99999999"; + $result = mysql_query($query) or die(mysql_error()); + echo "\n"; + } + } + $query = "DELETE FROM {$dbprefix}answers WHERE qid=99999999"; + $result = mysql_query($query) or die(mysql_error()); +} + +function moveAnswer($qid, $dbprefix) { + $newsortorder=sprintf("%05d", $_GET['sortorder']+$_GET['moveorder']); + $query = "UPDATE {$dbprefix}answers + SET sortorder='PEND' + WHERE qid=$qid + AND sortorder='$newsortorder'"; + $result = mysql_query($query); + $query = "UPDATE {$dbprefix}answers + SET sortorder='$newsortorder' + WHERE qid=$qid + AND sortorder='".$_GET['sortorder']."'"; + $result = mysql_query($query); + $query = "UPDATE {$dbprefix}answers + SET sortorder='".$_GET['sortorder']."' + WHERE qid=$qid + AND sortorder='PEND'"; + $result = mysql_query($query); +} + +function matchExists($table, $where) { + //This function will return true if a duplicate entry is found + //and false if one is not + //$table = tablename + //$duplicates = keyed array containing "field"=>"value" where duplicates are being searched for + //$where = keyed array containing "field"=>"value" for the other conditions of the search + $query = "SELECT * FROM $table + WHERE "; + foreach ($where as $key=>$val) { + $wheres[]= "$key = '$val'"; + } + $query .= implode("\nAND ", $wheres); + $result = mysql_query($query); + if (mysql_num_rows($result) > 0) { + return true; + } else { + return false; + } +} + +?> \ No newline at end of file diff --git a/admin/index.php b/admin/index.php new file mode 100644 index 00000000000..98277913c22 --- /dev/null +++ b/admin/index.php @@ -0,0 +1,463 @@ +>> PHP Surveyor # + ############################################################# + # > Author: Jason Cleeland # + # > E-mail: jason@cleeland.org # + # > Mail: Box 99, Trades Hall, 54 Victoria St, # + # > CARLTON SOUTH 3053, AUSTRALIA + # > Date: 20 February 2003 # + # # + # This set of scripts allows you to develop, publish and # + # perform data-entry on surveys. # + ############################################################# + # # + # Copyright (C) 2003 Jason Cleeland # + # # + # This program is free software; you can redistribute # + # it and/or modify it under the terms of the GNU General # + # Public License as published by the Free Software # + # Foundation; either version 2 of the License, or (at your # + # option) any later version. # + # # + # This program is distributed in the hope that it will be # + # useful, but WITHOUT ANY WARRANTY; without even the # + # implied warranty of MERCHANTABILITY or FITNESS FOR A # + # PARTICULAR PURPOSE. See the GNU General Public License # + # for more details. # + # # + # You should have received a copy of the GNU General # + # Public License along with this program; if not, write to # + # the Free Software Foundation, Inc., 59 Temple Place - # + # Suite 330, Boston, MA 02111-1307, USA. # + ############################################################# +*/ +require_once("config.php"); + +if (!isset($sid)) {$sid=returnglobal('sid');} +if (!isset($gid)) {$gid=returnglobal('gid');} +if (!isset($qid)) {$qid=returnglobal('qid');} +if (!isset($lid)) {$lid=returnglobal('lid');} +if (!isset($code)) {$code=returnglobal('code');} +if (!isset($action)) {$action=returnglobal('action');} +if (!isset($ok)) {$ok=returnglobal('ok');} +if (!isset($user)) {$user=returnglobal('user');} +if (!isset($pass)) {$pass=returnglobal('pass');} +if (!isset($dbaction)) {$dbaction=returnglobal('dbaction');} + +sendcacheheaders(); + +//SOME SETTINGS - TO PUT INTO CONFIG.PHP EVENTUALLY +$navigation['dropdownaction'] = "onMouseOver"; +$navigation['defaultqdisplay'] = 0; + +$auth_function = "is_authorised"; + +//TRANSLATIONS: +define("_SN_TITLE", "Survey Navigator"); +define("_NEVER", "Never"); +define("_SN_OPTIONS", "Options"); +define("_SN_ACTIONS", "Actions"); +define("_SN_OTHER", "Other"); +define("_SN_QUICKDISPLAY", "Brief"); +define("_SN_EXCLUDE", "Exclude"); +define("_SN_GROUPS", "Groups"); +define("_SN_QUESTIONS", "Questions"); +define("_SN_SV_GENERAL", "General"); +define("_SN_SV_EXTRA", "Extra"); +define("_SN_SV_EMAIL", "Email"); +define("_SN_SV_MISC", "Miscellaneous"); +define("_SN_CANNOTCHANGE_SURVEYACTIVE", "Cannot change in active survey"); +define("_SN_ACTIVESURVEYOPTIONS", "Active Survey Options"); +define("_SN_ACTIVEQUESTIONOPTIONS", "Active Question Options"); +define("_SN_RESULTS", "Summary of Current Results"); +define("_SN_RECORDS", "Records"); +define("_Q_PREVIEWQUESTION", "View a preview of this question"); +define("_Q_VIEWSUMMARY", "View Summary for this Question"); +define("_PR_HEADING", "Preview"); +define("_IMPORT", "Import"); +define("_CREATE", "Create"); +define("_AUTHENTICATION_BT", "Authentication"); +define("_SYSTEM_BT", "System Summary"); +define("_G_RENUMBER_BT", "Renumber Questions in Group"); +define("_G_RENUMBERGROUPWARNING", "This will consecutively renumber all questions in this group. Are you sure you want to continue?"); +define("_S_RENUMBER_BT", "Renumber Questions in Survey"); +define("_S_RENUMBERSURVEYWARNING", "This will consecutively renumber all questions in this survey. Are you sure you want to continue?"); + +//This overrides the common.php setting until this gets merged back.. +$htmlheader = "\n\n" + . "$sitename\n" + . "\n" + . "\n" + . "\n" + . "\n" + . "\n\n"; +// . "\n" +// . "\t\n" +// . "\t\t\n" +// . "\t\n" +// . "
\n" +// . "\t\t\t$setfont$sitename\n" +// . "\t\t
\n"; +$scriptname = "index.php"; + +echo $htmlheader; + +echo "\n"; + +// CHECK IF FIRST USE - ie Database Exists! +if (!mysql_selectdb ($databasename, $connect)) + { + echo "
\n" + ."\n" + ."\t\n" + ."\t
" + ._SETUP."
$setfont\n" + ."" + ._ERROR."
\n" + ._ST_NODB1."


\n" + ._ST_NODB2."
\n" + ._ST_NODB3."

\n" + ._ST_NODB4." $databasename
\n" + ."
\n" + ."
\n" + ."\n\n"; + exit; + } +else + { + //OPEN DATABASE CONNECTION + $db = mysql_selectdb($databasename, $connect); + //DB EXISTS, CHECK FOR APPROPRIATE TABLES + checkfortables(); + } + + +if ($action == "activate") + { + include("activate.php"); + exit; + } +if ($action == "deactivate") + { + include("deactivate.php"); + exit; + } + +if ($action == "importsurvey") + { + include("importsurvey.php"); + exit; + } +if ($action == "importgroup") + { + include("importgroup.php"); + exit; + } +if ($action == "importquestion") + { + include("importquestion.php"); + exit; + } + +//CHECK THAT SURVEYS MARKED AS ACTIVE ACTUALLY HAVE MATCHING TABLES +checkactivations(); + + +//VARIOUS DATABASE OPTIONS/ACTIONS PERFORMED HERE +//if ($action == "delsurvey" || $action == "delgroup" || $action == "delgroupall" || +// $action=="delquestion" || $action=="delquestionall" || $action == "insertnewsurvey" || +// $action == "copynewquestion" || $action == "insertnewgroup" || +// $action == "insertnewquestion" || $action == "updatesurvey" || $action=="updategroup" || +// $action=="updatequestion" || $action == "modanswer" || $action == "renumberquestions" || +// $action == "delattribute" || $action == "addattribute" || $action == "editattribute") +// { +// include("database.php"); +// } + + +// WE DRAW THE PRETTY SCREEN HERE + +//include("html.php"); + + +//$cellstyle = "style='border: 1px inset #000080'"; +echo "\n" + ."\t\n" + ."\t\t\n"; + +helpscreen(); + +echo "\t\n"; +echo "
\n"; + //."\t\t\t\n"; + +echo adminmenu(); + +if (isset($dbaction) && $dbaction != "") { + //Database modifications to occur + include("dbedit.php"); +} + +//Creates new "mastertable" that includes navigator +include("navigator.php"); +echo " + \n"; +// helpscreen(); +// echo "\t\n" +// ."
"; +surveyNavigator($sid, $gid, $qid); +echo ""; +// + +//if ($action == "newsurvey") +// { +// echo "$newsurvey\n" +// ."\t\t
\n" +// .htmlfooter("instructions.html", "Using PHPSurveyors Admin Script"); +// exit; +// } + +//if (isset($surveysummary)) {echo $surveysummary;} +//if (isset($sid) && $sid) {echo javadropdown($sid, $gid, $qid);} +echo javadropdown($sid, $gid, $qid); +if (!empty($sid) && call_user_func($auth_function)) { + surveyDetails($sid, $gid, $qid); +} + +//if (isset($sid) && $sid) {surveyDetails($sid, $gid, $qid);} +//if (isset($gid) && $gid) {groupDetails($sid, $gid, $qid);} +if (!empty($gid) && call_user_func($auth_function)) {groupDetails($sid, $gid, $qid);} +if (!empty($qid) && call_user_func($auth_function)) {questionDetails($sid, $gid, $qid, $action);} + +if (isset($action) && call_user_func($auth_function)) { + switch($action) { + case "editsurvey": + case "addsurvey": + surveyEdit($sid); + break; + case "editgroup": + case "addgroup": + groupEdit($sid, $gid); + break; + case "editquestion": + case "addquestion": + case "copyquestion"; + questionEdit($sid, $gid, $qid); + break; + case "showlabelsets": + labelsetDetails($lid); + break; + case "addlabel": + labelAdd(); + break; + case "showsummary": + if(!empty($qid)) { + questionResultSummary($sid, $gid, $qid); + } + break; + case "showattributes": + if (!empty($qid)) { + attributeDetails($sid, $gid, $qid); + } + break; + case "showanswers": + if (!empty($qid)) { + answerDetails($sid, $gid, $qid); + } + break; + case "showassessments": + if (!empty($sid)) { + assessmentDetails($sid); + } + break; + case "checksettings": + case "changelang": + checksettings($dbprefix); + break; + case "showpreview": + showPreview($sid, $gid, $qid); + break; + } +} +//if (isset($action) && $action == "editsurvey" && isset($sid)) {surveyEdit($sid);} +//if (isset($action) && $action == "showattributes" && isset($qid) && $qid) {attributeDetails($sid, $gid, $qid);} +//if (isset($action) && $action == "showanswers" && isset($qid) && $qid) {answerDetails($sid, $gid, $qid);} + +//if (isset($cssummary)) {echo $cssummary;} +//if (isset($usersummary)) {echo $usersummary;} +//if (isset($addsummary)) {echo $addsummary;} +//if (isset($editsurvey)) {echo $editsurvey;} +//if (isset($newgroup)) {echo $newgroup;} +//if (isset($groupsummary)) {echo $groupsummary;} +//if (isset($editgroup)) {echo $editgroup;} +//if (isset($newquestion)) {echo $newquestion;} +//if (isset($questionsummary)) {echo $questionsummary;} +//if (isset($editquestion)) {echo $editquestion;} +//if (isset($newanswer)) {echo $newanswer;} +//if (isset($answersummary)) {echo $answersummary;} +//if (isset($vasummary)) {echo $vasummary;} +//if (isset($editanswer)) {echo $editanswer;} +echo "\t\t
\n"; + +//Closes off master table that includes new navigator +echo ""; +// + +echo footer("instructions.html", "Using PHPSurveyors Admin Script"); + +function helpscreen() + { + global $homeurl, $langdir, $setfont, $imagefiles; + global $sid, $gid, $qid, $action; + echo "\t\t\n" + ."\t\t\t
" + ."\n" + ."\t\t\t\t\n" + ."\t\t\t\t\t\n" + ."\t\t\t\t\n" + ."\t\t\t\t\n" + ."\t\t\t\t\t\n" + ."\t\t\t\t\n" + ."\t\t\t\t\n" + ."\t\t\t\t\t" + ."\t\t\t\t\n" + ."\t\t\t
\n" + ."\t\t\t\t\t\t$setfont" + ._HELP."\n" + ."\t\t\t\t\t
\n" + ."\t\t\t\t\t\t-\n" + ."\t\t\t\t\t\t\n" + ."\t\t\t\t\t
\n"; + //determine which help document to show + if (!$sid && $action != "editusers") + { + $helpdoc = "$langdir/admin.html"; + } + elseif (!$sid && $action=="editusers") + { + $helpdoc = "$langdir/users.html"; + } + elseif ($sid && !$gid) + { + $helpdoc = "$langdir/survey.html"; + } + elseif ($sid && $gid && !$qid) + { + $helpdoc = "$langdir/group.html"; + } + //elseif ($sid && $gid && $qid && !$_GET['viewanswer'] && !$_POST['viewanswer']) + elseif ($sid && $gid && $qid && !returnglobal('viewanswer')) + { + $helpdoc = "$langdir/question.html"; + } + elseif ($sid && $gid && $qid && (returnglobal('viewanswer'))) + { + $helpdoc = "$langdir/answer.html"; + } + echo "\t\t\t\t\t\t\n" + ."\t\t\t\t\t
\n" + ."\t\t\n"; + } + +function multiStringSearch($needle, $haystack, $method = "full") { + //Function returns true if any of the strings found in the needle array + //exist in the haystack. $method determines whether the needle is merely + //a "part" of the haystack (like a sql "%something%" search, or if it must + //be a full match. Values: "full" or "partial" + if ($method != "partial") {$method="full";} + foreach ($needle as $item) { + if ($method == "partial") { + if (ereg($item, $haystack)) { + return true; + } + } + if ($method == "full") { + if ($item == $haystack) { + return true; + } + } + } + return false; +} + +function adminmenu() { + global $accesscontrol, $homedir, $scriptname, $sid, $setfont, $imagefiles, $navigation; + echo " + +
+ + + + + +
+ + + + + + + + + +
+ + + +
+ + "._SN_OPTIONS." + "._SN_ACTIONS." + "._SN_OTHER." + +
+
"; +} + +function footer($url, $explanation) + { + global $versionnumber, $setfont, $imagefiles; + $htmlfooter = "\n" + . "\t\n" + . "\t\t\n" + . "\t\n" + . "
\n" + . "\t\t\t$setfont\n" + . "\t\t\tHelp - $explanation\n" + . "\t\t\tHelp - $explanation\n" + . "Ver $versionnumber\n" + . "\t\t
\n" + . "\n"; + return $htmlfooter; + } + +function is_authorised() { + return true; +} +?> \ No newline at end of file diff --git a/admin/navigator.php b/admin/navigator.php new file mode 100644 index 00000000000..c9f42354e26 --- /dev/null +++ b/admin/navigator.php @@ -0,0 +1,2028 @@ +"folder.gif", "cssClass"=>"auto", "autostyles"=>array("smalltextBold", "smallitalic", "smalltext")); + $nodePropertiesActive = array("icon"=>"activefolder.gif", "cssClass"=>"auto", "autostyles"=>array("smalltextBold", "smallitalic", "smalltext")); + $questionProperties = array("icon"=>"document.gif", "cssClass"=>"auto", "autostyles"=>array("smalltextBold", "smallitalic", "smalltext")); + foreach(getSurveysBrief(null, $sid) as $toplevel) { + if ($toplevel['active']=="Y") { $nodeProp=$nodePropertiesActive;} else {$nodeProp=$nodeProperties;} + $text=makeJavaSafe($toplevel['title'], 35); + $node01=new HTML_TreeNodeXL($text, "$scriptname?sid=".$toplevel['sid'], $nodeProp); + $m=0; + foreach(getGroupsBrief($toplevel['sid']) as $grouplevel) { + $nxgroups="node01_group_".$m; + $text=makeJavaSafe($grouplevel['group_name'], 37); + $$nxgroups = &$node01->addItem(new HTML_TreeNodeXL($text, "$scriptname?sid=$sid&gid=".$grouplevel['gid'], $nodeProperties)); + $n=0; + foreach(getQuestionsBrief($grouplevel['gid']) as $questionlevel) { + $nxquestions=$nxgroups."_".$n; + $text=makeJavaSafe($questionlevel['question'], 27); + $$nxquestions = &${$nxgroups}->addItem(new HTML_TreeNodeXL($questionlevel['title'].": ".$text, "$scriptname?sid=$sid&gid=".$grouplevel['gid']."&qid=".$questionlevel['qid'], $questionProperties)); + $n++; + } + $m++; + } + $menu01->addItem($node01); + } + $sidmenu= &new HTML_TreeMenu_DHTMLXL($menu01, array("images"=>"classes/TMimages")); + //$sidmenu->printMenu(); + $_SESSION['java_thissurvey']=$sidmenu->toHTML(); + } + + if (!isset($_SESSION['java_allsurveys']) || isset($_GET['changenavdisplay'])) { + $menu00 = new HTML_TreeMenuXL(); + $nodeProperties = array("icon"=>"folder.gif", "cssClass"=>"auto", "autostyles"=>array("smalltextBold", "smallitalic", "smalltext")); + $nodePropertiesActive = array("icon"=>"activefolder.gif", "cssClass"=>"auto", "autostyles"=>array("smalltextBold", "smallitalic", "smalltext")); + + $i=0; + //$node0 = new HTML_TreeNodeXL("Surveys", "#", $nodeProperties); + foreach(getSurveysBrief(null, null, $sid) as $toplevel) { + $nodename="node".$i; + $text=makeJavaSafe($toplevel['title'], 35); + $title=makeJavaSafe($toplevel['title'], 150); + //echo "
"; print_r($toplevel); echo "
"; + if ($toplevel['active']=="Y") { $nodeProp=$nodePropertiesActive;} else {$nodeProp=$nodeProperties;} + $$nodename = new HTML_TreeNodeXL($text, "$scriptname?sid=".$toplevel['sid'], $nodeProp); + //$nx = &$node0->addItem(new HTML_TreeNodeXL($toplevel['title'], "#", $nodeProperties)); + $k=0; + foreach(getGroupsBrief($toplevel['sid']) as $grouplevel) { + $nxgroups=$nodename."_group_".$k; + $text=makeJavaSafe($grouplevel['group_name'], 37); + $$nxgroups = &${$nodename}->addItem(new HTML_TreeNodeXL($text, "$scriptname?sid=".$toplevel['sid']."&gid=".$grouplevel['gid'], $nodeProperties)); + $l=0; + if ($_SESSION['noquestions'] != "noquestions") { + foreach(getQuestionsBrief($grouplevel['gid']) as $questionlevel){ + $nxquestions=$nxgroups."_".$l; + $text=makeJavaSafe($questionlevel['question'], 27); + if ($text == "") {$text="No title";} + + $$nxquestions = &${$nxgroups}->addItem(new HTML_TreeNodeXL($questionlevel['title'].": ".$text, "$scriptname?sid=".$toplevel['sid']."&gid=".$grouplevel['gid']."&qid=".$questionlevel['qid'], $nodeProperties)); + $l++; + } + } + $k++; + } + $menu00->addItem($$nodename); + $i++; + } + $surveymenu = &new HTML_TreeMenu_DHTMLXL($menu00, array("images"=>"classes/TMimages")); + $_SESSION['java_allsurveys']=$surveymenu->toHTML(); + $_SESSION['java_exclude']=$sid; + } + + + + echo "
+ + + + + + + + +
"; + + $display=""; + if (isset($sid) && $sid) { + echo " + + +
"; + $display="style='display: none'"; + } + + echo " + + + + + + + +
+
"; +} + +function labelsetDetails($lid = null) { + global $publicurl, $homeurl, $imagefiles, $scriptname, $navigation; + $theselabelsets=getLabelSetList(); + $thislabelset=getLabelSetInfo($lid); + if (!empty($lid)) { + $theselabels=getLabels($lid); + } + echo " + + + +
+ + + + + + + + "; + if (!empty($lid)) { + $activeqids=labelsInActiveSurvey($lid); + $otherqids=labelsInSurvey($lid); + echo " "; +// echo "
";print_r($activeqids);echo "
"; +// echo "
";print_r($otherqids);echo "
"; + $noedit=0; + $notes=""; + if (count($activeqids) > 0) { + $notes = "\n"; + $noedit=1; + } elseif (count($otherqids) > 0) { + $notes = "\n"; + } + echo " + + + + + "; + $i=1; + $max=count($theselabels); + foreach ($theselabels as $label) { + echo " + + + + + \n"; + $i++; + } + if (count($activeqids) < 1) { + echo " + + + + + + \n"; + } + echo $notes; + echo "
"._WARNING.": "._LB_ACTIVEUSE."
"._WARNING.": "._LB_TOTALUSE."
"._LL_CODE.""._LL_ANSWER.""._LL_ACTION.""._LL_SORTORDER."
+ + +
+
"; + if (count($activeqids) > 0 || count($otherqids) > 0) { + if (count($activeqids) > 0 && count($otherqids) > 0) { + $allqids = $activeqids; + foreach ($otherqids as $key=>$qid) { + $allqids[$key]=$qid; + } + //echo "
"; print_r($allqids); echo "
"; + } elseif (count($activeqids) >0 && count($otherqids) < 1) { + $allqids=$activeqids; + } elseif (count($activeqids) <1 && count($otherqids) > 0) { + $allqids=$otherqids; + } + echo "
+ + \n"; + foreach ($allqids as $sid=>$detail) { + echo " \n"; + } + echo "
Questions/Surveys Using this LabelSet
[Survey $sid]
+ +
"; + } + } + +} + +function labelAdd() { + global $publicurl, $imagefiles, $scriptname; + $theselabelsets=getLabelSetList(); + + echo " + +
+ + + + + + + + +
+ + + + + + + + + + + + + + +
"._LL_NAME.":
\n"; + +} + +function surveyDetails($sid, $gid, $qid) { + global $publicurl, $homeurl, $imagefiles, $scriptname, $slstyle, $navigation; + $thissurvey=getSurveyInfo($sid); + + list($ny, $nm, $nd)=explode("-", $thissurvey['expiry']); + if ($ny < 1970) { + $nicedate=_NEVER; + } else { + $nicedate=date("D, d M Y", mktime(0,0,0,$nm,$nd,$ny)); + } + + if ((isset($gid) && $gid) || returnglobal('action') == "editsurvey" || returnglobal('action') == "addsurvey" || returnglobal('action') == "editgroup" || returnglobal('action') == "addgroup" || returnglobal('action') == "showassessments") {$display="none";} else {$display="";} + $fields=array(_SL_TITLE=>$thissurvey['name'], + _SL_LINK=>"".$publicurl."?sid=$sid", + _SL_DESCRIPTION=>$thissurvey['description'], + _SL_WELCOME=>$thissurvey['welcome'], + _SL_ADMIN=>$thissurvey['adminname']." (".$thissurvey['adminemail'].")", + _SL_FAXTO=>$thissurvey['faxto'], + _SL_EXPIRES=>$nicedate, + _SL_URL=>"".$thissurvey['urldescrip']."", + _SL_AUTORELOAD=>yesno($thissurvey['autoredirect']), + _SL_LANGUAGE=>$thissurvey['language'], + _SL_FORMAT=>formatName($thissurvey['format']), + _SL_TEMPLATE=>$thissurvey['template'], + _SL_ALLOWSAVE=>yesno($thissurvey['allowsave']), + _SL_ANONYMOUS=>yesno($thissurvey['private']), + _SL_DATESTAMP=>yesno($thissurvey['datestamp']), + _SL_EMAILINVITE_SUBJ=>$thissurvey['email_invite_subj'], + _SL_EMAILINVITE=>nl2br($thissurvey['email_invite']), + _SL_EMAILREMIND_SUBJ=>$thissurvey['email_remind_subj'], + _SL_EMAILREMIND=>nl2br($thissurvey['email_remind']), + _SL_EMAILCONFIRM_SUBJ=>$thissurvey['email_confirm_subj'], + _SL_EMAILCONFIRM=>nl2br($thissurvey['email_confirm']), + _SL_EMAILREGISTER_SUBJ=>$thissurvey['email_register_subj'], + _SL_EMAILREGISTER=>nl2br($thissurvey['email_register']), + _SL_ATTRIBUTENAMES=>$thissurvey['attribute1'].autoComparitor(empty($thissurvey['attribute1']), false, " / ").$thissurvey['attribute2'], + _SL_NOTIFICATION=>notifications($thissurvey['sendnotification']), + _SL_AUTONUMBER=>$thissurvey['autonumber_start'], + _SL_ALLOWPREV=>yesno($thissurvey['allowprev'])); + + $pages[_SN_SV_GENERAL]=array(_SL_EXPIRES, _SL_TITLE, _SL_LINK, _SL_DESCRIPTION, _SL_WELCOME, _SL_ADMIN, _SL_FAXTO); + $pages[_SN_SV_EXTRA]=array(_SL_TEMPLATE, _SL_LANGUAGE, _SL_URL, _SL_AUTORELOAD, _SL_FORMAT, _SL_ALLOWSAVE, _SL_ANONYMOUS, _SL_DATESTAMP); + $pages[_SN_SV_EMAIL]=array(_SL_EMAILINVITE_SUBJ, _SL_EMAILINVITE, _SL_EMAILREMIND_SUBJ, _SL_EMAILREMIND, _SL_EMAILCONFIRM_SUBJ,_SL_EMAILCONFIRM, _SL_EMAILREGISTER_SUBJ, _SL_EMAILREGISTER); + $pages[_SN_SV_MISC]=array(_SL_ATTRIBUTENAMES, _SL_NOTIFICATION, _SL_AUTONUMBER, _SL_ALLOWPREV); + + if ($thissurvey['active'] == "Y") { + $surveystatus=""._S_ACTIVE_BT.""; + } else { + $surveystatus=""._S_INACTIVE_BT.""; + } + + $contents = buildSummaryRows($fields, 'surveysummary', $display, $pages); + + echo " + + + +
+ + + + + + + + + $contents +
\n"; +} + +function surveyEdit($sid) { + global $publicurl, $homeurl, $imagefiles, $scriptname, $slstyle, $action, $navigation; + + if ($action == "editsurvey") { + $thissurvey=getSurveyInfo($sid); + $title=""._S_EDIT_BT; + $button=_UPDATE; + } elseif ($action == "addsurvey") { + //Set defaults for a new survey + $thissurvey=array("name"=>"", + "description"=>"", + "welcome"=>"", + "adminname"=>"", + "adminemail"=>"", + "faxto"=>"", + "expiry"=>"", + "url"=>"", + "active"=>"N", + "urldescrip"=>"", + "autoredirect"=>"N", + "usecookie"=>"N", + "language"=>"", + "format"=>"G", + "template"=>"default", + "allowsave"=>"N", + "private"=>"Y", + "datestamp"=>"N", + "allowregister"=>"N", + "email_invite_subj"=>_TC_EMAILINVITE_SUBJ, + "email_invite"=>_TC_EMAILINVITE, + "email_remind_subj"=>_TC_EMAILREMIND_SUBJ, + "email_remind"=>_TC_EMAILREMIND, + "email_confirm_subj"=>_TC_EMAILCONFIRM_SUBJ, + "email_confirm"=>_TC_EMAILCONFIRM, + "email_register_subj"=>_TC_EMAILREGISTER_SUBJ, + "email_register"=>_TC_EMAILREGISTER, + "attribute1"=>"", + "attribute2"=>"", + "sendnotification"=>"0", + "autonumber_start"=>"", + "allowprev"=>"Y"); + $title = ""._A_ADDSURVEY_BT; + $button = _ADDS; + } + + $fields=array(_SL_TITLE=>textinput($thissurvey['name'], "short_title", "size='60'"), + _SL_DESCRIPTION=>textarea($thissurvey['description'], "description", "rows='6' cols='70'"), + _SL_WELCOME=>textarea($thissurvey['welcome'], "welcome", "rows='6' cols='70'"), + _SL_ADMIN=>textinput($thissurvey['adminname'], "admin", "size='30'"), + _SL_EMAIL=>textinput($thissurvey['adminemail'], "adminemail", "size='30'"), + _SL_FAXTO=>textinput($thissurvey['faxto'], "faxto", "size='30'"), + _SL_EXPIRES=>textinput($thissurvey['expiry'], "expires"), + _SL_URL=>textinput($thissurvey['url'], "url", "size='60'"), + _SL_URLDESCRIP=>textinput($thissurvey['urldescrip'], "urldescrip", "size='60'"), + _SL_AUTORELOAD=>yesnoSelect($thissurvey['autoredirect'], "autoredirect"), + _SL_USECOOKIES=>yesnoSelect($thissurvey['usecookie'], "usecookie"), + _SL_LANGUAGE=>languages($thissurvey['language'], "language"), + _SL_FORMAT=>formats($thissurvey['format'], "format"), + _SL_TEMPLATE=>templates($thissurvey['template'], "template"), + _SL_ALLOWSAVE=>yesnoSelect($thissurvey['allowsave'], "allowsave"), + _SL_ANONYMOUS=>yesnoSelect($thissurvey['private'], "private", autoComparitor($thissurvey['active'], "Y", "disabled")).autoComparitor($thissurvey['active'], "Y", _SN_CANNOTCHANGE_SURVEYACTIVE), + _SL_DATESTAMP=>yesnoSelect($thissurvey['datestamp'], "datestamp", autoComparitor($thissurvey['active'], "Y", "disabled")).autoComparitor($thissurvey['active'], "Y", _SN_CANNOTCHANGE_SURVEYACTIVE), + _SL_ALLOWREGISTER=>yesnoSelect($thissurvey['allowregister'], "allowregister"), + _SL_EMAILINVITE_SUBJ=>textinput($thissurvey['email_invite_subj'], "email_invite_subj", "size='60'"), + _SL_EMAILINVITE=>textarea($thissurvey['email_invite'], "email_invite", "rows='6' cols='70'"), + _SL_EMAILREMIND_SUBJ=>textinput($thissurvey['email_remind_subj'], "email_remind_subj", "size='60'"), + _SL_EMAILREMIND=>textarea($thissurvey['email_remind'], "email_remind", "rows='6' cols='70'"), + _SL_EMAILCONFIRM_SUBJ=>textinput($thissurvey['email_confirm_subj'], "email_confirm_subj", "size='60'"), + _SL_EMAILCONFIRM=>textarea($thissurvey['email_confirm'], "email_confirm", "rows='6' cols='70'"), + _SL_EMAILREGISTER_SUBJ=>textinput($thissurvey['email_register_subj'], "email_register_subj", "size='60'"), + _SL_EMAILREGISTER=>textarea($thissurvey['email_register'], "email_register", "rows='6' cols='70'"), + _TL_ATTR1=>textinput($thissurvey['attribute1'], "attribute1", "size='60'"), + _TL_ATTR2=>textinput($thissurvey['attribute2'], "attribute2", "size='60'"), + _SL_NOTIFICATION=>notificationlist($thissurvey['sendnotification'], "notification"), + _SL_AUTONUMBER=>textinput($thissurvey['autonumber_start'], "autonumber_start", "size='60'"), + _SL_ALLOWPREV=>yesnoSelect($thissurvey['allowprev'], "allowprev")); + + echo " + + + + + + + + + +
+ + + + + + + + +
+ \n"; + + $contents = buildSummaryRows($fields, 'surveysummary', ""); + echo $contents; + echo "
+ + + + + +
+ + +
+
"; +} + +function groupDetails($sid, $gid, $qid) { + global $publicurl, $imagefiles, $scriptname, $navigation; + $thisgroup=getGroupInfo($sid, $gid); + if (isset($qid) || multiStringSearch(array("editgroup", "addgroup"), returnglobal('action'))) {$display="none";} else {$display="";} + $fields=array(_GL_TITLE=>$thisgroup['group_name'], + _GL_DESCRIPTION=>$thisgroup['description']); + + $contents = buildSummaryRows($fields, 'groupsummary', $display); + + echo " + + + +
+ + + + + + + + + $contents +
\n"; +} + +function groupEdit($sid, $gid) { + global $publicurl, $imagefiles, $scriptname, $action; + if ($action == "editgroup") { + $thisgroup=getGroupInfo($sid, $gid); + $title=""._G_EDIT_BT; + $button=_UPDATE; + } elseif ($action == "addgroup") { + //Set defaults for a new survey + $thisgroup=array("group_name"=>"", + "description"=>""); + $title = ""._S_ADDGROUP_BT; + $button = _ADDG; + } + + $fields = array(_GL_TITLE=>textinput($thisgroup['group_name'], "group_name", "size='60'"), + _GL_DESCRIPTION=>textarea($thisgroup['description'], "description", "cols='60' rows='5' ")); + $contents = buildSummaryRows($fields, 'groupsummary'); + echo " + + + + + + + + + + + + +
+ + + + + + + + $contents +
+ + + + + +
+ + +
+
"; +} + +function questionDetails($sid, $gid, $qid, $action) { + global $publicurl, $imagefiles, $scriptname, $navigation; + $thissurvey=getSurveyInfo($sid); + $thisquestion=getQuestionInfo($qid); + $qtypes = getqtypelist("", "array"); + if (isset($action) && multiStringSearch(array("showanswers", "showattributes", "showsummary", "editquestion", "addquestion", "copyquestion"), $action)) {$display="none";} else {$display="";} + $fields=array(_QL_CODE=>$thisquestion['title'], + _QL_QUESTION=>$thisquestion['question'], + _QL_HELP=>$thisquestion['help'], + _QL_TYPE=>$qtypes[$thisquestion['type']]." (".$thisquestion['type'].")"); + + $contents = buildSummaryRows($fields, 'questionsummary', $display); + + echo " + + + +
+ + + + + + + + + $contents +
\n"; +} + +function questionEdit($sid, $gid, $qid) { + global $publicurl, $homeurl, $imagefiles, $scriptname, $slstyle, $action, $navigation; + + if ($action == "editquestion") { + $thissurvey = getSurveyInfo($sid); + $thisquestion = getQuestionInfo($qid); + $title=""._Q_EDIT_BT; + $button = _UPDATE; + } elseif ($action == "copyquestion") { + $thissurvey = getSurveyInfo($sid); + $thisquestion = getQuestionInfo($qid); + $thisquestion['title']=""; + $title=""._Q_COPY_BT; + $button = _COPYQ; + } elseif ($action == "addquestion") { + $thissurvey=getSurveyInfo($sid); + $thisquestion = array("sid"=>$sid, + "gid"=>$gid, + "type"=>"S", + "title"=>"", + "question"=>"", + "help"=>"", + "other"=>"N", + "mandatory"=>"N", + "lid"=>"", + "preg"=>""); + $title = ""._G_ADDQUESTION_BT; + $button = _ADDS; + } + + $fields=array(_QL_TYPE=>questionTypeSelect($thisquestion['type'], "type", "onChange='otherSelection(this.value)'".autoComparitor($thissurvey['active'], "Y", " disabled")).autoComparitor($thissurvey['active'], "Y", _SN_CANNOTCHANGE_SURVEYACTIVE), + _QL_CODE=>textinput($thisquestion['title'], "title", "size='5' maxlength='5'"), + _QL_QUESTION=>textarea($thisquestion['question'], "question", "rows='4' cols='50'"), + _QL_HELP=>textarea($thisquestion['help'], "help", "rows='3' cols='50'"), + _QL_OTHER=>yesnoSelect($thisquestion['other'], "other", "id='OtherSelection'".autoComparitor($thissurvey['active'], "Y", " disabled")).autoComparitor($thissurvey['active'], "Y", _SN_CANNOTCHANGE_SURVEYACTIVE), + _QL_MANDATORY=>yesnoSelect($thisquestion['mandatory'], "mandatory", "id='Mandatory'"), + _QL_LABELSET=>labelsetSelect($thisquestion['lid'], "lid", "id='LabelSets'".autoComparitor($thissurvey['active'], "Y", " disabled")).autoComparitor($thissurvey['active'], "Y", _SN_CANNOTCHANGE_SURVEYACTIVE), + _QL_VALIDATION=>textinput($thisquestion['preg'], "preg", "id='Validation' size='40'")); + + if ($action == "copyquestion") { + $fields[_QL_COPYANS]=yesnoSelect("Y", "copyanswers"); + $fields[_QL_COPYATT]=yesnoSelect("Y", "copyattributes"); + $qid=""; + } + + echo " + + + + + + + + + + + +
+ + + + + + + + +
+ \n"; + $contents = buildSummaryRows($fields, 'surveysummary', ""); + echo $contents; + echo "
+ + + + + +
+ + +
+
"; + echo " \n"; +} + +function questionResultSummary($sid, $gid, $qid) { + global $publicurl, $imagefiles, $scriptname; + + $thisquestion=getQuestionInfo($qid); + + require_once("results.php"); + $results=giveMeRawDataFromFieldNames($sid, $gid, $qid, array(), "full"); + $total=count($results); + echo " + +
+ + + + + + + + "; + + if ($summary=makeSummaryFromRawData($results, $sid, $gid, $qid)) { + foreach ($summary as $sum) { + echo "
\n"; + echo "\n"; + foreach ($sum['summary'] as $key=>$val) { + $percentage=sprintf("%02.2f", ($val/$total)*100); + echo "\n"; + } + echo "
$key$percentage% ($val)
"; + } + } + echo "
\n"; + +} + +function assessmentDetails($sid) { + global $imagefiles, $scriptname, $homeurl; + $thissurvey=getSurveyInfo($sid); + $theseassessments=getAssessments($sid); + $thesegroups=getGroupsBrief($sid); + foreach($theseassessments as $assessments) { + $fields[]=array("id"=>$assessments['id'], + _AS_SCOPE=>$assessments['scope'], + _AS_GID=>$assessments['gid'], + _AS_MINIMUM=>$assessments['minimum'], + _AS_MAXIMUM=>$assessments['maximum'], + _AS_HEADING=>$assessments['name'], + _AS_MESSAGE=>$assessments['message'], + _AS_URL=>$assessments['link']); + } + if (!empty($_GET['id'])) { + $thisassessment=getAssessmentInfo($_GET['id']); + $actiontitle=_AS_EDIT; + $actionbutton=_AS_EDIT; + $dbaction = "editassessment"; + } else { + $thisassessment=array("id"=>"", + "sid"=>$sid, + "scope"=>"G", + "gid"=>"", + "name"=>"", + "minimum"=>"", + "maximum"=>"", + "message"=>"", + "link"=>""); + $actiontitle=_AS_ADD; + $actionbutton=_AS_ADD; + $dbaction = "addassessment"; + } + echo " + +
+ + + + + + + + + + +
+ + + + + + + + + + + "; + if (isset($fields) && is_array($fields) && count($fields) > 0) { + $max=count($fields); + foreach ($fields as $field) { + echo " + + + + + + + + + + + "; + } + } + $groupselect="\n"; + $headings=array(_AS_SCOPE, _AS_GID, _AS_MINIMUM, _AS_MAXIMUM, _AS_HEADING, _AS_MESSAGE, _AS_URL); + $inputs=array("", + $groupselect, + "", + "", + "", + "", + ""); + + echo "
"._AS_SCOPE.""._AS_GID.""._AS_MINIMUM.""._AS_MAXIMUM.""._AS_HEADING.""._AS_MESSAGE.""._AS_URL.""._AL_ACTION."
".$field[_AS_SCOPE]."".$field[_AS_GID]."".$field[_AS_MINIMUM]."".$field[_AS_MAXIMUM]."".$field[_AS_HEADING]."".$field[_AS_MESSAGE]."".$field[_AS_URL]."
+ + + + + + +
\n\t
\n
+ + + \n"; + $i=0; + foreach ($headings as $head) { + echo "\n"; + $i++; + } + echo " + + + + + +
$actiontitle
$head".$inputs[$i]."
+ \n"; + if (!empty($_GET['id'])) { + echo " \n"; + } + echo " +
\n
"; + +} + +function answerDetails($sid, $gid, $qid) { + global $publicurl, $imagefiles, $scriptname; + $thissurvey=getSurveyInfo($sid); + $thisquestion=getQuestionInfo($qid); + $theseanswers=getAnswerInfo($qid); + $fields=array(); + foreach($theseanswers as $answers) { + $fields[]=array(_AL_CODE=>$answers['code'], + _AL_ANSWER=>$answers['answer'], + _AL_DEFAULT=>$answers['default_value'], + "sortorder"=>$answers['sortorder'], + "qid"=>$answers['qid']); + } + echo keycontroljs(); + echo " + + + +
+ + + + + + + + + + + + + "; + $i=1; + if (isset($fields) && is_array($fields) && count($fields) > 0) { + $max=count($fields); + foreach ($fields as $field) { + echo " + + + + + + + \n"; + $i++; + } + echo " + + + + + + + + + + \n"; + } + if ($thissurvey['active'] == "Y" && + ($thisquestion['type'] == "M" + || $thisquestion['type'] == "O" + || $thisquestion['type'] == "R")) { + + } else { + echo " + + + + + + + + + + + + + + + + + + "; + } + echo "
"._AL_CODE.""._AL_ANSWER.""._AL_DEFAULT.""._AL_ACTION.""._AL_MOVE."
+ + + +
+ + + +
+
+
"; +} + +function attributeDetails($sid, $gid, $qid) { + global $publicurl, $imagefiles, $scriptname, $homeurl; + $theseattributes=getAttributeInfo($qid); + $thisquestion=getQuestionInfo($qid); + + echo " + + + +
+ + + + + + + + + + + "; + foreach ($theseattributes as $attributes) { + echo " + + + + + + + + + + + \n"; + } + echo " + + + + + + + + + + + + "; + echo "
AttributeValue"._AL_ACTION."
".$attributes['attribute']."
+ + + + +
+
"; +//echo "
";print_r(questionAttributes());echo "
".$thisquestion['type']; +echo "
"; + +} + +function showPreview($sid, $gid, $qid=null) { + global $publicdir, $publicurl, $tempdir, $tempurl, $imagefiles; + //Show a preview of this question/group + //Currently just for questions + require_once("$publicdir/qanda.php"); + $thissurvey=getSurveyInfo($sid); + $thisgroup=getGroupInfo($sid, $gid); + if ($qid !== null) { + $thisquestion=getQuestionInfo($qid); + } + loadPublicLangFile($sid); + $ia=array($qid, + "DUMMY", + $thisquestion['title'], + $thisquestion['question'], + $thisquestion['type'], + $gid, + $thisquestion['mandatory'], + "N"); + list($plus_qanda, $plus_inputnames)=retrieveAnswers($ia); + $qanda[]=$plus_qanda; + $inputnames[]=$plus_inputnames; + + $thistpl=$publicdir."/templates/".$thissurvey['template']; + if (!is_dir($thistpl)) {$thistpl=$publicdir."/templates"."/default";} + $GLOBALS['thistpl']=$thistpl; + $GLOBALS['templatedir']=$publicurl."/templates/".$thissurvey['template']; + $GLOBALS['thissurvey']=$thissurvey; + + $output=array(); + + foreach(file("$thistpl/startpage.pstpl") as $op) + { + $output[]=templatereplace($op)."\n"; + } + if (is_array($qanda)) + { + foreach ($qanda as $qa) + { + //echo "
";print_r($qa);echo"
"; + $output[]= "\n\t\n"; + $output[]= "\t\t\t\t
"; + $GLOBALS['question']=""; + $GLOBALS['answer']=$qa[1]; + $GLOBALS['help']=$qa[2]; + $GLOBALS['questioncode']=$qa[5]; + foreach(file("$thistpl/question.pstpl") as $op) + { + $output[]= "\t\t\t\t\t".templatereplace($op)."\n"; + } + $output[]= "\t\t\t\t
\n"; + } + } + $output[]= "\n\n\n"; + foreach(file("$thistpl/endpage.pstpl") as $op) + { + $output[]=templatereplace($op)."\n"; + } + + unlink_wc($tempdir, "preview_temp_*.html"); //Delete any older template files + $time=date("ymdHis"); + $fnew=fopen("$tempdir/preview_temp_$time.html", "w+"); + foreach($output as $line) { + fwrite($fnew, $line); + } + fclose($fnew); + + echo "
+ + + +
+ +
\n"; + +} + + +function checkSettings($dbprefix) { + //GET NUMBER OF SURVEYS + global $defaultlang, $databasename, $realdefaultlang, $scriptname, $homeurl, $imagefiles; + + $query = "SELECT sid FROM {$dbprefix}surveys"; + $result = mysql_query($query); + $surveycount=mysql_num_rows($result); + $query = "SELECT sid FROM {$dbprefix}surveys WHERE active='Y'"; + $result = mysql_query($query); + $activesurveycount=mysql_num_rows($result); + $query = "SELECT user FROM {$dbprefix}users"; + $result = mysql_query($query); + $usercount = mysql_num_rows($result); + $result = mysql_list_tables($databasename); + while ($row = mysql_fetch_row($result)) + { + $stlength=strlen($dbprefix).strlen("old"); + if (substr($row[0], 0, $stlength+strlen("_tokens")) == $dbprefix."old_tokens") + { + $oldtokenlist[]=$row[0]; + } + elseif (substr($row[0], 0, strlen($dbprefix) + strlen("tokens")) == $dbprefix."tokens") + { + $tokenlist[]=$row[0]; + } + elseif (substr($row[0], 0, $stlength) == $dbprefix."old") + { + $oldresultslist[]=$row[0]; + } + } + if(isset($oldresultslist) && is_array($oldresultslist)) + {$deactivatedsurveys=count($oldresultslist);} else {$deactivatedsurveys=0;} + if(isset($oldtokenlist) && is_array($oldtokenlist)) + {$deactivatedtokens=count($oldtokenlist);} else {$deactivatedtokens=0;} + if(isset($tokenlist) && is_array($tokenlist)) + {$activetokens=count($tokenlist);} else {$activetokens=0;} + echo "
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
"._PS_DBNAME.":$databasename
"._PS_DEFLANG.":$realdefaultlang
"._PS_CURLANG.":
+ +
"._PS_USERS.":$usercount
"._SURVEYS.":$surveycount
"._PS_ACTIVESURVEYS.":$activesurveycount
"._PS_DEACTSURVEYS.":$deactivatedsurveys
"._PS_ACTIVETOKENS.":$activetokens
"._PS_DEACTTOKENS.":$deactivatedtokens
+
\n"; + +} + + + + + +function getSurveysBrief($user=null, $sid=null, $notsid=null) { + $surveyList=array(); + $query = "SELECT * FROM surveys "; + if ($sid !== null) { + $query .= "WHERE sid=$sid "; + } + if ($notsid !== null && $sid!="") { + $query .= "WHERE sid != $notsid "; + } + $query .= "ORDER BY short_title"; + $result = mysql_query($query) or die($query ."
".mysql_error()); + while($row=mysql_fetch_array($result)) { + $surveyList[]=array("title"=>$row['short_title'], + "sid"=>$row['sid'], + "active"=>$row['active']); + } // while + return $surveyList; +} +function getGroupsBrief($sid) { + $groupList=array(); + $query = "SELECT * FROM groups WHERE sid=$sid ORDER BY group_name"; + $result = mysql_query($query) or die($query."
".mysql_error()); + while($row=mysql_fetch_array($result)) { + $groupList[]=array("group_name"=>$row['group_name'], + "gid"=>$row['gid']); + } // while + usort($groupList, 'CompareGroupThenTitle'); + return $groupList; +} + +function getQuestionsBrief($gid) { + $questionList=array(); + $query = "SELECT * FROM questions WHERE gid=$gid ORDER BY title"; + $result = mysql_query($query); + while($row=mysql_fetch_array($result)) { + $questionList[]=array("title"=>$row['title'], + "question"=>$row['question'], + "qid"=>$row['qid']); + } // while + return $questionList; +} + +function windowControl($elementName, $closeLink="", $height=20, $width=20) { + global $imagefiles; + $windowcontrol = ""; + if ($closeLink !== null) { + $windowcontrol .= "\n"; + } + $windowcontrol .= "\n"; + $windowcontrol .= "\n"; + + return $windowcontrol; +} + +function buildSummaryRows($fields, $elementName, $display="", $pages=null) { + $summary = "\n"; + if (is_array($pages)) { + $summary .= ""; + $summary .= " "; + } + else { + foreach ($fields as $key=>$val) { + $summary .= " + "; + } + } + $summary .= "
+ + "; + $headerno=1; + foreach(array_keys($pages) as $page) { + if ($headerno==1) {$class='tabselected';} else {$class='tabselect';} + $summary .= ""; + $headerno++; + } + $summary .= "
+ $page
"; + $pageno=1; + foreach ($pages as $key=>$val) { + if ($pageno > 1) {$display='none';} else {$display='';} + $summary .= "\n"; + foreach ($fields as $fkey=>$fval) { + if (in_array($fkey, $val)) + $summary .= " + "; + } + $summary .= "
$fkey$fval
\n"; + $pageno++; + } + $summary .= "
$key$val
\n"; + return $summary; +} + +function buildEditRows($fields, $elementName, $display="") { + $summary = "\n"; + foreach ($fields as $key=>$val) { + $summary .= " + "; + } + $summary .= "
$key
\n"; + return $summary; +} + +function getGroupInfo($sid, $gid) { + global $dbprefix; + $query = "SELECT * FROM {$dbprefix}groups WHERE sid=$sid AND gid=$gid"; + $result = mysql_query($query) or die("Couldn't get info for group $gid
$query
".mysql_error()); + while($row=mysql_fetch_array($result)) { + return $row; + } // while +} + +function getQuestionInfo($qid) { + global $dbprefix; + $query = "SELECT * FROM {$dbprefix}questions where qid=$qid"; + $result = mysql_query($query) or die("Couldn't get info for question $qid
$query
".mysql_error()); + while($row=mysql_fetch_array($result)) { + return $row; + } // while +} + +function getAnswerInfo($qid) { + global $dbprefix; + $query = "SELECT * FROM {$dbprefix}answers WHERE qid=$qid ORDER BY sortorder, code"; + $result = mysql_query($query) or die("Couldn't get info for answers $qid
$query
".mysql_error()); + $output=array(); + while($row = mysql_fetch_array($result)){ + $output[] = $row; + } // while + return $output; +} + +function getAttributeInfo($qid) { + global $dbprefix; + $query = "SELECT * FROM {$dbprefix}question_attributes where qid=$qid"; + $result = mysql_query($query) or die("Couldn't get info for question attributes $qid
$query
".mysql_error()); + $output=array(); + while($row = mysql_fetch_array($result)){ + $output[] = $row; + } // while + return $output; + +} + +function getAssessments($sid) { + global $dbprefix; + $query = "SELECT id, sid, scope, gid, minimum, maximum, name, message, link + FROM {$dbprefix}assessments + WHERE sid=$sid + ORDER BY scope, gid"; + $result=mysql_query($query) or die("Error getting assessments
$query
".mysql_error()); + $output=array(); + while($row=mysql_fetch_array($result, MYSQL_ASSOC)) { + $output[]=$row; + } + return $output; +} + +function getLabelSetList() { + global $dbprefix; + $query = "SELECT * FROM {$dbprefix}labelsets ORDER BY label_name"; + $result = mysql_query($query); + $output=array(); + while($row=mysql_fetch_array($result, MYSQL_ASSOC)) {$output[]=$row;} + return $output; +} + +function getLabels($lid) { + global $dbprefix; + $query = "SELECT * FROM {$dbprefix}labels WHERE lid=$lid ORDER BY sortorder, title"; + $result = mysql_query($query); + $output=array(); + while($row=mysql_fetch_array($result, MYSQL_ASSOC)) {$output[]=$row;} + return $output; +} + +function getLabelSetInfo($lid) { + global $dbprefix; + if ($lid) { + $query = "SELECT * FROM {$dbprefix}labelsets WHERE lid=$lid"; + $result = mysql_query($query) or die("Error getting labelset
$query
".mysql_error()); + while($row=mysql_fetch_array($result, MYSQL_ASSOC)) { + $output=$row; + } + } else {$output=array();} + return $output; +} + +function getAssessmentInfo($id) { + global $dbprefix; + $query = "SELECT * FROM {$dbprefix}assessments WHERE id=$id"; + $result = mysql_query($query); + while($row=mysql_fetch_array($result, MYSQL_ASSOC)) { + $output=$row; + } + return $output; +} +//function getGroupList($sid) { +// global $dbprefix; +// $query = "SELECT gid, group_name +// FROM {$dbprefix}groups +// WHERE sid=$sid +// ORDER BY group_name"; +// $result = mysql_query($query) or die("Error getting groups
$query
".mysql_error()); +// $output=array(); +// while($row=mysql_fetch_array($result)) { +// $output[]=$row; +// } +// return $output; +//} + +function showPosition($sid, $gid, $qid) { + global $dbprefix; + $query = "SELECT {$dbprefix}surveys.short_title"; + $from = "\nFROM {$dbprefix}surveys"; + $join = "\n"; + $where = "\nWHERE {$dbprefix}surveys.sid = $sid"; + if (isset($gid) && $gid) { + $query .= ",\n{$dbprefix}groups.group_name"; + $join .= "LEFT JOIN {$dbprefix}groups ON {$dbprefix}surveys.sid={$dbprefix}groups.sid"; + $where .= "\nAND {$dbprefix}groups.gid = $gid"; + } + if (isset($qid) && $qid) { + $query .= ",\n{$dbprefix}questions.title, {$dbprefix}questions.question"; + $join .= "\nLEFT JOIN {$dbprefix}questions ON {$dbprefix}surveys.sid={$dbprefix}questions.sid"; + $where .= "\nAND {$dbprefix}questions.qid=$qid"; + } + $sql=$query.$from.$join.$where; + $result=mysql_query($sql) or die("Couldn't do good join for position display
$query
".mysql_error()); + while($row=mysql_fetch_array($result)) { + $output = "[".$row['short_title']."]"; + if (isset($gid) && $gid) { + $output .= "->[".$row['group_name']."]"; + } + if (isset($qid) && $qid) { + $output .= "->[".$row['title'].": ".$row['question']."]"; + } + } // while + return $output; +} + +function makeJavaSafe($string, $maxlength) { + $string=strip_tags($string); + $string=htmlentities($string, ENT_QUOTES); + $string=trim($string); + $string=str_replace(array("\n\r", "\n", "\r"), array(" ", " ", " "), $string); + //Reduce to $maxlength + if (strlen($string) > $maxlength) { + $string=substr($string, 0, $maxlength-2).".."; + } + return $string; +} + +function autoComparitor($value, $comparitor, $returnvalue) { + //returns $returnvalue if the $comparitor is equal to the value + if ($value == $comparitor) { + return $returnvalue; + } +} + +function labelsets() { + global $dbprefix; + $query = "SELECT * FROM {$dbprefix}labelsets + ORDER BY label_name"; + $result=mysql_query($query) or die(mysql_error()); + while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {$output[]=$row;} + return $output; +} + +function questionTypes() { + $qtypes = array( + "5"=>_5PT, + "D"=>_DATE, + "G"=>_GENDER, + "!"=>_LIST_DROPDOWN, + "L"=>_LIST, + "O"=>_LISTWC, + "M"=>_MULTO, + "P"=>_MULTOC, + "Q"=>_MULTITEXT, + "N"=>_NUMERICAL, + "R"=>_RANK, + "S"=>_STEXT, + "T"=>_LTEXT, + "U"=>_HTEXT, + "Y"=>_YESNO, + "A"=>_ARR5, + "B"=>_ARR10, + "C"=>_ARRYN, + "E"=>_ARRMV, + "F"=>_ARRFL, + "H"=>_ARRFLC, + "X"=>_BOILERPLATE, + "W"=>_LISTFL_DROPDOWN, + "Z"=>_LISTFL_RADIO + ); + array_multisort($qtypes); + return $qtypes; +} + +function yesno($value) { + switch($value){ + case "Y": + return _AD_YES; + case "N": + return _AD_NO; + } // switch +} + +function notifications($value) { + switch($value) { + case "0": + return _NT_NONE; + case "1": + return _NT_SINGLE; + case "2": + return _NT_RESULTS; + } +} + +function formatName($format) { + switch($format){ + case "S": + return _QBYQ; + case "G": + return _GBYG; + case "A": + return _SBYS; + default: + return _QBYQ; + } // switch +} + +function textinput($value, $name, $extras=null) { + return ""; +} + +function textarea($value, $name, $extras=null) { + return ""; +} + +function yesnoSelect($value=null, $name, $extras=null) { + return ""; +} + +function labelsetSelect($value=null, $name, $extras=null) { + $output = ""; + return $output; +} + +function questionTypeSelect($value=null, $name, $extras=null) { + $output = ""; + return $output; +} + +function languages($value=null, $name, $extras=null) { + $return = "\n"; + return $return; +} + +function formats($value=null, $name, $extras=null) { + return " \n"; + +} + +function templates($value=null, $name, $extras=null) { + $return = " + + + + \n"; +} + +function labelsInActiveSurvey($lid) { + global $dbprefix; + $query = "SELECT {$dbprefix}questions.sid, {$dbprefix}questions.gid, {$dbprefix}questions.qid + FROM {$dbprefix}questions, {$dbprefix}surveys + WHERE {$dbprefix}questions.sid={$dbprefix}surveys.sid + AND {$dbprefix}questions.lid=$lid + AND {$dbprefix}surveys.active = 'Y'"; + $result = mysql_query($query); + $output=array(); + $sid=null; + while($row=mysql_fetch_array($result, MYSQL_ASSOC)) { + if ($row['sid'] != $sid) { + $sid=$row['sid']; + } + $output[$sid][]=array('gid'=>$row['gid'], 'qid'=>$row['qid']); + } + return $output; +} + +function labelsInSurvey($lid) { + global $dbprefix; + $query = "SELECT {$dbprefix}questions.sid, {$dbprefix}questions.gid, {$dbprefix}questions.qid + FROM {$dbprefix}questions, {$dbprefix}surveys + WHERE {$dbprefix}questions.sid={$dbprefix}surveys.sid + AND {$dbprefix}questions.lid=$lid + AND {$dbprefix}surveys.active != 'Y' + ORDER BY {$dbprefix}questions.sid, {$dbprefix}questions.qid"; + $result = mysql_query($query); + $output=array(); + $sid=0; + while($row=mysql_fetch_array($result, MYSQL_ASSOC)) { + if ($row['sid'] != $sid) { + $sid=$row['sid']; + } + $output[$sid][]=array('gid'=>$row['gid'], 'qid'=>$row['qid']); + } + return $output; +} + +function javadropdown($sid, $gid, $qid) { +global $publicurl, $homeurl, $imagefiles, $scriptname; +global $lid; + +//Menu entries go here +//CREATENEW +$menu['system']["0"]=""._AUTHENTICATION_BT."
"; +$menu['system']["1"]=""._SYSTEM_BT."
"; + +$menu['systemdb']["0"]=""._CHECKFIELDS."
"; +$menu['systemdb']["1"]=""._PS_CHECKDBINTEGRITY."
"; +$menu['systemdb']["2"]=""._A_BACKUPDB_BT."
"; + +$menu['systemother']["0"]=""._Q_LABELS_BT."
"; + +$menu['createnew']["2"]=""._A_ADDSURVEY_BT."
"; +$menu['importnew']["2"]=""._IMPORTSURVEY."
"; + +$menu['labeloptions']["0"]=""._LB_NEWSET."
"; +if (!empty($lid)) { + $activeqids=labelsInActiveSurvey($lid); + if (count($activeqids) < 1) { + $menu['labeloptions']["1"]=""._L_DEL_BT."
"; + } +} +if(!empty($sid)) { + $thissurvey=getSurveyInfo($sid); + if ($thissurvey['active'] != "Y") { + $menu['createnew']["1"]=""._S_ADDGROUP_BT."
"; + $menu['importnew']["1"]=""._IMPORTGROUP."
"; + } + + if(!empty($gid)) { + if ($thissurvey['active'] != "Y") { + $menu['createnew']["0"]=""._G_ADDQUESTION_BT."
"; + $menu['importnew']["0"]=""._IMPORTQUESTION."
"; + } + } + + + $menu['surveyactions']["0"]=""._S_DOSURVEY_BT."
"; + $menu['surveyactions']["1"]=""._S_DATAENTRY_BT."
"; + $menu['surveyactions']["2"]=""._S_PRINTABLE_BT."
"; + $menu['surveyactions']["3"]=""._S_RENUMBER_BT."
"; + + + if ($thissurvey['active'] == "Y") { + $menu['surveyactivation']["0"]=""._S_DEACTIVATE_BT."
"; + } else { + $menu['surveyactivation']["0"]=""._S_ACTIVATE_BT."
"; + } + + $menu['surveyoptions']["0"]=""._S_EDIT_BT."
"; + $menu['surveyoptions']["2"]=""._S_EXPORT_BT."
"; + if ($thissurvey['active'] != "Y") { + $menu['surveyoptions']["1"]=""._S_DELETE_BT."
"; + } + $menu['surveyoptions']["3"]=""._S_ASSESSMENT_BT."
"; + + if ($thissurvey['active'] == "Y") { + $menu['surveyactive']["0"]=""._S_BROWSE_BT."
"; + $menu['surveyactive']["1"]=""._B_STATISTICS_BT."
"; + $menu['surveyactive']["2"]=""._S_TOKENS_BT."
"; + if ($thissurvey['allowsave'] == "Y") { + $menu['surveyactive']["3"]=""._S_SAVED_BT."
"; + } + } + + if (!empty($gid)) { + $menu['groupoptions']["0"]=""._G_EDIT_BT."
"; + if ($thissurvey['active'] != "Y") { + $menu['groupoptions']["1"] = ""._G_DELETE_BT."
"; + } + $menu['groupoptions']["2"]=""._G_EXPORT_BT."
"; + + $menu['groupactions']["0"]=""._G_RENUMBER_BT."
"; + } + + if (!empty($qid)) { + $menu['questionoptions']["0"]=""._Q_EDIT_BT."
"; + if ($thissurvey['active'] != "Y") { + $menu['questionoptions']["1"]=""._Q_DELETE_BT."
"; + } + $menu['questionoptions']["2"]=""._Q_EXPORT_BT."
"; + $menu['questionoptions']["3"]=""._Q_COPY_BT."
"; + + $thisquestion=getQuestionInfo($qid); + switch($thisquestion['type']){ + case "L": case "M": case "O": case "!": case "A": case "B": case "C": case "E": case "F": + case "P": case "Q": case "R": case "H": + $menu["questionactions"]["0"]=""._Q_ANSWERS_BT."
"; + break; + } // switch + $menu["questionactions"]["1"]=""._QL_QUESTIONATTRIBUTES."
"; + $menu["questionactions"]["2"]=""._Q_CONDITIONS_BT."
"; + $menu["questionactions"]["3"]=""._Q_PREVIEWQUESTION."
"; + if($thissurvey['active'] == "Y") { + $menu['activequestion']["0"]=""._Q_VIEWSUMMARY."
"; + } + } +} + +$java="\n"; +return $java; +} + +function unlink_wc($dir, $pattern){ + if ($dh = opendir($dir)) { + + //List and put into an array all files + while (false !== ($file = readdir($dh))){ + if ($file != "." && $file != "..") { + $files[] = $file; + } + } + closedir($dh); + + + //Split file name and extenssion + if(strpos($pattern,".")) { + $baseexp=substr($pattern,0,strpos($pattern,".")); + $typeexp=substr($pattern,strpos($pattern,".")+1,strlen($pattern)); + }else{ + $baseexp=$pattern; + $typeexp=""; + } + + //Escape all regexp Characters + $baseexp=preg_quote($baseexp); + $typeexp=preg_quote($typeexp); + + // Allow ? and * + $baseexp=str_replace(array("\*","\?"), array(".*","."), $baseexp); + $typeexp=str_replace(array("\*","\?"), array(".*","."), $typeexp); + + //Search for pattern match + $i=0; + foreach($files as $file) { + $filename=basename($file); + if(strpos($filename,".")) { + $base=substr($filename,0,strpos($filename,".")); + $type=substr($filename,strpos($filename,".")+1,strlen($filename)); + }else{ + $base=$filename; + $type=""; + } + + if(preg_match("/^".$baseexp."$/i",$base) && preg_match("/^".$typeexp."$/i",$type)) { + $matches[$i]=$file; + $i++; + } + } + if (isset($matches)) { + while(list($idx,$val) = each($matches)){ + if (substr($dir,-1) == "/"){ + unlink($dir.$val); + }else{ + unlink($dir."/".$val); + } + } + } + + } +} +?> \ No newline at end of file diff --git a/admin/phpsurveyor.css b/admin/phpsurveyor.css new file mode 100644 index 00000000000..aa5b109e465 --- /dev/null +++ b/admin/phpsurveyor.css @@ -0,0 +1,245 @@ +body,td,th,a,p { + font-family:verdana,arial,sans-serif; + font-size:10pt} + +input, textarea, select { + font-family:verdana; + font-size:11px; + background-color:#DDDFFF; + color:#000080; + border: 1px inset #CCCCCC; +} + +.headingtable, .headingtable A, .headingtable A:visited { + color: #FFFFFF; + font-size: 8.5pt; + text-decoration: none; +} +.headingtable A:hover { + color: #111111; +} + +.buttons { + border: 1px outset #CCCCCC; +} + +/* StandardTable */ +.outlinetable { + border: 1px solid #111111; +} + +.outlinetable td { + background-color: #EEEEEE; + border: 1px solid #CCCCCC; + border: 0px; +} + +.outlinetable th { + background-color: #777777; color: #FFFFFF; +} + +/* Summary Rows */ +.rowheading { + background-color: #BBBBBB; + text-align: right; + font-weight: bold; + border: 1px solid #888888; + vertical-align: top; +} +.rowdata { + border: 1px solid #BBBBBB; + background-color: #DDDDDD; +} +/* Dropdowns */ +.smallselect { + font-family: Verdana, Arial, Helvetica, sans-serif; + font-size: 7pt; + background-color: #CCCCCC; +} + +/* Menu Tables*/ +.menutable { + border: 0.5px solid #111111; + color: #EEEEEE; +} +.menutable th { + /*background-color: #555555;*/ + background-color: #5E6F86; + border: 1px solid #111111; + color: #FFFFFF; + font-size: 8.5pt; + font-align: left; +} +.menutable td { + background-color: #999999; + border: 1px solid #111111; + font-size: 8.5pt; +} +.menutable A { + color: #EEEEEE; + font-size: 8.5pt; + text-decoration:none; +} +.menutable A:hover { + text-decoration:none; + color: #999999; + background-color: #EEEEEE; +} +.menutable input { + border: 0px; +} +/* Navigator Table */ +.navtable { + border: 0.5px solid #111111; + color: #EEEEEE; +} +.navtable th { + /*background-color: #555555;*/ + background-color: #5E6F86; + border: 1px solid #111111; + color: #EEEEEE; + font-size: 8.5pt; + font-align: left; +} +.navtable td { + background-color: #BBBBBB; + border: 1px solid #111111; + font-size: 7.5pt; + color: #555555; +} +.navtable input { + border: 0px; +} + +.tabselect { + background-color: #BBBBBB; + border-left: 1px solid #333333; + border-top: 1px solid #333333; + border-right: 0.5px solid #DDDDDD; +} +.tabselect A:active, .tabselect A:link, .tabselect A:visited{ + font-size: 9pt; + text-decoration: none; + padding-left: 15px; + padding-right: 5px; + color: #222222; +} +.tabselect A:hover { + background-color: #777777; +} +.tabselected { + background-color: #CCCCCC; + border-left: 2px solid #DDDDDD; + border-top: 2px solid #DDDDDD; + border-right: 0.5px solid #333333; +} +.tabselected A:active, .tabselected A:link, .tabselected A:visited { + font-size: 9pt; + text-decoration: none; + padding-left: 15px; + padding-right: 5px; + color: #000080; +} + +/* Select Boxes */ +.select { + background-color: #EEEFFF; + height: 18; + font-family: verdana; + font-size: 10; + color: #000080; +} + +/* treeMenu css */ +.tmenu0text { + font-family: Verdana, Arial, Helvetica, sans-serif; + font-size: 7.5pt; + letter-spacing: -0.07em; + font-weight: bold; +} +.tmenu1text { + font-family: Verdana, Arial, Helvetica, sans-serif; + font-size: 7.5pt; + letter-spacing: -0.07em; +} +.tmenu2text { + font-family: Verdana, Arial, Helvetica, sans-serif; + font-size: 7.5pt; + letter-spacing: -0.07em; +} +.tmenu3text { + font-family: Verdana, Arial, Helvetica, sans-serif; + font-size: 7pt; + letter-spacing: -0.07em; +} + +/* Since all menu items are links, the following is equally important + * to your menu appearance. + * The main thing you may want to change are the A:link and A:visited colors. + */ +*.tmenu0text A:link,*.tmenu1text A:link,*.tmenu2text A:link,*.tmenu3text A:link + { text-decoration:none; color:#505080; font-size: 7.5pt } +*.tmenu0text A:visited,*.tmenu1text A:visited,*.tmenu2text A:visited,*.tmenu3text A:visited + { text-decoration:none; color:#505080; font-size: 7.5pt } +*.tmenu0text A:active,*.tmenu1text A:active,*.tmenu2text A:active,*.tmenu3text A:active + { text-decoration:none; color:#805050; font-size: 7.5pt } +*.tmenu0text A:hover,*.tmenu1text A:hover,*.tmenu2text A:hover,*.tmenu3text A:hover + { text-decoration:underline; color:#FF0000; font-size: 7.5pt } + +/* .tmlistbox controls the appearance of Listbox menus */ +.tmlistbox { + font-family: Arial, Helvetica, sans-serif; + font-size: 7.5px; /* match 'smalltext' value */ + font-size-adjust: 0.58; /* Verdana */ + margin-bottom: 0px; +} + +/* .tmenuSelected is used with linkSelectKey to highlight selected items */ +.tmenuSelected { + background-color: #CCCCCC; +} +*.tmenuSelected A:link { text-decoration:none; color:#2020ff; font-size: 7pt; font-weight: bold; } +*.tmenuSelected A:visited { text-decoration:none; color:#2020ff; font-size: 7pt; font-weight: bold; } +*.tmenuSelected A:active { text-decoration:none; color:#ff2020; font-size: 7pt; font-weight: bold; } +*.tmenuSelected A:hover { text-decoration:underline; color:#FF0000; font-size: 7pt; font-weight: bold; } + +/* dropmenu */ +#dropmenudiv { + position:absolute; + font:normal 11px Verdana; + border-left:2px solid black; + border-bottom:2px solid black; + border-right:2px solid black; + line-height:18px; + z-index:100; +} +#dropmenudiv A:link { + font:normal 11px Verdana; + line-height: 18px; + text-decoration: none; + color: #111111; +} +#dropmenudiv A:visited { + font:normal 11px Verdana; + line-height: 18px; + text-decoration: none; + color: #111111; +} +#dropmenudiv A:hover { + text-decoration: underline; + background-color: #555555; + color: #FFFFFF; +} + +.resultstable { + border: 1px solid #111111; + font-size: 9pt; +} + +.resultstable th { + background-color: #777777; color: #FFFFFF; +} + +.result { + background-color: #EEEEEE; border-bottom: 2px solid #BBBBBB; +} \ No newline at end of file diff --git a/admin/results.php b/admin/results.php new file mode 100644 index 00000000000..3ca4f4acbab --- /dev/null +++ b/admin/results.php @@ -0,0 +1,550 @@ +>> PHP Surveyor # + ############################################################# + # > Author: Jason Cleeland # + # > E-mail: jason@cleeland.org # + # > Mail: Box 99, Trades Hall, 54 Victoria St, # + # > CARLTON SOUTH 3053, AUSTRALIA + # > Date: 20 February 2003 # + # # + # This set of scripts allows you to develop, publish and # + # perform data-entry on surveys. # + ############################################################# + # # + # Copyright (C) 2003 Jason Cleeland # + # # + # This program is free software; you can redistribute # + # it and/or modify it under the terms of the GNU General # + # Public License as published by the Free Software # + # Foundation; either version 2 of the License, or (at your # + # option) any later version. # + # # + # This program is distributed in the hope that it will be # + # useful, but WITHOUT ANY WARRANTY; without even the # + # implied warranty of MERCHANTABILITY or FITNESS FOR A # + # PARTICULAR PURPOSE. See the GNU General Public License # + # for more details. # + # # + # You should have received a copy of the GNU General # + # Public License along with this program; if not, write to # + # the Free Software Foundation, Inc., 59 Temple Place - # + # Suite 330, Boston, MA 02111-1307, USA. # + ############################################################# +*/ + +require_once("config.php"); + +//OK: Here's how it works so far! + +/*include this file in a php script + +* The two "overall" functions are: +* - giveMeRawDataFromFieldNames($sid, $gid, $qid, $fieldarray, responsestyle) +* $sid = the survey id number +* $gid = the group id for the question you want results for +* $qid = the question id for the question you want results for +* $fieldarray = a keyed array containing the fieldnames as key, and the value for of that fieldname that you want matches to +* -ie: array ("1X2X34"=>"FL", "1X2X35"=>"Cork") +* $responsestyle should be "full" - the alternative (which would just be the codes) is not yet coded +* +* This function will return a multi-level array. The first level is a numbered array with an +* entry for every individual response. Within that array will be a further array, with an entry +* for every possible answer to that question. Then, within each of those arrays will be +* the question title, and the answer to that question for that record. +* +* As an example, a single answer type question (like a List, or Yes/No) +* will look like this: +* Array +* ( +* [0]=> Array +* ( +* [4X6X22] => Array +* ( +* [0] => What is your Employment Type? +* [1] => Ongoing +* ) +* ) +* [1]=> Array +* ..... and so forth for each record in the responses table +* +* A multiple answer type question, such as "Multiple Choice" will look like this: +* Array +* ( +* [0]=> Array +* ( +* [2X2X7C] => Array +* ( +* [0] => Choose your favourite foods [Cheese] +* [1] => Yes +* ) +* [2X2X7I] => Array +* ( +* [0] => Choose your favourite foods [Ice Cream] +* [1] => +* ) +* ) +* +* - makeSummaryFromRawData($results) +* Feed this function the "raw results" string generated by the "giveMeRawDataFromFieldNames" +* function and you'll be returned an array containing a summary/count of results +* for every possible answer within that question. +* +* An example result for a single option question (ie: List or Yes/No) is: +* +* Array +* ( +* [4X6X22] => Array +* ( +* [question] => What is your Employment Type? +* [summary] => Array +* ( +* [Ongoing] => 429 +* [Fixed Term] => 61 +* [None] => 4 +* [Agency / Temp] => 4 +* [Casual] => 1 +* ) +* +* ) +* ) +* +* An example result for a multiple answer type question is: +* Array +* ( +* [2X2X7G] => Array +* ( +* [question] => Which of the following issues do you want addressed in negotiations for the next Enterprise Bargaining Agreement? [Accrual of Time In Lieu / Flex Time] +* [summary] => Array +* ( +* [Yes] => 10 +* [None] => 3 +* ) +* +* ) +* +* [2X2X7K] => Array +* ( +* [question] => Which of the following issues do you want addressed in negotiations for the next Enterprise Bargaining Agreement? [Allowances / Reimbursement of Expenses] +* [summary] => Array +* ( +* [Yes] => 5 +* [None] => 8 +* ) +* +* ) +* ) +* +*/ + +//THIS BIT IS JUST FOR DEBUGGING +if (!empty($_GET['debug'])) { + // $table = "survey_4"; + // //$questionfields[]="4X6X22"; + // //$questionfields[]="4X6X23"; + // $limitby=array("4X6X22"=>"A", + // "4X6X23"=>"B"); + // $sql = buildSqlFromFieldnamesArray($limitby); + // $questionfields=buildQuestionFields("4", "7", "29"); + // if (!empty($questionfields)) { + // $results = returnQuestionResults($table, $questionfields, $sql); + // echo "TOTAL RESULTS: ".count($results); + // echo "
";
+	//		print_r($results);
+	//		echo "
"; + // } + $sid=$_GET['sid']; + $gid=$_GET['gid']; + $qid=$_GET['qid']; + //$results = giveMeRawDataFromFieldNames("4", "6", "22", array(), "full"); + //$results = giveMeRawDataFromFieldNames("2", "2", "7", array(), "full"); + //$results = giveMeRawDataFromFieldNames("8", "18", "66", array(), "full"); + //$results = giveMeRawDataFromFieldNames("29", "89", "559", array(), "full"); + $results = giveMeRawDataFromFieldNames($sid, $gid, $qid, array(), "full"); + + $summary = makeSummaryFromRawData($results); + foreach ($results as $result) { foreach ($result as $answer) {echo $answer[1];} } + echo "
";
+	print_r($results);
+	echo "
"; +// +// foreach ($summary as $sum) { +// echo "\n"; +// echo "\n"; +// foreach ($sum['summary'] as $key=>$val) { +// echo "\n"; +// } +// echo "
".$sum['question']."
$key$val

"; +// } +} + +function makeSummaryFromRawData($results, $sid=null, $gid=null, $qid=null) { + + //echo "
";print_r($results);echo "
"; + if (empty($results)) { + return array(); + } + if (!empty($qid)) { + $thisquestion=getQuestionInfo($qid); + } + $rowcodes=array_keys($results[0]); +// echo "
";print_r($rowcodes);echo "
"; + + $summary = array(); + foreach ($results as $result) { + foreach($rowcodes as $row) { + //echo "
";print_r($result);echo "
"; + + if (is_array($result[$row])) { + //echo "
";print_r($result);echo "
"; + $summary[$row]['question']=$result[$row][0]; + switch($thisquestion['type']) { + case "T": + case "S": + case "H": + if ($result[$row][1] != "") { + if (!isset($summary[$row]['summary'][_SV_RESPONSECOUNT])) { + $summary[$row]['summary'][_SV_RESPONSECOUNT]=1; + } else { + $summary[$row]['summary'][_SV_RESPONSECOUNT]++; + } + } + break; + default: + if (!isset($summary[$row]['summary'][$result[$row][1]])) { + $summary[$row]['summary'][$result[$row][1]]=1; + } else { + $summary[$row]['summary'][$result[$row][1]]++; + } + break; + } + } + if ($thisquestion['type'] == "N") { + ksort($summary[$row]['summary'], SORT_NUMERIC); + } + } + } + //echo "
";print_r($summary);echo "
"; + //fill in the blanks from answer table and sort + if (isset($sid) && isset($qid) && $summary) { + //$thissurvey=getSurveyInfo($sid); + $rowcodes=array_keys($summary); + switch($thisquestion['type']){ + case "F": + case "H": + $answers=getLabelSet($thisquestion['lid']); + break; + case "!": + case "L": + case "O": + $answers=getAnswersSingle($sid, $gid, $qid); + $answers[]=array("code"=>"", "answer"=>_NOANSWER); + break; + case "W": + case "Z": + $answers=getLabelSet($thisquestion['lid']); + $answers[]=array("code"=>"", "answer"=>_NOANSWER); + break; + case "C": + $answers[]=array("code"=>"Y", "answer"=>_YES); + $answers[]=array("code"=>"U", "answer"=>_UNCERTAIN); + $answers[]=array("code"=>"N", "answer"=>_NO); + break; + case "E": + $answers[]=array("code"=>"I", "answer"=>_INCREASE); + $answers[]=array("code"=>"S", "answer"=>_SAME); + $answers[]=array("code"=>"D", "answer"=>_DECREASE); + $answers[]=array("code"=>"", "answer"=>_NOANSWER); + break; + case "M": + case "P": + $answers[]=array("code"=>"Y", "answer"=>_YES); + $answers[]=array("code"=>"", "answer"=>_NOANSWER); + break; + case "Y": + $answers[]=array("code"=>"Y", "answer"=>_YES); + $answers[]=array("code"=>"N", "answer"=>_NO); + $answers[]=array("code"=>"", "answer"=>_NOANSWER); + break; + case "G": + $answers[]=array("code"=>"M", "answer"=>_MALE); + $answers[]=array("code"=>"F", "answer"=>_FEMALE); + $answers[]=array("code"=>"", "answer"=>_NOANSWER); + break; + case "T": + case "S": + case "U": + $answers[]=array("code"=>_SV_RESPONSECOUNT, "answer"=>_SV_RESPONSECOUNT); + $answers[]=array("code"=>"", "answer"=>_NOANSWER); + break; + } // switch + + if (isset($answers)) { + foreach($rowcodes as $row) { + $newarray[$row]['question']=$summary[$row]['question']; + foreach($answers as $answer) { + //echo "
";print_r($answer);echo "
"; + if (isset($summary[$row]['summary'][$answer['answer']])) { + $newarray[$row]['summary'][$answer['answer']]=$summary[$row]['summary'][$answer['answer']]; + } else { + $newarray[$row]['summary'][$answer['answer']]=0; + } + } + } + $summary=$newarray; + } + } + + //Fix the output for multiple + if ($thisquestion['type'] == "M" || $thisquestion['type'] == "P") { + if (isset($newarray)) {unset($newarray);} + $newarray[$thisquestion['sid']."X".$thisquestion['gid']."X".$thisquestion['qid']]['question']=$thisquestion['question']; + foreach ($summary as $sum) { + ereg("\[(.*)\]", $sum['question'], $regs); + $newarray[$thisquestion['sid']."X".$thisquestion['gid']."X".$thisquestion['qid']]['summary'][$regs[1]]=$sum['summary'][_YES]; + } + $summary=$newarray; + } +// echo "
";print_r($summary);echo "
"; + return $summary; +} + +function giveMeRawDataFromFieldNames($sid, $gid, $qid, $fieldlimiters=array(), $output="full") { + //Builds output data for question $sid$gid$qid, limiting with $fieldlimiters array + $questionfields = buildQuestionFields($sid, $qid); + $sql = buildSqlFromFieldnamesArray($fieldlimiters); + $tablename = "survey_".$sid; + $fieldmap=createFieldMap($sid, "full"); + //echo "
"; print_r($answers); echo "
"; + list($questioninfo, $results) = returnQuestionResults($sid, $questionfields, $sql); + //echo "
"; print_r($questioninfo); echo "
"; + if (count($results) < 1) { + return array(); + } + foreach ($questioninfo as $qi) { + $questiontype=$qi['type']; + } +// echo "[$questiontype]
"; + if ($output == "full") { + loadPublicLangFile($sid); + //echo "
"; print_r($answers); echo "
"; + switch($questiontype) { + case "L": + case "!": + case "O": + case "D": + case "E": + case "M": + case "P": + case "C": + case "B": + case "A": + case "F": + case "H": + $answers = getAnswersSingle($sid, $gid, $qid); + break; + case "W": + case "Z": + $thisquestion=getQuestionInfo($qid); + $answers=getLabelSet($thisquestion['lid']); + break; + case "Y": + $answers[]=array("code"=>"Y", "answer"=>_YES); + $answers[]=array("code"=>"N", "answer"=>_NO); + break; + case "G": + $answers[]=array("code"=>"M", "answer"=>_MALE); + $answers[]=array("code"=>"F", "answer"=>_FEMALE); + break; + } // switch + $answers[]=array("code"=>"", "answer"=>_NOANSWER); + $answers[]=array("code"=>"-oth-", "answer"=>_OTHER); + + switch($questiontype) { + case "A": + for ($i=1; $i <= 5; $i++) { + $values[]=array("code"=>$i, "answer"=>$i); + } + break; + case "B": + for ($i=1; $i<=10; $i++) { + $values[]=array("code"=>$i, "answer"=>$i); + } + break; + case "E": + $values[]=array("code"=>"I", "answer"=>_INCREASE); + $values[]=array("code"=>"S", "answer"=>_SAME); + $values[]=array("code"=>"D", "answer"=>_DECREASE); + break; + case "C": + case "M": + case "P": + $values[]=array("code"=>"Y", "answer"=>_YES); + $values[]=array("code"=>"U", "answer"=>_UNCERTAIN); + $values[]=array("code"=>"N", "answer"=>_NO); + break; + case "F": + case "H": + $thisquestion=getQuestionInfo($qid); + $values = getLabelSet($thisquestion['lid']); + break; + } + $values[]=array("code"=>"", "answer"=>_NOANSWER); + + switch($questiontype) { + case "L": + case "!": + case "O": + case "Y": + case "G": + case "S": + case "T": + case "H": + case "N": + case "5": + case "D": + case "W": + case "Z": + //The first key needs to be expanded + $firstkey=array_keys($results[0]); + $firstkey=$firstkey[0]; + $questions=arraySearchByKey($firstkey, $fieldmap, "fieldname", 1); + //echo $firstkey; + $i=0; + foreach($results as $result) { + $results[$i][$firstkey]=array($questions['question'], arraySubstitute($result[$firstkey], $answers)); + $i++; + } + break; + case "A": + case "B": + case "C": + case "E": + case "F": + case "H": + case "M": + case "P": + case "Q": + $i=0; + foreach($results as $result) { + foreach($result as $key=>$val) { + $questions=arraySearchByKey($key, $fieldmap, "fieldname", 1); + if (substr($key, -7, 7) != "comment") { + $code=substr($key, strlen($sid."X".$gid."X".$qid), strlen($key)-strlen($sid."X".$gid."X".$qid)); + //echo $code; + $results[$i][$key]=array($questions['question'], arraySubstitute($val, $values)); + } + } + $i++; + } + break; + } // switch + } + return $results; +} + +function buildSqlFromFieldnamesArray($fieldnamesarray) { + //Expects an array like this: "1x2x3"=>"FL" + //and builds SQL "where" statement out of it (without the "WHERE" at the front) + if (count($fieldnamesarray)) { + foreach ($fieldnamesarray as $key=>$val) { + if ($val == "{NULL}") { + $sql[] = "$key IS NULL"; + } else { + $sql[] = "$key = '$val'"; + } + } + if (count($sql) > 1) { + return implode(" AND\n", $sql); + } else { + return $sql[0]; + } + } +} + +function buildQuestionFields($sid, $qid) { + //Takes a specific question, and returns an array containing + //all the possible fieldnames for responses to that question + $fieldmap=createFieldMap($sid); + foreach ($fieldmap as $fields) { + if ($fields['sid'] == $sid && $fields['qid'] == $qid && $fields['aid'] != "comment") { + $questionfields[]=$fields['fieldname']; + } + } + if (!empty($questionfields)) { + return $questionfields; + } else { + return array("id"); + } +} + +function returnQuestionResults($sid, $questionfields, $sql=null) { + //Returns uninterpreted raw results from survey table for question(s) + //$table = survcey table name (ie: "survey_1") + //$questionfields should contain an array of the question fields that are being returned + //$sql is any additional "filtering" sql code + $details=array(); + $output=array(); + foreach($questionfields as $questionfield) { + $detailsarray=arraySearchByKey($questionfield, createFieldMap($sid), "fieldname"); + foreach ($detailsarray as $dt) { + $details[]=$dt; + } + } + $table="survey_".$sid; + + if (count($questionfields) > 1) { + $selects = "`".implode("`, `", $questionfields)."`"; + } else { + $selects = "`".$questionfields[0]."`"; + } + $query = "SELECT $selects + FROM $table"; + if (!empty($sql)) { + $query .= "\nWHERE $sql"; + } + $result = mysql_query($query) or die("error getting results in returnQuestionResults
$query
".mysql_error()); + while($row=mysql_fetch_array($result, MYSQL_ASSOC)) { + $output[]=$row; + } // while + return array($details, $output); +} + +function getAnswersSingle($sid, $gid, $qid) { + global $dbprefix; + $query = "SELECT * + FROM {$dbprefix}answers + WHERE qid=$qid + ORDER BY sortorder, answer"; + $result = mysql_query($query); + while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { + $answer[]=array("code"=>$row['code'], + "answer"=>$row['answer']); + } // while + return $answer; +} + +function getLabelSet($lid) { + global $dbprefix; + $query = "SELECT * + FROM {$dbprefix}labels + WHERE lid=$lid + ORDER BY sortorder, title"; + $result = mysql_query($query) or die(mysql_error()); + while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { + $answer[]=array("code"=>$row['code'], + "answer"=>$row['title']); + } // while + return $answer; +} + +function arraySubstitute($value, $substitutes) { + foreach ($substitutes as $sub) { + if ($value == $sub['code']) { + return $sub['answer']; + } + } + return $value; +} +?> \ No newline at end of file