Esempio n. 1
0
 /**
  * Do insert record
  *
  * @param array $inputRecord
  * @return void
  */
 protected function _doInsert($inputRecord)
 {
     $dataRec = new DataRecord(null, $this->getDataObj());
     // $inputRecord['Id'] = null; // comment it out for name PK case
     foreach ($inputRecord as $k => $v) {
         $dataRec[$k] = $v;
     }
     // or $dataRec->$k = $v;
     try {
         $dataRec->save();
     } catch (ValidationException $e) {
         $errElements = $this->getErrorElements($e->m_Errors);
         if (count($e->m_Errors) == count($errElements)) {
             $this->formHelper->processFormObjError($errElements);
         } else {
             $errmsg = implode("<br />", $e->m_Errors);
             BizSystem::clientProxy()->showErrorMessage($errmsg);
         }
         return;
     } catch (BDOException $e) {
         $this->processBDOException($e);
         return;
     }
     $this->m_ActiveRecord = null;
     $this->getActiveRecord($dataRec["Id"]);
     //$this->runEventLog();
     return $dataRec["Id"];
 }
Esempio n. 2
0
 /**
  * Update login time
  *
  * @return void
  */
 protected function UpdateloginTime()
 {
     $userObj = BizSystem::getObject('system.do.UserDO');
     $curRecs = $userObj->directFetch("[username]='" . $this->username . "'", 1);
     if (count($curRecs) == 0) {
         return false;
     }
     $dataRec = new DataRecord($curRecs[0], $userObj);
     $dataRec['lastlogin'] = date("Y-m-d H:i:s");
     $ok = $dataRec->save();
     return true;
 }
Esempio n. 3
0
 public function put($resource, $id, $request, $response)
 {
     $format = strtolower($request->params('format'));
     $DOName = $this->getDOName($resource);
     if (empty($DOName)) {
         $response->status(404);
         $response->body("Resource '{$resource}' is not found.");
         return;
     }
     $dataObj = BizSystem::getObject($DOName);
     $rec = $dataObj->fetchById($id);
     if (empty($rec)) {
         $response->status(404);
         $response->body("No data is found for {$resource} {$id}");
         return;
     }
     $dataRec = new DataRecord($rec, $dataObj);
     $inputRecord = json_decode($request->getBody());
     if ($inputRecord->password != $inputRecord->password_repeat) {
         $errors['password_repeat'] = "Password repeat is not same as password";
         $this->setErrorResponse(400, $errors, $response, $format);
         return;
     }
     foreach ($inputRecord as $k => $v) {
         // if password is ********, ignore password value
         if ($k == 'password' && $v == '********') {
             continue;
         }
         if ($k == 'password') {
             $v = hash(HASH_ALG, $v);
         }
         if ($k == 'password_repeat') {
             continue;
         }
         $dataRec[$k] = $v;
         // or $dataRec->$k = $v;
     }
     try {
         $dataRec->save();
     } catch (ValidationException $e) {
         $response->status(400);
         $errmsg = implode("\n", $e->m_Errors);
         $response->body($errmsg);
         return;
     } catch (BDOException $e) {
         $response->status(400);
         $response->body($e->getMessage());
         return;
     }
     return $this->setResponse($dataRec->toArray(), $response, $format);
 }
 public function put($resource, $id, $request, $response)
 {
     $inputRecord = json_decode($request->getBody());
     $format = strtolower($request->params('format'));
     try {
         $this->validateInputs($inputRecord);
     } catch (ValidationException $e) {
         $this->setErrorResponse(400, $e->m_Errors, $response, $format);
         return;
     }
     $DOName = $this->getDOName($resource);
     if (empty($DOName)) {
         $response->status(404);
         $response->body("Resource '{$resource}' is not found.");
         return;
     }
     $dataObj = BizSystem::getObject($DOName);
     $rec = $dataObj->fetchById($id);
     if (empty($rec)) {
         $response->status(400);
         $response->body("No data is found for {$resource} {$id}");
         return;
     }
     $dataRec = new DataRecord($rec, $dataObj);
     $dataRec['password'] = hash(HASH_ALG, $inputRecord->password_new);
     try {
         $dataRec->save();
     } catch (ValidationException $e) {
         $this->setErrorResponse(400, $e->m_Errors, $response, $format);
         return;
     } catch (BDOException $e) {
         $this->setErrorResponse(400, $e->m_Errors, $response, $format);
         return;
     }
     $this->setNoticeResponse("Data is successfully saved.", $response, $format);
 }
 /**
  * Dispatch an action based on the request passed.
  * @param Request $request
  * @param Response $response
  * @return type 
  */
 public function dispatch(Request $request, Response $response = null)
 {
     // FB::group("[".__METHOD__."] dispatch: $request->action");
     $this->route($request);
     if ($response == null) {
         $response = new Response();
     }
     // register request and response here and at plugs
     $this->setRequest($request);
     $this->setResponse($response);
     do {
         $request->setDispatched(true);
         $this->preDispatch($request);
         /**
          * Skip requested action if preDispatch() has reset it
          */
         if (!$this->getRequest()->isDispatched()) {
             continue;
         }
         fb($request, __METHOD__);
         fb($response, __METHOD__);
         try {
             $controller = $this->getController($request, $response);
             $controller->dispatch($request, $response);
         } catch (Exception $exc) {
             // FB::groupEnd();
             // FB::groupEnd();
             fb($exc);
             fb($controller);
             $o = DataRecord::createErrorOutSt();
             $o['data'] = $exc;
             $response->loadData($exc);
         }
         /**
          * zend post dispatch with the plugin broker.
          */
         $this->postDispatch($request);
     } while (!$request->isDispatched());
     if ($this->returnResponse()) {
         return $this->getResponse();
     }
     $this->getResponse()->sendResponse();
     // FB::groupEnd();
 }
Esempio n. 6
0
 function generate()
 {
     $_SESSION['PARAMETER_RETRIEVAL'] = PARAMETER_SURVEY_RETRIEVAL;
     set_time_limit(0);
     ini_set('memory_limit', Config::dataExportMemoryLimit());
     /* 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());
     }
     /* set file names */
     $this->setProperty(DATA_OUTPUT_FILENAME_STATA, $this->getProperty(DATA_OUTPUT_FILENAME) . ".dta");
     $this->setProperty(DATA_OUTPUT_FILENAME_CSV, $this->getProperty(DATA_OUTPUT_FILENAME) . ".csv");
     $extracompleted = "";
     if ($this->getProperty(DATA_OUTPUT_COMPLETED) == INTERVIEW_COMPLETED) {
         $extracompleted = " and completed=" . $this->getProperty(DATA_OUTPUT_COMPLETED);
     }
     // find any data names in the data
     $extra = "";
     if ($this->getProperty(DATA_OUTPUT_FROM) != "") {
         $extra .= " and ts > '" . $this->getProperty(DATA_OUTPUT_FROM) . "'";
     }
     if ($this->getProperty(DATA_OUTPUT_TO) != "") {
         $extra .= " and ts < '" . $this->getProperty(DATA_OUTPUT_TO) . "'";
     }
     $datanames = array();
     $this->maxwidths = array();
     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);
                 }
             }
             $res = null;
             unset($res);
             // get max width
             $decrypt = "answer";
             if ($this->survey->getDataEncryptionKey() != "") {
                 $decrypt = "cast(aes_decrypt(answer, '" . $this->survey->getDataEncryptionKey() . "') as char)";
             }
             $query = "SELECT variablename, MAX( LENGTH( " . $decrypt . " )) AS max FROM " . $this->getProperty(DATA_OUTPUT_MAINDATATABLE) . "_data WHERE suid = " . $this->suid . " and length(primkey) >= " . $this->minprimkeylength . " and length(primkey) <= " . $this->maxprimkeylength . $extra . $extracompleted . " GROUP BY variablename";
             $res = $this->db->selectQuery($query);
             if ($res) {
                 if ($this->db->getNumberOfRows($res) == 0) {
                 } else {
                     /* go through records */
                     while ($row = $this->db->getRow($res)) {
                         $this->maxwidths[strtoupper($row["variablename"])] = $row["max"];
                         $row = null;
                         unset($row);
                     }
                 }
                 $res = null;
                 unset($res);
             }
         }
     } else {
         $decrypt = ", MAX( LENGTH(answer)) as max";
         if ($this->survey->getDataEncryptionKey() != "") {
             $decrypt = ", MAX( LENGTH( cast(aes_decrypt(answer, '" . $this->survey->getDataEncryptionKey() . "') as char))) AS max";
         }
         $query = "select variablename" . $decrypt . " from " . $this->getProperty(DATA_OUTPUT_MAINDATATABLE) . "_data where suid=" . $this->suid . " and length(primkey) >= " . $this->minprimkeylength . " and length(primkey) <= " . $this->maxprimkeylength . $extracompleted . $extra . " group by variablename";
         //echo $query;
         //exit;
         $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"];
                     $this->maxwidths[strtoupper($row["variablename"])] = $row["max"];
                     $row = null;
                     unset($row);
                 }
             }
             $res = null;
             unset($res);
         }
     }
     // check for filter
     $filter = array();
     if ($this->getProperty(DATA_OUTPUT_VARLIST) != "") {
         $filter = explode("~", $this->getProperty(DATA_OUTPUT_VARLIST));
         //echo $this->getProperty(DATA_OUTPUT_VARLIST);
         //exit;
     }
     /* collect info to sort */
     $vars = array();
     $this->arrayfields = array();
     $this->skipvariables = array();
     $this->descriptives = 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;
                 }
             }
             // array and not a specific instance, then store for later so we know to process it differently
             if ($vd->isArray() && contains($d, "[") == false) {
                 $this->arrayfields[strtoupper($d)] = strtoupper($d);
             }
             // 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);
             $vd = null;
             unset($vd);
         }
     }
     $datanames = null;
     unset($datanames);
     /* collect variables not found in data */
     if ($this->getProperty(DATA_OUTPUT_VARIABLES_WITHOUT_DATA) == VARIABLES_WITHOUT_DATA_YES) {
         $this->variabledescriptives = $this->survey->getVariableDescriptives();
         foreach ($this->variabledescriptives as $vd) {
             //echo 'going to add: ' . $vd->getName() . "<br/>";
             // hidden variable
             if ($this->getProperty(DATA_OUTPUT_HIDDEN) == DATA_HIDDEN && $vd->isHidden()) {
                 continue;
             } else {
                 if (inArray($vd->getAnswerType(), array(ANSWER_TYPE_NONE, ANSWER_TYPE_SECTION))) {
                     continue;
                 } else {
                     if (sizeof($filter) > 0 && !inArray($vd->getName(), $filter)) {
                         continue;
                     }
                 }
             }
             // array, then store for later so we know to process it differently
             if ($vd->isArray()) {
                 $this->arrayfields[strtoupper($vd->getName())] = strtoupper($vd->getName());
             }
             $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($vd->getName())] = $vd;
             $arr[] = strtoupper($vd->getName());
             //$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);
             // no width set, so first time, then no data at all so we set width to 2
             if (!isset($this->maxwidths[strtoupper($vd->getName())])) {
                 $this->maxwidths[strtoupper($vd->getName())] = 2;
             }
             //$vd = null;
             //unset($vd);
         }
     }
     /* sort data names by section position, section seid, variable position, variable name */
     uasort($vars, 'dataexportSort');
     /* retrieve variable information */
     foreach ($vars as $key => $subvars) {
         //echo "<br/>" . $key;
         $subvars = $subvars["vars"];
         sort($subvars, SORT_STRING);
         // sort by variable name
         foreach ($subvars as $d) {
             $this->processVariable($d, $this->getVariableDescriptive(getBasicName($d)));
         }
         $vars[$key] = null;
     }
     $vars = null;
     unset($vars);
     $this->descriptives = null;
     unset($this->descriptives);
     /* check for primkey variable presence */
     if ($this->getProperty(DATA_OUTPUT_PRIMARY_KEY_IN_DATA) != PRIMARYKEY_NO) {
         /* TODO */
     }
     /* set number of variables */
     $this->variablenumber = sizeof($this->variablenames);
     /* get number of records */
     if ($this->getProperty(DATA_OUTPUT_TYPE) == DATA_OUTPUT_TYPE_DATARECORD_TABLE) {
         $query = "select count(*) as cnt 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);
         $row = $this->db->getRow($res);
         $this->recordcount = $row["cnt"];
     } 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 . $extra;
         $res = $this->db->selectQuery($query);
         $this->recordcount = $this->db->getNumberOfRows($res);
     }
     /* start writing files */
     $outputtype = strtolower($this->getProperty(DATA_OUTPUT_FILETYPE));
     $this->asked = sprintf('%.0F', "8.988465625461158E307");
     if ($outputtype == FILETYPE_CSV) {
         $this->startCSVFile();
         $this->separator = ",";
     } else {
         if ($outputtype == FILETYPE_STATA) {
             $this->startStataFile();
             $this->littleendian = $this->isLittleEndian();
             // http://www.stata.com/help.cgi?dta_113
             $this->shortempty = 32741;
             $this->shorterror = 32763;
             $this->shortdk = 32745;
             $this->shortna = 32755;
             $this->shortrf = 32759;
             $this->shortmarkempty = 32746;
             $this->doubleempty = sprintf('%.0F', "8.98846567431158E307");
             // 2^1013
             $this->doubledk = sprintf('%.0F', "8.99724347282165E307");
             $this->doublerf = sprintf('%.0F', "9.027965767606894E307");
             $this->doublemarkempty = sprintf('%.0F', "8.98846567431158E307") * 1.001220703125;
             $this->doublena = sprintf('%.0F', "8.98846567431158E307") * 1.00341796875;
             $this->doubleerror = sprintf('%.0F', "8.98846567431158E307") * 1.00537109375;
             // floats not used right now
             $this->floatempty = sprintf('%.0F', "1.7014118E38F");
             $this->floatdk = sprintf('%.0F', "1.7030734E38F");
             $this->floatna = sprintf('%.0F', "1.7030734E38F");
             // TODO
             $this->floatrf = sprintf('%.0F', "1.7088887E38F");
             $this->floatmarkempty = sprintf('%.0F', "1.7030734E38F");
         }
     }
     // get languages, modes, versions
     $this->languages = $this->getProperty(DATA_OUTPUT_LANGUAGES);
     $this->modes = $this->getProperty(DATA_OUTPUT_MODES);
     $this->versions = $this->getProperty(DATA_OUTPUT_VERSIONS);
     $this->encoding = $this->getProperty(DATA_OUTPUT_ENCODING);
     /* go through all records */
     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 primkey, {$decrypt} from " . $this->getProperty(DATA_OUTPUT_MAINDATATABLE) . "_datarecords where suid=" . $this->suid . " and length(primkey) >= " . $this->minprimkeylength . " and length(primkey) <= " . $this->maxprimkeylength . $extracompleted . $extra . " 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($this->suid, $row["primkey"]);
                     $record = new DataRecord();
                     $record->setAllData(unserialize(gzuncompress($row["data_dec"])));
                     if ($outputtype == FILETYPE_CSV) {
                         $this->addCSVRecord($row["primkey"], $record);
                     } else {
                         if ($outputtype == FILETYPE_STATA) {
                             $this->addStataRecord($row["primkey"], $record);
                         }
                     }
                     $record = null;
                     $row = null;
                     unset($record);
                     unset($row);
                 }
             }
         }
     } else {
         // we already got all distinct primkeys before when we determined the number of records
         if ($res) {
             if ($this->db->getNumberOfRows($res) == 0) {
                 return 'No records found';
             } else {
                 $decrypt = "answer as data_dec";
                 if ($this->survey->getDataEncryptionKey() != "") {
                     $decrypt = "aes_decrypt(answer, '" . $this->survey->getDataEncryptionKey() . "') as data_dec";
                 }
                 /* go through records */
                 while ($row = $this->db->getRow($res)) {
                     $query = "select primkey, variablename, {$decrypt}, language, mode, version, dirty from " . $this->getProperty(DATA_OUTPUT_MAINDATATABLE) . "_data where suid=" . $this->suid . " and primkey='" . $row["primkey"] . "'";
                     $this->currentrecord = array();
                     //echo $query;
                     //exit;
                     $res2 = $this->db->selectQuery($query);
                     if ($res2) {
                         while ($row2 = $this->db->getRow($res2)) {
                             $this->currentrecord[strtoupper($row2["variablename"])] = array("name" => $row2["variablename"], "dirty" => $row2["dirty"], "answer" => $row2["data_dec"], "language" => $row2["language"], "mode" => $row2["mode"], "version" => $row2["version"]);
                             $row2 = null;
                             unset($row2);
                         }
                         if (sizeof($this->currentrecord) > 0) {
                             if ($outputtype == FILETYPE_CSV) {
                                 $this->addCSVRecord($row["primkey"]);
                             } else {
                                 if ($outputtype == FILETYPE_STATA) {
                                     $this->addStataRecord($row["primkey"]);
                                 }
                             }
                         }
                         $this->currentrecord = null;
                         unset($this->currentrecord);
                     }
                     $query = null;
                     unset($query);
                     $res2 = null;
                     unset($res2);
                     $row = null;
                     unset($row);
                 }
             }
         }
     }
     /* finish */
     if ($outputtype == FILETYPE_CSV) {
         $this->finishCSVFile();
     } else {
         if ($outputtype == FILETYPE_STATA) {
             $this->addValueLabels();
             $this->finishStataFile();
         }
     }
     $_SESSION['PARAMETER_RETRIEVAL'] = PARAMETER_ADMIN_RETRIEVAL;
 }
Esempio n. 7
0
 public function ShareRecord()
 {
     $prtForm = $this->m_ParentFormName;
     if (!$prtForm) {
         return;
     }
     $prtFormObj = BizSystem::GetObject($prtForm);
     $recId = $this->m_ParentRecordId;
     $dataObj = $prtFormObj->getDataObj();
     $dataRec = $dataObj->fetchById($recId);
     $recArr = $this->readInputRecord();
     $DataRec = $dataRec;
     $DataRecOld = $dataRec;
     $currentRecord = $DataRecOld->toArray();
     //notice users has new shared data
     //test if changed a new owner
     if ($recArr['notify_user']) {
         $data = $this->fetchData();
         $data['app_index'] = APP_INDEX;
         $data['app_url'] = APP_URL;
         $data['operator_name'] = BizSystem::GetProfileName(BizSystem::getUserProfile("Id"));
         $emailSvc = BizSystem::getService(USER_EMAIL_SERVICE);
         if ($DataRec['owner_id'] != $recArr['owner_id']) {
             $emailSvc->DataAssignedEmail($recArr['owner_id'], $data);
         }
         //test if changes for group level visiable
         if ($recArr['group_perm'] >= 1) {
             $group_id = $recArr['group_id'];
             $userList = $this->_getGroupUserList($group_id);
             foreach ($userList as $user_id) {
                 $emailSvc->DataSharingEmail($user_id, $data);
             }
         }
         //test if changes for other group level visiable
         if ($recArr['other_perm'] >= 1) {
             $groupList = $this->_getGroupList();
             foreach ($groupList as $group_id) {
                 if ($recArr['group_id'] == $group_id) {
                     continue;
                 }
                 $userList = $this->_getGroupUserList($group_id);
                 foreach ($userList as $user_id) {
                     $emailSvc->DataSharingEmail($user_id, $data);
                 }
             }
         }
     }
     if (isset($recArr['group_perm'])) {
         $DataRec['group_perm'] = $recArr['group_perm'];
     }
     if (isset($recArr['other_perm'])) {
         $DataRec['other_perm'] = $recArr['other_perm'];
     }
     if (isset($recArr['group_id'])) {
         $DataRec['group_id'] = $recArr['group_id'];
     }
     if (isset($recArr['owner_id'])) {
         $DataRec['owner_id'] = $recArr['owner_id'];
     }
     if (isset($recArr['create_by'])) {
         $DataRec['create_by'] = $recArr['create_by'];
         $DataRec['update_by'] = $recArr['create_by'];
         $DataRec['update_time'] = date('Y-m-d H:i:s');
     }
     $DataRec->save();
     $inputRecord = $recArr;
     //$prtFormObj->getDataObj()->updateRecord($newDataRec,$dataRec);
     //save change log
     $postFields = $_POST;
     $elem_mapping = array();
     foreach ($postFields as $elem_name => $value) {
         $elem = $this->m_DataPanel->get($elem_name);
         $fld_name = $elem->m_FieldName;
         if ($elem) {
             $elem_mapping[$fld_name] = $elem;
         }
     }
     $logDO = $dataObj->getRefObject($this->m_LogDO);
     if ($logDO) {
         $cond_column = $logDO->m_Association['CondColumn'];
         $cond_value = $logDO->m_Association['CondValue'];
         if ($cond_column) {
             $type = $cond_value;
         }
         $foreign_id = $currentRecord['Id'];
         $logRecord = array();
         foreach ($inputRecord as $fldName => $fldVal) {
             $oldVal = $currentRecord[$fldName];
             if ($oldVal == $fldVal) {
                 continue;
             }
             if ($oldVal === null || $fldVal === null) {
                 continue;
             }
             $elem = $elem_mapping[$fldName]->m_XMLMeta;
             if (!$elem) {
                 $elem = $this->m_DataPanel->getByField($fldName)->m_XMLMeta;
             }
             $logRecord[$fldName] = array('old' => $oldVal, 'new' => $fldVal, 'element' => $elem);
         }
         $formMetaLite = array("name" => $this->m_Name, "package" => $this->m_Package, "message_file" => $this->m_MessageFile);
         // save to comment do
         $logRec = new DataRecord(null, $logDO);
         $logRec['foreign_id'] = $foreign_id;
         $logRec['type'] = $type;
         $logRec['form'] = serialize($formMetaLite);
         $logRec['data'] = serialize($logRecord);
         $logRec['comment'] = $comment;
         $logRec->save();
     }
     //end save change log
     if ($recArr['update_ref_data']) {
         if ($dataObj->m_ObjReferences->count()) {
             $this->_casacadeUpdate($dataObj, $recArr);
         }
     }
     if ($this->m_ParentFormName) {
         $this->close();
         $this->renderParent();
     }
     $this->processPostAction();
 }
Esempio n. 8
0
 /**
  * Update login time
  *
  * @return void
  */
 protected function UpdateloginTime()
 {
     $userObj = BizSystem::getObject('system.do.UserDO');
     try {
         $curRecs = $userObj->directFetch("[username]='" . $this->username . "'", 1);
         $dataRec = new DataRecord($curRecs[0], $userObj);
         $dataRec['lastlogin'] = date("Y-m-d H:i:s");
         $ok = $dataRec->save();
         if (!$ok) {
             $errorMsg = $userObj->getErrorMessage();
             BizSystem::log(LOG_ERR, "DATAOBJ", "DataObj error = " . $errorMsg);
             BizSystem::ClientProxy()->showErrorMessage($errorMsg);
             return false;
         }
     } catch (BDOException $e) {
         $errorMsg = $e->getMessage();
         BizSystem::log(LOG_ERR, "DATAOBJ", "DataObj error = " . $errorMsg);
         BizSystem::ClientProxy()->showErrorMessage($errorMsg);
         return false;
     }
     return true;
 }
Esempio n. 9
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;
    }
Esempio n. 10
0
 /**
  * Import from CSV file
  * NOTE: This method must be called from a popup form where a file is uploaded.
  *       The parent form of the popup form is the target to import.
  *
  * @param string $objName
  * @return void
  */
 public function importCSV($objName)
 {
     // read in file from $_FILE
     foreach ($_FILES as $file) {
         $error = $file['error'];
         if ($error != 0) {
             $this->reportError($error);
             return;
         }
         $tmpFileName = $file['tmp_name'];
         break;
     }
     //echo "upload file name = $tmpFileName";
     $filename = $file['name'];
     if (strpos($filename, ".csv") === false) {
         $errorMsg = BizSystem::getMessage("EXCELSVC_INVALID_FILE", array($filename));
         BizSystem::log(LOG_ERR, "EXCEL SERVICE", "Import error = " . $errorMsg);
         BizSystem::clientProxy()->showClientAlert($errorMsg);
         return;
     }
     /* @var $formObj EasyForm */
     $formObj = BizSystem::objectFactory()->getObject($objName);
     // get the existing EasyForm object
     $parentFormObj = BizSystem::objectFactory()->getObject($formObj->m_ParentFormName);
     $dataObj = $parentFormObj->getDataObj();
     $handle = fopen($tmpFileName, "r");
     $fields = fgetcsv($handle, 2000, ",");
     if (!$fields || count($fields) < 2) {
         $errorMsg = BizSystem::getMessage("EXCELSVC_INVALID_FILE", array($filename));
         BizSystem::log(LOG_ERR, "EXCEL SERVICE", "Import error = " . $errorMsg);
         BizSystem::clientProxy()->showClientAlert($errorMsg);
         return;
     }
     // convert form element names to DO field names
     foreach ($parentFormObj->m_DataPanel as $element) {
         $elem_fields[$element->m_Label] = $element->m_FieldName;
     }
     // validate with dataobj fields
     for ($i = 0; $i < count($fields); $i++) {
         $fields[$i] = $elem_fields[$fields[$i]];
         $field = $fields[$i];
         if (!$dataObj->getField($field)) {
             $errorMsg = BizSystem::getMessage("EXCELSVC_INVALID_COLUMN", array($field, $dataObj->m_Name));
             BizSystem::log(LOG_ERR, "EXCEL SERVICE", "Import error = " . $errorMsg);
             BizSystem::clientProxy()->showClientAlert($errorMsg);
             return;
         }
     }
     while (($arr = fgetcsv($handle, 2000, ",")) !== FALSE) {
         if (count($arr) != count($fields)) {
             continue;
         }
         unset($recArr);
         $i = 0;
         for ($i = 0; $i < count($arr); $i++) {
             $recArr[$fields[$i]] = $arr[$i];
         }
         //print_r($recArr); echo "<hr>";
         $dataRec = new DataRecord(null, $dataObj);
         foreach ($recArr as $k => $v) {
             $dataRec[$k] = $v;
         }
         $ok = $dataRec->save();
         if (!$ok) {
             // NOTE: EasyForm::processDataObjError() not return any value (void)
             return $formObj->processDataObjError($ok);
         }
     }
     fclose($handle);
     // in case of popup form, close it, then rerender the parent form
     if ($formObj->m_ParentFormName) {
         $formObj->close();
         $formObj->renderParent();
     }
 }
Esempio n. 11
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;
 }
Esempio n. 12
0
 /**
  * Do update record
  *
  * @param array $inputRecord
  * @param array $currentRecord
  * @return void
  */
 protected function _doUpdate($inputRecord, $currentRecord)
 {
     $dataRec = new DataRecord($currentRecord, $this->getDataObj());
     foreach ($inputRecord as $k => $v) {
         $dataRec[$k] = $v;
         // or $dataRec->$k = $v;
     }
     try {
         $dataRec->save();
     } catch (ValidationException $e) {
         $errElements = $this->getErrorElements($e->m_Errors);
         if (count($e->m_Errors) == count($errElements)) {
             $this->formHelper->processFormObjError($errElements);
         } else {
             $errmsg = implode("<br />", $e->m_Errors);
             BizSystem::clientProxy()->showErrorMessage($errmsg);
         }
         return false;
     } catch (BDOException $e) {
         $this->processBDOException($e);
         return false;
     }
     $this->m_ActiveRecord = null;
     $this->getActiveRecord($dataRec["Id"]);
     //$this->runEventLog();
     return true;
 }
Esempio n. 13
0
 /**
  * Save wizard data of current+previous pages into database or other storage
  *
  * @return void
  */
 public function commit()
 {
     // commit the form input. call SaveRecord()
     $recArr = $this->m_ActiveRecord;
     if ($this->m_FormType == "NEW") {
         $dataRec = new DataRecord(null, $this->getDataObj());
     } else {
         //$currentRec = $this->fetchData(); // wrong way to get current data. need to query the old one
         $currentRec = array();
         // to get record with "" values
         $dataRec = new DataRecord($currentRec, $this->getDataObj());
     }
     foreach ($recArr as $k => $v) {
         $dataRec[$k] = $v;
     }
     // or $dataRec->$k = $v;
     try {
         $dataRec->save();
     } catch (BDOException $e) {
         $this->processBDOException($e);
         return false;
     }
     return true;
 }
Esempio n. 14
0
 /**
  * BizForm::deleteRecord() - Delete the record of current row
  *
  * @return void
  */
 public function deleteRecord()
 {
     // TODO: support delete multiple records
     // read the id array from the check box list _REQUEST['row_selections']
     global $g_BizSystem;
     $values = BizSystem::clientProxy()->getFormInputs('row_selections', false);
     if ($values) {
         foreach ($values as $id) {
             $recArray = $this->getDataObj()->fetchById($id);
             $dataRec = new DataRecord($recArray, $this->getDataObj());
             // take care of exception
             try {
                 $dataRec->delete();
             } catch (BDOException $e) {
                 // call $this->processBDOException($e);
                 $this->processBDOException($e);
                 return;
             }
         }
     } else {
         $rec = $this->getActiveRecord();
         if (!$rec) {
             return;
         }
         global $g_BizSystem;
         //$recId = $this->m_ActiveRecord["Id"];
         $ok = $this->getDataObj()->deleteRecord($rec);
         if (!$ok) {
             return $this->processDataObjError($ok);
         }
     }
     $this->m_RecordId = null;
     // clean the current record id
     // TODO: adjust current page. if current page return no record, goto prev page
     $this->rerender();
 }
Esempio n. 15
0
 /**
  * Do insert record
  *
  * @param array $inputRecord
  * @return void
  */
 protected function _doInsert($inputRecord)
 {
     // check access, if deny, redirect to access deny page
     if ($this->m_Resource != "" && !$this->allowAccess($this->m_Resource . ".create")) {
         return BizSystem::clientProxy()->redirectView(ACCESS_DENIED_VIEW);
     }
     $dataRec = new DataRecord(null, $this->getDataObj());
     // $inputRecord['Id'] = null; // comment it out for name PK case
     foreach ($inputRecord as $k => $v) {
         $dataRec[$k] = $v;
     }
     // or $dataRec->$k = $v;
     try {
         $dataRec->save();
     } catch (ValidationException $e) {
         $errElements = $this->getErrorElements($e->m_Errors);
         if (count($e->m_Errors) == count($errElements)) {
             $this->processFormObjError($errElements);
         } else {
             $errmsg = implode("<br />", $e->m_Errors);
             BizSystem::clientProxy()->showErrorMessage($errmsg);
         }
         return;
     } catch (BDOException $e) {
         $this->processBDOException($e);
         return;
     }
     $this->m_ActiveRecord = null;
     $this->getActiveRecord($dataRec["Id"]);
     $this->runEventLog();
 }
Esempio n. 16
0
 public function delete($resource, $id, $request, $response)
 {
     $DOName = $this->getDOName($resource);
     if (empty($DOName)) {
         $response->status(404);
         $response->body("Resource '{$resource}' is not found.");
         return;
     }
     $dataObj = BizSystem::getObject($DOName);
     $rec = $dataObj->fetchById($id);
     if (empty($rec)) {
         $response->status(404);
         $response->body("No data is found for {$resource} {$id}");
         return;
     }
     $dataRec = new DataRecord($rec, $dataObj);
     try {
         $dataRec->delete();
     } catch (BDOException $e) {
         $response->status(500);
         $response->body($e->getMessage());
         return;
     }
     $format = strtolower($request->params('format'));
     return $this->setResponse($dataRec->toArray(), $response, $format);
 }