echo "<br />"; // initialize error arrays and open file $err_count = 0; $invalid_prefixes = array(); $filename = $_FILES['csv_file']['tmp_name']; $import_data = fopen($filename, 'r'); // import file contents into array while (!feof($import_data)) { $import_array[] = fgetcsv($import_data); } // check if array contains nonexistent tariffs // since we can only insert tariffs for already defined prefixes, if we wont find requested prefix, hit err_count foreach ($import_array as $check) { if ($check['0'] != 0) { // omit empty tariffs $prefix_exists = fbilling_check_if_exists('prefixes', 'pref', $check[0]); if ($prefix_exists == 0) { $err_count = $err_count + 1; array_push($invalid_prefixes, $check[0]); } } } if ($err_count > 0) { // notify user about errors echo _("There are {$err_count} errors in CSV files..."); echo "<br />"; foreach ($invalid_prefixes as $invalid_prefix) { echo _("Prefix {$invalid_prefix} does not exist in database"); echo "<br />"; } } else {
// add new permission $fields = array('name', 'is_active'); $values = array($name, $is_active); fbilling_add($cat, $fields, $values); unset($fields); unset($values); // add permission/weight relationships $fields = array('permission_id', 'weight_id'); foreach ($weight_id as $w) { $values[] = array($name, $w); } fbilling_add('permission_weights', $fields, $values); redirect_standard('cat'); } if ($action == 'conf_edit') { $insert_ok = fbilling_check_if_exists($cat, 'name', $name); // get number of permissions with same name if ($insert_ok > 0) { // if there is permission with requested name check whether it's not permission we are editing $permission_data = fbilling_get_data_by_id($cat, $id); if ($permission_data['name'] == $name) { $insert_ok = 0; } else { $insert_ok = 1; } } if ($insert_ok > 0) { echo _("Permission with specified name already exists in database, please provide different name, and try again"); echo "<a href='javascript:history.go(-1)''> Go Back</a>"; return true; } else {
echo "<br />"; echo _("Checking if file contains valid data..."); echo "<br />"; $err_coount = 0; $invalid_prefixes = array(); $filename = $_FILES['csv_file']['tmp_name']; $import_data = fopen($filename, "r"); // load csv into array while (!feof($import_data)) { $import_array[] = fgetcsv($import_data); } // check if array contains existent prefixes foreach ($import_array as $check) { if ($check['0'] != 0) { // omit empty prefixes $prefix_exists = fbilling_check_if_exists($cat, 'pref', $check[0]); if ($prefix_exists > 0) { $err_coount = $err_coount + 1; array_push($invalid_prefixes, $check[0]); } } } // if one ore more prefix exists in db, exit if ($err_coount > 0) { // TODO maybe ask user to proceed anyways without these prefixes? echo _("You have {$err_coount} errors in your file."); echo "<br />"; foreach ($invalid_prefixes as $invalid_prefix) { echo _("Prefix {$invalid_prefix} already exists in database."); echo "<br />"; }