00001
00002 <style type="text/css">
00003 <!--
00004 body {
00005 font-family:sans-serif;
00006 font-size:12px;
00007 color:blue;
00008 }
00009 h2.info {
00010 color:green;
00011 font-size:20px;
00012 font-family:sans-serif;
00013 }
00014 h2.error {
00015 color:red;
00016 font-size:20px;
00017 font-family:sans-serif;
00018 }
00019 .warning {
00020 font-family:sans-serif;
00021 font-size:12px;
00022 color:red;
00023 }
00024 .info {
00025 color:green;
00026 font-size:12px;
00027 font-family:sans-serif;
00028 }
00029
00030 -->
00031 </style>
00032 <p align="center">
00033 <IMG SRC="../image/logo7.jpg" alt="Logo">
00034 </p>
00035 <?
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00063 $inc_path=get_include_path();
00064 if ( strpos($inc_path,";") != 0 ) {
00065 $new_path=$inc_path.';..\..\include;addon';
00066 } else {
00067 $new_path=$inc_path.':../../include:addon';
00068 }
00069
00070 set_include_path($new_path);
00071
00072 include_once('constant.php');
00073 include_once('postgres.php');
00074 include_once('debug.php');
00075 include_once('ac_common.php');
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087 function GetVersion($p_cn) {
00088 $Res=ExecSql($p_cn,"select val from version");
00089 $a=pg_fetch_array($Res,0);
00090 return $a['val'];
00091 }
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104 function ExecuteScript($p_cn,$script) {
00105 $hf=fopen($script,'r');
00106 if ( $hf == false ) {
00107 echo 'Ne peut ouvrir '.$script;
00108 exit();
00109 }
00110 $sql="";
00111 $flag_function=false;
00112 while (!feof($hf)) {
00113 $buffer=fgets($hf);
00114 $buffer=str_replace ("$","\$",$buffer);
00115 print $buffer."<br>";
00116
00117 if ( substr($buffer,0,2) == "--" ) {
00118
00119 continue;
00120 }
00121
00122 If ( Strlen($buffer)==0) {
00123
00124 Continue;
00125 }
00126 if ( strpos(strtolower($buffer),"create function")===0 ) {
00127 echo "found a function";
00128 $flag_function=true;
00129 $sql=$buffer;
00130 continue;
00131 }
00132 if ( strpos(strtolower($buffer),"create or replace function")===0 ) {
00133 echo "found a function";
00134 $flag_function=true;
00135 $sql=$buffer;
00136 continue;
00137 }
00138
00139 if ( $flag_function== false && strpos($buffer,';') == false ) {
00140 $sql.=$buffer;
00141 continue;
00142 }
00143 if ( $flag_function ) {
00144 if ( strpos(strtolower($buffer), "language plpgsql") === false &&
00145 strpos(strtolower($buffer), "language 'plpgsql'") === false ) {
00146 $sql.=$buffer;
00147 continue;
00148 }
00149 } else {
00150
00151 $buffer=str_replace (';','',$buffer);
00152 }
00153 $sql.=$buffer;
00154 if ( ExecSql($p_cn,$sql) == false ) {
00155 Rollback($p_cn);
00156 if ( DEBUG=='false' ) ob_end_flush();
00157 print "ERROR : $sql";
00158 exit();
00159 }
00160 $sql="";
00161 $flag_function=false;
00162 print "<hr>";
00163 }
00164 fclose($hf);
00165 }
00166
00167
00168
00169
00170
00171
00172
00173 ?>
00174 <h2>Info</h2>
00175 Vous utilisez le domaine <? echo domaine; ?>
00176 <h2>Php setting</h2>
00177 <?
00178
00179 $flag_php=0;
00180 foreach (array('magic_quotes_gpc','magic_quotes_runtime') as $a) {
00181
00182 if ( ini_get($a) == false ) print $a.': Ok <br>';
00183 else {
00184 print ("<h2 class=\"error\">$a has a bad value !!!</h2>");
00185 $flag_php++;
00186 }
00187
00188 }
00189 if ( ini_get("max_execution_time") < 60 ) {
00190 print '<h2 class="info"> max_execution_time should be set to 60 minimum</h2>';
00191 }
00192 if ( ini_get("session.auto_start") == false ) {
00193 print '<h2 class="error"> session.auto_start must be set to true </h2>';
00194 $flag_php++;
00195 }
00196 if ( ini_get("session.use_trans_sid") == false ) {
00197 print '<h2 class="error"> avertissement session.use_trans_sid should be set to true </h2>';
00198 }
00199 if ( ereg("..\/include",$inc_path) == 0 and ereg("..\\include",$inc_path) == 0)
00200 {
00201 print ("<h2 class=\"error\">include_path incorrect !!!".$inc_path."</h2>");
00202 $flag_php++;
00203 }
00204 else
00205 if ( ereg("addon",$inc_path) == 0) {
00206 print ("<h2 class=\"error\">include_path incorrect !!!".$inc_path."</h2>");
00207 $flag_php++;
00208 }else
00209 print 'include_path : ok ('.$inc_path.')<br>';
00210
00211 if ( $flag_php==0 ) {
00212 echo '<p class="info">php.ini est bien configuré</p>';
00213 } else {
00214 echo '<p class="error"> php mal configuré</p>';
00215 exit -1;
00216 }
00217 $cn=DbConnect(-2,'phpcompta');
00218
00219 if ($cn == false ) {
00220 print "<p> Vous devez absolument taper dans une console la commande 'createuser -A -d -P phpcompta et vous donnez dany comme mot de passe (voir la documentation)'
00221 puis la commande 'createdb -O phpcompta phpcompta'. </p>
00222 <p>Ces commandes créeront l'utilisateur phpcompta
00223 puis la base de données par défaut de phpcompta.</p>";
00224 exit();
00225 }
00226 ?>
00227 <h2>Database version </h2>
00228 <?
00229
00230
00231 $sql="select setting from pg_settings where name='server_version'";
00232 $Res=ExecSql($cn,$sql);
00233 $row=pg_fetch_array($Res,0);
00234 $version=$row[0];
00235
00236 var_dump($version);
00237
00238 if ( $version[0] != '8' ) {
00239 ?>
00240 <p> Vous devez absolument utiliser au minimum une version 8 de PostGresql, si votre distribution n'en
00241 offre pas, installez en une en la compilant. </p><p>Lisez attentivement la notice sur postgresql.org pour migrer
00242 vos bases de données en 8
00243 </p>
00244 <? exit();
00245 }
00246
00247 ?>
00248 <h2>Database Setting</h2>
00249 <?
00250
00251
00252 $sql="select lanname from pg_language where lanname='plpgsql'";
00253 $Res=CountSql($cn,$sql);
00254 if ( $Res==0) { ?>
00255 <p> Vous devez installer le langage plpgsql pour permettre aux fonctions SQL de fonctionner.</p>
00256 <p>Pour cela, sur la ligne de commande, faites
00257 createlang plpgsql pour chaque base de données que vous possédez (y compris template0 et template1).
00258 </p>
00259 <p>Pour afficher toutes les bases de données, tapez sur la ligne de commande "psql -l"</p>
00260 <? exit(); }
00261
00262
00263
00264 $sql="select name,setting
00265 from pg_settings
00266 where
00267 name in ('effective_cache_size','shared_buffers','work_mem')";
00268 $Res=ExecSql($cn,$sql);
00269 $flag=0;
00270 for ($e=0;$e<pg_NumRows($Res);$e++) {
00271 $a=pg_fetch_array($Res,$e);
00272 switch ($a['name']){
00273 case 'effective_cache_size':
00274 if ( $a['setting'] < 1000 ){
00275 print '<p class="warning">Attention le paramètre effective_cache_size est de '.
00276 $a['setting']." au lieu de 1000 </p>";
00277 $flag++;
00278 }
00279 break;
00280 case 'shared_buffers':
00281 if ( $a['setting'] < 640 ){
00282 print '<p class="warning">Attention le paramètre shared_buffer est de '.
00283 $a['setting']."au lieu de 640</p>";
00284 $flag++;
00285 }
00286 break;
00287 case 'work_mem':
00288 if ( $a['setting'] < 8192 ){
00289 print '<p class="warning">Attention le paramètre work_mem est de '.
00290 $a['setting']." au lieu de 8192 </p>";
00291 $flag++;
00292 }
00293 break;
00294
00295 }
00296 }
00297 if ( $flag == 0 ) {
00298 echo '<p class="info">La base de données est bien configurée</p>';
00299 } else {
00300 echo '<p class="warning">Il y a '.$flag.' paramètre qui sont trop bas</p>';
00301 }
00302 if ( ! isset($_POST['go']) ) {
00303 ?>
00304 <FORM action="setup.php" METHOD="post">
00305 <input type="submit" name="go" value="Prêt à commencer la mise à jour ou l'installation?">
00306 </form>
00307 <?
00308 }
00309 if ( ! isset($_POST['go']) )
00310 exit();
00311
00312 $account=CountSql($cn,
00313 "select * from pg_database where datname='".domaine."account_repository'");
00314
00315
00316 if ($account == 0 ) {
00317
00318 echo "Creation of ".domaine."account_repository";
00319 if ( DEBUG=='false') ob_start();
00320 ExecSql($cn,"create database ".domaine."account_repository encoding='latin1'");
00321 $cn=DbConnect();
00322 ExecuteScript($cn,"sql/account_repository/schema.sql");
00323 ExecuteScript($cn,"sql/account_repository/data.sql");
00324 if ( DEBUG=='false') ob_end_clean();
00325 echo "Creation of Démo";
00326 if ( DEBUG=='false') ob_start();
00327 ExecSql($cn,"create database ".domaine."dossier1 encoding='latin1'");
00328 $cn=DbConnect(1,'dossier');
00329 ExecuteScript($cn,'sql/dossier1/schema.sql');
00330 ExecuteScript($cn,'sql/dossier1/data.sql');
00331 if ( DEBUG=='false') ob_end_clean();
00332
00333 echo "Creation of Modele1";
00334 if ( DEBUG=='false') ob_start();
00335 ExecSql($cn,"create database ".domaine."mod1 encoding='latin1'");
00336 $cn=DbConnect(1,'mod');
00337 ExecuteScript($cn,'sql/mod1/schema.sql');
00338 ExecuteScript($cn,'sql/mod1/data.sql');
00339 if ( DEBUG=='false') ob_end_clean();
00340 }
00341
00342
00343 $cn=DbConnect();
00344 $Res=CountSql($cn,"select * from modeledef where mod_id=2");
00345
00346
00347 if ( $Res == 1 )
00348 {
00349 $cn=DbConnect();
00350 ExecSql($cn,"drop database ".domaine."mod2;");
00351 ExecSql($cn,"delete from modeledef where mod_id=2");
00352 }
00353
00354 $Res=CountSql($cn,"select * from modeledef where mod_id=2");
00355 if ( $Res == 0) {
00356 echo "Creation of Modele2";
00357 ExecSql($cn,"create database ".domaine."mod2 encoding='latin1'");
00358 $cn=DbConnect(2,'mod');
00359 if ( DEBUG=='false') { ob_start(); }
00360 ExecuteScript($cn,'sql/mod2/schema.sql');
00361 ExecuteScript($cn,'sql/mod2/data.sql');
00362 $sql="INSERT INTO modeledef VALUES (2, '(FR) Basique', 'Comptabilité Française, tout doit être adaptée');";
00363 $cn=DbConnect();
00364 ExecSql($cn,$sql);
00365 if ( DEBUG=='false') ob_end_clean();
00366 }
00367
00368
00369
00370 $a=DbConnect();
00371 if ( $a==false) {
00372 exit ("<h2 class=\"error\">".__LINE__." test has failed !!!</h2>");
00373
00374 }
00375 if ( ($Res=ExecSql($a,"select * from ac_users") ) == false ) {
00376 exit ("<h2 class=\"error\">".__LINE__." test has failed !!!</h2>");
00377 } else
00378 print "Connect to database success <br>";
00379 echo "<h2 class=\"info\"> Congratulation : Test successfull</h2>";
00380
00381 echo "<h2 class=\"info\"> Patching databases</h2>";
00382
00383 $cn=DbConnect();
00384 $Resdossier=ExecSql($cn,"select dos_id, dos_name from ac_dossier");
00385 $MaxDossier=pg_NumRows($Resdossier);
00386
00387 for ($e=0;$e < $MaxDossier;$e++) {
00388 $db_row=pg_fetch_array($Resdossier,$e);
00389 $db=DbConnect($db_row['dos_id'],'dossier');
00390 echo "Patching ".$db_row['dos_name']." from the version ".GetVersion($db)."<hr>";
00391 if ( DEBUG=='false' ) ob_start();
00392 if ( GetVersion($db) <= 4 ) {
00393 ExecuteScript($db,'sql/patch/upgrade4.sql');
00394
00395 $sql="select jrn_def_id from jrn_def ";
00396 $Res=ExecSql($db,$sql);
00397 $Max=pg_NumRows($Res);
00398 for ($seq=0;$seq<$Max;$seq++) {
00399 $row=pg_fetch_array($Res,$seq);
00400 $sql=sprintf ("create sequence s_jrn_%d",$row['jrn_def_id']);
00401 ExecSql($db,$sql);
00402 }
00403 }
00404
00405
00406
00407 if ( GetVersion($db) == 5 ) {
00408 ExecuteScript($db,'sql/patch/upgrade5.sql');
00409 }
00410
00411
00412
00413
00414
00415 if ( GetVersion($db) == 6 ) {
00416 ExecuteScript($db,'sql/patch/upgrade6.sql');
00417 }
00418
00419
00420
00421
00422 if ( GetVersion($db) == 7 ) {
00423 ExecuteScript($db,'sql/patch/upgrade7.sql');
00424
00425
00426 $Res2=ExecSql($db,'select coalesce(max(jr_grpt_id),1) as l from jrn');
00427 $Max2= pg_NumRows($Res2) ;
00428 if ( $Max2 == 1) {
00429 $Row=pg_fetch_array($Res2,0);
00430 var_dump($Row);
00431 $M=$Row['l'];
00432 ExecSql($db,"select setval('s_grpt',$M,true)");
00433 }
00434 }
00435
00436 if ( GetVersion($db) == 8 ) {
00437 ExecuteScript($db,'sql/patch/upgrade8.sql');
00438 }
00439 if ( GetVersion($db) == 9 ) {
00440 ExecuteScript($db,'sql/patch/upgrade9.sql');
00441 }
00442 if ( GetVersion($db) == 10 ) {
00443 ExecuteScript($db,'sql/patch/upgrade10.sql');
00444 }
00445 if ( GetVersion($db) == 11 ) {
00446 ExecuteScript($db,'sql/patch/upgrade11.sql');
00447 }
00448 if ( GetVersion($db) == 12 ) {
00449 ExecuteScript($db,'sql/patch/upgrade12.sql');
00450 }
00451
00452 if ( GetVersion($db) == 13 ) {
00453 ExecuteScript($db,'sql/patch/upgrade13.sql');
00454 }
00455
00456
00457 if ( DEBUG == 'false') ob_end_clean();
00458 }
00459
00460 $Resdossier=ExecSql($cn,"select mod_id, mod_name from modeledef");
00461 $MaxDossier=pg_NumRows($Resdossier);
00462 echo "Upgrading Dossier";
00463 for ($e=0;$e < $MaxDossier;$e++) {
00464 $db_row=pg_fetch_array($Resdossier,$e);
00465 echo "Patching ".$db_row['mod_name']."<hr>";
00466 $db=DbConnect($db_row['mod_id'],'mod');
00467 if (DEBUG == 'false' ) ob_start();
00468 if ( GetVersion($db) <= 4 ) {
00469 ExecuteScript($db,'sql/patch/upgrade4.sql');
00470
00471 $sql="select jrn_def_id from jrn_def ";
00472 $Res=ExecSql($db,$sql);
00473 $Max=pg_NumRows($Res);
00474 for ($seq=0;$seq<$Max;$seq++) {
00475 $row=pg_fetch_array($Res,$seq);
00476 $sql=sprintf ("create sequence s_jrn_%d",$row['jrn_def_id']);
00477 ExecSql($db,$sql);
00478 }
00479 }
00480 if ( GetVersion($db) == 5 ) {
00481 ExecuteScript($db,'sql/patch/upgrade5.sql');
00482 }
00483
00484
00485
00486
00487
00488 if ( GetVersion($db) == 6 ) {
00489 ExecuteScript($db,'sql/patch/upgrade6.sql');
00490 }
00491
00492
00493
00494
00495 if ( GetVersion($db) == 7 ) {
00496 ExecuteScript($db,'sql/patch/upgrade7.sql');
00497
00498
00499 $Res2=ExecSql($db,'select coalesce(max(jr_grpt_id),1) as l from jrn');
00500 $Max2= pg_NumRows($Res2) ;
00501 if ( $Max2 == 1) {
00502 $Row=pg_fetch_array($Res2,0);
00503 $M=$Row['l'];
00504 ExecSql($db,"select setval('s_grpt',$M,true)");
00505 }
00506 }
00507
00508
00509
00510 if ( GetVersion($db) == 8 ) {
00511 ExecuteScript($db,'sql/patch/upgrade8.sql');
00512 }
00513
00514
00515 if ( GetVersion($db) == 9 ) {
00516 ExecuteScript($db,'sql/patch/upgrade9.sql');
00517 }
00518 if ( GetVersion($db) == 10 ) {
00519 ExecuteScript($db,'sql/patch/upgrade10.sql');
00520 }
00521 if ( GetVersion($db) == 11 ) {
00522 ExecuteScript($db,'sql/patch/upgrade11.sql');
00523 }
00524 if ( GetVersion($db) == 12 ) {
00525 ExecuteScript($db,'sql/patch/upgrade12.sql');
00526 }
00527 if ( GetVersion($db) == 13 ) {
00528 ExecuteScript($db,'sql/patch/upgrade13.sql');
00529 }
00530
00531 if ( DEBUG == 'false') ob_end_clean();
00532 }
00533
00534 echo "Upgrading Repository";
00535 $cn=DbConnect();
00536 if ( DEBUG == 'false') ob_start();
00537 if ( GetVersion($cn) <= 4 ) {
00538 ExecuteScript($cn,'sql/patch/ac-upgrade4.sql');
00539 }
00540 if ( GetVersion($cn) == 5 ) {
00541 ExecuteScript($cn,'sql/patch/ac-upgrade5.sql');
00542 }
00543 if ( GetVersion($cn) == 6 ) {
00544 ExecuteScript($cn,'sql/patch/ac-upgrade6.sql');
00545 }
00546 if ( GetVersion($cn) == 7 ) {
00547 ExecuteScript($cn,'sql/patch/ac-upgrade7.sql');
00548 }
00549
00550 if (DEBUG=='false') ob_end_clean();
00551 echo "<h2 class=\"info\">Voilà tout est installé ;-)</h2>";