PageRenderTime 65ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 0ms

/SugarCE-6.5.4/SugarCE-Full-6.5.4/modules/Administration/DiagnosticRun.php

https://bitbucket.org/blakeball/test-repository
PHP | 840 lines | 715 code | 62 blank | 63 comment | 44 complexity | 71ec61f38b53d9c45430ad010f073744 MD5 | raw file
Possible License(s): LGPL-2.1, MPL-2.0-no-copyleft-exception
  1. <?php
  2. if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
  3. /*********************************************************************************
  4. * SugarCRM Community Edition is a customer relationship management program developed by
  5. * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
  6. *
  7. * This program is free software; you can redistribute it and/or modify it under
  8. * the terms of the GNU Affero General Public License version 3 as published by the
  9. * Free Software Foundation with the addition of the following permission added
  10. * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
  11. * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
  12. * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
  13. *
  14. * This program is distributed in the hope that it will be useful, but WITHOUT
  15. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  16. * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  17. * details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License along with
  20. * this program; if not, see http://www.gnu.org/licenses or write to the Free
  21. * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  22. * 02110-1301 USA.
  23. *
  24. * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
  25. * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
  26. *
  27. * The interactive user interfaces in modified source and object code versions
  28. * of this program must display Appropriate Legal Notices, as required under
  29. * Section 5 of the GNU Affero General Public License version 3.
  30. *
  31. * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
  32. * these Appropriate Legal Notices must retain the display of the "Powered by
  33. * SugarCRM" logo. If the display of the logo is not reasonably feasible for
  34. * technical reasons, the Appropriate Legal Notices must display the words
  35. * "Powered by SugarCRM".
  36. ********************************************************************************/
  37. require_once( 'include/utils/progress_bar_utils.php' );
  38. require_once( 'include/utils/zip_utils.php' );
  39. global $current_user;
  40. if (!is_admin($current_user)) sugar_die("Unauthorized access to administration.");
  41. if (isset($GLOBALS['sugar_config']['hide_admin_diagnostics']) && $GLOBALS['sugar_config']['hide_admin_diagnostics'])
  42. {
  43. sugar_die("Unauthorized access to diagnostic tool.");
  44. }
  45. global $skip_md5_diff;
  46. $skip_md5_diff = false;
  47. set_time_limit(3600);
  48. // get all needed globals
  49. global $app_strings;
  50. global $app_list_strings;
  51. global $mod_strings;
  52. global $theme;
  53. global $db;
  54. if(empty($db)) {
  55. $db = DBManagerFactory::getInstance();
  56. }
  57. global $current_user;
  58. if(!is_admin($current_user)){
  59. die($mod_strings['LBL_DIAGNOSTIC_ACCESS']);
  60. }
  61. global $sugar_config;
  62. global $beanFiles;
  63. //get sugar version and flavor
  64. global $sugar_version;
  65. global $sugar_flavor;
  66. //guid used for directory path
  67. global $sod_guid;
  68. $sod_guid = create_guid();
  69. //GET CURRENT DATETIME STAMP TO USE IN FILENAME
  70. global $curdatetime;
  71. $curdatetime = date("Ymd-His");
  72. global $progress_bar_percent;
  73. $progress_bar_percent = 0;
  74. global $totalweight;
  75. $totalweight = 0;
  76. global $totalitems;
  77. $totalitems = 0;
  78. global $currentitems;
  79. $currentitems = 0;
  80. define("CONFIG_WEIGHT", 1);
  81. define("CUSTOM_DIR_WEIGHT", 1);
  82. define("PHPINFO_WEIGHT", 1);
  83. define("SQL_DUMPS_WEIGHT", 2);
  84. define("SQL_SCHEMA_WEIGHT", 3);
  85. define("SQL_INFO_WEIGHT", 1);
  86. define("MD5_WEIGHT", 5);
  87. define("BEANLISTBEANFILES_WEIGHT", 1);
  88. define("SUGARLOG_WEIGHT", 2);
  89. define("VARDEFS_WEIGHT", 2);
  90. //THIS MUST CHANGE IF THE NUMBER OF DIRECTORIES TRAVERSED TO GET TO
  91. // THE DIAGNOSTIC CACHE DIR CHANGES
  92. define("RETURN_FROM_DIAG_DIR", "../../../..");
  93. global $getDumpsFrom;
  94. $getDumpsFrom = Array();
  95. global $cacheDir;
  96. $cacheDir = "";
  97. function sodUpdateProgressBar($itemweight){
  98. global $progress_bar_percent;
  99. global $totalweight;
  100. global $totalitems;
  101. global $currentitems;
  102. $currentitems++;
  103. if($currentitems == $totalitems)
  104. update_progress_bar("diagnostic", 100, 100);
  105. else
  106. {
  107. $progress_bar_percent += ($itemweight / $GLOBALS['totalweight'] * 100);
  108. update_progress_bar("diagnostic", $progress_bar_percent, 100);
  109. }
  110. }
  111. /**
  112. * Dump table as array
  113. * @param $header string table header
  114. * @param $values array list of values
  115. * @return string
  116. */
  117. function array_as_table($header, $values)
  118. {
  119. $contents = "<table border=\"0\" cellpadding=\"0\" class=\"tabDetailView\">";
  120. $keys = array();
  121. foreach($values as $field) {
  122. $keys = array_unique($keys + array_keys($field));
  123. }
  124. $cols = count($keys);
  125. $contents .= "<tr colspan=\"$cols\">$header</tr><tr>";
  126. foreach($keys as $key) {
  127. $contents .= "<th class=\"tabDetailViewDL\"><b>$key</b></th>";
  128. }
  129. $contents .= "</tr>";
  130. foreach($values as $field) {
  131. $contents .= "<tr>";
  132. foreach($field as $item) {
  133. if(is_array($item)) {
  134. $item = join(",", $item);
  135. }
  136. $contents .= "<td class=\"tabDetailViewDF\">$item</td>";
  137. }
  138. $contents .= "</tr>";
  139. }
  140. $contents .= "</table>";
  141. return $contents;
  142. }
  143. // expects a string containing the name of the table you would like to get the dump of
  144. // expects there to already be a connection to the db and the 'use database_name' to be done
  145. // returns a string containing (in html) the dump of all rows
  146. function getFullTableDump($tableName){
  147. global $db;
  148. $cols = $db->get_columns($tableName);
  149. $indexes = $db->get_indices($tableName);
  150. $returnString = "";
  151. //setting up table header for each file
  152. $returnString .= array_as_table("{$db->dbName} $tableName Definitions:", $cols);
  153. $returnString .= array_as_table("{$db->dbName} $tableName Keys:", $indexes);
  154. $returnString .= "<BR><BR>";
  155. $def_count = count($cols);
  156. $td_result = $db->query("select * from ".$tableName);
  157. if(!$td_result) {
  158. return $db->lastError();
  159. }
  160. $returnString .= "<table border=\"0\" cellpadding=\"0\" class=\"tabDetailView\"><tr><th class=\"tabDetailViewDL\">#</th>";
  161. $fields = $db->getFieldsArray($td_result);
  162. foreach($fields as $field) {
  163. $returnString .= "<th class=\"tabDetailViewDL\">$field</th>";
  164. }
  165. $returnString .= "</tr>";
  166. $row_counter = 1;
  167. while($row = $db->fetchByAssoc($td_result))
  168. {
  169. $row = array_values($row);
  170. $returnString .= "<tr>";
  171. $returnString .= "<td class=\"tabDetailViewDL\">".$row_counter."</td>";
  172. for($counter = 0; $counter < $def_count; $counter++) {
  173. $replace_val = false;
  174. //perform this check when counter is set to two, which means it is on the 'value' column
  175. if($counter == 2) {
  176. //if the previous "name" column value was set to smtppass, set replace_val to true
  177. if(strcmp($row[$counter - 1], "smtppass") == 0 )
  178. $replace_val = true;
  179. //if the previous "name" column value was set to smtppass,
  180. //and the "category" value set to ldap, set replace_val to true
  181. if (strcmp($row[$counter - 2], "ldap") == 0 && strcmp($row[$counter - 1], "admin_password") == 0)
  182. $replace_val = true;
  183. //if the previous "name" column value was set to password,
  184. //and the "category" value set to proxy, set replace_val to true
  185. if(strcmp($row[$counter - 2], "proxy") == 0 && strcmp($row[$counter - 1], "password") == 0 )
  186. $replace_val = true;
  187. }
  188. if($replace_val) {
  189. $returnString .= "<td class=\"tabDetailViewDF\">********</td>";
  190. } else {
  191. $returnString .= "<td class=\"tabDetailViewDF\">".($row[$counter] == "" ? "&nbsp;" : $row[$counter])."</td>";
  192. }
  193. }
  194. $row_counter++;
  195. $returnString .= "</tr>";
  196. }
  197. $returnString .= "</table>";
  198. return $returnString;
  199. }
  200. // Deletes the directory recursively
  201. function deleteDir($dir)
  202. {
  203. if (substr($dir, strlen($dir)-1, 1) != '/')
  204. $dir .= '/';
  205. if ($handle = opendir($dir))
  206. {
  207. while ($obj = readdir($handle))
  208. {
  209. if ($obj != '.' && $obj != '..')
  210. {
  211. if (is_dir($dir.$obj))
  212. {
  213. if (!deleteDir($dir.$obj))
  214. return false;
  215. }
  216. elseif (is_file($dir.$obj))
  217. {
  218. if (!unlink($dir.$obj))
  219. return false;
  220. }
  221. }
  222. }
  223. closedir($handle);
  224. if (!@rmdir($dir))
  225. return false;
  226. return true;
  227. }
  228. return false;
  229. }
  230. function prepareDiag()
  231. {
  232. global $getDumpsFrom;
  233. global $cacheDir;
  234. global $curdatetime;
  235. global $progress_bar_percent;
  236. global $skip_md5_diff;
  237. global $sod_guid;
  238. global $mod_strings;
  239. echo getClassicModuleTitle(
  240. "Administration",
  241. array(
  242. "<a href='index.php?module=Administration&action=index'>{$mod_strings['LBL_MODULE_NAME']}</a>",
  243. translate('LBL_DIAGNOSTIC_TITLE')
  244. ),
  245. false
  246. );
  247. echo "<BR>";
  248. echo $mod_strings['LBL_DIAGNOSTIC_EXECUTING'];
  249. echo "<BR>";
  250. //determine if files.md5 exists or not
  251. if(file_exists('files.md5'))
  252. $skip_md5_diff = false;
  253. else
  254. $skip_md5_diff = true;
  255. // array of all tables that we need to pull rows from below
  256. $getDumpsFrom = array('config' => 'config',
  257. 'fields_meta_data' => 'fields_meta_data',
  258. 'upgrade_history' => 'upgrade_history',
  259. 'versions' => 'versions',
  260. );
  261. //Creates the diagnostic directory in the cache directory
  262. $cacheDir = create_cache_directory("diagnostic/");
  263. $cacheDir = create_cache_directory("diagnostic/".$sod_guid);
  264. $cacheDir = create_cache_directory("diagnostic/".$sod_guid."/diagnostic".$curdatetime."/");
  265. display_progress_bar("diagnostic", $progress_bar_percent, 100);
  266. ob_flush();
  267. }
  268. function executesugarlog()
  269. {
  270. //BEGIN COPY SUGARCRM.LOG
  271. //Copies the Sugarcrm log to our diagnostic directory
  272. global $cacheDir;
  273. require_once('include/SugarLogger/SugarLogger.php');
  274. $logger = new SugarLogger();
  275. if(!copy($logger->getLogFileNameWithPath(), $cacheDir.'/'.$logger->getLogFileName())) {
  276. echo "Couldn't copy sugarcrm.log to cacheDir.<br>";
  277. }
  278. //END COPY SUGARCRM.LOG
  279. //UPDATING PROGRESS BAR
  280. sodUpdateProgressBar(SUGARLOG_WEIGHT);
  281. }
  282. function executephpinfo()
  283. {
  284. //BEGIN GETPHPINFO
  285. //This gets phpinfo, writes to a buffer, then I write to phpinfo.html
  286. global $cacheDir;
  287. ob_start();
  288. phpinfo();
  289. $phpinfo = ob_get_contents();
  290. ob_clean();
  291. $handle = sugar_fopen($cacheDir."phpinfo.html", "w");
  292. if(fwrite($handle, $phpinfo) === FALSE){
  293. echo "Cannot write to file ".$cacheDir."phpinfo.html<br>";
  294. }
  295. fclose($handle);
  296. //END GETPHPINFO
  297. //UPDATING PROGRESS BAR
  298. sodUpdateProgressBar(PHPINFO_WEIGHT);
  299. }
  300. function executeconfigphp()
  301. {
  302. //BEGIN COPY CONFIG.PHP
  303. //store db_password in temp var so we can get config.php w/o making anyone angry
  304. global $cacheDir; global $sugar_config;
  305. $tempPass = $sugar_config['dbconfig']['db_password'];
  306. $sugar_config['dbconfig']['db_password'] = '********';
  307. //write config.php to a file
  308. write_array_to_file("Diagnostic", $sugar_config, $cacheDir."config.php");
  309. //restore db_password so everything still works
  310. $sugar_config['dbconfig']['db_password'] = $tempPass;
  311. //END COPY CONFIG.PHP
  312. //UPDATING PROGRESS BAR
  313. sodUpdateProgressBar(CONFIG_WEIGHT);
  314. }
  315. function execute_sql($getinfo, $getdumps, $getschema)
  316. {
  317. //BEGIN GET DB INFO
  318. global $getDumpsFrom;
  319. global $curdatetime;
  320. global $sod_guid;
  321. global $db;
  322. $sqlInfoDir = create_cache_directory("diagnostic/".$sod_guid."/diagnostic".$curdatetime."/{$db->dbName}/");
  323. //create directory for table definitions
  324. if($getschema)
  325. $tablesSchemaDir = create_cache_directory("diagnostic/".$sod_guid."/diagnostic".$curdatetime."/{$db->dbName}/TableSchema/");
  326. //make sure they checked the box to get basic info
  327. if($getinfo)
  328. {
  329. $info = $db->getDbInfo();
  330. $content = '';
  331. if(!empty($info)) {
  332. foreach($info as $name => $value) {
  333. $content .= "$name: $value<BR>";
  334. }
  335. }
  336. if(!empty($content)) {
  337. file_put_contents($sqlInfoDir."{$db->dbName}-General-info.html", $content);
  338. sodUpdateProgressBar(SQL_INFO_WEIGHT);
  339. }
  340. }
  341. $style = '<style>
  342. .tabDetailView
  343. {
  344. border-bottom:2px solid;
  345. border-top:2px solid;
  346. margin-bottom:10px;
  347. margin-top:2px;
  348. border-bottom-color:#ABC3D7;
  349. border-top-color:#4E8CCF;
  350. }
  351. .tabDetailView td table td
  352. {
  353. border: 0;
  354. background: white;
  355. }
  356. .tabDetailView tr.pagination td
  357. {
  358. padding-top: 4px;
  359. padding-bottom: 4px;
  360. border-bottom:1px solid #CBDAE6;
  361. }
  362. .tabDetailView tr.pagination td table td
  363. {
  364. border: none;
  365. }
  366. .tabDetailViewDL
  367. {
  368. background-color:#F6F6F6;
  369. color:#000000;
  370. border-bottom:1px solid #CBDAE6;
  371. font-size:12px;
  372. padding:5px 6px;
  373. text-align:left;
  374. vertical-align:top;
  375. }
  376. .tabDetailViewDF
  377. {
  378. background-color:#FFFFFF;
  379. color:#444444;
  380. border-bottom:1px solid #CBDAE6;
  381. font-size:12px;
  382. padding:5px 10px 5px 8px;
  383. vertical-align:top;
  384. }
  385. .listViewThS1
  386. {
  387. background:#EBEBED none repeat scroll 0 0;
  388. border-color:#CCCCCC -moz-use-text-color;
  389. border-style:solid none;
  390. border-width:1px medium;
  391. font-size:11px;
  392. font-weight:bold;
  393. padding:4px 5px;
  394. text-align:left;
  395. }
  396. </style>';
  397. if($getschema)
  398. {
  399. //BEGIN GET ALL TABLES SCHEMAS
  400. $all_tables = $db->getTablesArray();
  401. $contents = $style;
  402. foreach($all_tables as $tablename){
  403. $cols = $db->get_columns($tablename);
  404. $indexes = $db->get_indices($tablename);
  405. //setting up table header for each file
  406. $contents .= array_as_table("{$db->dbName} $tablename Definitions:", $cols);
  407. $contents .= array_as_table("{$db->dbName} $tablename Keys:", $indexes);
  408. $contents .= "<BR><BR>";
  409. }
  410. file_put_contents($tablesSchemaDir."{$db->dbName}TablesSchema.html", $contents);
  411. //END GET ALL TABLES SCHEMAS
  412. //BEGIN UPDATING PROGRESS BAR
  413. sodUpdateProgressBar(SQL_SCHEMA_WEIGHT);
  414. //END UPDATING PROGRESS BAR
  415. }
  416. if($getdumps)
  417. {
  418. //BEGIN GET TABLEDUMPS
  419. $tableDumpsDir = create_cache_directory("diagnostic/".$sod_guid."/diagnostic".$curdatetime."/{$db->dbName}/TableDumps/");
  420. foreach ($getDumpsFrom as $table)
  421. {
  422. //calling function defined above to get the string for dump
  423. $contents = $style .getFullTableDump($table);
  424. file_put_contents($tableDumpsDir.$table.".html", $contents);
  425. }
  426. //END GET TABLEDUMPS
  427. //BEGIN UPDATING PROGRESS BAR
  428. sodUpdateProgressBar(SQL_DUMPS_WEIGHT);
  429. //END UPDATING PROGRESS BAR
  430. }
  431. //END GET DB INFO
  432. }
  433. function executebeanlistbeanfiles()
  434. {
  435. //BEGIN CHECK BEANLIST FILES ARE AVAILABLE
  436. global $cacheDir;
  437. global $beanList;
  438. global $beanFiles;
  439. global $mod_strings;
  440. ob_start();
  441. echo $mod_strings['LBL_DIAGNOSTIC_BEANLIST_DESC'];
  442. echo "<BR>";
  443. echo "<font color=green>";
  444. echo $mod_strings['LBL_DIAGNOSTIC_BEANLIST_GREEN'];
  445. echo "</font>";
  446. echo "<BR>";
  447. echo "<font color=orange>";
  448. echo $mod_strings['LBL_DIAGNOSTIC_BEANLIST_ORANGE'];
  449. echo "</font>";
  450. echo "<BR>";
  451. echo "<font color=red>";
  452. echo $mod_strings['LBL_DIAGNOSTIC_BEANLIST_RED'];
  453. echo "</font>";
  454. echo "<BR><BR>";
  455. foreach ($beanList as $beanz)
  456. {
  457. if(!isset($beanFiles[$beanz]))
  458. {
  459. echo "<font color=orange>NO! --- ".$beanz." is not an index in \$beanFiles</font><br>";
  460. }
  461. else
  462. {
  463. if(file_exists($beanFiles[$beanz]))
  464. echo "<font color=green>YES --- ".$beanz." file \"".$beanFiles[$beanz]."\" exists</font><br>";
  465. else
  466. echo "<font color=red>NO! --- ".$beanz." file \"".$beanFiles[$beanz]."\" does NOT exist</font><br>";
  467. }
  468. }
  469. $content = ob_get_contents();
  470. ob_clean();
  471. $handle = sugar_fopen($cacheDir."beanFiles.html", "w");
  472. if(fwrite($handle, $content) === FALSE){
  473. echo "Cannot write to file ".$cacheDir."beanFiles.html<br>";
  474. }
  475. fclose($handle);
  476. //END CHECK BEANLIST FILES ARE AVAILABLE
  477. //BEGIN UPDATING PROGRESS BAR
  478. sodUpdateProgressBar(BEANLISTBEANFILES_WEIGHT);
  479. //END UPDATING PROGRESS BAR
  480. }
  481. function executecustom_dir()
  482. {
  483. //BEGIN ZIP AND SAVE CUSTOM DIRECTORY
  484. global $cacheDir;
  485. zip_dir("custom", $cacheDir."custom_directory.zip");
  486. //END ZIP AND SAVE CUSTOM DIRECTORY
  487. //BEGIN UPDATING PROGRESS BAR
  488. sodUpdateProgressBar(CUSTOM_DIR_WEIGHT);
  489. //END UPDATING PROGRESS BAR
  490. }
  491. function executemd5($filesmd5, $md5calculated)
  492. {
  493. //BEGIN ALL MD5 CHECKS
  494. global $curdatetime;
  495. global $skip_md5_diff;
  496. global $sod_guid;
  497. if(file_exists('files.md5'))
  498. include( 'files.md5');
  499. //create dir for md5s
  500. $md5_directory = create_cache_directory("diagnostic/".$sod_guid."/diagnostic".$curdatetime."/md5/");
  501. //skip this if the files.md5 didn't exist
  502. if(!$skip_md5_diff)
  503. {
  504. //make sure the files.md5
  505. if($filesmd5)
  506. if(!copy('files.md5', $md5_directory."files.md5"))
  507. echo "Couldn't copy files.md5 to ".$md5_directory."<br>Skipping md5 checks.<br>";
  508. }
  509. $md5_string_calculated = generateMD5array('./');
  510. if($md5calculated)
  511. write_array_to_file('md5_string_calculated', $md5_string_calculated, $md5_directory."md5_array_calculated.php");
  512. //if the files.md5 didn't exist, we can't do this
  513. if(!$skip_md5_diff)
  514. {
  515. $md5_string_diff = array_diff($md5_string_calculated, $md5_string);
  516. write_array_to_file('md5_string_diff', $md5_string_diff, $md5_directory."md5_array_diff.php");
  517. }
  518. //END ALL MD5 CHECKS
  519. //BEGIN UPDATING PROGRESS BAR
  520. sodUpdateProgressBar(MD5_WEIGHT);
  521. //END UPDATING PROGRESS BAR
  522. }
  523. function executevardefs()
  524. {
  525. //BEGIN DUMP OF SUGAR SCHEMA (VARDEFS)
  526. //END DUMP OF SUGAR SCHEMA (VARDEFS)
  527. //BEGIN UPDATING PROGRESS BAR
  528. //This gets the vardefs, writes to a buffer, then I write to vardefschema.html
  529. global $cacheDir;
  530. global $beanList;
  531. global $beanFiles;
  532. global $dictionary;
  533. global $sugar_version;
  534. global $sugar_db_version;
  535. global $sugar_flavor;
  536. ob_start();
  537. foreach ( $beanList as $beanz ) {
  538. // echo "Module: ".$beanz."<br>";
  539. $path_parts = pathinfo( $beanFiles[ $beanz ] );
  540. $vardefFileName = $path_parts[ 'dirname' ]."/vardefs.php";
  541. if( file_exists( $vardefFileName )) {
  542. // echo "<br>".$vardefFileName."<br>";
  543. }
  544. include_once( $vardefFileName );
  545. }
  546. echo "<html lang='en'>";
  547. echo "<BODY>";
  548. echo "<H1>Schema listing based on vardefs</H1>";
  549. echo "<P>Sugar version: ".$sugar_version." / Sugar DB version: ".$sugar_db_version." / Sugar flavor: ".$sugar_flavor;
  550. echo "</P>";
  551. echo "<style> th { text-align: left; } </style>";
  552. $tables = array();
  553. foreach($dictionary as $vardef) {
  554. $tables[] = $vardef['table'];
  555. $fields[$vardef['table']] = $vardef['fields'];
  556. $comments[$vardef['table']] = $vardef['comment'];
  557. }
  558. asort($tables);
  559. foreach($tables as $t) {
  560. $name = $t;
  561. if ( $name == "does_not_exist" )
  562. continue;
  563. $comment = $comments[$t];
  564. echo "<h2>Table: $t</h2>
  565. <p><i>{$comment}</i></p>";
  566. echo "<table border=\"0\" cellpadding=\"3\" class=\"tabDetailView\">";
  567. echo '<TR BGCOLOR="#DFDFDF">
  568. <TD NOWRAP ALIGN=left class=\"tabDetailViewDL\">Column</TD>
  569. <TD NOWRAP class=\"tabDetailViewDL\">Type</TD>
  570. <TD NOWRAP class=\"tabDetailViewDL\">Length</TD>
  571. <TD NOWRAP class=\"tabDetailViewDL\">Required</TD>
  572. <TD NOWRAP class=\"tabDetailViewDL\">Comment</TD>
  573. </TR>';
  574. ksort( $fields[ $t ] );
  575. foreach($fields[$t] as $k => $v) {
  576. // we only care about physical tables ('source' can be 'non-db' or 'nondb' or 'function' )
  577. if ( isset( $v[ 'source' ] ))
  578. continue;
  579. $columnname = $v[ 'name' ];
  580. $columntype = $v[ 'type' ];
  581. $columndbtype = $v[ 'dbType' ];
  582. $columnlen = $v[ 'len' ];
  583. $columncomment = $v[ 'comment' ];
  584. $columnrequired = $v[ 'required' ];
  585. if ( empty( $columnlen ) ) $columnlen = '<i>n/a</i>';
  586. if ( empty( $columncomment ) ) $columncomment = '<i>(none)</i>';
  587. if ( !empty( $columndbtype ) ) $columntype = $columndbtype;
  588. if ( empty( $columnrequired ) || ( $columnrequired == false ))
  589. $columndisplayrequired = 'no';
  590. else
  591. $columndisplayrequired = 'yes';
  592. echo '<TR BGCOLOR="#FFFFFF" ALIGN=left>
  593. <TD ALIGN=left class=\"tabDetailViewDF\">'.$columnname.'</TD>
  594. <TD NOWRAP class=\"tabDetailViewDF\">'.$columntype.'</TD>
  595. <TD NOWRAP class=\"tabDetailViewDF\">'.$columnlen.'</TD>
  596. <TD NOWRAP class=\"tabDetailViewDF"\">'.$columndisplayrequired.'</TD>
  597. <TD WRAP class=\"tabDetailViewDF\">'.$columncomment.'</TD></TR>';
  598. }
  599. echo "</table></p>";
  600. }
  601. echo "</body></html>";
  602. $vardefFormattedOutput = ob_get_contents();
  603. ob_clean();
  604. $handle = sugar_fopen($cacheDir."vardefschema.html", "w");
  605. if(fwrite($handle, $vardefFormattedOutput) === FALSE){
  606. echo "Cannot write to file ".$cacheDir."vardefschema.html<br>";
  607. }
  608. fclose($handle);
  609. sodUpdateProgressBar(VARDEFS_WEIGHT);
  610. //END UPDATING PROGRESS BAR
  611. }
  612. function finishDiag(){
  613. //BEGIN ZIP ALL FILES AND EXTRACT IN CACHE ROOT
  614. global $cacheDir;
  615. global $curdatetime;
  616. global $sod_guid;
  617. global $mod_strings;
  618. chdir($cacheDir);
  619. zip_dir(".", "../diagnostic".$curdatetime.".zip");
  620. //END ZIP ALL FILES AND EXTRACT IN CACHE ROOT
  621. chdir(RETURN_FROM_DIAG_DIR);
  622. deleteDir($cacheDir);
  623. print "<a href=\"index.php?module=Administration&action=DiagnosticDownload&guid=$sod_guid&time=$curdatetime&to_pdf=1\">".$mod_strings['LBL_DIAGNOSTIC_DOWNLOADLINK']."</a><BR>";
  624. print "<a href=\"index.php?module=Administration&action=DiagnosticDelete&file=diagnostic".$curdatetime."&guid=".$sod_guid."\">".$mod_strings['LBL_DIAGNOSTIC_DELETELINK']."</a><br>";
  625. }
  626. //BEGIN check for what we are executing
  627. $doconfigphp = ((empty($_POST['configphp']) || $_POST['configphp'] == 'off') ? false : true);
  628. $docustom_dir = ((empty($_POST['custom_dir']) || $_POST['custom_dir'] == 'off') ? false : true);
  629. $dophpinfo = ((empty($_POST['phpinfo']) || $_POST['phpinfo'] == 'off') ? false : true);
  630. $domysql_dumps = ((empty($_POST['mysql_dumps']) || $_POST['mysql_dumps'] == 'off') ? false : true);
  631. $domysql_schema = ((empty($_POST['mysql_schema']) || $_POST['mysql_schema'] == 'off') ? false : true);
  632. $domysql_info = ((empty($_POST['mysql_info']) || $_POST['mysql_info'] == 'off') ? false : true);
  633. $domd5 = ((empty($_POST['md5']) || $_POST['md5'] == 'off') ? false : true);
  634. $domd5filesmd5 = ((empty($_POST['md5filesmd5']) || $_POST['md5filesmd5'] == 'off') ? false : true);
  635. $domd5calculated = ((empty($_POST['md5calculated']) || $_POST['md5calculated'] == 'off') ? false : true);
  636. $dobeanlistbeanfiles = ((empty($_POST['beanlistbeanfiles']) || $_POST['beanlistbeanfiles'] == 'off') ? false : true);
  637. $dosugarlog = ((empty($_POST['sugarlog']) || $_POST['sugarlog'] == 'off') ? false : true);
  638. $dovardefs = ((empty($_POST['vardefs']) || $_POST['vardefs'] == 'off') ? false : true);
  639. //END check for what we are executing
  640. //BEGIN items to calculate progress bar
  641. $totalitems = 0;
  642. $totalweight = 0;
  643. if($doconfigphp) {$totalweight += CONFIG_WEIGHT; $totalitems++;}
  644. if($docustom_dir) {$totalweight += CUSTOM_DIR_WEIGHT; $totalitems++;}
  645. if($dophpinfo) {$totalweight += PHPINFO_WEIGHT; $totalitems++;}
  646. if($domysql_dumps) {$totalweight += SQL_DUMPS_WEIGHT; $totalitems++;}
  647. if($domysql_schema) {$totalweight += SQL_SCHEMA_WEIGHT; $totalitems++;}
  648. if($domysql_info) {$totalweight += SQL_INFO_WEIGHT; $totalitems++;}
  649. if($domd5) {$totalweight += MD5_WEIGHT; $totalitems++;}
  650. if($dobeanlistbeanfiles) {$totalweight += BEANLISTBEANFILES_WEIGHT; $totalitems++;}
  651. if($dosugarlog) {$totalweight += SUGARLOG_WEIGHT; $totalitems++;}
  652. if($dovardefs) {$totalweight += VARDEFS_WEIGHT; $totalitems++;}
  653. //END items to calculate progress bar
  654. //prepare initial steps
  655. prepareDiag();
  656. if($doconfigphp)
  657. {
  658. echo $mod_strings['LBL_DIAGNOSTIC_GETCONFPHP']."<BR>";
  659. executeconfigphp();
  660. echo $mod_strings['LBL_DIAGNOSTIC_DONE']."<BR><BR>";
  661. }
  662. if($docustom_dir)
  663. {
  664. echo $mod_strings['LBL_DIAGNOSTIC_GETCUSTDIR']."<BR>";
  665. executecustom_dir();
  666. echo $mod_strings['LBL_DIAGNOSTIC_DONE']."<BR><BR>";
  667. }
  668. if($dophpinfo)
  669. {
  670. echo $mod_strings['LBL_DIAGNOSTIC_GETPHPINFO']."<BR>";
  671. executephpinfo();
  672. echo $mod_strings['LBL_DIAGNOSTIC_DONE']."<BR><BR>";
  673. }
  674. if($domysql_info || $domysql_dumps || $domysql_schema)
  675. {
  676. echo $mod_strings['LBL_DIAGNOSTIC_GETTING'].
  677. ($domysql_info ? "... ".$mod_strings['LBL_DIAGNOSTIC_GETMYSQLINFO'] : " ").
  678. ($domysql_dumps ? "... ".$mod_strings['LBL_DIAGNOSTIC_GETMYSQLTD'] : " ").
  679. ($domysql_schema ? "... ".$mod_strings['LBL_DIAGNOSTIC_GETMYSQLTS'] : "...").
  680. "<BR>";
  681. execute_sql($domysql_info, $domysql_dumps, $domysql_schema);
  682. echo $mod_strings['LBL_DIAGNOSTIC_DONE']."<BR><BR>";
  683. }
  684. if($domd5)
  685. {
  686. echo $mod_strings['LBL_DIAGNOSTIC_GETMD5INFO']."<BR>";
  687. executemd5($domd5filesmd5, $domd5calculated);
  688. echo $mod_strings['LBL_DIAGNOSTIC_DONE']."<BR><BR>";
  689. }
  690. if($dobeanlistbeanfiles)
  691. {
  692. echo $mod_strings['LBL_DIAGNOSTIC_GETBEANFILES']."<BR>";
  693. executebeanlistbeanfiles();
  694. echo $mod_strings['LBL_DIAGNOSTIC_DONE']."<BR><BR>";
  695. }
  696. if($dosugarlog)
  697. {
  698. echo $mod_strings['LBL_DIAGNOSTIC_GETSUGARLOG']."<BR>";
  699. executesugarlog();
  700. echo $mod_strings['LBL_DIAGNOSTIC_DONE']."<BR><BR>";
  701. }
  702. if($dovardefs)
  703. {
  704. echo $mod_strings['LBL_DIAGNOSTIC_VARDEFS']."<BR>";
  705. executevardefs();
  706. echo $mod_strings['LBL_DIAGNOSTIC_DONE']."<BR><BR>";
  707. }
  708. //finish up the last steps
  709. finishDiag();
  710. ?>