<?php 
error_reporting(E_ALL);
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
ini_set('display_errors', '1');
// session_start();
require_once 'EPPersistentDataManager.php';
require_once '../php/EPConfigFile.php';
require_once '../php/EPListProvider.php';
require_once '../php/EPConfigFile.php';
require_once '../php/EPBackground.php';
require_once '../php/EPTrait.php';
require_once '../php/EPGear.php';
require_once '../php/EPPsySleight.php';
$epListP = new EPListProvider('../php/config.ini');
$persistManager = new EPPersistentDataManager('../php/config.ini');
$_SESSION['backgroundList'] = $epListP->getListBackgrounds();
$_SESSION['traitList'] = $epListP->getListTraits();
$_SESSION['gearList'] = $epListP->getListGears();
$_SESSION['psyList'] = $epListP->getListPsySleights();
$_SESSION['morphList'] = $epListP->getListMorph();
$_SESSION['aiList'] = $epListP->getListAi();
if (isset($_POST['addBook'])) {
    $totalInject = array();
    if (isset($_POST['selectedBackground'])) {
        foreach ($_POST['selectedBackground'] as $b) {
            array_push($totalInject, $b);
        }
    }
    if (isset($_POST['selectedTraits'])) {
        foreach ($_POST['selectedTraits'] as $t) {
            array_push($totalInject, $t);
 $bm2_1 = new EPBonusMalus("Free Networking 20 Bonus", EPBonusMalus::$ON_SKILL_PREFIX, 20, "Networking", "", array("Hacker pack", "Scientist base tech"));
 $bm2_2 = new EPBonusMalus("Free Networking 20 Bonus", EPBonusMalus::$ON_SKILL_PREFIX, 20, "Networking", "", array("Hacker pack", "Scientist base tech"));
 $trait = new EPTrait("Test Trait 1", "Not existing in the rule, just for test", EPTrait::$POSITIVE_TRAIT, EPTrait::$MORPH_TRAIT, 10, $bonusMalusArray);
 array_push($backgrounds, new EPBackground('Origine Test ', 'Bla bla bla bla', EPBackground::$ORIGIN, array($bm1_1, $bm1_2, $bm1_3, $bm2_2), array($trait), array('Limitation group 1 ', 'Limitation group 2'), array('Obligation group 1', 'Obligation group 2')));
 array_push($backgrounds, new EPBackground('Faction Test ', 'Fla fla fla fla', EPBackground::$FACTION, array($bm2_1, $bm2_2, $bm1_2), array($trait), array('Limitation faction group 1 ', 'Limitation  factiongroup 2'), array('Obligation  faction group 1', 'Obligation faction group 2')));
 foreach ($backgrounds as $m) {
     if (!$persistManager->persistBackground($m)) {
         echo $persistManager->getLastError();
         echo "<br>";
     } else {
         echo "DONE ! <br>";
     }
 }
 //Echo Background list
 echo "<br><br>BACKGROUND LIST------------------------------------------ <br><br>";
 $bcksList = $listProvider->getListBackgrounds();
 if ($bcksList == null) {
     echo $listProvider->getLastError();
     echo "<br>";
 } else {
     foreach ($bcksList as $m) {
         echo $m->name . " : " . $m->description . " Types : " . $m->backgroundType;
         echo '<br>';
         $malusBonus = $m->bonusMalus;
         echo "With BonusMalus : <br>";
         foreach ($malusBonus as $o) {
             echo $o->name . " - " . $o->description . " - Type : " . $o->bonusMalusType . " - for target : " . $o->forTargetNamed . " - value : " . $o->value . "<br>";
         }
         echo '<br>';
         $traits = $m->traits;
         echo "With Traits : <br>";