FormDisplay.class.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Form management class, displays and processes forms
  5. *
  6. * Explanation of used terms:
  7. * o work_path - original field path, eg. Servers/4/verbose
  8. * o system_path - work_path modified so that it points to the first server,
  9. * eg. Servers/1/verbose
  10. * o translated_path - work_path modified for HTML field name, a path with
  11. * slashes changed to hyphens, eg. Servers-4-verbose
  12. *
  13. * @package PhpMyAdmin
  14. */
  15. /**
  16. * Core libraries.
  17. */
  18. require_once './libraries/config/FormDisplay.tpl.php';
  19. require_once './libraries/config/validate.lib.php';
  20. require_once './libraries/js_escape.lib.php';
  21. /**
  22. * Form management class, displays and processes forms
  23. *
  24. * @package PhpMyAdmin
  25. */
  26. class FormDisplay
  27. {
  28. /**
  29. * Form list
  30. * @var Form[]
  31. */
  32. private $_forms = array();
  33. /**
  34. * Stores validation errors, indexed by paths
  35. * [ Form_name ] is an array of form errors
  36. * [path] is a string storing error associated with single field
  37. * @var array
  38. */
  39. private $_errors = array();
  40. /**
  41. * Paths changed so that they can be used as HTML ids, indexed by paths
  42. * @var array
  43. */
  44. private $_translatedPaths = array();
  45. /**
  46. * Server paths change indexes so we define maps from current server
  47. * path to the first one, indexed by work path
  48. * @var array
  49. */
  50. private $_systemPaths = array();
  51. /**
  52. * Language strings which will be sent to PMA_messages JS variable
  53. * Will be looked up in $GLOBALS: str{value} or strSetup{value}
  54. * @var array
  55. */
  56. private $_jsLangStrings = array();
  57. /**
  58. * Tells whether forms have been validated
  59. * @var bool
  60. */
  61. private $_isValidated = true;
  62. /**
  63. * Dictionary with user preferences keys
  64. * @var array
  65. */
  66. private $_userprefsKeys;
  67. /**
  68. * Dictionary with disallowed user preferences keys
  69. * @var array
  70. */
  71. private $_userprefsDisallow;
  72. /**
  73. * Constructor
  74. */
  75. public function __construct()
  76. {
  77. $this->_jsLangStrings = array(
  78. 'error_nan_p' => __('Not a positive number'),
  79. 'error_nan_nneg' => __('Not a non-negative number'),
  80. 'error_incorrect_port' => __('Not a valid port number'),
  81. 'error_invalid_value' => __('Incorrect value'),
  82. 'error_value_lte' => __('Value must be equal or lower than %s'));
  83. // initialize validators
  84. PMA_config_get_validators();
  85. }
  86. /**
  87. * Registers form in form manager
  88. *
  89. * @param string $form_name
  90. * @param array $form
  91. * @param int $server_id 0 if new server, validation; >= 1 if editing a server
  92. *
  93. * @return void
  94. */
  95. public function registerForm($form_name, array $form, $server_id = null)
  96. {
  97. $this->_forms[$form_name] = new Form($form_name, $form, $server_id);
  98. $this->_isValidated = false;
  99. foreach ($this->_forms[$form_name]->fields as $path) {
  100. $work_path = $server_id === null
  101. ? $path
  102. : str_replace('Servers/1/', "Servers/$server_id/", $path);
  103. $this->_systemPaths[$work_path] = $path;
  104. $this->_translatedPaths[$work_path] = str_replace('/', '-', $work_path);
  105. }
  106. }
  107. /**
  108. * Processes forms, returns true on successful save
  109. *
  110. * @param bool $allow_partial_save allows for partial form saving
  111. * on failed validation
  112. * @param bool $check_form_submit whether check for $_POST['submit_save']
  113. *
  114. * @return boolean whether processing was successful
  115. */
  116. public function process($allow_partial_save = true, $check_form_submit = true)
  117. {
  118. if ($check_form_submit && !isset($_POST['submit_save'])) {
  119. return false;
  120. }
  121. // save forms
  122. if (count($this->_forms) > 0) {
  123. return $this->save(array_keys($this->_forms), $allow_partial_save);
  124. }
  125. return false;
  126. }
  127. /**
  128. * Runs validation for all registered forms
  129. *
  130. * @return void
  131. */
  132. private function _validate()
  133. {
  134. if ($this->_isValidated) {
  135. return;
  136. }
  137. $cf = ConfigFile::getInstance();
  138. $paths = array();
  139. $values = array();
  140. foreach ($this->_forms as $form) {
  141. /* @var $form Form */
  142. $paths[] = $form->name;
  143. // collect values and paths
  144. foreach ($form->fields as $path) {
  145. $work_path = array_search($path, $this->_systemPaths);
  146. $values[$path] = $cf->getValue($work_path);
  147. $paths[] = $path;
  148. }
  149. }
  150. // run validation
  151. $errors = PMA_config_validate($paths, $values, false);
  152. // change error keys from canonical paths to work paths
  153. if (is_array($errors) && count($errors) > 0) {
  154. $this->_errors = array();
  155. foreach ($errors as $path => $error_list) {
  156. $work_path = array_search($path, $this->_systemPaths);
  157. // field error
  158. if (!$work_path) {
  159. // form error, fix path
  160. $work_path = $path;
  161. }
  162. $this->_errors[$work_path] = $error_list;
  163. }
  164. }
  165. $this->_isValidated = true;
  166. }
  167. /**
  168. * Outputs HTML for forms
  169. *
  170. * @param bool $tabbed_form
  171. * @param bool $show_restore_default whether show "restore default" button
  172. * besides the input field
  173. *
  174. * @return void
  175. */
  176. public function display($tabbed_form = false, $show_restore_default = false)
  177. {
  178. static $js_lang_sent = false;
  179. $js = array();
  180. $js_default = array();
  181. $tabbed_form = $tabbed_form && (count($this->_forms) > 1);
  182. $validators = PMA_config_get_validators();
  183. PMA_displayFormTop();
  184. if ($tabbed_form) {
  185. $tabs = array();
  186. foreach ($this->_forms as $form) {
  187. $tabs[$form->name] = PMA_lang("Form_$form->name");
  188. }
  189. PMA_displayTabsTop($tabs);
  190. }
  191. // valdiate only when we aren't displaying a "new server" form
  192. $is_new_server = false;
  193. foreach ($this->_forms as $form) {
  194. /* @var $form Form */
  195. if ($form->index === 0) {
  196. $is_new_server = true;
  197. break;
  198. }
  199. }
  200. if (!$is_new_server) {
  201. $this->_validate();
  202. }
  203. // user preferences
  204. $this->_loadUserprefsInfo();
  205. // display forms
  206. foreach ($this->_forms as $form) {
  207. /* @var $form Form */
  208. $form_desc = isset($GLOBALS["strConfigForm_{$form->name}_desc"])
  209. ? PMA_lang("Form_{$form->name}_desc")
  210. : '';
  211. $form_errors = isset($this->_errors[$form->name])
  212. ? $this->_errors[$form->name] : null;
  213. PMA_displayFieldsetTop(
  214. PMA_lang("Form_$form->name"),
  215. $form_desc,
  216. $form_errors,
  217. array('id' => $form->name)
  218. );
  219. foreach ($form->fields as $field => $path) {
  220. $work_path = array_search($path, $this->_systemPaths);
  221. $translated_path = $this->_translatedPaths[$work_path];
  222. // always true/false for user preferences display
  223. // otherwise null
  224. $userprefs_allow = isset($this->_userprefsKeys[$path])
  225. ? !isset($this->_userprefsDisallow[$path])
  226. : null;
  227. // display input
  228. $this->_displayFieldInput(
  229. $form,
  230. $field,
  231. $path,
  232. $work_path,
  233. $translated_path,
  234. $show_restore_default,
  235. $userprefs_allow,
  236. $js_default
  237. );
  238. // register JS validators for this field
  239. if (isset($validators[$path])) {
  240. PMA_addJsValidate($translated_path, $validators[$path], $js);
  241. }
  242. }
  243. PMA_displayFieldsetBottom();
  244. }
  245. if ($tabbed_form) {
  246. PMA_displayTabsBottom();
  247. }
  248. PMA_displayFormBottom();
  249. // if not already done, send strings used for valdiation to JavaScript
  250. if (!$js_lang_sent) {
  251. $js_lang_sent = true;
  252. $js_lang = array();
  253. foreach ($this->_jsLangStrings as $strName => $strValue) {
  254. $js_lang[] = "'$strName': '" . PMA_jsFormat($strValue, false) . '\'';
  255. }
  256. $js[] = "$.extend(PMA_messages, {\n\t" . implode(",\n\t", $js_lang) . '})';
  257. }
  258. $js[] = "$.extend(defaultValues, {\n\t" . implode(",\n\t", $js_default) . '})';
  259. PMA_displayJavascript($js);
  260. }
  261. /**
  262. * Prepares data for input field display and outputs HTML code
  263. *
  264. * @param Form $form
  265. * @param string $field field name as it appears in $form
  266. * @param string $system_path field path, eg. Servers/1/verbose
  267. * @param string $work_path work path, eg. Servers/4/verbose
  268. * @param string $translated_path work path changed so that it can be
  269. * used as XHTML id
  270. * @param bool $show_restore_default whether show "restore default" button
  271. * besides the input field
  272. * @param mixed $userprefs_allow whether user preferences are enabled
  273. * for this field (null - no support,
  274. * true/false - enabled/disabled)
  275. * @param array &$js_default array which stores JavaScript code
  276. * to be displayed
  277. *
  278. * @return void
  279. */
  280. private function _displayFieldInput(
  281. Form $form, $field, $system_path, $work_path,
  282. $translated_path, $show_restore_default, $userprefs_allow, array &$js_default
  283. ) {
  284. $name = PMA_lang_name($system_path);
  285. $description = PMA_lang_name($system_path, 'desc', '');
  286. $cf = ConfigFile::getInstance();
  287. $value = $cf->get($work_path);
  288. $value_default = $cf->getDefault($system_path);
  289. $value_is_default = false;
  290. if ($value === null || $value === $value_default) {
  291. $value = $value_default;
  292. $value_is_default = true;
  293. }
  294. $opts = array(
  295. 'doc' => $this->getDocLink($system_path),
  296. 'wiki' => $this->getWikiLink($system_path),
  297. 'show_restore_default' => $show_restore_default,
  298. 'userprefs_allow' => $userprefs_allow,
  299. 'userprefs_comment' => PMA_lang_name($system_path, 'cmt', ''));
  300. if (isset($form->default[$system_path])) {
  301. $opts['setvalue'] = $form->default[$system_path];
  302. }
  303. if (isset($this->_errors[$work_path])) {
  304. $opts['errors'] = $this->_errors[$work_path];
  305. }
  306. switch ($form->getOptionType($field)) {
  307. case 'string':
  308. $type = 'text';
  309. break;
  310. case 'short_string':
  311. $type = 'short_text';
  312. break;
  313. case 'double':
  314. case 'integer':
  315. $type = 'number_text';
  316. break;
  317. case 'boolean':
  318. $type = 'checkbox';
  319. break;
  320. case 'select':
  321. $type = 'select';
  322. $opts['values'] = $form->getOptionValueList($form->fields[$field]);
  323. break;
  324. case 'array':
  325. $type = 'list';
  326. $value = (array) $value;
  327. $value_default = (array) $value_default;
  328. break;
  329. case 'group':
  330. // :group:end is changed to :group:end:{unique id} in Form class
  331. if (substr($field, 7, 4) != 'end:') {
  332. PMA_displayGroupHeader(substr($field, 7));
  333. } else {
  334. PMA_displayGroupFooter();
  335. }
  336. return;
  337. case 'NULL':
  338. trigger_error("Field $system_path has no type", E_USER_WARNING);
  339. return;
  340. }
  341. // TrustedProxies requires changes before displaying
  342. if ($system_path == 'TrustedProxies') {
  343. foreach ($value as $ip => &$v) {
  344. if (!preg_match('/^-\d+$/', $ip)) {
  345. $v = $ip . ': ' . $v;
  346. }
  347. }
  348. }
  349. $this->_setComments($system_path, $opts);
  350. // send default value to form's JS
  351. $js_line = '\'' . $translated_path . '\': ';
  352. switch ($type) {
  353. case 'text':
  354. case 'short_text':
  355. case 'number_text':
  356. $js_line .= '\'' . PMA_escapeJsString($value_default) . '\'';
  357. break;
  358. case 'checkbox':
  359. $js_line .= $value_default ? 'true' : 'false';
  360. break;
  361. case 'select':
  362. $value_default_js = is_bool($value_default)
  363. ? (int) $value_default
  364. : $value_default;
  365. $js_line .= '[\'' . PMA_escapeJsString($value_default_js) . '\']';
  366. break;
  367. case 'list':
  368. $js_line .= '\'' . PMA_escapeJsString(implode("\n", $value_default))
  369. . '\'';
  370. break;
  371. }
  372. $js_default[] = $js_line;
  373. PMA_displayInput(
  374. $translated_path, $name, $type, $value,
  375. $description, $value_is_default, $opts
  376. );
  377. }
  378. /**
  379. * Displays errors
  380. *
  381. * @return void
  382. */
  383. public function displayErrors()
  384. {
  385. $this->_validate();
  386. if (count($this->_errors) == 0) {
  387. return;
  388. }
  389. foreach ($this->_errors as $system_path => $error_list) {
  390. if (isset($this->_systemPaths[$system_path])) {
  391. $path = $this->_systemPaths[$system_path];
  392. $name = PMA_lang_name($path);
  393. } else {
  394. $name = $GLOBALS["strConfigForm_$system_path"];
  395. }
  396. PMA_displayErrors($name, $error_list);
  397. }
  398. }
  399. /**
  400. * Reverts erroneous fields to their default values
  401. *
  402. * @return void
  403. */
  404. public function fixErrors()
  405. {
  406. $this->_validate();
  407. if (count($this->_errors) == 0) {
  408. return;
  409. }
  410. $cf = ConfigFile::getInstance();
  411. foreach (array_keys($this->_errors) as $work_path) {
  412. if (!isset($this->_systemPaths[$work_path])) {
  413. continue;
  414. }
  415. $canonical_path = $this->_systemPaths[$work_path];
  416. $cf->set($work_path, $cf->getDefault($canonical_path));
  417. }
  418. }
  419. /**
  420. * Validates select field and casts $value to correct type
  421. *
  422. * @param string $value
  423. * @param array $allowed
  424. *
  425. * @return bool
  426. */
  427. private function _validateSelect(&$value, array $allowed)
  428. {
  429. $value_cmp = is_bool($value)
  430. ? (int) $value
  431. : $value;
  432. foreach ($allowed as $vk => $v) {
  433. // equality comparison only if both values are numeric or not numeric
  434. // (allows to skip 0 == 'string' equalling to true)
  435. // or identity (for string-string)
  436. if (($vk == $value && !(is_numeric($value_cmp) xor is_numeric($vk)))
  437. || $vk === $value
  438. ) {
  439. // keep boolean value as boolean
  440. if (!is_bool($value)) {
  441. settype($value, gettype($vk));
  442. }
  443. return true;
  444. }
  445. }
  446. return false;
  447. }
  448. /**
  449. * Validates and saves form data to session
  450. *
  451. * @param array|string $forms array of form names
  452. * @param bool $allow_partial_save allows for partial form saving on
  453. * failed validation
  454. *
  455. * @return boolean true on success (no errors and all saved)
  456. */
  457. public function save($forms, $allow_partial_save = true)
  458. {
  459. $result = true;
  460. $cf = ConfigFile::getInstance();
  461. $forms = (array) $forms;
  462. $values = array();
  463. $to_save = array();
  464. $is_setup_script = defined('PMA_SETUP');
  465. if ($is_setup_script) {
  466. $this->_loadUserprefsInfo();
  467. }
  468. $this->_errors = array();
  469. foreach ($forms as $form_name) {
  470. /* @var $form Form */
  471. if (isset($this->_forms[$form_name])) {
  472. $form = $this->_forms[$form_name];
  473. } else {
  474. continue;
  475. }
  476. // get current server id
  477. $change_index = $form->index === 0
  478. ? $cf->getServerCount() + 1
  479. : false;
  480. // grab POST values
  481. foreach ($form->fields as $field => $system_path) {
  482. $work_path = array_search($system_path, $this->_systemPaths);
  483. $key = $this->_translatedPaths[$work_path];
  484. $type = $form->getOptionType($field);
  485. // skip groups
  486. if ($type == 'group') {
  487. continue;
  488. }
  489. // ensure the value is set
  490. if (!isset($_POST[$key])) {
  491. // checkboxes aren't set by browsers if they're off
  492. if ($type == 'boolean') {
  493. $_POST[$key] = false;
  494. } else {
  495. $this->_errors[$form->name][] = sprintf(
  496. __('Missing data for %s'),
  497. '<i>' . PMA_lang_name($system_path) . '</i>'
  498. );
  499. $result = false;
  500. continue;
  501. }
  502. }
  503. // user preferences allow/disallow
  504. if ($is_setup_script
  505. && isset($this->_userprefsKeys[$system_path])
  506. ) {
  507. if (isset($this->_userprefsDisallow[$system_path])
  508. && isset($_POST[$key . '-userprefs-allow'])
  509. ) {
  510. unset($this->_userprefsDisallow[$system_path]);
  511. } else if (!isset($_POST[$key . '-userprefs-allow'])) {
  512. $this->_userprefsDisallow[$system_path] = true;
  513. }
  514. }
  515. // cast variables to correct type
  516. switch ($type) {
  517. case 'double':
  518. $_POST[$key] = PMA_Util::requestString($_POST[$key]);
  519. settype($_POST[$key], 'float');
  520. break;
  521. case 'boolean':
  522. case 'integer':
  523. if ($_POST[$key] !== '') {
  524. $_POST[$key] = PMA_Util::requestString($_POST[$key]);
  525. settype($_POST[$key], $type);
  526. }
  527. break;
  528. case 'select':
  529. $successfully_validated = $this->_validateSelect(
  530. $_POST[$key],
  531. $form->getOptionValueList($system_path)
  532. );
  533. if (! $successfully_validated) {
  534. $this->_errors[$work_path][] = __('Incorrect value');
  535. $result = false;
  536. continue;
  537. }
  538. break;
  539. case 'string':
  540. case 'short_string':
  541. $_POST[$key] = PMA_Util::requestString($_POST[$key]);
  542. break;
  543. case 'array':
  544. // eliminate empty values and ensure we have an array
  545. $post_values = is_array($_POST[$key])
  546. ? $_POST[$key]
  547. : explode("\n", $_POST[$key]);
  548. $_POST[$key] = array();
  549. foreach ($post_values as $v) {
  550. $v = PMA_Util::requestString($v);
  551. if ($v !== '') {
  552. $_POST[$key][] = $v;
  553. }
  554. }
  555. break;
  556. }
  557. // now we have value with proper type
  558. $values[$system_path] = $_POST[$key];
  559. if ($change_index !== false) {
  560. $work_path = str_replace(
  561. "Servers/$form->index/",
  562. "Servers/$change_index/", $work_path
  563. );
  564. }
  565. $to_save[$work_path] = $system_path;
  566. }
  567. }
  568. // save forms
  569. if ($allow_partial_save || empty($this->_errors)) {
  570. foreach ($to_save as $work_path => $path) {
  571. // TrustedProxies requires changes before saving
  572. if ($path == 'TrustedProxies') {
  573. $proxies = array();
  574. $i = 0;
  575. foreach ($values[$path] as $value) {
  576. $matches = array();
  577. $match = preg_match(
  578. "/^(.+):(?:[ ]?)(\\w+)$/", $value, $matches
  579. );
  580. if ($match) {
  581. // correct 'IP: HTTP header' pair
  582. $ip = trim($matches[1]);
  583. $proxies[$ip] = trim($matches[2]);
  584. } else {
  585. // save also incorrect values
  586. $proxies["-$i"] = $value;
  587. $i++;
  588. }
  589. }
  590. $values[$path] = $proxies;
  591. }
  592. $cf->set($work_path, $values[$path], $path);
  593. }
  594. if ($is_setup_script) {
  595. $cf->set(
  596. 'UserprefsDisallow',
  597. array_keys($this->_userprefsDisallow)
  598. );
  599. }
  600. }
  601. // don't look for non-critical errors
  602. $this->_validate();
  603. return $result;
  604. }
  605. /**
  606. * Tells whether form validation failed
  607. *
  608. * @return boolean
  609. */
  610. public function hasErrors()
  611. {
  612. return count($this->_errors) > 0;
  613. }
  614. /**
  615. * Returns link to documentation
  616. *
  617. * @param string $path
  618. *
  619. * @return string
  620. */
  621. public function getDocLink($path)
  622. {
  623. $test = substr($path, 0, 6);
  624. if ($test == 'Import' || $test == 'Export') {
  625. return '';
  626. }
  627. return PMA_Util::getDocuLink(
  628. 'config',
  629. 'cfg_' . $this->_getOptName($path)
  630. );
  631. }
  632. /**
  633. * Returns link to wiki
  634. *
  635. * @param string $path
  636. *
  637. * @return string
  638. */
  639. public function getWikiLink($path)
  640. {
  641. $opt_name = $this->_getOptName($path);
  642. if (substr($opt_name, 0, 7) == 'Servers') {
  643. $opt_name = substr($opt_name, 8);
  644. if (strpos($opt_name, 'AllowDeny') === 0) {
  645. $opt_name = str_replace('_', '_.28', $opt_name) . '.29';
  646. }
  647. }
  648. $test = substr($path, 0, 6);
  649. if ($test == 'Import') {
  650. $opt_name = substr($opt_name, 7);
  651. if ($opt_name == 'format') {
  652. $opt_name = 'format_2';
  653. }
  654. }
  655. if ($test == 'Export') {
  656. $opt_name = substr($opt_name, 7);
  657. }
  658. return PMA_linkURL('https://wiki.phpmyadmin.net/pma/Config#' . $opt_name);
  659. }
  660. /**
  661. * Changes path so it can be used in URLs
  662. *
  663. * @param string $path
  664. *
  665. * @return string
  666. */
  667. private function _getOptName($path)
  668. {
  669. return str_replace(array('Servers/1/', '/'), array('Servers/', '_'), $path);
  670. }
  671. /**
  672. * Fills out {@link userprefs_keys} and {@link userprefs_disallow}
  673. *
  674. * @return void
  675. */
  676. private function _loadUserprefsInfo()
  677. {
  678. if ($this->_userprefsKeys === null) {
  679. $this->_userprefsKeys = array_flip(PMA_readUserprefsFieldNames());
  680. // read real config for user preferences display
  681. $userprefs_disallow = defined('PMA_SETUP')
  682. ? ConfigFile::getInstance()->get('UserprefsDisallow', array())
  683. : $GLOBALS['cfg']['UserprefsDisallow'];
  684. $this->_userprefsDisallow = array_flip($userprefs_disallow);
  685. }
  686. }
  687. /**
  688. * Sets field comments and warnings based on current environment
  689. *
  690. * @param string $system_path
  691. * @param array $opts
  692. *
  693. * @return void
  694. */
  695. private function _setComments($system_path, array &$opts)
  696. {
  697. // RecodingEngine - mark unavailable types
  698. if ($system_path == 'RecodingEngine') {
  699. $comment = '';
  700. if (!function_exists('iconv')) {
  701. $opts['values']['iconv'] .= ' (' . __('unavailable') . ')';
  702. $comment = sprintf(
  703. __('"%s" requires %s extension'), 'iconv', 'iconv'
  704. );
  705. }
  706. if (!function_exists('recode_string')) {
  707. $opts['values']['recode'] .= ' (' . __('unavailable') . ')';
  708. $comment .= ($comment ? ", " : '') . sprintf(
  709. __('"%s" requires %s extension'),
  710. 'recode', 'recode'
  711. );
  712. }
  713. $opts['comment'] = $comment;
  714. $opts['comment_warning'] = true;
  715. }
  716. // ZipDump, GZipDump, BZipDump - check function availability
  717. if ($system_path == 'ZipDump'
  718. || $system_path == 'GZipDump'
  719. || $system_path == 'BZipDump'
  720. ) {
  721. $comment = '';
  722. $funcs = array(
  723. 'ZipDump' => array('zip_open', 'gzcompress'),
  724. 'GZipDump' => array('gzopen', 'gzencode'),
  725. 'BZipDump' => array('bzopen', 'bzcompress'));
  726. if (!function_exists($funcs[$system_path][0])) {
  727. $comment = sprintf(
  728. __('import will not work, missing function (%s)'),
  729. $funcs[$system_path][0]
  730. );
  731. }
  732. if (!function_exists($funcs[$system_path][1])) {
  733. $comment .= ($comment ? '; ' : '') . sprintf(
  734. __('export will not work, missing function (%s)'),
  735. $funcs[$system_path][1]
  736. );
  737. }
  738. $opts['comment'] = $comment;
  739. $opts['comment_warning'] = true;
  740. }
  741. if ($system_path == 'SQLQuery/Validate'
  742. && ! $GLOBALS['cfg']['SQLValidator']['use']
  743. ) {
  744. $opts['comment'] = __('SQL Validator is disabled');
  745. $opts['comment_warning'] = true;
  746. }
  747. if ($system_path == 'SQLValidator/use') {
  748. if (!class_exists('SOAPClient')) {
  749. @include_once 'SOAP/Client.php';
  750. if (!class_exists('SOAP_Client')) {
  751. $opts['comment'] = __('SOAP extension not found');
  752. $opts['comment_warning'] = true;
  753. }
  754. }
  755. }
  756. if (!defined('PMA_SETUP')) {
  757. if (($system_path == 'MaxDbList' || $system_path == 'MaxTableList'
  758. || $system_path == 'QueryHistoryMax')
  759. ) {
  760. $opts['comment'] = sprintf(
  761. __('maximum %s'), $GLOBALS['cfg'][$system_path]
  762. );
  763. }
  764. }
  765. }
  766. }
  767. ?>