function getContactCodeData($code, $urid = 0, $rorh = 2)
 {
     global $db;
     $dataStr = '';
     $actions = array();
     $uridstr = '';
     if ($urid > 0) {
         $uridstr = ' t1.urid = ' . $urid . ' AND ';
     } else {
         $uridstr = $this->getUridQuery('t2.');
     }
     if ($rorh == 1) {
         //houseohld level
         $query = 'select DATE(t1.ts) as dateobs, count(*) as cntobs, t1.primkey from ' . dbConfig::dbSurvey() . '_contacts as t1 ';
         $query .= 'left join ' . dbConfig::dbSurvey() . '_households as t2 on t2.primkey = t1.primkey ';
         $query .= 'where ' . $uridstr . getTextmodeStr() . ' t1.ts > "' . date('Y-m-d', config::graphStartDate()) . ' 23:59:99" AND t2.primkey is not null and t1.code = ' . $code . ' group by DATE(t1.ts) order by t1.ts asc';
     } else {
         $query = 'select DATE(t1.ts) as dateobs, count(*) as cntobs, t1.primkey from ' . dbConfig::dbSurvey() . '_contacts as t1 ';
         $query .= 'left join ' . dbConfig::dbSurvey() . '_respondents t2 on t2.primkey = t1.primkey ';
         $query .= 'where ' . $uridstr . getTextmodeStr() . ' t1.ts > "' . date('Y-m-d', config::graphStartDate()) . ' 23:59:99" AND t2.primkey is not null and t1.code = ' . $code . ' group by DATE(t1.ts) order by t1.ts asc';
         //$query = 'select DATE(ts) as dateobs, count(*) as cntobs, primkey from ' . dbConfig::dbSurvey()  . '_contacts as t1 where code = ' . $code . $uridstr . ' group by DATE(ts) order by ts asc';
     }
     //                echo '<br/><br/><br/>' . $query;
     $total = 0;
     $dataStr .= "[Date.UTC(" . date('Y,m,d', strtotime(date('Y-m-d', config::graphStartDate()) . " -1 months")) . "), 0   ],";
     $result = $db->selectQuery($query);
     while ($row = $db->getRow($result)) {
         $key = $row['dateobs'];
         $total += $row['cntobs'];
         $dataStr .= "[Date.UTC(" . substr($key, 0, 4) . ", " . (substr($key, 5, 2) - 1) . ", " . substr($key, 8, 2) . "), " . $total . "],";
     }
     $returnStr = rtrim($dataStr, ',');
     return $returnStr;
 }
Example #2
0
 function getRefusalsByUrid($urid)
 {
     global $db;
     if (isset($this->refusalsByUridArray[$urid])) {
         $contacts = $this->refusalsByUridArray[$urid];
     } else {
         $contacts = array();
         //$csidQuery = ' AND code = 103 ';
         //   $result = $db->selectQuery('select *, aes_decrypt(remark, "' . Config::smsContactRemarkKey() . '") as remark_dec, aes_decrypt(proxyname, "' . Config::smsContactNameKey() . '") as proxyname_dec from ' . Config::dbSurvey() . '_contacts as t1 left join ' . Config::dbSurvey() . '_users as t2 on t1.urid = t2.urid where t1.urid = ' . prepareDatabaseString($urid) . $csidQuery . ' order by t1.contactts desc');
         //echo '<br/><br/><br/>'. 'select *, aes_decrypt(remark, "' . Config::smsContactRemarkKey() . '") as remark_dec, aes_decrypt(proxyname, "' . Config::smsContactNameKey() . '") as proxyname_dec from ' . Config::dbSurvey() . '_contacts as t1 left join ' . Config::dbSurvey() . '_users as t2 on t1.urid = t2.urid where t1.urid = ' . prepareDatabaseString($urid) . ' order by t1.contactts desc';
         $query = 'select *, aes_decrypt(remark, "' . Config::smsContactRemarkKey() . '") as remark_dec, aes_decrypt(proxyname, "' . Config::smsContactNameKey() . '") as proxyname_dec from ' . Config::dbSurvey() . '_contacts as t1 ';
         $query .= 'left join ' . Config::dbSurvey() . '_users as t2 on t1.urid = t2.urid ';
         $query .= 'left join ' . Config::dbSurvey() . '_respondents as t3 on t1.primkey = t3.primkey ';
         $query .= 'where t3.primkey is not null AND ' . getTextmodeStr() . ' t1.urid = ' . prepareDatabaseString($urid) . ' order by t1.contactts desc';
         $result = $db->selectQuery($query);
         while ($row = $db->getRow($result)) {
             $contact = new Contact($row);
             if ($contact->isRefusal()) {
                 $contacts[] = $contact;
             }
         }
         $this->refusalsByUridArray[$urid] = $contacts;
     }
     return $contacts;
 }