Esempio n. 1
0
 function generateAuxiliary()
 {
     $_SESSION['PARAMETER_RETRIEVAL'] = PARAMETER_SURVEY_RETRIEVAL;
     set_time_limit(0);
     ini_set('memory_limit', Config::dataExportMemoryLimit());
     /* set file names */
     $this->setProperty(DATA_OUTPUT_FILENAME_CSV, $this->getProperty(DATA_OUTPUT_FILENAME) . "_auxiliary.csv");
     /* set arrays */
     if (trim($this->getProperty(DATA_OUTPUT_MODES)) != "") {
         $this->setProperty(DATA_OUTPUT_MODES, explode("~", $this->getProperty(DATA_OUTPUT_MODES)));
     } else {
         $this->setProperty(DATA_OUTPUT_MODES, array());
     }
     if (trim($this->getProperty(DATA_OUTPUT_LANGUAGES)) != "") {
         $this->setProperty(DATA_OUTPUT_LANGUAGES, explode("~", $this->getProperty(DATA_OUTPUT_LANGUAGES)));
     } else {
         $this->setProperty(DATA_OUTPUT_LANGUAGES, array());
     }
     if (trim($this->getProperty(DATA_OUTPUT_VERSIONS)) != "") {
         $this->setProperty(DATA_OUTPUT_VERSIONS, explode("~", $this->getProperty(DATA_OUTPUT_VERSIONS)));
     } else {
         $this->setProperty(DATA_OUTPUT_VERSIONS, array());
     }
     $this->languages = $this->getProperty(DATA_OUTPUT_LANGUAGES);
     $this->modes = $this->getProperty(DATA_OUTPUT_MODES);
     $this->versions = $this->getProperty(DATA_OUTPUT_VERSIONS);
     $extracompleted = '';
     /* get records to consider if only completed */
     if ($this->getProperty(DATA_OUTPUT_COMPLETED) == INTERVIEW_COMPLETED) {
         $extracompleted = " and completed=" . $this->getProperty(DATA_OUTPUT_COMPLETED);
     }
     if ($this->getProperty(DATA_OUTPUT_FROM) != "") {
         $extracompleted .= " and ts > '" . $this->getProperty(DATA_OUTPUT_FROM) . "'";
     }
     if ($this->getProperty(DATA_OUTPUT_TO) != "") {
         $extracompleted .= " and ts < '" . $this->getProperty(DATA_OUTPUT_TO) . "'";
     }
     $datanames = array();
     $extra = "";
     if ($this->getProperty(DATA_OUTPUT_TYPE) == DATA_OUTPUT_TYPE_DATARECORD_TABLE) {
         $query = "select distinct datanames from " . $this->getProperty(DATA_OUTPUT_MAINDATATABLE) . "_datarecords where suid=" . $this->suid . " and length(primkey) >= " . $this->minprimkeylength . " and length(primkey) <= " . $this->maxprimkeylength . $extracompleted . $extra;
         $res = $this->db->selectQuery($query);
         if ($res) {
             if ($this->db->getNumberOfRows($res) == 0) {
                 return 'No records found';
             } else {
                 /* go through records */
                 while ($row = $this->db->getRow($res)) {
                     $datanames = array_unique(array_merge($datanames, explode("~", gzuncompress($row["datanames"]))));
                     $row = null;
                     unset($row);
                 }
             }
         }
     } else {
         $query = "select distinct variablename from " . $this->getProperty(DATA_OUTPUT_MAINDATATABLE) . "_data where suid=" . $this->suid . " and length(primkey) >= " . $this->minprimkeylength . " and length(primkey) <= " . $this->maxprimkeylength . $extracompleted . $extra;
         $res = $this->db->selectQuery($query);
         if ($res) {
             if ($this->db->getNumberOfRows($res) == 0) {
                 return 'No records found';
             } else {
                 /* go through records */
                 while ($row = $this->db->getRow($res)) {
                     $datanames[] = $row["variablename"];
                     $row = null;
                     unset($row);
                 }
                 $datanames = array_unique($datanames);
             }
         }
     }
     // check for filter
     $filter = array();
     if ($this->getProperty(DATA_OUTPUT_VARLIST) != "") {
         $filter = explode("~", $this->getProperty(DATA_OUTPUT_VARLIST));
     }
     /* collect data names */
     $vars = array();
     foreach ($datanames as $d) {
         $vd = $this->getVariableDescriptive(getBasicName($d));
         if ($vd->getVsid() != "") {
             // if info not found, then ignore since we don't know how to handle it
             // hidden variable
             if ($this->getProperty(DATA_OUTPUT_HIDDEN) == HIDDEN_YES && $vd->isHidden()) {
                 continue;
             } else {
                 if (sizeof($filter) > 0 && !inArray($vd->getName(), $filter)) {
                     continue;
                 }
             }
             // create index to track
             $section = $this->getSection($vd->getSeid());
             $key = $vd->getSuid() . $vd->getSeid() . $vd->getVsid();
             if (isset($vars[$key])) {
                 $arrtemp = $vars[$key];
                 $arr = $arrtemp["vars"];
             } else {
                 $arr = array();
             }
             //$arr[strtoupper($d)] = $vd; // this needs to work to ensure we are getting the right array and putting it in $vars array
             $arr[] = strtoupper($d);
             // this needs to work to ensure we are getting the right array and putting it in $vars array
             //$vars[$key] = array("sectionposition" => $section->getPosition(), "seid" => $vd->getSeid(), "varposition" => $vd->getPosition(), "vsid" => $vd->getVsid(), "varname" => strtoupper($vd->getName()), "vars" => $arr);
             $vars[$key] = array("order" => $section->getPosition() . $vd->getSeid() . $vd->getPosition() . $vd->getVsid(), "vars" => $arr);
         }
     }
     $datanames = null;
     unset($datanames);
     $varnames = array();
     /* sort data names by section position, section seid, variable position, variable name */
     uasort($vars, 'dataexportSort');
     // get variable names
     foreach ($vars as $key => $subvars) {
         //echo "<br/>" . $key;
         $subvars = $subvars["vars"];
         ksort($subvars, SORT_STRING);
         // sort by variable name
         foreach ($subvars as $d) {
             $varnames[] = $d;
         }
     }
     /* start writing files */
     $outputtype = strtolower($this->getProperty(DATA_OUTPUT_FILETYPE));
     $this->startCSVAuxiliaryFile();
     // no variables
     if (sizeof($varnames) == 0) {
         return 'No records found';
     }
     $this->separator = ",";
     /* go through all entries */
     // datarecords based
     if ($this->getProperty(DATA_OUTPUT_TYPE) == DATA_OUTPUT_TYPE_DATARECORD_TABLE) {
         $decrypt = "data as data_dec";
         if ($this->survey->getDataEncryptionKey() != "") {
             $decrypt = "aes_decrypt(data, '" . $this->survey->getDataEncryptionKey() . "') as data_dec";
         }
         $query = "select *, {$decrypt} from " . $this->getProperty(DATA_OUTPUT_MAINDATATABLE) . "_datarecords where suid=" . $this->suid . " and length(primkey) >= " . $this->minprimkeylength . " and length(primkey) <= " . $this->maxprimkeylength . " " . $extracompleted . " order by primkey";
         $res = $this->db->selectQuery($query);
         if ($res) {
             if ($this->db->getNumberOfRows($res) == 0) {
                 return 'No records found';
             } else {
                 /* go through records */
                 while ($row = $this->db->getRow($res)) {
                     $record = new DataRecord();
                     $record->setAllData(unserialize(gzuncompress($row["data_dec"])));
                     for ($i = 0; $i < sizeof($varnames); $i++) {
                         $variable = $record->getData($varnames[$i]);
                         $line = "";
                         if ($variable) {
                             /* no match on language, mode and version, then treat as never gotten */
                             if (!(sizeof($this->languages) == 0 || sizeof($this->languages) > 0 && inArray($variable->getLanguage(), $this->languages))) {
                                 //
                                 continue;
                             } else {
                                 if (!(sizeof($this->modes) == 0 || sizeof($this->modes) > 0 && inArray($variable->getMode(), $this->modes))) {
                                     //
                                     continue;
                                 }
                             }
                             if ($this->getProperty(DATA_OUTPUT_PRIMARY_KEY_IN_DATA) != PRIMARYKEY_NO) {
                                 if ($this->getProperty(DATA_OUTPUT_PRIMARY_KEY_ENCRYPTION) != "") {
                                     $prim = encryptC($row["primkey"], $this->getProperty(DATA_OUTPUT_PRIMARY_KEY_ENCRYPTION));
                                 } else {
                                     $prim = $row["primkey"];
                                 }
                                 $line .= $prim . $this->separator;
                             }
                             // language, mode, version, timestamp
                             $line .= strtolower($varnames[$i]) . $this->separator . $variable->getLanguage() . $this->separator . $variable->getMode() . $this->separator . $variable->getVersion() . $this->separator . $variable->getTs();
                             fwrite($this->csvhandle, $line . "\n");
                             $line = null;
                             unset($line);
                         }
                     }
                     $record = null;
                     $row = null;
                     unset($record);
                     unset($row);
                 }
             }
         }
     } else {
         $query = "select distinct primkey from " . $this->getProperty(DATA_OUTPUT_MAINDATATABLE) . "_data where suid=" . $this->suid . " and length(primkey) >= " . $this->minprimkeylength . " and length(primkey) <= " . $this->maxprimkeylength . " " . $extracompleted . " order by primkey";
         $res = $this->db->selectQuery($query);
         if ($res) {
             if ($this->db->getNumberOfRows($res) == 0) {
                 return 'No records found';
             } else {
                 while ($row = $this->db->getRow($res)) {
                     $query2 = "select * from " . $this->getProperty(DATA_OUTPUT_MAINDATATABLE) . "_data where suid=" . $this->suid . " and primkey='" . $row["primkey"] . "'";
                     $currentrecord = array();
                     $res2 = $this->db->selectQuery($query2);
                     if ($res2) {
                         while ($row2 = $this->db->getRow($res2)) {
                             /* no match on language, mode and version, then treat as never gotten */
                             if (!(sizeof($this->languages) == 0 || sizeof($this->languages) > 0 && inArray($row2["language"], $this->languages))) {
                                 //
                                 continue;
                             } else {
                                 if (!(sizeof($this->modes) == 0 || sizeof($this->modes) > 0 && inArray($row2["mode"], $this->modes))) {
                                     //
                                     continue;
                                 }
                             }
                             $currentrecord[strtoupper($row2["variablename"])] = array("name" => $row2["variablename"], "language" => $row2["language"], "mode" => $row2["mode"], "version" => $row2["version"], "ts" => $row2["ts"]);
                             $row2 = null;
                             unset($row2);
                         }
                         // loop through variables
                         for ($i = 0; $i < sizeof($varnames); $i++) {
                             $line = "";
                             if (isset($currentrecord[strtoupper($varnames[$i])])) {
                                 $info = $currentrecord[strtoupper($varnames[$i])];
                                 if ($this->getProperty(DATA_OUTPUT_PRIMARY_KEY_IN_DATA) != PRIMARYKEY_NO) {
                                     if ($this->getProperty(DATA_OUTPUT_PRIMARY_KEY_ENCRYPTION) != "") {
                                         $prim = encryptC($row["primkey"], $this->getProperty(DATA_OUTPUT_PRIMARY_KEY_ENCRYPTION));
                                     } else {
                                         $prim = $row["primkey"];
                                     }
                                     $line .= $prim . $this->separator;
                                 }
                                 $line .= strtolower($varnames[$i]) . $this->separator . $info["language"] . $this->separator . $info["mode"] . $this->separator . $info["version"] . $this->separator . $info["ts"];
                                 fwrite($this->csvhandle, $line . "\n");
                                 $info = null;
                                 unset($info);
                                 $line = null;
                                 unset($line);
                             }
                         }
                         $currentrecord = null;
                         unset($currentrecord);
                     }
                     $row = null;
                     unset($row);
                 }
             }
         }
     }
     /* finish */
     $this->finishCSVFile();
     $_SESSION['PARAMETER_RETRIEVAL'] = PARAMETER_ADMIN_RETRIEVAL;
 }
Esempio n. 2
0
    function showModalNewAddress($respondent)
    {
        $content = '  
<!-- Modal -->
<div class="modal fade" id="myModal' . $respondent->getHhOrder() . '" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">' . Language::buttonClose() . '</span></button>
        <h4 class="modal-title" id="myModalLabel">' . Language::labelRespondentNewAddress() . '</h4>
      </div>
      <div class="modal-body">';
        $d = new DataRecord(1, $respondent->getHhid());
        $var = $d->getData('HR016[' . $respondent->getHhOrder() . ']');
        if (isset($var)) {
            $content .= $var->getAnswer();
        } else {
            $content .= Language::labelRespondentAddressUnknown();
        }
        $content .= '
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">' . Language::buttonClose() . '</button>
      </div>
    </div>
  </div>
</div> 
';
        return $content;
    }