public static function toXml($data, $rootNodeName = 'data', $xml = null) { // turn off compatibility mode as simple xml throws a wobbly if you don't. if (ini_get('zend.ze1_compatibility_mode') == 1) { ini_set('zend.ze1_compatibility_mode', 0); } if ($xml == null) { $xml = simplexml_load_string("<?xml version='1.0' encoding='utf-8'?><{$rootNodeName} />"); } // loop through the data passed in. foreach ($data as $key => $value) { // no numeric keys in our xml please! if (is_numeric($key)) { // make string key... $key = "child_" . (string) $key; } // replace anything not alpha numeric $key = preg_replace('/[^a-z]/i', '', $key); // if there is another array found recrusively call this function if (is_array($value)) { $node = $xml->addChild($key); // recrusive call. ArrayToXML::toXml($value, $rootNodeName, $node); } else { // add single node. $value = htmlentities($value); $xml->addChild($key, $value); } } // pass back as string. or simple xml object if you want! return $xml->asXML(); }
/** * The main function for converting to an XML document. * Pass in a multi dimensional array and this recrusively loops through and builds up an XML document. * * @param array $data * @param string $rootNodeName - what you want the root node to be - defaultsto data. * @param SimpleXMLElement $xml - should only be used recursively * @return string XML */ public static function toXML($data, $rootNodeName = 'ResultSet', &$xml = null) { // turn off compatibility mode as simple xml throws a wobbly if you don't. if (ini_get('zend.ze1_compatibility_mode') == 1) { ini_set('zend.ze1_compatibility_mode', 0); } if (is_null($xml)) { $xml = simplexml_load_string("<?xml version='1.0' encoding='utf-8'?><{$rootNodeName} />"); } //if ( is_null( $xml ) ) $xml = simplexml_load_string( "" ); // loop through the data passed in. foreach ($data as $key => $value) { // no numeric keys in our xml please! if (is_numeric($key)) { $numeric = 1; $key = $rootNodeName; } // delete any char not allowed in XML element names $key = preg_replace('/[^a-z0-9\\-\\_\\.\\:]/i', '', $key); // if there is another array found recrusively call this function if (is_array($value)) { $node = ArrayToXML::isAssoc($value) || $numeric ? $xml->addChild($key) : $xml; // recrusive call. if ($numeric) { $key = 'anon'; } ArrayToXML::toXml($value, $key, $node); } else { // add single node. $value = htmlentities($value); $xml->addChild($key, $value); } } // pass back as XML //return $xml->asXML(); // if you want the XML to be formatted, use the below instead to return the XML $doc = new DOMDocument('1.0'); $doc->preserveWhiteSpace = false; $doc->loadXML($xml->asXML()); $doc->formatOutput = true; return $doc->saveXML(); }
/** * The main function for converting to an XML document. * Pass in a multi dimensional array and this recrusively loops through and builds up an XML document. * * @static * @param array $data * @param string $rootNodeName - what you want the root node to be - defaultsto data. * @param SimpleXMLElement $xml - should only be used recursively * @return string XML */ public static function toXml($data, $rootNodeName = 'data', &$xml = NULL) { if (is_null($xml)) { $xml = new SimpleXMLElement('<' . $rootNodeName . '/>'); } // loop through the data passed in. foreach ($data as $key => $value) { // if numeric key, assume array of rootNodeName elements if (is_numeric($key)) { $key = $rootNodeName; } // Check if is attribute if ($key == ArrayToXML::attr_arr_string) { // Add attributes to node foreach ($value as $attr_name => $attr_value) { $xml->addAttribute($attr_name, $attr_value); } } else { // delete any char not allowed in XML element names $key = preg_replace('/[^a-z0-9\\-\\_\\.\\:]/i', '', $key); // if there is another array found recrusively call this function if (is_array($value)) { // create a new node unless this is an array of elements $node = ArrayToXML::isAssoc($value) ? $xml->addChild($key) : $xml; // recrusive call - pass $key as the new rootNodeName ArrayToXML::toXml($value, $key, $node); } else { // add single node. // $value = htmlentities($value, ENT_COMPAT | ENT_XHTML, ADA_CHARSET); $new_child = $xml->addChild($key); if ($new_child !== NULL) { $node = dom_import_simplexml($new_child); $no = $node->ownerDocument; $node->appendChild($no->createCDATASection($value)); } } } } // pass back as string. or simple xml object if you want! return $xml->asXML(); }
$pulse = $_POST['pulse']; $respiration = $_POST['respiration']; $note = $_POST['note']; $BMI = $_POST['BMI']; $BMI_status = $_POST['BMI_status']; $waist_circ = $_POST['waist_circ']; $head_circ = $_POST['head_circ']; $oxygen_saturation = $_POST['oxygen_saturation']; if ($userId = validateToken($token)) { $user = getUsername($userId); $acl_allow = acl_check('encounters', 'auth_a', $user); if ($acl_allow) { $strQuery = "UPDATE `form_vitals` SET \n `date`='" . add_escape_custom($date) . "',\n `pid`='" . add_escape_custom($patientId) . "',\n `user`='" . add_escape_custom($user) . "',\n `groupname`='" . add_escape_custom($groupname) . "',\n `authorized`='" . add_escape_custom($authorized) . "',\n `activity`='" . add_escape_custom($activity) . "',\n `bps`='" . add_escape_custom($bps) . "',\n `bpd`='" . add_escape_custom($bpd) . "',\n `weight`='" . add_escape_custom($weight) . "',\n `height`='" . add_escape_custom($height) . "',\n `temperature`='" . add_escape_custom($temperature) . "',\n `temp_method`='" . add_escape_custom($temp_method) . "',\n `pulse`='" . add_escape_custom($pulse) . "',\n `respiration`='" . add_escape_custom($respiration) . "',\n `note`='" . add_escape_custom($note) . "',\n `BMI`='" . add_escape_custom($BMI) . "',\n `BMI_status`='" . add_escape_custom($BMI_status) . "',\n `waist_circ`='" . add_escape_custom($waist_circ) . "',\n `head_circ`='" . add_escape_custom($head_circ) . "',\n `oxygen_saturation`='" . add_escape_custom($oxygen_saturation) . "' \n WHERE id = ?"; $result = sqlStatement($strQuery, array($vital_id)); if ($result !== FALSE) { $xml_array['status'] = 0; $xml_array['reason'] = 'Visit vital update successfully'; } else { $xml_array['status'] = -1; $xml_array['reason'] = 'Could not update isit vital'; } } else { $xml_string .= "<status>-2</status>\n"; $xml_string .= "<reason>You are not Authorized to perform this action</reason>\n"; } } else { $xml_array['status'] = -2; $xml_array['reason'] = 'Invalid Token'; } $xml = ArrayToXML::toXml($xml_array, 'visitvitals'); echo $xml;
$active = $_POST['active']; if ($userId = validateToken($token)) { $username = getUsername($userId); $acl_allow = acl_check('patients', 'notes', $username); if ($acl_allow) { $noteIds_array = explode(',', $noteIds); foreach ($noteIds_array as $noteId) { switch ($active) { case 1: reappearPnote($noteId); break; case 0: disappearPnote($noteId); break; } } $xml_array['status'] = 0; $xml_array['reason'] = 'The Patient notes has been updated'; } else { $xml_string .= "<status>-2</status>\n"; $xml_string .= "<reason>You are not Authorized to perform this action</reason>\n"; } } else { $xml_array['status'] = -2; $xml_array['reason'] = 'Invalid Token'; } $xml = ArrayToXML::toXml($xml_array, 'PatientNotes'); echo $xml; ?>
$rowvalue = xmlsafestring($fieldvalue8); $xml_array['Patient']['vitalslist']['vitals-' . $counter8][$fieldname] = $rowvalue; } // foreach $counter8++; } } else { $xml_array['Patient']['vitalslist']['status'] = 1; $xml_array['Patient']['vitalslist']['reason'] = 'No Patient Vital Data found'; } $strQuery1 = "SELECT d.date,d.size,d.url,d.docdate,d.mimetype,c2d.category_id\n FROM `documents` AS d\n INNER JOIN `categories_to_documents` AS c2d ON d.id = c2d.document_id\n WHERE foreign_id = ?\n AND category_id = 13\n ORDER BY category_id, d.date DESC \n LIMIT 1"; $result1 = sqlQuery($strQuery1, array($p_id)); if ($result1) { $xml_array['Patient']['demographics']['profile_image'] = getUrl($result1['url']); } else { $xml_array['Patient']['demographics']['profile_image'] = ''; } } else { $xml_array['Patient']['patientdata']['status'] = 1; $xml_array['Patient']['patientdata']['reason'] = 'Error processing patient records'; } } else { $xml_array['status'] = -2; $xml_array['reason'] = 'You are not Authorized to perform this action'; } } else { $xml_array['status'] = -2; $xml_array['reason'] = 'Invalid Token'; } echo ArrayToXML::toXml($xml_array, 'PatientList');
$video_name = date('Y-m-d_H-i-s') . "." . $ext; file_put_contents($path . "/videos/" . $video_name, base64_decode($data)); $notes = $sitesUrl . "{$site}/documents/userdata/videos/" . $video_name; break; } $select_query = "SELECT * FROM `list_options` \n WHERE `list_id` LIKE 'lists' AND `option_id` LIKE '" . add_escape_custom($list_id) . "' AND `title` LIKE '" . add_escape_custom($list_id) . "'"; $result_select = sqlQuery($select_query); $result1 = true; if (!$result_select) { $insert_list = "INSERT INTO list_options ( list_id, option_id, title, seq, is_default, option_value ) \n VALUES ( 'lists','" . add_escape_custom($list_id) . "','" . add_escape_custom($list_id) . "', '0','1', '0')"; $result1 = sqlStatement($insert_list); } $strQuery = "INSERT INTO `list_options`(`list_id`, `option_id`, `title`, `seq`, `is_default`, `option_value`, `mapping`, `notes`) \n VALUES (\n '" . add_escape_custom($list_id) . "',\n '" . add_escape_custom($option_id) . "',\n '" . add_escape_custom($title) . "',\n '" . add_escape_custom($seq) . "',\n '" . add_escape_custom($is_default) . "',\n '" . add_escape_custom($userId) . "',\n '" . add_escape_custom($mapping) . "',\n '" . add_escape_custom($notes) . "')"; $result = sqlStatement($strQuery); if ($result) { $xml_array['status'] = "0"; $xml_array['reason'] = "The Resource has been added"; } else { $xml_array['status'] = "-1"; $xml_array['reason'] = "ERROR: Sorry, there was an error processing your data. Please re-submit the information again."; } } else { $xml_array['status'] = -2; $xml_array['reason'] = 'You are not Authorized to perform this action'; } } else { $xml_array['status'] = "-2"; $xml_array['reason'] = 'Invalid Token'; } $xml = ArrayToXML::toXml($xml_array, 'Resource'); echo $xml;
function Send($data) { global $pgmstart, $wgXMLRoot; if (!is_array($data)) { $data = array("result" => $data); } if (!isset($data["err"])) { $data["err"]["id"] = 0; $data["err"]["msg"] = ""; } $data["runtime"] = microtime(true) - $pgmstart; if (isset($_ENV["APIExpires"])) { header("Pragma: public"); header("Cache-Control: maxage=" . ($_ENV["APIExpires"] + 0)); header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $_ENV["APIExpires"]) . ' GMT'); } switch (strtolower(isset($_REQUEST["format"]) ? $_REQUEST["format"] : "")) { case "successcode": header("Content-Type: text/plain"); if ($data["err"]["id"] + 0 == 0) { @header($_SERVER["SERVER_PROTOCOL"] . " 200 Ok"); } else { header($_SERVER["SERVER_PROTOCOL"] . " 400 " . $data["err"]["msg"]); } echo $data["err"]["id"] + 0; break; case "json": header("Content-Type: application/json"); $data["Request"] = $_REQUEST; echo json_encode($data); break; case "jsonac": header("Content-Type: application/json"); echo json_encode($data["result"]); break; case "json-in-script": header("Content-Type: text/javascript"); $data["Request"] = $_REQUEST; if ($_REQUEST["callback"] . "" == "") { $_REQUEST["callback"] = str_replace(array("/"), "_", $_REQUEST["action"]); } echo strip_tags($_REQUEST["callback"]) . "(" . json_encode($data) . ");"; break; case "php": $data["Request"] = $_REQUEST; echo serialize($data); break; case "html": $data["Request"] = $_REQUEST; echo '<table><tr><td>' . Array2HTML($data) . '</td></tr></table>'; break; case "plain": header("Content-Type: text/plain; charset=utf-8"); if ($data["err"]["id"] + 0 == 0) { @header($_SERVER["SERVER_PROTOCOL"] . " 200 Ok"); } else { header($_SERVER["SERVER_PROTOCOL"] . " 400 " . $data["err"]["msg"]); } if ($data["err"]["id"] != 0) { die("ERR:" . $data["err"]["id"] . ";" . $data["err"]["msg"]); } if (is_array($data["result"])) { foreach ($data["result"] as $a) { echo (string) $a . "\r\n"; } break; } echo (string) $data["result"]; break; case "xml": default: header("Content-Type: text/xml"); $data["Request"] = $_REQUEST; echo ArrayToXML::toXml($data, $wgXMLRoot); // echo(Array2XML($data, true)); break; } exit(1); }
if ($acl_allow) { $strQuery = "UPDATE openemr_postcalendar_events SET \n pc_title = '" . add_escape_custom($pc_title) . "', \n pc_hometext = '" . add_escape_custom($pc_hometext) . "' , \n pc_catid = '" . add_escape_custom($pc_catid) . "' , \n pc_eventDate = '" . add_escape_custom($appointmentDate) . "', \n pc_startTime = '" . add_escape_custom($appointmentTime) . "', \n pc_endTime = '" . add_escape_custom($endTime) . "', \n pc_aid = '" . add_escape_custom($admin_id) . "', \n pc_facility = '" . add_escape_custom($facility) . "',\n pc_billing_location = '" . add_escape_custom($pc_billing_location) . "',\n pc_duration = '" . add_escape_custom($pc_duration) . "',\n pc_pid = '" . add_escape_custom($patientId) . "',\n pc_apptstatus = '" . add_escape_custom($app_status) . "' \n WHERE pc_eid=?"; $result = sqlStatement($strQuery, array($appointmentId)); $device_token_badge = getDeviceTokenBadge($provider_username, 'appointment'); $badge = $device_token_badge['badge']; $deviceToken = $device_token_badge['device_token']; if ($deviceToken) { $notification_res = notification($deviceToken, $badge, $msg_count = 0, $apt_count = 0, $message = 'Appointment Updated!'); } if ($result !== FALSE) { $xml_array['status'] = 0; $xml_array['reason'] = 'The Appointment has been updated.'; if ($notification_res) { $xml_array['notification'] = 'Update Appointment Notification(' . $notification_res . ')'; } else { $xml_array['notification'] = 'Notificaiotn Failed.'; } } else { $xml_array['status'] = -1; $xml_array['reason'] = 'ERROR: Sorry, there was an error processing your request. Please re-submit the information again.'; } } else { $xml_array['status'] = -2; $xml_array['reason'] = 'You are not Authorized to perform this action'; } } else { $xml_array['status'] = -2; $xml_array['reason'] = 'Invalid Token'; } $xml = ArrayToXML::toXml($xml_array, 'Appointment'); echo $xml;
} /** * User Messages */ $sql = "SELECT pnotes.id, pnotes.user, pnotes.pid, pnotes.title, pnotes.date,pnotes.body, pnotes.message_status, \n IF(pnotes.user != pnotes.pid,users.fname,patient_data.fname) as users_fname,\n IF(pnotes.user != pnotes.pid,users.lname,patient_data.lname) as users_lname,\n patient_data.fname as patient_data_fname, patient_data.lname as patient_data_lname\n FROM ((pnotes LEFT JOIN users ON pnotes.user = users.username) \n JOIN patient_data ON pnotes.pid = patient_data.pid) WHERE pnotes.message_status LIKE 'New' \n AND pnotes.deleted != '1' AND pnotes.date >= '{$date} 00:00:00' AND pnotes.date <= '{$date} 24:00:00' AND pnotes.assigned_to LIKE ?"; $messageResult = sqlStatement($sql, array($username)); if ($messageResult->_numOfRows > 0) { $xml_array["Messages"]['status'] = 0; $xml_array["Messages"]['reason'] = 'Messages Processed successfully'; $count = 1; while ($myrow = sqlFetchArray($messageResult)) { foreach ($myrow as $fieldName => $fieldValue) { $rowValue = xmlsafestring($fieldValue); $xml_array["Messages"]['Message-' . $count][$fieldName] = $rowValue; } $count++; } } else { $xml_array["Messages"]['status'] = -1; $xml_array["Messages"]['reason'] = 'Messages not found.'; } } $ip = $_SERVER['REMOTE_ADDR']; newEvent($event = 'login', $username, $groupname = 'Default', $success = '1', 'success: ' . $ip); } else { newEvent($event = 'login', $username, $groupname = 'Default', $success = '1', 'failure: ' . $ip . ". user password mismatch (" . sha1($password) . ")"); $xml_array['status'] = -1; $xml_array['reason'] = 'Username/Password incorrect.'; } $xml = ArrayToXML::toXml($xml_array, 'MedMasterUser'); echo $xml;
$lab_report_catid = document_category_to_id("Lab Report"); if ($cat_id == $lab_report_catid) { $device_token_badge = getDeviceTokenBadge($provider_username, 'labreport'); $badge = $device_token_badge['badge']; $deviceToken = $device_token_badge['device_token']; if ($deviceToken) { $notification_res = notification($deviceToken, $badge, $msg_count = 0, $apt_count = 0, $message = 'New Labreport Notification!'); } } if ($res) { $xml_array['status'] = "0"; $xml_array['reason'] = "Document added successfully"; if ($notification_res) { $xml_array['notification'] = 'Add Patient document Notification(' . $notification_res . ')'; } else { $xml_array['notification'] = 'Notificaiotn Failed.'; } } else { $xml_array['status'] = "-1"; $xml_array['reason'] = "ERROR: Sorry, there was an error processing your data. Please re-submit the information again."; } } else { $xml_array['status'] = -2; $xml_array['reason'] = 'You are not Authorized to perform this action'; } } else { $xml_array['status'] = "-2"; $xml_array['reason'] = 'Invalid Token'; } $xml = ArrayToXML::toXml($xml_array, 'PatientImage'); echo $xml;
//Si se especifica otro formato, por el momento simplemente imprimo el array como está... default: print_r($retCommentersFinal); } } else { switch ($format) { //Convierto el array de posts en JSON case "json": log_action("RESPONSE: " . '{"post":' . indent(json_encode($posts)) . "}"); echo '{"post":' . indent(json_encode($posts)) . "}"; break; //Convierto el array de posts en XML, utilizando la librería //Convierto el array de posts en XML, utilizando la librería case "xml": $xml = new ArrayToXML(); $xmlElement = new SimpleXMLElement($xml->toXml($posts, "posts")); $xmlElement->addAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); $xmlElement->addAttribute("xsi:noNamespaceSchemaLocation", "http://200.69.225.53:30082/XZone.xsd"); echo $xmlElement->asXML(); //echo $xml->toXml($posts, "posts"); break; //Si se especifica otro formato, por el momento simplemente imprimo el array como está... //Si se especifica otro formato, por el momento simplemente imprimo el array como está... default: print_r($posts); } } /* * ****************** Procesamiento de feeds **************** */ function processFeed($feed, $zone = null, $tags = null, $lat = null, $lon = null, $extendedString = null) { global $format, $facebook, $getComments;
if ($format == 'info') { $plugin = $mainframe->triggerEvent('onRestInfo', array($req)); } else { $plugin = $mainframe->triggerEvent('onRestCall', array($req)); } } else { $plugin[0] = 'Cannot login - Please provide correct auth_user and auth_password'; } // Generate response switch ($format) { case 'json': default: $document->setMimeEncoding('application/json'); $op = json_encode($plugin[0]); // $op = custom_json::encode($plugin[0]); break; case 'xml': $document->setMimeEncoding('application/xml'); $op = ArrayToXML::toXml($plugin[0]); break; case 'html': break; case 'info': $op = JoomlaRest::getInfo($plugin[0]); break; } // Logout $mainframe->logout(); // Deliver response to client echo $op; jexit();
switch ($action) { case 'add': $_POST['question'] = array_key_exists('question', $_POST) ? $_POST['question'] : ''; $_POST['correct'] = array_key_exists('correct', $_POST) ? $_POST['correct'] : null; $_POST['answer-explanation'] = array_key_exists('answer-explanation', $_POST) ? $_POST['answer-explanation'] : ''; $alternatives = array(); for ($i = 0; $i < 4; $i++) { $alternatives[] = $_POST['alt-' . $i]; } $response = Question::add($_POST['question'], $alternatives, $_POST['correct'], $_POST['answer-explanation'], $_POST['gid']); break; case 'get': $response = Question::get($params[0], $params[1]); break; case 'my': $params[0] = count($params) >= 1 ? $params[0] : null; $response = Question::getMine($params[0]); break; case 'answer': $_POST['qid'] = array_key_exists('qid', $_POST) ? $_POST['qid'] : ''; $_POST['aid'] = array_key_exists('aid', $_POST) ? $_POST['aid'] : ''; $response = Question::answer($_POST['qid'], $_POST['aid']); break; } break; // end $model } header(200); header('Content-type: application/xml'); print is_array($response) ? ArrayToXML::toXml($response, 'data') : '<data>' . $response . '</data>'; exit;
/** * The main function for converting to an XML document. * Pass in a multi dimensional array and this recrusively loops through and builds up an XML document. * * @param array $data * @param string $rootNodeName - what you want the root node to be - defaultsto data. * @param SimpleXMLElement $xml - should only be used recursively * @return string XML */ public static function toXml($data, $rootNodeName = 'data', &$xml = null) { // turn off compatibility mode as simple xml throws a wobbly if you don't. if (ini_get('zend.ze1_compatibility_mode') == 1) { ini_set('zend.ze1_compatibility_mode', 0); } if (is_null($xml)) { $xml = simplexml_load_string("<?xml version='1.0' encoding='utf-8'?><{$rootNodeName} />"); } // loop through the data passed in. foreach ($data as $key => $value) { // if numeric key, assume array of rootNodeName elements if (is_numeric($key)) { $key = $rootNodeName; } // delete any char not allowed in XML element names $key = preg_replace('/[^a-z0-9\\-\\_\\.\\:]/i', '', $key); // if there is another array found recrusively call this function if (is_array($value)) { // create a new node unless this is an array of elements $node = ArrayToXML::isAssoc($value) ? $xml->addChild($key) : $xml; // recrusive call - pass $key as the new rootNodeName ArrayToXML::toXml($value, $key, $node); } else { // add single node. $value = htmlentities($value); $xml->addChild($key, $value); } } // pass back as string. or simple xml object if you want! return $xml->asXML(); }