1<?php 2//$PageSecurity = 15; 3include('includes/session.php'); 4$Title = _('Upgrade webERP 3.11 - 4.00'); 5include('includes/header.php'); 6 7 8if (empty($_POST['DoUpgrade'])){ 9 prnMsg(_('This script will run perform any modifications to the database since v 3.11 required to allow the additional functionality in version 4.00 scripts'),'info'); 10 11 echo '<p><form method="post" action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '">'; 12 echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />'; 13 echo '<div class="centre"?><input type="submit" name="DoUpgrade" value="' . _('Perform Upgrade') . '" /></div>'; 14 echo '</form>'; 15} 16 17if ($_POST['DoUpgrade'] == _('Perform Upgrade')){ 18 19 echo '<br />'; 20 prnMsg(_('If there are any failures then please check with your system administrator'). 21 '. '._('Please read all notes carefully to ensure they are expected'),'info'); 22 23 $SQLScriptFile = file('./sql/mysql/upgrade3.11.1-4.00.sql'); 24 25 $ScriptFileEntries = sizeof($SQLScriptFile); 26 $ErrMsg = _('The script to upgrade the database failed because'); 27 $sql =''; 28 $InAFunction = false; 29 echo '<br /><table>'; 30 for ($i=0; $i<=$ScriptFileEntries; $i++) { 31 32 $SQLScriptFile[$i] = trim($SQLScriptFile[$i]); 33 34 if (mb_substr($SQLScriptFile[$i], 0, 2) == '--') { 35 $comment=mb_substr($SQLScriptFile[$i], 2); 36 } 37 38 if (mb_substr($SQLScriptFile[$i], 0, 2) != '--' 39 AND mb_substr($SQLScriptFile[$i], 0, 3) != 'USE' 40 AND mb_strstr($SQLScriptFile[$i],'/*')==FALSE 41 AND mb_strlen($SQLScriptFile[$i])>1){ 42 43 $sql .= ' ' . $SQLScriptFile[$i]; 44 45 //check if this line kicks off a function definition - pg chokes otherwise 46 if (mb_substr($SQLScriptFile[$i],0,15) == 'CREATE FUNCTION'){ 47 $InAFunction = true; 48 } 49 //check if this line completes a function definition - pg chokes otherwise 50 if (mb_substr($SQLScriptFile[$i],0,8) == 'LANGUAGE'){ 51 $InAFunction = false; 52 } 53 if (mb_strpos($SQLScriptFile[$i],';')>0 AND ! $InAFunction){ 54 $sql = mb_substr($sql,0,mb_strlen($sql)-1); 55 $result = DB_query($sql, $ErrMsg, $DBMsg, false, false); 56 switch (DB_error_no()) { 57 case 0: 58 echo '<tr><td>' . $comment . '</td><td style="background-color:green">' . _('Success') . '</td></tr>'; 59 break; 60 case 1050: 61 echo '<tr><td>' . $comment . '</td><td style="background-color:yellow">' . _('Note').' - '. 62 _('Table has already been created') . '</td></tr>'; 63 break; 64 case 1060: 65 echo '<tr><td>' . $comment . '</td><td style="background-color:yellow">' . _('Note').' - '. 66 _('Column has already been created') . '</td></tr>'; 67 break; 68 case 1061: 69 echo '<tr><td>' . $comment . '</td><td style="background-color:yellow">' . _('Note').' - '. 70 _('Index already exists') . '</td></tr>'; 71 break; 72 case 1062: 73 echo '<tr><td>' . $comment . '</td><td style="background-color:yellow">' . _('Note').' - '. 74 _('Entry has already been done') . '</td></tr>'; 75 break; 76 case 1068: 77 echo '<tr><td>' . $comment . '</td><td style="background-color:yellow">' . _('Note').' - '. 78 _('Primary key already exists') . '</td></tr>'; 79 break; 80 default: 81 echo '<tr><td>' . $comment . '</td><td style="background-color:red">' . _('Failure').' - '. 82 _('Error number').' - '.DB_error_no() . '</td></tr>'; 83 break; 84 } 85 unset($sql); 86 } 87 88 } //end if its a valid sql line not a comment 89 } //end of for loop around the lines of the sql script 90 echo '</table>'; 91 92 /*Now run the data conversions required. */ 93 94} /*Dont do upgrade */ 95 96include('includes/footer.php'); 97?> 98