#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2008
    Posts
    9
    Rep Power
    0

    Help with this php script autodialer


    Hoping someone would be willing to simply have pitty on a novice and assist with this script I had done by a programmer I am currently unable to reach.

    This is my autodialer script. It calls customers off of a set list and lets them know their account is expired or out of minutes.

    I want to add coding that simply says if the number that the script is dialing is 2401234567 do not dial it.

    Any help would be GREATLY appreciated...



    <?php
    set_time_limit(0);
    $pid = getmypid();

    echo "Script started with PID $pid\n";
    $pid_s = $pid."\n";
    file_put_contents("/tmp/autodialer.pid",$pid_s);

    $debug = 0;

    mysql_connect("74.xx.xxx.xxx","1430xxxxxx","763a57526856bba2");
    mysql_select_db("dxxxxxx");

    function do_query($query) {


    $result = mysql_query($query);
    if (mysql_errno()) {
    $error = "MySQL error ".mysql_errno().": ".mysql_error()." when executing: \" $query \"\n";
    echo $error;
    return NULL;
    } else {
    return $result;
    }

    }

    function generate_call_file($destination) {

    echo "Generating call file to $destination\n";

    $file = tempnam("/tmp","asteriskdialer");

    $destination = ltrim($destination);
    $destination = rtrim($destination);

    $call_file_contents = "
    Channel: SIP/*31$destination@cwu
    Callerid: xxxxxxx
    MaxRetries: 1
    RetryTime: 600
    WaitTime: 45
    Context: autodialer
    Extension: 101
    Priority: 1
    Set: destnum=$destination
    ";
    file_put_contents($file,$call_file_contents);
    $filename = basename($file);
    rename($file,"/var/spool/asterisk/outgoing/".$filename);

    }

    function update_status($card_id, $destination) {

    $sql = "insert into active_calls (card_id,phone_number,time_started,call_status) values ('$card_id','$destination',NOW(),'Placed/Ringing')";
    do_query($sql);

    }

    function call_destinations($cc_card_id) {

    $sql = "update call_attempts set last_attempt = NOW() where cc_card_id = $cc_card_id";
    do_query($sql);
    if (mysql_affected_rows() == 0) {
    // No attempt in the table, insert it
    $sql = "insert into call_attempts (cc_card_id) values ($cc_card_id)";
    do_query($sql);
    }

    $sql = "select distinct(destination) from cc_did_destination where id_cc_card = $cc_card_id";
    $didresult = do_query($sql);
    while ($didrow = mysql_fetch_array($didresult,MYSQL_BOTH)) {
    generate_call_file($didrow[0]);
    update_status($cc_card_id,$didrow[0]);
    }


    }

    function check_for_attempts($cc_card_id) {

    $sql = "select UNIX_TIMESTAMP(last_attempt) from call_attempts where cc_card_id = $cc_card_id";
    $result = mysql_query($sql);
    if (mysql_num_rows($result) == 0) {
    echo "Never attempted\n";
    //We've never attempted this number, so we're good to go.
    return 1;
    }

    $row = mysql_fetch_array($result,MYSQL_BOTH);

    echo "Last attempt at ".$row[0]." (".date(DATE_RFC822,$row[0]).") - ";
    if ((time() - $row[0]) > 86400) {
    echo "More than 1 day ago\n";
    return 1;
    } else {
    echo "Less than 1 day ago\n";
    return 0;
    }
    }



    // Main loop here:
    $i = 1;
    $sql = "select * from cc_card where expirationdate < NOW() and activated = 't' order by id";
    $sql = "select * from cc_card where (expirationdate < NOW() or credit < 10) and activated = 't' order by id";
    $cardresult = mysql_query($sql);

    while ($cardrow = mysql_fetch_array($cardresult,MYSQL_BOTH)) {

    echo "\n";


    $hour = date("G");
    if (($hour > 20) || ($hour < 10)) {
    echo "After 9pm and before 10am, exit lest we wake someone up\n";
    unlink("/tmp/autodialer.pid");
    exit(0);
    }



    echo "Card number ".$cardrow["username"]." is expired, processing it for outgoing calls\n";

    if ($cardrow["activated"] == "f") {
    echo "Skipping ".$cardrow["username"]." due to deactivation";
    echo "\n";
    continue;
    }

    if (check_for_attempts($cardrow["id"]) == 0) {
    echo "Not calling ".$cardrow["username"];
    echo "\n";
    continue;
    }

    call_destinations($cardrow["id"]);
    echo "\n";
    echo "\n";
    $i++;

    if ($i >= 7) {
    // After 8 concurrent calls calls pause for a few minutes so we don't spam the hell out of people or overwhelm the call center
    // Nowhere near a predictive dialer, but simple enough
    echo "Pausing for a few minutes\n";
    touch("/tmp/autodialer.pause");
    sleep(240);
    unlink("/tmp/autodialer.pause");
    echo "Resuming\n";
    $i = 0;
    }

    }

    unlink("/tmp/autodialer.pid");
  2. #2
  3. No Profile Picture
    I haz teh codez!
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2003
    Posts
    2,549
    Rep Power
    2337
    Wouldn't it make more sense to remove that number from your list?
    I ♥ ManiacDan & requinix

    This is a sig, and not necessarily a comment on the OP:
    Please don't be a help vampire!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2008
    Posts
    9
    Rep Power
    0
    Originally Posted by ptr2void
    Wouldn't it make more sense to remove that number from your list?
    Unfortunately, due to the overall operation this is not an option...

IMN logo majestic logo threadwatch logo seochat tools logo