Ejemplo n.º 1
0
function editBook()
{
    if (!isLogged()) {
        header('Location: ./');
        exit;
    }
    $books = new Books(isLogged());
    $id = (int) $_GET['edit'] + 0;
    if (!isset($books[$id])) {
        notFound();
    }
    $book = $books[$id];
    global $tpl;
    global $_CONFIG;
    // process to edit book in database
    if (isset($_POST) && !empty($_POST)) {
        if (!empty($_POST['token']) && acceptToken($_POST['token'])) {
            $inputs = array('title' => isset($_POST['title']) ? trim(htmlspecialchars($_POST['title'])) : NULL, 'author' => isset($_POST['author']) ? trim(htmlspecialchars($_POST['author'])) : NULL, 'summary' => isset($_POST['summary']) ? checkNewLineContent($_POST['summary']) : NULL, 'publisher' => isset($_POST['publisher']) ? trim(htmlspecialchars($_POST['publisher'])) : NULL, 'status' => isset($_POST['status']) ? Book::SEEN : NULL, 'note' => isset($_POST['note']) ? checkRatingNote($_POST['note'], isset($_POST['status']) ? Book::SEEN : NULL) : NULL, 'read_date' => isset($_POST['read_date']) ? checkInputDate($_POST['read_date']) : NULL, 'review' => isset($_POST['review']) ? checkNewLineContent($_POST['review']) : NULL, 'genre' => isset($_POST['genre']) ? checkGenre($_POST['genre']) : NULL, 'publication_year' => isset($_POST['publication_year']) ? checkInputYear($_POST['publication_year']) : NULL, 'pages' => isset($_POST['pages']) ? checkPages($_POST['pages']) : NULL, 'country' => isset($_POST['country']) ? checkCountry($_POST['country']) : NULL, 'link_website' => isset($_POST['link_website']) ? checkLink($_POST['link_website']) : NULL, 'link_image' => isset($_POST['link_image']) ? checkLink($_POST['link_image']) : NULL, 'link_image_import' => isset($_POST['link_image_import']) ? TRUE : NULL);
            try {
                if (empty($inputs['title'])) {
                    throw new \Exception('Title must not be empty.');
                }
                if (empty($inputs['author'])) {
                    throw new \Exception('Author must not be empty.');
                }
                if (empty($inputs['summary'])) {
                    throw new \Exception('Summary must not be empty.');
                }
                $book = array('id' => $id);
                // check if we need to get the image given with url
                if ($inputs['link_image_import']) {
                    importImage($inputs['link_image'], $book['id']);
                    $inputs['link_image'] = $_CONFIG['images'] . '/' . $id . '.jpg';
                }
                unset($inputs['link_image_import']);
                foreach ($inputs as $key => $value) {
                    $book[$key] = $value;
                }
                $books[$id] = $book;
                $books->save();
                header('Location: ' . Path::book($id));
                exit;
            } catch (\Exception $e) {
                $tpl->assign('error', $e->getMessage());
            }
        } else {
            errorPage('The received token was empty or invalid.', 'Invalid security token');
        }
    } else {
        $inputs = array('title' => $book['title'], 'author' => $book['author'], 'summary' => str_replace('<br />', '', $book['summary']), 'publisher' => $book['publisher'], 'status' => $book['status'], 'note' => $book['note'], 'read_date' => $book['read_date'], 'review' => str_replace('<br />', '', $book['review']), 'genre' => $book['genre'], 'publication_year' => $book['publication_year'], 'pages' => $book['pages'], 'country' => $book['country'], 'link_website' => preg_replace('#http://#', '', $book['link_website']), 'link_image' => preg_replace('#http://#', '', $book['link_image']));
    }
    $tpl->assign('page_title', 'Edit book');
    $tpl->assign('menu_links', Path::menu('edit'));
    $tpl->assign('menu_links_admin', Path::menuAdmin('edit'));
    $tpl->assign('inputs', $inputs);
    $tpl->assign('today', date('Y-m-d'));
    $tpl->assign('countries', displayCountryOptions($inputs['country']));
    $tpl->assign('token', getToken());
    $tpl->assign('target', Path::edit($id));
    $tpl->assign('delete', Path::delete($id));
    $tpl->draw('form.book');
    exit;
}
Ejemplo n.º 2
0
      <td class="field_name">
      <vllabel validators="shipping_zip_required,shipping_zip_syntax" errclass="error" for="shipping_zip" cerrclass="controlerror">Zip:</vllabel>
      </td>
<td><input id="shipping_zip" type="text" name="shipping_zip" size="40" ></td>
    <vlvalidator name="shipping_zip_required" type="required" control="shipping_zip" errmsg="'Zip' is required in Shipping Information">
    <vlvalidator name="shipping_zip_syntax" type="regexp" control="shipping_zip" errmsg="'Zip' in Shipping Information is not valid" regexp="/^[0-9a-zA-Z]+[- ]?[0-9a-zA-Z]*?$/">
    </tr>
    
    <tr align="left" valign="top" bgcolor="f0f0f0"> 
      <td class="field_name">
      <vllabel validators="shipping_country_required" errclass="error" for="shipping_country" cerrclass="controlerror">Country:</vllabel>
      </td>
<td><select name="shipping_country">
<option value="" selected>Choose a Country 
	<?php 
echo displayCountryOptions();
?>
     </select></td>
         <vlvalidator name="shipping_country_required" type="required" control="shipping_country" errmsg="'Country' is required in Shipping Information">
   </tr>
  </table>
  <br>
<br>
  <table width="500" align="center" cellpadding="4" cellspacing="0" class="border_configuration">
    <tr align="left" valign="top" bgcolor="#FFFFFF"> 
      <td colspan="2" bgcolor="666666" class="header"><div align="center"><b> 
          CREDIT CARD INFORMATION</b></div></td>
    </tr>
    <tr align="left" valign="top" bgcolor="f0f0f0"> 
      <td width="145" class="field_name">&nbsp;</td>
      <td width="337"><img src="images/cclogos2.gif" width="200" height="30"></td>