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