function GetProjectDetail($projId) { //Return metadata about the columns in each table for a given database (table_schema) $qry = "SELECT id, p_name, p_details FROM tb_projects where id = " . $projId; date_default_timezone_set('Australia/Sydney'); error_log("In project_get_detail.php...\n" . $qry); $dbConn = opendatabase(); $result = mysqli_query($dbConn, $qry); date_default_timezone_set('Australia/Sydney'); error_log("Records in Projects: " . mysqli_num_rows($result)); if (!$result || mysqli_num_rows($result) <= 0) { echo "Could not obtain metadata information."; return false; } /*****************************************************************/ $xml = new XMLWriter(); //$projXml = new DOMDocument(); //$xml->openURI("php://output"); $xml->openMemory(); $xml->startDocument(); $xml->setIndent(true); $xml->startElement("projects"); while ($row = mysqli_fetch_assoc($result)) { $xml->startElement("project"); $xml->writeAttribute('id', $projId); $xml->writeRaw($row['p_name']); $xml->endElement(); $xml->startElement("project_details"); $xml->startCData("details"); $xml->writeRaw($row['p_details']); $xml->endCData(); $xml->endElement(); } $xml->endElement(); $xml->endDocument(); $dbConn->close(); header('Content-type: text/xml'); $strXML = $xml->outputMemory(TRUE); $xml->flush(); date_default_timezone_set('Australia/Sydney'); error_log("String XML:\n " . $strXML); //$projXml->loadXML($strXML); echo $strXML; /***************************************************************** $options = array(); while ($row = mysqli_fetch_assoc($result)){ $options['object_row'][] = $row; } echo json_encode($options); *****************************************************************/ }
function GetProjectRubrics($projId) { //Return metadata about the columns in each table for a given database (table_schema) $qry = "SELECT r_level, r_text, task_id, tb_tasks.task_text FROM tb_rubrics " . "INNER JOIN tb_tasks ON tb_rubrics.task_id = tb_tasks.id " . "WHERE tb_tasks.project_id = " . $projId . " ORDER BY tb_tasks.id, tb_rubrics.r_level;"; date_default_timezone_set('Australia/Sydney'); error_log("In get_project_rubrics.php...\n" . $qry); $dbConn = opendatabase(); $result = mysqli_query($dbConn, $qry); date_default_timezone_set('Australia/Sydney'); error_log("Records in Projects: " . mysqli_num_rows($result)); $row_cnt = mysqli_num_rows($result); $field_cnt = $result->field_count; error_log("Fields: " . $field_cnt); if (!$result || mysqli_num_rows($result) <= 0) { //echo("Could not obtain metadata information."); return false; } /*****************************************************************/ $xml = new XMLWriter(); $xml->openMemory(); $xml->startDocument(); $xml->setIndent(true); $xml->startElement("task_rubrics"); /* fetch associative array */ /* $row = mysqli_fetch_row($result); for($i = 0; $i < $field_cnt; $i++){ error_log("Row[". $i . "] = " . $row[$i]); error_log("Row[". $i . "] = " . $row[$i].name); } */ /* $finfo = $result->fetch_fields(); foreach ($finfo as $val) { error_log("Name: " . $val->name); error_log("Table: " . $val->table); error_log("Max. Len: " . $val->max_length); error_log("Length: " . $val->length); error_log("charsetnr: " . $val->charsetnr); error_log("Flags: " . $val->flags); error_log("Type: " . $val->type); } $result->free(); */ while ($row = mysqli_fetch_assoc($result)) { $xml->startElement("task"); $xml->writeAttribute('id', $row['task_id']); $xml->writeRaw($row['task_text']); $xml->startElement("rubric_details"); $xml->writeAttribute('r_level', $row['r_level']); $xml->startCData("details"); $xml->writeRaw($row['r_text']); $xml->endCData(); $xml->endElement(); $xml->endElement(); } $xml->endElement(); $xml->endDocument(); $dbConn->close(); header('Content-type: text/xml'); $strXML = $xml->outputMemory(TRUE); $xml->flush(); date_default_timezone_set('Australia/Sydney'); //error_log("String XML:\n " . $strXML); $projXml = new DOMDocument(); $projXml->loadXML($strXML); error_log("loading xsl document..."); $xsl = new DOMDocument(); $xsl->load('xsl/proj_rub_html.xsl'); // Configure the transformer $proc = new XSLTProcessor(); $proc->importStyleSheet($xsl); // attach the xsl rules $projRubs = $proc->transformToXML($projXml); //error_log("XML Transform result\n" . $projRubs); echo $proc->transformToXML($projXml); }
/** * build Solr index document xml for an application * @gearman = false * @rest = false * @background = false * * @param * [in] array $documentData array of data for the xml document of * application * @param * [in] array $dynaformFieldTypes array of dynaform field types, used * to store the info of APP_DATA with types * @param * [in] array $appTitles array of array of application titles in all * languages * @param * [in] array $proTitles array of array of process titles in all * languages * @param * [in] array $assignedUsers array of array of uids of assigned users * to Application UIDs * @param * [in] array $draftUsers array of array of uids of draft users to * Application UIDs * @param * [in] array $participatedUsers array of array of participated users * UIDs in application * @param * [in] array $unassignedUsers array of unassigned users UIDs * @param * [in] array $unassignedGroups array of unassigned groups UIDs * @param * [out] xml xml document * * $xmlDoc .= buildSearchIndexDocumentPMOS2($documentInformation, * $dynaformFieldTypes, * $lastUpdateDate, $maxPriority, * $assignedUsers, $assignedUsersRead, $assignedUsersUnread, * $draftUser, * $participatedUsers, $participatedUsersStartedByUser, * $participatedUsersCompletedByUser, * $unassignedUsers, $unassignedGroups);* */ public function buildSearchIndexDocumentPMOS2($documentData, $dynaformFieldTypes, $lastUpdateDate, $maxPriority, $delLastIndex, $assignedUsers, $assignedUsersRead, $assignedUsersUnread, $draftUser, $participatedUsers, $participatedUsersStartedByUser, $participatedUsersCompletedByUser, $unassignedUsers, $unassignedGroups, $pausedtUser) { // build xml document $writer = new XMLWriter(); $writer->openMemory(); $writer->setIndent(4); $writer->startElement("doc"); $writer->startElement("field"); $writer->writeAttribute('name', 'APP_UID'); $writer->text($documentData['APP_UID']); $writer->endElement(); $writer->startElement("field"); $writer->writeAttribute('name', 'APP_NUMBER'); $writer->text($documentData['APP_NUMBER']); $writer->endElement(); $writer->startElement("field"); $writer->writeAttribute('name', 'APP_STATUS'); $writer->text($documentData['APP_STATUS']); $writer->endElement(); $writer->startElement("field"); $writer->writeAttribute('name', 'PRO_UID'); $writer->text($documentData['PRO_UID']); $writer->endElement(); if (!empty($documentData['APP_TITLE'])) { $writer->startElement("field"); $writer->writeAttribute('name', 'APP_TITLE'); $writer->text($documentData['APP_TITLE']); $writer->endElement(); } else { $writer->startElement("field"); $writer->writeAttribute('name', 'APP_TITLE'); $writer->text(""); $writer->endElement(); } if (!empty($documentData['PRO_TITLE'])) { $writer->startElement("field"); $writer->writeAttribute('name', 'APP_PRO_TITLE'); $writer->text($documentData['PRO_TITLE']); $writer->endElement(); } else { $writer->startElement("field"); $writer->writeAttribute('name', 'APP_PRO_TITLE'); $writer->text(""); $writer->endElement(); } $writer->startElement("field"); $writer->writeAttribute('name', 'APP_CREATE_DATE'); // convert date to UTC with gmdate $writer->text(gmdate("Y-m-d\\TH:i:s\\Z", strtotime($documentData['APP_CREATE_DATE']))); $writer->endElement(); $writer->startElement("field"); $writer->writeAttribute('name', 'DEL_LAST_UPDATE_DATE'); // convert date to UTC with gmdate $writer->text(gmdate("Y-m-d\\TH:i:s\\Z", strtotime($lastUpdateDate))); $writer->endElement(); $writer->startElement("field"); $writer->writeAttribute('name', 'DEL_MAX_PRIORITY'); $writer->text($maxPriority); $writer->endElement(); if (!empty($documentData["PRO_CATEGORY_UID"])) { $writer->startElement("field"); $writer->writeAttribute("name", "PRO_CATEGORY_UID_s"); $writer->text($documentData["PRO_CATEGORY_UID"]); $writer->endElement(); } foreach ($delLastIndex as $lastIndex) { $writer->startElement("field"); $writer->writeAttribute('name', 'DEL_LAST_INDEX'); $writer->text($lastIndex); $writer->endElement(); } if (is_array($assignedUsers) && !empty($assignedUsers)) { foreach ($assignedUsers as $userUID) { $writer->startElement("field"); $writer->writeAttribute('name', 'APP_ASSIGNED_USERS'); $writer->text($userUID['USR_UID']); $writer->endElement(); // add dynamic field for del_index information $writer->startElement("field"); $writer->writeAttribute('name', 'APP_ASSIGNED_USER_DEL_INDEX_' . trim($userUID['USR_UID']) . '_txt'); $writer->text($userUID['DEL_INDEX']); $writer->endElement(); } } if (is_array($assignedUsersRead) && !empty($assignedUsersRead)) { foreach ($assignedUsersRead as $userUID) { $writer->startElement("field"); $writer->writeAttribute('name', 'APP_ASSIGNED_USERS_READ'); $writer->text($userUID['USR_UID']); $writer->endElement(); // add dynamic field for del_index information $writer->startElement("field"); $writer->writeAttribute('name', 'APP_ASSIGNED_USER_READ_DEL_INDEX_' . trim($userUID['USR_UID']) . '_txt'); $writer->text($userUID['DEL_INDEX']); $writer->endElement(); } } if (is_array($assignedUsersUnread) && !empty($assignedUsersUnread)) { foreach ($assignedUsersUnread as $userUID) { $writer->startElement("field"); $writer->writeAttribute('name', 'APP_ASSIGNED_USERS_UNREAD'); $writer->text($userUID['USR_UID']); $writer->endElement(); // add dynamic field for del_index information $writer->startElement("field"); $writer->writeAttribute('name', 'APP_ASSIGNED_USER_UNREAD_DEL_INDEX_' . trim($userUID['USR_UID']) . '_txt'); $writer->text($userUID['DEL_INDEX']); $writer->endElement(); } } if (!empty($draftUser)) { $writer->startElement("field"); $writer->writeAttribute('name', 'APP_DRAFT_USER'); $writer->text($draftUser['USR_UID']); $writer->endElement(); } if (is_array($participatedUsers) && !empty($participatedUsers)) { foreach ($participatedUsers as $userUID) { $writer->startElement("field"); $writer->writeAttribute('name', 'APP_PARTICIPATED_USERS'); $writer->text($userUID['USR_UID']); $writer->endElement(); // add dynamic field for del_index information $writer->startElement("field"); $writer->writeAttribute('name', 'APP_PARTICIPATED_USER_DEL_INDEX_' . trim($userUID['USR_UID']) . '_txt'); $writer->text($userUID['DEL_INDEX']); $writer->endElement(); } } if (is_array($participatedUsersStartedByUser) && !empty($participatedUsersStartedByUser)) { foreach ($participatedUsersStartedByUser as $userUID) { $writer->startElement("field"); $writer->writeAttribute('name', 'APP_PARTICIPATED_USERS_STARTED'); $writer->text($userUID['USR_UID']); $writer->endElement(); // add dynamic field for del_index information $writer->startElement("field"); $writer->writeAttribute('name', 'APP_PARTICIPATED_USER_STARTED_DEL_INDEX_' . trim($userUID['USR_UID']) . '_txt'); $writer->text($userUID['DEL_INDEX']); $writer->endElement(); } } if (is_array($participatedUsersCompletedByUser) && !empty($participatedUsersCompletedByUser)) { foreach ($participatedUsersCompletedByUser as $userUID) { $writer->startElement("field"); $writer->writeAttribute('name', 'APP_PARTICIPATED_USERS_COMPLETED'); $writer->text($userUID['USR_UID']); $writer->endElement(); // add dynamic field for del_index information $writer->startElement("field"); $writer->writeAttribute('name', 'APP_PARTICIPATED_USER_COMPLETED_DEL_INDEX_' . trim($userUID['USR_UID']) . '_txt'); $writer->text($userUID['DEL_INDEX']); $writer->endElement(); } } if (is_array($unassignedUsers) && !empty($unassignedUsers)) { foreach ($unassignedUsers as $userUID) { $writer->startElement("field"); $writer->writeAttribute('name', 'APP_UNASSIGNED_USERS'); $writer->text($userUID['USR_UID']); $writer->endElement(); // add dynamic field for del_index information $writer->startElement("field"); $writer->writeAttribute('name', 'APP_UNASSIGNED_USER_GROUP_DEL_INDEX_' . trim($userUID['USR_UID']) . '_txt'); $writer->text($userUID['DEL_INDEX']); $writer->endElement(); } } if (is_array($unassignedGroups) && !empty($unassignedGroups)) { foreach ($unassignedGroups as $groupUID) { $writer->startElement("field"); $writer->writeAttribute('name', 'APP_UNASSIGNED_GROUPS'); $writer->text($groupUID['USR_UID']); $writer->endElement(); // add dynamic field for del_index information $writer->startElement("field"); $writer->writeAttribute('name', 'APP_UNASSIGNED_USER_GROUP_DEL_INDEX_' . trim($groupUID['USR_UID']) . '_txt'); $writer->text($groupUID['DEL_INDEX']); $writer->endElement(); } } if (!empty($pausedtUser)) { foreach ($pausedtUser as $paused) { $writer->startElement("field"); $writer->writeAttribute('name', 'APP_PAUSED_USERS'); $writer->text($paused['USR_UID']); $writer->endElement(); $writer->startElement("field"); $writer->writeAttribute('name', 'APP_PAUSED_USER_DEL_INDEX_' . trim($paused['USR_UID']) . '_txt'); $writer->text($paused['DEL_INDEX']); $writer->endElement(); } } // get the serialized fields if (!empty($documentData['APP_DATA']) && $documentData['APP_DATA'] != "N;") { $UnSerializedCaseData = unserialize($documentData['APP_DATA']); if ($UnSerializedCaseData === false) { $UnSerializedCaseData = preg_replace('!s:(\\d+):"(.*?)";!e', "'s:'.strlen('\$2').':\"\$2\";'", $documentData['APP_DATA']); // utf8_encode $UnSerializedCaseData = unserialize($UnSerializedCaseData); } if (!$UnSerializedCaseData) { // error unserializing throw new ApplicationAPP_DATAUnserializeException(date('Y-m-d H:i:s:u') . " Could not unserialize APP_DATA of APP_UID: " . $documentData['APP_UID'] . "\n"); } else { foreach ($UnSerializedCaseData as $k => $value) { if (!is_array($value) && !is_object($value) && $value != '' && $k != 'SYS_LANG' && $k != 'SYS_SKIN' && $k != 'SYS_SYS') { // search the field type in array of dynaform fields if (!empty($dynaformFieldTypes) && array_key_exists(trim($k), $dynaformFieldTypes)) { $type = $dynaformFieldTypes[trim($k)]; $typeSufix = '_t'; switch ($type) { case 'text': $typeSufix = '_t'; break; case 'Int': if (intval($value) > 2147483647) { $typeSufix = '_tl'; //for long values $value = intval($value); } else { $typeSufix = '_ti'; $value = str_replace(',', '', $value); $value = intval($value); } break; case 'Real': $typeSufix = '_td'; $value = str_replace(',', '', $value); $value = floatval($value); break; case 'date': $newdate = false; $withHour = true; // try to convert string to date // TODO convert to php 5.2 format /* * $newdate = date_create_from_format ( 'Y-m-d H:i:s', $value * ); if (! $newdate) { $newdate = date_create_from_format ( * 'Y-m-d', $value ); $withHour = false; } if (! $newdate) { * $newdate = date_create_from_format ( 'd/m/Y', $value ); * $withHour = false; } if (! $newdate) { $newdate = * date_create_from_format ( 'j/m/Y', $value ); $withHour = * false; } */ $newdate = strtotime($value); if (!$newdate) { $typeSufix = '*'; // not store field } else { $typeSufix = '_tdt'; /* * if ($withHour) //$value = gmdate ( "Y-m-d\TH:i:s\Z", * $newdate->getTimestamp () ); $value = gmdate ( * "Y-m-d\TH:i:s\Z", $newdate ); else { $value = gmdate ( * "Y-m-d\T00:00:00\Z", $newdate ); } */ $value = gmdate("Y-m-d\\T00:00:00\\Z", $newdate); } break; case 'dropdown': $typeSufix = '_t'; break; case 'textarea': $typeSufix = '_t'; break; case 'currency': $typeSufix = '_td'; $value = floatval($value); break; case 'percentage': $typeSufix = '_t'; break; case 'password': $typeSufix = '_t'; break; case 'suggest': $typeSufix = '_t'; break; case 'yesno': $typeSufix = '_t'; break; case 'listbox': $typeSufix = '_t'; break; case 'checkbox': $typeSufix = '_t'; break; case 'checkgroup': $typeSufix = '_t'; break; case 'radiogroup': $typeSufix = '_t'; break; case 'hidden': $typeSufix = '_t'; break; } if ($typeSufix != '*') { $value = trim($value); $pairs = array("" => "", "" => "", "" => "", "" => "", "" => "", "" => "", "" => "", "" => "", "-" => "", "\t" => "", "" => "", "" => "", "-" => "", "" => "", "" => ""); $value = strtr($value, $pairs); $writer->startElement("field"); $writer->writeAttribute('name', trim($k) . $typeSufix); $writer->startCData(); $writer->text($value); $writer->endCData(); $writer->endElement(); } } else { $value = trim($value); $pairs = array("" => "", "" => "", "" => "", "" => "", "" => "", "" => "", "" => "", "" => "", "-" => "", "\t" => "", "" => "", "" => "", "-" => "", "" => "", "" => ""); $value = strtr($value, $pairs); $writer->startElement("field"); $writer->writeAttribute('name', trim($k) . '_t'); $writer->startCData(); $writer->text($value); $writer->endCData(); $writer->endElement(); } } } // foreach unserialized data } // else unserialize APP_DATA } // empty APP_DATA $writer->endElement(); // end /doc return $writer->outputMemory(true); }
function GetTaskDetails($taskId) { //Return metadata about the columns in each table for a given database (table_schema) $qry = "SELECT r_level, r_text, tb_tasks.task_text FROM tb_rubrics " . "INNER JOIN tb_tasks on tb_rubrics.task_id = tb_tasks.id " . "WHERE task_id = " . $taskId . " ORDER by r_level;"; date_default_timezone_set('Australia/Sydney'); error_log("In get_task_details.php...\n" . $qry); $dbConn = opendatabase(); $result = mysqli_query($dbConn, $qry); date_default_timezone_set('Australia/Sydney'); error_log("Records in Projects: " . mysqli_num_rows($result)); $row_cnt = mysqli_num_rows($result); $field_cnt = $result->field_count; error_log("Fields: " . $field_cnt); if (!$result || mysqli_num_rows($result) <= 0) { //echo("Could not obtain metadata information."); return false; } /*****************************************************************/ $xml = new XMLWriter(); $xml->openMemory(); $xml->startDocument(); $xml->setIndent(true); $xml->startElement("task_rubrics"); /* fetch associative array */ while ($row = mysqli_fetch_assoc($result)) { $xml->startElement("task"); $xml->writeAttribute('id', $taskId); $xml->writeRaw($row['task_text']); $xml->startElement("rubric_details"); $xml->writeAttribute('r_level', $row['r_level']); $xml->startCData("details"); $xml->writeRaw($row['r_text']); $xml->endCData(); $xml->endElement(); $xml->endElement(); } $xml->endElement(); $xml->endDocument(); $dbConn->close(); header('Content-type: text/xml'); $strXML = $xml->outputMemory(TRUE); $xml->flush(); date_default_timezone_set('Australia/Sydney'); error_log("String XML:\n " . $strXML); //$projXml->loadXML($strXML); //echo $strXML; $projXml = new DOMDocument(); $projXml->loadXML($strXML); //error_log($projXml->saveXML()); error_log("loading xsl document..."); $xsl = new DOMDocument(); $xsl->load('xsl/task_rub_html.xsl'); //error_log($xsl->saveXML()); // Configure the transformer $proc = new XSLTProcessor(); $proc->importStyleSheet($xsl); // attach the xsl rules $projRubs = $proc->transformToXML($projXml); error_log("XML Transform result\n" . $projRubs); echo $proc->transformToXML($projXml); }