function check_post_values() { if (!isset($_POST['catalog_name'])) { return false; } $name = $_POST['catalog_name']; $name .= '.txt'; $fields = $_POST['fields']; $path = 'users/' . $_SESSION['ms_username'] . '/'; $catalogs = get_catalogs(); // Make sure that catalog does not eists. foreach ($catalogs as $tmp) { if ($tmp == $name) { echo 'Catalog already exists with this name!'; return false; } } $fh = @fopen($path . $name, 'w'); if (!$fh) { echo 'Cannot create catalogue file!'; return false; } // Write fields in the first row of catalog. $fields = str_replace(',', '|', $fields); fwrite($fh, $fields . "\n"); fclose($fh); return true; }
function show_main_page() { $catalogs = get_catalogs(); if (count($catalogs) == 0) { echo 'No catalogues found.<br /><br />'; } else { echo '<div id="list_catalogs">'; echo '<table>'; foreach ($catalogs as $tmp) { $name_tmp = explode('.', $tmp); $name = $name_tmp[0]; echo '<tr>'; echo '<td>'; echo '<a href="catalogs.php?catalog=' . $tmp . '">' . $name . '</a><br />'; echo '</td>'; echo '<td width="20%">'; echo '<a href="remove.php?catalog=' . $tmp . '">Delete</a>'; echo '</td>'; echo '</tr>'; } echo '</table>'; echo '</div>'; } echo '<div id="main_links">'; echo '<a href="edit_catalogues.php">Create new catalog</a>'; echo '<a href="logout.php">Logout</a>'; echo '</div>'; }