From 8c4d7373b4038d6dc4cd3d7c2e2bbbcf1b7be4f6 Mon Sep 17 00:00:00 2001 From: azammitdcarf Date: Thu, 28 May 2009 02:22:47 +0000 Subject: [PATCH] Appointment list: error in SQL No case available, now list quota row's Do not allow the assigning of a case_id or creation of a token in the Limesurvey tables where a transaction has failed --- appointmentlist.php | 2 +- functions/functions.operator.php | 34 +++++++++++++++++--------------- nocaseavailable.php | 21 ++++++++++++++++++++ 3 files changed, 40 insertions(+), 17 deletions(-) diff --git a/appointmentlist.php b/appointmentlist.php index 3d157ba6..00188764 100644 --- a/appointmentlist.php +++ b/appointmentlist.php @@ -75,7 +75,7 @@ else $sql = "SELECT q.description, DATE_FORMAT(CONVERT_TZ(c.start,'UTC',r.Time_zone_name),'".DATE_TIME_FORMAT."') as start,DATE_FORMAT(CONVERT_TZ(c.end,'UTC',r.Time_zone_name),'".TIME_FORMAT."') as end, c.completed_call_id, IFNULL(ou.firstName,'" . T_("Not yet called") . "') as firstName, r.firstName as rname, r.lastName as rsname, IFNULL(o.description,'" . T_("Not yet called") . "') as des FROM `appointment` as c JOIN respondent as r on (r.respondent_id = c.respondent_id) - JOIN `case` as ca on (ca.case_id = c.case_id) + JOIN `case` as cas on (cas.case_id = c.case_id) LEFT JOIN (`call` as ca, outcome as o, operator as ou) on (ca.call_id = c.completed_call_id and ca.outcome_id = o.outcome_id and ou.operator_id = ca.operator_id) WHERE oq.operator_id = '$operator_id' AND ca.questionnaire_id = oq.questionnaire_id diff --git a/functions/functions.operator.php b/functions/functions.operator.php index b2a2e114..1ba37809 100644 --- a/functions/functions.operator.php +++ b/functions/functions.operator.php @@ -428,21 +428,23 @@ function get_case_id($operator_id, $create = false) //add resopndent to Lime Survey token table for this questionnaire //first we need to get the limesurvey survey id - - $lime_sid = get_limesurvey_id($operator_id); - - if ($lime_sid) + + if (!$db->HasFailedTrans()) //if the transaction hasn't failed { - $sql = "INSERT INTO ".LIME_PREFIX."tokens_$lime_sid (tid,firstname,lastname,email,token,language,sent,completed,attribute_1,attribute_2,mpid) - VALUES (NULL,'','','',$case_id,'en','N','N','','',NULL)"; - - if (!$ldb->Execute($sql)) //if we cannot insert + $lime_sid = get_limesurvey_id($operator_id); + + if ($lime_sid) { - $db->FailTrans(); - $case_id = false; + $sql = "INSERT INTO ".LIME_PREFIX."tokens_$lime_sid (tid,firstname,lastname,email,token,language,sent,completed,attribute_1,attribute_2,mpid) + VALUES (NULL,'','','',$case_id,'en','N','N','','',NULL)"; + + if (!$ldb->Execute($sql)) //if we cannot insert + { + $db->FailTrans(); + $case_id = false; + } } } - } } else @@ -470,13 +472,13 @@ function get_case_id($operator_id, $create = false) } - //if ($db->HasFailedTrans()) { print "FAILED in get_case_id"; exit; } + if ($db->HasFailedTrans()) + { + error_log("FAILED in get_case_id for case $case_id",0); + $case_id = false; //make sure we aren't returning an invalid case id + } $db->CompleteTrans(); - /** - * @todo should re return some sort of status? Like "on appointment" "refusal" "supervisor"? - */ - return $case_id; } diff --git a/nocaseavailable.php b/nocaseavailable.php index e47cdf7e..e4f06285 100644 --- a/nocaseavailable.php +++ b/nocaseavailable.php @@ -196,6 +196,27 @@ if (isset($rs) && !empty($rs)) } } +//quota row's full +$sql = "SELECT questionnaire_sample_quota_row_id,q.questionnaire_id,sample_import_id,lime_sgqa,value,comparison,completions,quota_reached,q.lime_sid + FROM questionnaire_sample_quota_row as qsq, questionnaire as q, operator_questionnaire as oq + WHERE oq.operator_id = '$operator_id' + AND qsq.questionnaire_id = oq.questionnaire_id + AND q.questionnaire_id = oq.questionnaire_id"; + +$rs = $db->GetAll($sql); + +if (isset($rs) && !empty($rs)) +{ + foreach($rs as $r) + { + if ($r['quota_reached'] == 1) + { + print "

" . T_("POSSIBLE ERROR: Row quota reached for this question") . " - " . $r['lime_sgqa']; + } + } +} + + //no tokens table associated with questionnaire in limesurvey