diagnoser.lib.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. *
  5. * * Class that is responsible for generating diagnostic information about the system
  6. *
  7. *
  8. * @package chamilo.diagnoser
  9. * @author Ivan Tcholakov, 2008, initiall proposal and sample code.
  10. * @author spou595, 2009, implementation for Chamilo 2.x
  11. * @author Julio Montoya <gugli100@gmail.com>, 2010, port to chamilo 1.8.7, Some fixes
  12. *
  13. */
  14. /**
  15. * Diagnoser class
  16. * @package chamilo.diagnoser
  17. */
  18. class Diagnoser
  19. {
  20. /**
  21. * The status's
  22. */
  23. const STATUS_OK = 1;
  24. const STATUS_WARNING = 2;
  25. const STATUS_ERROR = 3;
  26. const STATUS_INFORMATION = 4;
  27. function __construct()
  28. {
  29. }
  30. function show_html()
  31. {
  32. $sections = array('chamilo', 'php', 'mysql', 'webserver');
  33. if (!in_array($_GET['section'], $sections)) {
  34. $current_section = 'chamilo';
  35. } else {
  36. $current_section = $_GET['section'];
  37. }
  38. $html = '<div class="tabbable"><ul class="nav nav-tabs">';
  39. foreach ($sections as $section) {
  40. if ($current_section == $section) {
  41. $html .= '<li class="active">';
  42. } else {
  43. $html .= '<li>';
  44. }
  45. $params['section'] = $section;
  46. $html .= '<a href="system_status.php?section=' . $section . '">' . get_lang($section) . '</a></li>';
  47. }
  48. $html .= '</ul><div class="tab-pane">';
  49. $data = call_user_func(array($this, 'get_' . $current_section . '_data'));
  50. echo $html;
  51. $table = new SortableTableFromArray($data, 1, 100);
  52. $table->set_header(0, '', false);
  53. $table->set_header(1, get_lang('Section'), false);
  54. $table->set_header(2, get_lang('Setting'), false);
  55. $table->set_header(3, get_lang('Current'), false);
  56. $table->set_header(4, get_lang('Expected'), false);
  57. $table->set_header(5, get_lang('Comment'), false);
  58. $table->display();
  59. echo '</div></div>';
  60. }
  61. /**
  62. * Functions to get the data for the chamilo diagnostics
  63. * @return array of data
  64. */
  65. function get_chamilo_data()
  66. {
  67. $array = array();
  68. $writable_folders = array(
  69. 'data/',
  70. 'main/upload/users/'
  71. );
  72. foreach ($writable_folders as $index => $folder) {
  73. $writable = is_writable(api_get_path(SYS_PATH) . $folder);
  74. $status = $writable ? self :: STATUS_OK : self :: STATUS_ERROR;
  75. $array[] = $this->build_setting(
  76. $status,
  77. '[FILES]',
  78. get_lang('IsWritable') . ': ' . $folder,
  79. 'http://be2.php.net/manual/en/function.is-writable.php',
  80. $writable,
  81. 1,
  82. 'yes_no',
  83. get_lang('DirectoryMustBeWritable')
  84. );
  85. }
  86. $exists = file_exists(api_get_path(SYS_CODE_PATH) . 'install');
  87. $status = $exists ? self :: STATUS_WARNING : self :: STATUS_OK;
  88. $array[] = $this->build_setting(
  89. $status,
  90. '[FILES]',
  91. get_lang('DirectoryExists') . ': /install',
  92. 'http://be2.php.net/file_exists',
  93. $exists,
  94. 0,
  95. 'yes_no',
  96. get_lang('DirectoryShouldBeRemoved')
  97. );
  98. $app_version = api_get_setting('chamilo_database_version');
  99. $array[] = $this->build_setting(
  100. self :: STATUS_INFORMATION,
  101. '[DB]',
  102. 'chamilo_database_version',
  103. '#',
  104. $app_version,
  105. 0,
  106. null,
  107. 'Chamilo DB version'
  108. );
  109. return $array;
  110. }
  111. /**
  112. * Functions to get the data for the php diagnostics
  113. * @return array of data
  114. */
  115. function get_php_data()
  116. {
  117. $array = array();
  118. // General Functions
  119. $version = phpversion();
  120. $status = $version > REQUIRED_PHP_VERSION ? self :: STATUS_OK : self :: STATUS_ERROR;
  121. $array[] = $this->build_setting(
  122. $status,
  123. '[PHP]',
  124. 'phpversion()',
  125. 'http://www.php.net/manual/en/function.phpversion.php',
  126. phpversion(),
  127. '>= ' . REQUIRED_PHP_VERSION,
  128. null,
  129. get_lang('PHPVersionInfo')
  130. );
  131. $setting = ini_get('output_buffering');
  132. $req_setting = 1;
  133. $status = $setting >= $req_setting ? self :: STATUS_OK : self :: STATUS_ERROR;
  134. $array[] = $this->build_setting(
  135. $status,
  136. '[INI]',
  137. 'output_buffering',
  138. 'http://www.php.net/manual/en/outcontrol.configuration.php#ini.output-buffering',
  139. $setting,
  140. $req_setting,
  141. 'on_off',
  142. get_lang('OutputBufferingInfo')
  143. );
  144. $setting = ini_get('file_uploads');
  145. $req_setting = 1;
  146. $status = $setting == $req_setting ? self :: STATUS_OK : self :: STATUS_ERROR;
  147. $array[] = $this->build_setting(
  148. $status,
  149. '[INI]',
  150. 'file_uploads',
  151. 'http://www.php.net/manual/en/ini.core.php#ini.file-uploads',
  152. $setting,
  153. $req_setting,
  154. 'on_off',
  155. get_lang('FileUploadsInfo')
  156. );
  157. $setting = ini_get('magic_quotes_runtime');
  158. $req_setting = 0;
  159. $status = $setting == $req_setting ? self :: STATUS_OK : self :: STATUS_ERROR;
  160. $array[] = $this->build_setting(
  161. $status,
  162. '[INI]',
  163. 'magic_quotes_runtime',
  164. 'http://www.php.net/manual/en/ini.core.php#ini.magic-quotes-runtime',
  165. $setting,
  166. $req_setting,
  167. 'on_off',
  168. get_lang('MagicQuotesRuntimeInfo')
  169. );
  170. $setting = ini_get('safe_mode');
  171. $req_setting = 0;
  172. $status = $setting == $req_setting ? self :: STATUS_OK : self :: STATUS_WARNING;
  173. $array[] = $this->build_setting(
  174. $status,
  175. '[INI]',
  176. 'safe_mode',
  177. 'http://www.php.net/manual/en/ini.core.php#ini.safe-mode',
  178. $setting,
  179. $req_setting,
  180. 'on_off',
  181. get_lang('SafeModeInfo')
  182. );
  183. $setting = ini_get('register_globals');
  184. $req_setting = 0;
  185. $status = $setting == $req_setting ? self :: STATUS_OK : self :: STATUS_ERROR;
  186. $array[] = $this->build_setting(
  187. $status,
  188. '[INI]',
  189. 'register_globals',
  190. 'http://www.php.net/manual/en/ini.core.php#ini.register-globals',
  191. $setting,
  192. $req_setting,
  193. 'on_off',
  194. get_lang('RegisterGlobalsInfo')
  195. );
  196. $setting = ini_get('short_open_tag');
  197. $req_setting = 0;
  198. $status = $setting == $req_setting ? self :: STATUS_OK : self :: STATUS_WARNING;
  199. $array[] = $this->build_setting(
  200. $status,
  201. '[INI]',
  202. 'short_open_tag',
  203. 'http://www.php.net/manual/en/ini.core.php#ini.short-open-tag',
  204. $setting,
  205. $req_setting,
  206. 'on_off',
  207. get_lang('ShortOpenTagInfo')
  208. );
  209. $setting = ini_get('magic_quotes_gpc');
  210. $req_setting = 0;
  211. $status = $setting == $req_setting ? self :: STATUS_OK : self :: STATUS_ERROR;
  212. $array[] = $this->build_setting(
  213. $status,
  214. '[INI]',
  215. 'magic_quotes_gpc',
  216. 'http://www.php.net/manual/en/ini.core.php#ini.magic_quotes_gpc',
  217. $setting,
  218. $req_setting,
  219. 'on_off',
  220. get_lang('MagicQuotesGpcInfo')
  221. );
  222. $setting = ini_get('display_errors');
  223. $req_setting = 0;
  224. $status = $setting == $req_setting ? self :: STATUS_OK : self :: STATUS_WARNING;
  225. $array[] = $this->build_setting(
  226. $status,
  227. '[INI]',
  228. 'display_errors',
  229. 'http://www.php.net/manual/en/ini.core.php#ini.display_errors',
  230. $setting,
  231. $req_setting,
  232. 'on_off',
  233. get_lang('DisplayErrorsInfo')
  234. );
  235. $setting = ini_get('default_charset');
  236. if ($setting == '') {
  237. $setting = null;
  238. }
  239. $req_setting = null;
  240. $status = $setting == $req_setting ? self :: STATUS_OK : self :: STATUS_ERROR;
  241. $array[] = $this->build_setting(
  242. $status,
  243. '[INI]',
  244. 'default_charset',
  245. 'http://www.php.net/manual/en/ini.core.php#ini.default-charset',
  246. $setting,
  247. $req_setting,
  248. null,
  249. get_lang('DefaultCharsetInfo')
  250. );
  251. $setting = ini_get('max_execution_time');
  252. $req_setting = '300 (' . get_lang('minimum') . ')';
  253. $status = $setting >= 300 ? self :: STATUS_OK : self :: STATUS_WARNING;
  254. $array[] = $this->build_setting(
  255. $status,
  256. '[INI]',
  257. 'max_execution_time',
  258. 'http://www.php.net/manual/en/ini.core.php#ini.max-execution-time',
  259. $setting,
  260. $req_setting,
  261. null,
  262. get_lang('MaxExecutionTimeInfo')
  263. );
  264. $setting = ini_get('max_input_time');
  265. $req_setting = '300 (' . get_lang('minimum') . ')';
  266. $status = $setting >= 300 ? self :: STATUS_OK : self :: STATUS_WARNING;
  267. $array[] = $this->build_setting(
  268. $status,
  269. '[INI]',
  270. 'max_input_time',
  271. 'http://www.php.net/manual/en/ini.core.php#ini.max-input-time',
  272. $setting,
  273. $req_setting,
  274. null,
  275. get_lang('MaxInputTimeInfo')
  276. );
  277. $setting = ini_get('memory_limit');
  278. $req_setting = '>= ' . REQUIRED_MIN_MEMORY_LIMIT . 'M';
  279. $status = self :: STATUS_ERROR;
  280. if ((float)$setting >= REQUIRED_MIN_MEMORY_LIMIT) {
  281. $status = self :: STATUS_OK;
  282. }
  283. $array[] = $this->build_setting(
  284. $status,
  285. '[INI]',
  286. 'memory_limit',
  287. 'http://www.php.net/manual/en/ini.core.php#ini.memory-limit',
  288. $setting,
  289. $req_setting,
  290. null,
  291. get_lang('MemoryLimitInfo')
  292. );
  293. $setting = ini_get('post_max_size');
  294. $req_setting = '>= ' . REQUIRED_MIN_POST_MAX_SIZE . 'M';
  295. $status = self :: STATUS_ERROR;
  296. if ((float)$setting >= REQUIRED_MIN_POST_MAX_SIZE) {
  297. $status = self :: STATUS_OK;
  298. }
  299. $array[] = $this->build_setting(
  300. $status,
  301. '[INI]',
  302. 'post_max_size',
  303. 'http://www.php.net/manual/en/ini.core.php#ini.post-max-size',
  304. $setting,
  305. $req_setting,
  306. null,
  307. get_lang('PostMaxSizeInfo')
  308. );
  309. $setting = ini_get('upload_max_filesize');
  310. $req_setting = '>= ' . REQUIRED_MIN_UPLOAD_MAX_FILESIZE . 'M';
  311. $status = self :: STATUS_ERROR;
  312. if ((float)$setting >= REQUIRED_UPLOAD_MAX_FILESIZE) {
  313. $status = self :: STATUS_OK;
  314. }
  315. $array[] = $this->build_setting(
  316. $status,
  317. '[INI]',
  318. 'upload_max_filesize',
  319. 'http://www.php.net/manual/en/ini.core.php#ini.upload_max_filesize',
  320. $setting,
  321. $req_setting,
  322. null,
  323. get_lang('UploadMaxFilesizeInfo')
  324. );
  325. $setting = ini_get('variables_order');
  326. $req_setting = 'GPCS';
  327. $status = $setting == $req_setting ? self :: STATUS_OK : self :: STATUS_ERROR;
  328. $array[] = $this->build_setting(
  329. $status,
  330. '[INI]',
  331. 'variables_order',
  332. 'http://www.php.net/manual/en/ini.core.php#ini.variables-order',
  333. $setting,
  334. $req_setting,
  335. null,
  336. get_lang('VariablesOrderInfo')
  337. );
  338. $setting = ini_get('session.gc_maxlifetime');
  339. $req_setting = '4320';
  340. $status = $setting == $req_setting ? self :: STATUS_OK : self :: STATUS_WARNING;
  341. $array[] = $this->build_setting(
  342. $status,
  343. '[SESSION]',
  344. 'session.gc_maxlifetime',
  345. 'http://www.php.net/manual/en/ini.core.php#session.gc-maxlifetime',
  346. $setting,
  347. $req_setting,
  348. null,
  349. get_lang('SessionGCMaxLifetimeInfo')
  350. );
  351. if (api_check_browscap()) {
  352. $setting = true;
  353. } else {
  354. $setting = false;
  355. }
  356. $req_setting = true;
  357. $status = $setting == $req_setting ? self :: STATUS_OK : self :: STATUS_WARNING;
  358. $array[] = $this->build_setting(
  359. $status,
  360. '[INI]',
  361. 'browscap',
  362. 'http://www.php.net/manual/en/misc.configuration.php#ini.browscap',
  363. $setting,
  364. $req_setting,
  365. 'on_off',
  366. get_lang('BrowscapInfo')
  367. );
  368. //Extensions
  369. $extensions = array(
  370. 'gd' => array(
  371. 'link' => 'http://www.php.net/gd',
  372. 'expected' => 1,
  373. 'comment' => get_lang('ExtensionMustBeLoaded')
  374. ),
  375. 'mysql' => array(
  376. 'link' => 'http://www.php.net/mysql',
  377. 'expected' => 1,
  378. 'comment' => get_lang('ExtensionMustBeLoaded')
  379. ),
  380. 'pcre' => array(
  381. 'link' => 'http://www.php.net/pcre',
  382. 'expected' => 1,
  383. 'comment' => get_lang('ExtensionMustBeLoaded')
  384. ),
  385. 'session' => array(
  386. 'link' => 'http://www.php.net/session',
  387. 'expected' => 1,
  388. 'comment' => get_lang('ExtensionMustBeLoaded')
  389. ),
  390. 'standard' => array(
  391. 'link' => 'http://www.php.net/spl',
  392. 'expected' => 1,
  393. 'comment' => get_lang('ExtensionMustBeLoaded')
  394. ),
  395. 'zlib' => array(
  396. 'link' => 'http://www.php.net/zlib',
  397. 'expected' => 1,
  398. 'comment' => get_lang('ExtensionMustBeLoaded')
  399. ),
  400. 'xsl' => array(
  401. 'link' => 'http://be2.php.net/xsl',
  402. 'expected' => 2,
  403. 'comment' => get_lang('ExtensionShouldBeLoaded')
  404. ),
  405. 'curl' => array(
  406. 'link' => 'http://www.php.net/curl',
  407. 'expected' => 2,
  408. 'comment' => get_lang('ExtensionShouldBeLoaded')
  409. ),
  410. );
  411. foreach ($extensions as $extension => $data) {
  412. $url = $data['link'];
  413. $expected_value = $data['expected'];
  414. $comment = $data['comment'];
  415. $loaded = extension_loaded($extension);
  416. $status = $loaded ? self :: STATUS_OK : self :: STATUS_ERROR;
  417. $array[] = $this->build_setting(
  418. $status,
  419. '[EXTENSION]',
  420. get_lang('LoadedExtension') . ': ' . $extension,
  421. $url,
  422. $loaded,
  423. $expected_value,
  424. 'yes_no_optional',
  425. $comment
  426. );
  427. }
  428. return $array;
  429. }
  430. /**
  431. * Functions to get the data for the mysql diagnostics
  432. * @return array of data
  433. */
  434. function get_mysql_data()
  435. {
  436. $array = array();
  437. // A note: Maybe it would be better if all "MySQL"-like variable names and words on the page to be replaced with "Database"-like ones.
  438. //$array[] = $this->build_setting(self :: STATUS_INFORMATION, '[MySQL]', 'mysql_get_host_info()', 'http://www.php.net/manual/en/function.mysql-get-host-info.php', Database::get_host_info(), null, null, get_lang('MysqlHostInfo'));
  439. ///$array[] = $this->build_setting(self :: STATUS_INFORMATION, '[MySQL]', 'mysql_get_server_info()', 'http://www.php.net/manual/en/function.mysql-get-server-info.php', Database::get_server_info(), null, null, get_lang('MysqlServerInfo'));
  440. //$array[] = $this->build_setting(self :: STATUS_INFORMATION, '[MySQL]', 'mysql_get_proto_info()', 'http://www.php.net/manual/en/function.mysql-get-proto-info.php', Database::get_proto_info(), null, null, get_lang('MysqlProtoInfo'));
  441. //$array[] = $this->build_setting(self :: STATUS_INFORMATION, '[MySQL]', 'mysql_get_client_info()', 'http://www.php.net/manual/en/function.mysql-get-client-info.php', Database::get_client_info(), null, null, get_lang('MysqlClientInfo'));
  442. return $array;
  443. }
  444. /**
  445. * Functions to get the data for the webserver diagnostics
  446. * @return array of data
  447. */
  448. function get_webserver_data()
  449. {
  450. $array = array();
  451. $array[] = $this->build_setting(
  452. self :: STATUS_INFORMATION,
  453. '[SERVER]',
  454. '$_SERVER["SERVER_NAME"]',
  455. 'http://be.php.net/reserved.variables.server',
  456. $_SERVER["SERVER_NAME"],
  457. null,
  458. null,
  459. get_lang('ServerNameInfo')
  460. );
  461. $array[] = $this->build_setting(
  462. self :: STATUS_INFORMATION,
  463. '[SERVER]',
  464. '$_SERVER["SERVER_ADDR"]',
  465. 'http://be.php.net/reserved.variables.server',
  466. $_SERVER["SERVER_ADDR"],
  467. null,
  468. null,
  469. get_lang('ServerAddessInfo')
  470. );
  471. $array[] = $this->build_setting(
  472. self :: STATUS_INFORMATION,
  473. '[SERVER]',
  474. '$_SERVER["SERVER_PORT"]',
  475. 'http://be.php.net/reserved.variables.server',
  476. $_SERVER["SERVER_PORT"],
  477. null,
  478. null,
  479. get_lang('ServerPortInfo')
  480. );
  481. $array[] = $this->build_setting(
  482. self :: STATUS_INFORMATION,
  483. '[SERVER]',
  484. '$_SERVER["SERVER_SOFTWARE"]',
  485. 'http://be.php.net/reserved.variables.server',
  486. $_SERVER["SERVER_SOFTWARE"],
  487. null,
  488. null,
  489. get_lang('ServerSoftwareInfo')
  490. );
  491. $array[] = $this->build_setting(
  492. self :: STATUS_INFORMATION,
  493. '[SERVER]',
  494. '$_SERVER["REMOTE_ADDR"]',
  495. 'http://be.php.net/reserved.variables.server',
  496. $_SERVER["REMOTE_ADDR"],
  497. null,
  498. null,
  499. get_lang('ServerRemoteInfo')
  500. );
  501. $array[] = $this->build_setting(
  502. self :: STATUS_INFORMATION,
  503. '[SERVER]',
  504. '$_SERVER["HTTP_USER_AGENT"]',
  505. 'http://be.php.net/reserved.variables.server',
  506. $_SERVER["HTTP_USER_AGENT"],
  507. null,
  508. null,
  509. get_lang('ServerUserAgentInfo')
  510. );
  511. /*$path = $this->manager->get_url(array('section' => Request :: get('section')));
  512. $request = $_SERVER["REQUEST_URI"];
  513. $status = $request != $path ? self :: STATUS_ERROR : self :: STATUS_OK;
  514. $array[] = $this->build_setting($status, '[SERVER]', '$_SERVER["REQUEST_URI"]', 'http://be.php.net/reserved.variables.server', $request, $path, null, get_lang('RequestURIInfo'));
  515. */
  516. $array[] = $this->build_setting(
  517. self :: STATUS_INFORMATION,
  518. '[SERVER]',
  519. '$_SERVER["SERVER_PROTOCOL"]',
  520. 'http://be.php.net/reserved.variables.server',
  521. $_SERVER["SERVER_PROTOCOL"],
  522. null,
  523. null,
  524. get_lang('ServerProtocolInfo')
  525. );
  526. $array[] = $this->build_setting(
  527. self :: STATUS_INFORMATION,
  528. '[SERVER]',
  529. 'php_uname()',
  530. 'http://be2.php.net/php_uname',
  531. php_uname(),
  532. null,
  533. null,
  534. get_lang('UnameInfo')
  535. );
  536. return $array;
  537. }
  538. /**
  539. * Additional functions needed for fast integration
  540. */
  541. function build_setting(
  542. $status,
  543. $section,
  544. $title,
  545. $url,
  546. $current_value,
  547. $expected_value,
  548. $formatter,
  549. $comment,
  550. $img_path = null
  551. )
  552. {
  553. switch ($status) {
  554. case self :: STATUS_OK :
  555. $img = 'bullet_green.gif';
  556. break;
  557. case self :: STATUS_WARNING :
  558. $img = 'bullet_orange.gif';
  559. break;
  560. case self :: STATUS_ERROR :
  561. $img = 'bullet_red.gif';
  562. break;
  563. case self :: STATUS_INFORMATION :
  564. $img = 'bullet_blue.gif';
  565. break;
  566. }
  567. if (!$img_path) {
  568. $img_path = api_get_path(WEB_IMG_PATH);
  569. }
  570. $image = '<img src="' . $img_path . $img . '" alt="' . $status . '" />';
  571. $url = $this->get_link($title, $url);
  572. $formatted_current_value = $current_value;
  573. $formatted_expected_value = $expected_value;
  574. if ($formatter) {
  575. if (method_exists($this, 'format_' . $formatter)) {
  576. $formatted_current_value = call_user_func(array($this, 'format_' . $formatter), $current_value);
  577. $formatted_expected_value = call_user_func(array($this, 'format_' . $formatter), $expected_value);
  578. }
  579. }
  580. return array($image, $section, $url, $formatted_current_value, $formatted_expected_value, $comment);
  581. }
  582. /**
  583. * Create a link with a url and a title
  584. * @param $title
  585. * @param $url
  586. * @return string the url
  587. */
  588. function get_link($title, $url)
  589. {
  590. return '<a href="' . $url . '" target="about:bank">' . $title . '</a>';
  591. }
  592. function format_yes_no_optional($value)
  593. {
  594. $return = '';
  595. switch ($value) {
  596. case 0:
  597. $return = get_lang('No');
  598. break;
  599. case 1:
  600. $return = get_lang('Yes');
  601. break;
  602. case 2:
  603. $return = get_lang('Optional');
  604. break;
  605. }
  606. return $return;
  607. }
  608. function format_yes_no($value)
  609. {
  610. return $value ? get_lang('Yes') : get_lang('No');
  611. }
  612. function format_on_off($value)
  613. {
  614. $value = intval($value);
  615. if ($value > 1) {
  616. // Greater than 1 values are shown "as-is", they may be interpreted as "On" later.
  617. return $value;
  618. }
  619. // These are the values 'On' and 'Off' used in the php-ini file. Translation (get_lang()) is not needed here.
  620. return $value ? 'On' : 'Off';
  621. }
  622. }