insert_edit.lib.php 88 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * set of functions with the insert/edit features in pma
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. if (! defined('PHPMYADMIN')) {
  9. exit;
  10. }
  11. /**
  12. * Retrieve form parameters for insert/edit form
  13. *
  14. * @param string $db name of the database
  15. * @param string $table name of the table
  16. * @param array $where_clauses where clauses
  17. * @param array $where_clause_array array of where clauses
  18. * @param string $err_url error url
  19. *
  20. * @return array $_form_params array of insert/edit form parameters
  21. */
  22. function PMA_getFormParametersForInsertForm($db, $table, $where_clauses,
  23. $where_clause_array, $err_url
  24. ) {
  25. $_form_params = array(
  26. 'db' => $db,
  27. 'table' => $table,
  28. 'goto' => $GLOBALS['goto'],
  29. 'err_url' => $err_url,
  30. 'sql_query' => $_REQUEST['sql_query'],
  31. );
  32. if (isset($where_clauses)) {
  33. foreach ($where_clause_array as $key_id => $where_clause) {
  34. $_form_params['where_clause[' . $key_id . ']'] = trim($where_clause);
  35. }
  36. }
  37. if (isset($_REQUEST['clause_is_unique'])) {
  38. $_form_params['clause_is_unique'] = $_REQUEST['clause_is_unique'];
  39. }
  40. return $_form_params;
  41. }
  42. /**
  43. * Creates array of where clauses
  44. *
  45. * @param array $where_clause where clause
  46. *
  47. * @return whereClauseArray array of where clauses
  48. */
  49. function PMA_getWhereClauseArray($where_clause)
  50. {
  51. if (isset ($where_clause)) {
  52. if (is_array($where_clause)) {
  53. return $where_clause;
  54. } else {
  55. return array(0 => $where_clause);
  56. }
  57. }
  58. }
  59. /**
  60. * Analysing where clauses array
  61. *
  62. * @param array $where_clause_array array of where clauses
  63. * @param string $table name of the table
  64. * @param string $db name of the database
  65. *
  66. * @return array $where_clauses, $result, $rows
  67. */
  68. function PMA_analyzeWhereClauses(
  69. $where_clause_array, $table, $db
  70. ) {
  71. $rows = array();
  72. $result = array();
  73. $where_clauses = array();
  74. $found_unique_key = false;
  75. foreach ($where_clause_array as $key_id => $where_clause) {
  76. $local_query = 'SELECT * FROM '
  77. . PMA_Util::backquote($db) . '.'
  78. . PMA_Util::backquote($table)
  79. . ' WHERE ' . $where_clause . ';';
  80. $result[$key_id] = PMA_DBI_query($local_query, null, PMA_DBI_QUERY_STORE);
  81. $rows[$key_id] = PMA_DBI_fetch_assoc($result[$key_id]);
  82. $where_clauses[$key_id] = str_replace('\\', '\\\\', $where_clause);
  83. $has_unique_condition = PMA_showEmptyResultMessageOrSetUniqueCondition(
  84. $rows, $key_id, $where_clause_array, $local_query, $result
  85. );
  86. if ($has_unique_condition) {
  87. $found_unique_key = true;
  88. }
  89. }
  90. return array($where_clauses, $result, $rows, $found_unique_key);
  91. }
  92. /**
  93. * Show message for empty reult or set the unique_condition
  94. *
  95. * @param array $rows MySQL returned rows
  96. * @param string $key_id ID in current key
  97. * @param array $where_clause_array array of where clauses
  98. * @param string $local_query query performed
  99. * @param array $result MySQL result handle
  100. *
  101. * @return boolean $has_unique_condition
  102. */
  103. function PMA_showEmptyResultMessageOrSetUniqueCondition($rows, $key_id,
  104. $where_clause_array, $local_query, $result
  105. ) {
  106. $has_unique_condition = false;
  107. // No row returned
  108. if (! $rows[$key_id]) {
  109. unset($rows[$key_id], $where_clause_array[$key_id]);
  110. PMA_Response::getInstance()->addHtml(
  111. PMA_Util::getMessage(
  112. __('MySQL returned an empty result set (i.e. zero rows).'),
  113. $local_query
  114. )
  115. );
  116. /**
  117. * @todo not sure what should be done at this point, but we must not
  118. * exit if we want the message to be displayed
  119. */
  120. } else {// end if (no row returned)
  121. $meta = PMA_DBI_get_fields_meta($result[$key_id]);
  122. list($unique_condition, $tmp_clause_is_unique)
  123. = PMA_Util::getUniqueCondition(
  124. $result[$key_id], count($meta), $meta, $rows[$key_id], true
  125. );
  126. if (! empty($unique_condition)) {
  127. $has_unique_condition = true;
  128. }
  129. unset($unique_condition, $tmp_clause_is_unique);
  130. }
  131. return $has_unique_condition;
  132. }
  133. /**
  134. * No primary key given, just load first row
  135. *
  136. * @param string $table name of the table
  137. * @param string $db name of the database
  138. *
  139. * @return array containing $result and $rows arrays
  140. */
  141. function PMA_loadFirstRow($table, $db)
  142. {
  143. $result = PMA_DBI_query(
  144. 'SELECT * FROM ' . PMA_Util::backquote($db)
  145. . '.' . PMA_Util::backquote($table) . ' LIMIT 1;',
  146. null,
  147. PMA_DBI_QUERY_STORE
  148. );
  149. $rows = array_fill(0, $GLOBALS['cfg']['InsertRows'], false);
  150. return array($result, $rows);
  151. }
  152. /**
  153. * Add some url parameters
  154. *
  155. * @param array $url_params containing $db and $table as url parameters
  156. * @param array $where_clause_array where clauses array
  157. * @param string $where_clause where clause
  158. *
  159. * @return array Add some url parameters to $url_params array and return it
  160. */
  161. function PMA_urlParamsInEditMode($url_params, $where_clause_array, $where_clause)
  162. {
  163. if (isset($where_clause)) {
  164. foreach ($where_clause_array as $where_clause) {
  165. $url_params['where_clause'] = trim($where_clause);
  166. }
  167. }
  168. if (! empty($_REQUEST['sql_query'])) {
  169. $url_params['sql_query'] = $_REQUEST['sql_query'];
  170. }
  171. return $url_params;
  172. }
  173. /**
  174. * Show function fields in data edit view in pma
  175. *
  176. * @param array $url_params containing url parameters
  177. * @param boolean $showFuncFields whether to show function field
  178. *
  179. * @return string an html snippet
  180. */
  181. function PMA_showFunctionFieldsInEditMode($url_params, $showFuncFields)
  182. {
  183. $params = array();
  184. if (! $showFuncFields) {
  185. $params['ShowFunctionFields'] = 1;
  186. } else {
  187. $params['ShowFunctionFields'] = 0;
  188. }
  189. $params['ShowFieldTypesInDataEditView']
  190. = $GLOBALS['cfg']['ShowFieldTypesInDataEditView'];
  191. $params['goto'] = 'sql.php';
  192. $this_url_params = array_merge($url_params, $params);
  193. if (! $showFuncFields) {
  194. return ' : <a href="tbl_change.php'
  195. . PMA_generate_common_url($this_url_params) . '">'
  196. . __('Function')
  197. . '</a>' . "\n";
  198. }
  199. return '<th><a href="tbl_change.php'
  200. . PMA_generate_common_url($this_url_params)
  201. . '" title="' . __('Hide') . '">'
  202. . __('Function')
  203. . '</a></th>' . "\n";
  204. }
  205. /**
  206. * Show field types in data edit view in pma
  207. *
  208. * @param array $url_params containing url parameters
  209. * @param boolean $showColumnType whether to show column type
  210. *
  211. * @return string an html snippet
  212. */
  213. function PMA_showColumnTypesInDataEditView($url_params, $showColumnType)
  214. {
  215. $params = array();
  216. if (! $showColumnType) {
  217. $params['ShowFieldTypesInDataEditView'] = 1;
  218. } else {
  219. $params['ShowFieldTypesInDataEditView'] = 0;
  220. }
  221. $params['ShowFunctionFields'] = $GLOBALS['cfg']['ShowFunctionFields'];
  222. $params['goto'] = 'sql.php';
  223. $this_other_url_params = array_merge($url_params, $params);
  224. if (! $showColumnType) {
  225. return ' : <a href="tbl_change.php'
  226. . PMA_generate_common_url($this_other_url_params) . '">'
  227. . __('Type') . '</a>' . "\n";
  228. }
  229. return '<th><a href="tbl_change.php'
  230. . PMA_generate_common_url($this_other_url_params)
  231. . '" title="' . __('Hide') . '">' . __('Type') . '</a></th>' . "\n";
  232. }
  233. /**
  234. * Retrieve the default for datetime data type
  235. *
  236. * @param array $column containing column type, Default and null
  237. *
  238. * @return nothing
  239. */
  240. function PMA_getDefaultForDatetime($column)
  241. {
  242. // d a t e t i m e
  243. //
  244. // Current date should not be set as default if the field is NULL
  245. // for the current row, but do not put here the current datetime
  246. // if there is a default value (the real default value will be set
  247. // in the Default value logic below)
  248. // Note: (tested in MySQL 4.0.16): when lang is some UTF-8,
  249. // $column['Default'] is not set if it contains NULL:
  250. // Array ([Field] => d [Type] => datetime [Null] => YES [Key] =>
  251. // [Extra] => [True_Type] => datetime)
  252. // but, look what we get if we switch to iso: (Default is NULL)
  253. // Array ([Field] => d [Type] => datetime [Null] => YES [Key] =>
  254. // [Default] => [Extra] => [True_Type] => datetime)
  255. // so I force a NULL into it (I don't think it's possible
  256. // to have an empty default value for DATETIME)
  257. // then, the "if" after this one will work
  258. if ($column['Type'] == 'datetime'
  259. && ! isset($column['Default'])
  260. && isset($column['Null'])
  261. && $column['Null'] == 'YES'
  262. ) {
  263. $column['Default'] = null;
  264. }
  265. }
  266. /**
  267. * Analyze the table column array
  268. *
  269. * @param array $column description of column in given table
  270. * @param array $comments_map comments for every column that has a comment
  271. * @param boolean $timestamp_seen whether a timestamp has been seen
  272. *
  273. * @return array description of column in given table
  274. */
  275. function PMA_analyzeTableColumnsArray($column, $comments_map, $timestamp_seen)
  276. {
  277. $column['Field_html'] = htmlspecialchars($column['Field']);
  278. $column['Field_md5'] = md5($column['Field']);
  279. // True_Type contains only the type (stops at first bracket)
  280. $column['True_Type'] = preg_replace('@\(.*@s', '', $column['Type']);
  281. PMA_getDefaultForDatetime($column);
  282. $column['len'] = preg_match('@float|double@', $column['Type']) ? 100 : -1;
  283. $column['Field_title'] = PMA_getColumnTitle($column, $comments_map);
  284. $column['is_binary'] = PMA_isColumnBinary($column);
  285. $column['is_blob'] = PMA_isColumnBlob($column);
  286. $column['is_char'] = PMA_isColumnChar($column);
  287. list($column['pma_type'], $column['wrap'], $column['first_timestamp'])
  288. = PMA_getEnumSetAndTimestampColumns($column, $timestamp_seen);
  289. return $column;
  290. }
  291. /**
  292. * Retrieve the column title
  293. *
  294. * @param array $column description of column in given table
  295. * @param array $comments_map comments for every column that has a comment
  296. *
  297. * @return string column title
  298. */
  299. function PMA_getColumnTitle($column, $comments_map)
  300. {
  301. if (isset($comments_map[$column['Field']])) {
  302. return '<span style="border-bottom: 1px dashed black;" title="'
  303. . htmlspecialchars($comments_map[$column['Field']]) . '">'
  304. . $column['Field_html'] . '</span>';
  305. } else {
  306. return $column['Field_html'];
  307. }
  308. }
  309. /**
  310. * check whether the column is a bainary
  311. *
  312. * @param array $column description of column in given table
  313. *
  314. * @return boolean If check to ensure types such as "enum('one','two','binary',..)"
  315. * or "enum('one','two','varbinary',..)" are not categorized as
  316. * binary.
  317. */
  318. function PMA_isColumnBinary($column)
  319. {
  320. // The type column.
  321. // Fix for bug #3152931 'ENUM and SET cannot have "Binary" option'
  322. if (stripos($column['Type'], 'binary') === 0
  323. || stripos($column['Type'], 'varbinary') === 0
  324. ) {
  325. return stristr($column['Type'], 'binary');
  326. } else {
  327. return false;
  328. }
  329. }
  330. /**
  331. * check whether the column is a blob
  332. *
  333. * @param array $column description of column in given table
  334. *
  335. * @return boolean If check to ensure types such as "enum('one','two','blob',..)"
  336. * or "enum('one','two','tinyblob',..)" etc. are not categorized
  337. * as blob.
  338. */
  339. function PMA_isColumnBlob($column)
  340. {
  341. if (stripos($column['Type'], 'blob') === 0
  342. || stripos($column['Type'], 'tinyblob') === 0
  343. || stripos($column['Type'], 'mediumblob') === 0
  344. || stripos($column['Type'], 'longblob') === 0
  345. ) {
  346. return stristr($column['Type'], 'blob');
  347. } else {
  348. return false;
  349. }
  350. }
  351. /**
  352. * check is table column char
  353. *
  354. * @param array $column description of column in given table
  355. *
  356. * @return boolean If check to ensure types such as "enum('one','two','char',..)" or
  357. * "enum('one','two','varchar',..)" are not categorized as char.
  358. */
  359. function PMA_isColumnChar($column)
  360. {
  361. if (stripos($column['Type'], 'char') === 0
  362. || stripos($column['Type'], 'varchar') === 0
  363. ) {
  364. return stristr($column['Type'], 'char');
  365. } else {
  366. return false;
  367. }
  368. }
  369. /**
  370. * Retrieve set, enum, timestamp table columns
  371. *
  372. * @param array $column description of column in given table
  373. * @param boolean $timestamp_seen whether a timestamp has been seen
  374. *
  375. * @return array $column['pma_type'], $column['wrap'], $column['first_timestamp']
  376. */
  377. function PMA_getEnumSetAndTimestampColumns($column, $timestamp_seen)
  378. {
  379. $column['first_timestamp'] = false;
  380. switch ($column['True_Type']) {
  381. case 'set':
  382. $column['pma_type'] = 'set';
  383. $column['wrap'] = '';
  384. break;
  385. case 'enum':
  386. $column['pma_type'] = 'enum';
  387. $column['wrap'] = '';
  388. break;
  389. case 'timestamp':
  390. if (! $timestamp_seen) { // can only occur once per table
  391. $timestamp_seen = true;
  392. $column['first_timestamp'] = true;
  393. }
  394. $column['pma_type'] = $column['Type'];
  395. $column['wrap'] = ' nowrap';
  396. break;
  397. default:
  398. $column['pma_type'] = $column['Type'];
  399. $column['wrap'] = ' nowrap';
  400. break;
  401. }
  402. return array($column['pma_type'], $column['wrap'], $column['first_timestamp']);
  403. }
  404. /**
  405. * The function column
  406. * We don't want binary data to be destroyed
  407. * Note: from the MySQL manual: "BINARY doesn't affect how the column is
  408. * stored or retrieved" so it does not mean that the contents is binary
  409. *
  410. * @param array $column description of column in given table
  411. * @param boolean $is_upload upload or no
  412. * @param string $column_name_appendix the name atttibute
  413. * @param string $unnullify_trigger validation string
  414. * @param array $no_support_types list of datatypes that are not (yet)
  415. * handled by PMA
  416. * @param integer $tabindex_for_function +3000
  417. * @param integer $tabindex tab index
  418. * @param integer $idindex id index
  419. * @param boolean $insert_mode insert mode or edit mode
  420. *
  421. * @return string an html sippet
  422. */
  423. function PMA_getFunctionColumn($column, $is_upload, $column_name_appendix,
  424. $unnullify_trigger, $no_support_types, $tabindex_for_function,
  425. $tabindex, $idindex, $insert_mode
  426. ) {
  427. $html_output = '';
  428. if (($GLOBALS['cfg']['ProtectBinary'] && $column['is_blob'] && ! $is_upload)
  429. || ($GLOBALS['cfg']['ProtectBinary'] === 'all' && $column['is_binary'])
  430. || ($GLOBALS['cfg']['ProtectBinary'] === 'noblob' && ! $column['is_blob'])
  431. ) {
  432. $html_output .= '<td class="center">' . __('Binary') . '</td>' . "\n";
  433. } elseif (strstr($column['True_Type'], 'enum')
  434. || strstr($column['True_Type'], 'set')
  435. || in_array($column['pma_type'], $no_support_types)
  436. ) {
  437. $html_output .= '<td class="center">--</td>' . "\n";
  438. } else {
  439. $html_output .= '<td>' . "\n";
  440. $html_output .= '<select name="funcs' . $column_name_appendix . '"'
  441. . ' ' . $unnullify_trigger
  442. . ' tabindex="' . ($tabindex + $tabindex_for_function) . '"'
  443. . ' id="field_' . $idindex . '_1">';
  444. $html_output .= PMA_Util::getFunctionsForField($column, $insert_mode) . "\n";
  445. $html_output .= '</select>' . "\n";
  446. $html_output .= '</td>' . "\n";
  447. }
  448. return $html_output;
  449. }
  450. /**
  451. * The null column
  452. *
  453. * @param array $column description of column in given table
  454. * @param string $column_name_appendix the name atttibute
  455. * @param array $real_null_value is column value null or not null
  456. * @param integer $tabindex tab index
  457. * @param integer $tabindex_for_null +6000
  458. * @param integer $idindex id index
  459. * @param array $vkey [multi_edit]['row_id']
  460. * @param array $foreigners keys into foreign fields
  461. * @param array $foreignData data about the foreign keys
  462. *
  463. * @return string an html snippet
  464. */
  465. function PMA_getNullColumn($column, $column_name_appendix, $real_null_value,
  466. $tabindex, $tabindex_for_null, $idindex, $vkey, $foreigners, $foreignData
  467. ) {
  468. if ($column['Null'] != 'YES') {
  469. return "<td></td>\n";
  470. }
  471. $html_output = '';
  472. $html_output .= '<td>' . "\n";
  473. $html_output .= '<input type="hidden" name="fields_null_prev'
  474. . $column_name_appendix . '"';
  475. if ($real_null_value && !$column['first_timestamp']) {
  476. $html_output .= ' value="on"';
  477. }
  478. $html_output .= ' />' . "\n";
  479. $html_output .= '<input type="checkbox" class="checkbox_null" tabindex="'
  480. . ($tabindex + $tabindex_for_null) . '"'
  481. . ' name="fields_null' . $column_name_appendix . '"';
  482. if ($real_null_value) {
  483. $html_output .= ' checked="checked"';
  484. }
  485. $html_output .= ' id="field_' . ($idindex) . '_2" />';
  486. // nullify_code is needed by the js nullify() function
  487. $nullify_code = PMA_getNullifyCodeForNullColumn(
  488. $column, $foreigners, $foreignData
  489. );
  490. // to be able to generate calls to nullify() in jQuery
  491. $html_output .= '<input type="hidden" class="nullify_code" name="nullify_code'
  492. . $column_name_appendix . '" value="' . $nullify_code . '" />';
  493. $html_output .= '<input type="hidden" class="hashed_field" name="hashed_field'
  494. . $column_name_appendix . '" value="' . $column['Field_md5'] . '" />';
  495. $html_output .= '<input type="hidden" class="multi_edit" name="multi_edit'
  496. . $column_name_appendix . '" value="' . PMA_escapeJsString($vkey) . '" />';
  497. $html_output .= '</td>' . "\n";
  498. return $html_output;
  499. }
  500. /**
  501. * Retrieve the nullify code for the null column
  502. *
  503. * @param array $column description of column in given table
  504. * @param array $foreigners keys into foreign fields
  505. * @param array $foreignData data about the foreign keys
  506. *
  507. * @return integer $nullify_code
  508. */
  509. function PMA_getNullifyCodeForNullColumn($column, $foreigners, $foreignData)
  510. {
  511. if (strstr($column['True_Type'], 'enum')) {
  512. if (strlen($column['Type']) > 20) {
  513. $nullify_code = '1';
  514. } else {
  515. $nullify_code = '2';
  516. }
  517. } elseif (strstr($column['True_Type'], 'set')) {
  518. $nullify_code = '3';
  519. } elseif ($foreigners
  520. && isset($foreigners[$column['Field']])
  521. && $foreignData['foreign_link'] == false
  522. ) {
  523. // foreign key in a drop-down
  524. $nullify_code = '4';
  525. } elseif ($foreigners
  526. && isset($foreigners[$column['Field']])
  527. && $foreignData['foreign_link'] == true
  528. ) {
  529. // foreign key with a browsing icon
  530. $nullify_code = '6';
  531. } else {
  532. $nullify_code = '5';
  533. }
  534. return $nullify_code;
  535. }
  536. /**
  537. * Get the HTML elements for value column in insert form
  538. *
  539. * @param array $column description of column in given table
  540. * @param string $backup_field hidden input field
  541. * @param string $column_name_appendix the name atttibute
  542. * @param string $unnullify_trigger validation string
  543. * @param integer $tabindex tab index
  544. * @param integer $tabindex_for_value offset for the values tabindex
  545. * @param integer $idindex id index
  546. * @param array $data description of the column field
  547. * @param array $special_chars special characters
  548. * @param array $foreignData data about the foreign keys
  549. * @param boolean $odd_row whether row is odd
  550. * @param array $paramTableDbArray array containing $table and $db
  551. * @param array $rownumber_param &amp;rownumber=row_id
  552. * @param array $titles An HTML IMG tag for a particular icon from
  553. * a theme, which may be an actual file or
  554. * an icon from a sprite
  555. * @param array $text_dir text direction
  556. * @param string $special_chars_encoded replaced char if the string starts
  557. * with a \r\n pair (0x0d0a) add an extra \n
  558. * @param string $vkey [multi_edit]['row_id']
  559. * @param boolean $is_upload is upload or not
  560. * @param integer $biggest_max_file_size 0 intger
  561. * @param string $default_char_editing default char editing mode which is stroe
  562. * in the config.inc.php script
  563. * @param array $no_support_types list of datatypes that are not (yet)
  564. * handled by PMA
  565. * @param array $gis_data_types list of GIS data types
  566. * @param array $extracted_columnspec associative array containing type,
  567. * spec_in_brackets and possibly
  568. * enum_set_values (another array)
  569. *
  570. * @return string an html snippet
  571. */
  572. function PMA_getValueColumn($column, $backup_field, $column_name_appendix,
  573. $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex, $data,
  574. $special_chars, $foreignData, $odd_row, $paramTableDbArray, $rownumber_param,
  575. $titles, $text_dir, $special_chars_encoded, $vkey,
  576. $is_upload, $biggest_max_file_size,
  577. $default_char_editing, $no_support_types, $gis_data_types, $extracted_columnspec
  578. ) {
  579. $html_output = '';
  580. if ($foreignData['foreign_link'] == true) {
  581. $html_output .= PMA_getForeignLink(
  582. $column, $backup_field, $column_name_appendix,
  583. $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex, $data,
  584. $paramTableDbArray, $rownumber_param, $titles
  585. );
  586. } elseif (is_array($foreignData['disp_row'])) {
  587. $html_output .= PMA_dispRowForeignData(
  588. $backup_field, $column_name_appendix,
  589. $unnullify_trigger, $tabindex, $tabindex_for_value,
  590. $idindex, $data, $foreignData
  591. );
  592. } elseif ($GLOBALS['cfg']['LongtextDoubleTextarea']
  593. && strstr($column['pma_type'], 'longtext')
  594. ) {
  595. $html_output = '&nbsp;</td>';
  596. $html_output .= '</tr>';
  597. $html_output .= '<tr class="' . ($odd_row ? 'odd' : 'even') . '">'
  598. . '<td colspan="5" class="right">';
  599. $html_output .= PMA_getTextarea(
  600. $column, $backup_field, $column_name_appendix, $unnullify_trigger,
  601. $tabindex, $tabindex_for_value, $idindex, $text_dir,
  602. $special_chars_encoded
  603. );
  604. } elseif (strstr($column['pma_type'], 'text')) {
  605. $html_output .= PMA_getTextarea(
  606. $column, $backup_field, $column_name_appendix, $unnullify_trigger,
  607. $tabindex, $tabindex_for_value, $idindex, $text_dir,
  608. $special_chars_encoded
  609. );
  610. $html_output .= "\n";
  611. if (strlen($special_chars) > 32000) {
  612. $html_output .= "</td>\n";
  613. $html_output .= '<td>' . __(
  614. 'Because of its length,<br /> this column might not be editable'
  615. );
  616. }
  617. } elseif ($column['pma_type'] == 'enum') {
  618. $html_output .= PMA_getPmaTypeEnum(
  619. $column, $backup_field, $column_name_appendix, $extracted_columnspec,
  620. $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex, $data
  621. );
  622. } elseif ($column['pma_type'] == 'set') {
  623. $html_output .= PMA_getPmaTypeSet(
  624. $column, $extracted_columnspec, $backup_field,
  625. $column_name_appendix, $unnullify_trigger, $tabindex,
  626. $tabindex_for_value, $idindex, $data
  627. );
  628. } elseif ($column['is_binary'] || $column['is_blob']) {
  629. $html_output .= PMA_getBinaryAndBlobColumn(
  630. $column, $data, $special_chars, $biggest_max_file_size,
  631. $backup_field, $column_name_appendix, $unnullify_trigger, $tabindex,
  632. $tabindex_for_value, $idindex, $text_dir, $special_chars_encoded,
  633. $vkey, $is_upload
  634. );
  635. } elseif (! in_array($column['pma_type'], $no_support_types)) {
  636. $html_output .= PMA_getNoSupportTypes(
  637. $column, $default_char_editing, $backup_field,
  638. $column_name_appendix, $unnullify_trigger, $tabindex, $special_chars,
  639. $tabindex_for_value, $idindex, $text_dir, $special_chars_encoded,
  640. $data, $extracted_columnspec
  641. );
  642. }
  643. if (in_array($column['pma_type'], $gis_data_types)) {
  644. $html_output .= PMA_getHTMLforGisDataTypes();
  645. }
  646. return $html_output;
  647. }
  648. /**
  649. * Get HTML for foreign link in insert form
  650. *
  651. * @param array $column description of column in given table
  652. * @param string $backup_field hidden input field
  653. * @param string $column_name_appendix the name atttibute
  654. * @param string $unnullify_trigger validation string
  655. * @param integer $tabindex tab index
  656. * @param integer $tabindex_for_value offset for the values tabindex
  657. * @param integer $idindex id index
  658. * @param array $data data to edit
  659. * @param array $paramTableDbArray array containing $table and $db
  660. * @param array $rownumber_param &amp;rownumber=row_id
  661. * @param array $titles An HTML IMG tag for a particular icon from
  662. * a theme, which may be an actual file or
  663. * an icon from a sprite
  664. *
  665. * @return string an html snippet
  666. */
  667. function PMA_getForeignLink($column, $backup_field, $column_name_appendix,
  668. $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex, $data,
  669. $paramTableDbArray, $rownumber_param, $titles
  670. ) {
  671. list($table, $db) = $paramTableDbArray;
  672. $html_output = '';
  673. $html_output .= $backup_field . "\n";
  674. $html_output .= '<input type="hidden" name="fields_type'
  675. . $column_name_appendix . '" value="foreign" />';
  676. $html_output .= '<input type="text" name="fields' . $column_name_appendix . '" '
  677. . 'class="textfield" '
  678. . $unnullify_trigger . ' '
  679. . 'tabindex="' . ($tabindex + $tabindex_for_value) . '" '
  680. . 'id="field_' . ($idindex) . '_3" '
  681. . 'value="' . htmlspecialchars($data) . '" />';
  682. $html_output .= '<a class="foreign_values_anchor" target="_blank" '
  683. . 'onclick="window.open(this.href,\'foreigners\', \'width=640,height=240,'
  684. . 'scrollbars=yes,resizable=yes\'); return false;" '
  685. . 'href="browse_foreigners.php?'
  686. . PMA_generate_common_url($db, $table) . '&amp;field='
  687. . PMA_escapeJsString(urlencode($column['Field']) . $rownumber_param) . '">'
  688. . str_replace("'", "\'", $titles['Browse']) . '</a>';
  689. return $html_output;
  690. }
  691. /**
  692. * Get HTML to display foreign data
  693. *
  694. * @param string $backup_field hidden input field
  695. * @param string $column_name_appendix the name atttibute
  696. * @param string $unnullify_trigger validation string
  697. * @param integer $tabindex tab index
  698. * @param integer $tabindex_for_value offset for the values tabindex
  699. * @param integer $idindex id index
  700. * @param array $data data to edit
  701. * @param array $foreignData data about the foreign keys
  702. *
  703. * @return string an html snippet
  704. */
  705. function PMA_dispRowForeignData($backup_field, $column_name_appendix,
  706. $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex, $data,
  707. $foreignData
  708. ) {
  709. $html_output = '';
  710. $html_output .= $backup_field . "\n";
  711. $html_output .= '<input type="hidden"'
  712. . ' name="fields_type' . $column_name_appendix . '"'
  713. . ' value="foreign" />';
  714. $html_output .= '<select name="fields' . $column_name_appendix . '"'
  715. . ' ' . $unnullify_trigger
  716. . ' class="textfield"'
  717. . ' tabindex="' . ($tabindex + $tabindex_for_value). '"'
  718. . ' id="field_' . $idindex . '_3">';
  719. $html_output .= PMA_foreignDropdown(
  720. $foreignData['disp_row'], $foreignData['foreign_field'],
  721. $foreignData['foreign_display'], $data,
  722. $GLOBALS['cfg']['ForeignKeyMaxLimit']
  723. );
  724. $html_output .= '</select>';
  725. return $html_output;
  726. }
  727. /**
  728. * Get HTML textarea for insert form
  729. *
  730. * @param array $column column information
  731. * @param string $backup_field hidden input field
  732. * @param string $column_name_appendix the name atttibute
  733. * @param string $unnullify_trigger validation string
  734. * @param integer $tabindex tab index
  735. * @param integer $tabindex_for_value offset for the values tabindex
  736. * @param integer $idindex id index
  737. * @param array $text_dir text direction
  738. * @param array $special_chars_encoded replaced char if the string starts
  739. * with a \r\n pair (0x0d0a) add an extra \n
  740. *
  741. * @return string an html snippet
  742. */
  743. function PMA_getTextarea($column, $backup_field, $column_name_appendix,
  744. $unnullify_trigger,
  745. $tabindex, $tabindex_for_value, $idindex, $text_dir, $special_chars_encoded
  746. ) {
  747. $the_class = '';
  748. $textAreaRows = $GLOBALS['cfg']['TextareaRows'];
  749. $textareaCols = $GLOBALS['cfg']['TextareaCols'];
  750. if ($column['is_char']) {
  751. $the_class = 'char';
  752. $textAreaRows = $GLOBALS['cfg']['CharTextareaRows'];
  753. $textareaCols = $GLOBALS['cfg']['CharTextareaCols'];
  754. } elseif ($GLOBALS['cfg']['LongtextDoubleTextarea']
  755. && strstr($column['pma_type'], 'longtext')
  756. ) {
  757. $textAreaRows = $GLOBALS['cfg']['TextareaRows'] * 2;
  758. $textareaCols = $GLOBALS['cfg']['TextareaCols'] * 2;
  759. }
  760. $html_output = $backup_field . "\n"
  761. . '<textarea name="fields' . $column_name_appendix . '"'
  762. . ' class="' . $the_class . '"'
  763. . ' rows="' . $textAreaRows . '"'
  764. . ' cols="' . $textareaCols . '"'
  765. . ' dir="' . $text_dir . '"'
  766. . ' id="field_' . ($idindex) . '_3"'
  767. . ' ' . $unnullify_trigger
  768. . ' tabindex="' . ($tabindex + $tabindex_for_value) . '">'
  769. . $special_chars_encoded
  770. . '</textarea>';
  771. return $html_output;
  772. }
  773. /**
  774. * Get HTML for enum type
  775. *
  776. * @param type $column description of column in given table
  777. * @param type $backup_field hidden input field
  778. * @param type $column_name_appendix the name atttibute
  779. * @param type $extracted_columnspec associative array containing type,
  780. * spec_in_brackets and possibly
  781. * enum_set_values (another array)
  782. * @param type $unnullify_trigger validation string
  783. * @param type $tabindex tab index
  784. * @param type $tabindex_for_value offset for the values tabindex
  785. * @param type $idindex id index
  786. * @param type $data data to edit
  787. *
  788. * @return type string an html snippet
  789. */
  790. function PMA_getPmaTypeEnum($column, $backup_field, $column_name_appendix,
  791. $extracted_columnspec, $unnullify_trigger, $tabindex, $tabindex_for_value,
  792. $idindex, $data
  793. ) {
  794. $html_output = '';
  795. if (! isset($column['values'])) {
  796. $column['values'] = PMA_getColumnEnumValues(
  797. $column, $extracted_columnspec
  798. );
  799. }
  800. $column_enum_values = $column['values'];
  801. $html_output .= '<input type="hidden" name="fields_type'
  802. . $column_name_appendix. '" value="enum" />';
  803. $html_output .= '<input type="hidden" name="fields'
  804. . $column_name_appendix . '" value="" />';
  805. $html_output .= "\n" . ' ' . $backup_field . "\n";
  806. if (strlen($column['Type']) > 20) {
  807. $html_output .= PMA_getDropDownDependingOnLength(
  808. $column, $column_name_appendix, $unnullify_trigger,
  809. $tabindex, $tabindex_for_value, $idindex, $data, $column_enum_values
  810. );
  811. } else {
  812. $html_output .= PMA_getRadioButtonDependingOnLength(
  813. $column_name_appendix, $unnullify_trigger,
  814. $tabindex, $column, $tabindex_for_value,
  815. $idindex, $data, $column_enum_values
  816. );
  817. }
  818. return $html_output;
  819. }
  820. /**
  821. * Get column values
  822. *
  823. * @param array $column description of column in given table
  824. * @param array $extracted_columnspec associative array containing type,
  825. * spec_in_brackets and possibly enum_set_values
  826. * (another array)
  827. *
  828. * @return array column values as an associative array
  829. */
  830. function PMA_getColumnEnumValues($column, $extracted_columnspec)
  831. {
  832. $column['values'] = array();
  833. foreach ($extracted_columnspec['enum_set_values'] as $val) {
  834. $column['values'][] = array(
  835. 'plain' => $val,
  836. 'html' => htmlspecialchars($val),
  837. );
  838. }
  839. return $column['values'];
  840. }
  841. /**
  842. * Get HTML drop down for more than 20 string length
  843. *
  844. * @param array $column description of column in given table
  845. * @param string $column_name_appendix the name atttibute
  846. * @param string $unnullify_trigger validation string
  847. * @param integer $tabindex tab index
  848. * @param integer $tabindex_for_value offset for the values tabindex
  849. * @param integer $idindex id index
  850. * @param array $data data to edit
  851. * @param array $column_enum_values $column['values']
  852. *
  853. * @return string an html snippet
  854. */
  855. function PMA_getDropDownDependingOnLength(
  856. $column, $column_name_appendix, $unnullify_trigger,
  857. $tabindex, $tabindex_for_value, $idindex, $data, $column_enum_values
  858. ) {
  859. $html_output = '<select name="fields' . $column_name_appendix . '"'
  860. . ' ' . $unnullify_trigger
  861. . ' class="textfield"'
  862. . ' tabindex="' . ($tabindex + $tabindex_for_value) . '"'
  863. . ' id="field_' . ($idindex) . '_3">';
  864. $html_output .= '<option value="">&nbsp;</option>' . "\n";
  865. foreach ($column_enum_values as $enum_value) {
  866. $html_output .= '<option value="' . $enum_value['html'] . '"';
  867. if ($data == $enum_value['plain']
  868. || ($data == ''
  869. && (! isset($_REQUEST['where_clause']) || $column['Null'] != 'YES')
  870. && isset($column['Default'])
  871. && $enum_value['plain'] == $column['Default'])
  872. ) {
  873. $html_output .= ' selected="selected"';
  874. }
  875. $html_output .= '>' . $enum_value['html'] . '</option>' . "\n";
  876. }
  877. $html_output .= '</select>';
  878. return $html_output;
  879. }
  880. /**
  881. * Get HTML radio button for less than 20 string length
  882. *
  883. * @param string $column_name_appendix the name atttibute
  884. * @param string $unnullify_trigger validation string
  885. * @param integer $tabindex tab index
  886. * @param array $column description of column in given table
  887. * @param integer $tabindex_for_value offset for the values tabindex
  888. * @param integer $idindex id index
  889. * @param array $data data to edit
  890. * @param array $column_enum_values $column['values']
  891. *
  892. * @return string an html snippet
  893. */
  894. function PMA_getRadioButtonDependingOnLength(
  895. $column_name_appendix, $unnullify_trigger,
  896. $tabindex, $column, $tabindex_for_value, $idindex, $data, $column_enum_values
  897. ) {
  898. $j = 0;
  899. $html_output = '';
  900. foreach ($column_enum_values as $enum_value) {
  901. $html_output .= ' '
  902. . '<input type="radio" name="fields' . $column_name_appendix . '"'
  903. . ' class="textfield"'
  904. . ' value="' . $enum_value['html'] . '"'
  905. . ' id="field_' . ($idindex) . '_3_' . $j . '"'
  906. . ' ' . $unnullify_trigger;
  907. if ($data == $enum_value['plain']
  908. || ($data == ''
  909. && (! isset($_REQUEST['where_clause']) || $column['Null'] != 'YES')
  910. && isset($column['Default'])
  911. && $enum_value['plain'] == $column['Default'])
  912. ) {
  913. $html_output .= ' checked="checked"';
  914. }
  915. $html_output .= ' tabindex="' . ($tabindex + $tabindex_for_value) . '" />';
  916. $html_output .= '<label for="field_' . $idindex . '_3_' . $j . '">'
  917. . $enum_value['html'] . '</label>' . "\n";
  918. $j++;
  919. }
  920. return $html_output;
  921. }
  922. /**
  923. * Get the HTML for 'set' pma type
  924. *
  925. * @param array $column description of column in given table
  926. * @param array $extracted_columnspec associative array containing type,
  927. * spec_in_brackets and possibly
  928. * enum_set_values (another array)
  929. * @param string $backup_field hidden input field
  930. * @param string $column_name_appendix the name atttibute
  931. * @param string $unnullify_trigger validation string
  932. * @param integer $tabindex tab index
  933. * @param integer $tabindex_for_value offset for the values tabindex
  934. * @param integer $idindex id index
  935. * @param array $data description of the column field
  936. *
  937. * @return string an html snippet
  938. */
  939. function PMA_getPmaTypeSet(
  940. $column, $extracted_columnspec, $backup_field,
  941. $column_name_appendix, $unnullify_trigger, $tabindex,
  942. $tabindex_for_value, $idindex, $data
  943. ) {
  944. list($column_set_values, $select_size) = PMA_getColumnSetValueAndSelectSize(
  945. $column, $extracted_columnspec
  946. );
  947. $vset = array_flip(explode(',', $data));
  948. $html_output = $backup_field . "\n";
  949. $html_output .= '<input type="hidden" name="fields_type'
  950. . $column_name_appendix . '" value="set" />';
  951. $html_output .= '<select name="fields' . $column_name_appendix . '[]' . '"'
  952. . ' class="textfield"'
  953. . ' size="' . $select_size . '"'
  954. . ' multiple="multiple"'
  955. . ' ' . $unnullify_trigger
  956. . ' tabindex="' . ($tabindex + $tabindex_for_value) . '"'
  957. . ' id="field_' . ($idindex) . '_3">';
  958. foreach ($column_set_values as $column_set_value) {
  959. $html_output .= '<option value="' . $column_set_value['html'] . '"';
  960. if (isset($vset[$column_set_value['plain']])) {
  961. $html_output .= ' selected="selected"';
  962. }
  963. $html_output .= '>' . $column_set_value['html'] . '</option>' . "\n";
  964. }
  965. $html_output .= '</select>';
  966. return $html_output;
  967. }
  968. /**
  969. * Retrieve column 'set' value and select size
  970. *
  971. * @param array $column description of column in given table
  972. * @param array $extracted_columnspec associative array containing type,
  973. * spec_in_brackets and possibly enum_set_values
  974. * (another array)
  975. *
  976. * @return array $column['values'], $column['select_size']
  977. */
  978. function PMA_getColumnSetValueAndSelectSize($column, $extracted_columnspec)
  979. {
  980. if (! isset($column['values'])) {
  981. $column['values'] = array();
  982. foreach ($extracted_columnspec['enum_set_values'] as $val) {
  983. $column['values'][] = array(
  984. 'plain' => $val,
  985. 'html' => htmlspecialchars($val),
  986. );
  987. }
  988. $column['select_size'] = min(4, count($column['values']));
  989. }
  990. return array($column['values'], $column['select_size']);
  991. }
  992. /**
  993. * Get HTML for binary and blob column
  994. *
  995. * @param array $column description of column in given table
  996. * @param array $data data to edit
  997. * @param array $special_chars special characters
  998. * @param integer $biggest_max_file_size biggest max file size for uploading
  999. * @param string $backup_field hidden input field
  1000. * @param string $column_name_appendix the name atttibute
  1001. * @param string $unnullify_trigger validation string
  1002. * @param integer $tabindex tab index
  1003. * @param integer $tabindex_for_value offset for the values tabindex
  1004. * @param integer $idindex id index
  1005. * @param string $text_dir text direction
  1006. * @param string $special_chars_encoded replaced char if the string starts
  1007. * with a \r\n pair (0x0d0a) add an extra \n
  1008. * @param string $vkey [multi_edit]['row_id']
  1009. * @param boolean $is_upload is upload or not
  1010. *
  1011. * @return string an html snippet
  1012. */
  1013. function PMA_getBinaryAndBlobColumn(
  1014. $column, $data, $special_chars, $biggest_max_file_size,
  1015. $backup_field, $column_name_appendix, $unnullify_trigger, $tabindex,
  1016. $tabindex_for_value, $idindex, $text_dir, $special_chars_encoded,
  1017. $vkey, $is_upload
  1018. ) {
  1019. $html_output = '';
  1020. if (($GLOBALS['cfg']['ProtectBinary'] && $column['is_blob'])
  1021. || ($GLOBALS['cfg']['ProtectBinary'] == 'all' && $column['is_binary'])
  1022. || ($GLOBALS['cfg']['ProtectBinary'] == 'noblob' && !$column['is_blob'])
  1023. ) {
  1024. $html_output .= __('Binary - do not edit');
  1025. if (isset($data)) {
  1026. $data_size = PMA_Util::formatByteDown(
  1027. strlen(stripslashes($data)), 3, 1
  1028. );
  1029. $html_output .= ' ('. $data_size [0] . ' ' . $data_size[1] . ')';
  1030. unset($data_size);
  1031. }
  1032. $html_output .= '<input type="hidden" name="fields_type'
  1033. . $column_name_appendix . '" value="protected" />'
  1034. . '<input type="hidden" name="fields'
  1035. . $column_name_appendix . '" value="" />';
  1036. } elseif ($column['is_blob']) {
  1037. $html_output .= "\n" . PMA_getTextarea(
  1038. $column, $backup_field, $column_name_appendix, $unnullify_trigger,
  1039. $tabindex, $tabindex_for_value, $idindex, $text_dir,
  1040. $special_chars_encoded
  1041. );
  1042. } else {
  1043. // field size should be at least 4 and max $GLOBALS['cfg']['LimitChars']
  1044. $fieldsize = min(max($column['len'], 4), $GLOBALS['cfg']['LimitChars']);
  1045. $html_output .= "\n" . $backup_field . "\n" . PMA_getHTMLinput(
  1046. $column, $column_name_appendix, $special_chars, $fieldsize,
  1047. $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex
  1048. );
  1049. }
  1050. if ($is_upload && $column['is_blob']) {
  1051. $html_output .= '<br />'
  1052. . '<input type="file"'
  1053. . ' name="fields_upload' . $vkey . '[' . $column['Field_md5'] . ']"'
  1054. . ' class="textfield" id="field_' . $idindex . '_3" size="10"'
  1055. . ' ' . $unnullify_trigger . '/>&nbsp;';
  1056. list($html_out, $biggest_max_file_size) = PMA_getMaxUploadSize(
  1057. $column, $biggest_max_file_size
  1058. );
  1059. $html_output .= $html_out;
  1060. }
  1061. if (!empty($GLOBALS['cfg']['UploadDir'])) {
  1062. $html_output .= PMA_getSelectOptionForUpload($vkey, $column);
  1063. }
  1064. return $html_output;
  1065. }
  1066. /**
  1067. * Get HTML input type
  1068. *
  1069. * @param array $column description of column in given table
  1070. * @param string $column_name_appendix the name atttibute
  1071. * @param array $special_chars special characters
  1072. * @param integer $fieldsize html field size
  1073. * @param string $unnullify_trigger validation string
  1074. * @param integer $tabindex tab index
  1075. * @param integer $tabindex_for_value offset for the values tabindex
  1076. * @param integer $idindex id index
  1077. *
  1078. * @return string an html snippet
  1079. */
  1080. function PMA_getHTMLinput($column, $column_name_appendix, $special_chars,
  1081. $fieldsize, $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex
  1082. ) {
  1083. $the_class = 'textfield';
  1084. if ($column['pma_type'] == 'date') {
  1085. $the_class .= ' datefield';
  1086. } elseif ($column['pma_type'] == 'datetime'
  1087. || substr($column['pma_type'], 0, 9) == 'timestamp'
  1088. ) {
  1089. $the_class .= ' datetimefield';
  1090. }
  1091. return '<input type="text" name="fields' . $column_name_appendix . '"'
  1092. . ' value="' . $special_chars . '" size="' . $fieldsize . '"'
  1093. . ' class="' . $the_class . '" ' . $unnullify_trigger
  1094. . ' tabindex="' . ($tabindex + $tabindex_for_value). '"'
  1095. . ' id="field_' . ($idindex) . '_3" />';
  1096. }
  1097. /**
  1098. * Get HTML select option for upload
  1099. *
  1100. * @param string $vkey [multi_edit]['row_id']
  1101. * @param array $column description of column in given table
  1102. *
  1103. * @return string an html snippet
  1104. */
  1105. function PMA_getSelectOptionForUpload($vkey, $column)
  1106. {
  1107. $files = PMA_getFileSelectOptions(
  1108. PMA_Util::userDir($GLOBALS['cfg']['UploadDir'])
  1109. );
  1110. if ($files === false) {
  1111. return '<font color="red">' . __('Error') . '</font><br />' . "\n"
  1112. . __('The directory you set for upload work cannot be reached') . "\n";
  1113. } elseif (!empty($files)) {
  1114. return "<br />\n"
  1115. . '<i>' . __('Or') . '</i>' . ' '
  1116. . __('web server upload directory') . ':<br />' . "\n"
  1117. . '<select size="1" name="fields_uploadlocal'
  1118. . $vkey . '[' . $column['Field_md5'] . ']">' . "\n"
  1119. . '<option value="" selected="selected"></option>' . "\n"
  1120. . $files
  1121. . '</select>' . "\n";
  1122. }
  1123. }
  1124. /**
  1125. * Retrieve the maximum upload file size
  1126. *
  1127. * @param array $column description of column in given table
  1128. * @param integer $biggest_max_file_size biggest max file size for uploading
  1129. *
  1130. * @return array an html snippet and $biggest_max_file_size
  1131. */
  1132. function PMA_getMaxUploadSize($column, $biggest_max_file_size)
  1133. {
  1134. // find maximum upload size, based on field type
  1135. /**
  1136. * @todo with functions this is not so easy, as you can basically
  1137. * process any data with function like MD5
  1138. */
  1139. global $max_upload_size;
  1140. $max_field_sizes = array(
  1141. 'tinyblob' => '256',
  1142. 'blob' => '65536',
  1143. 'mediumblob' => '16777216',
  1144. 'longblob' => '4294967296' // yeah, really
  1145. );
  1146. $this_field_max_size = $max_upload_size; // from PHP max
  1147. if ($this_field_max_size > $max_field_sizes[$column['pma_type']]) {
  1148. $this_field_max_size = $max_field_sizes[$column['pma_type']];
  1149. }
  1150. $html_output
  1151. = PMA_Util::getFormattedMaximumUploadSize(
  1152. $this_field_max_size
  1153. ) . "\n";
  1154. // do not generate here the MAX_FILE_SIZE, because we should
  1155. // put only one in the form to accommodate the biggest field
  1156. if ($this_field_max_size > $biggest_max_file_size) {
  1157. $biggest_max_file_size = $this_field_max_size;
  1158. }
  1159. return array($html_output, $biggest_max_file_size);
  1160. }
  1161. /**
  1162. * Get HTML for pma no support types
  1163. *
  1164. * @param array $column description of column in given table
  1165. * @param string $default_char_editing default char editing mode which is stroe
  1166. * in the config.inc.php script
  1167. * @param string $backup_field hidden input field
  1168. * @param string $column_name_appendix the name atttibute
  1169. * @param string $unnullify_trigger validation string
  1170. * @param integer $tabindex tab index
  1171. * @param array $special_chars apecial characters
  1172. * @param integer $tabindex_for_value offset for the values tabindex
  1173. * @param integer $idindex id index
  1174. * @param string $text_dir text direction
  1175. * @param array $special_chars_encoded replaced char if the string starts
  1176. * with a \r\n pair (0x0d0a) add an extra \n
  1177. * @param strign $data data to edit
  1178. * @param array $extracted_columnspec associative array containing type,
  1179. * spec_in_brackets and possibly
  1180. * enum_set_values (another array)
  1181. *
  1182. * @return string an html snippet
  1183. */
  1184. function PMA_getNoSupportTypes($column, $default_char_editing, $backup_field,
  1185. $column_name_appendix, $unnullify_trigger, $tabindex, $special_chars,
  1186. $tabindex_for_value, $idindex, $text_dir, $special_chars_encoded, $data,
  1187. $extracted_columnspec
  1188. ) {
  1189. $fieldsize = PMA_getColumnSize($column, $extracted_columnspec);
  1190. $html_output = $backup_field . "\n";
  1191. if ($column['is_char']
  1192. && ($GLOBALS['cfg']['CharEditing'] == 'textarea'
  1193. || strpos($data, "\n") !== false)
  1194. ) {
  1195. $html_output .= "\n";
  1196. $GLOBALS['cfg']['CharEditing'] = $default_char_editing;
  1197. $html_output .= PMA_getTextarea(
  1198. $column, $backup_field, $column_name_appendix, $unnullify_trigger,
  1199. $tabindex, $tabindex_for_value, $idindex, $text_dir,
  1200. $special_chars_encoded
  1201. );
  1202. } else {
  1203. $html_output .= PMA_getHTMLinput(
  1204. $column, $column_name_appendix, $special_chars,
  1205. $fieldsize, $unnullify_trigger, $tabindex, $tabindex_for_value, $idindex
  1206. );
  1207. if ($column['Extra'] == 'auto_increment') {
  1208. $html_output .= '<input type="hidden" name="auto_increment'
  1209. . $column_name_appendix . '" value="1" />';
  1210. }
  1211. if (substr($column['pma_type'], 0, 9) == 'timestamp') {
  1212. $html_output .= '<input type="hidden" name="fields_type'
  1213. . $column_name_appendix . '" value="timestamp" />';
  1214. }
  1215. if (substr($column['pma_type'], 0, 8) == 'datetime') {
  1216. $html_output .= '<input type="hidden" name="fields_type'
  1217. . $column_name_appendix . '" value="datetime" />';
  1218. }
  1219. if ($column['True_Type'] == 'bit') {
  1220. $html_output .= '<input type="hidden" name="fields_type'
  1221. . $column_name_appendix . '" value="bit" />';
  1222. }
  1223. if ($column['pma_type'] == 'date'
  1224. || $column['pma_type'] == 'datetime'
  1225. || substr($column['pma_type'], 0, 9) == 'timestamp'
  1226. ) {
  1227. // the _3 suffix points to the date field
  1228. // the _2 suffix points to the corresponding NULL checkbox
  1229. // in dateFormat, 'yy' means the year with 4 digits
  1230. }
  1231. }
  1232. return $html_output;
  1233. }
  1234. /**
  1235. * Get the field size
  1236. *
  1237. * @param array $column description of column in given table
  1238. * @param array $extracted_columnspec associative array containing type,
  1239. * spec_in_brackets and possibly enum_set_values
  1240. * (another array)
  1241. *
  1242. * @return integer field size
  1243. */
  1244. function PMA_getColumnSize($column, $extracted_columnspec)
  1245. {
  1246. if ($column['is_char']) {
  1247. $fieldsize = $extracted_columnspec['spec_in_brackets'];
  1248. if ($fieldsize > $GLOBALS['cfg']['MaxSizeForInputField']) {
  1249. /**
  1250. * This case happens for CHAR or VARCHAR columns which have
  1251. * a size larger than the maximum size for input field.
  1252. */
  1253. $GLOBALS['cfg']['CharEditing'] = 'textarea';
  1254. }
  1255. } else {
  1256. /**
  1257. * This case happens for example for INT or DATE columns;
  1258. * in these situations, the value returned in $column['len']
  1259. * seems appropriate.
  1260. */
  1261. $fieldsize = $column['len'];
  1262. }
  1263. return min(
  1264. max($fieldsize, $GLOBALS['cfg']['MinSizeForInputField']),
  1265. $GLOBALS['cfg']['MaxSizeForInputField']
  1266. );
  1267. }
  1268. /**
  1269. * Get HTML for gis data types
  1270. *
  1271. * @return string an html snippet
  1272. */
  1273. function PMA_getHTMLforGisDataTypes()
  1274. {
  1275. $edit_str = PMA_Util::getIcon('b_edit.png', __('Edit/Insert'));
  1276. return '<span class="open_gis_editor">'
  1277. . PMA_Util::linkOrButton(
  1278. '#', $edit_str, array(), false, false, '_blank'
  1279. )
  1280. . '</span>';
  1281. }
  1282. /**
  1283. * get html for continue insertion form
  1284. *
  1285. * @param string $table name of the table
  1286. * @param string $db name of the database
  1287. * @param array $where_clause_array array of where clauses
  1288. * @param string $err_url error url
  1289. *
  1290. * @return string an html snippet
  1291. */
  1292. function PMA_getContinueInsertionForm($table, $db, $where_clause_array, $err_url)
  1293. {
  1294. $html_output = '<form id="continueForm" method="post"'
  1295. . ' action="tbl_replace.php" name="continueForm">'
  1296. . PMA_generate_common_hidden_inputs($db, $table)
  1297. . '<input type="hidden" name="goto"'
  1298. . ' value="' . htmlspecialchars($GLOBALS['goto']) . '" />'
  1299. . '<input type="hidden" name="err_url"'
  1300. . ' value="' . htmlspecialchars($err_url) . '" />'
  1301. . '<input type="hidden" name="sql_query"'
  1302. . ' value="' . htmlspecialchars($_REQUEST['sql_query']) . '" />';
  1303. if (isset($_REQUEST['where_clause'])) {
  1304. foreach ($where_clause_array as $key_id => $where_clause) {
  1305. $html_output .= '<input type="hidden"'
  1306. . ' name="where_clause[' . $key_id . ']"'
  1307. . ' value="' . htmlspecialchars(trim($where_clause)) . '" />'. "\n";
  1308. }
  1309. }
  1310. $tmp = '<select name="insert_rows" id="insert_rows">' . "\n";
  1311. $option_values = array(1, 2, 5, 10, 15, 20, 30, 40);
  1312. foreach ($option_values as $value) {
  1313. $tmp .= '<option value="' . $value . '"';
  1314. if ($value == $GLOBALS['cfg']['InsertRows']) {
  1315. $tmp .= ' selected="selected"';
  1316. }
  1317. $tmp .= '>' . $value . '</option>' . "\n";
  1318. }
  1319. $tmp .= '</select>' . "\n";
  1320. $html_output .= "\n" . sprintf(__('Continue insertion with %s rows'), $tmp);
  1321. unset($tmp);
  1322. $html_output .= '</form>' . "\n";
  1323. return $html_output;
  1324. }
  1325. /**
  1326. * Get action panel
  1327. *
  1328. * @param array $where_clause where clause
  1329. * @param string $after_insert insert mode, e.g. new_insert, same_insert
  1330. * @param integer $tabindex tab index
  1331. * @param integer $tabindex_for_value offset for the values tabindex
  1332. * @param boolean $found_unique_key boolean variable for unique key
  1333. *
  1334. * @return string an html snippet
  1335. */
  1336. function PMA_getActionsPanel($where_clause, $after_insert, $tabindex,
  1337. $tabindex_for_value, $found_unique_key
  1338. ) {
  1339. $html_output = '<fieldset id="actions_panel">'
  1340. . '<table cellpadding="5" cellspacing="0">'
  1341. . '<tr>'
  1342. . '<td class="nowrap vmiddle">'
  1343. . PMA_getSubmitTypeDropDown($where_clause, $tabindex, $tabindex_for_value)
  1344. . "\n";
  1345. $html_output .= '</td>'
  1346. . '<td class="vmiddle">'
  1347. . '&nbsp;&nbsp;&nbsp;<strong>'
  1348. . __('and then') . '</strong>&nbsp;&nbsp;&nbsp;'
  1349. . '</td>'
  1350. . '<td class="nowrap vmiddle">'
  1351. . PMA_getAfterInsertDropDown(
  1352. $where_clause, $after_insert, $found_unique_key
  1353. )
  1354. . '</td>'
  1355. . '</tr>';
  1356. $html_output .='<tr>'
  1357. . PMA_getSumbitAndResetButtonForActionsPanel($tabindex, $tabindex_for_value)
  1358. . '</tr>'
  1359. . '</table>'
  1360. . '</fieldset>';
  1361. return $html_output;
  1362. }
  1363. /**
  1364. * Get a HTML drop down for submit types
  1365. *
  1366. * @param array $where_clause where clause
  1367. * @param integer $tabindex tab index
  1368. * @param integer $tabindex_for_value offset for the values tabindex
  1369. *
  1370. * @return string an html snippet
  1371. */
  1372. function PMA_getSubmitTypeDropDown($where_clause, $tabindex, $tabindex_for_value)
  1373. {
  1374. $html_output = '<select name="submit_type" class="control_at_footer" tabindex="'
  1375. . ($tabindex + $tabindex_for_value + 1) . '">';
  1376. if (isset($where_clause)) {
  1377. $html_output .= '<option value="save">' . __('Save') . '</option>';
  1378. }
  1379. $html_output .= '<option value="insert">'
  1380. . __('Insert as new row')
  1381. . '</option>'
  1382. . '<option value="insertignore">'
  1383. . __('Insert as new row and ignore errors')
  1384. . '</option>'
  1385. . '<option value="showinsert">'
  1386. . __('Show insert query')
  1387. . '</option>'
  1388. . '</select>';
  1389. return $html_output;
  1390. }
  1391. /**
  1392. * Get HTML drop down for after insert
  1393. *
  1394. * @param array $where_clause where clause
  1395. * @param string $after_insert insert mode, e.g. new_insert, same_insert
  1396. * @param boolean $found_unique_key boolean variable for unique key
  1397. *
  1398. * @return string an html snippet
  1399. */
  1400. function PMA_getAfterInsertDropDown($where_clause, $after_insert, $found_unique_key)
  1401. {
  1402. $html_output = '<select name="after_insert" class="control_at_footer">'
  1403. . '<option value="back" '
  1404. . ($after_insert == 'back' ? 'selected="selected"' : '') . '>'
  1405. . __('Go back to previous page') . '</option>'
  1406. . '<option value="new_insert" '
  1407. . ($after_insert == 'new_insert' ? 'selected="selected"' : '') . '>'
  1408. . __('Insert another new row') . '</option>';
  1409. if (isset($where_clause)) {
  1410. $html_output .= '<option value="same_insert" '
  1411. . ($after_insert == 'same_insert' ? 'selected="selected"' : '') . '>'
  1412. . __('Go back to this page') . '</option>';
  1413. // If we have just numeric primary key, we can also edit next
  1414. // in 2.8.2, we were looking for `field_name` = numeric_value
  1415. //if (preg_match('@^[\s]*`[^`]*` = [0-9]+@', $where_clause)) {
  1416. // in 2.9.0, we are looking for `table_name`.`field_name` = numeric_value
  1417. $is_numeric = false;
  1418. if (! is_array($where_clause)) {
  1419. $where_clause = array($where_clause);
  1420. }
  1421. for ($i = 0; $i < count($where_clause); $i++) {
  1422. $is_numeric = preg_match(
  1423. '@^[\s]*`[^`]*`[\.]`[^`]*` = [0-9]+@',
  1424. $where_clause[$i]
  1425. );
  1426. if ($is_numeric == true) {
  1427. break;
  1428. }
  1429. }
  1430. if ($found_unique_key && $is_numeric) {
  1431. $html_output .= '<option value="edit_next" '
  1432. . ($after_insert == 'edit_next' ? 'selected="selected"' : '') . '>'
  1433. . __('Edit next row') . '</option>';
  1434. }
  1435. }
  1436. $html_output .= '</select>';
  1437. return $html_output;
  1438. }
  1439. /**
  1440. * get Submit button and Reset button for action panel
  1441. *
  1442. * @param integer $tabindex tab index
  1443. * @param integer $tabindex_for_value offset for the values tabindex
  1444. *
  1445. * @return string an html snippet
  1446. */
  1447. function PMA_getSumbitAndResetButtonForActionsPanel($tabindex, $tabindex_for_value)
  1448. {
  1449. return '<td>'
  1450. . PMA_Util::showHint(
  1451. __(
  1452. 'Use TAB key to move from value to value,'
  1453. . ' or CTRL+arrows to move anywhere'
  1454. )
  1455. )
  1456. . '</td>'
  1457. . '<td colspan="3" class="right vmiddle">'
  1458. . '<input type="submit" class="control_at_footer" value="' . __('Go') . '"'
  1459. . 'tabindex="' . ($tabindex + $tabindex_for_value + 6) . '" id="buttonYes" />'
  1460. . '<input type="reset" class="control_at_footer" value="' . __('Reset') . '"'
  1461. . 'tabindex="' . ($tabindex + $tabindex_for_value + 7) . '" />'
  1462. . '</td>';
  1463. }
  1464. /**
  1465. * Get table head and table foot for insert row table
  1466. *
  1467. * @param array $url_params url parameters
  1468. *
  1469. * @return string an html snippet
  1470. */
  1471. function PMA_getHeadAndFootOfInsertRowTable($url_params)
  1472. {
  1473. $html_output = '<table class="insertRowTable">'
  1474. . '<thead>'
  1475. . '<tr>'
  1476. . '<th>' . __('Column') . '</th>';
  1477. if ($GLOBALS['cfg']['ShowFieldTypesInDataEditView']) {
  1478. $html_output .= PMA_showColumnTypesInDataEditView($url_params, true);
  1479. }
  1480. if ($GLOBALS['cfg']['ShowFunctionFields']) {
  1481. $html_output .= PMA_showFunctionFieldsInEditMode($url_params, true);
  1482. }
  1483. $html_output .= '<th>'. __('Null') . '</th>'
  1484. . '<th>' . __('Value') . '</th>'
  1485. . '</tr>'
  1486. . '</thead>'
  1487. . ' <tfoot>'
  1488. . '<tr>'
  1489. . '<th colspan="5" class="tblFooters right">'
  1490. . '<input type="submit" value="' . __('Go') . '" />'
  1491. . '</th>'
  1492. . '</tr>'
  1493. . '</tfoot>';
  1494. return $html_output;
  1495. }
  1496. /**
  1497. * Prepares the field value and retrieve special chars, backup field and data array
  1498. *
  1499. * @param array $current_row a row of the table
  1500. * @param array $column description of column in given table
  1501. * @param array $extracted_columnspec associative array containing type,
  1502. * spec_in_brackets and possibly
  1503. * enum_set_values (another array)
  1504. * @param boolean $real_null_value whether column value null or not null
  1505. * @param array $gis_data_types list of GIS data types
  1506. * @param string $column_name_appendix string to append to column name in input
  1507. *
  1508. * @return array $real_null_value, $data, $special_chars, $backup_field,
  1509. * $special_chars_encoded
  1510. */
  1511. function PMA_getSpecialCharsAndBackupFieldForExistingRow(
  1512. $current_row, $column, $extracted_columnspec,
  1513. $real_null_value, $gis_data_types, $column_name_appendix
  1514. ) {
  1515. $special_chars_encoded = '';
  1516. // (we are editing)
  1517. if (is_null($current_row[$column['Field']])) {
  1518. $real_null_value = true;
  1519. $current_row[$column['Field']] = '';
  1520. $special_chars = '';
  1521. $data = $current_row[$column['Field']];
  1522. } elseif ($column['True_Type'] == 'bit') {
  1523. $special_chars = PMA_Util::printableBitValue(
  1524. $current_row[$column['Field']], $extracted_columnspec['spec_in_brackets']
  1525. );
  1526. } elseif (in_array($column['True_Type'], $gis_data_types)) {
  1527. // Convert gis data to Well Know Text format
  1528. $current_row[$column['Field']] = PMA_Util::asWKT(
  1529. $current_row[$column['Field']], true
  1530. );
  1531. $special_chars = htmlspecialchars($current_row[$column['Field']]);
  1532. } else {
  1533. // special binary "characters"
  1534. if ($column['is_binary']
  1535. || ($column['is_blob'] && ! $GLOBALS['cfg']['ProtectBinary'])
  1536. ) {
  1537. if ($_SESSION['tmp_user_values']['display_binary_as_hex']
  1538. && $GLOBALS['cfg']['ShowFunctionFields']
  1539. ) {
  1540. $current_row[$column['Field']] = bin2hex(
  1541. $current_row[$column['Field']]
  1542. );
  1543. $column['display_binary_as_hex'] = true;
  1544. } else {
  1545. $current_row[$column['Field']]
  1546. = PMA_Util::replaceBinaryContents(
  1547. $current_row[$column['Field']]
  1548. );
  1549. }
  1550. } // end if
  1551. $special_chars = htmlspecialchars($current_row[$column['Field']]);
  1552. //We need to duplicate the first \n or otherwise we will lose
  1553. //the first newline entered in a VARCHAR or TEXT column
  1554. $special_chars_encoded
  1555. = PMA_Util::duplicateFirstNewline($special_chars);
  1556. $data = $current_row[$column['Field']];
  1557. } // end if... else...
  1558. //when copying row, it is useful to empty auto-increment column
  1559. // to prevent duplicate key error
  1560. if (isset($_REQUEST['default_action'])
  1561. && $_REQUEST['default_action'] === 'insert'
  1562. ) {
  1563. if ($column['Key'] === 'PRI'
  1564. && strpos($column['Extra'], 'auto_increment') !== false
  1565. ) {
  1566. $data = $special_chars_encoded = $special_chars = null;
  1567. }
  1568. }
  1569. // If a timestamp field value is not included in an update
  1570. // statement MySQL auto-update it to the current timestamp;
  1571. // however, things have changed since MySQL 4.1, so
  1572. // it's better to set a fields_prev in this situation
  1573. $backup_field = '<input type="hidden" name="fields_prev'
  1574. . $column_name_appendix . '" value="'
  1575. . htmlspecialchars($current_row[$column['Field']]) . '" />';
  1576. return array(
  1577. $real_null_value,
  1578. $special_chars_encoded,
  1579. $special_chars,
  1580. $data,
  1581. $backup_field
  1582. );
  1583. }
  1584. /**
  1585. * display default values
  1586. *
  1587. * @param type $column description of column in given table
  1588. * @param boolean $real_null_value whether column value null or not null
  1589. *
  1590. * @return array $real_null_value, $data, $special_chars,
  1591. * $backup_field, $special_chars_encoded
  1592. */
  1593. function PMA_getSpecialCharsAndBackupFieldForInsertingMode(
  1594. $column, $real_null_value
  1595. ) {
  1596. if (! isset($column['Default'])) {
  1597. $column['Default'] = '';
  1598. $real_null_value = true;
  1599. $data = '';
  1600. } else {
  1601. $data = $column['Default'];
  1602. }
  1603. if ($column['True_Type'] == 'bit') {
  1604. $special_chars = PMA_Util::convertBitDefaultValue($column['Default']);
  1605. } else {
  1606. $special_chars = htmlspecialchars($column['Default']);
  1607. }
  1608. $backup_field = '';
  1609. $special_chars_encoded = PMA_Util::duplicateFirstNewline($special_chars);
  1610. // this will select the UNHEX function while inserting
  1611. if (($column['is_binary']
  1612. || ($column['is_blob'] && ! $GLOBALS['cfg']['ProtectBinary']))
  1613. && (isset($_SESSION['tmp_user_values']['display_binary_as_hex'])
  1614. && $_SESSION['tmp_user_values']['display_binary_as_hex'])
  1615. && $GLOBALS['cfg']['ShowFunctionFields']
  1616. ) {
  1617. $column['display_binary_as_hex'] = true;
  1618. }
  1619. return array(
  1620. $real_null_value, $data, $special_chars,
  1621. $backup_field, $special_chars_encoded
  1622. );
  1623. }
  1624. /**
  1625. * Prepares the update/insert of a row
  1626. *
  1627. * @return array $loop_array, $using_key, $is_insert, $is_insertignore
  1628. */
  1629. function PMA_getParamsForUpdateOrInsert()
  1630. {
  1631. if (isset($_REQUEST['where_clause'])) {
  1632. // we were editing something => use the WHERE clause
  1633. $loop_array = is_array($_REQUEST['where_clause'])
  1634. ? $_REQUEST['where_clause']
  1635. : array($_REQUEST['where_clause']);
  1636. $using_key = true;
  1637. $is_insert = $_REQUEST['submit_type'] == 'insert'
  1638. || $_REQUEST['submit_type'] == 'showinsert'
  1639. || $_REQUEST['submit_type'] == 'insertignore';
  1640. } else {
  1641. // new row => use indexes
  1642. $loop_array = array();
  1643. foreach ($_REQUEST['fields']['multi_edit'] as $key => $dummy) {
  1644. $loop_array[] = $key;
  1645. }
  1646. $using_key = false;
  1647. $is_insert = true;
  1648. }
  1649. $is_insertignore = $_REQUEST['submit_type'] == 'insertignore';
  1650. return array($loop_array, $using_key, $is_insert, $is_insertignore);
  1651. }
  1652. /**
  1653. * Check wether insert row mode and if so include tbl_changen script and set
  1654. * global variables.
  1655. *
  1656. * @return void
  1657. */
  1658. function PMA_isInsertRow()
  1659. {
  1660. if (isset($_REQUEST['insert_rows'])
  1661. && is_numeric($_REQUEST['insert_rows'])
  1662. && $_REQUEST['insert_rows'] != $GLOBALS['cfg']['InsertRows']
  1663. ) {
  1664. $GLOBALS['cfg']['InsertRows'] = $_REQUEST['insert_rows'];
  1665. $response = PMA_Response::getInstance();
  1666. $header = $response->getHeader();
  1667. $scripts = $header->getScripts();
  1668. $scripts->addFile('tbl_change.js');
  1669. include 'tbl_change.php';
  1670. exit;
  1671. }
  1672. }
  1673. /**
  1674. * set $_SESSION for edit_next
  1675. *
  1676. * @param string $one_where_clause one where clause from where clauses array
  1677. *
  1678. * @return void
  1679. */
  1680. function PMA_setSessionForEditNext($one_where_clause)
  1681. {
  1682. $local_query = 'SELECT * FROM ' . PMA_Util::backquote($GLOBALS['db'])
  1683. . '.' . PMA_Util::backquote($GLOBALS['table']) . ' WHERE '
  1684. . str_replace('` =', '` >', $one_where_clause) . ' LIMIT 1;';
  1685. $res = PMA_DBI_query($local_query);
  1686. $row = PMA_DBI_fetch_row($res);
  1687. $meta = PMA_DBI_get_fields_meta($res);
  1688. // must find a unique condition based on unique key,
  1689. // not a combination of all fields
  1690. list($unique_condition, $clause_is_unique)
  1691. = PMA_Util::getUniqueCondition(
  1692. $res, count($meta), $meta, $row, true
  1693. );
  1694. if (! empty($unique_condition)) {
  1695. $_SESSION['edit_next'] = $unique_condition;
  1696. }
  1697. unset($unique_condition, $clause_is_unique);
  1698. }
  1699. /**
  1700. * set $goto_include variable for different cases and retrieve like,
  1701. * if $GLOBALS['goto'] empty, if $goto_include previously not defined
  1702. * and new_insert, same_insert, edit_next
  1703. *
  1704. * @param string $goto_include store some script for include, otherwise it is
  1705. * boolean false
  1706. *
  1707. * @return string $goto_include
  1708. */
  1709. function PMA_getGotoInclude($goto_include)
  1710. {
  1711. $valid_options = array('new_insert', 'same_insert', 'edit_next');
  1712. if (isset($_REQUEST['after_insert'])
  1713. && in_array($_REQUEST['after_insert'], $valid_options)
  1714. ) {
  1715. $goto_include = 'tbl_change.php';
  1716. } elseif (! empty($GLOBALS['goto'])) {
  1717. if (! preg_match('@^[a-z_]+\.php$@', $GLOBALS['goto'])) {
  1718. // this should NOT happen
  1719. //$GLOBALS['goto'] = false;
  1720. $goto_include = false;
  1721. } else {
  1722. $goto_include = $GLOBALS['goto'];
  1723. }
  1724. if ($GLOBALS['goto'] == 'db_sql.php' && strlen($GLOBALS['table'])) {
  1725. $GLOBALS['table'] = '';
  1726. }
  1727. }
  1728. if (! $goto_include) {
  1729. if (! strlen($GLOBALS['table'])) {
  1730. $goto_include = 'db_sql.php';
  1731. } else {
  1732. $goto_include = 'tbl_sql.php';
  1733. }
  1734. }
  1735. return $goto_include;
  1736. }
  1737. /**
  1738. * Defines the url to return in case of failure of the query
  1739. *
  1740. * @param array $url_params url parameters
  1741. *
  1742. * @return string error url for query failure
  1743. */
  1744. function PMA_getErrorUrl($url_params)
  1745. {
  1746. if (isset($_REQUEST['err_url'])) {
  1747. return $_REQUEST['err_url'];
  1748. } else {
  1749. return 'tbl_change.php' . PMA_generate_common_url($url_params);
  1750. }
  1751. }
  1752. /**
  1753. * Builds the sql query
  1754. *
  1755. * @param boolean $is_insertignore $_REQUEST['submit_type'] == 'insertignore'
  1756. * @param array $query_fields column names array
  1757. * @param array $value_sets array of query values
  1758. *
  1759. * @return string a query
  1760. */
  1761. function PMA_buildSqlQuery($is_insertignore, $query_fields, $value_sets)
  1762. {
  1763. if ($is_insertignore) {
  1764. $insert_command = 'INSERT IGNORE ';
  1765. } else {
  1766. $insert_command = 'INSERT ';
  1767. }
  1768. $query[] = $insert_command . 'INTO '
  1769. . PMA_Util::backquote($GLOBALS['db']) . '.'
  1770. . PMA_Util::backquote($GLOBALS['table'])
  1771. . ' (' . implode(', ', $query_fields) . ') VALUES ('
  1772. . implode('), (', $value_sets) . ')';
  1773. unset($insert_command, $query_fields);
  1774. return $query;
  1775. }
  1776. /**
  1777. * Executes the sql query and get the result, then move back to the calling page
  1778. *
  1779. * @param array $url_params url paramters array
  1780. * @param string $query built query from PMA_buildSqlQuery()
  1781. *
  1782. * @return array $url_params, $total_affected_rows, $last_messages
  1783. * $warning_messages, $error_messages, $return_to_sql_query
  1784. */
  1785. function PMA_executeSqlQuery($url_params, $query)
  1786. {
  1787. $return_to_sql_query = '';
  1788. if (! empty($GLOBALS['sql_query'])) {
  1789. $url_params['sql_query'] = $GLOBALS['sql_query'];
  1790. $return_to_sql_query = $GLOBALS['sql_query'];
  1791. }
  1792. $GLOBALS['sql_query'] = implode('; ', $query) . ';';
  1793. // to ensure that the query is displayed in case of
  1794. // "insert as new row" and then "insert another new row"
  1795. $GLOBALS['display_query'] = $GLOBALS['sql_query'];
  1796. $total_affected_rows = 0;
  1797. $last_messages = array();
  1798. $warning_messages = array();
  1799. $error_messages = array();
  1800. foreach ($query as $single_query) {
  1801. if ($_REQUEST['submit_type'] == 'showinsert') {
  1802. $last_messages[] = PMA_Message::notice(__('Showing SQL query'));
  1803. continue;
  1804. }
  1805. if ($GLOBALS['cfg']['IgnoreMultiSubmitErrors']) {
  1806. $result = PMA_DBI_try_query($single_query);
  1807. } else {
  1808. $result = PMA_DBI_query($single_query);
  1809. }
  1810. if (! $result) {
  1811. $error_messages[] = PMA_Message::sanitize(PMA_DBI_getError());
  1812. } else {
  1813. // The next line contains a real assignment, it's not a typo
  1814. if ($tmp = @PMA_DBI_affected_rows()) {
  1815. $total_affected_rows += $tmp;
  1816. }
  1817. unset($tmp);
  1818. $insert_id = PMA_DBI_insert_id();
  1819. if ($insert_id != 0) {
  1820. // insert_id is id of FIRST record inserted in one insert, so if we
  1821. // inserted multiple rows, we had to increment this
  1822. if ($total_affected_rows > 0) {
  1823. $insert_id = $insert_id + $total_affected_rows - 1;
  1824. }
  1825. $last_message = PMA_Message::notice(__('Inserted row id: %1$d'));
  1826. $last_message->addParam($insert_id);
  1827. $last_messages[] = $last_message;
  1828. }
  1829. PMA_DBI_free_result($result);
  1830. }
  1831. $warning_messages = PMA_getWarningMessages();
  1832. }
  1833. return array(
  1834. $url_params,
  1835. $total_affected_rows,
  1836. $last_messages,
  1837. $warning_messages,
  1838. $error_messages,
  1839. $return_to_sql_query
  1840. );
  1841. }
  1842. /**
  1843. * get the warning messages array
  1844. *
  1845. * @return array $warning_essages
  1846. */
  1847. function PMA_getWarningMessages()
  1848. {
  1849. $warning_essages = array();
  1850. foreach (PMA_DBI_get_warnings() as $warning) {
  1851. $warning_essages[] = PMA_Message::sanitize(
  1852. $warning['Level'] . ': #' . $warning['Code'] . ' ' . $warning['Message']
  1853. );
  1854. }
  1855. return $warning_essages;
  1856. }
  1857. /**
  1858. * Column to display from the foreign table?
  1859. *
  1860. * @param string $where_comparison string that contain relation field value
  1861. * @param string $relation_field_value relation field value
  1862. * @param array $map all Relations to foreign tables for a given
  1863. * table or optionally a given column in a table
  1864. * @param string $relation_field relation field
  1865. *
  1866. * @return string $dispval display value from the foreign table
  1867. */
  1868. function PMA_getDisplayValueForForeignTableColumn($where_comparison,
  1869. $relation_field_value, $map, $relation_field
  1870. ) {
  1871. $display_field = PMA_getDisplayField(
  1872. $map[$relation_field]['foreign_db'],
  1873. $map[$relation_field]['foreign_table']
  1874. );
  1875. // Field to display from the foreign table?
  1876. if (isset($display_field) && strlen($display_field)) {
  1877. $dispsql = 'SELECT ' . PMA_Util::backquote($display_field)
  1878. . ' FROM ' . PMA_Util::backquote($map[$relation_field]['foreign_db'])
  1879. . '.' . PMA_Util::backquote($map[$relation_field]['foreign_table'])
  1880. . ' WHERE ' . PMA_Util::backquote($map[$relation_field]['foreign_field'])
  1881. . $where_comparison;
  1882. $dispresult = PMA_DBI_try_query($dispsql, null, PMA_DBI_QUERY_STORE);
  1883. if ($dispresult && PMA_DBI_num_rows($dispresult) > 0) {
  1884. list($dispval) = PMA_DBI_fetch_row($dispresult, 0);
  1885. }
  1886. @PMA_DBI_free_result($dispresult);
  1887. return $dispval;
  1888. }
  1889. return '';
  1890. }
  1891. /**
  1892. * Display option in the cell according to user choises
  1893. *
  1894. * @param array $map all Relations to foreign tables for a given
  1895. * table or optionally a given column in a table
  1896. * @param string $relation_field relation field
  1897. * @param string $where_comparison string that contain relation field value
  1898. * @param string $dispval display value from the foreign table
  1899. * @param string $relation_field_value relation field value
  1900. *
  1901. * @return string $output HTML <a> tag
  1902. */
  1903. function PMA_getLinkForRelationalDisplayField($map, $relation_field,
  1904. $where_comparison, $dispval, $relation_field_value
  1905. ) {
  1906. if ('K' == $_SESSION['tmp_user_values']['relational_display']) {
  1907. // user chose "relational key" in the display options, so
  1908. // the title contains the display field
  1909. $title = (! empty($dispval))
  1910. ? ' title="' . htmlspecialchars($dispval) . '"'
  1911. : '';
  1912. } else {
  1913. $title = ' title="' . htmlspecialchars($relation_field_value) . '"';
  1914. }
  1915. $_url_params = array(
  1916. 'db' => $map[$relation_field]['foreign_db'],
  1917. 'table' => $map[$relation_field]['foreign_table'],
  1918. 'pos' => '0',
  1919. 'sql_query' => 'SELECT * FROM '
  1920. . PMA_Util::backquote($map[$relation_field]['foreign_db'])
  1921. . '.' . PMA_Util::backquote($map[$relation_field]['foreign_table'])
  1922. . ' WHERE ' . PMA_Util::backquote($map[$relation_field]['foreign_field'])
  1923. . $where_comparison
  1924. );
  1925. $output = '<a href="sql.php'
  1926. . PMA_generate_common_url($_url_params) . '"' . $title . '>';
  1927. if ('D' == $_SESSION['tmp_user_values']['relational_display']) {
  1928. // user chose "relational display field" in the
  1929. // display options, so show display field in the cell
  1930. $output .= (!empty($dispval)) ? htmlspecialchars($dispval) : '';
  1931. } else {
  1932. // otherwise display data in the cell
  1933. $output .= htmlspecialchars($relation_field_value);
  1934. }
  1935. $output .= '</a>';
  1936. return $output;
  1937. }
  1938. /**
  1939. * Transform edited values
  1940. *
  1941. * @param string $db db name
  1942. * @param string $table table name
  1943. * @param array $transformation mimetypes for all columns of a table
  1944. * [field_name][field_key]
  1945. * @param array $edited_values transform columns list and new values
  1946. * @param string $file file containing the transformation plugin
  1947. * @param string $column_name column name
  1948. * @param array $extra_data extra data array
  1949. *
  1950. * @return array $extra_data
  1951. */
  1952. function PMA_transformEditedValues($db, $table,
  1953. $transformation, $edited_values, $file, $column_name, $extra_data
  1954. ) {
  1955. foreach ($edited_values as $cell_index => $curr_cell_edited_values) {
  1956. if (isset($curr_cell_edited_values[$column_name])) {
  1957. $column_data = $curr_cell_edited_values[$column_name];
  1958. $_url_params = array(
  1959. 'db' => $db,
  1960. 'table' => $table,
  1961. 'where_clause' => $_REQUEST['where_clause'],
  1962. 'transform_key' => $column_name
  1963. );
  1964. $include_file = 'libraries/plugins/transformations/' . $file;
  1965. if (file_exists($include_file)) {
  1966. include_once $include_file;
  1967. $transform_options = PMA_transformation_getOptions(
  1968. isset($transformation['transformation_options'])
  1969. ? $transformation['transformation_options']
  1970. : ''
  1971. );
  1972. $transform_options['wrapper_link']
  1973. = PMA_generate_common_url($_url_params);
  1974. $class_name = str_replace('.class.php', '', $file);
  1975. $plugin_manager = null;
  1976. $transformation_plugin = new $class_name(
  1977. $plugin_manager
  1978. );
  1979. }
  1980. $extra_data['transformations'][$cell_index]
  1981. = $transformation_plugin->applyTransformation(
  1982. $column_data,
  1983. $transform_options,
  1984. ''
  1985. );
  1986. }
  1987. } // end of loop for each transformation cell
  1988. return $extra_data;
  1989. }
  1990. /**
  1991. * Get current value in multi edit mode
  1992. *
  1993. * @param array $multi_edit_colummns multiple edit column array
  1994. * @param array $multi_edit_columns_name multiple edit columns name array
  1995. * @param array $multi_edit_funcs multiple edit functions array
  1996. * @param array $gis_from_text_functions array that contains gis from text functions
  1997. * @param string $current_value current value in the column
  1998. * @param array $gis_from_wkb_functions initialy $val is $multi_edit_colummns[$key]
  1999. * @param array $func_optional_param array('RAND','UNIX_TIMESTAMP')
  2000. * @param array $func_no_param array of set of string
  2001. * @param string $key an md5 of the column name
  2002. *
  2003. * @return array $cur_value
  2004. */
  2005. function PMA_getCurrentValueAsAnArrayForMultipleEdit($multi_edit_colummns,
  2006. $multi_edit_columns_name, $multi_edit_funcs, $gis_from_text_functions,
  2007. $current_value, $gis_from_wkb_functions, $func_optional_param,
  2008. $func_no_param, $key
  2009. ) {
  2010. if (empty($multi_edit_funcs[$key])) {
  2011. return $current_value;
  2012. } elseif ('UUID' === $multi_edit_funcs[$key]) {
  2013. /* This way user will know what UUID new row has */
  2014. $uuid = PMA_DBI_fetch_value('SELECT UUID()');
  2015. return "'" . $uuid . "'";
  2016. } elseif ((in_array($multi_edit_funcs[$key], $gis_from_text_functions)
  2017. && substr($current_value, 0, 3) == "'''")
  2018. || in_array($multi_edit_funcs[$key], $gis_from_wkb_functions)
  2019. ) {
  2020. // Remove enclosing apostrophes
  2021. $current_value = substr($current_value, 1, strlen($current_value) - 2);
  2022. // Remove escaping apostrophes
  2023. $current_value = str_replace("''", "'", $current_value);
  2024. return $multi_edit_funcs[$key] . '(' . $current_value . ')';
  2025. } elseif (! in_array($multi_edit_funcs[$key], $func_no_param)
  2026. || ($current_value != "''"
  2027. && in_array($multi_edit_funcs[$key], $func_optional_param))
  2028. ) {
  2029. return $multi_edit_funcs[$key] . '(' . $current_value . ')';
  2030. } else {
  2031. return $multi_edit_funcs[$key] . '()';
  2032. }
  2033. }
  2034. /**
  2035. * Get query values array and query fileds array for insert and update in multi edit
  2036. *
  2037. * @param array $multi_edit_columns_name multiple edit columns name array
  2038. * @param array $multi_edit_columns_null multiple edit columns null array
  2039. * @param string $current_value current value in the column in loop
  2040. * @param array $multi_edit_columns_prev multiple edit previous columns array
  2041. * @param array $multi_edit_funcs multiple edit functions array
  2042. * @param boolean $is_insert boolean value whether insert or not
  2043. * @param array $query_values SET part of the sql query
  2044. * @param array $query_fields array of query fileds
  2045. * @param string $current_value_as_an_array current value in the column
  2046. * as an array
  2047. * @param array $value_sets array of valu sets
  2048. * @param string $key an md5 of the column name
  2049. * @param array $multi_edit_columns_null_prev array of multiple edit columns
  2050. * null previous
  2051. *
  2052. * @return array ($query_values, $query_fields)
  2053. */
  2054. function PMA_getQueryValuesForInsertAndUpdateInMultipleEdit($multi_edit_columns_name,
  2055. $multi_edit_columns_null, $current_value, $multi_edit_columns_prev,
  2056. $multi_edit_funcs,$is_insert, $query_values, $query_fields,
  2057. $current_value_as_an_array, $value_sets, $key, $multi_edit_columns_null_prev
  2058. ) {
  2059. // i n s e r t
  2060. if ($is_insert) {
  2061. // no need to add column into the valuelist
  2062. if (strlen($current_value_as_an_array)) {
  2063. $query_values[] = $current_value_as_an_array;
  2064. // first inserted row so prepare the list of fields
  2065. if (empty($value_sets)) {
  2066. $query_fields[] = PMA_Util::backquote(
  2067. $multi_edit_columns_name[$key]
  2068. );
  2069. }
  2070. }
  2071. } elseif (! empty($multi_edit_columns_null_prev[$key])
  2072. && ! isset($multi_edit_columns_null[$key])
  2073. ) {
  2074. // u p d a t e
  2075. // field had the null checkbox before the update
  2076. // field no longer has the null checkbox
  2077. $query_values[]
  2078. = PMA_Util::backquote($multi_edit_columns_name[$key])
  2079. . ' = ' . $current_value_as_an_array;
  2080. } elseif (empty($multi_edit_funcs[$key])
  2081. && isset($multi_edit_columns_prev[$key])
  2082. && ("'" . PMA_Util::sqlAddSlashes($multi_edit_columns_prev[$key]) . "'"
  2083. == $current_value)
  2084. ) {
  2085. // No change for this column and no MySQL function is used -> next column
  2086. } elseif (! empty($current_value)) {
  2087. // avoid setting a field to NULL when it's already NULL
  2088. // (field had the null checkbox before the update
  2089. // field still has the null checkbox)
  2090. if (empty($multi_edit_columns_null_prev[$key])
  2091. || empty($multi_edit_columns_null[$key])
  2092. ) {
  2093. $query_values[]
  2094. = PMA_Util::backquote($multi_edit_columns_name[$key])
  2095. . ' = ' . $current_value_as_an_array;
  2096. }
  2097. }
  2098. return array($query_values, $query_fields);
  2099. }
  2100. /**
  2101. * Get the current column value in the form for different data types
  2102. *
  2103. * @param string $possibly_uploaded_val uploaded file content
  2104. * @param string $key an md5 of the column name
  2105. * @param array $multi_edit_columns_type array of multi edit column types
  2106. * @param string $current_value current column value in the form
  2107. * @param array $multi_edit_auto_increment multi edit auto increment
  2108. * @param string $rownumber index of where clause array
  2109. * @param array $multi_edit_columns_name multi edit column names array
  2110. * @param array $multi_edit_columns_null multi edit columns null array
  2111. * @param array $multi_edit_columns_null_prev multi edit columns previous null
  2112. * @param boolean $is_insert whether insert or not
  2113. * @param boolean $using_key whether editing or new row
  2114. * @param array $where_clause where clauses
  2115. * @param string $table table name
  2116. *
  2117. * @return string $current_value current column value in the form
  2118. */
  2119. function PMA_getCurrentValueForDifferentTypes($possibly_uploaded_val, $key,
  2120. $multi_edit_columns_type, $current_value, $multi_edit_auto_increment,
  2121. $rownumber, $multi_edit_columns_name, $multi_edit_columns_null,
  2122. $multi_edit_columns_null_prev, $is_insert, $using_key, $where_clause, $table
  2123. ) {
  2124. // Fetch the current values of a row to use in case we have a protected field
  2125. if ($is_insert
  2126. && $using_key && isset($multi_edit_columns_type)
  2127. && is_array($multi_edit_columns_type) && isset($where_clause)
  2128. ) {
  2129. $protected_row = PMA_DBI_fetch_single_row(
  2130. 'SELECT * FROM ' . PMA_Util::backquote($table)
  2131. . ' WHERE ' . $where_clause . ';'
  2132. );
  2133. }
  2134. if (false !== $possibly_uploaded_val) {
  2135. $current_value = $possibly_uploaded_val;
  2136. } else {
  2137. // c o l u m n v a l u e i n t h e f o r m
  2138. if (isset($multi_edit_columns_type[$key])) {
  2139. $type = $multi_edit_columns_type[$key];
  2140. } else {
  2141. $type = '';
  2142. }
  2143. if ($type != 'protected' && $type != 'set' && 0 === strlen($current_value)) {
  2144. // best way to avoid problems in strict mode
  2145. // (works also in non-strict mode)
  2146. if (isset($multi_edit_auto_increment)
  2147. && isset($multi_edit_auto_increment[$key])
  2148. ) {
  2149. $current_value = 'NULL';
  2150. } else {
  2151. $current_value = "''";
  2152. }
  2153. } elseif ($type == 'set') {
  2154. if (! empty($_REQUEST['fields']['multi_edit'][$rownumber][$key])) {
  2155. $current_value = implode(
  2156. ',', $_REQUEST['fields']['multi_edit'][$rownumber][$key]
  2157. );
  2158. $current_value = "'" . PMA_Util::sqlAddSlashes($current_value) . "'";
  2159. } else {
  2160. $current_value = "''";
  2161. }
  2162. } elseif ($type == 'protected') {
  2163. // here we are in protected mode (asked in the config)
  2164. // so tbl_change has put this special value in the
  2165. // coulmns array, so we do not change the column value
  2166. // but we can still handle column upload
  2167. // when in UPDATE mode, do not alter field's contents. When in INSERT
  2168. // mode, insert empty field because no values were submitted.
  2169. // If protected blobs where set, insert original fields content.
  2170. if (! empty($protected_row[$multi_edit_columns_name[$key]])) {
  2171. $current_value = '0x'
  2172. . bin2hex($protected_row[$multi_edit_columns_name[$key]]);
  2173. } else {
  2174. $current_value = '';
  2175. }
  2176. } elseif ($type == 'bit') {
  2177. $current_value = preg_replace('/[^01]/', '0', $current_value);
  2178. $current_value = "b'" . PMA_Util::sqlAddSlashes($current_value) . "'";
  2179. } elseif (! ($type == 'datetime' || $type == 'timestamp')
  2180. || $current_value != 'CURRENT_TIMESTAMP'
  2181. ) {
  2182. $current_value = "'" . PMA_Util::sqlAddSlashes($current_value) . "'";
  2183. }
  2184. // Was the Null checkbox checked for this field?
  2185. // (if there is a value, we ignore the Null checkbox: this could
  2186. // be possible if Javascript is disabled in the browser)
  2187. if (! empty($multi_edit_columns_null[$key])
  2188. && ($current_value == "''" || $current_value == '')
  2189. ) {
  2190. $current_value = 'NULL';
  2191. }
  2192. // The Null checkbox was unchecked for this field
  2193. if (empty($current_value)
  2194. && ! empty($multi_edit_columns_null_prev[$key])
  2195. && ! isset($multi_edit_columns_null[$key])
  2196. ) {
  2197. $current_value = "''";
  2198. }
  2199. } // end else (column value in the form)
  2200. return $current_value;
  2201. }
  2202. /**
  2203. * Check whether inline edited value can be truncated or not,
  2204. * and add additional parameters for extra_data array if needed
  2205. *
  2206. * @param string $db Database name
  2207. * @param string $table Table name
  2208. * @param string $column_name Column name
  2209. * @param array &$extra_data Extra data for ajax response
  2210. *
  2211. * @return void
  2212. */
  2213. function PMA_verifyWhetherValueCanBeTruncatedAndAppendExtraData(
  2214. $db, $table, $column_name, &$extra_data
  2215. ) {
  2216. $extra_data['isNeedToRecheck'] = true;
  2217. $sql_for_real_value = 'SELECT '. PMA_Util::backquote($table) . '.'
  2218. . PMA_Util::backquote($column_name)
  2219. . ' FROM ' . PMA_Util::backquote($db) . '.'
  2220. . PMA_Util::backquote($table)
  2221. . ' WHERE ' . $_REQUEST['where_clause'][0];
  2222. if (PMA_DBI_fetch_value($sql_for_real_value) !== false) {
  2223. $extra_data['truncatableFieldValue'] = PMA_DBI_fetch_value($sql_for_real_value);
  2224. } else {
  2225. $extra_data['isNeedToRecheck'] = false;
  2226. }
  2227. }
  2228. ?>