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