That code can't work ....perfectlly...because it update all when anyone add a new number to same country DID and It can't work the Priority feature.
I use PostgresSQL
So I resend the code....
If it has any error or bug then post the ack so that i can post the perfect one.
if (strlen($destination)>0 && is_numeric($choose_did) && is_numeric($voip_call)){
$FG_DID_TABLE = "cc_did";
$FG_DID_FIELDS = "did";
$instance_sub_table = new Table($FG_DID_TABLE, $FG_DID_FIELDS);
$QUERY = "SELECT * FROM cc_did_destination where id_cc_did = ".$choose_did;
$result = $instance_sub_table -> SQLExec ($HD_Form -> DBHandle, $QUERY);
if( $result[0][4]==$choose_did)
{
$instance_sub_table_P = new Table("cc_did_destination", "priority");
$QUERY_P = "SELECT MAX(priority) FROM cc_did_destination where id_cc_did = ".$choose_did;
$result_P = $instance_sub_table_P -> SQLExec ($HD_Form -> DBHandle, $QUERY_P);
$Set_Priority=$result_P[0][0] + 1;
$QUERY = "INSERT INTO cc_did_destination (activated, id_cc_card, id_cc_did, destination, priority, voip_call) VALUES ('1', '".$_SESSION["card_id"]."', '".$choose_did."', '".$destination."', '".$Set_Priority."', '".$voip_call."')";
$DID_UID_QUERY .= "UPDATE cc_did SET iduser='".$_SESSION["card_id"]."' WHERE id='".$choose_did."'";
}
else
{ $QUERY = "INSERT INTO cc_did_destination (activated, id_cc_card, id_cc_did, destination, priority, voip_call) VALUES ('1', '".$_SESSION["card_id"]."', '".$choose_did."', '".$destination."', '1', '".$voip_call."')";
$DID_UID_QUERY .= "UPDATE cc_did SET iduser='".$_SESSION["card_id"]."' WHERE id='".$choose_did."'";
}
$result = $instance_sub_table -> SQLExec ($HD_Form -> DBHandle, $QUERY, 0);
$DID_UID_result = $instance_sub_table -> SQLExec ($HD_Form -> DBHandle, $DID_UID_QUERY, 0);
//$QUERY = "INSERT INTO cc_did_destination (activated, id_cc_card, id_cc_did, destination, priority, voip_call) VALUES ('0', '".$_SESSION["card_id"]."', '".$choose_did."', '".$destination."', '1', '".$voip_call."')";
//$result = $instance_sub_table -> SQLExec ($HD_Form -> DBHandle, $QUERY, 0);
$date = date("D M j G:i:s T Y", time());
$message = "\n\n".gettext("The following Destinaton-DID has been added:")."\n\n";
$message .= "$QUERY";
// email header
$em_headers = "From: IPS ALERT <IPS_alert@localhost>\n";
$em_headers .= "X-Priority: 3\n";
if (strlen($A2B->config["webcustomerui"]['error_email'])>3)
mail($A2B->config["webcustomerui"]['error_email'], "[$date] Destinaton-DID notification", $message, $em_headers);
}
|