<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> </head> <body> <?php require_once dirname(__FILE__) . '/menu.php'; try { require_once dirname(__FILE__) . "/lib/Providers.php"; $providers =& Providers::getProviders(); if (isset($_POST['save'])) { $provs_by_names =& Providers::getProvidersIdsByNamesArray(); if (isset($provs_by_names[$_POST['name']]) && $provs_by_names[$_POST['name']] != $_POST['id']) { $error_message = 'Поставщик с таким названием уже <a href="provider.php?id=' . $provs_by_names[$_POST['name']] . '">существует</a>'; $_POST['name'] = $providers[$_POST['id']]['name']; } if ((int) $_POST['id'] > 0) { Providers::updateProv((int) $_POST['id'], $_POST['name'], $_POST['prog_name'], (int) isset($_POST['use_for_our_prices'])); } else { $_REQUEST['id'] = Providers::insertProv($_POST['name'], $_POST['prog_name'], (int) isset($_POST['use_for_our_prices'])); } } $providers =& Providers::getProviders(); $provider = array('name' => '', 'prog_name' => '', 'use_for_our_prices' => 0); echo "<h2>{$error_message}</h2>"; if (isset($_REQUEST['id']) && isset($providers[$_REQUEST['id']])) { $provider = $providers[$_REQUEST['id']]; echo '<h2>Редактирование поставщика ' . $provider['name'] . '</h2>'; } else { echo '<h2>Добавление поставщика</h2>';
public static function importRelations($file_path) { $tmp_file_name = ''; if (is_array($file_path)) { if ($file_path['type'] == 'text/csv') { $file_path = $file_path['tmp_name']; } else { if ($file_path['type'] == 'application/vnd.ms-excel') { if (filesize($file_path['tmp_name'])) { $tmp_file_name = tempnam('/tmp', 'xls2csv_relations_'); $res = shell_exec("export LANG=en_US.UTF-8 && xls2csv -dUTF-8 -q3 -c, -x " . $file_path['tmp_name'] . ' > ' . $tmp_file_name); $file_path = $tmp_file_name; } else { throw new Exception("Empty file."); } } else { throw new Exception("Incorrect file."); } } } if (filesize($file_path)) { $fp = fopen($file_path, "r"); if ($fp) { $provs_ids = array(); $provs =& Providers::getProvidersIdsByNamesArray(); $data = fgetcsv($fp, 0, ',', '"'); for ($i = 1; $i < count($data); $i++) { if (isset($provs[$data[$i]])) { $provs_ids[$i] = $provs[$data[$i]]; } } while (($data = fgetcsv($fp, 0, ',', '"')) !== false) { for ($i = 1; $i < count($data); $i++) { if (isset($provs_ids[$i]) && strlen($data[$i])) { self::setRelationByName($data[0], $provs_ids[$i], $data[$i]); } } } fclose($fp); } else { throw new Exception("Can't get access to " . $file_path); } } else { throw new Exception("Empty file."); } if (strlen($tmp_file_name)) { unlink($tmp_file_name); } return true; }