extranet/includes/annonces/annonces.php
2010-12-17 14:37:52 +00:00

218 lines
7.5 KiB
PHP

<?php
// -------------------------------------------------------------------------- //
// class Annonces
// -------------------------------------------------------------------------- //
function afficheListeAnnonces(&$annonces, $siret, $idEntreprise)
{
if (count($annonces) > 0) {
$objAnnonces = new Annonces($annonces->liste->item);
$typeAnnonces =
array('Bodacc' => 'EV&Eacute;NEMENTS L&Eacute;GAUX',
'Balo' => 'BALO',
'Bomp' => 'March&eacute;s publics',
'Asso' => 'Associations');
foreach ($typeAnnonces as $type => $titre) {
$classType = 'annonces'.$type;
if (count($objAnnonces->$classType) > 0) {
print '<h2>'.$titre.'</h2>';
print '<table>';
foreach ($objAnnonces->$classType as $ann) {
$resume = $objAnnonces->getAnnonceResume($ann);
print '<tr>';
print '<td width="30">&nbsp;</td>';
print '<td width="140" class="StyleInfoLib">';
print '<span id="annoncesDate">Le '.$resume['date'].
' </span>';
print '<span id="annoncesImg">'.$resume['logo'].'</span>';
print '</td>';
print '<td width="450" colspan="2" class="StyleInfoData">';
print '<a href="/?page=annonces&siret='.$siret.
'&idEntreprise='.$idEntreprise.'&'.$resume['href'].'">';
print $resume['lib'];
print '</a>';
print '</td>';
print '</tr>';
}
print '</table>';
}
}
} else {
// Aucune annonce bodacc pour cette entreprise
print '<h2>Evénements légaux</h2>';
print '<table>';
print '<tr>';
print '<td width="30">&nbsp;</td>';
print '<td width="100" class="StyleInfoLib">&nbsp;</td>';
print '<td width="450" colspan="2" class="StyleInfoData">'.
'N&eacute;ant</td>';
print '</tr>';
print '<tr>';
print '<td colspan="4">&nbsp;</td>';
print '</tr>';
print '</table>';
}
}
// -------------------------------------------------------------------------- //
// class Annonces
// -------------------------------------------------------------------------- //
class Annonces
{
public $annoncesBodacc = array();
public $annoncesBalo = array();
public $annoncesAsso = array();
public $annoncesBomp = array();
protected $annonces;
public function __construct($annonces = array())
{
if (is_array($annonces) && count($annonces) > 0) {
$this->annonces = $annonces;
$this->triAnnonces();
}
}
public function getAnnonceResume($ann)
{
return
array('date' => $this->dateAnnonce($ann->DateParution),
'logo' => $this->logoAnnonce($ann),
'href' => $this->hrefAnnonce($ann),
'lib' => $this->libAnnonce($ann));
}
protected function hrefAnnonce($ann)
{
$href = false;
if ($this->isBodacc($ann->BodaccCode)){
$href = 'idan='.$ann->id.'&vue=bodacc';
} else if ($this->isBalo($ann->BodaccCode)) {
$href = 'idan='.$ann->id.'&vue=balo';
} else if ($this->isAsso($ann->BodaccCode)) {
$href = 'idan='.$ann->id.'&vue=asso';
} else if ($this->isBomp($ann->BodaccCode)) {
$href = 'idan='.$ann->id.'&vue=bomp';
} else {
$href = 'idan='.$ann->id.'&vue=bodacc';
}
return $href;
}
protected function dateAnnonce($date)
{
$wdate = new WDate;
return $wdate->dateT('Y-m-d', 'd/m/Y', $date);
}
protected function logoAnnonce($ann)
{
$src = '';
$title = '';
if ($this->isBalo($ann->BodaccCode)) {
$src = './img/logo_jo.png';
$title = 'Source BALO n&deg;'.$ann->BodaccNum;
} else if ($this->isAsso($ann->BodaccCode)) {
$src = './img/logo_jo.png';
$title = 'Source JO ASSOCIATION n&deg;'.$ann['BodaccNum'];
} else if ($this->isBomp($ann->BodaccCode)) {
$src = './img/logo_jo.png';
if ($ann->BodaccCode == 'MAPA') {
$title = 'Source '.$ann->BodaccCode.' '.
intval($ann->BodaccNum);
} else {
$title = 'Source '.$ann->BodaccCode.' '.
'n&deg;'.intval($ann->BodaccNum).' de '.
substr($ann->DateParution, 0, 4);
}
} else {
$tabSource = explode('-', $ann->BodaccCode);
$source = $tabSource[0];
if ($source[0] == 'B') {
$src = './img/logo_jo.png';
$title = 'Source BODACC '.$ann->BodaccNum.' '.
substr($source, -1).' de ' .
substr($ann->DateParution, 0, 4);
} else if ($source[0] == 'G' || $source[0] == 'T') {
$src = './img/logo_greffe.png';
$title = 'Source Collecte Greffe';
} else if ($source[0] == 'P') {
$src = './img/logo_inpi.png';
$title = 'Source Collecte RNCS';
} else {
$src = './img/logo_jal.png';
$title = 'Source Collecte JAL';
if (isset($tabSource[1]) && $tabSource[1] > 0) {
$title .= ' '.$tabSource[1];
}
}
}
if ($src != '') {
return '<img src="'.$src.'" title="'.$title.'">';
} else {
return false;
}
}
protected function libAnnonce($ann)
{
$wdate = new WDate;
$lib = '';
foreach ($ann->evenements->item as $even) {
$lib .= $even->LibEven;
$tabSource = explode('-', $ann->BodaccCode);
$source = $tabSource[0];
$numEven = intval($even->CodeEven);
if ($numEven > 3000 && $numEven < 3999) {
if (isset($ann->dateEffet)) {
$lib .= ' (clôture au '.
$wdate->dateT('Y-m-d','d/m/Y', $ann->dateEffet).')';
}
}
if (hasModeEdition() && substr($source, 0, 2) == 'JT') {
$lib .= ' - <b>(Source TESSI)</b>';
}
$lib .= '<br/>';
}
return $lib;
}
protected function triAnnonces()
{
foreach ($this->annonces as $ann) {
if ($this->isBodacc($ann->BodaccCode)){
$this->annoncesBodacc[] = $ann;
} elseif ($this->isBalo($ann->BodaccCode)) {
$this->annoncesBalo[] = $ann;
} elseif ($this->isAsso($ann->BodaccCode)) {
$this->annoncesAsso[] = $ann;
} elseif ($this->isBomp($ann->BodaccCode)) {
$this->annoncesBomp[] = $ann;
} else {
$this->annoncesBodacc[] = $ann;
}
}
}
protected function isBodacc($code)
{
return in_array($code, array('BODA', 'BODB', 'BODC'));
}
protected function isBalo($code)
{
return ($code == 'BALO');
}
protected function isAsso($code)
{
return ($code == 'ASSO');
}
protected function isBomp($code)
{
return in_array($code, array('BOMP A', 'BOMP B', 'BOMP C', 'MAPA'));
}
}