Changeset 873 for trunk/Modules/API/API.php
- Timestamp:
- Apr 6, 2020, 11:17:40 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Modules/API/API.php
r804 r873 47 47 { 48 48 // p - token 49 if (array_key_exists('p', $_GET)) {49 if (array_key_exists('p', $_GET)) { 50 50 $Token = $_GET['p']; 51 51 $DbResult = $this->Database->query('SELECT `User` FROM `APIToken` WHERE `Token`="'.$Token.'"'); 52 if ($DbResult->num_rows > 0)52 if ($DbResult->num_rows > 0) 53 53 { 54 54 $DbRow = $DbResult->fetch_assoc(); … … 57 57 } else die('Missing access token'); 58 58 // f - data format 59 if (array_key_exists('f', $_GET)) $this->DataFormat = $_GET['f'];59 if (array_key_exists('f', $_GET)) $this->DataFormat = $_GET['f']; 60 60 else $this->DataFormat = 'php'; 61 61 // a - action 62 if (array_key_exists('a', $_GET)) $Action = $_GET['a'];62 if (array_key_exists('a', $_GET)) $Action = $_GET['a']; 63 63 else $Action = ''; 64 64 // t - table 65 if (array_key_exists('t', $_GET)) $Table = $_GET['t'];65 if (array_key_exists('t', $_GET)) $Table = $_GET['t']; 66 66 else $Table = ''; 67 67 // i - index of item 68 if (array_key_exists('i', $_GET)) $ItemId = $_GET['i'];68 if (array_key_exists('i', $_GET)) $ItemId = $_GET['i']; 69 69 else $ItemId = 0; 70 70 71 if ($Action == 'list') $Output = $this->ShowList($Table, $ItemId);71 if ($Action == 'list') $Output = $this->ShowList($Table, $ItemId); 72 72 else $Output = 'Unsupported action'; 73 73 74 return ($Output);74 return ($Output); 75 75 } 76 76 77 77 function ShowList($Table, $ItemId) 78 78 { 79 if (($Table != '') and (array_key_exists($Table, $this->System->FormManager->Classes)))79 if (($Table != '') and (array_key_exists($Table, $this->System->FormManager->Classes))) 80 80 $FormClass = $this->System->FormManager->Classes[$Table]; 81 else return ('Table not found');81 else return ('Table not found'); 82 82 83 if (array_key_exists('SQL', $FormClass))83 if (array_key_exists('SQL', $FormClass)) 84 84 $SourceTable = '('.$FormClass['SQL'].') AS `TX`'; 85 85 else $SourceTable = '`'.$FormClass['Table'].'` AS `TX`'; 86 86 87 87 $Filter = ''; 88 if ($ItemId != 0)88 if ($ItemId != 0) 89 89 { 90 90 $Filter .= '`Id`='.$ItemId; 91 91 } 92 if ($Filter != '') $Filter = ' WHERE '.$Filter;92 if ($Filter != '') $Filter = ' WHERE '.$Filter; 93 93 94 94 $Result = array(); 95 95 $DbResult = $this->Database->query('SELECT * FROM '.$SourceTable.$Filter); 96 while ($DbRow = $DbResult->fetch_assoc())96 while ($DbRow = $DbResult->fetch_assoc()) 97 97 { 98 98 $Result[] = $DbRow; 99 99 } 100 if ($this->DataFormat == 'php') $Output = serialize($Result);101 else if ($this->DataFormat == 'xml') $Output = $this->array2xml($Result);102 else if ($this->DataFormat == 'json') $Output = json_encode($Result);100 if ($this->DataFormat == 'php') $Output = serialize($Result); 101 else if ($this->DataFormat == 'xml') $Output = $this->array2xml($Result); 102 else if ($this->DataFormat == 'json') $Output = json_encode($Result); 103 103 else die('Unknown data format '.$this->DataFormat); 104 return ($Output);104 return ($Output); 105 105 } 106 106 … … 114 114 $array2xml = function ($node, $array) use ($dom, &$array2xml) 115 115 { 116 foreach ($array as $key => $value)116 foreach ($array as $key => $value) 117 117 { 118 118 if ( is_array($value) ) 119 119 { 120 if (is_numeric($key)) $key = 'N'.$key; //die('XML tag name "'.$key.'" can\'t be numeric');120 if (is_numeric($key)) $key = 'N'.$key; //die('XML tag name "'.$key.'" can\'t be numeric'); 121 121 $n = $dom->createElement($key); 122 122 $node->appendChild($n); 123 123 $array2xml($n, $value); 124 124 } else { 125 if (is_numeric($key)) $key = 'N'.$key; //die('XML attribute name "'.$key.'" can\'t be numeric');125 if (is_numeric($key)) $key = 'N'.$key; //die('XML attribute name "'.$key.'" can\'t be numeric'); 126 126 $attr = $dom->createAttribute($key); 127 127 $attr->value = $value;
Note:
See TracChangeset
for help on using the changeset viewer.