$action = $_POST['action'];
$search_num = $_POST['search_num'];
$search_text = $_POST['search_text'];
function output_formatted($data){
echo '
';
foreach($data as $line){
$line = explode("|", $line);
$from_number = $line[1];
$date = $line[2];
$text = $line[3];
echo '| '.$from_number.' | '.$date.' | '.$text.' |
';
}
echo '
';
}
//Function to run queries against the SMS.db
//action = 1 will return raw result. action = 2 will output result in fancy table
function sms_query($query, $action){
//echo 'Query: '.$query.'
';
exec('sqlite3 /var/mobile/Library/SMS/sms.db "'.$query.';"', $data);
if($action == 1){
return($data[0]);
}
if($action == 2){
output_formatted($data);
}
}
$lb = "
";
$total_incoming_sms = sms_query("select value from _SqliteDatabaseProperties WHERE key = 'counter_in_all'",1);
$total_outgoing_sms = sms_query("select value from _SqliteDatabaseProperties WHERE key = 'counter_out_all'",1);
if(!$action){
echo "Total SMS in: ".$total_incoming_sms;
echo $lb;
echo "Total SMS out: ".$total_outgoing_sms;
//Form for Search through SMS
echo '
';
}
if($search_num != "" AND $search_text == ""){
echo "Searching database for any SMS from ".$search_num.$lb;
flush();
sms_query("select * from message WHERE address LIKE '%$search_num%'",2);
}
if($search_text != "" AND $search_num == ""){
echo "Searching database for any SMS including the text ".$search_text.$lb;
flush();
sms_query("select * from message WHERE text LIKE '%$search_text%'",2);
}
?>