diff --git a/admin/index.php b/admin/index.php
index 6be6b8f4..75f41971 100644
--- a/admin/index.php
+++ b/admin/index.php
@@ -98,6 +98,7 @@ include ("../lang.inc.php");
+
@@ -161,8 +162,9 @@ include ("../lang.inc.php");
">
+
-
+
diff --git a/admin/set_outcomes.php b/admin/set_outcomes.php
new file mode 100644
index 00000000..60884676
--- /dev/null
+++ b/admin/set_outcomes.php
@@ -0,0 +1,252 @@
+Execute($sql);
+
+ if(!empty($_POST['select']) ){
+ foreach($_POST['select'] as $n => $val)
+ {
+ $sel[] = $val;
+ }
+ $sel=implode($sel,",");
+
+ $sql = "UPDATE `outcome` as o
+ SET `deflt` = 1
+ WHERE o.const != 1
+ AND o.outcome_id IN ($sel)";
+
+ $db->Execute($sql);
+ }
+
+ $_GET['default'] = $_POST['default'];
+
+ unset($_POST['default']);
+ unset($_POST['save']);
+}
+
+if (isset($_POST['qid']) && isset($_POST['save'])){
+
+ //get id's for 'constant' outcomes
+ $sql = "SELECT o.outcome_id
+ FROM `outcome` as o
+ WHERE o.const = 1
+ AND o.deflt = 1;";
+ $def = $db->GetAll($sql);
+
+ for ($i=0; $i < count($def); $i++){
+ foreach($def[$i] as $key => $val){
+ $sel[] = $val;
+ }
+ }
+
+ if(!empty($_POST['select']) ){
+ //add selected outcomes
+ foreach($_POST['select'] as $n => $val)
+ {
+ $sel[] = $val;
+ }
+ }
+
+ $sel=implode($sel,",");
+
+ print $sel . "";
+
+ $qid = intval($_POST['qid']);
+ $sql = "UPDATE questionnaire
+ SET outcomes = '$sel'
+ WHERE questionnaire_id = $qid";
+
+ $db->Execute($sql);
+
+
+ $_GET['qid'] = $_POST['qid'];
+
+ unset($_POST['qid']);
+ unset($_POST['save']);
+}
+
+
+
+/*select outcomes list*/
+
+if (isset($_GET['default'])) { $title = T_("Default outcomes"); }
+else if (isset($_GET['qid'])){ $title = T_("Questionnaire outcomes"); $qid = intval($_GET['qid']); }
+else die();
+
+xhtml_head($title,true,$css,$js_head);
+
+/* for questionnire outcomes */
+if (isset($_GET['qid'])) {
+
+ if($qid == 0) $qid = false;
+
+ print "";
+
+ $sql = "SELECT questionnaire_id as value,description, CASE WHEN questionnaire_id = '$qid' THEN 'selected=\'selected\'' ELSE '' END AS selected
+ FROM questionnaire
+ WHERE enabled = 1";
+ display_chooser($db->GetAll($sql),"questionnaire","qid", true,false,true,true,false,true,"form-inline pull-left ");
+
+
+ if ($qid != false)
+ {
+ $qoutc = $db->GetOne("SELECT q.outcomes FROM `questionnaire` as q WHERE q.questionnaire_id = $qid");
+
+ if (empty($qoutc)) { // update q.outcomes with default list
+
+ $sql = "SELECT o.outcome_id
+ FROM `outcome` as o
+ WHERE o.deflt = 1;";
+ $def = $db->GetAll($sql);
+
+ for ($i=0; $i < count($def); $i++){
+ foreach($def[$i] as $key => $val){
+ $do[] = $val;
+ }
+ }
+
+ $qoutc = implode($do,",");
+
+ $sql = "UPDATE questionnaire
+ SET outcomes = '$qoutc'
+ WHERE questionnaire_id = $qid";
+
+ $db->Execute($sql);
+ }
+
+ $sql = "SELECT o.*, ot.description as type,
+ CONCAT('') as `select`
+ from `outcome` as o, `outcome_type` as ot
+ WHERE o.outcome_type_id = ot.outcome_type_id
+ ORDER BY `o`.`outcome_id` ASC";
+
+ $rs = $db->GetAll($sql);
+
+ $row = array("outcome_id","description","type","select");
+ $hdr = array(T_("Outcome ID"),T_("Description"),T_("Outcome type"),T_("Select"));
+ $hid = "qid";
+ $value = "$qid";
+ }
+}
+
+/* for default outcomes */
+if (isset($_GET['default'])) {
+
+ $sql = "SELECT o.*, ot.description as type,
+ CONCAT(' " . T_("Yes") . "' ELSE 'default\">" . T_("No") . "' END , '
') as tryanother,
+ CONCAT(' " . T_("Yes") . "' ELSE 'default\">" . T_("No") . "' END , '
') as tryagain,
+ CONCAT(' " . T_("Yes") . "' ELSE 'default\">" . T_("No") . "' END , '
') as contacted,
+ CONCAT(' " . T_("Yes") . "' ELSE 'default\">" . T_("No") . "' END , '
') as eligible,
+ CONCAT(' " . T_("Yes") . "' ELSE 'default\">" . T_("No") . "' END , '
') as require_note,
+ CONCAT('') as `select`
+ from `outcome` as o, `outcome_type` as ot
+ WHERE o.outcome_type_id = ot.outcome_type_id
+ ORDER BY `o`.`outcome_id` ASC";
+
+ $rs = $db->GetAll($sql);
+
+ $row = array("outcome_id","description","select","type","default_delay_minutes","contacted","tryanother","tryagain","eligible","require_note");
+ $hdr = array(T_("Outcome ID"),T_("Description"),T_("Default"),T_("Outcome type"),T_("Delay, min"),T_("Contacted"),T_("Try another"),T_("Try again"),T_("Eligible"),T_("Require note"));
+ $hid = "default";
+ $value = "";
+
+}
+
+
+if (isset($rs) && !empty($rs)){
+
+ translate_array($rs, array("description","type"));
+
+ for ($i = 0; $i < count($rs); $i++){
+ foreach ($rs[$i] as $key => $val){
+ if ($key == "type"){
+ $rs[$i]['type'] = preg_replace("#\s*\(.+#m", '', $val); // cut description in bracets for 'outcome_type'
+ }
+ }
+ }
+
+
+?>
+
+
+
+
+
+
+
+
+
\ No newline at end of file