Example #1
0
 function saveRecord()
 {
     if (Config::useDataRecords() == false) {
         return;
     }
     global $db, $survey;
     $key = $survey->getDataEncryptionKey();
     $data = "?";
     if ($key != "") {
         $data = "aes_encrypt(?, '" . $key . "')";
     }
     $datanames = $this->getDataNames();
     $names = '';
     if (is_array($datanames)) {
         sort($datanames);
         $names = implode("~", $datanames);
     }
     //echo implode("~", $datanames) . '----';
     if ($this->newrecord == true) {
         $query = "insert into " . Config::dbSurveyData() . "_datarecords (suid, primkey, datanames, data) values (?,?,?,{$data})";
         $bp = new BindParam();
         $bp->add(MYSQL_BINDING_INTEGER, $this->suid);
         $bp->add(MYSQL_BINDING_STRING, $this->primkey);
         $bp->add(MYSQL_BINDING_STRING, gzcompress($names, 9));
         $data = gzcompress(serialize($this->data), 9);
         $bp->add(MYSQL_BINDING_STRING, $data);
         $db->executeBoundQuery($query, $bp->get());
         //echo 'new<br/>';
     } else {
         $query = "update " . Config::dbSurveyData() . "_datarecords set datanames=?, data={$data} where suid=? and primkey=?";
         $bp = new BindParam();
         $bp->add(MYSQL_BINDING_STRING, gzcompress(implode("~", $datanames), 9));
         $data = gzcompress(serialize($this->data), 9);
         $bp->add(MYSQL_BINDING_STRING, $data);
         $bp->add(MYSQL_BINDING_INTEGER, $this->suid);
         $bp->add(MYSQL_BINDING_STRING, $this->primkey);
         $db->executeBoundQuery($query, $bp->get());
         //echo 'update<br/>';
     }
 }
Example #2
0
 function getAggregrateDataOld($variable)
 {
     global $survey, $db;
     $arr = array();
     $decrypt = "data as data_dec";
     if ($survey->getDataEncryptionKey() != "") {
         $decrypt = "aes_decrypt(data, '" . $survey->getDataEncryptionKey() . "') as data_dec";
     }
     if (Config::useDataRecords()) {
         $query = "select {$decrypt} from " . Config::dbSurveyData() . "_datarecords where suid=" . $survey->getSuid() . $extracompleted . " order by primkey";
     } else {
         $query = "select {$decrypt} from " . Config::dbSurveyData() . "_data where suid=" . $survey->getSuid() . " and variablename='" . VARIABLE_PRIMKEY . "' " . $extracompleted . " order by primkey";
     }
     $res = $db->selectQuery($query);
     $datanames = array();
     if ($res) {
         if ($db->getNumberOfRows($res) == 0) {
             return 'No records found';
         } else {
             /* go through records */
             while ($row = $db->getRow($res)) {
                 $record = new DataRecord();
                 $record->setAllData(unserialize(gzuncompress($row["data_dec"])));
                 $data = $record->getDataForVariable($variable->getName());
                 foreach ($data as $rec) {
                     $arr[$rec->getAnswer()]++;
                 }
             }
         }
     }
     return $arr;
 }
Example #3
0
 function getDataFromSurvey($d, $variablename, $default = '')
 {
     // using data records
     if (Config::useDataRecords()) {
         $var = $d->getData($variablename);
         if (isset($var)) {
             return $var->getAnswer();
         } else {
             return $default;
         }
     }
     // fall back on _data table
     global $db;
     $surv = new Survey($d->getSuid());
     $decrypt = "answer as answer_dec";
     if ($surv->getDataEncryptionKey() != "") {
         $decrypt = "aes_decrypt(answer, '" . $surv->getDataEncryptionKey() . "') as answer_dec";
     }
     $query = "select " . $decrypt . " from " . Config::dbSurveyData() . "_data where suid=" . $d->getSuid() . " and primkey='" . $d->getPrimaryKey() . "' and variablename='" . $variablename . "'";
     $res = $db->selectQuery($query);
     if ($res) {
         if ($db->getNumberOfRows($res) > 0) {
             $row = $db->getRow($res);
             return $row["answer_dec"];
         }
     }
     // not found or something went wrong
     return $default;
 }