designreport.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  1. <?php require_once 'auth.php'; ?>
  2. <html>
  3. <head>
  4. <title><?=__('Design Report')?></title>
  5. <link rel="stylesheet" href="phpME.css" type="text/css"></link>
  6. </head>
  7. <body>
  8. <?=__('Parameter')?>: [userid]<br/><br/>
  9. <script language=javascript>
  10. function addtable() {
  11. tableElement = document.forms[0].table;
  12. id = tableElement.options[tableElement.selectedIndex].value;
  13. f = document.fReport;
  14. f.addtable.value = 1;
  15. f.idtable.value = id
  16. f.submit();
  17. }
  18. function deletetable(id) {
  19. f = document.fReport;
  20. f.deltable.value = 1;
  21. f.idtable.value = id
  22. f.submit();
  23. }
  24. function addcolumn(table, columnElement) {
  25. id = columnElement.options[columnElement.selectedIndex].value;
  26. f = document.fReport;
  27. f.addcolumn.value = 1;
  28. f.idcolumn.value = id;
  29. f.tbcolumn.value = table;
  30. f.submit();
  31. }
  32. function deletecolumn(id) {
  33. f = document.fReport;
  34. f.idcolumn.value = id;
  35. f.delcolumn.value = 1;
  36. f.submit();
  37. }
  38. function savedesign(f) {
  39. f.submit();
  40. }
  41. function addrelation(f) {
  42. f.addrelation.value = 1;
  43. f.submit();
  44. }
  45. function deleterelation(id) {
  46. f.delrelation.value = 1;
  47. f.idrelation.value = id;
  48. f.submit();
  49. }
  50. function generatesql(f) {
  51. f.generate.value = 1;
  52. f.submit();
  53. }
  54. </script>
  55. <?php
  56. # print_r($_SESSION);
  57. if (isset($_GET['idReport'])) {
  58. $rs = $adodb->Execute("SELECT * FROM qb_report ".
  59. " WHERE id = ? ", array($_GET['idReport']));
  60. if (!$rs->EOF) {
  61. $_SESSION['selectedTable'] = array();
  62. $_SESSION['selectedColumn'] = array();
  63. $_SESSION['selectedRelation'] = array();
  64. $unSerialize = unserialize($rs->fields['serialize']);
  65. if (is_array($unSerialize['selectedTable'])) {
  66. $_SESSION['selectedTable'] = $unSerialize['selectedTable'];
  67. $_SESSION['selectedColumn'] = $unSerialize['selectedColumn'];
  68. $_SESSION['selectedRelation'] = $unSerialize['selectedRelation'];
  69. }
  70. #$tableId = $rs->fields['tableid'];
  71. $reportName = htmlspecialchars($rs->fields['name']);
  72. }
  73. $_SESSION['selectedReport'] = $_GET['idReport'];
  74. }
  75. if (!isset($_SESSION['selectedTable'])) $_SESSION['selectedTable'] = array();
  76. if (!isset($_SESSION['selectedColumn'])) $_SESSION['selectedColumn'] = array();
  77. if (!isset($_SESSION['selectedRelation'])) $_SESSION['selectedRelation'] = array();
  78. if ($_REQUEST['tableid']) $tableId = $_REQUEST['tableid'];
  79. if ($_POST['addtable']) $tableId = $_POST['idtable'];
  80. if ($tableId) {
  81. $_SESSION['selectedTable'] = array($tableId);
  82. $saveKey = array();
  83. $metaColumns = $adodb->MetaColumns($tableId);
  84. $i = 0;
  85. foreach ($metaColumns as $k => $v) {
  86. foreach ($_SESSION['selectedColumn'] as $k2 => $v2) {
  87. if ( $v2[0] === $tableId && $v2[1] === $v->name) {
  88. $saveKey[$i] = $v2;
  89. }
  90. }
  91. if (!isset($saveKey[$i])) $saveKey[$i] = array($tableId, $v->name);
  92. $i++;
  93. }
  94. $_SESSION['selectedColumn'] = $saveKey;
  95. }
  96. if ($_POST['deltable']) {
  97. unset($_SESSION['selectedTable'][$_POST['idtable']]);
  98. }
  99. /*
  100. if ($_POST['addtable']) {
  101. $tableId = $_POST['idtable'];
  102. $_SESSION['selectedTable'] = array($tableId);
  103. $_SESSION['selectedColumn'] = array();
  104. $metaColumns = $adodb->MetaColumns($tableId);
  105. if (!is_array($metaColumns)) $metaColumns = array();
  106. foreach ($metaColumns as $k => $v) {
  107. $_SESSION['selectedColumn'][] = array($tableId, $v->name);
  108. }
  109. }
  110. */
  111. ?>
  112. <form method=post action='<?=$_SERVER['PHP_SELF']?>'>
  113. <?=__('Tables')?>:
  114. <select name=table>
  115. <option value=""></option>
  116. <?php
  117. $metaTables = $adodb->MetaTables();
  118. foreach ($metaTables as $k => $v) {
  119. if (ereg('^qb_', $v) || ereg('_crc$', $v) || ereg('_flag$', $v)) continue;
  120. $selected = '';
  121. if ($v === $_SESSION['selectedTable'][0]) {
  122. $selected = 'selected';
  123. #echo $v;
  124. }
  125. $v = htmlspecialchars($v);
  126. echo "<option value=\"".$v."\" ".$selected.">".$v."</option>\n";
  127. }
  128. ?>
  129. </select>
  130. <input type=button style='width:80px' value='<?=__('Change')?>' onClick='addtable()'><br/>
  131. </form>
  132. <table border=0><tr>
  133. <?php
  134. if ($_POST['delcolumn']) {
  135. unset($_SESSION['selectedColumn'][$_POST['idcolumn']]);
  136. }
  137. if ($_POST['addcolumn']) {
  138. $tableId = $_POST['tbcolumn'];
  139. $_SESSION['selectedColumn'][] = array($tableId, $_POST['idcolumn']);
  140. }
  141. if ($_POST['action'] === 'savedesign') {
  142. if (!is_array($_POST['id'])) $_POST['id'] = array();
  143. foreach ($_POST['id'] as $k => $v) {
  144. if ($_POST['delcolumn'] && $v === $_POST['idcolumn']) continue;
  145. if (!isset($_SESSION['selectedColumn'][$v])) continue;
  146. $_SESSION['selectedColumn'][$v]['total'] = $_POST['total'][$k];
  147. #$_SESSION['selectedColumn'][$v]['sort'] = $_POST['sort'][$k];
  148. $_SESSION['selectedColumn'][$v]['filterName'] = $_POST['filterName'][$k];
  149. $_SESSION['selectedColumn'][$v]['filterType'] = $_POST['filterType'][$k];
  150. $_SESSION['selectedColumn'][$v]['filterOp'] = $_POST['filterOp'][$k];
  151. $showVal = $_POST['show'][$k];
  152. if ($showVal === 'on') $_SESSION['selectedColumn'][$v]['show'] = 1;
  153. else $_SESSION['selectedColumn'][$v]['show'] = 0;
  154. $hiddenVal = $_POST['hidden'][$k];
  155. if ($hiddenVal === 'on') $_SESSION['selectedColumn'][$v]['hidden'] = 1;
  156. else $_SESSION['selectedColumn'][$v]['hidden'] = 0;
  157. $groupVal = $_POST['group'];
  158. if ($groupVal === $v) $_SESSION['selectedColumn'][$v]['group'] = 1;
  159. else $_SESSION['selectedColumn'][$v]['group'] = 0;
  160. #$fieldVal = $_POST['field'][$k];
  161. #list($table, $field) = explode(".", $fieldVal);
  162. #$_SESSION['selectedColumn'][$v][0] = $table;
  163. #$_SESSION['selectedColumn'][$v][1] = $field;
  164. #$_SESSION['selectedColumn'][$v]['criteria'] = $_POST['criteria'][$k];
  165. $_SESSION['selectedColumn'][$v]['or'] = $_POST['or'][$k];
  166. }
  167. }
  168. if ($_POST['addrelation']) {
  169. $a = $_POST['rLeft'];
  170. $b = $_POST['rJoin'];
  171. $c = $_POST['rRight'];
  172. $_SESSION['selectedRelation'][] = array($a, $b, $c);
  173. }
  174. if ($_POST['delrelation']) {
  175. unset($_SESSION['selectedRelation'][$_POST['idrelation']]);
  176. }
  177. if ($_POST['generate']) {
  178. $column = $where = $orderby = $table = $group = $groupby1 = $groupby2 = '';
  179. $notShow = $arrHidden = $arrColumn = array();
  180. foreach ($_SESSION['selectedColumn'] as $k => $v) {
  181. if (!isset($arrTable[$v[0]])) $arrTable[$v[0]] = 1;
  182. $tableField = $v[0].".".$v[1];
  183. $xtableField = $v[1];
  184. //***************************************************************************************************************************
  185. // Edited by Dennis Ritz
  186. // 11.04.2006
  187. //***************************************************************************************************************************
  188. if ($v['filterName'] && $v['filterType'] && $v['filterOp'])
  189. {
  190. if($v['filterName'] != '' && $v['filterType'] != '' && $v['filterOp'] != '')
  191. {
  192. if($filters)
  193. {
  194. $filters .= ",".$v[1].":".$v['filterName'].":".$v['filterType'];
  195. $filtersSQL .= " and ".$v[1]." ".$v['filterOp']." [".$v['filterName'].":".$v[1]."]";
  196. }
  197. else
  198. {
  199. $filters = $v[1].":".$v['filterName'].":".$v['filterType'];
  200. $filtersSQL = $v[1]." ".$v['filterOp']." [".$v['filterName'].":".$v[1]."]";
  201. }
  202. }
  203. }
  204. //****************************************************************************************************************************
  205. // END OF EDIT
  206. //****************************************************************************************************************************
  207. if ($v['criteria']) {
  208. if ($where) $where .= " AND ";
  209. $where .= $tableField." = '".$v['criteria']."'";
  210. }
  211. if ($v['or']) {
  212. if ($where) $where .= " AND ";
  213. $where .= $tableField." ".$v['or']."";
  214. }
  215. if ($v['show'] || $v['hidden']) {
  216. #if ($column) $column .= ", ";
  217. #$column .= $xtableField;
  218. $arrColumn[$xtableField] = 1;
  219. } else {
  220. $notShow[$xtableField] = 1;
  221. }
  222. if ($v['hidden']) {
  223. $arrHidden[$xtableField] = 1;
  224. }
  225. if ($v['sort'] && $v[1] !== '*') {
  226. $order = "ASC";
  227. if ($v['sort'] === 'Descending') $order = "DESC";
  228. if ($orderby) $orderby .= ",";
  229. $orderby .= $tableField." ".$order;
  230. }
  231. if ($v['total']) {
  232. if ($v['total'] === 'Group By') {
  233. #if ($group) $group .= ",";
  234. #$group .= $tableField;
  235. } else if ($v['show']) {
  236. #if ($column) $column .= ",";
  237. #$column .= strtoupper($v['total'])."(".$tableField.")";
  238. if ($groupby2) $groupby2 .= ",";
  239. $groupby2 .= strtoupper($v['total']).'.'.$xtableField;
  240. }
  241. }
  242. if ($v['group']) {
  243. $groupby1 = $xtableField.':';
  244. $orderby = $xtableField;
  245. }
  246. }
  247. $groupby = '';
  248. if ($groupby1) $groupby = $groupby1.$groupby2.";";
  249. $countTable = count($arrTable);
  250. if ($countTable > 1) {
  251. $arrRelation = array();
  252. foreach ($_SESSION['selectedRelation'] as $k => $v) {
  253. $left = $v[0];
  254. $join = $v[1];
  255. $right = $v[2];
  256. list($leftTable, $leftField) = explode(".", $left);
  257. list($rightTable, $rightField) = explode(".", $right);
  258. $arrRelation[$leftTable][$join][$rightTable][] = array($v[0],$v[2]);
  259. }
  260. foreach ($arrRelation as $leftTable => $v) {
  261. foreach ($v as $join => $v2) {
  262. foreach ($v2 as $rightTable => $v3) {
  263. if ($table) $table .= $join." ".$rightTable;
  264. else $table .= $leftTable." ".$join." ".$rightTable;
  265. $table .= " ON (";
  266. $using = '';
  267. foreach ($v3 as $k4 => $v4) {
  268. if ($using) $using .= " AND ";
  269. $using .= $v4[0]." = ".$v4[1];
  270. }
  271. $table .= $using.")";
  272. }
  273. }
  274. }
  275. }
  276. if ($table === '') {
  277. foreach ($arrTable as $k => $v) {
  278. if ($table) $table .= ", ";
  279. $table .= $k;
  280. }
  281. }
  282. $metaPK = $adodb->MetaPrimaryKeys($table);
  283. foreach ($metaPK as $k => $v) {
  284. if (!array_key_exists($v, $arrColumn)) {
  285. $arrColumn[$v] = 1;
  286. $arrHidden[$v] = 1;
  287. }
  288. }
  289. $column = implode(", ", array_keys($arrColumn));
  290. $sql = "SELECT ".$column."\n".
  291. "FROM ".$table."\n";
  292. if ($where) $sql .= "WHERE ".$where."\n";
  293. //if ($group) $sql .= "GROUP BY ".$group."\n";
  294. if ($group) $sql .= "ORDER BY ".$group."\n";
  295. if ($orderby) $sql .= "ORDER BY ".$orderby;
  296. $generateSQL = nl2br($sql);
  297. $sql = addslashes($sql);
  298. $sql = str_replace("\n", "\\n", $sql);
  299. $metaColumns = $adodb->MetaColumns($table);
  300. $arrCols = $arrCols2 = $arrCols3 = array();
  301. foreach ($metaColumns as $k => $v) {
  302. if ($v->primary_key === true) {
  303. $arrCols3[] = $v->name." = [".$v->name."]";
  304. } else {
  305. if ($notShow[$v->name]) continue;
  306. $arrCols2[] = $v->name." = [".$v->name."]";
  307. }
  308. $arrCols[] = $v->name;
  309. }
  310. $onInsert = "INSERT INTO ".$table." (".implode(", ", $arrCols).") ".
  311. " VALUES ( [".implode("], [", $arrCols)."] ); ";
  312. $onInsert = addslashes($onInsert);
  313. $onInsert = str_replace("\n", "\\n", $onInsert);
  314. $onUpdate = "UPDATE ".$table." SET ".implode(", ", $arrCols2).
  315. " WHERE ".implode(" AND ", $arrCols3).";";
  316. $onUpdate = addslashes($onUpdate);
  317. $onUpdate = str_replace("\n", "\\n", $onUpdate);
  318. $onDelete = "DELETE FROM ".$table." ".
  319. " WHERE ".implode(" AND ", $arrCols3).";";
  320. $onDelete = addslashes($onDelete);
  321. $onDelete = str_replace("\n", "\\n", $onDelete);
  322. $isDelete = "SELECT * FROM ".$table."_crc".
  323. " WHERE ".implode(" AND ", $arrCols3).";";
  324. $isDelete = addslashes($isDelete);
  325. $isDelete = str_replace("\n", "\\n", $isDelete);
  326. $readonly = '';
  327. $rs = $adodb->Execute("SELECT qb_config_odbc.serialize FROM qb_config ".
  328. " LEFT JOIN qb_config_odbc USING (id) ".
  329. " WHERE qb_config.tableid = ? ", array($table));
  330. if (!$rs->EOF) {
  331. $odbcCol = unserialize($rs->fields['serialize']);
  332. if (!is_array($odbcCol)) $odbcCol = array();
  333. #$readonly = implode(", ", $odbcCol);
  334. foreach ($odbcCol as $k => $v) {
  335. if ($notShow[$v]) continue;
  336. if ($readonly) $readonly .= ", ";
  337. $readonly .= $v;
  338. }
  339. }
  340. print $filters;
  341. print $filtersSQL;
  342. if(!isset($filters))
  343. $filters = '';
  344. if(!isset($filtersSQL))
  345. $filtersSQL = '';
  346. $hiddenStr = implode(",", array_keys($arrHidden));
  347. $pkey = implode(",", $metaPK);
  348. echo "<script language=javascript>
  349. function generateSQL() {
  350. if (! opener) return false;
  351. if (! opener.document) return false;
  352. if (! opener.document.forms[0]) return false;
  353. f = opener.document.forms[0];
  354. if (f.sql) f.sql.value = \"".$sql."\";
  355. if (f.oninsert) f.oninsert.value = \"".$onInsert."\";
  356. if (f.onupdate) f.onupdate.value = \"".$onUpdate."\";
  357. if (f.ondelete) f.ondelete.value = \"".$onDelete."\";
  358. if (f.isdelete) f.isdelete.value = \"".$isDelete."\";
  359. if (f.readonly) f.readonly.value = \"".$readonly."\";
  360. if (f.hidden) f.hidden.value = \"".$hiddenStr."\";
  361. if (f.paramtxt) f.paramtxt.value = \"".$filters."\";
  362. if (f.paramsql) f.paramsql.value = \"".$filtersSQL."\";
  363. if (f.groupby) f.groupby.value = \"".$groupby."\";
  364. if (f.pkey) f.pkey.value = \"".$pkey."\";
  365. return true;
  366. }
  367. generateSQL();
  368. </script>";
  369. }
  370. /*
  371. echo "<form method=post action='".$_SERVER['PHP_SELF']."'>";
  372. $i = 0;
  373. foreach ($_SESSION['selectedTable'] as $k => $v) {
  374. $tableId = $v;
  375. $metaColumns = $adodb->MetaColumns($tableId);
  376. $sizeColumns = count($metaColumns)+1;
  377. if ($sizeColumns>10) $sizeColumns = 10;
  378. $thStyle = "style='white-space: nowrap; background-color:#0055f6;color:white'";
  379. #$selectStyle = "style='width:100%'";
  380. $selectJs = "ondblclick='addcolumn(\"".$tableId."\", this)'";
  381. $selectSize = "size=".$sizeColumns;
  382. $buttonStyle = "style='background-color:#E64C20;color:white'";
  383. $buttonJs = "onClick='deletetable(\"".$k."\")'";
  384. echo "<td valign=top>";
  385. echo "<table style='border:1px #0055f6 solid;'>".
  386. "<tr><th ".$thStyle.">".$tableId." ".
  387. " <input ".$buttonStyle." type=button value=X ".$buttonJs."></th></tr>";
  388. echo "<tr><td align=center>";
  389. echo "<select ".$selectStyle." name=column".$i." ".$selectSize." ".$selectJs.">";
  390. echo "<option value='*'>*</option>";
  391. foreach ($metaColumns as $k => $v) {
  392. echo "<option value='".$v->name."'>".$v->name."</option>";
  393. }
  394. echo "</select>";
  395. echo "</td></tr>";
  396. echo "</table>";
  397. echo "</td>";
  398. $i++;
  399. }
  400. echo "</form>";
  401. */
  402. ?>
  403. </tr></table>
  404. <form name=fReport method=post action='<?=$_SERVER['PHP_SELF']?>'>
  405. <?php
  406. $countTable = array();
  407. foreach ($_SESSION['selectedColumn'] as $k => $v) {
  408. if (!isset($countTable[$v[0]])) $countTable[$v[0]] = 1;
  409. }
  410. $countSelectedTable = count($countTable);
  411. ?>
  412. <table width=100%>
  413. <?php
  414. $arrTd = array('', 'Field', 'Table', 'Show', 'Hidden', 'Group', /*'Sort',*/ 'Total', 'Filter-Name', 'Filter-Type', 'Filter-Operation', /*'Criteria',*/ 'or');
  415. $arrSort = array ('Ascending', 'Descending', '' => '(not sorted)');
  416. $arrTotal = array ('', 'Count', /*'Group By',*/ 'Sum', 'Avg', 'Min', 'Max');
  417. $arrFilterType = array ('', 'Text', 'Date', 'Select', 'Radio');
  418. $arrFilterOp = array ('', '=', '<', '<=', '>', '>=');
  419. //, 'StDev', 'Var', 'First', 'Last', 'Expression', 'Where');
  420. if (count($_SESSION['selectedColumn'])) {
  421. echo "<tr>";
  422. foreach ($arrTd as $k => $v) {
  423. $tdText = '';
  424. if ($v === 'or') $v = 'Criteria';
  425. if ($v) $tdText = __($v)."";
  426. if ($v === 'Table' || $v === '') {
  427. } else {
  428. echo "<th>".$tdText." </td>";
  429. }
  430. if ($v === 'Group') {
  431. echo "<br/><input type=radio name=group ".$checked." value=''>".__("Off");
  432. }
  433. }
  434. echo "</tr>";
  435. }
  436. $i = 0;
  437. foreach ($_SESSION['selectedColumn'] as $k2 => $v2) {
  438. if ($v === 'Table' || $v === '') {
  439. } else {
  440. echo "<tr>";
  441. }
  442. foreach ($arrTd as $k => $v) {
  443. if ($v === 'Field') {
  444. echo "<td align=center>
  445. <input type=hidden name=id[] value='$k2'>
  446. <input type=hidden name=field[] ";
  447. if (!isset($issetTable[$v2[0]])) {
  448. $metaColumns = $adodb->MetaColumns($v2[0]);
  449. $starObj->name = '*';
  450. $metaStar = array('star' => $starObj);
  451. $issetTable[$v2[0]] = array_merge($metaStar, $metaColumns);
  452. }
  453. $metaColumns = $issetTable[$v2[0]];
  454. foreach ($metaColumns as $k3 => $v3) {
  455. $optionVal = $v2[0].".".$v3->name;
  456. $optionText = $v3->name;
  457. $selected = '';
  458. if ($v2[1] === $v3->name) {
  459. $selected = 'selected';
  460. echo " value='".$optionVal."'>".$optionText;
  461. }
  462. }
  463. echo "
  464. </td>";
  465. } else if ($v === 'Table') {
  466. echo "<input type=hidden name=table[] value='".$v2[0]."'>";
  467. } else if ($v === 'Group') {
  468. #if (!isset($_SESSION['selectedColumn'][$k2]['group'])) {
  469. # $_SESSION['selectedColumn'][$k2]['group'] = '0';
  470. #}
  471. $checked = '';
  472. if ($_SESSION['selectedColumn'][$k2]['group']) $checked = 'checked';
  473. echo "<td align=center>
  474. <input type=radio name=group ".$checked." value='$k2'>
  475. </td>";
  476. } else if ($v === 'Show') {
  477. if (!isset($_SESSION['selectedColumn'][$k2]['show'])) {
  478. $_SESSION['selectedColumn'][$k2]['show'] = '1';
  479. }
  480. $checked = '';
  481. if ($_SESSION['selectedColumn'][$k2]['show']) $checked = 'checked';
  482. echo "<td align=center>
  483. <input type=checkbox name=show[".$i."] ".$checked.">
  484. </td>";
  485. } else if ($v === 'Hidden') {
  486. if (!isset($_SESSION['selectedColumn'][$k2]['hidden'])) {
  487. $_SESSION['selectedColumn'][$k2]['hidden'] = '0';
  488. }
  489. $checked = '';
  490. if ($_SESSION['selectedColumn'][$k2]['hidden']) $checked = 'checked';
  491. if (! $_SESSION['selectedColumn'][$k2]['show']
  492. && is_array($metaPK) && is_int(array_search($k2, $metaPK))) {
  493. $checked = 'checked';
  494. }
  495. echo "<td align=center>
  496. <input type=checkbox name=hidden[".$i."] ".$checked.">
  497. </td>";
  498. } else if ($v === '') {
  499. #$buttonStyle = "style='background-color:#E64C20;color:white'";
  500. #$buttonJs = "onClick='deletecolumn(\"".$k2."\")'";
  501. #echo "<td align=center>
  502. #<input ".$buttonStyle." type=button value=X ".$buttonJs.">
  503. #</td>";
  504. } else if ($v === 'Sort') {
  505. /*
  506. if (!isset($_SESSION['selectedColumn'][$k2]['sort'])) {
  507. $_SESSION['selectedColumn'][$k2]['sort'] = '';
  508. }
  509. #$selectStyle = "style='width:100%'";
  510. echo "<td>
  511. <select name=sort[] ".$selectStyle.">";
  512. foreach ($arrSort as $k3 => $v3) {
  513. if (ereg('[0-9]+', $k3)) $k3 = $v3;
  514. $selected = '';
  515. if ($_SESSION['selectedColumn'][$k2]['sort'] === $k3) {
  516. $selected = 'selected';
  517. }
  518. echo "<option value='".$k3."' ".$selected.">".$v3."</option>\n";
  519. }
  520. echo "</select>
  521. </td>";
  522. */
  523. } else if ($v === 'Total') {
  524. if (!isset($_SESSION['selectedColumn'][$k2]['total'])) {
  525. $_SESSION['selectedColumn'][$k2]['total'] = '';
  526. }
  527. #$selectStyle = "style='width:100%'";
  528. echo "<td>
  529. <select name=total[] ".$selectStyle.">";
  530. foreach ($arrTotal as $k3 => $v3) {
  531. if (ereg('[0-9]+', $k3)) $k3 = $v3;
  532. $selected = '';
  533. if ($_SESSION['selectedColumn'][$k2]['total'] === $k3) {
  534. $selected = 'selected';
  535. }
  536. echo "<option value='".$k3."' ".$selected.">".$v3."</option>\n";
  537. }
  538. echo "</select>
  539. </td>";
  540. } else if ($v === 'Filter-Name') {
  541. $textValue = "value='".$_SESSION['selectedColumn'][$k2]['filterName']."'";
  542. $textStyle = "style='width:100%'";
  543. echo "<td>
  544. <input ".$textStyle." type=text name=filterName[] ".$textValue.">
  545. </td>";
  546. } else if ($v === 'Filter-Type') {
  547. if (!isset($_SESSION['selectedColumn'][$k2]['filterType'])) {
  548. $_SESSION['selectedColumn'][$k2]['filterType'] = '';
  549. }
  550. #$selectStyle = "style='width:100%'";
  551. echo "<td>
  552. <select name=filterType[] ".$selectStyle.">";
  553. foreach ($arrFilterType as $k3 => $v3) {
  554. if (ereg('[0-9]+', strtolower($k3))) $k3 = $v3;
  555. $selected = '';
  556. if ($_SESSION['selectedColumn'][$k2]['filterType'] === strtolower($k3)) {
  557. $selected = 'selected';
  558. }
  559. echo "<option value='".strtolower($k3)."' ".$selected.">".$v3."</option>\n";
  560. }
  561. echo "</select>
  562. </td>";
  563. } else if ($v === 'Filter-Operation') {
  564. if (!isset($_SESSION['selectedColumn'][$k2]['filterOp'])) {
  565. $_SESSION['selectedColumn'][$k2]['filterOp'] = '';
  566. }
  567. #$selectStyle = "style='width:100%'";
  568. echo "<td>
  569. <select name=filterOp[] ".$selectStyle.">";
  570. foreach ($arrFilterOp as $k3 => $v3) {
  571. if (ereg('[0-9]+', strtolower($k3))) $k3 = $v3;
  572. $selected = '';
  573. if ($_SESSION['selectedColumn'][$k2]['filterOp'] === strtolower($k3)) {
  574. $selected = 'selected';
  575. }
  576. echo "<option value='".strtolower($k3)."' ".$selected.">".$v3."</option>\n";
  577. }
  578. echo "</select>
  579. </td>";
  580. } else if ($v === 'Criteria') {
  581. $textValue = "value='".$_SESSION['selectedColumn'][$k2]['criteria']."'";
  582. $textStyle = "style='width:100%'";
  583. echo "<td>
  584. <input ".$textStyle." type=text name=criteria[] ".$textValue.">
  585. </td>";
  586. } else if ($v === 'or') {
  587. $textValue = "value=\"".htmlspecialchars($v2['or'])."\"";
  588. $textStyle = "style='width:99%'";
  589. echo "<td>
  590. <input ".$textStyle." type=text name=or[] ".$textValue.">
  591. </td>";
  592. }
  593. }
  594. if ($v === 'Table' || $v === '') {
  595. } else {
  596. echo "</tr>";
  597. }
  598. $i++;
  599. }
  600. $record = array();
  601. $record['serialize'] = serialize(array(
  602. 'selectedTable' => $_SESSION['selectedTable'],
  603. 'selectedColumn' => $_SESSION['selectedColumn'],
  604. 'selectedRelation' => $_SESSION['selectedRelation']
  605. ));
  606. $rs = $adodb->Execute("SELECT * FROM qb_report ".
  607. " WHERE id = ? ", array($_SESSION['selectedReport']));
  608. $updateSQL = $adodb->GetUpdateSQL($rs, $record);
  609. if ($updateSQL) $adodb->Execute($updateSQL);
  610. $record['serialize'] = str_replace("\n", "\\n", $record['serialize']);
  611. echo "<script language=javascript>
  612. form = opener.document.forms[0];
  613. serializeElement = null;
  614. if (form) serializeElement = form.serialize;
  615. if (serializeElement) {
  616. serializeElement.value = \"".addslashes($record['serialize'])."\";
  617. }
  618. </script>";
  619. ?>
  620. </table>
  621. <input type=hidden name=deltable>
  622. <input type=hidden name=addtable>
  623. <input type=hidden name=idtable>
  624. <input type=hidden name=addcolumn>
  625. <input type=hidden name=idcolumn>
  626. <input type=hidden name=tbcolumn>
  627. <input type=hidden name=delcolumn>
  628. <input type=hidden name=action value=savedesign>
  629. <input type=hidden name=generate>
  630. <input type=button value='<?=__('Save')?>' onClick=generatesql(this.form)>
  631. <input type=button value='<?=__('Cancel')?>' onClick="self.close()">
  632. </form>
  633. <?php
  634. #<input type=button value='<?=__('Save')? >' onClick=savedesign(this.form)>
  635. #if ($generateSQL) echo $generateSQL;
  636. ?>
  637. </body>
  638. </html>