-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbook.php
More file actions
65 lines (53 loc) · 1.62 KB
/
book.php
File metadata and controls
65 lines (53 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
require_once 'util.php';
require_once 'db_helper.php';
$id = decode_and_int($_REQUEST['id']);
$db = getDBInstance();
$book = getRowById($db, 'books', $id);
// $db->debug();
$smarty = getSmartyInstance();
$smarty->assign('book',$book);
$sql = "select c.* from categories c, book_category bc where bc.book_id = $id and bc.category_id = c.id;";
$categories = $db->get_results($sql);
// $db->debug();
$smarty->assign('categories',$categories);
$type = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'VIEW';
if($type == 'VIEW'){
$smarty->display('book.html');
}elseif($type == 'EDIT'){
$all_categories = getAllRows($db, 'categories');
if($book->pages){
$aids = str_replace('|',',',$book->pages);
$pages = getRowsByCondition($db, 'attachments', array("id in ($aids)"));
$attachments = array();
foreach (explode('|',$book->pages) as $aid){
$attachments[$aid] = null;
}
foreach ($pages as $p){
if(key_exists($p->id, $attachments)){
$attachments[$p->id] = $p;
}
}
unset($_SESSION['attachments']);
$_SESSION['attachments'] = array();
foreach ($attachments as $k=>$v){
$_SESSION['attachments'][$k] = array('url'=>$v->file_url,'path'=>$v->file_path);
}
}else{
$attachments = array();
}
$select_ids = array();
if($categories){
foreach ($categories as $c){
$select_ids[] = $c->id;
}
}
$smarty->assign('all_categories',$all_categories);
$smarty->assign('select_ids',$select_ids);
$smarty->assign('attachments',$attachments);
$smarty->display('book_edit.html');
}else{
message('No such action!');
redirect('index.php');
}
?>