-
Notifications
You must be signed in to change notification settings - Fork 11
/
display_books.inc
executable file
·154 lines (154 loc) · 6.15 KB
/
display_books.inc
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
/* function to display books in progress */
function tbc_books_in_progress_all()
{
$output = "";
$query = db_select('list_of_category');
$query->fields('list_of_category');
$query->orderBy('id', 'ASC');
$category_list = $query->execute();
$query = "
SELECT po.creation_date, pe.book as book, pe.author as author, pe.publisher as publisher,pe.edition as edition, pe.isbn as isbn, pe.year as year, pe.id as pe_id, loc.category_name as category, loc.category_id as cat_id
FROM textbook_companion_preference pe
LEFT JOIN textbook_companion_proposal po ON pe.proposal_id = po.id
LEFT JOIN list_of_category loc on pe.category = loc.category_id
WHERE po.proposal_status IN (1,4) AND pe.approval_status = 1
ORDER BY po.creation_date DESC
";
$result = db_query($query);
$proposal_rows = array();
$i = 1;
$category_data = _tbc_list_of_category($preference_data->category);
$output = "<hr>";
while ($row = $result->fetchObject())
{
$proposal_date = date("d-m-Y", $row->creation_date); // remove comment to display year
if ($row->category != NULL)
{
$category = $row->category;
} //$row->category != NULL
else
{
$category = "Not assigned";
}
$preference_rows[] = array(
$i,
$proposal_date,
$row->book . "<br><br>[ Author: " . $row->author . ", Publisher: " . $row->publisher . ", Year: " . $row->year . ", Edition: " . $row->edition . ", ISBN: " . $row->isbn . " ]",
$category
);
$i++;
} //$row = $result->fetchObject()
$preference_header = array(
'No',
'Proposal Date',
'Book',
'Category'
);
$output .= theme('table', array(
'header' => $preference_header,
'rows' => $preference_rows
));
return $output;
}
function _textbook_companion_list_of_new_category($category_id = NULL)
{
$category .= "";
if ($category_id != NULL)
{
$query = db_select('list_of_category');
$query->fields('list_of_category');
$query->condition('id', $category_id);
$category_list = $query->execute();
$category .= "<ul>";
} //$category_id != NULL
else
{
$category_list = db_query('SELECT * FROM list_of_category WHERE category_id != 0');
}
$i = 1;
while ($category_list_data = $category_list->fetchObject())
{
$category .= "<li><a href=#$i>$category_list_data->maincategory</a></li>";
$i++;
} //$category_list_data = $category_list->fetchObject()
$category .= "</ul>";
return $category;
}
function _textbook_companion_list_of_new_category_display($category_id = NULL)
{
$category .= "";
if ($category_id != NULL)
{
$query = db_select('list_of_category');
$query->fields('list_of_category');
$query->condition('id', $category_id);
$category_list = $query->execute();
} //$category_id != NULL
else
{
$category_list = db_query('SELECT * FROM list_of_category WHERE category_id != 0');
}
while ($category_list_data = $category_list->fetchObject())
{
$category .= "<li>$category_list_data->maincategory</li>";
$query_sub_cat = db_select('list_of_subcategory');
$query_sub_cat->fields('list_of_subcategory');
$query_sub_cat->condition('maincategory_id', $category_id);
$subcategory_list = $query_sub_cat->execute();
$category .= "<ol style='list-style-type: lower-roman;'><h5>";
while ($sub_category_list_data = $subcategory_list->fetchObject())
{
$preference_q = db_query("
SELECT DISTINCT (tcbm.sub_category), los.subcategory, loc.category_id,loc.maincategory,
pe.book as book, pe.author as author, pe.publisher as publisher, pe.year as year, pe.id as pe_id,
po.approval_date as approval_date
FROM textbook_companion_preference pe
LEFT JOIN textbook_companion_proposal po ON pe.proposal_id = po.id
LEFT JOIN textbook_companion_book_main_subcategories tcbm ON pe.id = tcbm.pref_id
LEFT JOIN list_of_category loc ON tcbm.main_category = loc.category_id
LEFT JOIN list_of_subcategory los ON tcbm.sub_category = los.subcategory_id
WHERE po.proposal_status = 3 AND pe.approval_status = 1 AND pe.category>0
AND pe.id = tcbm.pref_id AND tcbm.sub_category= :subcategory", array(
":subcategory" => $sub_category_list_data->subcategory_id
));
$category .= "<li>$sub_category_list_data->subcategory</li>";
$category .= "<ol style='list-style-type: decimal;'>";
while ($preference_data = $preference_q->fetchObject())
{
if ($sub_category_list_data->subcategory == $preference_data->subcategory && $sub_category_list_data->maincategory_id == $preference_data->category_id)
{
$category .= "<li>";
$category .= l($preference_data->book . " by " . $preference_data->author . ", " . $preference_data->publisher . ", " . $preference_data->year, 'textbook_run/' . $preference_data->pe_id);
$category .= "</li>";
} //$sub_category_list_data->subcategory == $preference_data->subcategory && $sub_category_list_data->maincategory_id == $preference_data->category_id
} //$preference_data = $preference_q->fetchObject()
$category .= "</ol>";
} //$sub_category_list_data = $subcategory_list->fetchObject()
$category .= "</h5></ol>";
} //$category_list_data = $category_list->fetchObject()
return $category;
}
/* Display Completed books */
function tbc_completed_books_all()
{
$category_id = NULL;
$output = "";
$output = "<h4>Category</h4>";
$output .= "<hr style='background-color: #abb2b8;' /><div style='width:100%; float:left;'><h4>";
$output .= _textbook_companion_list_of_new_category($category_id);
$output .= "</h4></div>";
$result_count = db_query("SELECT pe.book FROM textbook_companion_preference pe LEFT JOIN textbook_companion_proposal po ON pe.proposal_id = po.id WHERE po.proposal_status =3 AND pe.approval_status =1 AND pe.category>0");
$row_count = $result_count->rowCount();
$output .= "<p style='clear: both;'>Total number of completed books : " . $row_count . " </p>";
$output .= "<hr style='background-color: #abb2b8;' />";
$result_category = db_query("SELECT * FROM list_of_category WHERE category_id !=0");
$row_category_count = $result_category->rowCount();
$output .= "<ol style='list-style-type: upper-roman;'><h4>";
for ($i = 1; $i <= $row_category_count; $i++)
{
$output .= "<div id=$i>" . _textbook_companion_list_of_new_category_display($i) . "</div><br>";
} //$i = 1; $i <= $row_category_count; $i++
$output .= "</h4></ol>";
return $output;
}