diff --git a/CHANGELOG b/CHANGELOG index 93dc3425..4ec7d0f5 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -63,6 +63,9 @@ ALTER TABLE `outcome` ADD `default` TINYINT(1) UNSIGNED NOT NULL DEFAULT '1' COM /* -- define and set mandatory(constant) outcome_id's --*/ UPDATE `outcome` SET `permanent` = '1' WHERE `outcome`.`outcome_id` IN (1,2,3,7,9,10,14,17,18,19) ; +/* -- set AUTO_INCREMENT to 100 @ `outcome` to reserve some id's -- */ +ALTER TABLE `outcome` AUTO_INCREMENT = '100'; + /* -- add `outcomes` parameter , define default list of outcome_ID's to be enabled for new questionnaries --*/ ALTER TABLE `questionnaire` ADD `outcomes` VARCHAR(256) NULL DEFAULT '1,2,3,7,9,10,14,17,18,19' COMMENT 'Comma-separated string of outcomes defined for the questionnaire' AFTER `enabled`; diff --git a/admin/set_outcomes.php b/admin/set_outcomes.php index 9f11402e..cbbc847d 100644 --- a/admin/set_outcomes.php +++ b/admin/set_outcomes.php @@ -45,11 +45,12 @@ $js_foot = array( "../js/custom.js" ); -global $db; - +global $db; if (isset($_POST['default']) && isset($_POST['save'])){ + $db->StartTrans(); + $sql = "UPDATE `outcome` as o SET `default` = 0 WHERE o.permanent != 1"; @@ -66,25 +67,27 @@ if (isset($_POST['default']) && isset($_POST['save'])){ SET `default` = 1 WHERE o.permanent != 1 AND o.outcome_id IN ($sel)"; - - $db->Execute($sql); + $db->Execute($sql); } if(!empty($_POST['delay']) && $_SESSION['user'] === "admin" ){ - - foreach($_POST['delay'] as $n => $val) - { - $sql = "UPDATE `outcome`SET default_delay_minutes = $val WHERE outcome_id = $n"; - $db->Execute($sql); - } + foreach($_POST['delay'] as $n => $val) { + $db->Execute("UPDATE `outcome`SET default_delay_minutes = $val WHERE outcome_id = $n"); + } + } + if(!empty($_POST['delete']) && $_SESSION['user'] === "admin" ){ + foreach($_POST['delete'] as $n => $val) { + $db->Execute("DELETE FROM `outcome` WHERE outcome_id = $n AND outcome_id >= 100"); + } } - $_GET['default'] = $_POST['default']; + if($db->CompleteTrans()) $msg_ok = T_("Default outcomes updated"); else $msg_err = T_("Default outcomes NOT updated"); + $_GET['default'] = $_POST['default']; unset($_POST['default']); unset($_POST['save']); } -if (isset($_POST['qid']) && isset($_POST['save'])){ +if (isset($_POST['qid']) && $_POST['qid'] > 0 && isset($_POST['save'])){ //get id's for 'permanent' outcomes $sql = "SELECT o.outcome_id @@ -112,39 +115,98 @@ if (isset($_POST['qid']) && isset($_POST['save'])){ $sql = "UPDATE questionnaire SET outcomes = '$sel' WHERE questionnaire_id = $qid"; - - $db->Execute($sql); + if ($db->Execute($sql)) $msg_ok = T_("Questionnaire outcomes saved"); else $msg_err = T_("Error:") . " " . T("Questionnaire outcomes not saved"); $_GET['qid'] = $_POST['qid']; - unset($_POST['qid']); unset($_POST['save']); } +if ($_SESSION['user'] === "admin" && isset($_POST['addoutcome']) && isset($_POST['save'])){ + if (isset($_POST['description']) && !empty($_POST['description']) && intval($_POST['outcome_type_id']) > 0 ) { + $desc = $_POST['description']; + $outcome_type_id = intval($_POST['outcome_type_id']); + if (isset($_POST['default_delay_minutes'])) $ddm = $_POST['default_delay_minutes']; else $ddm = 0; + if (isset($_POST['contacted'])) $contacted = 1; else $contacted = 0; + if (isset($_POST['tryanother'])) $tryanother = 1; else $tryanother = 0; + if (isset($_POST['tryagain'])) $tryagain = 1; else $tryagain = 0; + if (isset($_POST['eligible'])) $eligible = 1; else $eligible = 0; + if (isset($_POST['require_note'])) $require_note = 1; else $require_note = 0; + if (isset($_POST['calc'])) $calc = $_POST['calc']; else $calc = ""; + if (isset($_POST['aapor_id'])) $aapor_id = $_POST['aapor_id']; else $aapor_id = ""; + if (isset($_POST['default_o'])) $def = 1; else $def = 0; + if (isset($_POST['permanent'])) $perm = 1; else $perm = 0; + + $sql = "INSERT INTO `outcome` VALUES ('NULL','$aapor_id','$desc','$ddm','$outcome_type_id','$tryanother','$contacted','$tryagain','$eligible','$require_note','$calc','$def','$perm')"; + if ($db->Execute($sql)) { + $msg_ok = T_("Custom outcome") . " " . $desc . " " . T_("saved"); + } + else $msg_err = T_("Error:") . " " . T_("New outcome not saved"); + } + else { + if (empty($_POST['description'])) $ms = T_("Description"); + if ($_POST['outcome_type_id'] <= 0) $ms = T_("Outcome type"); + $msg_err = T_("Error:") . " " . $ms . " " . T_("is not set"); + $_GET['addoutcome'] = $_POST['addoutcome']; + } + + if (isset($_POST['h']) && isset($_POST['v'])) {$h = $_POST['h']; $_GET[$h] = $_POST['v'];} + unset($_POST['addoutcome']); + unset($_POST['save']); +} /*select outcomes list*/ -if (isset($_GET['default'])) { $title = T_("Set default outcomes"); } -else if (isset($_GET['qid'])){ $title = T_("Set questionnaire outcomes"); $qid = intval($_GET['qid']); } +if (isset($_GET['default'])) $title = T_("Set default outcomes"); +else if (isset($_GET['qid'])) $title = T_("Set questionnaire outcomes"); +else if (isset($_GET['addoutcome'])) $title = T_("ADD custom outcome"); else die(); xhtml_head($title,true,$css,$js_head); + +/* to add customm outcome*/ +if ($_SESSION['user'] === "admin" && isset($_GET['addoutcome'])){ + + $rs[] = ["description" => "", "value" => ""]; + $sql = "SELECT outcome_type_id as value,description FROM `outcome_type`"; + $ot = $db->GetAll($sql); translate_array($ot, array("description")); + $select = display_chooser($ot,"outcome_type_id","outcome_type_id",true,false,false,true,false,false); + $rs[] = ["description" => "", "value" => "{$select}"]; + $rs[] = ["description" => "", "value" => ""]; + $rs[] = ["description" => "", "value" => ""]; + $rs[] = ["description" => "", "value" => ""]; + $rs[] = ["description" => "", "value" => ""]; + $rs[] = ["description" => "", "value" => ""]; + $rs[] = ["description" => "", "value" => ""]; + $rs[] = ["description" => "", "value" => ""]; + $rs[] = ["description" => "", "value" => ""]; + $rs[] = ["description" => "", "value" => ""]; + $rs[] = ["description" => "", "value" => ""]; + + $hid = "addoutcome"; $value = "newoutcome"; $h = $_GET['h']; $v = $_GET['v']; + $row = array("description","value"); + $hdr = array(T_("Description"),T_("Value")); + $sbtn = T_("Save custom Outcome"); + $class = "table-hover table-condensed"; +} + /* for questionnire outcomes */ if (isset($_GET['qid'])) { + $qid = intval($_GET['qid']); if($qid == 0) $qid = false; - print "

" . T_("Questionnaire") . ": 

"; + print "

" . T_("Questionnaire") . ": 

"; $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 "); + display_chooser($db->GetAll($sql),"questionnaire","qid",true,false,true,true,false,true,"form-inline"); + print "
"; - - if ($qid != false) + if ($qid != 0) { $qd = $db->GetRow("SELECT outcomes, self_complete, referral FROM `questionnaire` WHERE questionnaire_id = $qid"); @@ -164,13 +226,11 @@ if (isset($_GET['qid'])) { $do[] = $val; } } - $qoutc = implode($do,","); $sql = "UPDATE questionnaire SET outcomes = '$qoutc' WHERE questionnaire_id = $qid"; - $db->Execute($sql); } @@ -186,11 +246,12 @@ if (isset($_GET['qid'])) { ORDER BY `o`.`outcome_id` ASC"; $rs = $db->GetAll($sql); - + $hid = "qid"; $value = $qid; $h = "qid"; $v = $qid; $row = array("outcome_id","description","type","select"); - $hdr = array(T_("Outcome ID"),T_("Description"),T_("Outcome type"),T_("Select")); - $hid = "qid"; - $value = "$qid"; + $hdr = array(T_("Outcome ID"),T_("Description"),T_("Outcome type"),T_("Select")." ?"); + $abtn = T_("Add custom Outcome"); + $sbtn = T_("Save questionnaire outcomes"); + $class = "tclass"; } } @@ -199,29 +260,33 @@ if (isset($_GET['default'])) { /* allow delay edit only to superadmins (currenlty admin) */ if ($_SESSION['user'] === "admin"){ - $delay = "CONCAT('') "; + $delay = "CONCAT('') "; + $delete = "CASE WHEN o.outcome_id >= 100 THEN CONCAT('') ELSE '' END as `delete`,"; } else { $delay = "CONCAT('', o.default_delay_minutes ,' ')"; + $delete = ""; } - $sql = "SELECT o.*, ot.description as type, $delay as `delay`, - 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` + $sql = "SELECT o.*, ot.description as type, $delay as `delay`, $delete + 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 + 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","delay","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 = ""; + $hdr = array(T_("Outcome ID"),T_("Description"),T_("Set default")." ?",T_("Outcome type"),T_("Delay, min"),T_("Contacted")." ?",T_("Try another")." ?",T_("Try again")." ?",T_("Eligible")." ?",T_("Require note")." ?"); + if ($_SESSION['user'] === "admin"){ $row[] = "delete"; $hdr[] = T_("Delete")." ?";} + $hid = "default"; $value = ""; $h = "default"; $v = ""; + $abtn = T_("Add custom Outcome"); + $sbtn = T_("Update default outcomes"); + $class = "tclass"; } @@ -237,31 +302,38 @@ if (isset($rs) && !empty($rs)){ } } } - + + if (isset($msg_ok)) print "
" . $msg_ok . "
"; + if (isset($msg_err)) print "
" . $msg_err . "
"; + ?>
- - -
+ + + +
-
- +
+
-
- +
+ + + +
+
+
-