]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Administration/DiagnosticRun.php
Release 6.1.5
[Github/sugarcrm.git] / modules / Administration / DiagnosticRun.php
1 <?php
2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4  * SugarCRM is a customer relationship management program developed by
5  * SugarCRM, Inc. Copyright (C) 2004-2011 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
38
39
40
41 require_once( 'include/utils/progress_bar_utils.php' );
42 require_once( 'include/utils/zip_utils.php' );
43
44 global $current_user;
45
46
47 if (!is_admin($current_user)) sugar_die("Unauthorized access to administration.");
48
49
50 global $skip_md5_diff;
51 $skip_md5_diff = false;
52
53 set_time_limit(3600);
54 // get all needed globals
55 global $app_strings;
56 global $app_list_strings;
57 global $mod_strings;
58
59 global $theme;
60
61
62 global $db;
63 if(empty($db)) {
64
65         $db = DBManagerFactory::getInstance();
66 }
67
68 global $current_user;
69 if(!is_admin($current_user)){
70         die($mod_strings['LBL_DIAGNOSTIC_ACCESS']);
71 }
72 global $sugar_config;
73 global $beanFiles;
74
75
76
77 //get sugar version and flavor
78 global $sugar_version;
79 global $sugar_flavor;
80
81
82 //guid used for directory path
83 global $sod_guid;
84 $sod_guid = create_guid();
85
86 //GET CURRENT DATETIME STAMP TO USE IN FILENAME
87 global $curdatetime;
88 $curdatetime = date("Ymd-His");
89
90
91 global $progress_bar_percent;
92 $progress_bar_percent = 0;
93 global $totalweight;
94 $totalweight = 0;
95 global $totalitems;
96 $totalitems = 0;
97 global $currentitems;
98 $currentitems = 0;
99 define("CONFIG_WEIGHT", 1);
100 define("CUSTOM_DIR_WEIGHT", 1);
101 define("PHPINFO_WEIGHT", 1);
102 define("MYSQL_DUMPS_WEIGHT", 2);
103 define("MYSQL_SCHEMA_WEIGHT", 3);
104 define("MYSQL_INFO_WEIGHT", 1);
105 define("MD5_WEIGHT", 5);
106 define("BEANLISTBEANFILES_WEIGHT", 1);
107 define("SUGARLOG_WEIGHT", 2);
108 define("VARDEFS_WEIGHT", 2);
109
110 //THIS MUST CHANGE IF THE NUMBER OF DIRECTORIES TRAVERSED TO GET TO
111 //   THE DIAGNOSTIC CACHE DIR CHANGES
112 define("RETURN_FROM_DIAG_DIR", "../../../..");
113
114 global $getDumpsFrom;
115 $getDumpsFrom = Array();
116
117 global $cacheDir;
118 $cacheDir = "";
119
120 function sodUpdateProgressBar($itemweight){
121     global $progress_bar_percent;
122     global $totalweight;
123     global $totalitems;
124     global $currentitems;
125
126     $currentitems++;
127     if($currentitems == $totalitems)
128       update_progress_bar("diagnostic", 100, 100);
129     else
130     {
131       $progress_bar_percent += ($itemweight / $GLOBALS['totalweight'] * 100);
132       update_progress_bar("diagnostic", $progress_bar_percent, 100);
133     }
134 }
135
136
137 // expects a string containing the name of the table you would like to get the dump of
138 // expects there to already be a connection to mysql and the 'use database_name' to be done
139 // returns a string containing (in html) the dump of all rows
140 function getFullTableDump($tableName){
141
142         global $db;
143
144         $returnString = "<table border=\"1\">";
145         $returnString .= "<tr><b><center>Table ".$tableName."</center></b></tr>";
146         //get table field definitions
147         $definitions = array();
148         $def_result = $db->query("describe ".$tableName);
149         if(!$def_result)
150         {
151                 return mysql_error();
152         }
153         else
154         {
155                 $returnString .= "<tr><td><b>Row Num</b></td>";
156                 $def_count = 0;
157                 while($row = $db->fetchByAssoc($def_result))
158                 {
159                         $row = array_values($row);
160                         $definitions[$def_count] = $row[0];
161                         $def_count++;
162                         $returnString .= "<td><b>".$row[0]."</b></td>";
163                 }
164                 $returnString .= "</tr>";
165         }
166
167         $td_result = $db->query("select * from ".$tableName);
168         if(!$td_result)
169         {
170                 return mysql_error();
171         }
172         else
173         {
174                 $row_counter = 1;
175                 while($row = $db->fetchByAssoc($td_result))
176                 {
177                         $row = array_values($row);
178                         $returnString .= "<tr>";
179                         $returnString .= "<td>".$row_counter."</td>";
180                         for($counter = 0; $counter < $def_count; $counter++){
181
182                         $replace_val = false;
183                         //perform this check when counter is set to two, which means it is on the 'value' column
184                         if($counter == 2){
185                                 //if the previous "name" column value was set to smtppass, set replace_val to true 
186                                 if(strcmp($row[$counter - 1], "smtppass") == 0  )
187                                         $replace_val = true;
188                                 
189                                 //if the previous "name" column value was set to smtppass, 
190                                 //and the "category" value set to ldap, set replace_val to true
191                                 if (strcmp($row[$counter - 2], "ldap") == 0 && strcmp($row[$counter - 1], "admin_password") == 0)
192                                         $replace_val = true;
193                                         
194                                 //if the previous "name" column value was set to password, 
195                                 //and the "category" value set to proxy, set replace_val to true
196                                 if(strcmp($row[$counter - 2], "proxy") == 0 && strcmp($row[$counter - 1], "password") == 0 )
197                                         $replace_val = true;                            
198                         }
199
200                         if($replace_val)                                
201                                         $returnString .= "<td>********</td>";
202                                 else
203                                         $returnString .= "<td>".($row[$counter] == "" ? "&nbsp;" : $row[$counter])."</td>";
204                         }
205                         $row_counter++;
206                         $returnString .= "</tr>";
207                 }
208         }
209         $returnString .= "</table>";
210
211         return $returnString;
212
213 }
214
215 // Deletes the directory recursively
216 function deleteDir($dir)
217 {
218    if (substr($dir, strlen($dir)-1, 1) != '/')
219        $dir .= '/';
220
221    if ($handle = opendir($dir))
222    {
223        while ($obj = readdir($handle))
224        {
225            if ($obj != '.' && $obj != '..')
226            {
227                if (is_dir($dir.$obj))
228                {
229                    if (!deleteDir($dir.$obj))
230                        return false;
231                }
232                elseif (is_file($dir.$obj))
233                {
234                    if (!unlink($dir.$obj))
235                        return false;
236                }
237            }
238        }
239
240        closedir($handle);
241
242        if (!@rmdir($dir))
243            return false;
244        return true;
245    }
246    return false;
247 }
248
249
250 function prepareDiag()
251 {
252         global $getDumpsFrom;
253         global $cacheDir;
254         global $curdatetime;
255         global $progress_bar_percent;
256         global $skip_md5_diff;
257         global $sod_guid;
258         global $mod_strings;
259
260         echo getClassicModuleTitle(
261         "Administration", 
262         array(
263             "<a href='index.php?module=Administration&action=index'>{$mod_strings['LBL_MODULE_NAME']}</a>",
264            translate('LBL_DIAGNOSTIC_TITLE')
265            ), 
266         true
267         );
268         echo "<BR>";
269         echo $mod_strings['LBL_DIAGNOSTIC_EXECUTING'];
270         echo "<BR>";
271
272
273         //determine if files.md5 exists or not
274         if(file_exists('files.md5'))
275                 $skip_md5_diff = false;
276         else
277                 $skip_md5_diff = true;
278
279         // array of all tables that we need to pull rows from below
280         $getDumpsFrom = array('config' => 'config',
281                               'fields_meta_data' => 'fields_meta_data',
282                               'upgrade_history' => 'upgrade_history',
283                               'versions' => 'versions',
284                               );
285
286
287         //Creates the diagnostic directory in the cache directory
288     $cacheDir = create_cache_directory("diagnostic/");
289     $cacheDir = create_cache_directory("diagnostic/".$sod_guid);
290     $cacheDir = create_cache_directory("diagnostic/".$sod_guid."/diagnostic".$curdatetime."/");
291
292         display_progress_bar("diagnostic", $progress_bar_percent, 100);
293
294         ob_flush();
295 }
296
297 function executesugarlog()
298 {
299     //BEGIN COPY SUGARCRM.LOG
300     //Copies the Sugarcrm log to our diagnostic directory
301     global $cacheDir;
302         require_once('include/SugarLogger/SugarLogger.php');
303         $logger = new SugarLogger();
304     if(!copy($logger->getLogFileNameWithPath(), $cacheDir.'/'.$logger->getLogFileName())) {
305       echo "Couldn't copy sugarcrm.log to cacheDir.<br>";
306     }
307     //END COPY SUGARCRM.LOG
308
309     //UPDATING PROGRESS BAR
310     sodUpdateProgressBar(SUGARLOG_WEIGHT);
311 }
312
313 function executephpinfo()
314 {
315     //BEGIN GETPHPINFO
316     //This gets phpinfo, writes to a buffer, then I write to phpinfo.html
317     global $cacheDir;
318
319     ob_start();
320     phpinfo();
321     $phpinfo = ob_get_contents();
322     ob_clean();
323
324     $handle = sugar_fopen($cacheDir."phpinfo.html", "w");
325     if(fwrite($handle, $phpinfo) === FALSE){
326       echo "Cannot write to file ".$cacheDir."phpinfo.html<br>";
327     }
328     fclose($handle);
329     //END GETPHPINFO
330
331     //UPDATING PROGRESS BAR
332     sodUpdateProgressBar(PHPINFO_WEIGHT);
333 }
334
335 function executeconfigphp()
336 {
337     //BEGIN COPY CONFIG.PHP
338     //store db_password in temp var so we can get config.php w/o making anyone angry
339     global $cacheDir;    global $sugar_config;
340
341     $tempPass = $sugar_config['dbconfig']['db_password'];
342     $sugar_config['dbconfig']['db_password'] = '********';
343     //write config.php to a file
344     write_array_to_file("Diagnostic", $sugar_config, $cacheDir."config.php");
345     //restore db_password so everything still works
346     $sugar_config['dbconfig']['db_password'] = $tempPass;
347     //END COPY CONFIG.PHP
348
349     //UPDATING PROGRESS BAR
350     sodUpdateProgressBar(CONFIG_WEIGHT);
351 }
352
353 function executemysql($getinfo, $getdumps, $getschema)
354 {
355     //BEGIN GET DB INFO
356     global $getDumpsFrom;
357     global $curdatetime;
358     global $sugar_config;
359     global $progress_bar_percent;
360     global $sod_guid;
361     global $db;
362
363     if($db->dbType != "mysql") {
364         if($getinfo) sodUpdateProgressBar(MYSQL_INFO_WEIGHT);
365         if($getschema) sodUpdateProgressBar(MYSQL_SCHEMA_WEIGHT);
366         if($getdumps) sodUpdateProgressBar(MYSQL_DUMPS_WEIGHT);
367         return;
368     }
369     
370     $mysqlInfoDir = create_cache_directory("diagnostic/".$sod_guid."/diagnostic".$curdatetime."/MySQL/");
371
372
373     //create directory for table definitions
374     if($getschema)
375       $tablesSchemaDir = create_cache_directory("diagnostic/".$sod_guid."/diagnostic".$curdatetime."/MySQL/TableSchema/");
376
377     //BEGIN GET MYSQL INFO
378     //make sure they checked the box to get basic info
379     if($getinfo)
380     {
381       ob_start();
382       echo "MySQL Version: ".(function_exists('mysqli_get_client_info') ? @mysqli_get_client_info() : @mysql_get_client_info())."<BR>";
383       echo "MySQL Host Info: ".(function_exists('mysqli_get_host_info') ? @mysqli_get_host_info($db->getDatabase()) : @mysql_get_host_info())."<BR>";
384       echo "MySQL Server Info: ".(function_exists('mysqli_get_client_info') ? @mysqli_get_client_info() : @mysql_get_client_info())."<BR>";
385       echo "MySQL Client Encoding: ".(function_exists('mysqli_character_set_name') ? @mysqli_character_set_name($db->getDatabase()) : @mysql_client_encoding())."<BR>";
386
387       /* Uncomment to get current processes as well
388       echo "<BR>MySQL Processes<BR>";
389       $res = $db->query('SHOW PROCESSLIST');
390       echo "<table border=\"1\"><tr><th>Id</th><th>Host</th><th>db</th><th>Command</th><th>Time</th></tr>";
391       if($db->getRowCount($res) > 0)
392       {
393         while($row = $db->fetchByAssoc($res))
394         {
395           printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>",
396                  $row['Id'], $row['Host'], $row['db'], $row['Command'], $row['Time']
397                  );
398         }
399         echo "</table><br>";
400       }
401       else
402       {
403         echo "</table>";
404         echo "No processes running<br>";
405       }
406       */
407
408       echo "<BR>MySQL Character Set Settings<BR>";
409       $res = $db->query("show variables like 'character\_set\_%'");
410       echo "<table border=\"1\"><tr><th>Variable Name</th><th>Value</th></tr>";
411       while($row = $db->fetchByAssoc($res))
412       {
413         printf("<tr><td>%s</td><td>%s</td></tr>",
414                $row['Variable_name'], $row['Value']
415                );
416       }
417       echo "</table>";
418
419       $content = ob_get_contents();
420       ob_clean();
421
422       $handle = sugar_fopen($mysqlInfoDir."MySQL-General-info.html", "w");
423       if(fwrite($handle, $content) === FALSE){
424         echo "Cannot write to file ".$mysqlInfoDir."_MySQL-General-info.html<br>";
425       }
426       fclose($handle);
427       //BEGIN UPDATING PROGRESS BAR
428       sodUpdateProgressBar(MYSQL_INFO_WEIGHT);
429       //END UPDATING PROGRESS BAR
430     }
431     //END GET MYSQL INFO
432
433
434     if($getschema)
435     {
436         //BEGIN GET ALL TABLES SCHEMAS
437         $all_tables = $db->getTablesArray();
438
439         global $theme_path;
440
441                 ob_start();
442                 echo "<style>";
443                 echo file_get_contents($theme_path."style.css");
444                 echo "</style>";
445         foreach($all_tables as $tablename){
446                         //setting up table header for each file
447                         echo "<table border=\"0\" cellpadding=\"0\" class=\"tabDetailView\">";
448                         echo "<tr>MySQL ".$tablename." Definitions:</tr>".
449                                 "<tr><td class=\"tabDetailViewDL\"><b>Field</b></td>".
450                                         "<td class=\"tabDetailViewDL\">Type</td>".
451                                         "<td class=\"tabDetailViewDL\">Null</td>".
452                                         "<td class=\"tabDetailViewDL\">Key</td>".
453                                         "<td class=\"tabDetailViewDL\">Default</td>".
454                                         "<td class=\"tabDetailViewDL\">Extra</td></tr>";
455                         $describe = $db->query("describe ".$tablename);
456                         while($inner_row = $db->fetchByAssoc($describe)){
457                                 $inner_row = array_values($inner_row);
458                                 echo "<tr><td class=\"tabDetailViewDF\"><b>".$inner_row[0]."</b></td>";
459                                 echo     "<td class=\"tabDetailViewDF\">".$inner_row[1]."</td>";
460                                 echo     "<td class=\"tabDetailViewDF\">".$inner_row[2]."</td>";
461                                 echo     "<td class=\"tabDetailViewDF\">".$inner_row[3]."</td>";
462                                 echo     "<td class=\"tabDetailViewDF\">".$inner_row[4]."</td>";
463                                 echo     "<td class=\"tabDetailViewDF\">".$inner_row[5]."</td></tr>";
464                         }
465                         echo "</table>";
466                         echo "<BR><BR>";
467                 }
468
469                 $content = ob_get_contents();
470                 ob_clean();
471
472                 $handle = sugar_fopen($tablesSchemaDir."MySQLTablesSchema.html", "w");
473                 if(fwrite($handle, $content) === FALSE){
474                   echo "Cannot write to file ".$tablesSchemaDir."MySQLTablesSchema.html<br>";
475                 }
476                 fclose($handle);
477
478                 //END GET ALL TABLES SCHEMAS
479                 //BEGIN UPDATING PROGRESS BAR
480                 sodUpdateProgressBar(MYSQL_SCHEMA_WEIGHT);
481                 //END UPDATING PROGRESS BAR
482     }
483
484     if($getdumps)
485     {
486                 //BEGIN GET TABLEDUMPS
487                 $tableDumpsDir = create_cache_directory("diagnostic/".$sod_guid."/diagnostic".$curdatetime."/MySQL/TableDumps/");
488
489
490                 foreach ($getDumpsFrom as $table)
491                 {
492                         ob_start();
493                         //calling function defined above to get the string for dump
494                         echo getFullTableDump($table);
495                         $content = ob_get_contents();
496                         ob_clean();
497                         $handle = sugar_fopen($tableDumpsDir.$table.".html", "w");
498                         if(fwrite($handle, $content) === FALSE){
499                           echo "Cannot write to file ".$tableDumpsDir.$table."html<br>";
500                         }
501                         fclose($handle);
502                 }
503                 //END GET TABLEDUMPS
504                 //BEGIN UPDATING PROGRESS BAR
505                 sodUpdateProgressBar(MYSQL_DUMPS_WEIGHT);
506                 //END UPDATING PROGRESS BAR
507         }
508
509
510     //END GET DB INFO
511 }
512
513
514 function executebeanlistbeanfiles()
515 {
516     //BEGIN CHECK BEANLIST FILES ARE AVAILABLE
517     global $cacheDir;
518     global $beanList;
519     global $beanFiles;
520     global $mod_strings;
521
522     ob_start();
523
524     echo $mod_strings['LBL_DIAGNOSTIC_BEANLIST_DESC'];
525     echo "<BR>";
526     echo "<font color=green>";
527     echo $mod_strings['LBL_DIAGNOSTIC_BEANLIST_GREEN'];
528     echo "</font>";
529     echo "<BR>";
530     echo "<font color=orange>";
531     echo $mod_strings['LBL_DIAGNOSTIC_BEANLIST_ORANGE'];
532     echo "</font>";
533     echo "<BR>";
534     echo "<font color=red>";
535     echo $mod_strings['LBL_DIAGNOSTIC_BEANLIST_RED'];
536     echo "</font>";
537     echo "<BR><BR>";
538
539         foreach ($beanList as $beanz)
540         {
541                 if(!isset($beanFiles[$beanz]))
542                 {
543                         echo "<font color=orange>NO! --- ".$beanz." is not an index in \$beanFiles</font><br>";
544                 }
545                 else
546                 {
547                         if(file_exists($beanFiles[$beanz]))
548                                 echo "<font color=green>YES --- ".$beanz." file \"".$beanFiles[$beanz]."\" exists</font><br>";
549                         else
550                                 echo "<font color=red>NO! --- ".$beanz." file \"".$beanFiles[$beanz]."\" does NOT exist</font><br>";
551                 }
552         }
553
554         $content = ob_get_contents();
555         ob_clean();
556
557         $handle = sugar_fopen($cacheDir."beanFiles.html", "w");
558         if(fwrite($handle, $content) === FALSE){
559         echo "Cannot write to file ".$cacheDir."beanFiles.html<br>";
560     }
561     fclose($handle);
562     //END CHECK BEANLIST FILES ARE AVAILABLE
563     //BEGIN UPDATING PROGRESS BAR
564     sodUpdateProgressBar(BEANLISTBEANFILES_WEIGHT);
565     //END UPDATING PROGRESS BAR
566 }
567
568 function executecustom_dir()
569 {
570     //BEGIN ZIP AND SAVE CUSTOM DIRECTORY
571     global $cacheDir;
572
573     zip_dir("custom", $cacheDir."custom_directory.zip");
574     //END ZIP AND SAVE CUSTOM DIRECTORY
575     //BEGIN UPDATING PROGRESS BAR
576     sodUpdateProgressBar(CUSTOM_DIR_WEIGHT);
577     //END UPDATING PROGRESS BAR
578 }
579
580 function executemd5($filesmd5, $md5calculated)
581 {
582         //BEGIN ALL MD5 CHECKS
583         global $curdatetime;
584         global $skip_md5_diff;
585         global $sod_guid;
586         if(file_exists('files.md5'))
587         include( 'files.md5');
588         //create dir for md5s
589         $md5_directory = create_cache_directory("diagnostic/".$sod_guid."/diagnostic".$curdatetime."/md5/");
590
591         //skip this if the files.md5 didn't exist
592         if(!$skip_md5_diff)
593         {
594                 //make sure the files.md5
595                 if($filesmd5)
596                         if(!copy('files.md5', $md5_directory."files.md5"))
597                                 echo "Couldn't copy files.md5 to ".$md5_directory."<br>Skipping md5 checks.<br>";
598         }
599
600         $md5_string_calculated = generateMD5array('./');
601
602         if($md5calculated)
603                 write_array_to_file('md5_string_calculated', $md5_string_calculated, $md5_directory."md5_array_calculated.php");
604
605
606         //if the files.md5 didn't exist, we can't do this
607         if(!$skip_md5_diff)
608         {
609                 $md5_string_diff = array_diff($md5_string_calculated, $md5_string);
610
611                 write_array_to_file('md5_string_diff', $md5_string_diff, $md5_directory."md5_array_diff.php");
612         }
613         //END ALL MD5 CHECKS
614     //BEGIN UPDATING PROGRESS BAR
615     sodUpdateProgressBar(MD5_WEIGHT);
616     //END UPDATING PROGRESS BAR
617 }
618
619 function executevardefs()
620 {
621     //BEGIN DUMP OF SUGAR SCHEMA (VARDEFS)
622
623     //END DUMP OF SUGAR SCHEMA (VARDEFS)
624     //BEGIN UPDATING PROGRESS BAR
625     //This gets the vardefs, writes to a buffer, then I write to vardefschema.html
626     global $cacheDir;
627     global $beanList;
628     global $beanFiles;
629     global $dictionary;
630     global $sugar_version;
631     global $sugar_db_version;
632     global $sugar_flavor;
633
634     ob_start();
635     foreach ( $beanList as $beanz ) {
636       // echo "Module: ".$beanz."<br>";
637
638         $path_parts = pathinfo( $beanFiles[ $beanz ] );
639         $vardefFileName = $path_parts[ 'dirname' ]."/vardefs.php";
640           if( file_exists( $vardefFileName )) {
641             // echo "<br>".$vardefFileName."<br>";
642             include_once( $vardefFileName );
643           }
644     }
645
646     echo "<html>";
647     echo "<BODY>";
648     echo "<H1>Schema listing based on vardefs</H1>";
649     echo "<P>Sugar version:  ".$sugar_version." / Sugar DB version:  ".$sugar_db_version." / Sugar flavor:  ".$sugar_flavor;
650     echo "</P>";
651
652     echo "<style> th { text-align: left; } </style>";
653
654     $tables = array();
655     foreach($dictionary as $vardef) {
656         $tables[] = $vardef['table'];
657         $fields[$vardef['table']] = $vardef['fields'];
658         $comments[$vardef['table']] = $vardef['comment'];
659     }
660
661     asort($tables);
662
663     foreach($tables as $t) {
664         $name = $t;
665         if ( $name == "does_not_exist" )
666           continue;
667         $comment = $comments[$t];
668         echo "<h2>Table: $t</h2>
669                 <p><i>{$comment}</i></p>";
670         echo "<table border=\"0\" cellpadding=\"3\" class=\"tabDetailView\">";
671         echo '<TR BGCOLOR="#DFDFDF">
672                 <TD NOWRAP ALIGN=left class=\"tabDetailViewDL\">Column</TD>
673                 <TD NOWRAP class=\"tabDetailViewDL\">Type</TD>
674                 <TD NOWRAP class=\"tabDetailViewDL\">Length</TD>
675                 <TD NOWRAP class=\"tabDetailViewDL\">Required</TD>
676                 <TD NOWRAP class=\"tabDetailViewDL\">Comment</TD>
677         </TR>';
678
679         ksort( $fields[ $t ] );
680
681         foreach($fields[$t] as $k => $v) {
682           // we only care about physical tables ('source' can be 'non-db' or 'nondb' or 'function' )
683           if ( isset( $v[ 'source' ] ))
684             continue;
685           $columnname = $v[ 'name' ];
686           $columntype = $v[ 'type' ];
687           $columndbtype = $v[ 'dbType' ];
688           $columnlen = $v[ 'len' ];
689           $columncomment = $v[ 'comment' ];
690           $columnrequired = $v[ 'required' ];
691
692           if ( empty( $columnlen ) ) $columnlen = '<i>n/a</i>';
693           if ( empty( $columncomment ) ) $columncomment = '<i>(none)</i>';
694           if ( !empty( $columndbtype ) ) $columntype = $columndbtype;
695           if ( empty( $columnrequired ) || ( $columnrequired == false ))
696             $columndisplayrequired = 'no';
697           else
698             $columndisplayrequired = 'yes';
699
700           echo '<TR BGCOLOR="#FFFFFF" ALIGN=left>
701                         <TD ALIGN=left class=\"tabDetailViewDF\">'.$columnname.'</TD>
702                         <TD NOWRAP class=\"tabDetailViewDF\">'.$columntype.'</TD>
703                         <TD NOWRAP class=\"tabDetailViewDF\">'.$columnlen.'</TD>
704                         <TD NOWRAP class=\"tabDetailViewDF"\">'.$columndisplayrequired.'</TD>
705                         <TD WRAP class=\"tabDetailViewDF\">'.$columncomment.'</TD></TR>';
706         }
707
708         echo "</table></p>";
709     }
710
711     echo "</body></html>";
712
713     $vardefFormattedOutput = ob_get_contents();
714     ob_clean();
715
716     $handle = sugar_fopen($cacheDir."vardefschema.html", "w");
717     if(fwrite($handle, $vardefFormattedOutput) === FALSE){
718       echo "Cannot write to file ".$cacheDir."vardefschema.html<br>";
719     }
720     fclose($handle);
721     sodUpdateProgressBar(VARDEFS_WEIGHT);
722     //END UPDATING PROGRESS BAR
723 }
724
725 function finishDiag(){
726         //BEGIN ZIP ALL FILES AND EXTRACT IN CACHE ROOT
727         global $cacheDir;
728         global $curdatetime;
729         global $sod_guid;
730         global $mod_strings;
731
732         chdir($cacheDir);
733         zip_dir(".", "../diagnostic".$curdatetime.".zip");
734         //END ZIP ALL FILES AND EXTRACT IN CACHE ROOT
735         chdir(RETURN_FROM_DIAG_DIR);
736
737         deleteDir($cacheDir);
738         
739         
740         print "<a href=\"index.php?module=Administration&action=DiagnosticDownload&guid=$sod_guid&time=$curdatetime&to_pdf=1\">".$mod_strings['LBL_DIAGNOSTIC_DOWNLOADLINK']."</a><BR>";
741
742         print "<a href=\"index.php?module=Administration&action=DiagnosticDelete&file=diagnostic".$curdatetime."&guid=".$sod_guid."\">".$mod_strings['LBL_DIAGNOSTIC_DELETELINK']."</a><br>";
743
744 }
745
746 //BEGIN check for what we are executing
747 $doconfigphp = ((empty($_POST['configphp']) || $_POST['configphp'] == 'off') ? false : true);
748 $docustom_dir = ((empty($_POST['custom_dir']) || $_POST['custom_dir'] == 'off') ? false : true);
749 $dophpinfo = ((empty($_POST['phpinfo']) || $_POST['phpinfo'] == 'off') ? false : true);
750 $domysql_dumps = ((empty($_POST['mysql_dumps']) || $_POST['mysql_dumps'] == 'off') ? false : true);
751 $domysql_schema = ((empty($_POST['mysql_schema']) || $_POST['mysql_schema'] == 'off') ? false : true);
752 $domysql_info = ((empty($_POST['mysql_info']) || $_POST['mysql_info'] == 'off') ? false : true);
753 $domd5 = ((empty($_POST['md5']) || $_POST['md5'] == 'off') ? false : true);
754 $domd5filesmd5 = ((empty($_POST['md5filesmd5']) || $_POST['md5filesmd5'] == 'off') ? false : true);
755 $domd5calculated = ((empty($_POST['md5calculated']) || $_POST['md5calculated'] == 'off') ? false : true);
756 $dobeanlistbeanfiles = ((empty($_POST['beanlistbeanfiles']) || $_POST['beanlistbeanfiles'] == 'off') ? false : true);
757 $dosugarlog = ((empty($_POST['sugarlog']) || $_POST['sugarlog'] == 'off') ? false : true);
758 $dovardefs = ((empty($_POST['vardefs']) || $_POST['vardefs'] == 'off') ? false : true);
759 //END check for what we are executing
760
761
762 //BEGIN items to calculate progress bar
763 $totalitems = 0;
764 $totalweight = 0;
765 if($doconfigphp) {$totalweight += CONFIG_WEIGHT; $totalitems++;}
766 if($docustom_dir) {$totalweight += CUSTOM_DIR_WEIGHT; $totalitems++;}
767 if($dophpinfo) {$totalweight += PHPINFO_WEIGHT; $totalitems++;}
768 if($domysql_dumps) {$totalweight += MYSQL_DUMPS_WEIGHT; $totalitems++;}
769 if($domysql_schema) {$totalweight += MYSQL_SCHEMA_WEIGHT; $totalitems++;}
770 if($domysql_info) {$totalweight += MYSQL_INFO_WEIGHT; $totalitems++;}
771 if($domd5) {$totalweight += MD5_WEIGHT; $totalitems++;}
772 if($dobeanlistbeanfiles) {$totalweight += BEANLISTBEANFILES_WEIGHT; $totalitems++;}
773 if($dosugarlog) {$totalweight += SUGARLOG_WEIGHT; $totalitems++;}
774 if($dovardefs) {$totalweight += VARDEFS_WEIGHT; $totalitems++;}
775 //END items to calculate progress bar
776
777 //prepare initial steps
778 prepareDiag();
779
780
781 if($doconfigphp)
782 {
783   echo $mod_strings['LBL_DIAGNOSTIC_GETCONFPHP']."<BR>";
784   executeconfigphp();
785   echo $mod_strings['LBL_DIAGNOSTIC_DONE']."<BR><BR>";
786 }
787 if($docustom_dir)
788 {
789   echo $mod_strings['LBL_DIAGNOSTIC_GETCUSTDIR']."<BR>";
790   executecustom_dir();
791   echo $mod_strings['LBL_DIAGNOSTIC_DONE']."<BR><BR>";
792 }
793 if($dophpinfo)
794 {
795   echo $mod_strings['LBL_DIAGNOSTIC_GETPHPINFO']."<BR>";
796   executephpinfo();
797   echo $mod_strings['LBL_DIAGNOSTIC_DONE']."<BR><BR>";
798 }
799 if($domysql_info || $domysql_dumps || $domysql_schema)
800 {
801   echo $mod_strings['LBL_DIAGNOSTIC_GETTING'].
802                  ($domysql_info ? "... ".$mod_strings['LBL_DIAGNOSTIC_GETMYSQLINFO'] : " ").
803                  ($domysql_dumps ? "... ".$mod_strings['LBL_DIAGNOSTIC_GETMYSQLTD'] : " ").
804                  ($domysql_schema ? "... ".$mod_strings['LBL_DIAGNOSTIC_GETMYSQLTS'] : "...").
805                  "<BR>";
806   executemysql($domysql_info, $domysql_dumps, $domysql_schema);
807   echo $mod_strings['LBL_DIAGNOSTIC_DONE']."<BR><BR>";
808 }
809 if($domd5)
810 {
811   echo $mod_strings['LBL_DIAGNOSTIC_GETMD5INFO']."<BR>";
812   executemd5($domd5filesmd5, $domd5calculated);
813   echo $mod_strings['LBL_DIAGNOSTIC_DONE']."<BR><BR>";
814 }
815 if($dobeanlistbeanfiles)
816 {
817   echo $mod_strings['LBL_DIAGNOSTIC_GETBEANFILES']."<BR>";
818   executebeanlistbeanfiles();
819   echo $mod_strings['LBL_DIAGNOSTIC_DONE']."<BR><BR>";
820 }
821 if($dosugarlog)
822 {
823   echo $mod_strings['LBL_DIAGNOSTIC_GETSUGARLOG']."<BR>";
824   executesugarlog();
825   echo $mod_strings['LBL_DIAGNOSTIC_DONE']."<BR><BR>";
826 }
827 if($dovardefs)
828 {
829   echo $mod_strings['LBL_DIAGNOSTIC_VARDEFS']."<BR>";
830   executevardefs();
831   echo $mod_strings['LBL_DIAGNOSTIC_DONE']."<BR><BR>";
832 }
833
834 //finish up the last steps
835 finishDiag();
836
837 ?>