Changeset 7168

Show
Ignore:
Timestamp:
10/28/08 03:54:57 (5 years ago)
Author:
xrobau
Message:

CIDoverride seems to be complete!

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • contributed_modules/modules/cidroute/agi-bin/cidoverride.agi

    r7167 r7168  
    4040/*  
    4141  Overview of the CIDoverride AGI 
    42     * Grab the ID of this call. (Done) 
    43     * Get the previous calls CallerID (DB->Exten/CallTrace) (Done) 
    44     * Check to make sure it's not an internal call (Done) 
     42    * Grab the ID of this call.  
     43    * Get the previous calls CallerID (DB->Exten/CallTrace) 
     44    * Check to make sure it's not an internal call 
    4545    * Say "The previous call from (number) was not found/was found in (tts->localarea) 
    4646    * Say "This call would be sent to (tts->cidroute_matches.name)/would be ignored" 
    47     * Say "To update this, press 1." 
     47    * Say "To update this, press 1." (Changed this.. I'll get user feedback on what they prefer) 
    4848    * If 1, then: 
    49     *  If found in an existing group,  
     49    *  If found in an existing group,  
    5050    *   prompt to send all numbers in that group to the destination selected 
    5151    *   If yes, say number range 
     
    6262    *  Say Update Complete, Thank you, goodbye 
    6363 
     64    * All complete! 
     65   
     66 
    6467*/ 
    6568 
     
    7982debug("Searching for previous call to Exten '$cidnum' in lookup tables",2); 
    8083$cidnum = $AGI->database_get("CALLTRACE", $mynum); 
    81 $cidnum['data'] = 295461936; 
    8284 
    8385debug("Previous call was from '".$cidnum['data']."'",3); 
     
    112114if (is_array($res) && isset($res['state'])) { 
    113115  debug("Found State:".$res['state'].", Region:".$res['region']." LocalArea:".$res['localarea'], 3); 
    114   $saystr = "This number is in the state: "; 
    115   $dest = select_destination(); 
     116  $saystr = "This number is in the state of: "; 
    116117  $tmp = str_split($res['state']); 
    117118  foreach ($tmp as $char) { $saystr .= strtolower($char." "); } 
     
    127128    exit; 
    128129  } 
     130  // select_destination() returns: 
     131  //     Array(name => 'text name', id => cidroute_matches.destid) 
    129132  $dest = select_destination(); 
    130133  $check = say_and_get("If you would like to alter just this number, press 1. If you would like to alter the entire range, press 2"); 
    131134  if ($check == "1") { 
    132     // This function exits; when finished. 
    133135    add_override($dest,$cidnum['data']); 
    134136  } elseif ($check == "2") { 
    135     // This function exits; when finished. 
    136137    modify_range($dest,$cidnum['data']); 
    137138  } 
    138    
    139139} else { 
    140   // It's not in a previously known range, so warn and add the number. 
    141 
    142  
    143 say("OK, we're off and running then."); 
    144  
    145  
     140  // A CallerID number NOT in the database. This means there's stuff missing from there.  
     141  say("The Caller ID number selected is not in the database. You can only add an override. Contact Support"); 
     142  add_override($dest,$cidnum['data']); 
     143
     144 
     145say ("Goodbye"); 
    146146exit; 
    147147 
     148 
    148149// Various Functions below here.. 
     150 
     151// Add an override for one specific number..  
     152// $dest = Arryay('id' => db.destid, 'name' => descriptive name of the match) 
     153// $cid = caller id of call you want to change 
     154function add_override($dest,$cid) { 
     155  global $AGI; 
     156 
     157  say("To confirm that you want to send only the caller ID number"); 
     158  $AGI->say_digits($cid); 
     159  $saystr =  "to ".$dest['name'].", you must push 5. Any other button will abort. Changes will happen immediately"; 
     160  $res = say_and_get($saystr); 
     161  if ($res == "5") { 
     162    $q = "delete from cidroute_override where number='".$cid."'", "query"); 
     163    sql("insert into cidroute_override (name, number, dest) values ('Via Phone', $cid, ".$dest['id'].")", "query"); 
     164  } 
     165  say("Update complete. Goodbye."); 
     166} 
     167 
     168// Add an override for a range of numbers 
     169// $dest = Arryay('id' => db.destid, 'name' => descriptive name of the match) 
     170// $cid = caller id of call you want to change 
     171function modify_range($dest,$cid) { 
     172  global $db; 
     173  global $AGI; 
     174  // We already check to make sure that this is part of a range, so we just need to grab the range 
     175  $q = "select localarea,min_numb,max_numb from cidroute_cidlist where '$cid' >= min_numb and '$cid' <= max_numb"; 
     176  $res = sql($q, "getRow",DB_FETCHMODE_ASSOC); 
     177  if (!isset($res['min_numb'])) { 
     178    // The database said one thing 50msec ago, and something else now. Panic. 
     179    say("Severe Error Occured. Attemped to add a range that does not exist. Goodbye."); 
     180    exit; 
     181  } 
     182  $min_numb = $res['min_numb']; 
     183  $max_numb = $res['max_numb']; 
     184  $localarea = $res['localarea']; 
     185 
     186  // Check to make sure it's not already assigned to some place else. 
     187  $q = "select min_numb,dest from cidroute_matches where min_numb='$min_numb'"; 
     188  $check = sql($q, "getRow", DB_FETCHMODE_ASSOC); 
     189 
     190  if (isset($check['min_numb'])) { 
     191    // It _IS_ assigned to someone else. 
     192    $prevdest = sql("select name,destid from cidroute_dests where destid='".$check['dest']."'", "getRow"); 
     193    $confirm = say_and_get("This range is already assigned to: ".$prevdest[0].": If you are sure you wish to alter this, press 2 now"); 
     194    if ($confirm != "2") { 
     195      say("Change Aborted. Goodbye."); 
     196      exit; 
     197    } 
     198  } 
     199  say("To confirm that you want to send the caller ID range from"); 
     200  $AGI->say_digits($min_numb); 
     201  say("to"); 
     202  $AGI->say_digits($max_numb); 
     203  $saystr = "which is part of the area: ".$localarea.", to: ".$dest['name'].": you must push 5. Any other button will abort. "; 
     204  $saystr .= "Changes will happen immediately."; 
     205  $res = say($saystr); 
     206  if ($res == "5") { 
     207    sql("delete from cidroute_matches where min_numb='$min_numb' and max_numb='$max_numb'", "query"); 
     208    $q = "insert into cidroute_matches (name, country, areacode, min_numb, max_numb, dest) values "; 
     209    $q .=   "('Via Phone', 'au', 99, '$min_numb', '$max_numb', '".$dest['id']."')"; 
     210    sql($q, "query"); 
     211    say("Update complete. Goodbye."); 
     212    exit; 
     213  } else { 
     214    say("Change Aborted. Goodbye."); 
     215    exit; 
     216  } 
     217} 
     218 
    149219 
    150220function select_destination() { 
     
    165235  } 
    166236 
    167   $saystr="Please select the destination. ".count($data); 
     237  $saystr="Please select the destination for this number. ".count($data); 
    168238  if (!$multiple) { 
    169239    while (1) { 
     
    178248      break; 
    179249    } 
    180     say("You selected $res, which is ".$data[$res][1]); 
    181250  } else { 
    182251     //Multiple. Need to care about pointers! 
     
    218287      } 
    219288    } 
    220     say("You selected ".$data[$res+$pointer][1]); 
    221   } 
    222 
    223      
    224  
    225    
    226    
     289  } 
     290  return(Array('name' => $data[$res+$pointer][1], 'id' => $res+$pointer)); 
     291
     292 
    227293function say_regions($state, $region, $area) { 
    228294  global $AGI; 
     
    237303    $AGI->say_phonetic($area, "#"); 
    238304    $check = say_and_get("Press 1 to repeat, or hash to continue"); 
    239     print_r($check); 
    240305    if ($check != "#") { 
    241306      $repeat = true; 
     
    243308  } 
    244309} 
    245      
    246310 
    247311 
     
    252316    $repeat = false; 
    253317    $res = say($str); 
    254     print_r($res); 
    255318    if ($res == null) { 
    256319      $readkey=$AGI->wait_for_digit(5000); 
     
    266329  } 
    267330} 
    268      
    269331 
    270332// 'say' takes a string and says it! If you push '*' it will repeat. If you push anything else, 
     
    334396function sql($sql,$type="query",$fetchmode=null) { 
    335397        global $db; 
     398   
     399  debug("CIDoverride db: $sql", 4); 
    336400        $results = $db->$type($sql,$fetchmode); 
    337401        if(DB::IsError($results)) {