function Import() { require_once "Structures/DataGrid.php"; require_once "Structures/DataGrid/DataSource/Excel.php"; require_once "Structures/DataGrid/DataSource/CSV.php"; require_once 'Image/Transform.php'; A::$REGFILES = getSectionByModule('pages'); mk_dir("files/" . DOMAIN . "/tmp"); clearDir("files/" . DOMAIN . "/tmp"); if (isset($_FILES['file']['tmp_name']) && file_exists($_FILES['file']['tmp_name'])) { $path_parts = pathinfo($_FILES['file']['name']); $ext = preg_replace("/[^a-z0-9]+/i", "", mb_strtolower($path_parts['extension'])); if ($ext == 'xls' || $ext == 'csv') { if ($ext == 'csv') { $sourcefile = $_FILES['file']['tmp_name']; $content = @file_get_contents($sourcefile); if ($content && !mb_check_encoding($content, 'UTF-8')) { file_put_contents($sourcefile, mb_convert_encoding($content, 'UTF-8', 'Windows-1251')); } } else { $sourcefile = $_FILES['file']['tmp_name']; } if ($ext == 'xls') { $datasource = new Structures_DataGrid_DataSource_Excel(); $datasource->bind($sourcefile); } elseif ($ext == 'csv') { $datasource = new Structures_DataGrid_DataSource_CSV(); $datasource->bind($sourcefile, array('delimiter' => ';', 'enclosure' => '"')); } else { return false; } $datagrid = new Structures_DataGrid(); $datagrid->bindDataSource($datasource); if (isset($_REQUEST['clear'])) { A::$DB->execute("TRUNCATE " . STRUCTURE); } $sort = A::$DB->getOne("SELECT MAX(sort) FROM " . STRUCTURE) + 1; $list = array(); foreach ($datagrid->recordSet as $row) { if (empty($row)) { continue; } if ($ext == 'xls') { $trow = array(); foreach ($row as $j => $value) { if (!empty($value)) { $trow[$j - 1] = $value; } } $row = $trow; } $data = array(); if (!empty($row[0])) { $data['name_' . LANG] = trim($row[0]); } else { continue; } $j = 1; A::$DB->query("SELECT * FROM " . DOMAIN . "_fields WHERE item='" . STRUCTURE . "' ORDER BY sort"); while ($frow = A::$DB->fetchRow()) { switch ($frow['type']) { default: $data[$frow['field']] = !empty($row[$j]) ? trim($row[$j]) : ""; break; case 'int': $data[$frow['field']] = !empty($row[$j]) ? (int) $row[$j] : 0; break; case 'float': $data[$frow['field']] = !empty($row[$j]) ? (double) $row[$j] : 0; break; case 'select': if (!empty($row[$j])) { if (!isset($list[$frow['property']])) { $list[$frow['property']] = loadList($frow['property']); } $row[$j] = trim($row[$j]); $key = array_search($row[$j], $list[$frow['property']]); if (empty($key) && !empty($row[$j])) { $key = addToList($frow['property'], $row[$j]); $list[$frow['property']][$key] = $row[$j]; } if (!empty($key)) { $data[$frow['field']] = $key; } } break; case 'mselect': if (!empty($row[$j])) { if (!isset($list[$frow['property']])) { $list[$frow['property']] = loadList($frow['property']); } $row[$j] = explode(',', $row[$j]); $data[$frow['field']] = array(); foreach ($row[$j] as $value) { $value = trim($value); $key = array_search($value, $list[$frow['property']]); if (empty($key) && !empty($value)) { $key = addToList($frow['idvar'], $value); $list[$frow['property']][$key] = $value; } if (!empty($key)) { $data[$frow['field']][] = sprintf("%04d", $key); } } $data[$frow['field']] = implode(",", $data[$frow['field']]); } break; case 'bool': $data[$frow['field']] = !empty($row[$j]) && $row[$j] != 'N' ? "Y" : "N"; break; case 'image': $row[$j] = preg_replace("/[^a-zA-Zа-яА-Я0-9-_.]/iu", "", $row[$j]); if (is_file($path = "ifiles/" . $row[$j])) { $data[$frow['field']] = RegisterImage($path, $data['name_' . LANG]); } break; case 'file': $row[$j] = preg_replace("/[^a-zA-Zа-яА-Я0-9-_.]/iu", "", $row[$j]); if (is_file($path = "ifiles/" . $row[$j])) { $data[$frow['field']] = RegisterFile($path, $data['name_' . LANG]); } break; } $j++; } A::$DB->free(); $data['sort'] = $sort++; A::$DB->Insert(STRUCTURE, $data); } return true; } } return false; }
function UploadImage() { // echo isset($_POST["Titre"]); if (isset($_POST["Titre"])) { $rep = 'Images/'; $Uniq = uniqid("", true); $fich = $rep . $Uniq . ".png"; $type = $_FILES['Image']['type']; if (strpos($type, 'image') !== false) { if (move_uploaded_file($_FILES['Image']['tmp_name'], $fich)) { RegisterImage($_SESSION['IDUsager'], $_POST["Titre"], "", $Uniq); } else { echo "Problème lors du déplacement"; } } } }
/** * Обработчик действия: Добавление изображений в альбом. */ function AddImage() { if ($album = A::$DB->getRowById($_REQUEST['idalb'], SECTION . "_albums")) { $sort = A::$DB->getOne("SELECT MAX(sort) FROM " . DOMAIN . "_images WHERE idsec=" . SECTION_ID . " AND iditem=" . $album['id']); for ($i = 1; $i <= 6; $i++) { $idimg = UploadImage("image{$i}", $_REQUEST["name{$i}"], 0, $album['id'], $sort + $i); if (empty($album['idimg'])) { A::$DB->Update(SECTION . "_albums", array('idimg' => $idimg), "id=" . $album['id']); $album['idimg'] = $idimg; } } if (extension_loaded('zip') && isset($_FILES['archzip']['tmp_name']) && file_exists($_FILES['archzip']['tmp_name'])) { delDir("files/" . DOMAIN . "/tmp"); mk_dir("files/" . DOMAIN . "/tmp"); $zip = new ZipArchive(); $zip->open($_FILES['archzip']['tmp_name']); if ($zip->extractTo("files/" . DOMAIN . "/tmp")) { $images = scandir("files/" . DOMAIN . "/tmp"); $i = 1; foreach ($images as $file) { if ($file != '.' && $file != '..') { $idimg = RegisterImage("files/" . DOMAIN . "/tmp/{$file}", '', 0, $album['id'], $sort + $i++, A::$OPTIONS['img_resize'], A::$OPTIONS['img_x'], A::$OPTIONS['img_y']); if (empty($album['idimg'])) { A::$DB->Update(SECTION . "_albums", array('idimg' => $idimg), "id=" . $album['id']); $album['idimg'] = $idimg; } } } } $zip->close(); delDir("files/" . DOMAIN . "/tmp"); } if (!empty($_REQUEST['path']) && A::$AUTH->isSuperAdmin()) { $_path = preg_replace("/^[.\\/]+/i", "", $_REQUEST['path']); if (empty($_path)) { return true; } if (A::$AUTH->isSuperAdmin()) { if (is_dir($_path)) { $path = $_path; } elseif (is_file($_path)) { $file = $_path; } elseif (is_dir("files/" . DOMAIN . "/" . $_path)) { $path = "files/" . DOMAIN . "/" . $_path; } elseif (is_file("files/" . DOMAIN . "/" . $_path)) { $file = "files/" . DOMAIN . "/" . $_path; } } elseif (is_dir("files/" . DOMAIN . "/" . $_path)) { $path = "files/" . DOMAIN . "/" . $_path; } elseif (is_file("files/" . DOMAIN . "/" . $_path)) { $file = "files/" . DOMAIN . "/" . $_path; } if (!empty($file) && extension_loaded('zip')) { delDir("files/" . DOMAIN . "/tmp"); mk_dir("files/" . DOMAIN . "/tmp"); $zip = new ZipArchive(); $zip->open($file); if ($zip->extractTo("files/" . DOMAIN . "/tmp")) { $path = "files/" . DOMAIN . "/tmp"; } $zip->close(); } if (!empty($path)) { $images = scandir($path); $i = 1; foreach ($images as $file) { if ($file != '.' && $file != '..') { $idimg = RegisterImage("{$path}/{$file}", '', 0, $album['id'], $sort + $i++, A::$OPTIONS['img_resize'], A::$OPTIONS['img_x'], A::$OPTIONS['img_y']); if (empty($album['idimg'])) { A::$DB->Update(SECTION . "_albums", array('idimg' => $idimg), "id=" . $album['id']); $album['idimg'] = $idimg; } } } } } } return true; }