diff --git a/api/surveycto/ethprism.php b/api/surveycto/ethprism.php new file mode 100644 index 00000000..49190cd3 --- /dev/null +++ b/api/surveycto/ethprism.php @@ -0,0 +1,97 @@ +query($alterQuery) !== TRUE) { + echo "Error altering table: " . $conn->error . "
"; + } + } +} + +function JSON_to_table($json_var, $tblName = 'ethprism01') { + $j_obj = json_decode($json_var, true); + + if (!$j_obj || !is_array($j_obj) || count($j_obj) === 0) { + die("Invalid JSON input or empty array"); + } + + // Establish a new connection using mysqli + $conn = new mysqli('localhost', 'surveyctoethprism', 'surveyctoethprism', 'surveyctoethprism'); + + // Check connection + if ($conn->connect_error) { + die("Connection failed: " . $conn->connect_error); + } + + // Extract column names from the first row of the JSON data + $firstRow = $j_obj[0]; + $columns = array_keys($firstRow); + $columnDefinitions = implode(", ", array_map(function($col) { + return "`$col` TEXT"; + }, $columns)); + + // Create table query if it doesn't exist + $createTableQuery = "CREATE TABLE IF NOT EXISTS `$tblName` ($columnDefinitions)"; + + if ($conn->query($createTableQuery) !== TRUE) { + die("Error creating table: " . $conn->error); + } + + // Iterate over the JSON data to insert rows and handle new columns + foreach ($j_obj as $row) { + $keys = array_keys($row); + + // Check for new columns and alter the table if needed + alterTable($conn, $tblName, $keys); + + $columns = implode(", ", array_map(function($key) { + return "`$key`"; + }, $keys)); + $escaped_values = array_map(array($conn, 'real_escape_string'), array_values($row)); + $values = "'" . implode("', '", $escaped_values) . "'"; + + // Use prepared statements for better security + $placeholders = implode(", ", array_fill(0, count($keys), '?')); + $stmt = $conn->prepare("INSERT INTO `$tblName` ($columns) VALUES ($placeholders)"); + + if ($stmt === false) { + echo "Error preparing statement: " . $conn->error; + continue; + } + + $stmt->bind_param(str_repeat('s', count($escaped_values)), ...$escaped_values); + + if (!$stmt->execute()) { + echo "Error executing statement: " . $stmt->error; + } + + $stmt->close(); + } + + $conn->close(); +} + +// Example usage +$url = 'https://ethiopiaprism.surveycto.com/api/v2/forms/data/wide/json/dup_t_module_v_facilityoffice_checklist?date=2024&r=approved|rejected'; +$username = 'fasil.w@merqconsultancy.org'; +$password = 'merq123'; + +$json_data = fetchJSONData($url, $username, $password); +JSON_to_table($json_data); + +?> diff --git a/api/surveycto/ethprismcsv.php b/api/surveycto/ethprismcsv.php new file mode 100644 index 00000000..c8516e31 --- /dev/null +++ b/api/surveycto/ethprismcsv.php @@ -0,0 +1,87 @@ +query($createTableQuery) !== TRUE) { + die("Error creating table: " . $conn->error); + } +} + +function CSV_to_table($csv_data, $tblName = 'ethprismcsv') { + $lines = explode("\n", $csv_data); + $header = str_getcsv(array_shift($lines)); + + if (empty($header)) { + die("Invalid CSV input"); + } + + // Ensure column names are unique + $header = array_unique($header); + + // Establish a new connection using mysqli + $conn = new mysqli('localhost', 'surveyctoethprism', 'surveyctoethprism', 'surveyctoethprism'); + + // Check connection + if ($conn->connect_error) { + die("Connection failed: " . $conn->connect_error); + } + + // Create table with all columns as TEXT + createTable($conn, $tblName, $header); + + // Iterate over the CSV data to insert rows + foreach ($lines as $line) { + if (empty(trim($line))) { + continue; // Skip empty lines + } + + $row = str_getcsv($line); + $escaped_values = array_map(array($conn, 'real_escape_string'), $row); + + $columns = implode(", ", array_map(function($col) { + return "`$col`"; + }, $header)); + $values = "'" . implode("', '", $escaped_values) . "'"; + + $sql = "INSERT INTO `$tblName` ($columns) VALUES ($values)"; + + if ($conn->query($sql) !== TRUE) { + echo "Error: " . $sql . "
" . $conn->error; + } + } + + $conn->close(); +} + + +// $url = 'https://ethiopiaprism.surveycto.com/api/v1/forms/data/wide/csv/dup_t_module_v_facilityoffice_checklist'; +// $url = 'https://ethiopiaprism.surveycto.com/api/v1/forms/data/csv/dup_t_module_v_facilityoffice_checklist?date=2024&r=approved|rejected'; +//$url = 'https://ethiopiaprism.surveycto.com/api/v1/forms/data/csv/dup_t_module_v_facilityoffice_checklist'; +$url = 'https://ethiopiaprism.surveycto.com/api/v1/forms/data/csv/dup_t_module_v_facilityoffice_checklist'; +$username = 'fasil.w@merqconsultancy.org'; +$password = 'merq123'; + + +$csv_data = fetchCSVData($url, $username, $password); +CSV_to_table($csv_data); + +?> + diff --git a/api/surveycto/test.php b/api/surveycto/test.php new file mode 100644 index 00000000..44f0f1c2 --- /dev/null +++ b/api/surveycto/test.php @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/app/connections/apis.php b/app/connections/apis.php index b4c97908..8930ab0e 100644 --- a/app/connections/apis.php +++ b/app/connections/apis.php @@ -110,6 +110,18 @@ protected function _setConnectionsData() $data["password"] = "district"; $connectionsData["devdhis2hispmdathispmdmerqcons"] = $data; + $data = array(); + $data["connId"] = "surveyctohispmdathispmdmerqcon"; + $data["connName"] = "SURVEYCTO_ETHIOPIA_PRISM_API"; + + $this->_connectionsIdByName["SURVEYCTO_ETHIOPIA_PRISM_API"] = "surveyctohispmdathispmdmerqcon"; + + $data["url"] = "https://ethiopiaprism.surveycto.com"; + $data["authType"] = "basic"; + $data["username"] = "fasil.merqconsultancy.org"; + $data["password"] = "merq123"; + + $connectionsData["surveyctohispmdathispmdmerqcon"] = $data; $this->_connectionsData = &$connectionsData; } diff --git a/app/include/appsettings.php b/app/include/appsettings.php index ca24547c..bd4069b2 100644 --- a/app/include/appsettings.php +++ b/app/include/appsettings.php @@ -737,9 +737,9 @@ $strLastSQL = ""; $showCustomMarkerOnPrint = false; -$projectBuildKey = "468_1723305847"; +$projectBuildKey = "469_1723305847"; $wizardBuildKey = "39558"; -$projectBuildNumber = "468"; +$projectBuildNumber = "469"; $mlang_messages = array(); $mlang_charsets = array(); diff --git a/app/include/pages/.global_menu.php b/app/include/pages/.global_menu.php index 430bd13e..95acc896 100644 --- a/app/include/pages/.global_menu.php +++ b/app/include/pages/.global_menu.php @@ -1382,7 +1382,7 @@

Welcome to HISPMD

-

Health Information Management Information Systems Dashboard

+

Health Information Systems Performance Monitoring Dashboard

diff --git a/app/pdf/.global_menu.json b/app/pdf/.global_menu.json index 5b39b17e..348f6ae8 100644 --- a/app/pdf/.global_menu.json +++ b/app/pdf/.global_menu.json @@ -57,7 +57,7 @@ pdfDocument = { "text": [ - {"text":"\n\n\n\n\t\n\t\n\t\n\t\n\n\t\n\t\n\n\t\n\t\n\t\n\t\n\n\t\n\t\n\n\t\n\n\n\n\t\n\t
\n\t\t
\n\n\n\t\t\t\n\n\t\t
\n\t
\n
\n\n \n
\n \"\"\n\n
\n
\n
\n \n
\n\n\"\"\n
\n \n \n \n \n
\n\n
\n

Welcome to HISPMD

\n

Health Information Management Information Systems Dashboard

\n \n
\n \n \n \n
\n
\n\n
\n
\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n\n \n \n \n \n\n
\n\n\n\n\n\n
\n\n\n\n\n\t\t\t\t\t\t\n\n\t\t\t\t\t\t
\n\n\n\t\t\t\t\t\n\t\t\t\t\t\n\n\n\t\t\t\t\t
\n\t\t\t\t\n\t\t\t\t\t\n\n\n\n\n\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\n\t\t\t\t\n\t\n\t\n\n\t\n\t\n\n\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\n\t\n\t\n\n\n\t
\n\t
\n\t
\n\t
\n\n\n\n\n","hidden":"{$item_hide_text8}","isHtml":true}, + {"text":"\n\n\n\n\t\n\t\n\t\n\t\n\n\t\n\t\n\n\t\n\t\n\t\n\t\n\n\t\n\t\n\n\t\n\n\n\n\t\n\t
\n\t\t
\n\n\n\t\t\t\n\n\t\t
\n\t
\n
\n\n \n
\n \"\"\n\n
\n
\n
\n \n
\n\n\"\"\n
\n \n \n \n \n
\n\n
\n

Welcome to HISPMD

\n

Health Information Systems Performance Monitoring Dashboard

\n \n
\n \n \n \n
\n
\n\n
\n
\n\n \n \n \n \n \n \n \n \n \n \n \n \n \n\n \n \n \n \n\n
\n\n\n\n\n\n
\n\n\n\n\n\t\t\t\t\t\t\n\n\t\t\t\t\t\t
\n\n\n\t\t\t\t\t\n\t\t\t\t\t\n\n\n\t\t\t\t\t
\n\t\t\t\t\n\t\t\t\t\t\n\n\n\n\n\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\n\t\t\t\t\n\t\n\t\n\n\t\n\t\n\n\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\n\t\n\t\n\n\n\t
\n\t
\n\t
\n\t
\n\n\n\n\n","hidden":"{$item_hide_text8}","isHtml":true}, ], "border": [ false, false, false, false ], diff --git a/app/postgre.php b/app/postgre.php new file mode 100644 index 00000000..49b9dc37 --- /dev/null +++ b/app/postgre.php @@ -0,0 +1,598 @@ +Connect failed.
".@pg_last_error()."
"; + $todo=""; + } +} + +if($todo=="schema") +{ + show_schema(); + exit(); +} + +if(!$todo || $todo=="connect") +{ +?> + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +"; +?> + + + + +
Server address" onchange="mk_connstr();">
Username
Password
Additional parameters
Database +
Connection string
+ +
+"; + $dblist=pg_query($conn,"select * from pg_catalog.pg_database"); + while($row=pg_fetch_array($dblist)) + echo ""; + echo ""; +} + +else if($todo=="queryfields") +{ + $sql = @$_REQUEST["sql"]; + if(!$sql) + return; + $res = pg_query($conn,$sql); + echo ""; + for($i=0;$i"; + } + echo ""; +} +else if($todo=="tables") +{ + echo ""; + $tables=pg_query($conn,"select 1 as ord,'TABLE' as type,schemaname||'.'||tablename as name from pg_tables where schemaname not in ('pg_catalog','information_schema') + union all + select 3,'SYSTEM TABLE' as type,schemaname||'.'||tablename as name from pg_tables where schemaname in ('pg_catalog','information_schema') + union all + select 2,'VIEW' as type,schemaname||'.'||viewname as name from pg_views where schemaname not in ('pg_catalog','information_schema') + union all + select 4,'SYSTEM VIEW' as type,schemaname||'.'||viewname as name from pg_views where schemaname in ('pg_catalog','information_schema') + order by ord,name") or showerror(); + while($table=pg_fetch_array($tables)) + { +?> + + "; +} +else if($todo=="tablefields") +{ + $table = @$_REQUEST["table"]; + if(!$table) + return; + showtablefields($table); +} +else if($todo=="tablekeys") +{ + $table = @$_REQUEST["table"]; + if(!$table) + return; + showtablekeys($table); +} +else if($todo=="queryvalues") +{ + $sql = @$_REQUEST["sql"]; + if(!$sql) + return; + $sql.=" limit 200"; + $res = pg_query($conn,$sql); + if(pg_num_fields($res)==1) + { + echo ""; + while($row=pg_fetch_array($res)) + echo "".htmlspecialchars($row[0]).""; + echo ""; + } + else + { + echo "\r\n"; + while($row=pg_fetch_array($res)) + { + echo ""; + for($i=0;$i".htmlspecialchars($row[$i]).""; + echo "\r\n"; + } + echo "\r\n"; + } +} +else if($todo=="queryvaluesraw") +{ + $sql = @$_REQUEST["sql"]; + if(!$sql) + return; + $res = pg_query($conn,$sql); + if(!$res) + { + echo pg_last_error($conn); + return; + } + + echo "\r\n"; + + echo "\r\n"; + for($i=0;$i".htmlspecialchars(pg_field_name($res,$i))."\r\n"; + echo "\r\n"; + + while($row=pg_fetch_array($res)) + { + echo "\r\n"; + for($i=0;$i".htmlspecialchars($row[$i])."\r\n"; + } + echo "\r\n"; + } + echo "\r\n"; +} +else if($todo=="queryvaluesstr") +{ + $sql = @$_REQUEST["sql"]; + if(!$sql) + return; + $res = pg_query($conn,$sql); + if(!$res) + { + echo @pg_last_error($conn); + return; + } + + $binfields = array(); + for($i=0;$i\r\n"; + + echo "\r\n"; + for($i=0;$i".htmlspecialchars(pg_field_name($res,$i))."\r\n"; + echo "\r\n"; + + while($row=pg_fetch_array($res)) + { + echo "\r\n"; + for($i=0;$i".htmlspecialchars($row[$i])."\r\n"; + } + else + { + if (strlen($row[$i]) == 0) //if stored NULL value + echo "NULL\r\n"; + else if (strpos($row[$i], '\\x') === false) //if used octal escape sequence + echo "0x".bin2hex(pg_unescape_bytea($row[$i]))."\r\n"; + else //if already used hex representation + echo "0x".substr($row[$i], 2)."\r\n"; + } + } + echo "\r\n"; + } + echo "\r\n"; +} + + + +function showtablefields($table) +{ + global $conn; + $arr=explode(".",$table); + if(count($arr)<2) + { + $schema="public"; + } + else + { + $table=$arr[1]; + $schema=$arr[0]; + } + echo ""; + $sql=sprintf("select pg_attribute.attname,typname from pg_attribute, pg_class, pg_namespace, pg_type + where pg_type.oid=atttypid and pg_class.oid=attrelid and pg_namespace.oid=relnamespace + and relname='%s' and nspname='%s' and attnum>0 + order by attnum",$table,$schema); + $fields=pg_query($conn,$sql); + while($field=pg_fetch_array($fields)) + { + $attr=array(); + $attr["name"]=$field[0]; + $attr["type"]=$field[1]; + + echo '$value) + echo $key.'="'.htmlspecialchars($value).'" '; + echo '/>'; + } + echo ""; +} + +function showtablekeys($table) +{ + global $conn; + $arr=explode(".",$table); + if(count($arr)<2) + { + $schema="public"; + } + else + { + $table=$arr[1]; + $schema=$arr[0]; + } + echo ""; + $sql=sprintf("select pg_attribute.attname + from pg_constraint, pg_class, pg_namespace,pg_attribute + where pg_class.oid=conrelid and pg_namespace.oid=connamespace and attrelid=conrelid and attnum=conkey[1] + and relname='%s' and nspname='%s' and contype='p'",$table,$schema); + $fields=pg_query($conn,$sql); + while($field=pg_fetch_array($fields)) + { + $attr=array(); + $attr["name"]=$field[0]; + echo '$value) { + echo $key.'="'.htmlspecialchars($value).'" '; + } + echo '/>'; + } + echo ""; +} + +function showerror() +{ + echo @pg_last_error($conn); + exit(); +} + +function show_schema() +{ + global $conn; + header("Content-type: text/xml"); + echo ''; + // determine php version + $phpversion=phpversion(); + // determine pg version + $pgversion = "unknown"; + $res = pg_query($conn,"select version()"); + if($res && $row=pg_fetch_array($res)) + $pgversion = $row["version"]; +?> + + + +
+ +
+ +
+ +"; +// display fields info + echo ""; + for($i=0;$i"; + } + echo ""; +// display query data + echo ""; + $recno=0; + while($data=pg_fetch_row($rs)) + { + $recno++; + if($recno<=$skip) + continue; + if($reccount>=0 && $recno+$skip>$reccount) + break; + echo ""; + foreach($data as $i=>$val) + { + if(is_null($val)) + { + echo ''; + } + else if($bfields[$i]) + { + if (strpos($val, '\\x') === false) //if used octal escape sequence + echo '0x'.bin2hex(pg_unescape_bytea($val)).''; + else //if already used hex representation + echo '0x'.substr($val, 2).''; + } + else + { + echo ''.xmlencode($val).''; + } + } + echo ""; + } + echo ""; + echo ""; + echo "end-script-output"; + pg_close($conn); + exit(); +} + +function xmlencode($str) +{ + $str = str_replace("&","&",$str); + $str = str_replace("<","<",$str); + $str = str_replace(">",">",$str); + $str = str_replace("\"",""",$str); + return str_replace("'", "'", $str); + + /* + $out=""; + $len=strlen($str); + $ind=0; + for($i=0;$i<$len;$i++) + { + if(ord($str[$i])>=128) + { + if($ind<$i) + $out.=substr($str,$ind,$i-$ind); + $out.="&#".ord($str[$i]).";"; + $ind=$i+1; + } + } + if($ind<$len) + $out.=substr($str,$ind); + return str_replace("'","'",$out); + /**/ +} + +?> \ No newline at end of file diff --git a/app/start.php b/app/start.php index 4ed27711..0ec4747c 100644 --- a/app/start.php +++ b/app/start.php @@ -149,7 +149,7 @@ function getGreeting() {

Welcome to HISPMD

-

Health Information Management Information Systems Dashboard

+

Health Information Systems Performance Monitoring Dashboard

Get Started diff --git a/app/templates/.global_menu.htm b/app/templates/.global_menu.htm index c6bb876c..0d5fb772 100644 --- a/app/templates/.global_menu.htm +++ b/app/templates/.global_menu.htm @@ -255,7 +255,7 @@

Welcome to HISPMD

-

Health Information Management Information Systems Dashboard

+

Health Information Systems Performance Monitoring Dashboard