PageRenderTime 70ms CodeModel.GetById 36ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/gazpme/gaz_pme_edit.php

https://bitbucket.org/marcor/gazie
PHP | 233 lines | 138 code | 21 blank | 74 comment | 50 complexity | 2d20e83167c5f1ea3b3003d60336a69e MD5 | raw file
Possible License(s): LGPL-2.1, LGPL-3.0, GPL-2.0
  1. <?php
  2. require("../../library/include/datlib.inc.php");
  3. $admin_aziend=checkAdmin(9);
  4. if (!isset($_POST['hidden_req'])) { //al primo accesso allo script
  5. $form['table'] = '';
  6. $form['hidden_req'] = '';
  7. $form['ritorno'] = $_SERVER['HTTP_REFERER'];
  8. } else {
  9. $form['table'] = $_POST['table'];
  10. $form['hidden_req'] = $_POST['hidden_req'];
  11. $form['ritorno'] = $_POST['ritorno'];
  12. if (isset($_POST['Return'])) {
  13. header("Location:docume_finean.php");
  14. exit;
  15. }
  16. }
  17. // MySQL host name, user name, password, database, and table to edit
  18. $opts["hn"] = $Host;
  19. $opts["un"] = $User;
  20. $opts["pw"] = $Password;
  21. $opts["db"] = $Database;
  22. // Number of records to display on the screen
  23. // Note value of -1 lists all records in a table.
  24. $opts['inc'] = $passo;
  25. // Options you wish to give the users
  26. // A(dd) C(hange) (co)P(y) V(iew) D(elete) F(ilter) I(nitial sort suppressed)
  27. $opts['options'] = 'ACPVDF';
  28. // Number of lines to display on multiple selection filters
  29. $opts['multiple'] = '4';
  30. // Number of lines to display on multiple selection filters
  31. //$opts['default_sort_columns'] = array('pushId','due','priority','task');
  32. // Navigation style: B - buttons (default), T - text links, G - graphic links
  33. // Buttons position: U - up, D - down (default)
  34. $opts['navigation'] = 'DB';
  35. // Display special page elements
  36. $opts['display'] = array(
  37. 'query' => false,
  38. 'sort' => true,
  39. 'time' => false
  40. );
  41. $select_tab=array();
  42. $tables = gaz_dbi_query ("SHOW TABLES FROM ".$Database." LIKE '".$table_prefix.'_'."%'");// ottengo le tabelle in un unico array associativo
  43. $cnt=0;
  44. while ($r = gaz_dbi_fetch_array($tables)) {
  45. //
  46. // Mi accerto che la tabella indicata da $r[0] sia una di quelle
  47. // che si vuole rendere accessibile alla modifica diretta.
  48. // Diversamente la si ignora e si salta a un nuovo ciclo.
  49. //
  50. $lunghezza_prefisso = strlen ($table_prefix."_".$id);
  51. //
  52. if (! strncmp ($r[0], $table_prefix."_".$id, $lunghezza_prefisso)) {
  53. //
  54. // Si tratta di una tabella dell'azienda $id, ovvero quella
  55. // attuale: tabella valida.
  56. //
  57. ;
  58. } else if ( ($r[0] == $table_prefix."_"."anagra")
  59. || ($r[0] == $table_prefix."_"."aziend")
  60. || ($r[0] == $table_prefix."_"."country")
  61. || ($r[0] == $table_prefix."_"."currencies")
  62. || ($r[0] == $table_prefix."_"."currency_history")
  63. || ($r[0] == $table_prefix."_"."languages")
  64. || ($r[0] == $table_prefix."_"."municipalities")
  65. || ($r[0] == $table_prefix."_"."provinces")
  66. || ($r[0] == $table_prefix."_"."regions")) {
  67. //
  68. // Si tratta di una tabella generale che si ritiene
  69. // utile poter modificare direttamente.
  70. //
  71. ;
  72. } else {
  73. //
  74. // Non si espongono altre tabelle.
  75. //
  76. continue;
  77. }
  78. $select_tab[]=$r[0];
  79. if (!isset($_POST['hidden_req']) && $cnt==0) { // al primo accesso seleziono comunque la prima tabella
  80. $form['table']=$r[0];
  81. }
  82. if ($r[0] == $form['table']){
  83. $opts["tb"] = $r[0];
  84. // ---- INIZIO ROUTINE PRESA DA phpMyEditSetup e modificata
  85. // ---- per generare l'array $fdd anziche' il file php con il nome della tabella
  86. $tb_desc = @mysql_query("DESCRIBE ".$opts["tb"]);
  87. $fds = @mysql_list_fields($opts["db"], $opts["tb"], $link);
  88. $num_fds = @mysql_num_fields($fds);
  89. $ts_cnt = 0;
  90. $opts['fdd']=array();
  91. $k_cnt = true;
  92. $first = true;
  93. for ($k = 0; $k < $num_fds; $k++) {
  94. $fd = mysql_field_name($fds,$k);
  95. $fm = mysql_fetch_field($fds,$k);
  96. if ($first) {
  97. $opts["key"] = $fm->name;
  98. $opts["sort_field"] = $fm->name;
  99. $opts["key_type"] = $fm->type;
  100. $first=false ;
  101. }
  102. if ($fm->primary_key ==1 && $k_cnt) {
  103. $opts["key"] = $fm->name;
  104. $opts["sort_field"] = $fm->name;
  105. $opts["key_type"] = $fm->type;
  106. $k_cnt=false ;
  107. }
  108. $fn = strtr($fd, '_-.', ' ');
  109. //--- GAZIE $fn = preg_replace('/(^| +)id( +|$)/', '\\1ID\\2', $fn); // uppercase IDs
  110. //--- GAZIE $fn = ucfirst($fn);
  111. $row = @mysql_fetch_array($tb_desc);
  112. //--- GAZIE echo_buffer('$opts[\'fdd\'][\''.$fd.'\'] = array('); // )
  113. //--- GAZIE echo_buffer(" 'name' => '".str_replace('\'','\\\'',$fn)."',");
  114. $opts['fdd'][$fd]['name']=$fn;
  115. $auto_increment = strstr($row[5], 'auto_increment') ? 1 : 0;
  116. if (substr($row[1],0,3) == 'set') {
  117. //--- GAZIE echo_buffer(" 'select' => 'M',");
  118. $opts['fdd'][$fd]['select']='M';
  119. } else {
  120. //--- GAZIE echo_buffer(" 'select' => 'T',");
  121. $opts['fdd'][$fd]['select']='T';
  122. }
  123. if ($auto_increment) {
  124. //--- GAZIE echo_buffer(" 'options' => 'AVCPDR', // auto increment");
  125. $opts['fdd'][$fd]['options']='AVCPDR';
  126. } else if (@mysql_field_type($fds, $k) == 'timestamp') { // timestamps are read-only
  127. if ($ts_cnt > 0) {
  128. //--- GAZIE echo_buffer(" 'options' => 'AVCPD',");
  129. $opts['fdd'][$fd]['options']='AVCPD';
  130. } else { // first timestamp
  131. //--- GAZIE echo_buffer(" 'options' => 'AVCPDR', // updated automatically (MySQL feature)");
  132. $opts['fdd'][$fd]['options']='AVCPDR';
  133. }
  134. $ts_cnt++;
  135. }
  136. //--- GAZIE echo_buffer(" 'maxlen' => ".@mysql_field_len($fds,$k).',');
  137. $opts['fdd'][$fd]['maxlen']=@mysql_field_len($fds,$k);
  138. // blobs -> textarea
  139. if (@mysql_field_type($fds,$k) == 'blob') { // non permetto il trattamento dei campi BLOB
  140. /*--- GAZIE echo_buffer(" 'textarea' => array(");
  141. echo_buffer(" 'rows' => 5,");
  142. echo_buffer(" 'cols' => 50),");
  143. */
  144. unset($opts['fdd'][$fd]);
  145. continue;
  146. }
  147. // SETs and ENUMs get special treatment
  148. /*--- GAZIE if ((substr($row[1],0,3) == 'set' || substr($row[1],0,4) == 'enum')
  149. && ! (($pos = strpos($row[1], '(')) === false)) {
  150. $indent = str_repeat(' ', 18);
  151. $outstr = substr($row[1], $pos + 2, -2);
  152. $outstr = explode("','", $outstr);
  153. $outstr = str_replace("''", "'", $outstr);
  154. $outstr = str_replace('"', '\\"', $outstr);
  155. $outstr = implode('",'.PHP_EOL.$indent.'"', $outstr);
  156. echo_buffer(" 'values' => array(".PHP_EOL.$indent.'"'.$outstr.'"),');
  157. }
  158. */
  159. // automatic support for Default values
  160. if ($row[4] != '' && $row[4] != 'NULL') {
  161. //--- GAZIE echo_buffer(" 'default' => '".$row[4]."',");
  162. $opts['fdd'][$fd]['default']=$row[4];
  163. } else if ($auto_increment) {
  164. //--- GAZIE echo_buffer(" 'default' => '0',");
  165. $opts['fdd'][$fd]['default']='0';
  166. }
  167. // check for table constraints
  168. /*--- GAZIE $outstr = check_constraints($tb, $fd);
  169. if ($outstr != '') {
  170. //--- GAZIE echo_buffer($outstr);
  171. }*/
  172. //--- GAZIE echo_buffer(" 'sort' => true");
  173. $opts['fdd'][$fd]['sort']=true;
  174. //echo_buffer(" 'nowrap' => false,");
  175. $opts['fdd'][$fd]['nowrap']=false;
  176. }
  177. // ---- FINE ROUTINE PRESA DA phpMyEditSetup e modificata
  178. // ---- per generare l'array $fdd anziche' il file php con il nome della tabella
  179. }
  180. $cnt++;
  181. }
  182. /* Get the user's default language and use it if possible or you can specify
  183. language particular one you want to use. Available languages are:
  184. DE EN-US EN FR IT NL PG SK SP */
  185. $opts['language']= $admin_aziend['country'];
  186. require("../../library/include/header.php");
  187. // and now the all-important call to phpMyEdit
  188. // warning - beware of case-sensitive operating systems!
  189. require_once 'phpMyEdit.class.php';
  190. $script_transl = HeadMain();
  191. $gForm = new GAzieForm();
  192. echo '<form method="post" name="GAz_sys_form">';
  193. echo "<input type=\"hidden\" value=\"".$form['hidden_req']."\" name=\"hidden_req\" />\n";
  194. echo "<input type=\"hidden\" value=\"".$form['ritorno']."\" name=\"ritorno\" />\n";
  195. echo "<div align=\"center\" class=\"FacetFormHeaderFont\">".$script_transl['title'];
  196. echo "</div>\n";
  197. echo "<div align=\"center\" class=\"FacetFormHeaderRed\">".$script_transl['msg1'];
  198. echo "</div>\n";
  199. echo "<table class=\"Tmiddle\">\n";
  200. echo "\t<td class=\"FacetFieldCaptionTD\">".$script_transl['table']."</td><td class=\"FacetDataTD\">\n";
  201. $gForm->variousSelect('table',array_flip($select_tab),$form['table'],'FacetSelect',true,'table');
  202. echo "\t</td>\n";
  203. echo "</table>\n";
  204. $MyForm = new phpMyEdit($opts);
  205. echo "</form>\n";
  206. echo '<hr size="1" class="pme-hr" />';
  207. echo '<br />';
  208. echo "<div align=\"center\" class=\"FacetFormHeaderFont\"><a href=\"http://www.phpmyedit.org/\">".$script_transl['msg2'];
  209. echo "</a></div>\n";
  210. ?>
  211. </body>
  212. </html>