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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
|
<?php
function textbook_run_menu() {
$items = array();
$items["textbook_runs"] = array(
"title" => "Download Codes",
"page callback" => "textbook_run_all",
"access arguments" => array("textbook-run view/hide"),
"type" => MENU_CALLBACK
);
$items["textbook_runs/ajax"] = array(
"page callback" => "textbook_run_ajax",
"access callback" => TRUE,
"type" => MENU_CALLBACK
);
$items["textbook_runs/books/ajax"] = array(
"page callback" => "textbook_run_books_ajax",
"access callback" => TRUE,
"type" => MENU_CALLBACK
);
return $items;
}
function textbook_run_perm() {
return array(
"textbook-run view/hide",
);
}
function textbook_run_all(){
$url_book_id = (int)arg(1);
if ($url_book_id)
{
/* add javascript for book selected */
$chapter_name_js = " $(document).ready(function() {
$('#select_book').val(" . $url_book_id . ");
$('#select_book').change();
});";
drupal_add_js($chapter_name_js, 'inline', 'footer');
$book_titles_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d AND category= 3 AND approval_status = 1 AND proposal_id IN (SELECT id FROM textbook_companion_proposal WHERE proposal_status=3) ORDER BY book ASC", $url_book_id);
}
else{
$book_titles_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE category= 3 AND approval_status = 1 AND proposal_id IN (SELECT id FROM textbook_companion_proposal WHERE proposal_status=3) ORDER BY book ASC");
}
$page_content .= "";
$page_content .= "<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js'></script>";
$page_content .= "<div id = 'textbook_run_manage'>";
$page_content .= "";
$page_content .= "<form id='form_feedback_example' method='post' class= 'form_comments'>";
//$page_content .= "<input type='hidden' name='postid' value=".$id.">";
$page_content .= "<label>";
$page_content .= "<span><b>Title of the Book: </b></span><br><br>";
$page_content.= "<select id='select_book'><option value='0'>Please Select a book</option>";
while ($book_titles_data = db_fetch_object($book_titles_q))
{
$page_content.= "<option value='".$book_titles_data->id."'>".$book_titles_data->book . ' (Written by ' . $book_titles_data->author . ')'."</option>";
}
$page_content .= "</select>";
$page_content .= "<div id= 'entire_book'></div>";
$page_content .= "<div id= 'entire_chapter'></div>";
$page_content .= "<div id= 'entire_example'></div>";
$page_content .= "<div id= 'feedback_example'>";
$page_content .= "<label></label>";
// $page_content .= "<textarea id='feedback_example' rows='5' cols='60'></textarea></div>";
// $page_content .= "<input type='submit' value='Submit' class= 'submit_form_feedback_example' >";
$page_content .= "</form>";
$page_content .= "</div>";
return $page_content;
}
function textbook_run_ajax() {
$data = "";
//$value =$_POST['value'];
if(isset($_POST['id']) && isset($_POST['type'])){
$type =mysql_real_escape_string($_POST['type']);
$id =mysql_real_escape_string($_POST['id']);
}
//$chapter_id =
if($type== "select_book"){
$book_details = db_fetch_object(db_query("SELECT
preference.book as preference_book, preference.author as preference_author, preference.isbn as preference_isbn, preference.publisher as preference_publisher, preference.edition as preference_edition, preference.year as preference_year,
proposal.full_name as proposal_full_name, proposal.faculty as proposal_faculty, proposal.reviewer as proposal_reviewer, proposal.course as proposal_course, proposal.branch as proposal_branch, proposal.university as proposal_university
FROM {textbook_companion_proposal} proposal LEFT JOIN {textbook_companion_preference} preference ON proposal.id = preference.proposal_id WHERE preference.id = %d", $id));
$data .= "<br>";
$data .= "<table cellspacing='1' cellpadding='1' border='0' style='width: 100%;' valign='top'>" .
"<tr><td style='width: 35%;'><span style='color: rgb(128, 0, 0);'><strong>About the Book</strong></span></td><td style='width: 35%;'><span style='color: rgb(128, 0, 0);'>
<strong>About the Contributor</strong></span></td>" .
"<tr><td valign='top'><ul>" .
"<li><strong>Author:</strong> " . $book_details->preference_author . "</li>" .
"<li><strong>Title of the Book:</strong> " . $book_details->preference_book . "</li>" .
"<li><strong>Publisher:</strong> " . $book_details->preference_publisher . "</li>" .
"<li><strong>Year:</strong> " . $book_details->preference_year . "</li>" .
"<li><strong>Edition:</strong> " . $book_details->preference_edition . "</li>" .
"</ul></td><td valign='top'><ul>" .
"<li><strong>Contributor Name: </strong>" . $book_details->proposal_full_name . ", " . $book_details->proposal_course . ", " . $book_details->proposal_branch . ", " . $book_details->proposal_university . "</li>" .
"<li><strong>College Teacher: </strong>" . $book_details->proposal_faculty . "</li>" .
"<li><strong>Reviewer: </strong>" . $book_details->proposal_reviewer . "</li>" .
"</ul></td></tr>" .
"</table>";
$data .= "<span><a href= '../full_download/book/".$id."'><b>Download</b></a> (Download DWSIM codes for all the solved examples) </span><br>";
$data .= "<br>";
$data .= "<br>";
$data .= "<span><b>Title of the chapter: </b></span><br><br>";
$data .= "<select id='select_chapter'><option value='0'>Please Select a chapter</option>";
$book_titles_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE preference_id = %d ORDER BY number ASC", $id);
while ($book_titles_data = db_fetch_object($book_titles_q))
{
$data .= "<option value='".$book_titles_data->id."'>".$book_titles_data->number . ' (' . $book_titles_data->name . ')'."</option>";
}
$data .= "</select>";
echo $data;
exit();
}elseif($type== "select_chapter"){
$data .= "<br>";
$data .= "<br>";
$data .= "<span><a href= '../download/chapter/".$id."'><b>Download</b></a> (Download all the examples of the entire chapter) </span><br>";
$data .= "<br>";
$data .= "<br>";
$data .= "<span><b>Example Number (caption): </></span><br><br>";
$data .= "<select id='select_example'><option value='0'>Please Select a example</option>";
$example_titles_q = db_query("SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d", $id);
while ($example_titles_data = db_fetch_object($example_titles_q))
{
$data .= "<option value='".$example_titles_data->id."'>".$example_titles_data->number . ' (' . $example_titles_data->caption . ')'."</option>";
}
$data .= "</select>";
echo $data;
exit();
} elseif($type== "select_example"){
$data .= "<br>";
$data .= "<span><a href= '../download/file/".$id."'><b>Download</b></a> (Download example) </span><br>";
$data .= "<br>";
$data .= "<b>List of example file(s): <b>";
$example_list_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE example_id = %d", $id);
if ($example_list_q)
{
$example_files_rows = array();
while ($example_list_data = db_fetch_object($example_list_q))
{
$example_file_type = 'Source or Main file';
$example_files_rows[] = array(l($example_list_data->filename, 'download/file/' . $example_list_data->id), $example_file_type);
}
/* creating list of files table */
$example_files_header = array('Filename', 'Type');
$example_files = theme_table($example_files_header, $example_files_rows);
}
$data .= $example_files ;
$data .= "<br>";
//$data .= "Feedback on the above example: ";
echo $data;
exit();
}
else{
$data .= "Please try again";
echo json_encode($data);
exit();
}
}
// function textbook_run_books_ajax() {
// global $user;
// $data .= "";
// if(isset($_POST['pref_id']) && isset($_POST['action'])){
// $pref_id = mysql_real_escape_string($_POST['pref_id']);
// $action = mysql_real_escape_string($_POST['action']);
// $disapproval_reason = mysql_real_escape_string($_POST['dis_approve_reason']);
// }
// if($action == 1)
// {
// $data .= "";
// /* approving entire book */
// $query= "
// SELECT * FROM textbook_companion_preference WHERE id = %d ";
// $book_Q= db_query($query, $id);
// $chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE preference_id = %d", $pref_id);
// while ($chapter_data = db_fetch_object($chapter_q))
// {
// db_query("UPDATE {textbook_companion_example} SET approval_status = 1, approver_uid = %d WHERE chapter_id = %d AND approval_status = 0", $user->uid, $chapter_data->id);
// }
// $email_subject = t('Your uploaded examples have been approved');
// $email_body = t('Your all the uploaded examples for the book have been approved.');
// if ($email_subject)
// {
// $email_to = $user->mail;
// $param['standard']['subject'] = $email_subject;
// $param['standard']['body'] = $email_body;
// if (!drupal_mail('textbook_companion', 'standard', $email_to, language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE))
// $data .='Error sending email message.';
// }
// $data .= "Approved Entire Book";
// echo $data;
// exit();
// }elseif($action == 4){
// $root_path = textbook_companion_path();
// $data .= "";
// /* check if dependency files are present */
// // $dep_q = db_query("SELECT * FROM {textbook_companion_dependency_files} WHERE preference_id = %d", $pref_id);
// // if ($dep_data = db_fetch_object($dep_q))
// // {
// // drupal_set_message(t("Cannot delete book since it has dependency files that can be used by others. First delete the dependency files before deleing the Book."), 'error');
// // }
// if (delete_books($pref_id))
// {
// $dir_path = $root_path . $pref_id;
// if (is_dir($dir_path))
// {
// $res = rmdir($dir_path);
// if (!$res)
// {
// $data .= "Cannot delete Book directory : " . $dir_path . ". Please contact administrator.";
// echo $data;
// exit();
// }
// } else {
// $data = "Book directory not present : " . $dir_path . ". Skipping deleting book directory.";
// echo $data;
// exit();
// }
// /* deleting preference and proposal */
// $preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d", $pref_id);
// $preference_data = db_fetch_object($preference_q);
// $proposal_id = $preference_data->proposal_id;
// db_query("DELETE FROM {textbook_companion_preference} WHERE proposal_id = %d", $proposal_id);
// db_query("DELETE FROM {textbook_companion_proposal} WHERE id = %d", $proposal_id);
// $data .= 'Deleted Book Proposal.';
// /* email */
// $email_subject = t('Your uploaded examples including the book proposal have been deleted');
// $email_body = t('Your all the uploaded examples including the book have been deleted permanently.
// Reason for deletion:
// ' . $disapproval_reason);
// if ($email_subject)
// {
// $email_to = $user->mail;
// $param['standard']['subject'] = $email_subject;
// $param['standard']['body'] = $email_body;
// if (!drupal_mail('textbook_companion', 'standard', $email_to, language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE))
// $data .='Error sending email message.';
// echo $data;
// exit();
// }
// } else {
// $data .= "Error Dis-Approving and Deleting Entire Book.";
// echo $data;
// exit();
// }
// }
// }
function textbook_run_init() {
drupal_add_js(drupal_get_path("module", "textbook_run") . "/js/textbook_run_ajax.js");
drupal_add_js(drupal_get_path("module", "textbook_run") . "/js/jquery-1.4.1.min.js");
drupal_add_js(drupal_get_path("module", "textbook_run") . "/js/jquery-1.2.6.min.js");
}
?>
|