I'm working in a project that is in need of having custom action buttons in detail view so we can perform some custom actions. I watched the course that made Ahmed at Udemy and copied the example. My question is that, even I succeed in displaying buttons and creating a pair of custom actions (just printing an alert), I still have a problem with more elaborated actions.
Here is my code in hooks\rh_people.php (rh_people is the table what I am working with). I'll explain what it was supposed to do (but it doesn't) after:
Code: Select all
function rh_people_dv($selectedID, $memberInfo, &$html, &$args) {
ob_start(); ?>
<script>
$j(function(){
<?php if($selectedID){ ?> //per a que els botons no es mostren per un registre nou
$j('#appginihelper-dv-actionbuttons').append(
'<p></p>' +
'<div class="btn-group-vertical btn-group-lg" style="width: 100%;">' +
'<button type="button" name="activar" class="btn btn-success" onclick="activar_persona()">' +
'<i class="glyphicon glyphicon-plus"></i> <span> Activar</span></button>' +
'<button type="button" name="desactivar" class="btn btn-warning" onclick="desactivar_persona()">' +
'<i class="glyphicon glyphicon-minus"></i> <span> Desactivar</span></button>' +
'</div>'
);
<?php } ?>
});
function activar_persona(){
<?php
$id = makeSafe($selectedID);
$memberID = getLoggedMemberID();
$var_aux = "SELECT rh_people.status from rh_people where rh_people.id = '{$id}'";
$status = sqlValue($var_aux);
if ($status == "No"){
?> alert("Aquesta persona està INACTIVA, voleu TORNAR A ACTIVAR-LA?"); <?php
// sql ("insert into rh_people_activity_periods (name, family_name, entry_date, log_date, log_creator) values ( {$id}, {$id}, curdate(), curdate(), '{$memberID}' )", $eo);
}
elseif ($status == "Si"){
?> alert("Aquesta persona ja està ACTIVA"); <?php
}
?>
}
function desactivar_persona(){
alert("AQUEST ÉS EL BOTÓ DESACTIVAR");
<?php
// sql("update rh_people_activity_periods set rh_people_activity_periods.leaving_date = curdate() where rh_people_activity_periods.name = '{$id}' and rh_people_activity_periods.leaving_date is null", $eo);
?>
}
</script>
<?php
$form_code = ob_get_contents();
ob_end_clean();
$html .= $form_code;
}
- If status is 'Si' and I click on 'Activar' - just display a message in a popup
- If status is 'No' and I click on 'Activar' - display a message in a popup and run an "sql insert into"
- If status is 'Si' and I click on 'Desactivar' - display a message in a popup and run an "sql update"
- If status is 'No' and I click on 'Activar' - just display a message in a popup
Which is my problem? sql is executed when I enter the record, even if I don't click on the buttons.
Anyone having this problem? Or anyone using this code to display/configure action buttons?
Thanks in advance!