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