* * Creation: 2012-04-10 rb * Last Update: $Id$ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. *------------------------------------------------------------------------- */ error_reporting(E_ERROR | E_WARNING | E_PARSE); header('content-type: text/html; charset=utf-8'); // the following parameters are set by configuration parameters $call_file = '/public/anrufe.txt'; $phonelist_file = '/public/phonelist.txt'; $msn_replace_file = '/public/msn-replace.txt'; $default_ccode = '49'; $default_cname = 'DE'; // the following parameters could be customized using the index-params.inc file $capi2text_edit_title = 'Capi2Text: Phonelist-Eintrag bearbeiten'; $frm_name = 'Name'; $frm_street = 'Straße'; $frm_street_nbr = 'Nr.'; $frm_zip = 'PLZ'; $frm_city = 'Ort'; $frm_country = 'Land'; $btn_abort = 'Abbrechen'; $btn_save = 'Speichern'; $enter_name = "Bitte einen 'Namen' eintragen"; $enter_street = "Bitte eine 'Straße' eintragen"; $enter_zip = "Bitte die 'Postleitzahl' eintragen"; $enter_city = "Bitte einen 'Ort' eintragen"; $enter_country = "Bitte ein 'Landeskürzel' eintragen"; $input_for_nbr = 'Eintrag für'; $server_error = "Der Server meldet einen Fehler"; $missing_number = 'Keine Rufnummer gefunden.'; $program_error = 'fehlende Rufnumer -> falscher Programmaufruf'; $save_successful = 'Die Daten wurden erfolgreich gespeichert. Das Eingabefenster wird jetzt geschlossen.'; $comms_error = 'Ihr Browser kann keine direkte Kommunikation mit dem Webserver aufbauen (AJaX) oder die Funktion (ActiveX) wurde explizit abgeschaltet.'; $font_face = 'arial, verdana'; $font_size = '12pt'; // end of customizable parameters // override parameters if (@file_exists('capi2text-params.inc')) include_once('capi2text-params.inc'); // no phone-number => exit if (! isset($_REQUEST['nbr'])) die($program_error); //echo "
";print_r($_REQUEST);echo ""; // if form submitted => validation unset($error); if (isset($_POST['submit'])) { if (strlen($_POST['name']) == 0) $error .= $enter_name; if (strlen($_POST['street']) == 0) $error .= $enter_street; if (strlen($_POST['zip']) == 0) $error .= $enter_zip; if (strlen($_POST['city']) == 0) $error .= $enter_city; if (strlen($_POST['country']) == 0) $error .= $enter_country; } if (isset($error)) die($server_error . ":\n\n" . $error . "\n"); // if form submitted without errors => create recordset if (isset($_POST['submit']) && !isset($error)) { $nbr = $_POST['nbr']; $name = $_POST['name']; $street = str_replace(", "," ",$_POST['street']); $zip = str_replace(", "," ",$_POST['zip']); $city = str_replace(", "," ",$_POST['city']); $country = str_replace(", "," ",$_POST['country']); $addr = "$street, $zip $city, $country"; // append to phonelist if (trim($nbr) <> '') { // not an empty entry - make sure that number is in international format $nbr = preg_replace('/^0([0-9][0-9]+)/', "00$default_ccode$1", $nbr); if (is_writable($phonelist_file)) { // read phonelist content from file $pf_content = file_get_contents($phonelist_file); $pf_content = explode("\n",$pf_content); // replace matching entries $pf_content = preg_replace("/^$nbr.*/", "$nbr\t$name\t$addr", $pf_content); // write phonelist content to file $pf_content = implode("\n",$pf_content); file_put_contents($phonelist_file, $pf_content); } else die("File $phonelist_file not writeable"); } // update call_file if (is_writable($call_file)) { // read content of call_file $cf = fopen($call_file, 'r') or die("Cannot open file '$call_file'!"); $i = 0; while (!feof($cf)) { list($arr_phone_calls[$i]['date'], $arr_phone_calls[$i]['time'], $arr_phone_calls[$i]['from'], $arr_phone_calls[$i]['to'], $arr_phone_calls[$i]['name'], $arr_phone_calls[$i]['address'], $arr_phone_calls[$i]['flag_file']) = array_pad(explode("\t", rtrim(fgets($cf, 500))), 7, ''); if ($arr_phone_calls[$i]['from'] == $_POST['nbr']) { // update record $arr_phone_calls[$i]['name'] = $_POST['name']; $arr_phone_calls[$i]['address'] = $addr; } $i++; } fclose($cf); // rewrite call_file $cf = fopen($call_file, 'w') or die("Cannot open file '$call_file'!"); foreach ($arr_phone_calls as $phone_call) { if (trim($phone_call['date']) <> '' ) { // not an empty row - write it $line = rtrim($phone_call['date'] . "\t" . $phone_call['time'] . "\t" . $phone_call['from'] . "\t" . $phone_call['to'] . "\t" . $phone_call['name'] . "\t" . $phone_call['address']) . "\n"; $done = fwrite($cf, $line) or die("Cannot write to file '$call_file'"); } } fclose($cf); die($save_successful); } else { die("File $call_file not writeable"); } } else { // Form not submitted or error occurs // because of PHP parameter 'Register_Globals = off' if (isset($_GET)) { $nbr = $_GET['nbr']; $name = urldecode($_GET['N']); $get_addr = explode(", ", $_GET['A'], 3); $street = $get_addr[0]; $get_city = explode(" ", $get_addr[1], 2); $zip = $get_city[0]; $city = $get_city[1]; $country = (isset($get_addr[2])) ? $default_cname : $get_addr[2]; } else { $nbr = $_POST['nbr']; // $name = $_POST['name']; $street = $_POST['street']; $zip = $_POST['zip']; $city = $_POST['city']; $country = (empty($_POST['country'] )) ? $default_cname : $_POST['country']; } // create form $output = "\n"; } ?>