/** * Update the report table with a determinated case data * @param string $proUid * @param string $appUid * @param string $appNumber * @param string $caseData */ public function updateReportTables($proUid, $appUid, $appNumber, $caseData, $appStatus) { G::loadClass('pmTable'); //get all Active Report Tables $criteria = new Criteria('workflow'); $criteria->add(AdditionalTablesPeer::PRO_UID, $proUid); $dataset = AdditionalTablesPeer::doSelectRS($criteria); $dataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); // accomplish all related report tables for this process that contain case data // for the target ($appUid) application while ($dataset->next()) { $row = $dataset->getRow(); $className = $row['ADD_TAB_CLASS_NAME']; // verify if the report table class exists if (!file_exists(PATH_WORKSPACE . 'classes/' . $className . '.php')) { continue; } // the class exists then load it. require_once PATH_WORKSPACE . 'classes/' . $className . '.php'; // create a criteria object of report table class $c = new Criteria(pmTable::resolveDbSource($row['DBS_UID'])); // select all related records with this $appUid eval('$c->add(' . $className . 'Peer::APP_UID, \'' . $appUid . '\');'); eval('$records = ' . $className . 'Peer::doSelect($c);'); //Select all types require_once 'classes/model/Fields.php'; $criteriaField = new Criteria('workflow'); $criteriaField->add(FieldsPeer::ADD_TAB_UID, $row['ADD_TAB_UID']); $datasetField = FieldsPeer::doSelectRS($criteriaField); $datasetField->setFetchmode(ResultSet::FETCHMODE_ASSOC); $fieldTypes = array(); while ($datasetField->next()) { $rowfield = $datasetField->getRow(); switch ($rowfield['FLD_TYPE']) { case 'FLOAT': case 'DOUBLE': case 'INTEGER': $fieldTypes[] = array($rowfield['FLD_NAME']=>$rowfield['FLD_TYPE']); break; default: break; } } switch ($row['ADD_TAB_TYPE']) { //switching by report table type case 'NORMAL': // parsing empty values to null if (!is_array($caseData)) { $caseData = unserialize($caseData); } foreach ($caseData as $i => $v) { foreach ($fieldTypes as $key => $fieldType) { foreach ($fieldType as $name => $type) { if ( strtoupper ( $i) == $name) { $v = validateType ($v, $type); unset($name); } } } $caseData[$i] = $v === '' ? null : $v; } if (is_array($records) && count($records) > 0) { // if the record already exists on the report table foreach ($records as $record) { //update all records if (method_exists($record, 'setAppStatus')) { $record->setAppStatus($appStatus); } $record->fromArray(array_change_key_case($caseData, CASE_UPPER), BasePeer::TYPE_FIELDNAME); if ($record->validate()) { $record->save(); } } } else { // there are not any record for this application on the table, then create it eval('$obj = new ' . $className . '();'); $obj->fromArray(array_change_key_case($caseData, CASE_UPPER), BasePeer::TYPE_FIELDNAME); $obj->setAppUid($appUid); $obj->setAppNumber($appNumber); if (method_exists($obj, 'setAppStatus')) { $obj->setAppStatus($appStatus); } $obj->save(); } break; case 'GRID': list($gridName, $gridUid) = explode('-', $row['ADD_TAB_GRID']); $gridData = isset($caseData[$gridName]) ? $caseData[$gridName] : array(); // delete old records if (is_array($records) && count($records) > 0) { foreach ($records as $record) { $record->delete(); } } // save all grid rows on grid type report table foreach ($gridData as $i => $gridRow) { eval('$obj = new ' . $className . '();'); //Parsing values foreach ($gridRow as $j => $v) { foreach ($fieldTypes as $key => $fieldType) { foreach ($fieldType as $name => $type) { if ( strtoupper ( $j) == $name) { $v = validateType ($v, $type); unset($name); } } } $gridRow[$j] = $v === '' ? null : $v; } $obj->fromArray(array_change_key_case($gridRow, CASE_UPPER), BasePeer::TYPE_FIELDNAME); $obj->setAppUid($appUid); $obj->setAppNumber($appNumber); if (method_exists($obj, 'setAppStatus')) { $obj->setAppStatus($appStatus); } $obj->setRow($i); $obj->save(); } break; } } }
static function validateClassName($var, $className) { return validateType($var, "object") && get_class($var) === $className; }
function checkVar($target, $untrusted_value, $awaited_type, $min, $max, $default_value, $label, $array_return, $die_on_fail) { $value_accepted = true; $error = ""; // 1. filter value according to target (web page or database) // converts to correct charset, removes unwanted values, encodes special chars // does nothing if not $target = "" $untrusted_value = filterValue($target, $untrusted_value); // 2. checks var content against awaited type if ($awaited_type != "") { $value_accepted = validateType($target, $untrusted_value, $awaited_type); if ($value_accepted == 0) { $error .= "bad type, " . $awaited_type . " awaited."; } } else { // sets var type if not specified, for next check against bounds if (is_numeric($untrusted_value)) { $awaited_type = "float"; } else { $awaited_type = "string"; } } // 3. checks var content against bounds if ($value_accepted) { // numeric : checks var content against values bounds if ($awaited_type == "int" || $awaited_type == "float" || $awaited_type == "hex") { echo $awaited_type . "<br>"; $value_accepted = validateValue($untrusted_value, $min, $max); if (!$value_accepted) { $error .= "bad value, " . $min . " to " . $max . " expected."; } } // string : checks var content against length bounds if ($awaited_type == "string" || $awaited_type == "date" || $awaited_type == "url" || $awaited_type == "email") { $value_accepted = validateLength($untrusted_value, $min, $max); if (!$value_accepted) { $error .= "bad length, " . $min . " to " . $max . " chars expected."; } } } if ($value_accepted) { switch ($array_return) { case 0: // returns a single value without feedback return $untrusted_value; break; case 1: // returns an array with filtered value or default value with error feedback if validation fails (useful for form validation) return array("ok" => true, "value" => $untrusted_value, "error" => ""); } } else { if ($die_on_fail) { exit("Fatal error :: bad var value detected"); if ($debug_mode == "on") { echo "<br>'" . $label . "' " . $error; } } switch ($array_return) { case 0: // returns a single value without feedback return $default_value; break; case 1: // returns an array with filtered value or default value with error feedback if validation fails (useful for form validation) return array("ok" => false, "value" => $default_value, "error" => "'" . $label . "' " . $error); } } }