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 if ( $version[0] != '8' ) {
00237 ?>
00238 <p> Vous devez absolument utiliser au minimum une version 8 de PostGresql, si votre distribution n'en
00239 offre pas, installez en une en la compilant. </p><p>Lisez attentivement la notice sur postgresql.org pour migrer
00240 vos bases de données en 8
00241 </p>
00242 <? exit();
00243 }
00244
00245 ?>
00246 <h2>Database Setting</h2>
00247 <?
00248
00249
00250 $sql="select lanname from pg_language where lanname='plpgsql'";
00251 $Res=CountSql($cn,$sql);
00252 if ( $Res==0) { ?>
00253 <p> Vous devez installer le langage plpgsql pour permettre aux fonctions SQL de fonctionner.</p>
00254 <p>Pour cela, sur la ligne de commande, faites
00255 createlang plpgsql pour chaque base de données que vous possédez (y compris template0 et template1).
00256 </p>
00257 <p>Pour afficher toutes les bases de données, tapez sur la ligne de commande "psql -l"</p>
00258 <? exit(); }
00259
00260
00261
00262 $sql="select name,setting
00263 from pg_settings
00264 where
00265 name in ('effective_cache_size','shared_buffers','work_mem')";
00266 $Res=ExecSql($cn,$sql);
00267 $flag=0;
00268 for ($e=0;$e<pg_NumRows($Res);$e++) {
00269 $a=pg_fetch_array($Res,$e);
00270 switch ($a['name']){
00271 case 'effective_cache_size':
00272 if ( $a['setting'] < 1000 ){
00273 print '<p class="warning">Attention le paramètre effective_cache_size est de '.
00274 $a['setting']." au lieu de 1000 </p>";
00275 $flag++;
00276 }
00277 break;
00278 case 'shared_buffers':
00279 if ( $a['setting'] < 640 ){
00280 print '<p class="warning">Attention le paramètre shared_buffer est de '.
00281 $a['setting']."au lieu de 640</p>";
00282 $flag++;
00283 }
00284 break;
00285 case 'work_mem':
00286 if ( $a['setting'] < 8192 ){
00287 print '<p class="warning">Attention le paramètre work_mem est de '.
00288 $a['setting']." au lieu de 8192 </p>";
00289 $flag++;
00290 }
00291 break;
00292
00293 }
00294 }
00295 if ( $flag == 0 ) {
00296 echo '<p class="info">La base de données est bien configurée</p>';
00297 } else {
00298 echo '<p class="warning">Il y a '.$flag.' paramètre qui sont trop bas</p>';
00299 }
00300 if ( ! isset($_POST['go']) ) {
00301 ?>
00302 <FORM action="setup.php" METHOD="post">
00303 <input type="submit" name="go" value="Prêt à commencer la mise à jour ou l'installation?">
00304 </form>
00305 <?
00306 }
00307 if ( ! isset($_POST['go']) )
00308 exit();
00309
00310 $account=CountSql($cn,
00311 "select * from pg_database where datname='".domaine."account_repository'");
00312
00313
00314 if ($account == 0 ) {
00315
00316 echo "Creation of ".domaine."account_repository";
00317 if ( DEBUG=='false') ob_start();
00318 ExecSql($cn,"create database ".domaine."account_repository encoding='latin1'");
00319 $cn=DbConnect();
00320 ExecuteScript($cn,"sql/account_repository/schema.sql");
00321 ExecuteScript($cn,"sql/account_repository/data.sql");
00322 if ( DEBUG=='false') ob_end_clean();
00323 echo "Creation of Démo";
00324 if ( DEBUG=='false') ob_start();
00325 ExecSql($cn,"create database ".domaine."dossier1 encoding='latin1'");
00326 $cn=DbConnect(1,'dossier');
00327 ExecuteScript($cn,'sql/dossier1/schema.sql');
00328 ExecuteScript($cn,'sql/dossier1/data.sql');
00329 if ( DEBUG=='false') ob_end_clean();
00330
00331 echo "Creation of Modele1";
00332 if ( DEBUG=='false') ob_start();
00333 ExecSql($cn,"create database ".domaine."mod1 encoding='latin1'");
00334 $cn=DbConnect(1,'mod');
00335 ExecuteScript($cn,'sql/mod1/schema.sql');
00336 ExecuteScript($cn,'sql/mod1/data.sql');
00337 if ( DEBUG=='false') ob_end_clean();
00338 }
00339
00340
00341 $cn=DbConnect();
00342 $Res=CountSql($cn,"select * from modeledef where mod_id=2");
00343
00344
00345 if ( $Res == 1 )
00346 {
00347 $cn=DbConnect();
00348 ExecSql($cn,"drop database mod2;");
00349 ExecSql($cn,"delete from modeledef where mod_id=2");
00350 }
00351
00352 $Res=CountSql($cn,"select * from modeledef where mod_id=2");
00353 if ( $Res == 0) {
00354 echo "Creation of Modele2";
00355 ExecSql($cn,"create database ".domaine."mod2 encoding='latin1'");
00356 $cn=DbConnect(2,'mod');
00357 if ( DEBUG=='false') { ob_start(); }
00358 ExecuteScript($cn,'sql/mod2/schema.sql');
00359 ExecuteScript($cn,'sql/mod2/data.sql');
00360 $sql="INSERT INTO modeledef VALUES (2, '(FR) Basique', 'Comptabilité Française, tout doit être adaptée');";
00361 $cn=DbConnect();
00362 ExecSql($cn,$sql);
00363 if ( DEBUG=='false') ob_end_clean();
00364 }
00365
00366
00367
00368 $a=DbConnect();
00369 if ( $a==false) {
00370 exit ("<h2 class=\"error\">".__LINE__." test has failed !!!</h2>");
00371
00372 }
00373 if ( ($Res=ExecSql($a,"select * from ac_users") ) == false ) {
00374 exit ("<h2 class=\"error\">".__LINE__." test has failed !!!</h2>");
00375 } else
00376 print "Connect to database success <br>";
00377 echo "<h2 class=\"info\"> Congratulation : Test successfull</h2>";
00378
00379 echo "<h2 class=\"info\"> Patching databases</h2>";
00380
00381 $cn=DbConnect();
00382 $Resdossier=ExecSql($cn,"select dos_id, dos_name from ac_dossier");
00383 $MaxDossier=pg_NumRows($Resdossier);
00384
00385 for ($e=0;$e < $MaxDossier;$e++) {
00386 $db_row=pg_fetch_array($Resdossier,$e);
00387 $db=DbConnect($db_row['dos_id'],'dossier');
00388 echo "Patching ".$db_row['dos_name']." from the version ".GetVersion($db)."<hr>";
00389 if ( DEBUG=='false' ) ob_start();
00390 if ( GetVersion($db) <= 4 ) {
00391 ExecuteScript($db,'sql/patch/upgrade4.sql');
00392
00393 $sql="select jrn_def_id from jrn_def ";
00394 $Res=ExecSql($db,$sql);
00395 $Max=pg_NumRows($Res);
00396 for ($seq=0;$seq<$Max;$seq++) {
00397 $row=pg_fetch_array($Res,$seq);
00398 $sql=sprintf ("create sequence s_jrn_%d",$row['jrn_def_id']);
00399 ExecSql($db,$sql);
00400 }
00401 }
00402
00403
00404
00405 if ( GetVersion($db) == 5 ) {
00406 ExecuteScript($db,'sql/patch/upgrade5.sql');
00407 }
00408
00409
00410
00411
00412
00413 if ( GetVersion($db) == 6 ) {
00414 ExecuteScript($db,'sql/patch/upgrade6.sql');
00415 }
00416
00417
00418
00419
00420 if ( GetVersion($db) == 7 ) {
00421 ExecuteScript($db,'sql/patch/upgrade7.sql');
00422
00423
00424 $Res2=ExecSql($db,'select coalesce(max(jr_grpt_id),1) as l from jrn');
00425 $Max2= pg_NumRows($Res2) ;
00426 if ( $Max2 == 1) {
00427 $Row=pg_fetch_array($Res2,0);
00428 var_dump($Row);
00429 $M=$Row['l'];
00430 ExecSql($db,"select setval('s_grpt',$M,true)");
00431 }
00432 }
00433
00434 if ( GetVersion($db) == 8 ) {
00435 ExecuteScript($db,'sql/patch/upgrade8.sql');
00436 }
00437 if ( GetVersion($db) == 9 ) {
00438 ExecuteScript($db,'sql/patch/upgrade9.sql');
00439 }
00440 if ( GetVersion($db) == 10 ) {
00441 ExecuteScript($db,'sql/patch/upgrade10.sql');
00442 }
00443 if ( GetVersion($db) == 11 ) {
00444 ExecuteScript($db,'sql/patch/upgrade11.sql');
00445 }
00446 if ( GetVersion($db) == 12 ) {
00447 ExecuteScript($db,'sql/patch/upgrade12.sql');
00448 }
00449
00450 if ( GetVersion($db) == 13 ) {
00451 ExecuteScript($db,'sql/patch/upgrade13.sql');
00452 }
00453
00454
00455 if ( DEBUG == 'false') ob_end_clean();
00456 }
00457
00458 $Resdossier=ExecSql($cn,"select mod_id, mod_name from modeledef");
00459 $MaxDossier=pg_NumRows($Resdossier);
00460 echo "Upgrading Dossier";
00461 for ($e=0;$e < $MaxDossier;$e++) {
00462 $db_row=pg_fetch_array($Resdossier,$e);
00463 echo "Patching ".$db_row['mod_name']."<hr>";
00464 $db=DbConnect($db_row['mod_id'],'mod');
00465 if (DEBUG == 'false' ) ob_start();
00466 if ( GetVersion($db) <= 4 ) {
00467 ExecuteScript($db,'sql/patch/upgrade4.sql');
00468
00469 $sql="select jrn_def_id from jrn_def ";
00470 $Res=ExecSql($db,$sql);
00471 $Max=pg_NumRows($Res);
00472 for ($seq=0;$seq<$Max;$seq++) {
00473 $row=pg_fetch_array($Res,$seq);
00474 $sql=sprintf ("create sequence s_jrn_%d",$row['jrn_def_id']);
00475 ExecSql($db,$sql);
00476 }
00477 }
00478 if ( GetVersion($db) == 5 ) {
00479 ExecuteScript($db,'sql/patch/upgrade5.sql');
00480 }
00481
00482
00483
00484
00485
00486 if ( GetVersion($db) == 6 ) {
00487 ExecuteScript($db,'sql/patch/upgrade6.sql');
00488 }
00489
00490
00491
00492
00493 if ( GetVersion($db) == 7 ) {
00494 ExecuteScript($db,'sql/patch/upgrade7.sql');
00495
00496
00497 $Res2=ExecSql($db,'select coalesce(max(jr_grpt_id),1) as l from jrn');
00498 $Max2= pg_NumRows($Res2) ;
00499 if ( $Max2 == 1) {
00500 $Row=pg_fetch_array($Res2,0);
00501 $M=$Row['l'];
00502 ExecSql($db,"select setval('s_grpt',$M,true)");
00503 }
00504 }
00505
00506
00507
00508 if ( GetVersion($db) == 8 ) {
00509 ExecuteScript($db,'sql/patch/upgrade8.sql');
00510 }
00511
00512
00513 if ( GetVersion($db) == 9 ) {
00514 ExecuteScript($db,'sql/patch/upgrade9.sql');
00515 }
00516 if ( GetVersion($db) == 10 ) {
00517 ExecuteScript($db,'sql/patch/upgrade10.sql');
00518 }
00519 if ( GetVersion($db) == 11 ) {
00520 ExecuteScript($db,'sql/patch/upgrade11.sql');
00521 }
00522 if ( GetVersion($db) == 12 ) {
00523 ExecuteScript($db,'sql/patch/upgrade12.sql');
00524 }
00525 if ( GetVersion($db) == 13 ) {
00526 ExecuteScript($db,'sql/patch/upgrade13.sql');
00527 }
00528
00529 if ( DEBUG == 'false') ob_end_clean();
00530 }
00531
00532 echo "Upgrading Repository";
00533 $cn=DbConnect();
00534 if ( DEBUG == 'false') ob_start();
00535 if ( GetVersion($cn) <= 4 ) {
00536 ExecuteScript($cn,'sql/patch/ac-upgrade4.sql');
00537 }
00538 if ( GetVersion($cn) == 5 ) {
00539 ExecuteScript($cn,'sql/patch/ac-upgrade5.sql');
00540 }
00541 if ( GetVersion($cn) == 6 ) {
00542 ExecuteScript($cn,'sql/patch/ac-upgrade6.sql');
00543 }
00544 if ( GetVersion($cn) == 7 ) {
00545 ExecuteScript($cn,'sql/patch/ac-upgrade7.sql');
00546 }
00547
00548 if (DEBUG=='false') ob_end_clean();
00549 echo "<h2 class=\"info\">Voilà tout est installé ;-)</h2>";