Skip to content

Instantly share code, notes, and snippets.

@adamjakab
Created November 6, 2014 08:21
Show Gist options
  • Save adamjakab/c4479a5624e72a154b70 to your computer and use it in GitHub Desktop.
Save adamjakab/c4479a5624e72a154b70 to your computer and use it in GitHub Desktop.
Helper function to render agents
function getContactDataFor($id, $userType) {
$answer = array();
global $AZCOMP_CORE;
$db = $AZCOMP_CORE->get('_jdb');
$sql = 'SELECT res.*'
.' FROM #__dierre_agenti AS res'
.' WHERE res.id = ' . $id
.'';
$db->setQuery($sql);
$row = $db->loadObject();
//
$CAPOAREA = '';
$CAPOAREA .= '<tr><td colspan="3" class="chisei">'.JText::_( 'CAPOAREA' ).'</td></tr>';
$CAPOAREA .= '<tr>';
$CAPOAREA .= '<td class="td1">' . $row->capoarea_nome ."</td>";
$CAPOAREA .= '<td class="td2">' . '<a href="mailto:'.$row->capoarea_mail.'">' . $row->capoarea_mail . '</a>' . "</td>";
$CAPOAREA .= '<td class="td3">' . "Tel.: +39 (".$row->capoarea_prefisso.") " . $row->capoarea_telefono . "</td>";
$CAPOAREA .= '</tr>';
$RIVENDITORI = '';
$RIVENDITORI .= '<tr><td colspan="3" class="chisei">'.JText::_( 'AGENTE_DI_ZONA' ).'</td></tr>';
$RIVENDITORI .= '<tr>';
$RIVENDITORI .= '<td class="td1">' . $row->agente_nome . "</td>";
$RIVENDITORI .= '<td class="td2">' . '<a href="mailto:'.$row->agente_mail.'">' . $row->agente_mail . '</a>' . "</td>";
$RIVENDITORI .= '<td class="td3">' . "Tel.: +39 (".$row->agente_prefisso.") " . $row->agente_telefono . "</td>";
$RIVENDITORI .= '</tr>';
if (empty($row->impresa_nome)) {
$row->impresa_nome = $row->agente_nome;
$row->impresa_mail = $row->agente_mail;
$row->impresa_prefisso = $row->agente_prefisso;
$row->impresa_telefono = $row->agente_telefono;
}
$IMPRESE = '';
$IMPRESE .= '<tr><td colspan="3" class="chisei">'.JText::_( 'AGENTE_DI_ZONA' ).'</td></tr>';
$IMPRESE .= '<tr>';
$IMPRESE .= '<td class="td1">' . $row->impresa_nome . "</td>";
$IMPRESE .= '<td class="td2">' . '<a href="mailto:'.$row->impresa_mail.'">' . $row->impresa_mail . '</a>' . "</td>";
$IMPRESE .= '<td class="td3">' . "Tel.: +39 (".$row->impresa_prefisso.") " . $row->impresa_telefono . "</td>";
$IMPRESE .= '</tr>';
if (empty($row->atra_nome)) {
$row->atra_nome = $row->agente_nome;
$row->atra_mail = $row->agente_mail;
$row->atra_prefisso = $row->agente_prefisso;
$row->atra_telefono = $row->agente_telefono;
}
$ATRA = '';
$ATRA .= '<tr><td colspan="3" class="chisei">'.JText::_( 'AGENTE_DI_ZONA' ).'</td></tr>';
$ATRA .= '<tr>';
$ATRA .= '<td class="td1">' . $row->atra_nome . "</td>";
$ATRA .= '<td class="td2">' . '<a href="mailto:'.$row->atra_mail.'">' . $row->atra_mail . '</a>' . "</td>";
$ATRA .= '<td class="td3">' . "Tel.: +39 (".$row->atra_prefisso.") " . $row->atra_telefono . "</td>";
$ATRA .= '</tr>';
if ($row->extra1_agente_nome != null && $row->extra1_agente_nome != '') {
if (strtoupper($row->extra1_agente_categoria) == "IMPRESE") {
$tit2use = '&nbsp;';
} else {
$tit2use = JText::_( 'AGENTE_PER' ). " " . ucfirst(strtolower($row->extra1_agente_categoria));
}
$EXTRA1 = '';
$EXTRA1 .= '<tr><td colspan="3" class="chisei">'.$tit2use.'</td></tr>';
$EXTRA1 .= '<tr>';
$EXTRA1 .= '<td class="td1">' . $row->extra1_agente_nome . "</td>";
$EXTRA1 .= '<td class="td2">' . '<a href="mailto:'.$row->extra1_agente_mail.'">' . $row->extra1_agente_mail . '</a>' . "</td>";
$EXTRA1 .= '<td class="td3">' . "Tel.: +39 (".$row->extra1_agente_prefisso.") " . $row->extra1_agente_telefono . "</td>";
$EXTRA1 .= '</tr>';
}
if ($row->extra2_agente_nome != null && $row->extra2_agente_nome != '') {
if (strtoupper($row->extra2_agente_categoria) == "IMPRESE") {
$tit2use = '&nbsp;';
} else {
$tit2use = JText::_( 'AGENTE_PER' ). " " . ucfirst(strtolower($row->extra2_agente_categoria));
}
$EXTRA2 = '';
$EXTRA2 .= '<tr><td colspan="3" class="chisei">'.$tit2use.'</td></tr>';
$EXTRA2 .= '<tr>';
$EXTRA2 .= '<td class="td1">' . $row->extra2_agente_nome . "</td>";
$EXTRA2 .= '<td class="td2">' . '<a href="mailto:'.$row->extra2_agente_mail.'">' . $row->extra2_agente_mail . '</a>' . "</td>";
$EXTRA2 .= '<td class="td3">' . "Tel.: +39 (".$row->extra2_agente_prefisso.") " . $row->extra2_agente_telefono . "</td>";
$EXTRA2 .= '</tr>';
}
if ($row->extra3_agente_nome != null && $row->extra3_agente_nome != '') {
if (strtoupper($row->extra3_agente_categoria) == "IMPRESE") {
$tit2use = '&nbsp;';
} else {
$tit2use = JText::_( 'AGENTE_PER' ). " " . ucfirst(strtolower($row->extra3_agente_categoria));
}
$EXTRA3 = '';
$EXTRA3 .= '<tr><td colspan="3" class="chisei">'.$tit2use.'</td></tr>';
$EXTRA3 .= '<tr>';
$EXTRA3 .= '<td class="td1">' . $row->extra3_agente_nome . "</td>";
$EXTRA3 .= '<td class="td2">' . '<a href="mailto:'.$row->extra3_agente_mail.'">' . $row->extra3_agente_mail . '</a>' . "</td>";
$EXTRA3 .= '<td class="td3">' . "Tel.: +39 (".$row->extra3_agente_prefisso.") " . $row->extra3_agente_telefono . "</td>";
$EXTRA3 .= '</tr>';
}
//
$html = '';
$html .= '<table class="AGTBL">';
$html .= '<tr><td colspan="3" class="comune">'.$row->comune.'&nbsp;('.$row->provincia.')</td></tr>';
switch ($userType) {
case 2://RIVENDITORE
$html .= $CAPOAREA;
$html .= $RIVENDITORI;
if (/*countExtras*/
strtoupper(substr($row->extra1_agente_categoria,0,1)) == "R" ||
strtoupper(substr($row->extra2_agente_categoria,0,1)) == "R" ||
strtoupper(substr($row->extra3_agente_categoria,0,1)) == "R"
) {
//$html .= '<tr><td colspan="3" class="chisei">'.'&nbsp;'.'</td></tr>';
if ( strtoupper(substr($row->extra1_agente_categoria,0,1)) == "R") {$html .= $EXTRA1;}
if ( strtoupper(substr($row->extra2_agente_categoria,0,1)) == "R") {$html .= $EXTRA2;}
if ( strtoupper(substr($row->extra3_agente_categoria,0,1)) == "R") {$html .= $EXTRA3;}
}
break;
case 3://IMPRESA
$html .= $CAPOAREA;
$html .= $IMPRESE;
if (/*countExtras*/
strtoupper(substr($row->extra1_agente_categoria,0,1)) == "I" ||
strtoupper(substr($row->extra2_agente_categoria,0,1)) == "I" ||
strtoupper(substr($row->extra3_agente_categoria,0,1)) == "I"
) {
//$html .= '<tr><td colspan="3" class="chisei">'.'&nbsp;'.'</td></tr>';
if ( strtoupper(substr($row->extra1_agente_categoria,0,1)) == "I") {$html .= $EXTRA1;}
if ( strtoupper(substr($row->extra2_agente_categoria,0,1)) == "I") {$html .= $EXTRA2;}
if ( strtoupper(substr($row->extra3_agente_categoria,0,1)) == "I") {$html .= $EXTRA3;}
}
break;
case 4://FERRAMENTA
$html .= $CAPOAREA;
$html .= $ATRA;
if (/*countExtras*/
strtoupper(substr($row->extra1_agente_categoria,0,1)) == "A" ||
strtoupper(substr($row->extra2_agente_categoria,0,1)) == "A" ||
strtoupper(substr($row->extra3_agente_categoria,0,1)) == "A"
) {
//$$html .= '<tr><td colspan="3" class="chisei">'.'&nbsp;'.'</td></tr>';
if ( strtoupper(substr($row->extra1_agente_categoria,0,1)) == "A") {$html .= $EXTRA1;}
if ( strtoupper(substr($row->extra2_agente_categoria,0,1)) == "A") {$html .= $EXTRA2;}
if ( strtoupper(substr($row->extra3_agente_categoria,0,1)) == "A") {$html .= $EXTRA3;}
}
break;
}
$html .= '</table>';
//
$answer["html"] = $html;
return($answer);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment