public function doConfigPageInit($page) { $action = isset($_REQUEST['action']) ? trim($_REQUEST['action']) : ''; $number = isset($_REQUEST['number']) ? trim($_REQUEST['number']) : ''; $name = isset($_REQUEST['name']) ? trim($_REQUEST['name']) : ''; $speeddial = isset($_REQUEST['speeddial']) ? trim($_REQUEST['speeddial']) : ''; $gensd = isset($_REQUEST['gensd']) ? trim($_REQUEST['gensd']) : ''; $editnumber = isset($_REQUEST['editnumber']) ? trim($_REQUEST['editnumber']) : ''; $editspeeddial = isset($_REQUEST['editspeeddial']) ? trim($_REQUEST['editspeeddial']) : ''; $dispnum = "phonebook"; //used for switch on config.php switch ($action) { case "add": \phonebook_add($number, $name, $speeddial, $gensd); break; case "delete": if (!empty($number)) { \phonebook_del($number, $speeddial); } break; case "edit": $numbers = \phonebook_list(); \phonebook_del($editnumber, $editspeeddial); \phonebook_add($number, $name, $speeddial, $gensd); break; case "empty": \phonebook_empty(); break; case "import": $i = 0; // imported lines if (is_uploaded_file($_FILES['csv']['tmp_name'])) { $lines = file($_FILES['csv']['tmp_name']); if (is_array($lines)) { $n = count($lines); // total lines foreach ($lines as $line) { $fields = phonebook_fgetcsvfromline($line, 3); if (is_array($fields)) { $fields = array_map('trim', $fields); if (is_array($fields) && count($fields) == 3 && is_numeric($fields[2]) && ($fields[3] == '' || is_numeric($fields[3]))) { phonebook_del($fields[2], $numbers[$fields[2]]['speeddial']); phonebook_add(htmlentities($fields[2], ENT_QUOTES, 'UTF-8'), addslashes(htmlentities($fields[1], ENT_QUOTES, 'UTF-8')), htmlentities($fields[3], ENT_QUOTES, 'UTF-8')); $i++; } } } } } else { $n = 0; // total lines if no file } break; case "export": header('Content-Type: text/csv'); header('Content-disposition: attachment; filename=phonebook.csv'); $numbers = \phonebook_list(); foreach ($numbers as $number => $values) { printf("\"%s\";%s;%s\n", $values['name'], trim($number), $values['speeddial']); } exit; break; } }
phonebook_empty(); break; case "import": $i = 0; // imported lines if (is_uploaded_file($_FILES['csv']['tmp_name'])) { $lines = file($_FILES['csv']['tmp_name']); if (is_array($lines)) { $n = count($lines); // total lines foreach ($lines as $line) { $fields = phonebook_fgetcsvfromline($line, 3); $fields = array_map('trim', $fields); if (is_array($fields) && count($fields) == 3 && is_numeric($fields[2]) && ($fields[3] == '' || is_numeric($fields[3]))) { phonebook_del($fields[2], $numbers[$fields[2]]['speeddial']); phonebook_add(htmlentities($fields[2], ENT_QUOTES), addslashes(htmlentities($fields[1], ENT_QUOTES)), htmlentities($fields[3], ENT_QUOTES)); $i++; } } redirect_standard(); } } else { $n = 0; } // total lines if no file break; case "export": header('Content-Type: text/csv'); header('Content-disposition: attachment; filename=phonebook.csv'); $numbers = phonebook_list(); foreach ($numbers as $number => $values) {