summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorprashant2015-09-24 12:23:41 +0530
committerprashant2015-09-24 12:23:41 +0530
commit058634843b44a2cf695c77fcb7d30d6feb2a9e12 (patch)
treeaae29dc64c21cadaef54bf495f4fae342ef9d916
parentba081ebbf3bccd0c6d8aa98798fc5c396bea0f48 (diff)
downloadscilab_textbook_companion-058634843b44a2cf695c77fcb7d30d6feb2a9e12.tar.gz
scilab_textbook_companion-058634843b44a2cf695c77fcb7d30d6feb2a9e12.tar.bz2
scilab_textbook_companion-058634843b44a2cf695c77fcb7d30d6feb2a9e12.zip
module updated to Drupal 7
-rwxr-xr-xcheque_contact.inc376
-rwxr-xr-xcheque_manage.inc44
-rwxr-xr-xcode.inc292
-rwxr-xr-xcode_approval.inc968
-rwxr-xr-xdependency.inc309
-rwxr-xr-xdependency_approval.inc91
-rwxr-xr-xdownload.inc185
-rwxr-xr-xeditcode.inc506
-rwxr-xr-xeditcodeadmin.inc358
-rwxr-xr-xfull_download.inc153
-rwxr-xr-xgeneral.inc135
-rwxr-xr-xlatex.inc80
-rwxr-xr-xlatex/Initial_body113
-rwxr-xr-xlatex/latex_test.sh8
-rwxr-xr-xlatex/pdf_creator.sh11
-rwxr-xr-xmanage_proposal.inc780
-rwxr-xr-xnotes.inc84
-rwxr-xr-xpdf/151
-rwxr-xr-xpdf/1/1 FWR/FWR-cache.bak99
-rwxr-xr-xpdf/1/1 FWR/FWR-cache.lib125
-rwxr-xr-xpdf/1/1 FWR/FWR.bak204
-rwxr-xr-xpdf/1/1 FWR/FWR.cir16
-rwxr-xr-xpdf/1/1 FWR/FWR.cir.ckt14
-rwxr-xr-xpdf/1/1 FWR/FWR.cir.out21
-rwxr-xr-xpdf/1/1 FWR/FWR.pro74
-rwxr-xr-xpdf/1/1 FWR/FWR.proj1
-rwxr-xr-xpdf/1/1 FWR/FWR.sch199
-rwxr-xr-xpdf/1/1 FWR/FWR_last_input.txt1
-rwxr-xr-xpdf/1/1 FWR/analysis1
-rwxr-xr-xpdf/1/1 FWR/eeschema.exebin0 -> 6768128 bytes
-rwxr-xr-xpdf/1/1 FWR/libfftw3-3.dllbin0 -> 2365756 bytes
-rwxr-xr-xpdf/1/1 FWR/ngspice.exebin0 -> 4744192 bytes
-rwxr-xr-xpdf/1/1 FWR/plot_data_i.txt116
-rwxr-xr-xpdf/1/1 FWR/plot_data_v.txt116
-rwxr-xr-xpdf/1/1 FWR/python.exebin0 -> 26624 bytes
-rwxr-xr-xpdf/1/1 FWR/vcomp100.dllbin0 -> 51024 bytes
-rwxr-xr-xpdf/1/1.pdfbin0 -> 103290 bytes
-rwxr-xr-xpdf/generate_pdf.inc37
-rwxr-xr-xpdf/list_all_certificates.inc10
-rwxr-xr-xrun.inc1018
-rwxr-xr-xsearch.inc195
-rwxr-xr-xsettings.inc10
-rwxr-xr-xtextbook_companion.info4
-rwxr-xr-xtextbook_companion.module1306
44 files changed, 6066 insertions, 2045 deletions
diff --git a/cheque_contact.inc b/cheque_contact.inc
index 335ee42..c623ef4 100755
--- a/cheque_contact.inc
+++ b/cheque_contact.inc
@@ -6,12 +6,19 @@ function paper_submission_form($form_state, $proposal_id)
$proposal_id = arg(2);
/* get current proposal */
- $preference4_q = db_query("SELECT * FROM {textbook_companion_paper} WHERE proposal_id=".$proposal_id);
+
+ /*$preference4_q = db_query("SELECT * FROM {textbook_companion_paper} WHERE proposal_id=".$proposal_id);*/
+
+ $query = db_select('textbook_companion_paper');
+ $query->fields('textbook_companion_paper');
+ $query->condition('proposal_id', $proposal_id);
+ $preference4_q = $query->execute();
+
$form1=0;
$form2=0;
$form3=0;
$form4=0;
- if($data = db_fetch_object($preference4_q))
+ if($data = $preference4_q->fetchObject())
{
$form1 = $data->internship_form;
$form2 = $data->copyright_form;
@@ -20,8 +27,11 @@ function paper_submission_form($form_state, $proposal_id)
}
else
{
- $query = "insert into {textbook_companion_paper} (proposal_id) values(".$proposal_id.")";
- db_query($query);
+ $query = "Insert into {textbook_companion_paper} (proposal_id) values (:proposal_id)";
+ $args = array(
+ ":proposal_id"=>$proposal_id,
+ );
+ $result = db_query($query, $args, array('return' => Database::RETURN_INSERT_ID));
}
$form['proposal_id'] =array(
'#type' => 'hidden',
@@ -65,8 +75,18 @@ function paper_submission_form($form_state, $proposal_id)
function paper_submission_form_submit($form, &$form_state)
{
- $query ="UPDATE {textbook_companion_paper} SET internship_form = ".$form_state['values']['internshipform'].", copyright_form = ".$form_state['values']['copyrighttransferform'].", undertaking_form= ".$form_state['values']['undertakingform'].", reciept_form= ".$form_state['values']['recieptform']." WHERE proposal_id = ".$form_state['values']['proposal_id'];
- db_query($query);
+ /*$query ="UPDATE {textbook_companion_paper} SET internship_form = ".$form_state['values']['internshipform'].", copyright_form = ".$form_state['values']['copyrighttransferform'].", undertaking_form= ".$form_state['values']['undertakingform'].", reciept_form= ".$form_state['values']['recieptform']." WHERE proposal_id = ".$form_state['values']['proposal_id'];
+ db_query($query);*/
+
+ $query = db_update('textbook_companion_paper');
+ $query->fields(array(
+ 'internship_form' => $form_state[ values ][ internshipform ],
+ 'copyright_form' => $form_state[ values ][ copyrighttransferform ],
+ 'undertaking_form' => $form_state[ values ][ undertakingform ],
+ 'reciept_form' => $form_state[ values ][ recieptform ],
+ ));
+ $query->condition('proposal_id', $form_state['values']['proposal_id']);
+ $num_updated = $query->execute();
/************************************************
Check For the Internship Form is checked or not
@@ -204,8 +224,14 @@ function cheque_contct_form()
{
global $user;
- $preference4_q = db_query("SELECT id FROM {textbook_companion_proposal} WHERE uid=".$user->uid);
- $data = db_fetch_object($preference4_q);
+ /*$preference4_q = db_query("SELECT id FROM {textbook_companion_proposal} WHERE uid=".$user->uid);*/
+
+ $query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal', array('id'));
+ $query->condition('uid', $user->uid);
+ $result = $query->execute();
+ $data = $result->fetchObject();
+
$form1 = $data->id;
if($user->uid)
@@ -234,20 +260,26 @@ function cheque_contct_form()
'#attributes' => array('id' => 'perm_report'),
);
- $search_q = db_query("SELECT * FROM textbook_companion_proposal p,textbook_companion_cheque c WHERE c.address_con = 'Submitted' AND (p.id = c.proposal_id)");
+ /*$search_q = db_query("SELECT * FROM textbook_companion_proposal p,textbook_companion_cheque c WHERE c.address_con = 'Submitted' AND (p.id = c.proposal_id)");*/
+ $query = db_select('textbook_companion_proposal', 'p');
+ $query->join('textbook_companion_cheque','c','p.id = c.proposal_id');
+ $query->fields('p');
+ $query->fields('c');
+ $query->condition('c.address_con','Submitted');
+ $search_q = $query->execute();
- while ($search_data = db_fetch_object($search_q))
+ while ($search_data = $search_q->fetchObject())
{
$search_rows[] = array(l($search_data->full_name, 'cheque_contct/status/' . $search_data->proposal_id),$search_data->address_con,$search_data->cheque_no,$search_data->cheque_dispatch_date);
}
if ($search_rows)
{
$search_header = array('Name Of The Student', 'Application Form Status', 'Cheque No', 'Cheque Clearance Date');
- $output .= theme_table($search_header, $search_rows);
+ $output .= theme('table',array('header'=>$search_header, 'rows'=>$search_rows));
$form['search_results'] = array(
'#type' => 'item',
'#title' => $_POST['search'] ,
- '#value' => $output,
+ '#markup' => $output,
);
}
else
@@ -255,7 +287,7 @@ function cheque_contct_form()
$form['search_results'] = array(
'#type' => 'item',
'#title' => t('Search results for "') . $_POST['search'] . '"',
- '#value' => 'No results found',
+ '#markup' => 'No results found',
);
}
if ($_POST)
@@ -263,19 +295,29 @@ function cheque_contct_form()
$output = '';
$search_rows = array();
$search_quert = '';
- $search_q = db_query("SELECT * FROM textbook_companion_proposal p,textbook_companion_cheque c WHERE c.address_con = 'Submitted' AND (p.id = c.proposal_id) AND (p.full_name LIKE '%%%s%%')", $_POST['search']);
- while ($search_data = db_fetch_object($search_q))
+
+ /*$search_q = db_query("SELECT * FROM textbook_companion_proposal p,textbook_companion_cheque c WHERE c.address_con = 'Submitted' AND (p.id = c.proposal_id) AND (p.full_name LIKE '%%%s%%')", $_POST['search']);*/
+ $query = db_select('textbook_companion_proposal', 'p');
+ $query->join('textbook_companion_cheque','c','p.id = c.proposal_id');
+ $query->fields('p');
+ $query->fields('c');
+ $query->condition('c.address_con', 'Submitted');
+ $query->condition('p.full_name', '%%'.$_POST['search'].'%%', 'LIKE');
+ $result = $query->execute();
+
+
+ while ($search_data = $result->fetchObject())
{
$search_rows[] = array(l($search_data->full_name, 'cheque_contct/status/' . $search_data->proposal_id),$search_data->address_con,$search_data->cheque_no,$search_data->cheque_dispatch_date);
}
if ($search_rows)
{
$search_header = array('Name Of The Student', 'Application Form Status', 'Cheque No', 'Cheque Clearance Date');
- $output .= theme_table($search_header, $search_rows);
+ $output .= theme('table',array('header'=>$search_header,'rows'=>$search_rows));
$form['search_results'] = array(
'#type' => 'item',
'#title' => t('Search results for "') . $_POST['search'] . '"',
- '#value' => $output,
+ '#markup' => $output,
);
}
else
@@ -283,7 +325,7 @@ function cheque_contct_form()
$form['search_results'] = array(
'#type' => 'item',
'#title' => t('Search results for "') . $_POST['search'] . '"',
- '#value' => 'No results found',
+ '#markup' => 'No results found',
);
}
}
@@ -291,14 +333,28 @@ function cheque_contct_form()
}
else
{
- $preference5_q = db_query("SELECT * FROM {textbook_companion_paper} WHERE proposal_id=".$form1);
- $data1 = db_fetch_object($preference5_q);
+ /*$preference5_q = db_query("SELECT * FROM {textbook_companion_paper} WHERE proposal_id=".$form1);
+ $data1 = db_fetch_object($preference5_q);*/
+ $query = db_select('textbook_companion_paper');
+ $query->fields('textbook_companion_paper');
+ $query->condition('proposal_id', $form1);
+ $result = $query->execute();
+ $data1=$result->fetchObject();
+
$form2 = $data1->internship_form;
$form3 = $data1->copyright_form;
$form4 = $data1->undertaking_form;
$form5 = $data1->reciept_form;
- $chq_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id=".$form1);
- $data_chq = db_fetch_object($chq_q);
+
+ /*$chq_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id=".$form1);
+ $data_chq = db_fetch_object($chq_q);*/
+
+ $query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal');
+ $query->condition('id', $form1);
+ $result = $query->execute();
+ $data_chq=$result->fetchObject();
+
$form9 = $data_chq->full_name;
$form8 = $data->how_project;
$form10 = $data_chq->mobile;
@@ -402,10 +458,21 @@ function cheque_status_form($form_state, $proposal_id)
/* get current proposal */
$proposal_id = arg(2);
- $proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id =".$proposal_id);
- $proposal_q1 = db_query("SELECT * FROM {textbook_companion_cheque} WHERE proposal_id =".$proposal_id);
- $proposal_data1 = db_fetch_object($proposal_q1);
- if (!$proposal_data = db_fetch_object($proposal_q))
+ /*$proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id =".$proposal_id);*/
+ $query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal');
+ $query->condition('id', $proposal_id);
+ $proposal_q = $query->execute();
+
+ /*$proposal_q1 = db_query("SELECT * FROM {textbook_companion_cheque} WHERE proposal_id =".$proposal_id);*/
+ $query = db_select('textbook_companion_cheque');
+ $query->fields('textbook_companion_cheque');
+ $query->condition('proposal_id', $proposal_id);
+ $proposal_q1 = $query->execute();
+
+
+ $proposal_data1 = $proposal_q1->fetchObject();
+ if (!$proposal_data = $proposal_q->fetchObject())
{
drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
drupal_goto('manage_proposal');
@@ -415,10 +482,22 @@ function cheque_status_form($form_state, $proposal_id)
'#type' => 'hidden',
'#default_value' => $proposal_id,
);
- $empty = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = ".$proposal_id);
+
+ /*$empty = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = ".$proposal_id);*/
+ $query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal');
+ $query->condition('id', $proposal_id);
+ $empty = $query->execute();
+
if(!$empty)
{
- $prop =db_query("insert into {textbook_companion_cheque} (proposal_id) values(%d)",$proposal_id);
+ /*$prop =db_query("insert into {textbook_companion_cheque} (proposal_id) values(%d)",$proposal_id);*/
+
+ $query = "insert into {textbook_companion_cheque} (proposal_id) values (:proposal_id)";
+ $args = array(
+ ":proposal_id"=>$proposal_id,
+ );
+ $result = db_query($query, $args, array('return' => Database::RETURN_INSERT_ID));
}
$form['candidate_detail'] = array(
'#type' => 'fieldset',
@@ -429,31 +508,44 @@ function cheque_status_form($form_state, $proposal_id)
);
$form['candidate_detail']['full_name'] = array(
'#type' => 'item',
- '#value' => $proposal_data->full_name,
+ '#markup' => $proposal_data->full_name,
'#title' => t('Contributor Name'),
);
$form['candidate_detail']['email'] = array(
'#type' => 'item',
- '#value' => user_load($proposal_data->uid)->mail,
+ '#markup' => user_load($proposal_data->uid)->mail,
'#title' => t('Email'),
);
$form['candidate_detail']['mobile'] = array(
'#type' => 'item',
- '#value' => $proposal_data->mobile,
+ '#markup' => $proposal_data->mobile,
'#title' => t('Mobile'),
);
$form['candidate_detail']['alt_mobile'] = array(
'#type' => 'item',
- '#value' => $proposal_data1->alt_mobno,
+ '#markup' => $proposal_data1->alt_mobno,
'#title' => t('Alternate Mobile No.'),
);
- $form_q=db_query("SELECT * FROM {textbook_companion_paper} WHERE proposal_id =".$proposal_id);
- $form_data=db_fetch_object($form_q);
+ /*$form_q=db_query("SELECT * FROM {textbook_companion_paper} WHERE proposal_id =".$proposal_id);
+ $form_data=db_fetch_object($form_q);*/
+
+ $query = db_select('textbook_companion_paper');
+ $query->fields('textbook_companion_paper');
+ $query->condition('proposal_id', $proposal_id);
+ $result = $query->execute();
+ $form_data=$result->fetchObject();
/* get book preference */
$preference_html = '<ul>';
- $preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d ORDER BY pref_number ASC", $proposal_id);
- while ($preference_data = db_fetch_object($preference_q))
+
+ /*$preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d ORDER BY pref_number ASC", $proposal_id);*/
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('proposal_id', $proposal_id);
+ $query->orderBy('pref_number', 'ASC');
+ $preference_q = $query->execute();
+
+ while ($preference_data = $preference_q->fetchObject())
{
if ($preference_data->approval_status == 1)
$preference_html .= '<li><strong>' . $preference_data->book . ' (Written by ' . $preference_data->author . ') - Approved Book</strong></li>';
@@ -470,11 +562,18 @@ function cheque_status_form($form_state, $proposal_id)
);
$form['book_preference_f']['book_preference'] = array(
'#type' => 'item',
- '#value' => $preference_html,
+ '#markup' => $preference_html,
'#title' => t('Book Preferences'),
);
- $chq_q=db_query("SELECT * FROM {textbook_companion_cheque} WHERE proposal_id = %d", $proposal_id);
- $chq_data=db_fetch_object($chq_q);
+
+ /*$chq_q=db_query("SELECT * FROM {textbook_companion_cheque} WHERE proposal_id = %d", $proposal_id);
+ $chq_data=db_fetch_object($chq_q);*/
+ $query = db_select('textbook_companion_cheque');
+ $query->fields('textbook_companion_cheque');
+ $query->condition('proposal_id', $proposal_id);
+ $result = $query->execute();
+ $chq_data=$result->fetchObject();
+
$form_html .= '<ul>';
if($form_data->internship_form)
{
@@ -503,7 +602,7 @@ function cheque_status_form($form_state, $proposal_id)
$form_html .= '</ul>';
$form['book_preference_f']['formsubmit'] = array(
'#type' => 'item',
- '#value' => $form_html,
+ '#markup' => $form_html,
'#title' => t('Application Form Status'),
);
$form['stu_cheque_details'] = array(
@@ -548,7 +647,11 @@ function cheque_status_form($form_state, $proposal_id)
'#collapsed' => FALSE,
'#attributes' => array('id' => 'commentf'),
);
- $chq4_q = db_query("SELECT * FROM {textbook_companion_cheque} WHERE proposal_id=".$proposal_id);
+ /*$chq4_q = db_query("SELECT * FROM {textbook_companion_cheque} WHERE proposal_id=".$proposal_id);*/
+ $query = db_select('textbook_companion_cheque');
+ $query->fields('textbook_companion_cheque');
+ $query->condition('proposal_id', $proposal_id);
+ $chq4_q = $query->execute();
$chq1 = '';
$chq2 = '';
@@ -567,7 +670,7 @@ function cheque_status_form($form_state, $proposal_id)
$chq15 = '';
$chq16 = '';
$chq17 = '';
- if($chqe = db_fetch_object($chq4_q))
+ if($chqe = $chq4_q->fetchObject())
{
$chq1 = $chqe->cheque_no;
$chq2 = $chqe->address;
@@ -772,8 +875,16 @@ function cheque_status_form($form_state, $proposal_id)
'#type' => 'hidden',
'#value' => $proposal_id,
);
- $preference1_p = db_query("SELECT * FROM {textbook_companion_paper} WHERE proposal_id = %d ORDER BY id ASC", $proposal_id);
- if (!($proposal_data1 = db_fetch_object($preference1_p)))
+
+ /*$preference1_p = db_query("SELECT * FROM {textbook_companion_paper} WHERE proposal_id = %d ORDER BY id ASC", $proposal_id); */
+
+ $query = db_select('textbook_companion_paper');
+ $query->fields('textbook_companion_paper');
+ $query->condition('proposal_id', $proposal_id);
+ $query->orderBy('id', 'ASC');
+ $preference1_p = $query->execute();
+
+ if (!($proposal_data1 = $preference1_p->fetchObject()))
{
drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
drupal_goto('manage_proposal');
@@ -821,7 +932,7 @@ function cheque_status_form_submit($form, &$form_state)
$proposal_id=arg(2);
- $query ="UPDATE {textbook_companion_cheque} SET
+ /*$query ="UPDATE {textbook_companion_cheque} SET
cheque_no = ".$form_state['values']['cheque_no'].",
cheque_amt = ".$form_state['values']['cheq_amt'].",
alt_mobno = '".$form_state['values']['mobileno2']."',
@@ -838,12 +949,41 @@ function cheque_status_form_submit($form, &$form_state)
t_cheque_amt = ".$form_state['values']['cheq_amt_t']."
WHERE proposal_id = ".$proposal_id;
- db_query($query);
+ db_query($query);*/
+
+ $query = db_update('textbook_companion_cheque');
+ $query->fields(array(
+ 'cheque_no' => $form_state[ values ][ cheque_no ],
+ 'cheque_amt' => $form_state[ values ][ cheq_amt ],
+ 'alt_mobno' => $form_state[ values ][ mobileno2 ],
+ 'address' => $form_state[ values ][ chq_address ],
+ 'perm_city' => $form_state[ values ][ perm_city ],
+ 'perm_state' => $form_state[ values ][ perm_state ],
+ 'perm_pincode' => $form_state[ values ][ perm_pincode ],
+ 'temp_chq_address' => $form_state[ values ][ temp_chq_address ],
+ 'temp_city' => $form_state[ values ][ temp_city ],
+ 'temp_state' => $form_state[ values ][ temp_state ],
+ 'temp_pincode' => $form_state[ values ][ temp_pincode ],
+ 'commentf' => $form_state[ values ][ comment_cheque ],
+ 't_cheque_no' => $form_state[ values ][ cheque_no_t ],
+ 't_cheque_amt' => $form_state[ values ][ cheq_amt_t ],
+ ));
+ $query->condition('proposal_id', $proposal_id);
+ $num_updated = $query->execute();
+
if ($form_state['values']['cheque_sent'] == 1)
{
/* sending email */
- $query ="UPDATE {textbook_companion_cheque} SET cheque_sent = ".$form_state['values']['cheque_sent']." WHERE proposal_id = ".$proposal_id;
- db_query($query);
+ /*$query ="UPDATE {textbook_companion_cheque} SET cheque_sent = ".$form_state['values']['cheque_sent']." WHERE proposal_id = ".$proposal_id;
+ db_query($query);*/
+
+ $query = db_update('textbook_companion_cheque');
+ $query->fields(array(
+ 'cheque_sent' => $form_state[ values ][ cheque_sent ],
+ ));
+ $query->condition('proposal_id', $proposal_id);
+ $num_updated = $query->execute();
+
$book_user = user_load($proposal_data->uid);
$param['proposal_completed']['proposal_id'] = $proposal_id;
$param['proposal_completed']['user_id'] = $proposal_data->uid;
@@ -856,13 +996,28 @@ function cheque_status_form_submit($form, &$form_state)
if ($form_state['values']['cheque_cleared'] == 1)
{
- $query ="UPDATE {textbook_companion_cheque} SET cheque_cleared = ".$form_state['values']['cheque_cleared']." WHERE proposal_id = ".$proposal_id;
- db_query($query);
+ /*$query ="UPDATE {textbook_companion_cheque} SET cheque_cleared = ".$form_state['values']['cheque_cleared']." WHERE proposal_id = ".$proposal_id;
+ db_query($query);*/
+
+ $query = db_update('textbook_companion_cheque');
+ $query->fields(array(
+ 'cheque_cleared' => $form_state[ values ][ cheque_cleared ],
+ ));
+ $query->condition('proposal_id', $proposal_id);
+ $num_updated = $query->execute();
+
$curtime = MySQL_NOW();
echo $curtime;
drupal_set_message('Cheque Has Been Debited into User Account.', 'status');
- $queryc ="UPDATE {textbook_companion_cheque} SET cheque_dispatch_date = NOW() WHERE proposal_id = ".$form_state['values']['proposal_id']."";
- db_query($queryc);
+ /*$queryc ="UPDATE {textbook_companion_cheque} SET cheque_dispatch_date = NOW() WHERE proposal_id = ".$form_state['values']['proposal_id']."";
+ db_query($queryc);*/
+
+ $query = db_update('textbook_companion_cheque');
+ $query->fields(array(
+ 'cheque_dispatch_date' => 'NOW',
+ ));
+ $query->condition('proposal_id', $form_state['values']['proposal_id']);
+ $num_updated = $query->execute();
}
/************************************************
@@ -895,15 +1050,30 @@ function contact_details($form_state)
drupal_set_message('<strong>Caution</strong>:Please update Contact Detail carefully as this will be used for future reference during <strong>Payment</strong></li></ul>', 'error');
$x = $user->uid;
- $query2 = db_query("SELECT * FROM {textbook_companion_proposal} WHERE uid=".$x);
- $data2 = db_fetch_object($query2);
+ /*$query2 = db_query("SELECT * FROM {textbook_companion_proposal} WHERE uid=".$x);
+ $data2 = db_fetch_object($query2);*/
+
+ $query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal');
+ $query->condition('uid', $x);
+ $result = $query->execute();
+ $data2=$result->fetchObject();
+
+
if(!$data2)
{
drupal_set_message('Fill Up The <a href="proposal">Book Proposal Form</a>', 'error');
return '';
}
- $query3 = db_query("SELECT * FROM {textbook_companion_preference} WHERE approval_status=1 AND proposal_id=".$data2->id);
- $data3 = db_fetch_object($query3);
+ /*$query3 = db_query("SELECT * FROM {textbook_companion_preference} WHERE approval_status=1 AND proposal_id=".$data2->id);
+ $data3 = db_fetch_object($query3);*/
+
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('approval_status', 1);
+ $query->condition('proposal_id', $data2->id);
+ $result = $query->execute();
+ $data3=$result->fetchObject();
if(!$data3->approval_status)
{
@@ -912,12 +1082,26 @@ function contact_details($form_state)
}
$proposal_id = $data2->id;
- $comment_qx = db_query("SELECT * FROM textbook_companion_cheque c WHERE proposal_id =".$proposal_id);
- $commentv = db_fetch_object($comment_qx);
+
+ /*$comment_qx = db_query("SELECT * FROM textbook_companion_cheque c WHERE proposal_id =".$proposal_id);
+ $commentv = db_fetch_object($comment_qx);*/
+
+ $query = db_select('textbook_companion_cheque', 'c');
+ $query->fields('c');
+ $query->condition('proposal_id', $proposal_id);
+ $result = $query->execute();
+ $commentv=$result->fetchObject();
+
$form16 = $commentv->commentf;
$mob_no = $data2->mobile;
$full_name = $data2->full_name;
- $query1 = db_query("SELECT * FROM {textbook_companion_cheque} WHERE proposal_id=".$proposal_id);
+
+ /*$query1 = db_query("SELECT * FROM {textbook_companion_cheque} WHERE proposal_id=".$proposal_id);*/
+ $query = db_select('textbook_companion_cheque');
+ $query->fields('textbook_companion_cheque');
+ $query->condition('proposal_id', $proposal_id);
+ $result = $query->execute();
+
$form1 = 0;
$form2 = 0;
$form3 = 0;
@@ -934,7 +1118,7 @@ function contact_details($form_state)
$form14 = 0;
$form15 = 0;
- if($data = db_fetch_object($query1))
+ if($data = $result->fetchObject())
{
$form1 = $data->address;
$form8 = $data->alt_mobno;
@@ -948,7 +1132,13 @@ function contact_details($form_state)
}
else
{
- db_query("insert into {textbook_companion_cheque} (proposal_id) values(%d)",$proposal_id);
+ /*db_query("insert into {textbook_companion_cheque} (proposal_id) values(%d)",$proposal_id);*/
+
+ $query = "insert into {textbook_companion_cheque} (proposal_id) values (:proposal_id)";
+ $args = array(
+ ":proposal_id"=>$proposal_id,
+ );
+ $result = db_query($query, $args, array('return' => Database::RETURN_INSERT_ID));
}
$form['candidate_detail'] = array(
'#type' => 'fieldset',
@@ -986,11 +1176,26 @@ function contact_details($form_state)
'#size' => 48,
'#default_value' => $form8,
);
- $chq_q=db_query("SELECT * FROM {textbook_companion_cheque} WHERE proposal_id=".$proposal_id);
- $chq_data=db_fetch_object($chq_q);
+
+ /*$chq_q=db_query("SELECT * FROM {textbook_companion_cheque} WHERE proposal_id=".$proposal_id);
+ $chq_data=db_fetch_object($chq_q);*/
+
+ $query = db_select('textbook_companion_cheque');
+ $query->fields('textbook_companion_cheque');
+ $query->condition('proposal_id', $proposal_id);
+ $result = $query->execute();
+ $chq_data=$result->fetchObject();
- $q_form = db_query("SELECT * FROM {textbook_companion_paper} WHERE proposal_id=".$proposal_id);
- $q_data = db_fetch_object($q_form);
+
+ /*$q_form = db_query("SELECT * FROM {textbook_companion_paper} WHERE proposal_id=".$proposal_id);
+ $q_data = db_fetch_object($q_form);*/
+
+ $query = db_select('textbook_companion_paper');
+ $query->fields('textbook_companion_paper');
+ $query->condition('proposal_id', $proposal_id);
+ $result = $query->execute();
+ $q_data=$result->fetchObject();
+
$form_html .= '<ul>';
if($q_data->internship_form)
{
@@ -1120,11 +1325,18 @@ function contact_details_submit($form, &$form_state)
global $user;
$x = $user->uid;
- $query2 = db_query("SELECT * FROM {textbook_companion_proposal} WHERE uid=".$x);
- $data2 = db_fetch_object($query2);
+ /*$query2 = db_query("SELECT * FROM {textbook_companion_proposal} WHERE uid=".$x);
+ $data2 = db_fetch_object($query2);*/
- $query ="UPDATE {textbook_companion_cheque} SET
+ $query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal');
+ $query->condition('uid', $x);
+ $result = $query->execute();
+ $data2=$result->fetchObject();
+
+
+ /*$query ="UPDATE {textbook_companion_cheque} SET
alt_mobno = '".$form_state['values']['mobileno2']."' ,
address = '".$form_state['values']['chq_address']."',
perm_city = '".$form_state['values']['perm_city']."',
@@ -1136,8 +1348,23 @@ function contact_details_submit($form, &$form_state)
temp_pincode = '".$form_state['values']['temp_pincode']."' ,
address_con = 'Submitted'
WHERE proposal_id = ".$data2->id;
+ db_query($query);*/
- db_query($query);
+ $query = db_update('textbook_companion_cheque');
+ $query->fields(array(
+ 'alt_mobno' => $form_state[ values ][ mobileno2 ],
+ 'address' => $form_state[ values ][ chq_address ],
+ 'perm_city' => $form_state[ values ][ perm_city ],
+ 'perm_state' => $form_state[ values ][ perm_state ],
+ 'perm_pincode' => $form_state[ values ][ perm_pincode ],
+ 'temp_chq_address' => $form_state[ values ][ temp_chq_address ],
+ 'temp_city' => $form_state[ values ][ temp_city ],
+ 'temp_state' => $form_state[ values ][ temp_state ],
+ 'temp_pincode' => $form_state[ values ][ temp_pincode ],
+ 'address_con' => 'Submitted',
+ ));
+ $query->condition('proposal_id', $data2->id);
+ $num_updated = $query->execute();
drupal_set_message('Contact Details Has Been Updated.....!', 'status');
drupal_goto('mycontact', array('msg' => 0 ), $fragment = NULL, $http_response_code = 302);
@@ -1174,9 +1401,16 @@ function copy_address()
function cheque_report_form()
{
- $search_qx = db_query("SELECT * FROM textbook_companion_proposal p,textbook_companion_cheque c WHERE c.address_con = 'Submitted' AND (p.id = c.proposal_id)");
+ /*$search_qx = db_query("SELECT * FROM textbook_companion_proposal p,textbook_companion_cheque c WHERE c.address_con = 'Submitted' AND (p.id = c.proposal_id)");*/
+
+ $query = db_select('textbook_companion_proposal', 'p');
+ $query->join('textbook_companion_cheque','c','p.id = c.proposal_id');
+ $query->fields('p',array('textbook_companion_proposal'));
+ $query->fields('c',array('textbook_companion_cheque'));
+ $query->condition('c.address_con', 'Submitted');
+ $search_qx = $query->execute();
- while ($search_datax = db_fetch_object($search_qx))
+ while ($search_datax = $search_qx->fetchObject())
{
$result = array($search_datax->full_name,$search_datax->address_con,$search_datax->cheque_no,$search_datax->cheque_dispatch_date);
}
diff --git a/cheque_manage.inc b/cheque_manage.inc
index 750874f..8ddeffb 100755
--- a/cheque_manage.inc
+++ b/cheque_manage.inc
@@ -22,16 +22,42 @@ function cheque_proposal_all()
$count=20;
/* get pending proposals to be approved */
$proposal_rows = array();
- $proposal_q = "SELECT * FROM {textbook_companion_proposal} ORDER BY id DESC";
- $pagerquery = pager_query($proposal_q, $count);
- while ($proposal_data = db_fetch_object($pagerquery))
+
+ /*$proposal_q = "SELECT * FROM {textbook_companion_proposal} ORDER BY id DESC";*/
+ $query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal');
+ $query->orderBy('id', 'DESC');
+
+
+ /*$pagerquery = pager_query($proposal_q, $count); */
+ $pagerquery = $query->extend('PagerDefault')->limit($count)->execute();
+
+ while ($proposal_data = $pagerquery->fetchObject())
{
/* get preference */
- $preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND approval_status = 1 LIMIT 1", $proposal_data->id);
- $preference_data = db_fetch_object($preference_q);
- $preference_q1 = db_query("SELECT * FROM {textbook_companion_proposal} WHERE uid = %d AND approval_status = 1 LIMIT 1", $proposal_data->id);
- $preference_data1 = db_fetch_object($preference_q1);
+ /*$preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND approval_status = 1 LIMIT 1", $proposal_data->id);
+ $preference_data = db_fetch_object($preference_q);*/
+
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('proposal_id', $proposal_data->id);
+ $query->condition('approval_status', 1);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $preference_data =$result->fetchObject();
+
+ /*$preference_q1 = db_query("SELECT * FROM {textbook_companion_proposal} WHERE uid = %d AND approval_status = 1 LIMIT 1", $proposal_data->id);
+ $preference_data1 = db_fetch_object($preference_q1);*/
+
+ $query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal');
+ $query->condition('uid', $proposal_data->id);
+ $query->condition('proposal_status', 1);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $preference_data1=$result->fetchObject();
+
$proposal_status = '';
switch ($proposal_data->proposal_status)
@@ -53,8 +79,8 @@ function cheque_proposal_all()
}
$proposal_header = array('Date of Submission', 'Contributor Name', 'Expected Date of Completion', 'Status');
- $output = theme_table($proposal_header, $proposal_rows, $proposal_rows1);
- return $output . theme('pager', $count);
+ $output = theme('table',array('header' =>$proposal_header,'rows'=>$proposal_rows));
+ return $output . theme_pager($count);
}
return $form;
diff --git a/code.inc b/code.inc
index 8dfa7a2..633a7b2 100755
--- a/code.inc
+++ b/code.inc
@@ -6,13 +6,23 @@ function upload_examples()
return drupal_get_form('upload_examples_form');
}
-function upload_examples_form($form_state)
+function upload_examples_form($form, $form_state)
{
global $user;
/************************ start approve book details ************************/
- $proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE uid = %d ORDER BY id DESC LIMIT 1", $user->uid);
- $proposal_data = db_fetch_object($proposal_q);
+
+ /*$proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE uid = %d ORDER BY id DESC LIMIT 1", $user->uid);
+ $proposal_data = db_fetch_object($proposal_q);*/
+
+ $query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal');
+ $query->condition('uid', $user->uid);
+ $query->orderBy('id', 'DESC');
+ $query->range(0, 1);
+ $result = $query->execute();
+ $proposal_data=$result->fetchObject();
+
if (!$proposal_data)
{
drupal_set_message("Please submit a " . l('proposal', 'proposal') . ".", 'error');
@@ -45,8 +55,17 @@ function upload_examples_form($form_state)
}
}
- $preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND approval_status = 1 LIMIT 1", $proposal_data->id);
- $preference_data = db_fetch_object($preference_q);
+ /*$preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND approval_status = 1 LIMIT 1", $proposal_data->id);
+ $preference_data = db_fetch_object($preference_q);*/
+
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('proposal_id', $proposal_data->id);
+ $query->condition('approval_status', 1);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $preference_data=$result->fetchObject();
+
if (!$preference_data)
{
drupal_set_message(t('Invalid Book Preference status. Please contact site administrator for further information.'), 'error');
@@ -56,8 +75,15 @@ function upload_examples_form($form_state)
/************************ end approve book details **************************/
/* add javascript for automatic book title, check if example uploaded, dependency selection effects */
- $chapter_name_js = " $(document).ready(function() {
+ $chapter_name_js = "(function ($) {
+
+$(document).ready(function(){
+
$('#edit-number').change(function() {
+ var ed = $('#edit-number').val();
+
+
+
$.get('" . base_path() . "textbook_companion/ajax/chapter_title/' + $('#edit-number').val() + '/' + " . $preference_data->id . ", function(data) {
$('#edit-name').val(data);
});
@@ -65,7 +91,7 @@ function upload_examples_form($form_state)
$('#edit-example-number').change(function() {
$.get('" . base_path() . "textbook_companion/ajax/example_exists/' + $('#edit-number').val() + '/' + " . $preference_data->id . " + '/' + $('#edit-example-number').val(), function(data) {
if (data) {
- alert(data);
+ alert(data);
}
});
});
@@ -90,19 +116,21 @@ function upload_examples_form($form_state)
$('#edit-existing-depfile-dep-book-title').trigger('change');
});
$('#edit-existing-depfile-dep-book-title').trigger('change');
- });";
+
+ });
+ })(jQuery);";
drupal_add_js($chapter_name_js, 'inline', 'header');
$form['#attributes'] = array('enctype' => "multipart/form-data");
$form['book_details']['book'] = array(
'#type' => 'item',
- '#value' => $preference_data->book,
+ '#markup' => $preference_data->book,
'#title' => t('Title of the Book'),
);
$form['contributor_name'] = array(
'#type' => 'item',
- '#value' => $proposal_data->full_name,
+ '#markup' => $proposal_data->full_name,
'#title' => t('Contributor Name'),
);
$options = array('' => '(Select)');
@@ -189,27 +217,37 @@ function upload_examples_form($form_state)
$form['existing_depfile']['selected'] = array(
'#type' => 'item',
'#title' => t('Existing Dependency Files Selected'),
- '#value' => '<div id="existing_depfile_selected"></div>',
+ '#markup' => '<div id="existing_depfile_selected"></div>',
);
- $form['existing_depfile']['dep_book_title'] = array(
+ /* $form['existing_depfile']['dep_book_title'] = array(
'#type' => 'select',
'#title' => t('Title of the Book'),
'#options' => _list_of_book_titles(),
+ );*/
+
+
+
+ $form['existing_depfile']['dep_book'] = array(
+ '#type' => 'item',
+ '#title' => t('Dependency Files'),
+
);
list($files_options, $files_options_class) = _list_of_book_dependency_files();
$form['existing_depfile']['dep_chapter_example_files'] = array(
'#type' => 'checkboxes',
- '#title' => t('Dependency Files'),
+ //'#title' => t('Dependency Files'),
'#options' => $files_options,
'#options_class' => $files_options_class,
+ '#prefix' => '<div id="ckb" style="height:500px;overflow:auto;">',
+ '#suffix' =>'</div>',
'#multiple' => TRUE,
);
$form['existing_depfile']['dep_upload'] = array(
- '#type' => 'item',
- '#value' => l('Upload New Depedency Files', 'textbook_companion/code/upload_dep'),
+ '#type' => 'item',
+ '#markup' => '<hr style="color:red">'. l('Upload New Depedency Files', 'textbook_companion/code/upload_dep'),
);
/************ END OF EXISTING DEPENDENCIES **************/
@@ -328,7 +366,7 @@ function upload_examples_form_validate($form, &$form_state)
}
/* add javascript again for automatic book title, check if example uploaded, dependency selection effects */
- $chapter_name_js = " $(document).ready(function() {
+ $chapter_name_js = "(function ($) {
$('#edit-number').change(function() {
$.get('" . base_path() . "textbook_companion/ajax/chapter_title/' + $('#edit-number').val() + '/' + " . $row->pre_id . ", function(data) {
$('#edit-name').val(data);
@@ -362,7 +400,7 @@ function upload_examples_form_validate($form, &$form_state)
$('#edit-existing-depfile-dep-book-title').trigger('change');
});
$('#edit-existing-depfile-dep-book-title').trigger('change');
- });";
+ })(jQuery);";
drupal_add_js($chapter_name_js, 'inline', 'header');
}
@@ -372,8 +410,18 @@ function upload_examples_form_submit($form, &$form_state) {
$root_path = textbook_companion_path();
/************************ start approve book details ************************/
- $proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE uid = %d ORDER BY id DESC LIMIT 1", $user->uid);
- $proposal_data = db_fetch_object($proposal_q);
+
+ /*$proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE uid = %d ORDER BY id DESC LIMIT 1", $user->uid);
+ $proposal_data = db_fetch_object($proposal_q);*/
+ $query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal');
+ $query->condition('uid', $user->uid);
+ $query->orderBy('id', 'DESC');
+ $query->range(0, 1);
+ $result = $query->execute();
+ $proposal_data=$result->fetchObject();
+
+
if (!$proposal_data)
{
drupal_set_message("Please submit a " . l('proposal', 'proposal') . ".", 'error');
@@ -406,8 +454,18 @@ function upload_examples_form_submit($form, &$form_state) {
}
}
- $preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND approval_status = 1 LIMIT 1", $proposal_data->id);
- $preference_data = db_fetch_object($preference_q);
+ /*$preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND approval_status = 1 LIMIT 1", $proposal_data->id);
+ $preference_data = db_fetch_object($preference_q);*/
+
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('proposal_id', $proposal_data->id);
+ $query->condition('approval_status', 1);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $preference_data=$result->fetchObject();
+
+
if (!$preference_data)
{
drupal_set_message(t('Invalid Book Preference status. Please contact site administrator for further information.'), 'error');
@@ -424,23 +482,57 @@ function upload_examples_form_submit($form, &$form_state) {
/* inserting chapter details */
$chapter_id = 0;
- $chapter_result = db_query("SELECT * FROM {textbook_companion_chapter} WHERE preference_id = %d AND number = %d", $preference_id, $form_state['values']['number']);
- if (!$chapter_row = db_fetch_object($chapter_result))
+
+ /*$chapter_result = db_query("SELECT * FROM {textbook_companion_chapter} WHERE preference_id = %d AND number = %d", $preference_id, $form_state['values']['number']);*/
+
+ $query = db_select('textbook_companion_chapter');
+ $query->fields('textbook_companion_chapter');
+ $query->condition('preference_id', $preference_id);
+ $query->condition('number', $form_state['values']['number']);
+ $chapter_result = $query->execute();
+
+ if (!$chapter_row =$chapter_result->fetchObject())
{
- db_query("INSERT INTO {textbook_companion_chapter} (preference_id, number, name) VALUES (%d, '%s', '%s')",
+
+ /*db_query("INSERT INTO {textbook_companion_chapter} (preference_id, number, name) VALUES (%d, '%s', '%s')",
$preference_id,
$form_state['values']['number'],
$form_state['values']['name']
);
- $chapter_id = db_last_insert_id('textbook_companion_chapter', 'id');
+ $chapter_id = db_last_insert_id('textbook_companion_chapter', 'id'); */
+
+ $query = "INSERT INTO {textbook_companion_chapter} (preference_id, number, name) VALUES(:preference_id, :number, :name)";
+ $args = array(
+ ":preference_id"=> $preference_id,
+ ":number"=> $form_state['values']['number'],
+ ":name"=>$form_state['values']['name'],
+ );
+ $result = db_query($query, $args, array('return' => Database::RETURN_INSERT_ID));
+ $chapter_id=$result;
+
} else {
$chapter_id = $chapter_row->id;
- db_query("UPDATE {textbook_companion_chapter} SET name = '%s' WHERE id = %d", $form_state['values']['name'], $chapter_id);
+
+ /*db_query("UPDATE {textbook_companion_chapter} SET name = '%s' WHERE id = %d", $form_state['values']['name'], $chapter_id);*/
+ $query = db_update('textbook_companion_chapter');
+ $query->fields(array(
+ 'name' =>$form_state['values']['name'],
+ ));
+ $query->condition('id',$chapter_id);
+ $num_updated = $query->execute();
}
/* get example details - dont allow if already example present */
- $cur_example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d AND number = '%s'", $chapter_id, $form_state['values']['example_number']);
- if ($cur_example_d = db_fetch_object($cur_example_q))
+
+ /*$cur_example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d AND number = '%s'", $chapter_id, $form_state['values']['example_number']);*/
+
+ $query = db_select('textbook_companion_example');
+ $query->fields('textbook_companion_example');
+ $query->condition('chapter_id', $chapter_id);
+ $query->condition('number', $form_state['values']['example_number']);
+ $cur_example_q = $query->execute();
+
+ if ($cur_example_d = $cur_example_q->fetchObject())
{
if ($cur_example_d->approval_status == 1)
{
@@ -468,14 +560,29 @@ function upload_examples_form_submit($form, &$form_state) {
mkdir($root_path . $dest_path);
/* creating example database entry */
- db_query("INSERT INTO {textbook_companion_example} (chapter_id, number, caption, approval_status, timestamp) VALUES (%d, '%s', '%s', %d, %d)",
+
+ /*db_query("INSERT INTO {textbook_companion_example} (chapter_id, number, caption, approval_status, timestamp) VALUES (%d, '%s', '%s', %d, %d)",
$chapter_id,
$form_state['values']['example_number'],
$form_state['values']['example_caption'],
0,
time()
);
- $example_id = db_last_insert_id('textbook_companion_example', 'id');
+ $example_id = db_last_insert_id('textbook_companion_example', 'id');*/
+
+ $query = "INSERT INTO {textbook_companion_example} (approver_uid, chapter_id, number, caption, approval_date, approval_status, timestamp) VALUES (:approver_uid, :chapter_id, :number, :caption, :approval_date,:approval_status, :timestamp)";
+ $args = array(
+ ":approver_uid"=> 0,
+ ":chapter_id"=> $chapter_id,
+ ":number"=> $form_state['values']['example_number'],
+ ":caption"=> $form_state['values']['example_caption'],
+ ":approval_date"=>time(),
+ ":approval_status"=> 0,
+ ":timestamp"=>time(),
+ );
+ $result = db_query($query, $args, array('return' => Database::RETURN_INSERT_ID));
+ $example_id =$result;
+
/* linking existing dependencies */
foreach ($form_state['values']['existing_depfile']['dep_chapter_example_files'] as $row)
@@ -483,13 +590,24 @@ function upload_examples_form_submit($form, &$form_state) {
if ($row > 0)
{
/* insterting into database */
- db_query("INSERT INTO {textbook_companion_example_dependency} (example_id, dependency_id, approval_status, timestamp)
+
+ /*db_query("INSERT INTO {textbook_companion_example_dependency} (example_id, dependency_id, approval_status, timestamp)
VALUES (%d, %d, %d, %d)",
$example_id,
$row,
0,
time()
- );
+ );*/
+
+ $query = "INSERT INTO {textbook_companion_example_dependency} (example_id, dependency_id, approval_status, timestamp)
+ VALUES (:example_id, :dependency_id, :approval_status, :timestamp)";
+ $args = array(
+ ":example_id"=>$example_id,
+ ":dependency_id"=>$row,
+ ":approval_status"=> 0,
+ ":timestamp"=>time(),
+ );
+ $result = db_query($query, $args, array('return' => Database::RETURN_INSERT_ID));
}
}
@@ -518,7 +636,8 @@ function upload_examples_form_submit($form, &$form_state) {
if (move_uploaded_file($_FILES['files']['tmp_name'][$file_form_name], $root_path . $dest_path . $_FILES['files']['name'][$file_form_name]))
{
/* for uploaded files making an entry in the database */
- db_query("INSERT INTO {textbook_companion_example_files} (example_id, filename, filepath, filemime, filesize, filetype, timestamp)
+
+ /*db_query("INSERT INTO {textbook_companion_example_files} (example_id, filename, filepath, filemime, filesize, filetype, timestamp)
VALUES (%d, '%s', '%s', '%s', %d, '%s', %d)",
$example_id,
$_FILES['files']['name'][$file_form_name],
@@ -527,7 +646,21 @@ function upload_examples_form_submit($form, &$form_state) {
$_FILES['files']['size'][$file_form_name],
$file_type,
time()
- );
+ );*/
+
+ $query = "INSERT INTO {textbook_companion_example_files} (example_id, caption, filename, filepath,filemime, filesize, filetype, timestamp)
+ VALUES (:example_id, :caption, :filename, :filepath,:filemime, :filesize, :filetype, :timestamp)";
+ $args = array(
+ ":example_id"=>$example_id,
+ ":caption" => 'None',
+ ":filename"=>$_FILES['files']['name'][$file_form_name],
+ ":filepath"=>$dest_path . $_FILES['files']['name'][$file_form_name],
+ ":filemime"=>$_FILES['files']['type'][$file_form_name],
+ ":filesize"=>$_FILES['files']['size'][$file_form_name],
+ ":filetype"=> $file_type,
+ ":timestamp"=>time(),
+ );
+ $result = db_query($query, $args, array('return' => Database::RETURN_INSERT_ID));
drupal_set_message($file_name . ' uploaded successfully.', 'status');
} else {
drupal_set_message('Error uploading file : ' . $dest_path . '/' . $file_name, 'error');
@@ -557,8 +690,16 @@ function _upload_examples_delete()
$example_id = arg(3);
/* check example */
- $example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE id = %d LIMIT 1", $example_id);
- $example_data = db_fetch_object($example_q);
+
+ /*$example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE id = %d LIMIT 1", $example_id);
+ $example_data = db_fetch_object($example_q);*/
+ $query = db_select('textbook_companion_example');
+ $query->fields('textbook_companion_example');
+ $query->condition('id', $example_id);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $example_data=$result->fetchObject();
+
if (!$example_data)
{
drupal_set_message('Invalid example.', 'error');
@@ -572,8 +713,16 @@ function _upload_examples_delete()
return;
}
- $chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE id = %d LIMIT 1", $example_data->chapter_id);
- $chapter_data = db_fetch_object($chapter_q);
+ /*$chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE id = %d LIMIT 1", $example_data->chapter_id);
+ $chapter_data = db_fetch_object($chapter_q);*/
+ $query = db_select('textbook_companion_chapter');
+ $query->fields('textbook_companion_chapter');
+ $query->condition('id', $example_data->chapter_id);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $chapter_data=$result->fetchObject();
+
+
if (!$chapter_data)
{
drupal_set_message('You do not have permission to delete this example.', 'error');
@@ -581,8 +730,15 @@ function _upload_examples_delete()
return;
}
- $preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d LIMIT 1", $chapter_data->preference_id);
- $preference_data = db_fetch_object($preference_q);
+ /*$preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d LIMIT 1", $chapter_data->preference_id);
+ $preference_data = db_fetch_object($preference_q);*/
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('id', $chapter_data->preference_id);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $preference_data=$result->fetchObject();
+
if (!$preference_data)
{
drupal_set_message('You do not have permission to delete this example.', 'error');
@@ -590,8 +746,17 @@ function _upload_examples_delete()
return;
}
- $proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d AND uid = %d LIMIT 1", $preference_data->proposal_id, $user->uid);
- $proposal_data = db_fetch_object($proposal_q);
+ /*$proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d AND uid = %d LIMIT 1", $preference_data->proposal_id, $user->uid);
+ $proposal_data = db_fetch_object($proposal_q);*/
+
+ $query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal');
+ $query->condition('id', $preference_data->proposal_id);
+ $query->condition('uid', $user->uid);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $proposal_data=$result->fetchObject();
+
if (!$proposal_data)
{
drupal_set_message('You do not have permission to delete this example.', 'error');
@@ -630,8 +795,20 @@ function _upload_examples_delete()
function _list_of_book_titles()
{
$book_titles = array('0' => 'Please select...');
- $book_titles_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE approval_status = 1 OR approval_status = 3 ORDER BY book ASC");
- while ($book_titles_data = db_fetch_object($book_titles_q))
+
+ /*$book_titles_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE approval_status = 1 OR approval_status = 3 ORDER BY book ASC");*/
+
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+
+ $or = db_or();
+ $or->condition('approval_status', 1);
+ $or->condition('approval_status', 3);
+ $query->condition($or);
+ $query->orderBy('book', 'ASC');
+ $book_titles_q = $query->execute();
+
+ while ($book_titles_data =$book_titles_q->fetchObject())
{
$book_titles[$book_titles_data->id] = $book_titles_data->book . ' (Written by ' . $book_titles_data->author . ')';
}
@@ -642,14 +819,33 @@ function _list_of_book_dependency_files()
{
$book_dependency_files = array();
$book_dependency_files_class = array();
- $book_dependency_files_q = db_query("SELECT * FROM {textbook_companion_dependency_files} ORDER BY filename ASC");
- while ($book_dependency_files_data = db_fetch_object($book_dependency_files_q))
+ /*$book_dependency_files_q = db_query("SELECT * FROM {textbook_companion_dependency_files} ORDER BY filename ASC");*/
+
+ /*$query = db_select('textbook_companion_dependency_files');
+ $query->fields('textbook_companion_dependency_files');
+ $query->orderBy('filename', 'ASC');*/
+
+/* $query = db_select('textbook_companion_dependency_files', 'tcdp');
+ $query->fields('tcdp');
+ $query->fields('tcp', array('book', 'author','publisher', 'edition', 'year'));
+ $query->leftJoin('textbook_companion_preference', 'tcp', 'tcdp.preference_id = tcp.id');
+ $result = $query->execute();*/
+
+ $book_dependency_files_q = db_query("
+ select * from {textbook_companion_dependency_files} tcdf
+ LEFT JOIN textbook_companion_preference pe on tcdf.preference_id=pe.id
+ LEFT JOIN textbook_companion_proposal po ON pe.proposal_id = po.id
+ WHERE po.proposal_status = 3 AND pe.approval_status = 1
+ ");
+
+
+ while ($book_dependency_files_data = $book_dependency_files_q->fetchObject())
{
$temp_caption = '';
if ($book_dependency_files_data->caption)
- $temp_caption .= ' (' . $book_dependency_files_data->caption . ')';
- $book_dependency_files[$book_dependency_files_data->id] = l($book_dependency_files_data->filename . $temp_caption, 'download/dependency/' . $book_dependency_files_data->id, array('attributes' => array('class' => $book_dependency_files_data->preference_id)));
+ $temp_caption .= ' ===>[Caption: ' . $book_dependency_files_data->caption . ' ' .', Book: '. $book_dependency_files_data->book .', Author: '. $book_dependency_files_data->author . ', Publisher: '. $book_dependency_files_data->publisher . ', Edition: '. $book_dependency_files_data->edition .', Year: '. $book_dependency_files_data->year.']';
+ $book_dependency_files[$book_dependency_files_data->id] = l($book_dependency_files_data->filename , 'download/dependency/' . $book_dependency_files_data->id, array('attributes' => array('class' => 'title'))). $temp_caption;
$book_dependency_files_class[$book_dependency_files_data->id] = $book_dependency_files_data->preference_id;
}
return array($book_dependency_files, $book_dependency_files_class);
diff --git a/code_approval.inc b/code_approval.inc
index 571eb7b..f3bb2b1 100755
--- a/code_approval.inc
+++ b/code_approval.inc
@@ -4,21 +4,49 @@
function code_approval()
{
/* get a list of unapproved chapters */
- $pending_chapter_q = db_query("SELECT c.id as c_id, c.number as c_number, c.name as c_name, c.preference_id as c_preference_id FROM {textbook_companion_example} as e JOIN {textbook_companion_chapter} as c ON c.id = e.chapter_id WHERE e.approval_status = 0");
+
+ /*$pending_chapter_q = db_query("SELECT c.id as c_id, c.number as c_number, c.name as c_name, c.preference_id as c_preference_id FROM {textbook_companion_example} as e JOIN {textbook_companion_chapter} as c ON c.id = e.chapter_id WHERE e.approval_status = 0");*/
+
+ $query = db_select('textbook_companion_example', 'e');
+ $query->fields('c', array('id', 'number', 'name', 'preference_id'));
+ $query->addField('c','id','c_id');
+ $query->addField('c','number','c_number');
+ $query->addField('c','name','c_name');
+ $query->addField('c','preference_id','c_preference_id');
+ $query->innerJoin('textbook_companion_chapter', 'c', 'c.id = e.chapter_id');
+ $query->condition('e.approval_status', 0);
+ $pending_chapter_q = $query->execute();
+
if (!$pending_chapter_q)
{
drupal_set_message(t('There are no pending code approvals.'), 'status');
return '';
}
$rows = array();
- while ($row = db_fetch_object($pending_chapter_q))
+ while ($row = $pending_chapter_q->fetchObject())
{
/* get preference data */
- $preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d", $row->c_preference_id);
- $preference_data = db_fetch_object($preference_q);
+
+ /*$preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d", $row->c_preference_id);
+ $preference_data = db_fetch_object($preference_q);*/
+
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('id', $row->c_preference_id);
+ $result = $query->execute();
+ $preference_data=$result->fetchObject();
+
/* get proposal data */
- $proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d", $preference_data->proposal_id);
- $proposal_data = db_fetch_object($proposal_q);
+
+ /*$proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d", $preference_data->proposal_id);
+ $proposal_data = db_fetch_object($proposal_q);*/
+
+ $query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal');
+ $query->condition('id', $preference_data->proposal_id);
+ $result = $query->execute();
+ $proposal_data = $result->fetchObject();
+
/* setting table row information */
$rows[] = array($preference_data->book, $row->c_number, $row->c_name, $proposal_data->full_name, l('Edit', 'code_approval/approve/' . $row->c_id));
}
@@ -31,7 +59,7 @@ function code_approval()
}
$header = array('Title of the Book', 'Chapter Number', 'Title of the Chapter', 'Contributor Name', 'Actions');
- $output = theme_table($header, $rows);
+ $output = theme('table',array('header'=>$header,'rows'=>$rows));
return $output;
}
@@ -39,15 +67,38 @@ function code_approval_form($form_state)
{
/* get a list of unapproved chapters */
$chapter_id = arg(2);
- $pending_chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE id = %d", $chapter_id);
- if ($pending_chapter_data = db_fetch_object($pending_chapter_q))
+
+ /*$pending_chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE id = %d", $chapter_id);*/
+
+ $query = db_select('textbook_companion_chapter');
+ $query->fields('textbook_companion_chapter');
+ $query->condition('id', $chapter_id);
+ $pending_chapter_q = $query->execute();
+
+ if ($pending_chapter_data = $pending_chapter_q->fetchObject())
{
/* get preference data */
- $preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d", $pending_chapter_data->preference_id);
- $preference_data = db_fetch_object($preference_q);
+
+ /*$preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d", $pending_chapter_data->preference_id);
+ $preference_data = db_fetch_object($preference_q);*/
+
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('id',$pending_chapter_data->preference_id);
+ $result = $query->execute();
+ $preference_data=$result->fetchObject();
+
/* get proposal data */
- $proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d", $preference_data->proposal_id);
- $proposal_data = db_fetch_object($proposal_q);
+
+ /*$proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d", $preference_data->proposal_id);
+ $proposal_data = db_fetch_object($proposal_q);*/
+
+ $query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal');
+ $query->condition('id', $preference_data->proposal_id);
+ $result = $query->execute();
+ $proposal_data=$result->fetchObject();
+
} else {
drupal_set_message(t('Invalid chapter selected.'), 'error');
drupal_goto('code_approval');
@@ -58,36 +109,44 @@ function code_approval_form($form_state)
$form['contributor'] = array(
'#type' => 'item',
- '#value' => $proposal_data->full_name,
+ '#markup' => $proposal_data->full_name,
'#title' => t('Contributor Name'),
);
$form['book_details']['book'] = array(
'#type' => 'item',
- '#value' => $preference_data->book,
+ '#markup' => $preference_data->book,
'#title' => t('Title of the Book'),
);
$form['book_details']['number'] = array(
'#type' => 'item',
- '#value' => $pending_chapter_data->number,
+ '#markup' => $pending_chapter_data->number,
'#title' => t('Chapter Number'),
);
$form['book_details']['name'] = array(
'#type' => 'item',
- '#value' => $pending_chapter_data->name,
+ '#markup' => $pending_chapter_data->name,
'#title' => t('Title of the Chapter'),
);
$form['book_details']['back_to_list'] = array(
'#type' => 'item',
- '#value' => l('Back to Code Approval List', 'code_approval'),
+ '#markup' => l('Back to Code Approval List', 'code_approval'),
);
/* get example data */
- $example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d AND approval_status = 0", $chapter_id);
- while ($example_data = db_fetch_object($example_q))
+
+ /*$example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d AND approval_status = 0", $chapter_id);*/
+
+ $query = db_select('textbook_companion_example');
+ $query->fields('textbook_companion_example');
+ $query->condition('chapter_id', $chapter_id);
+ $query->condition('approval_status', 0);
+ $example_q = $query->execute();
+
+ while ($example_data = $example_q->fetchObject())
{
$form['example_details'][$example_data->id] = array(
'#type' => 'fieldset',
@@ -96,19 +155,19 @@ function code_approval_form($form_state)
);
$form['example_details'][$example_data->id]['example_number'] = array(
'#type' => 'item',
- '#value' => $example_data->number,
+ '#markup' => $example_data->number,
'#title' => t('Example Number'),
);
$form['example_details'][$example_data->id]['example_caption'] = array(
'#type' => 'item',
- '#value' => $example_data->caption,
+ '#markup' => $example_data->caption,
'#title' => t('Example Caption'),
);
$form['example_details'][$example_data->id]['download'] = array(
'#type' => 'markup',
- '#value' => l('Download Example', 'download/example/' . $example_data->id),
+ '#markup' => l('Download Example', 'download/example/' . $example_data->id),
);
$form['example_details'][$example_data->id]['approved'] = array(
@@ -140,18 +199,59 @@ function code_approval_form_submit($form, &$form_state)
foreach ($form_state['values']['example_details'] as $ex_id => $ex_data)
{
- $example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE id = %d LIMIT 1", $ex_data['example_id']);
- $example_data = db_fetch_object($example_q);
- $chapter_data = db_fetch_object(db_query("SELECT * FROM {textbook_companion_chapter} WHERE id = %d LIMIT 1", $example_data->chapter_id));
- $preference_data = db_fetch_object(db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d LIMIT 1", $chapter_data->preference_id));
- $proposal_data = db_fetch_object(db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d LIMIT 1", $preference_data->proposal_id));
+ /*$example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE id = %d LIMIT 1", $ex_data['example_id']);
+ $example_data = db_fetch_object($example_q);*/
+ $query = db_select('textbook_companion_example');
+ $query->fields('textbook_companion_example');
+ $query->condition('id', $ex_data['example_id']);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $example_data=$result->fetchObject();
+
+ /*$chapter_data = db_fetch_object(db_query("SELECT * FROM {textbook_companion_chapter} WHERE id = %d LIMIT 1", $example_data->chapter_id));*/
+ $query = db_select('textbook_companion_chapter');
+ $query->fields('textbook_companion_chapter');
+ $query->condition('id', $example_data->chapter_id);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $chapter_data=$result->fetchObject();
+
+
+ /*$preference_data = db_fetch_object(db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d LIMIT 1", $chapter_data->preference_id));*/
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('id',$chapter_data->preference_id);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $preference_data=$result->fetchObject();
+
+
+ /*$proposal_data = db_fetch_object(db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d LIMIT 1", $preference_data->proposal_id));*/
+ $query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal');
+ $query->condition('id', $preference_data->proposal_id);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $proposal_data=$result->fetchObject();
+
$user_data = user_load($proposal_data->uid);
del_book_pdf($preference_data->id);
if ($ex_data['approved'] == "0")
{
- db_query("UPDATE {textbook_companion_example} SET approval_status = 1, approver_uid = %d, approval_date = %d WHERE id = %d", $user->uid, time(), $ex_data['example_id']);
+
+ /*db_query("UPDATE {textbook_companion_example} SET approval_status = 1, approver_uid = %d, approval_date = %d WHERE id = %d", $user->uid, time(), $ex_data['example_id']);*/
+
+ $query = db_update('textbook_companion_example');
+ $query->fields(array(
+ 'approval_status' => 1,
+ 'approver_uid' => $user->uid,
+ 'approval_date' => time(),
+ ));
+ $query->condition('id', $ex_data['example_id']);
+ $num_updated = $query->execute();
+
/* sending email */
$email_to = $user_data->mail;
@@ -185,312 +285,236 @@ function code_approval_form_submit($form, &$form_state)
/********************************* BULK APPROVAL ******************************/
/******************************************************************************/
-function bulk_approval_form($form_state)
+function bulk_approval_form($form,$form_state)
{
- $form['#redirect'] = FALSE;
-
- ahah_helper_register($form, $form_state);
-
- /* default value for ahah fields */
- if (!isset($form_state['storage']['run']['book']))
- {
- $book_default_value = 0;
- } else {
- $book_default_value = $form_state['storage']['run']['book'];
- }
-
- if (!isset($form_state['storage']['run']['chapter']))
- {
- $chapter_default_value = 0;
- } else {
- if ($form_state['values']['run']['book_hidden'] != $form_state['values']['run']['book'])
- $chapter_default_value = 0;
- else
- $chapter_default_value = $form_state['storage']['run']['chapter'];
- }
-
- if (!isset($form_state['storage']['run']['example']))
- {
- $example_default_value = 0;
- } else {
- if ($form_state['values']['run']['book_hidden'] != $form_state['values']['run']['book'])
- $example_default_value = 0;
- else if ($form_state['values']['run']['chapter_hidden'] != $form_state['values']['run']['chapter'])
- $example_default_value = 0;
- else
- $example_default_value = $form_state['storage']['run']['example'];
- }
-
- $form['run'] = array(
- '#type' => 'fieldset',
- '#title' => t('Bulk Manage Code'),
- '#collapsible' => FALSE,
- '#collapsed' => FALSE,
- '#prefix' => '<div id="run-wrapper">',
- '#suffix' => '</div>',
- '#tree' => TRUE,
- );
-
- $form['run']['book'] = array(
- '#type' => 'select',
- '#title' => t('Title of the Book'),
- '#options' => _list_of_books(),
- '#default_value' => $book_default_value,
- '#tree' => TRUE,
- '#ahah' => array(
- 'event' => 'change',
- 'effect' => 'none',
- 'path' => ahah_helper_path(array('run')),
- 'wrapper' => 'run-wrapper',
- 'progress' => array(
- 'type' => 'throbber',
- 'message' => t(''),
- ),
- ),
- );
-
- /* hidden form elements */
- $form['run']['book_hidden'] = array(
- '#type' => 'hidden',
- '#value' => $form_state['values']['run']['book'],
- );
-
- /* hidden form elements */
- $form['run']['chapter_hidden'] = array(
- '#type' => 'hidden',
- '#value' => $form_state['values']['run']['chapter'],
- );
-
- if ($book_default_value > 0)
- {
- $form['run']['download_book'] = array(
+ $options_first = _bulk_list_of_books();
+ $options_two = _ajax_bulk_get_chapter_list();
+ $selected = isset($form_state['values']['book']) ? $form_state['values']['book'] : key($options_first);
+ $select_two = isset($form_state['values']['chapter']) ? $form_state['values']['chapter'] : key($options_two);
+
+ $form['book'] = array(
+ '#type' => 'select',
+ '#title' => t('Title of the Book'),
+ '#options' => _bulk_list_of_books(),
+ '#default_value' => $selected,
+ //'#tree' => TRUE,
+ '#ajax' => array(
+ 'callback' => 'ajax_bulk_chapter_list_callback',
+ ),
+ '#validated' => TRUE,
+ );
+
+ $form['download_book'] = array(
'#type' => 'item',
- '#value' => l('Download', 'full_download/book/' . $book_default_value) . ' ' . t('(Download all the approved and unapproved examples of the entire book)'),
+ '#markup' => '<div id="ajax_selected_book"></div>',
);
- $form['run']['download_pdf'] = array(
+ $form['download_pdf'] = array(
'#type' => 'item',
- '#value' => l('Download PDF', 'textbook_companion/generate_book/' . $book_default_value . '/1') . ' ' . t('(Download PDF of all the approved and unapproved examples of the entire book)'),
+ '#markup' => '<div id="ajax_selected_book_pdf"></div>',
);
- $form['run']['regenrate_book'] = array(
+ $form['regenrate_book'] = array(
'#type' => 'item',
- '#value' => l('Regenerate PDF', 'textbook_companion/delete_book/' . $book_default_value) . ' ' . t('(Manually Regenerate PDF of the entire book)'),
+ '#markup' => '<div id="ajax_selected_book_regenerate_pdf"></div>',
);
- $form['run']['notes_book'] = array(
+ $form['notes_book'] = array(
'#type' => 'item',
- '#value' => l('Notes for Reviewers', 'code_approval/notes/' . $book_default_value),
- );
-
- $form['run']['approve_book'] = array(
- '#type' => 'checkbox',
- '#title' => t('Approve Entire Book'),
+ '#markup' => '<div id="ajax_selected_book_notes"></div>',
);
- $form['run']['unapprove_book'] = array(
- '#type' => 'checkbox',
- '#title' => t('Pending Review Entire Book'),
- );
- $form['run']['disapprove_book'] = array(
- '#type' => 'checkbox',
- '#title' => t('Dis-Approve Entire Book (This will delete all the examples in the book)'),
- '#prefix' => '<div style="color:red;"><strong>',
- '#suffix' => '</strong></div>',
- );
- $form['run']['delete_book_including_proposal'] = array(
- '#type' => 'checkbox',
- '#title' => t('Delete Entire Book Including Proposal'),
- '#prefix' => '<div style="color:red;"><strong>',
- '#suffix' => '</strong></div>',
- );
-
- $form['run']['chapter'] = array(
+
+ $form['book_actions'] = array(
+ '#type' => 'select',
+ '#title' => t('Please select action for selected book'),
+ '#options' => _bulk_list_book_actions(),
+ //'#default_value' => isset($form_state['values']['lab_actions']) ? $form_state['values']['lab_actions'] : 0,
+ '#prefix' => '<div id="ajax_selected_book_action" style="color:red;">',
+ '#suffix' => '</div>',
+ '#states' => array('invisible' => array(':input[name="book"]' => array('value' => 0),),),
+ '#validated' => TRUE,
+ );
+
+ $form['chapter'] = array(
'#type' => 'select',
'#title' => t('Title of the Chapter'),
- '#options' => _list_of_chapters($book_default_value),
- '#default_value' => $chapter_default_value,
- '#tree' => TRUE,
- '#ahah' => array(
- 'event' => 'change',
- 'effect' => 'none',
- 'path' => ahah_helper_path(array('run')),
- 'wrapper' => 'run-wrapper',
- 'progress' => array(
- 'type' => 'throbber',
- 'message' => t(''),
- ),
- ),
+ '#options' => _ajax_bulk_get_chapter_list($selected),
+ //'#default_value' => $chapter_default_value,
+ '#prefix' => '<div id="ajax_select_chapter_list">',
+ '#suffix' => '</div>',
+ '#validated' => TRUE,
+ // '#tree' => TRUE,
+ '#ajax' => array(
+ 'callback' => 'ajax_bulk_example_list_callback',
+ ),
+ '#states' => array('invisible' => array(':input[name="book"]' => array('value' => 0),),),
);
- if ($chapter_default_value > 0)
- {
- $form['run']['download_chapter'] = array(
+
+ $form['download_chapter'] = array(
'#type' => 'item',
- '#value' => l('Download', 'full_download/chapter/' . $chapter_default_value) . ' ' . t('(Download all the approved and unapproved examples of the entire chapter)'),
+ '#markup' => '<div id="ajax_download_chapter"></div>',
);
-
- $form['run']['approve_chapter'] = array(
- '#type' => 'checkbox',
- '#title' => t('Approve Entire Chapter'),
- );
- $form['run']['unapprove_chapter'] = array(
- '#type' => 'checkbox',
- '#title' => t('Pending Review Entire Chapter'),
- );
- $form['run']['disapprove_chapter'] = array(
- '#type' => 'checkbox',
- '#title' => t('Dis-Approve Entire Chapter (This will delete all the examples in the chapter)'),
- '#prefix' => '<div style="color:red;"><strong>',
- '#suffix' => '</strong></div>',
- );
-
- $form['run']['example'] = array(
+
+ $form['chapter_actions'] = array(
+ '#type' => 'select',
+ '#title' => t('Please select action for selected chapter'),
+ '#options' => _bulk_list_chapter_actions(),
+ //'#default_value' => isset($form_state['values']['lab_actions']) ? $form_state['values']['lab_actions'] : 0,
+ '#prefix' => '<div id="ajax_selected_chapter_action" style="color:red;">',
+ '#suffix' => '</div>',
+ '#states' => array('invisible' => array(':input[name="book"]' => array('value' => 0),),),
+ '#ajax' => array(
+ 'callback' => 'ajax_bulk_chapter_actions_callback',
+ ),
+ );
+
+ $form['example'] = array(
'#type' => 'select',
'#title' => t('Example No. (Caption)'),
- '#options' => _list_of_examples($chapter_default_value),
- '#default_value' => $example_default_value,
- '#tree' => TRUE,
- '#ahah' => array(
- 'event' => 'change',
- 'effect' => 'none',
- 'path' => ahah_helper_path(array('run')),
- 'wrapper' => 'run-wrapper',
- 'progress' => array(
- 'type' => 'throbber',
- 'message' => t(''),
- ),
+ '#options' => _ajax_bulk_get_examples($chapter_default_value),
+ // '#default_value' => $example_default_value,
+ '#validated' => TRUE,
+ '#prefix' => '<div id="ajax_selected_example">',
+ '#suffix' => '</div>',
+ '#states' => array('invisible' => array(':input[name="book"]' => array('value' => 0),),),
+ '#ajax' => array(
+ 'callback' => 'ajax_bulk_example_files_callback',
),
- );
- }
- }
-
- /************ START OF $_POST **************/
- if ($_POST)
- {
- if (($book_default_value > 0) && ($chapter_default_value > 0) && ($example_default_value > 0))
- {
- $example_list_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE example_id = %d", $form_state['values']['run']['example']);
- if ($example_list_q)
- {
- $example_files_rows = array();
- while ($example_list_data = db_fetch_object($example_list_q))
- {
- $example_file_type = '';
- switch ($example_list_data->filetype)
- {
- case 'S' : $example_file_type = 'Source or Main file'; break;
- case 'R' : $example_file_type = 'Result file'; break;
- case 'X' : $example_file_type = 'xcos file'; break;
- default : $example_file_type = 'Unknown'; break;
- }
- $example_files_rows[] = array(l($example_list_data->filename, 'download/file/' . $example_list_data->id), $example_file_type);
- }
-
- /* dependency files */
- $dependency_list_q = db_query("SELECT dependency.id as dependency_id, dependency.filename as dependency_filename, dependency.caption as dependency_caption
- FROM {textbook_companion_example_dependency} example_dependency LEFT JOIN {textbook_companion_dependency_files} dependency
- ON example_dependency.dependency_id = dependency.id
- WHERE example_dependency.example_id = %d", $form_state['values']['run']['example']);
- while ($dependency_list_data = db_fetch_object($dependency_list_q))
- {
- $example_file_type = 'Dependency file';
- $temp_caption = '';
- if ($dependency_list_data->dependency_caption)
- $temp_caption = ' (' . $dependency_list_data->dependency_caption . ')';
- $example_files_rows[] = array(l($dependency_list_data->dependency_filename, 'download/dependency/' . $dependency_list_data->dependency_id) . $temp_caption, $example_file_type);
- }
-
- /* creating list of files table */
- $example_files_header = array('Filename', 'Type');
- $example_files = theme_table($example_files_header, $example_files_rows);
- }
- $form['run']['download_example'] = array(
+ );
+
+ $form['download_example'] = array(
'#type' => 'item',
- '#value' => l('Download Example', 'download/example/' . $example_default_value),
+ '#markup' => '<div id="ajax_download_selected_example"></div>',
);
- $form['run']['edit_example'] = array(
+ $form['edit_example'] = array(
'#type' => 'item',
- '#value' => l('Edit Example', 'code_approval/editcode/' . $example_default_value),
+ '#markup' => '<div id="ajax_edit_selected_example"></div>',
);
- $form['run']['example_files'] = array(
- '#type' => 'item',
- '#title' => 'List of example files',
- '#value' => $example_files,
- );
-
- $form['run']['approve_example'] = array(
- '#type' => 'checkbox',
- '#title' => t('Approve Example'),
- );
- $form['run']['unapprove_example'] = array(
- '#type' => 'checkbox',
- '#title' => t('Pending Review Example'),
- );
- $form['run']['disapprove_example'] = array(
- '#type' => 'checkbox',
- '#title' => t('Dis-approve Example (This will delete the example)'),
- '#prefix' => '<div style="color:red;"><strong>',
- '#suffix' => '</strong></div>',
+ $form['example_files'] = array(
+ '#type' => 'item',
+ '#markup' => '',
+ '#prefix' => '<div id="ajax_example_files_list">',
+ '#suffix' => '</div>',
+
);
- }
- }
- /************ END OF $_POST **************/
-
- if ($book_default_value > 0)
- {
- $form['run']['message'] = array(
+
+ $form['example_actions'] = array(
+ '#type' => 'select',
+ '#title' => t('Please select action for selected example'),
+ '#options' => _bulk_list_example_actions(),
+ //'#default_value' => isset($form_state['values']['lab_actions']) ? $form_state['values']['lab_actions'] : 0,
+ '#prefix' => '<div id="ajax_selected_example_action" style="color:red;">',
+ '#suffix' => '</div>',
+ '#states' => array('invisible' => array(':input[name="book"]' => array('value' => 0),),),
+ );
+
+ $form['message'] = array(
'#type' => 'textarea',
'#title' => t('If Dis-Approved please specify reason for Dis-Approval'),
+ '#states' => array('invisible' => array(':input[name="book"]' => array('value' => 0),),),
);
- $form['run']['submit'] = array(
+ $form['submit'] = array(
'#type' => 'submit',
- '#value' => t('Submit')
+ '#value' => t('Submit'),
+ '#validate' => array('bulk_approval_submit_validate'),
+ '#states' => array('invisible' => array(':input[name="book"]' => array('value' => 0),),),
);
- }
+
return $form;
}
+function bulk_approval_submit_validate($form, &$form_state){
+var_dump('test');
+if(($form_state['values']['book_actions'] == 0) && ($form_state['values']['chapter_actions']== 0) && ($form_state['values']['example_actions'] == 0))
+ drupal_set_message("Wrong selection of action. Please select any one action1", 'error');
+ return;
+ if(($form_state['values']['book_actions'] != 0) && ($form_state['values']['chapter_actions'] != 0) && ($form_state['values']['example_actions'] != 0))
+ drupal_set_message("Wrong selection of action. Please select any one action2");
+ return;
+ if(($form_state['values']['book_actions'] != 0) && ($form_state['values']['chapter_actions'] !=0) && ($form_state['values']['example_actions'] == 0))
+ drupal_set_message("Wrong selection of action. Please select any one action3", 'error');
+ return;
+ if(($form_state['values']['book_actions'] != 0) && ($form_state['values']['chapter_actions'] == 0) && ($form_state['values']['example_actions'] != 0))
+ drupal_set_message("Wrong selection of action. Please select any one action4", 'error');
+ return;
+
+if(($form_state['values']['book_actions'] == 0) && ($form_state['values']['chapter_actions'] != 0) && ($form_state['values']['lab_experiment_solution_actions'] != 0))
+ drupal_set_message("Wrong selection of action5. Please select any one action", 'error');
+ return;
+
+ }
function bulk_approval_form_submit($form, &$form_state)
{
global $user;
$root_path = textbook_companion_path();
-
+
if ($form_state['clicked_button']['#value'] == 'Submit')
{
- if ($form_state['values']['run']['book'])
- del_book_pdf($form_state['values']['run']['book']);
+ if ($form_state['values']['book'])
+ del_book_pdf($form_state['values']['book']);
if (user_access('bulk manage code'))
{
- if ($form_state['values']['run']['approve_book'] == "1")
+ if (($form_state['values']['book_actions'] == 1) && ($form_state['values']['chapter_actions']== 0) && ($form_state['values']['example_actions'] == 0))
{
/* approving entire book */
- $chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE preference_id = %d", $form_state['values']['run']['book']);
- while ($chapter_data = db_fetch_object($chapter_q))
+
+ /* $chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE preference_id = %d",
+ $form_state['values']['book']);*/
+
+ $query = db_select('textbook_companion_chapter');
+ $query->fields('textbook_companion_chapter');
+ $query->condition('preference_id', $form_state['values']['book']);
+ $chapter_q = $query->execute();
+
+ while ($chapter_data = $chapter_q->fetchObject())
{
- 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);
+ /*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);*/
+
+ $query = db_update('textbook_companion_example');
+ $query->fields(array(
+ 'approval_status' => 1,
+ 'approver_uid' => $user->uid,
+ ));
+ $query->condition('chapter_id', $chapter_data->id);
+ $query->condition('approval_status', 0);
+ $num_updated = $query->execute();
+
}
drupal_set_message(t('Approved Entire Book.'), 'status');
/* email */
$email_subject = t('Your uploaded examples have been approved');
- $email_body = t('Your all the uploaded examples for the book have been approved.');
+ $email_body = array(0=> t('Your all the uploaded examples for the book have been approved.'));
- } else if ($form_state['values']['run']['unapprove_book'] == "1") {
+ } else if (($form_state['values']['book_actions'] == 2) && ($form_state['values']['chapter_actions']== 0) && ($form_state['values']['example_actions'] == 0)) {
/* approving entire book */
- $chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE preference_id = %d", $form_state['values']['run']['book']);
- while ($chapter_data = db_fetch_object($chapter_q))
+
+ /*$chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE preference_id = %d", $form_state['values']['book']);*/
+ $query = db_select('textbook_companion_chapter');
+ $query->fields('textbook_companion_chapter');
+ $query->condition('preference_id', $form_state['values']['book']);
+ $result = $query->execute();
+
+ while ($chapter_data = $chapter_q->fetchObject())
{
- db_query("UPDATE {textbook_companion_example} SET approval_status = 0 WHERE chapter_id = %d", $chapter_data->id);
+ /*db_query("UPDATE {textbook_companion_example} SET approval_status = 0 WHERE chapter_id = %d", $chapter_data->id);*/
+ $query = db_update('textbook_companion_example');
+ $query->fields(array(
+ 'approval_status' => 0,
+ ));
+ $query->condition('chapter_id', $chapter_data->id);
+ $num_updated = $query->execute();
}
drupal_set_message(t('Pending Review Entire Book.'), 'status');
/* email */
$email_subject = t('Your uploaded examples have been marked as pending');
- $email_body = t('Your all the uploaded examples for the book have been marked as pending to be review. You will be able to see the exmaples after they have been approved by one of our reviewers.');
+ $email_body = array(0=> t('Your all the uploaded examples for the book have been marked as pending to be review. You will be able to see the exmaples after they have been approved by one of our reviewers.'));
- } else if ($form_state['values']['run']['disapprove_book'] == "1") {
+ } else if (($form_state['values']['book_actions'] == 3) && ($form_state['values']['chapter_actions']== 0) && ($form_state['values']['example_actions'] == 0)) {
if (!user_access('bulk delete code'))
{
@@ -498,7 +522,7 @@ function bulk_approval_form_submit($form, &$form_state)
return;
}
- if (delete_book($form_state['values']['run']['book']))
+ if (delete_book($form_state['values']['book']))
{
drupal_set_message(t('Dis-Approved and Deleted Entire Book.'), 'status');
} else {
@@ -507,13 +531,13 @@ function bulk_approval_form_submit($form, &$form_state)
/* email */
$email_subject = t('Your uploaded examples have been marked as dis-approved');
- $email_body = t('Your all the uploaded examples for the whole book have been marked as dis-approved.
+ $email_body = array(0 => t('Your all the uploaded examples for the whole book have been marked as dis-approved.
Reason for dis-approval:
-' . $form_state['values']['run']['message']);
+' . $form_state['values']['message']));
- } else if ($form_state['values']['run']['delete_book_including_proposal'] == "1") {
+ } elseif(($form_state['values']['book_actions'] == 4 )&& ($form_state['values']['chapter_actions']== 0) && ($form_state['values']['example_actions'] == 0)) {
if (!user_access('bulk delete code'))
{
@@ -522,18 +546,24 @@ Reason for dis-approval:
}
/* check if dependency files are present */
- $dep_q = db_query("SELECT * FROM {textbook_companion_dependency_files} WHERE preference_id = %d", $form_state['values']['run']['book']);
- if ($dep_data = db_fetch_object($dep_q))
+ /*$dep_q = db_query("SELECT * FROM {textbook_companion_dependency_files} WHERE preference_id = %d", $form_state['values']['book']);*/
+
+ /* $query = db_select('textbook_companion_dependency_files');
+ $query->fields('textbook_companion_dependency_files');
+ $query->condition('preference_id', $form_state['values']['book']);
+ $dep_q = $query->execute();
+
+ if ($dep_data =$dep_q->fetchObject())
{
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');
return;
}
-
- if (delete_book($form_state['values']['run']['book']))
+*/
+ if (delete_book($form_state['values']['book']))
{
drupal_set_message(t('Dis-Approved and Deleted Entire Book examples.'), 'status');
- $dir_path = $root_path . $form_state['values']['run']['book'];
+ $dir_path = $root_path . $form_state['values']['book'];
if (is_dir($dir_path))
{
$res = rmdir($dir_path);
@@ -547,45 +577,79 @@ Reason for dis-approval:
}
/* deleting preference and proposal */
- $preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d", $form_state['values']['run']['book']);
+ /*$preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d", $form_state['values']['book']);
$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);
+*/
+
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('id', $form_state['values']['book']);
+ $result = $query->execute();
+ $preference_data =$result->fetchObject();
+
+ $proposal_id = $preference_data->proposal_id;
+
+ /*db_query("DELETE FROM {textbook_companion_preference} WHERE proposal_id = %d", $proposal_id);*/
+ $query = db_delete('textbook_companion_preference');
+ $query->condition('proposal_id', $proposal_id);
+ $num_deleted = $query->execute();
+
+ /*db_query("DELETE FROM {textbook_companion_proposal} WHERE id = %d", $proposal_id);*/
+ $query = db_delete('textbook_companion_proposal');
+ $query->condition('id', $proposal_id);
+ $num_deleted = $query->execute();
- drupal_set_message(t('Deleted Book Proposal.'), 'status');
+ drupal_set_message(t('Deleted Book Proposal.'), 'status');
/* 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.
+ $email_subject = t('Your uploaded examples including the book proposal have been deleted');
+ $email_body = array(0 =>t('Your all the uploaded examples including the book have been deleted permanently.
Reason for deletion:
-' . $form_state['values']['run']['message']);
+' . $form_state['values']['message']));
} else {
drupal_set_message(t('Error Dis-Approving and Deleting Entire Book.'), 'error');
}
- } else if ($form_state['values']['run']['approve_chapter'] == "1") {
+ } elseif (($form_state['values']['book_actions'] == 0)&& ($form_state['values']['chapter_actions']== 1) && ($form_state['values']['example_actions'] == 0)) {
+
+ /*db_query("UPDATE {textbook_companion_example} SET approval_status = 1, approver_uid = %d WHERE chapter_id = %d AND approval_status = 0", $user->uid, $form_state['values']['chapter']);*/
+
+ $query = db_update('textbook_companion_example');
+ $query->fields(array(
+ 'approval_status' => 1,
+ 'approver_uid' => $user->uid,
+ ));
+ $query->condition('chapter_id', $form_state['values']['chapter']);
+ $query->condition('approval_status', 0);
+ $num_updated = $query->execute();
- db_query("UPDATE {textbook_companion_example} SET approval_status = 1, approver_uid = %d WHERE chapter_id = %d AND approval_status = 0", $user->uid, $form_state['values']['run']['chapter']);
drupal_set_message(t('Approved Entire Chapter.'), 'status');
/* email */
$email_subject = t('Your uploaded examples have been approved');
- $email_body = t('Your all the uploaded examples for the chapter have been approved.');
+ $email_body = array(0 => t('Your all the uploaded examples for the chapter have been approved.'));
+
+ } else if (($form_state['values']['book_actions'] == 0)&& ($form_state['values']['chapter_actions']== 2) && ($form_state['values']['example_actions'] == 0)) {
- } else if ($form_state['values']['run']['unapprove_chapter'] == "1") {
+ /*db_query("UPDATE {textbook_companion_example} SET approval_status = 0 WHERE chapter_id = %d", $form_state['values']['chapter']);*/
+
+ $query = db_update('textbook_companion_example');
+ $query->fields(array(
+ 'approval_status' => 0,
+ ));
+ $query->condition('chapter_id', $form_state['values']['chapter']);
+ $num_updated = $query->execute();
- db_query("UPDATE {textbook_companion_example} SET approval_status = 0 WHERE chapter_id = %d", $form_state['values']['run']['chapter']);
drupal_set_message(t('Entire Chapter marked as Pending Review.'), 'status');
/* email */
$email_subject = t('Your uploaded examples have been marked as pending');
- $email_body = t('Your all the uploaded examples for the chapter have been marked as pending to be review.');
+ $email_body = array(0 => t('Your all the uploaded examples for the chapter have been marked as pending to be review.'));
- } else if ($form_state['values']['run']['disapprove_chapter'] == "1") {
+ } else if (($form_state['values']['book_actions'] == 0)&& ($form_state['values']['chapter_actions']== 3) && ($form_state['values']['example_actions'] == 0)) {
if (!user_access('bulk delete code'))
{
@@ -593,7 +657,7 @@ Reason for deletion:
return;
}
- if (delete_chapter($form_state['values']['run']['chapter']))
+ if (delete_chapter($form_state['values']['chapter']))
{
drupal_set_message(t('Dis-Approved and Deleted Entire Chapter.'), 'status');
} else {
@@ -602,33 +666,50 @@ Reason for deletion:
/* email */
$email_subject = t('Your uploaded example have been marked as dis-approved');
- $email_body = t('Your uploaded example for the entire chapter have been marked as dis-approved.
+ $email_body = array(0 => t('Your uploaded example for the entire chapter have been marked as dis-approved.
Reason for dis-approval:
-' . $form_state['values']['run']['message']);
+' . $form_state['values']['message']));
+
+ } else if (($form_state['values']['book_actions'] == 0)&& ($form_state['values']['chapter_actions']== 0) && ($form_state['values']['example_actions'] == 1)) {
+
+ /*db_query("UPDATE {textbook_companion_example} SET approval_status = 1, approver_uid = %d WHERE id = %d", $user->uid, $form_state['values']['example']);*/
- } else if ($form_state['values']['run']['approve_example'] == "1") {
+ $query = db_update('textbook_companion_example');
+ $query->fields(array(
+ 'approval_status' => 1,
+ 'approver_uid' => $user->uid,
+ ));
+ $query->condition('id', $form_state['values']['example']);
+ $num_updated = $query->execute();
- db_query("UPDATE {textbook_companion_example} SET approval_status = 1, approver_uid = %d WHERE id = %d", $user->uid, $form_state['values']['run']['example']);
drupal_set_message(t('Example approved.'), 'status');
/* email */
$email_subject = t('Your uploaded example has been approved');
- $email_body = t('Your uploaded example has been approved.');
+ $email_body = array(0 => t('Your uploaded example has been approved.'));
- } else if ($form_state['values']['run']['unapprove_example'] == "1") {
+ } else if (($form_state['values']['book_actions'] == 0)&& ($form_state['values']['chapter_actions']== 0) && ($form_state['values']['example_actions'] == 2)) {
+
+ /*db_query("UPDATE {textbook_companion_example} SET approval_status = 0 WHERE id = %d", $form_state['values']['example']);*/
+
+ $query = db_update('textbook_companion_example');
+ $query->fields(array(
+ 'approval_status' => 0,
+ ));
+ $query->condition('id', $form_state['values']['example']);
+ $num_updated = $query->execute();
- db_query("UPDATE {textbook_companion_example} SET approval_status = 0 WHERE id = %d", $form_state['values']['run']['example']);
drupal_set_message(t('Example marked as Pending Review.'), 'status');
/* email */
$email_subject = t('Your uploaded example has been marked as pending');
- $email_body = t('Your uploaded example has been marked as pending to be review.');
+ $email_body = array( 0 => t('Your uploaded example has been marked as pending to be review.'));
- } else if ($form_state['values']['run']['disapprove_example'] == "1") {
+ } else if (($form_state['values']['book_actions'] == 0)&& ($form_state['values']['chapter_actions']== 0) && ($form_state['values']['example_actions'] == 3)) {
- if (delete_example($form_state['values']['run']['example']))
+ if (delete_example($form_state['values']['example']))
{
drupal_set_message(t('Example Dis-Approved and Deleted.'), 'status');
} else {
@@ -637,11 +718,11 @@ Reason for dis-approval:
/* email */
$email_subject = t('Your uploaded example has been marked as dis-approved');
- $email_body = t('Your uploaded example has been marked as dis-approved.
+ $email_body = array(0 => t('Your uploaded example has been marked as dis-approved.
Reason for dis-approval:
-' . $form_state['values']['run']['message']);
+' . $form_state['values']['message']));
}
@@ -661,39 +742,284 @@ Reason for dis-approval:
}
}
-function _list_of_books()
+function _bulk_list_of_books()
{
$book_titles = array('0' => 'Please select...');
- $book_titles_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE approval_status = 1 OR approval_status = 3 ORDER BY book ASC");
- while ($book_titles_data = db_fetch_object($book_titles_q))
+ /*$book_titles_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE approval_status = 1 OR approval_status = 3 ORDER BY book ASC");*/
+
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+
+ $or = db_or();
+ $or->condition('approval_status', 1);
+ $or->condition('approval_status', 3);
+ $query->condition($or);
+ $query->orderBy('book', 'ASC');
+ $book_titles_q = $query->execute();
+
+ while ($book_titles_data = $book_titles_q->fetchObject())
{
$book_titles[$book_titles_data->id] = $book_titles_data->book . ' (Written by ' . $book_titles_data->author . ')';
}
return $book_titles;
}
-function _list_of_chapters($preference_id = 0)
+function _ajax_bulk_get_chapter_list($preference_id = 0)
{
$book_chapters = array('0' => 'Please select...');
- $book_chapters_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE preference_id = %d ORDER BY number ASC", $preference_id);
- while ($book_chapters_data = db_fetch_object($book_chapters_q))
+
+ /*$book_chapters_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE preference_id = %d ORDER BY number ASC", $preference_id);*/
+ $query = db_select('textbook_companion_chapter');
+ $query->fields('textbook_companion_chapter');
+ $query->condition('preference_id', $preference_id);
+ $query->orderBy('number', 'ASC');
+ $book_chapters_q = $query->execute();
+
+ while ($book_chapters_data = $book_chapters_q->fetchObject())
{
$book_chapters[$book_chapters_data->id] = $book_chapters_data->number . '. ' . $book_chapters_data->name;
}
return $book_chapters;
}
-function _list_of_examples($chapter_id = 0)
+function _ajax_bulk_get_examples($chapter_id = 0)
{
$book_examples = array('0' => 'Please select...');
- $book_examples_q = db_query("SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d ORDER BY
+
+ /*$book_examples_q = db_query("SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d ORDER BY
CAST(SUBSTRING_INDEX(number, '.', 1) AS BINARY) ASC,
CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(number , '.', 2), '.', -1) AS UNSIGNED) ASC,
- CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(number , '.', -1), '.', 1) AS UNSIGNED) ASC", $chapter_id);
- while ($book_examples_data = db_fetch_object($book_examples_q))
+ CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(number , '.', -1), '.', 1) AS UNSIGNED) ASC", $chapter_id);*/
+
+ $query = db_select('textbook_companion_example');
+ $query->fields('textbook_companion_example');
+ $query->condition('chapter_id', $chapter_id);
+ //$query->orderBy('CAST', 'ASC');
+ //$query->orderBy('CAST', 'ASC');
+ //$query->orderBy('CAST', 'ASC');
+ $book_examples_q = $query->execute();
+
+
+ while ($book_examples_data = $book_examples_q->fetchObject())
{
$book_examples[$book_examples_data->id] = $book_examples_data->number . ' (' . $book_examples_data->caption . ')';
}
return $book_examples;
}
+function _bulk_list_book_actions(){
+ $book_actions = array(0 => 'Please select...');
+ $book_actions[1] = 'Approve Entire Book';
+ $book_actions[2] = 'Pending Review Entire Book';
+ $book_actions[3] = 'Dis-Approve Entire Book (This will delete all the examples in the book)';
+ $book_actions[4] = 'Delete Entire Book Including Proposal';
+ return $book_actions;
+ }
+
+ function _bulk_list_chapter_actions(){
+ $chapter_actions = array(0 => 'Please select...');
+ $chapter_actions[1] = 'Approve Entire Chapter';
+ $chapter_actions[2] = 'Pending Review Entire Chapter';
+ $chapter_actions[3] = 'Dis-Approve Entire Chapter (This will delete all the examples in the chapter)';
+
+ return $chapter_actions;
+ }
+ function _bulk_list_example_actions(){
+ $example_actions = array(0 => 'Please select...');
+ $example_actions[1] = 'Approve Approve Example';
+ $example_actions[2] = 'Pending Review Example';
+ $example_actions[3] = 'Dis-approve Example (This will delete the example)';
+
+ return $example_actions;
+ }
+ /****************************** Ajax Callback function ***************************/
+ function ajax_bulk_chapter_list_callback($form, $form_state) {
+
+ $commands = array();
+ $book_default_value = $form_state['values']['book'];
+ if($book_default_value > 0){
+ $commands[] = ajax_command_html('#ajax_selected_book', l('Download', 'full_download/book/' . $book_default_value) . ' ' . t('(Download all the approved and unapproved examples of the entire book)') );
+ $commands[] = ajax_command_html('#ajax_selected_book_pdf', l('Download PDF', 'textbook_companion/generate_book/' . $book_default_value . '/1') . ' ' . t('(Download PDF of all the approved and unapproved examples of the entire book)'));
+ $commands[] = ajax_command_html('#ajax_selected_book_regenerate_pdf', l('Regenerate PDF', 'textbook_companion/delete_book/' . $book_default_value) . ' ' . t('(Manually Regenerate PDF of the entire book)'));
+ $commands[] = ajax_command_html('#ajax_selected_book_notes', l('Notes for Reviewers', 'code_approval/notes/' . $book_default_value));
+ $form['book_actions']['#options'] = _bulk_list_book_actions();
+ $commands[] = ajax_command_replace('#ajax_selected_book_action',drupal_render($form['book_actions']));
+ $form['chapter']['#options'] = _ajax_bulk_get_chapter_list($book_default_value);
+ $commands[] = ajax_command_replace('#ajax_select_chapter_list',drupal_render($form['chapter']));
+ $commands[] = ajax_command_html('#ajax_download_chapter', '' );
+ $form['chapter_actions']['#options'] = _bulk_list_book_actions();
+ $commands[] = ajax_command_replace('#ajax_selected_chapter_action',drupal_render($form['chapter_actions']));
+ $commands[] = ajax_command_html('#ajax_selected_chapter_action', '' );
+ $commands[] = ajax_command_html('#ajax_selected_example', '' );
+ $form['example_actions']['#options'] = _bulk_list_example_actions();
+ $commands[] = ajax_command_replace('#ajax_selected_example_action',drupal_render($form['example_actions']));
+ $commands[] = ajax_command_html('#ajax_selected_example_action', '' );
+ $commands[] = ajax_command_html('#ajax_download_selected_example', '');
+ $commands[] = ajax_command_html('#ajax_edit_selected_example', '');
+ $form['example_files']['#title'] = '';
+ $form['example_files']['#markup'] = '' ;
+ $commands[] = ajax_command_replace('#ajax_example_files_list', drupal_render($form['example_files']));
+ }else{
+
+ $commands[] = ajax_command_html('#ajax_selected_book', '' );
+ $commands[] = ajax_command_html('#ajax_selected_book_pdf', '');
+ $commands[] = ajax_command_html('#ajax_selected_book_regenerate_pdf', '');
+ $commands[] = ajax_command_html('#ajax_selected_book_notes', '');
+ $form['chapter']['#options'] = _ajax_bulk_get_chapter_list();
+ $commands[] = ajax_command_replace('#ajax_select_chapter_list',drupal_render($form['chapter']));
+ $commands[] = ajax_command_html('#ajax_select_chapter_list', '');
+ $form['book_actions']['#options'] = _bulk_list_book_actions();
+ $commands[] = ajax_command_replace('#ajax_selected_book_action',drupal_render($form['book_actions']));
+ $commands[] = ajax_command_html('#ajax_selected_book_action', '');
+ $form['chapter_actions']['#options'] = _bulk_list_chapter_actions();
+ $commands[] = ajax_command_replace('#ajax_selected_chapter_action',drupal_render($form['chapter_actions']));
+ $commands[] = ajax_command_html('#ajax_selected_chapter_action', '' );
+ $commands[] = ajax_command_html('#ajax_download_chapter', '' );
+ $commands[] = ajax_command_html('#ajax_selected_example', '' );
+ $form['example_actions']['#options'] = _bulk_list_example_actions();
+ $commands[] = ajax_command_replace('#ajax_selected_example_action',drupal_render($form['example_actions']));
+ $commands[] = ajax_command_html('#ajax_selected_example_action', '' );
+ $commands[] = ajax_command_html('#ajax_download_selected_example', '');
+ $commands[] = ajax_command_html('#ajax_edit_selected_example', '');
+ $form['example_files']['#title'] = '';
+ $form['example_files']['#markup'] = '' ;
+ $commands[] = ajax_command_replace('#ajax_example_files_list', drupal_render($form['example_files']));
+
+ }
+ return array('#type' => 'ajax', '#commands' => $commands);
+ }
+
+ function ajax_bulk_example_list_callback($form, $form_state) {
+
+ $commands = array();
+ $chapter_default_value = $form_state['values']['chapter'];
+
+ if($chapter_default_value > 0){
+
+ $commands[] = ajax_command_html('#ajax_download_chapter', l('Download', 'full_download/chapter/' . $chapter_default_value) . ' ' . t('(Download all the approved and unapproved examples of the entire chapter)') );
+ $form['chapter_actions']['#options'] = _bulk_list_chapter_actions();
+ $commands[] = ajax_command_replace('#ajax_selected_chapter_action',drupal_render($form['chapter_actions']));
+ $form['example']['#options'] = _ajax_bulk_get_examples($chapter_default_value);
+ $commands[] = ajax_command_replace('#ajax_selected_example',drupal_render($form['example']));
+ $commands[] = ajax_command_html('#ajax_download_selected_example', '');
+ $commands[] = ajax_command_html('#ajax_edit_selected_example', '');
+ $form['example_actions']['#options'] = _bulk_list_example_actions();
+ $commands[] = ajax_command_replace('#ajax_selected_example_action',drupal_render($form['example_actions']));
+ $commands[] = ajax_command_html('#ajax_selected_example_action', '' );
+ $form['example_files']['#title'] = '';
+ $form['example_files']['#markup'] = '' ;
+ $commands[] = ajax_command_replace('#ajax_example_files_list', drupal_render($form['example_files']));
+
+ }else{
+
+ $commands[] = ajax_command_html('#ajax_download_chapter', '' );
+ $form['chapter_actions']['#options'] = _bulk_list_chapter_actions();
+ $commands[] = ajax_command_replace('#ajax_selected_chapter_action',drupal_render($form['chapter_actions']));
+ $commands[] = ajax_command_html('#ajax_selected_chapter_action', '' );
+ $form['example']['#options'] = _ajax_bulk_get_examples();
+ $commands[] = ajax_command_replace('#ajax_selected_example',drupal_render($form['example']));
+ $commands[] = ajax_command_html('#ajax_selected_example','');
+ $commands[] = ajax_command_html('#ajax_download_selected_example', '');
+ $commands[] = ajax_command_html('#ajax_edit_selected_example', '');
+ $form['example_files']['#title'] = '';
+ $form['example_files']['#markup'] = '' ;
+ $commands[] = ajax_command_replace('#ajax_example_files_list', drupal_render($form['example_files']));
+ $form['example_actions']['#options'] = _bulk_list_example_actions();
+ $commands[] = ajax_command_replace('#ajax_selected_example_action',drupal_render($form['example_actions']));
+ $commands[] = ajax_command_html('#ajax_selected_example_action', '' );
+
+ }
+ return array('#type' => 'ajax', '#commands' => $commands);
+ }
+
+ function ajax_bulk_example_files_callback($form, $form_state) {
+
+ $commands = array();
+ $example_list_default_value = $form_state['values']['example'];
+ //var_dump($example_list_default_value);
+ if($example_list_default_value > 0){
+ /*************************************************************************************/
+ /*$example_list_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE example_id = %d", $form_state['values']['example']);*/
+ $query = db_select('textbook_companion_example_files');
+ $query->fields('textbook_companion_example_files');
+ $query->condition('example_id', $example_list_default_value);
+ $example_list_q = $query->execute();
+
+ if ($example_list_q)
+ {
+ $example_files_rows = array();
+ while ($example_list_data = $example_list_q->fetchObject())
+ {
+ $example_file_type = '';
+ switch ($example_list_data->filetype)
+ {
+ case 'S' : $example_file_type = 'Source or Main file'; break;
+ case 'R' : $example_file_type = 'Result file'; break;
+ case 'X' : $example_file_type = 'xcos file'; break;
+ default : $example_file_type = 'Unknown'; break;
+ }
+ $example_files_rows[] = array(l($example_list_data->filename, 'download/file/' . $example_list_data->id), $example_file_type);
+ }
+
+ /* dependency files */
+
+ /*$dependency_list_q = db_query("SELECT dependency.id as dependency_id, dependency.filename as dependency_filename, dependency.caption as dependency_caption
+ FROM {textbook_companion_example_dependency} example_dependency LEFT JOIN {textbook_companion_dependency_files} dependency
+ ON example_dependency.dependency_id = dependency.id
+ WHERE example_dependency.example_id = %d", $form_state['values']['example']);*/
+
+ $query = db_select('textbook_companion_example_dependency', 'example_dependency');
+ $query->fields('dependency', array('id', 'filename', 'caption'));
+ $query->addField('dependency','id','dependency_id');
+ $query->addField('dependency','filename','dependency_filename');
+ $query->addField('dependency','caption','dependency_caption');
+ $query->leftJoin('textbook_companion_dependency_files', 'dependency', 'example_dependency.dependency_id = dependency.id');
+ $query->condition('example_dependency.example_id', $form_state['values']['example']);
+ $dependency_list_q = $query->execute();
+
+ while ($dependency_list_data = $dependency_list_q->fetchObject())
+ {
+ $example_file_type = 'Dependency file';
+ $temp_caption = '';
+ if ($dependency_list_data->dependency_caption)
+ $temp_caption = ' (' . $dependency_list_data->dependency_caption . ')';
+ $example_files_rows[] = array(l($dependency_list_data->dependency_filename, 'download/dependency/' . $dependency_list_data->dependency_id) . $temp_caption, $example_file_type);
+ }
+
+ /* creating list of files table */
+ $example_files_header = array('Filename', 'Type');
+ $example_files = theme('table', array('header'=> $example_files_header,'rows'=> $example_files_rows));
+
+ $form['example_files']['#title'] = 'List of example files';
+ $form['example_files']['#markup'] = $example_files ;
+ $commands[] = ajax_command_replace('#ajax_example_files_list', drupal_render($form['example_files']));
+ $commands[] = ajax_command_html('#ajax_download_selected_example', l('Download Example', 'download/example/' . $example_list_default_value) );
+ $commands[] = ajax_command_html('#ajax_edit_selected_example', l('Edit Example', 'code_approval/editcode/' . $example_list_default_value));
+ $form['example_actions']['#options'] = _bulk_list_example_actions();
+ $commands[] = ajax_command_replace('#ajax_selected_example_action',drupal_render($form['example_actions']));
+ //$commands[] = ajax_command_html('#ajax_selected_example_action', '' );
+ }
+
+ }else{
+
+ $commands[] = ajax_command_html('#ajax_download_selected_example', '');
+ $commands[] = ajax_command_html('#ajax_edit_selected_example', '');
+ $form['example_files']['#title'] = '';
+ $form['example_files']['#markup'] = '' ;
+ $commands[] = ajax_command_replace('#ajax_example_files_list', drupal_render($form['example_files']));
+ $form['example_actions']['#options'] = _bulk_list_example_actions();
+ $commands[] = ajax_command_replace('#ajax_selected_example_action',drupal_render($form['example_actions']));
+ $commands[] = ajax_command_html('#ajax_selected_example_action', '' );
+ }
+ return array('#type' => 'ajax', '#commands' => $commands);
+ }
+ function ajax_bulk_chapter_actions_callback(){
+ //if($form_state['values']['chapter_actions'] > 0){
+ // $form['book_actions']['#options'] = _bulk_list_book_actions();
+ //$commands[] = ajax_command_replace('#ajax_selected_book_action',drupal_render($form['book_actions']));
+ // }
+
+ return array('#type' => 'ajax', '#commands' => $commands);
+
+
+ }
diff --git a/dependency.inc b/dependency.inc
index a76d428..fc5bc0d 100755
--- a/dependency.inc
+++ b/dependency.inc
@@ -6,8 +6,18 @@ function upload_dependency_form($form_state)
global $user;
/************************ start approve book details ************************/
- $proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE uid = %d ORDER BY id DESC LIMIT 1", $user->uid);
- $proposal_data = db_fetch_object($proposal_q);
+
+ /*$proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE uid = %d ORDER BY id DESC LIMIT 1", $user->uid);
+ $proposal_data = db_fetch_object($proposal_q);*/
+
+ $query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal');
+ $query->condition('uid', $user->uid);
+ $query->orderBy('id', 'DESC');
+ $query->range(0, 1);
+ $result = $query->execute();
+ $proposal_data =$result->fetchObject();
+
if (!$proposal_data)
{
drupal_set_message("Please submit a " . l('proposal', 'proposal') . ".", 'error');
@@ -40,8 +50,16 @@ function upload_dependency_form($form_state)
}
}
- $preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND approval_status = 1 LIMIT 1", $proposal_data->id);
- $preference_data = db_fetch_object($preference_q);
+ /*$preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND approval_status = 1 LIMIT 1", $proposal_data->id);
+ $preference_data = db_fetch_object($preference_q);*/
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('proposal_id', $proposal_data->id);
+ $query->condition('approval_status', 1);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $preference_data=$result->fetchObject();
+
if (!$preference_data)
{
drupal_set_message(t('Invalid Book Preference status. Please contact site administrator for further information.'), 'error');
@@ -54,18 +72,18 @@ function upload_dependency_form($form_state)
$form['book_details']['book'] = array(
'#type' => 'item',
- '#value' => $preference_data->book,
+ '#markup' => $preference_data->book,
'#title' => t('Title of the Book'),
);
$form['contributor_name'] = array(
'#type' => 'item',
- '#value' => $proposal_data->full_name,
+ '#markup' => $proposal_data->full_name,
'#title' => t('Contributor Name'),
);
$form['existing_depfile'] = array(
'#type' => 'item',
- '#value' => _list_existing_dependency($preference_data->id),
+ '#markup' => _list_existing_dependency($preference_data->id),
'#title' => t('List of existing dependency files for this book'),
);
@@ -109,8 +127,18 @@ function upload_dependency_form_validate($form, &$form_state)
global $user;
/* get approved book details */
- $book_q = db_query("SELECT pro.id as pro_id, pre.id as pre_id, pre.book as pre_book, pro.full_name as pro_full_name FROM {textbook_companion_proposal} pro JOIN {textbook_companion_preference} pre ON pro.id = pre.proposal_id WHERE pro.proposal_status = 1 AND pre.approval_status = 1 AND pro.uid = %d", $user->uid);
- $book_data = db_fetch_object($book_q);
+ /*$book_q = db_query("SELECT pro.id as pro_id, pre.id as pre_id, pre.book as pre_book, pro.full_name as pro_full_name FROM {textbook_companion_proposal} pro JOIN {textbook_companion_preference} pre ON pro.id = pre.proposal_id WHERE pro.proposal_status = 1 AND pre.approval_status = 1 AND pro.uid = %d", $user->uid);
+ $book_data = db_fetch_object($book_q);*/
+
+ $query = db_select('textbook_companion_proposal', 'pro');
+ $query->fields('pro', array('id', 'full_name'));
+ $query->fields('pre', array('id', 'book'));
+ $query->innerJoin('textbook_companion_preference', 'pre', 'pro.id = pre.proposal_id');
+ $query->condition('pro.proposal_status', 1);
+ $query->condition('pre.approval_status', 1);
+ $query->condition('pro.uid', $user->uid);
+ $result = $query->execute();
+ $book_data=$result->fetchObject();
if (isset($_FILES['files']))
{
@@ -127,7 +155,15 @@ function upload_dependency_form_validate($form, &$form_state)
form_set_error($file_form_name, t('File size cannot be zero.'));
/* check if file already exists */
- $dep_exists_data = db_fetch_object(db_query("SELECT * FROM {textbook_companion_dependency_files} WHERE filename = '%s'", $_FILES['files']['name'][$file_form_name]));
+
+ /*$dep_exists_data = db_fetch_object(db_query("SELECT * FROM {textbook_companion_dependency_files} WHERE filename = '%s'", $_FILES['files']['name'][$file_form_name]));*/
+
+ $query = db_select('textbook_companion_dependency_files');
+ $query->fields('textbook_companion_dependency_files');
+ $query->condition('filename', $_FILES['files']['name'][$file_form_name]);
+ $result = $query->execute();
+ $dep_exists_data=$result->fetchObject();
+
if ($dep_exists_data)
form_set_error($file_form_name, t('Dependency file with the same name has already been uploaded in this or some other book. Please rename the file and try again.'));
@@ -145,8 +181,18 @@ function upload_dependency_form_submit($form, &$form_state) {
$root_path = textbook_companion_path();
/* get approved book details */
- $proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE uid = %d ORDER BY id DESC LIMIT 1", $user->uid);
- $proposal_data = db_fetch_object($proposal_q);
+
+ /*$proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE uid = %d ORDER BY id DESC LIMIT 1", $user->uid);
+ $proposal_data = db_fetch_object($proposal_q);*/
+
+ $query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal');
+ $query->condition('uid', $user->uid);
+ $query->orderBy('id', 'DESC');
+ $query->range(0, 1);
+ $result = $query->execute();
+ $proposal_data=$result->fetchObject();
+
if (!$proposal_data)
{
drupal_set_message("Please submit a " . l('proposal', 'proposal') . ".", 'error');
@@ -179,8 +225,17 @@ function upload_dependency_form_submit($form, &$form_state) {
}
}
- $preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND approval_status = 1 LIMIT 1", $proposal_data->id);
- $preference_data = db_fetch_object($preference_q);
+ /*$preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND approval_status = 1 LIMIT 1", $proposal_data->id);
+ $preference_data = db_fetch_object($preference_q);*/
+
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('proposal_id', $proposal_data->id);
+ $query->condition('approval_status', 1);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $preference_data=$result->fetchObject();
+
if (!$preference_data)
{
drupal_set_message(t('Invalid Book Preference status. Please contact site administrator for further information.'), 'error');
@@ -211,7 +266,7 @@ function upload_dependency_form_submit($form, &$form_state) {
if (move_uploaded_file($_FILES['files']['tmp_name'][$file_form_name], $root_path . $dest_path . $_FILES['files']['name'][$file_form_name]))
{
/* for uploaded files making an entry in the database */
- db_query("INSERT INTO {textbook_companion_dependency_files} (preference_id, filename, filepath, filemime, filesize, caption, description, timestamp)
+ /* db_query("INSERT INTO {textbook_companion_dependency_files} (preference_id, filename, filepath, filemime, filesize, caption, description, timestamp)
VALUES (%d, '%s', '%s', '%s', %d, '%s', '%s', %d)",
$preference_id,
$_FILES['files']['name'][$file_form_name],
@@ -221,9 +276,27 @@ function upload_dependency_form_submit($form, &$form_state) {
$form_state['values'][$file_form_name . '_caption'],
$form_state['values'][$file_form_name . '_description'],
time()
- );
+ );*/
+ $query = "INSERT INTO {textbook_companion_dependency_files} (preference_id, filename, filepath, filemime, filesize, caption, description, timestamp)
+ VALUES (:preference_id, :filename, :filepath, :filemime, :filesize, :caption, :description, :timestamp)";
+ $args = array(
+ ":preference_id"=>$preference_id,
+ ":filename"=>$_FILES['files']['name'][$file_form_name],
+ ":filepath"=>$dest_path . $_FILES['files']['name'][$file_form_name],
+ ":filemime"=>$_FILES['files']['type'][$file_form_name],
+ ":filesize"=>$_FILES['files']['size'][$file_form_name],
+ ":caption"=>$form_state['values'][$file_form_name . '_caption'],
+ ":description"=>$form_state['values'][$file_form_name . '_description'],
+ ":timestamp"=>time(),
+ );
+ $result = db_query($query, $args, array('return' => Database::RETURN_INSERT_ID));
+
+
drupal_set_message($file_name . ' uploaded successfully.', 'status');
- $dependency_ids[] = db_last_insert_id('textbook_companion_dependency_files', 'id');
+
+ //$dependency_ids[] = db_last_insert_id('textbook_companion_dependency_files', 'id');
+ $dependency_ids[]=$result;
+
$dependency_names[] = $_FILES['files']['name'][$file_form_name];
$file_upload_counter++;
} else {
@@ -252,8 +325,14 @@ function _list_existing_dependency($book_id)
{
// $return_html = '<ul>';
$return_html = "";
- $query = "SELECT * FROM textbook_companion_dependency_files WHERE preference_id = %d ORDER BY filename ASC";
- $result = db_query($query, $book_id);
+ /*$query = "SELECT * FROM textbook_companion_dependency_files WHERE preference_id = %d ORDER BY filename ASC";
+ $result = db_query($query, $book_id);*/
+
+ $query = db_select('textbook_companion_dependency_files');
+ $query->fields('textbook_companion_dependency_files');
+ $query->condition('preference_id', $book_id);
+ $query->orderBy('filename', 'ASC');
+ $result = $query->execute();
// $counter = 0;
// while ($row = db_fetch_object($query))
@@ -272,7 +351,7 @@ function _list_existing_dependency($book_id)
"File", "Action",
);
$rows = array();
- while($row = db_fetch_object($result)) {
+ while($row = $result->fetchObject()) {
$item = array(
l($row->filename . $temp_caption, 'download/dependency/' . $row->id),
l("Edit", "textbook_companion/code/edit_dep/{$row->id}")
@@ -280,7 +359,7 @@ function _list_existing_dependency($book_id)
);
array_push($rows, $item);
}
- $return_html .= theme("table", $headers, $rows);
+ $return_html .= theme("table",array("headers"=>$headers, "rows"=>$rows));
return $return_html;
}
@@ -291,8 +370,18 @@ function edit_dependency_form($form_state, $dependency_id=0)
global $user;
/************************ start approve book details ************************/
- $proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE uid = %d ORDER BY id DESC LIMIT 1", $user->uid);
- $proposal_data = db_fetch_object($proposal_q);
+
+ /*$proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE uid = %d ORDER BY id DESC LIMIT 1", $user->uid);
+ $proposal_data = db_fetch_object($proposal_q);*/
+
+ $query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal');
+ $query->condition('uid', $user->uid);
+ $query->orderBy('id', 'DESC');
+ $query->range(0, 1);
+ $result = $query->execute();
+ $proposal_data=$result->fetchObject();
+
if (!$proposal_data)
{
drupal_set_message("Please submit a " . l('proposal', 'proposal') . ".", 'error');
@@ -325,8 +414,17 @@ function edit_dependency_form($form_state, $dependency_id=0)
}
}
- $preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND approval_status = 1 LIMIT 1", $proposal_data->id);
- $preference_data = db_fetch_object($preference_q);
+ /*$preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND approval_status = 1 LIMIT 1", $proposal_data->id);
+ $preference_data = db_fetch_object($preference_q);*/
+
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('proposal_id', $proposal_data->id);
+ $query->condition('approval_status', 1);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $preference_data=$result->fetchObject();
+
if (!$preference_data)
{
drupal_set_message(t('Invalid Book Preference status. Please contact site administrator for further information.'), 'error');
@@ -335,12 +433,20 @@ function edit_dependency_form($form_state, $dependency_id=0)
}
/************************ end approve book details **************************/
/* fetching the default values */
- $query = "
+
+ /*$query = "
SELECT * FROM {textbook_companion_dependency_files}
WHERE id = {$dependency_id}
";
$result = db_query($query);
- $row = db_fetch_object($result);
+ $row = db_fetch_object($result);*/
+
+ $query = db_select('textbook_companion_dependency_files');
+ $query->fields('textbook_companion_dependency_files');
+ $query->condition('id', $dependency_id);
+ $result = $query->execute();
+ $row=$result->fetchObject();
+
$form['#attributes'] = array('enctype' => "multipart/form-data");
@@ -405,13 +511,19 @@ function edit_dependency_form_validate($form, &$form_state)
form_set_error($file_form_name, t('File size cannot be zero.'));
/* check if file already exists */
- $dep_exists_data = db_fetch_object(
+ /*$dep_exists_data = db_fetch_object(
db_query(
"SELECT * FROM {textbook_companion_dependency_files} WHERE filename = '%s' AND id != %d",
$_FILES['files']['name'][$file_form_name],
$form_state["values"]["dependency_id"]
)
- );
+ );*/
+ $query = db_select('textbook_companion_dependency_files');
+ $query->fields('textbook_companion_dependency_files');
+ $query->condition('filename', $_FILES['files']['name'][$file_form_name]);
+ $query->condition('id', $form_state["values"]["dependency_id"], '<>');
+ $result = $query->execute();
+ $dep_exists_data=$result->fetchObject();
if ($dep_exists_data)
form_set_error($file_form_name, t('Dendency file with the same name has already been uploaded in this or some other book. Please rename the file and try again.'));
@@ -430,8 +542,19 @@ function edit_dependency_form_submit($form, &$form_state) {
$root_path = textbook_companion_path();
/* get approved book details */
- $proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE uid = %d ORDER BY id DESC LIMIT 1", $user->uid);
- $proposal_data = db_fetch_object($proposal_q);
+
+ /*$proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE uid = %d ORDER BY id DESC LIMIT 1", $user->uid);
+ $proposal_data = db_fetch_object($proposal_q);*/
+
+ $query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal');
+ $query->condition('uid', $user->uid);
+ $query->orderBy('id', 'DESC');
+ $query->range(0, 1);
+ $result = $query->execute();
+ $proposal_data=$result->fetchObject();
+
+
if (!$proposal_data)
{
drupal_set_message("Please submit a " . l('proposal', 'proposal') . ".", 'error');
@@ -464,8 +587,17 @@ function edit_dependency_form_submit($form, &$form_state) {
}
}
- $preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND approval_status = 1 LIMIT 1", $proposal_data->id);
- $preference_data = db_fetch_object($preference_q);
+ /*$preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND approval_status = 1 LIMIT 1", $proposal_data->id);
+ $preference_data = db_fetch_object($preference_q);*/
+
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('proposal_id', $proposal_data->id);
+ $query->condition('approval_status', 1);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $preference_data=$result->fetchObject();
+
if (!$preference_data)
{
drupal_set_message(t('Invalid Book Preference status. Please contact site administrator for further information.'), 'error');
@@ -489,12 +621,20 @@ function edit_dependency_form_submit($form, &$form_state) {
$dependency_names = array();
/* deleting old dependency file if the filename changed */
- $query = "
+
+ /*$query = "
SELECT * FROM textbook_companion_dependency_files
WHERE id = %d
";
$result = db_query($query, $form_state["values"]["dependency_id"]);
- $row = db_fetch_object($result);
+ $row = db_fetch_object($result);*/
+
+ $query = db_select('textbook_companion_dependency_files');
+ $query->fields('textbook_companion_dependency_files');
+ $query->condition('id', $form_state["values"]["dependency_id"]);
+ $result = $query->execute();
+ $row = $result->fetchObject();
+
if($row->filename != $_FILES["files"]["name"][$file_form_name] && $_FILES["files"]["name"][$file_form_name]) {
unlink($root_path . $dest_path . $row->filename);
}
@@ -510,7 +650,7 @@ function edit_dependency_form_submit($form, &$form_state) {
if (move_uploaded_file($_FILES['files']['tmp_name'][$file_form_name], $root_path . $dest_path . $_FILES['files']['name'][$file_form_name]))
{
/* updating uploaded file entry in the database */
- db_query(
+ /*db_query(
"UPDATE {textbook_companion_dependency_files} SET
filename = '%s', filepath = '%s', filemime = '%s', filesize = %d,
caption = '%s', description = '%s', timestamp = %s
@@ -523,7 +663,21 @@ function edit_dependency_form_submit($form, &$form_state) {
$form_state['values'][$file_form_name . '_description'],
time(),
$form_state["values"]["dependency_id"]
- );
+ );*/
+
+ $query = db_update('textbook_companion_dependency_files');
+ $query->fields(array(
+ 'filename' => $_FILES['files']['name'][$file_form_name],
+ 'filepath' => $dest_path . $_FILES['files']['name'][$file_form_name],
+ 'filemime' => $_FILES['files']['type'][$file_form_name],
+ 'filesize' => $_FILES['files']['size'][$file_form_name],
+ 'caption' => $form_state['values'][$file_form_name . '_caption'],
+ 'description' => $form_state['values'][$file_form_name . '_description'],
+ 'timestamp' =>time(),
+ ));
+ $query->condition('id', $form_state["values"]["dependency_id"]);
+ $num_updated = $query->execute();
+
drupal_set_message($file_name . ' uploaded successfully.', 'status');
$dependency_ids[] = db_last_insert_id('textbook_companion_dependency_files', 'id');
@@ -567,8 +721,18 @@ function delete_dependency($dependency_id = 0, $confirm = "") {
global $user;
/************************ start approve book details ************************/
- $proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE uid = %d ORDER BY id DESC LIMIT 1", $user->uid);
- $proposal_data = db_fetch_object($proposal_q);
+
+ /*$proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE uid = %d ORDER BY id DESC LIMIT 1", $user->uid);
+ $proposal_data = db_fetch_object($proposal_q);*/
+
+ $query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal');
+ $query->condition('uid', $user->uid);
+ $query->orderBy('id', 'DESC');
+ $query->range(0, 1);
+ $result = $query->execute();
+ $proposal_data= $result->fetchObject();
+
if (!$proposal_data)
{
drupal_set_message("Please submit a " . l('proposal', 'proposal') . ".", 'error');
@@ -601,8 +765,18 @@ function delete_dependency($dependency_id = 0, $confirm = "") {
}
}
- $preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND approval_status = 1 LIMIT 1", $proposal_data->id);
- $preference_data = db_fetch_object($preference_q);
+ /*$preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND approval_status = 1 LIMIT 1", $proposal_data->id);
+ $preference_data = db_fetch_object($preference_q);*/
+
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('proposal_id', $proposal_data->id);
+ $query->condition('approval_status', 1);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $preference_data =$result->fetchObject();
+
+
if (!$preference_data)
{
drupal_set_message(t('Invalid Book Preference status. Please contact site administrator for further information.'), 'error');
@@ -613,12 +787,19 @@ function delete_dependency($dependency_id = 0, $confirm = "") {
$page_content = "";
if($dependency_id && $confirm == "yes") {
/* removing the dependency file from filesystem */
- $query = "
+
+ /*$query = "
SELECT * FROM {textbook_companion_dependency_files}
WHERE id = {$dependency_id}
";
$result = db_query($query);
- $row = db_fetch_object($result);
+ $row = db_fetch_object($result);*/
+
+ $query = db_select('textbook_companion_dependency_files');
+ $query->fields('textbook_companion_dependency_files');
+ $query->condition('id', $dependency_id);
+ $result = $query->execute();
+ $row=$result->fetchObject();
if($preference_data->id == $row->preference_id) {
$root_path = textbook_companion_path();
@@ -627,18 +808,28 @@ function delete_dependency($dependency_id = 0, $confirm = "") {
unlink($root_path . $dest_path . $row->filename);
/* deleting entry in textbook_companion_dependency_files */
- $query = "
+
+ /*$query = "
DELETE FROM {textbook_companion_dependency_files}
WHERE id = {$dependency_id}
";
- db_query($query);
+ db_query($query);*/
+
+ $query = db_delete('textbook_companion_dependency_files');
+ $query->condition('id', $dependency_id);
+ $num_deleted = $query->execute();
/* deleting entries from textbook_companion_example_dependency */
- $query = "
+
+ /*$query = "
DELETE FROM {textbook_companion_example_dependency}
WHERE dependency_id = {$dependency_id}
";
- db_query($query);
+ db_query($query);*/
+
+ $query = db_delete('textbook_companion_example_dependency');
+ $query->condition('dependency_id', $dependency_id);
+ $num_deleted = $query->execute();
drupal_set_message("Dependency deleted successfully.");
drupal_goto("textbook_companion/code/upload_dep");
@@ -647,12 +838,18 @@ function delete_dependency($dependency_id = 0, $confirm = "") {
drupal_goto("textbook_companion/code/upload_dep");
}
} else if($dependency_id) {
- $query = "
+ /*$query = "
SELECT * FROM {textbook_companion_dependency_files}
WHERE id = %d
";
$result = db_query($query, $dependency_id);
- $row = db_fetch_object($result);
+ $row = db_fetch_object($result);*/
+
+ $query = db_select('textbook_companion_dependency_files');
+ $query->fields('textbook_companion_dependency_files');
+ $query->condition('id', $dependency_id);
+ $result = $query->execute();
+ $row =$result->fetchObject();
if($preference_data->id == $row->preference_id) {
@@ -660,14 +857,22 @@ function delete_dependency($dependency_id = 0, $confirm = "") {
$page_content .= "Dependency filename: <b>{$row->filename}</b><br><br>";
/* fetching the examples linked to this dependency */
- $query = "
+
+ /*$query = "
SELECT * FROM textbook_companion_example_dependency dep
LEFT JOIN textbook_companion_example exa ON exa.id = dep.example_id
WHERE dep.id = %d
";
- $result = db_query($query, $dependency_id);
+ $result = db_query($query, $dependency_id);*/
+
+ $query = db_select('textbook_companion_example_dependency', 'dep');
+ $query->fields('dep');
+ $query->leftJoin('textbook_companion_example', 'exa', 'exa.id = dep.example_id');
+ $query->condition('dep.id', $dependency_id);
+ $result = $query->execute();
+
$list = "";
- while($row = db_fetch_object($result)) {
+ while($row = $result->fetchObject()) {
$list .= "<li>Example {$row->number}</li>";
}
if($list) {
diff --git a/dependency_approval.inc b/dependency_approval.inc
index 4903141..c2d8ab7 100755
--- a/dependency_approval.inc
+++ b/dependency_approval.inc
@@ -113,21 +113,57 @@ function textbook_companion_dependency_approval_form_submit($form, &$form_state)
{
if ($form_state['values']['run']['delete_dependency'] == "1")
{
- $example_q = db_query("SELECT * FROM {textbook_companion_example_dependency} WHERE dependency_id = %d", $form_state['values']['run']['dependency']);
- if ($example_data = db_fetch_object($example_q)) {
-
- $example_id_q = db_query("SELECT * FROM {textbook_companion_example_dependency} WHERE dependency_id = %d", $form_state['values']['run']['dependency']);
- while ($example_id_data = db_fetch_object($example_id_q)) {
- $example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE id = %d", $example_id_data->example_id);
- $example_data = db_fetch_object($example_q);
- $chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE id = %d", $example_data->chapter_id);
- $chapter_data = db_fetch_object($chapter_q);
- $preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d", $chapter_data->preference_id);
- $preference_data = db_fetch_object($preference_q);
+ /*$example_q = db_query("SELECT * FROM {textbook_companion_example_dependency} WHERE dependency_id = %d", $form_state['values']['run']['dependency']);*/
+
+ $query = db_select('textbook_companion_example_dependency');
+ $query->fields('textbook_companion_example_dependency');
+ $query->condition('dependency_id', $form_state['values']['run']['dependency']);
+ $example_q = $query->execute();
+
+ if ($example_data = $example_q->fetchObject()) {
+
+ /*$example_id_q = db_query("SELECT * FROM {textbook_companion_example_dependency} WHERE dependency_id = %d", $form_state['values']['run']['dependency']);*/
+
+ $query = db_select('textbook_companion_example_dependency');
+ $query->fields('textbook_companion_example_dependency');
+ $query->condition('dependency_id', $form_state['values']['run']['dependency']);
+ $example_id_q = $query->execute();
+
+ while ($example_id_data = $example_id_q->fetchObject()) {
+
+ /*$example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE id = %d", $example_id_data->example_id);
+ $example_data = db_fetch_object($example_q);*/
+
+ $query = db_select('textbook_companion_example');
+ $query->fields('textbook_companion_example');
+ $query->condition('id', $example_id_data->example_id);
+ $result = $query->execute();
+ $example_data=$result->fetchObject();
+
+ /*$chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE id = %d", $example_data->chapter_id);
+ $chapter_data = db_fetch_object($chapter_q);*/
+
+ $query = db_select('textbook_companion_chapter');
+ $query->fields('textbook_companion_chapter');
+ $query->condition('id', $example_data->chapter_id);
+ $result = $query->execute();
+ $chapter_data =$result->fetchObject();
+
+
+ /*$preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d", $chapter_data->preference_id);
+ $preference_data = db_fetch_object($preference_q);*/
+
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('id', $chapter_data->preference_id);
+ $result = $query->execute();
+ $preference_data =$result->fetchObject();
+
+
$example_list[] = array($preference_data->book, $chapter_data->number, $example_data->number);
}
$example_list_header = array('Book', 'Chapter', 'Code');
- $example = theme_table($example_list_header, $example_list);
+ $example = theme('table',array('headers'=>$example_list_header, 'rows'=>$example_list));
drupal_set_message('Cannot delete dependency since it is linked with following examples. Delete these examples first before deleting the dependency file :' . $example, 'error');
@@ -154,8 +190,16 @@ function textbook_companion_dependency_approval_form_submit($form, &$form_state)
function _textbook_companion_list_of_dependencies()
{
$dependencies = array('0' => 'Please select...');
- $dependency_q = db_query("SELECT * FROM {textbook_companion_dependency_files} ORDER BY filename ASC");
- while ($dependency_data = db_fetch_object($dependency_q))
+
+ /*$dependency_q = db_query("SELECT * FROM {textbook_companion_dependency_files} ORDER BY filename ASC");*/
+
+ $query = db_select('textbook_companion_dependency_files');
+ $query->fields('textbook_companion_dependency_files');
+ $query->orderBy('filename', 'ASC');
+ $dependency_q = $query->execute();
+
+
+ while ($dependency_data =$dependency_q->fetchObject())
{
$dependencies[$dependency_data->id] = $dependency_data->filename . ' (' . $dependency_data->filepath . ')';
}
@@ -168,8 +212,15 @@ function textbook_companion_delete_dependency($dependency_id)
$root_path = textbook_companion_path();
$status = TRUE;
- $dependency_files_q = db_query("SELECT * FROM {textbook_companion_dependency_files} WHERE id = %d", $dependency_id);
- $dependency_files_data = db_fetch_object($dependency_files_q);
+ /*$dependency_files_q = db_query("SELECT * FROM {textbook_companion_dependency_files} WHERE id = %d", $dependency_id);
+ $dependency_files_data = db_fetch_object($dependency_files_q);*/
+
+ $query = db_select('textbook_companion_dependency_files');
+ $query->fields('textbook_companion_dependency_files');
+ $query->condition('id', $dependency_id);
+ $result = $query->execute();
+ $dependency_files_data=$result->fetchObject();
+
if (!$dependency_files_data)
{
drupal_set_message(t('Invalid dependency.'), 'error');
@@ -199,7 +250,13 @@ function textbook_companion_delete_dependency($dependency_id)
drupal_set_message('Error sending email message.', 'error');
} else {
/* deleting dependency files database entries */
- db_query("DELETE FROM {textbook_companion_dependency_files} WHERE id = %d", $dependency_id);
+
+ /*db_query("DELETE FROM {textbook_companion_dependency_files} WHERE id = %d", $dependency_id);*/
+
+ $query = db_delete('textbook_companion_dependency_files');
+ $query->condition('id', $dependency_id);
+ $num_deleted = $query->execute();
+
}
return $status;
}
diff --git a/download.inc b/download.inc
index 1f27c5b..f851273 100755
--- a/download.inc
+++ b/download.inc
@@ -6,8 +6,17 @@ function textbook_companion_download_example_file()
$example_file_id = arg(2);
$root_path = textbook_companion_path();
- $example_files_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE id = %d LIMIT 1", $example_file_id);
- $example_file_data = db_fetch_object($example_files_q);
+ /*$example_files_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE id = %d LIMIT 1", $example_file_id);
+ $example_file_data = db_fetch_object($example_files_q);*/
+
+ $query = db_select('textbook_companion_example_files');
+ $query->fields('textbook_companion_example_files');
+ $query->condition('id', $example_file_id);
+ $query->range(0, 1);
+ $result = $query->execute();
+
+ $example_file_data =$result->fetchObject();
+
header('Content-Type: ' . $example_file_data->filemime);
header('Content-disposition: attachment; filename="' . $example_file_data->filename . '"');
header('Content-Length: ' . filesize($root_path . $example_file_data->filepath));
@@ -19,8 +28,18 @@ function textbook_companion_download_dependency_file()
$dependency_file_id = arg(2);
$root_path = textbook_companion_path();
- $dependency_file_q = db_query("SELECT * FROM {textbook_companion_dependency_files} WHERE id = %d LIMIT 1", $dependency_file_id);
- $dependency_file_data = db_fetch_object($dependency_file_q);
+ /*$dependency_file_q = db_query("SELECT * FROM {textbook_companion_dependency_files} WHERE id = %d LIMIT 1", $dependency_file_id);
+ $dependency_file_data = db_fetch_object($dependency_file_q);*/
+
+ $query = db_select('textbook_companion_dependency_files');
+ $query->fields('textbook_companion_dependency_files');
+ $query->condition('id', $dependency_file_id);
+ $query->range(0, 1);
+ $result = $query->execute();
+
+ $dependency_file_data =$result->fetchObject();
+
+
header('Content-Type: ' . $dependency_file_data->filemime);
header('Content-disposition: attachment; filename="' . $dependency_file_data->filename . '"');
header('Content-Length: ' . filesize($root_path . $dependency_file_data->filepath));
@@ -35,12 +54,38 @@ function textbook_companion_download_example()
$root_path = textbook_companion_path();
/* get example data */
- $example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE id = %d", $example_id);
- $example_data = db_fetch_object($example_q);
- $chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE id = %d", $example_data->chapter_id);
- $chapter_data = db_fetch_object($chapter_q);
- $example_files_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE example_id = %d", $example_id);
- $example_dependency_files_q = db_query("SELECT * FROM {textbook_companion_example_dependency} WHERE example_id = %d", $example_id);
+
+ /*$example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE id = %d", $example_id);
+ $example_data = db_fetch_object($example_q);*/
+ $query = db_select('textbook_companion_example');
+ $query->fields('textbook_companion_example');
+ $query->condition('id', $example_id);
+ $result = $query->execute();
+ $example_data =$result->fetchObject();
+
+
+ /*$chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE id = %d", $example_data->chapter_id);
+ $chapter_data = db_fetch_object($chapter_q);*/
+ $query = db_select('textbook_companion_chapter');
+ $query->fields('textbook_companion_chapter');
+ $query->condition('id', $example_data->chapter_id);
+ $result = $query->execute();
+ $chapter_data =$result->fetchObject();
+
+
+ /*$example_files_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE example_id = %d", $example_id);*/
+ $query = db_select('textbook_companion_example_files');
+ $query->fields('textbook_companion_example_files');
+ $query->condition('example_id', $example_id);
+ $example_files_q = $query->execute();
+
+
+ /*$example_dependency_files_q = db_query("SELECT * FROM {textbook_companion_example_dependency} WHERE example_id = %d", $example_id);*/
+ $query = db_select('textbook_companion_example_dependency');
+ $query->fields('textbook_companion_example_dependency');
+ $query->condition('example_id', $example_id);
+ $example_dependency_files_q = $query->execute();
+
$EX_PATH = 'EX' . $example_data->number . '/';
@@ -48,17 +93,25 @@ function textbook_companion_download_example()
$zip_filename = $root_path . 'zip-' . time() . '-' . rand(0, 999999) . '.zip';
/* creating zip archive on the server */
- $zip = new ZipArchive;
+ $zip = new ZipArchive();
$zip->open($zip_filename, ZipArchive::CREATE);
- while ($example_files_row = db_fetch_object($example_files_q))
+ while ($example_files_row = $example_files_q->fetchObject())
{
$zip->addFile($root_path . $example_files_row->filepath, $EX_PATH . $example_files_row->filename);
}
/* dependency files */
- while ($example_dependency_files_row = db_fetch_object($example_dependency_files_q))
+ while ($example_dependency_files_row = $example_dependency_files_q->fetchObject())
{
- $dependency_file_data = db_fetch_object(db_query("SELECT * FROM {textbook_companion_dependency_files} WHERE id = %d LIMIT 1", $example_dependency_files_row->dependency_id));
+ /*$dependency_file_data = db_fetch_object(db_query("SELECT * FROM {textbook_companion_dependency_files} WHERE id = %d LIMIT 1", $example_dependency_files_row->dependency_id));*/
+
+ $query = db_select('textbook_companion_dependency_files');
+ $query->fields('textbook_companion_dependency_files');
+ $query->condition('id', $example_dependency_files_row->dependency_id);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $dependency_file_data=$result->fetchObject();
+
if ($dependency_file_data)
$zip->addFile($root_path . $dependency_file_data->filepath, $EX_PATH . 'DEPENDENCIES/' . $dependency_file_data->filename);
}
@@ -85,31 +138,68 @@ function textbook_companion_download_chapter()
$root_path = textbook_companion_path();
/* get example data */
- $chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE id = %d", $chapter_id);
- $chapter_data = db_fetch_object($chapter_q);
+
+ /*$chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE id = %d", $chapter_id);
+ $chapter_data = db_fetch_object($chapter_q);*/
+
+ $query = db_select('textbook_companion_chapter');
+ $query->fields('textbook_companion_chapter');
+ $query->condition('id', $chapter_id);
+ $result = $query->execute();
+ $chapter_data =$result->fetchObject();
+
+
$CH_PATH = 'CH' . $chapter_data->number . '/';
/* zip filename */
$zip_filename = $root_path . 'zip-' . time() . '-' . rand(0, 999999) . '.zip';
/* creating zip archive on the server */
- $zip = new ZipArchive;
+ $zip = new ZipArchive();
$zip->open($zip_filename, ZipArchive::CREATE);
- $example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d AND approval_status = 1", $chapter_id);
- while ($example_row = db_fetch_object($example_q))
+ /*$example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d AND approval_status = 1", $chapter_id);*/
+
+ $query = db_select('textbook_companion_example');
+ $query->fields('textbook_companion_example');
+ $query->condition('chapter_id', $chapter_id);
+ $query->condition('approval_status', 1);
+ $example_q = $query->execute();
+
+ while ($example_row = $example_q->fetchObject())
{
$EX_PATH = 'EX' . $example_row->number . '/';
- $example_files_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE example_id = %d", $example_row->id);
- $example_dependency_files_q = db_query("SELECT * FROM {textbook_companion_example_dependency} WHERE example_id = %d", $example_row->id);
- while ($example_files_row = db_fetch_object($example_files_q))
+
+ /*$example_files_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE example_id = %d", $example_row->id);*/
+
+ $query = db_select('textbook_companion_example_files');
+ $query->fields('textbook_companion_example_files');
+ $query->condition('example_id', $example_row->id);
+ $example_files_q = $query->execute();
+
+ /*$example_dependency_files_q = db_query("SELECT * FROM {textbook_companion_example_dependency} WHERE example_id = %d", $example_row->id);*/
+
+ $query = db_select('textbook_companion_example_dependency');
+ $query->fields('textbook_companion_example_dependency');
+ $query->condition('example_id', $example_row->id);
+ $example_dependency_files_q = $query->execute();
+
+ while ($example_files_row = $example_files_q->fetchObject())
{
$zip->addFile($root_path . $example_files_row->filepath, $CH_PATH . $EX_PATH . $example_files_row->filename);
}
/* dependency files */
- while ($example_dependency_files_row = db_fetch_object($example_dependency_files_q))
+ while ($example_dependency_files_row = $example_dependency_files_q->fetchObject())
{
- $dependency_file_data = db_fetch_object(db_query("SELECT * FROM {textbook_companion_dependency_files} WHERE id = %d LIMIT 1", $example_dependency_files_row->dependency_id));
+ /*$dependency_file_data = db_fetch_object(db_query("SELECT * FROM {textbook_companion_dependency_files} WHERE id = %d LIMIT 1", $example_dependency_files_row->dependency_id));*/
+
+ $query = db_select('textbook_companion_dependency_files');
+ $query->fields('textbook_companion_dependency_files');
+ $query->condition('id', $example_dependency_files_row->dependency_id);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $dependency_file_data=$result->fetchObject();
+
if ($dependency_file_data)
$zip->addFile($root_path . $dependency_file_data->filepath, $CH_PATH . $EX_PATH . 'DEPENDENCIES/' . $dependency_file_data->filename);
}
@@ -136,49 +226,48 @@ function textbook_companion_download_book()
$book_id = arg(2);
$root_path = textbook_companion_path();
/* get example data */
- $book_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d", $book_id);
- $book_data = db_fetch_object($book_q);
+ $book_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = :book_id", array(':book_id' => $book_id));
+ $book_data = $book_q->fetchObject();
$zipname = str_replace(' ','_',($book_data->book));
$BK_PATH = $zipname . '/';
-
/* zip filename */
$zip_filename = $root_path . 'zip-' . time() . '-' . rand(0, 999999) . '.zip';
-
+
/* creating zip archive on the server */
$zip = new ZipArchive;
$zip->open($zip_filename, ZipArchive::CREATE);
-
- $chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE preference_id = %d", $book_id);
- while ($chapter_row = db_fetch_object($chapter_q))
+ $chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE preference_id = :book_id",array(':book_id' => $book_id));
+ while ($chapter_row = $chapter_q->fetchObject())
{
$CH_PATH = 'CH' . $chapter_row->number . '/';
- $example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d AND approval_status = 1", $chapter_row->id);
- while ($example_row = db_fetch_object($example_q))
+ $example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE chapter_id = :chapter_id AND approval_status = 1",array(':chapter_id' => $chapter_row->id));
+ while ($example_row = $example_q->fetchObject())
{
$EX_PATH = 'EX' . $example_row->number . '/';
- $example_files_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE example_id = %d", $example_row->id);
- $example_dependency_files_q = db_query("SELECT * FROM {textbook_companion_example_dependency} WHERE example_id = %d", $example_row->id);
- while ($example_files_row = db_fetch_object($example_files_q))
- {
+ $example_files_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE example_id = :id",array(':id' => $example_row->id));
+ $example_dependency_files_q = db_query("SELECT * FROM {textbook_companion_example_dependency} WHERE example_id = :id",array(':id'=> $example_row->id));
+ while ($example_files_row =$example_files_q->fetchObject())
+ {
$zip->addFile($root_path . $example_files_row->filepath, $BK_PATH . $CH_PATH . $EX_PATH . $example_files_row->filename);
}
/* dependency files */
- while ($example_dependency_files_row = db_fetch_object($example_dependency_files_q))
- {
- $dependency_file_data = db_fetch_object(db_query("SELECT * FROM {textbook_companion_dependency_files} WHERE id = %d LIMIT 1", $example_dependency_files_row->dependency_id));
- if ($dependency_file_data)
- $zip->addFile($root_path . $dependency_file_data->filepath, $BK_PATH . $CH_PATH . $EX_PATH . 'DEPENDENCIES/' . $dependency_file_data->filename);
+ while ($example_dependency_files_row = $example_dependency_files_q->fetchObject())
+ {
+ $query = db_query("SELECT * FROM {textbook_companion_dependency_files} WHERE id = :id LIMIT 1",array(':id' => $example_dependency_files_row->dependency_id));
+ $dependency_file_data = $query->fetchObject();
+ if ($dependency_file_data)
+$zip->addFile($root_path . $dependency_file_data->filepath, $BK_PATH . $CH_PATH . $EX_PATH . 'DEPENDENCIES/' . $dependency_file_data->filename);
}
- $query = "SELECT * FROM textbook_companion_dependency_files WHERE preference_id = %d";
- $result = db_query($query, $book_id);
- while($row = db_fetch_object($result)) {
+ $query = "SELECT * FROM textbook_companion_dependency_files WHERE preference_id = :preference_id";
+ $args = array(':preference_id' => $book_id);
+ $result = db_query($query,$args);
+ while($row = $result->fetchObject()) {
$zip->addFile($root_path . $row->filepath, $BK_PATH . 'DEPENDENCIES/' . $row->filename);
}
}
}
$zip_file_count = $zip->numFiles;
$zip->close();
-
if ($zip_file_count > 0)
{
/* download zip file */
@@ -187,7 +276,7 @@ function textbook_companion_download_book()
header('Content-Type: application/zip');
header('Content-disposition: attachment; filename="' . str_replace(' ','_',($book_data->book)) . '.zip"');
header('Content-Length: ' . filesize($zip_filename));
- ob_clean();
+ ob_clean();
readfile($zip_filename);
unlink($zip_filename);
}else{
@@ -208,4 +297,4 @@ function textbook_companion_download_book()
drupal_goto('textbook_run');
}
}
-
+
diff --git a/editcode.inc b/editcode.inc
index 39d751e..f1b35d5 100755
--- a/editcode.inc
+++ b/editcode.inc
@@ -5,14 +5,23 @@
/***************************** EDIT EXAMPLE ***********************************/
/******************************************************************************/
-function upload_examples_edit_form($form_state)
+function upload_examples_edit_form($form,$form_state)
{
global $user;
$example_id = arg(3);
/* get example details */
- $example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE id = %d LIMIT 1", $example_id);
- $example_data = db_fetch_object($example_q);
+
+ /*$example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE id = %d LIMIT 1", $example_id);
+ $example_data = db_fetch_object($example_q);*/
+
+ $query = db_select('textbook_companion_example');
+ $query->fields('textbook_companion_example');
+ $query->condition('id', $example_id);
+ $query->range(0, 1);
+ $example_q = $query->execute();
+ $example_data=$example_q->fetchObject();
+
if (!$example_q)
{
drupal_set_message(t("Invalid example selected."), 'error');
@@ -33,8 +42,13 @@ function upload_examples_edit_form($form_state)
$xcos1_file = ""; $xcos1_id = 0;
$xcos2_file = ""; $xcos2_id = 0;
- $example_files_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE example_id = %d", $example_id);
- while ($example_files_data = db_fetch_object($example_files_q))
+ /*$example_files_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE example_id = %d", $example_id);*/
+ $query = db_select('textbook_companion_example_files');
+ $query->fields('textbook_companion_example_files');
+ $query->condition('example_id', $example_id);
+ $example_files_q = $query->execute();
+
+ while ($example_files_data = $example_files_q->fetchObject())
{
if ($example_files_data->filetype == "S")
{
@@ -66,8 +80,15 @@ function upload_examples_edit_form($form_state)
}
/* get chapter details */
- $chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE id = %d", $example_data->chapter_id);
- $chapter_data = db_fetch_object($chapter_q);
+
+ /*$chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE id = %d", $example_data->chapter_id);
+ $chapter_data = db_fetch_object($chapter_q);*/
+ $query = db_select('textbook_companion_chapter');
+ $query->fields('textbook_companion_chapter');
+ $query->condition('id', $example_data->chapter_id);
+ $result = $query->execute();
+ $chapter_data=$result->fetchObject();
+
if (!$chapter_data)
{
drupal_set_message(t("Invalid chapter selected."), 'error');
@@ -76,8 +97,16 @@ function upload_examples_edit_form($form_state)
}
/* get preference details */
- $preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d", $chapter_data->preference_id);
- $preference_data = db_fetch_object($preference_q);
+
+ /*$preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d", $chapter_data->preference_id);
+ $preference_data = db_fetch_object($preference_q);*/
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('id', $chapter_data->preference_id);
+ $result = $query->execute();
+ $preference_data =$result->fetchObject();
+
+
if (!$preference_data)
{
drupal_set_message(t("Invalid book selected."), 'error');
@@ -92,8 +121,15 @@ function upload_examples_edit_form($form_state)
}
/* get proposal details */
- $proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d", $preference_data->proposal_id);
- $proposal_data = db_fetch_object($proposal_q);
+
+ /*$proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d", $preference_data->proposal_id);
+ $proposal_data = db_fetch_object($proposal_q);*/
+ $query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal');
+ $query->condition('id', $preference_data->proposal_id);
+ $result = $query->execute();
+ $proposal_data = $result->fetchObject();
+
if (!$proposal_data)
{
drupal_set_message(t("Invalid proposal selected."), 'error');
@@ -110,11 +146,12 @@ function upload_examples_edit_form($form_state)
$user_data = user_load($proposal_data->uid);
/* add javascript for automatic book title, check if example uploaded, dependency selection effects */
- $chapter_name_js = " $(document).ready(function() {
+ $chapter_name_js = " (function ($) {
+ $(document).ready(function() {
$('#edit-existing-depfile-dep-book-title').change(function() {
var dep_selected = '';
/* showing and hiding relevant files */
- $('.form-checkboxes .option').hide();
+ $('.form-checkboxes .option').hide();
$('.form-checkboxes .option').each(function(index) {
var activeClass = $('#edit-existing-depfile-dep-book-title').val();
if ($(this).children().hasClass(activeClass)) {
@@ -125,14 +162,15 @@ function upload_examples_edit_form($form_state)
}
});
/* showing list of already existing dependencies */
- $('#existing_depfile_selected').html(dep_selected);
+ $('#existing_depfile_selected').html(dep_selected);
});
$('.form-checkboxes .option').change(function() {
$('#edit-existing-depfile-dep-book-title').trigger('change');
});
$('#edit-existing-depfile-dep-book-title').trigger('change');
- });";
+ });
+})(jQuery);";
drupal_add_js($chapter_name_js, 'inline', 'header');
$form['#redirect'] = 'textbook_companion/code';
@@ -140,28 +178,28 @@ function upload_examples_edit_form($form_state)
$form['book_details']['book'] = array(
'#type' => 'item',
- '#value' => $preference_data->book,
+ '#markup' => $preference_data->book,
'#title' => t('Title of the Book'),
);
$form['contributor_name'] = array(
'#type' => 'item',
- '#value' => $proposal_data->full_name,
+ '#markup' => $proposal_data->full_name,
'#title' => t('Contributor Name'),
);
$form['number'] = array(
'#type' => 'item',
'#title' => t('Chapter No'),
- '#value' => $chapter_data->number,
+ '#markup' => $chapter_data->number,
);
$form['name'] = array(
'#type' => 'item',
'#title' => t('Title of the Chapter'),
- '#value' => $chapter_data->name,
+ '#markup' => $chapter_data->name,
);
$form['example_number'] = array(
'#type' => 'item',
'#title' => t('Example No'),
- '#value' => $example_data->number,
+ '#markup' => $example_data->number,
);
$form['example_caption'] = array(
'#type' => 'textfield',
@@ -189,7 +227,7 @@ function upload_examples_edit_form($form_state)
$form['sourcefile']['cur_source'] = array(
'#type' => 'item',
'#title' => t('Existing Main or Source File'),
- '#value' => $source_file,
+ '#markup' => $source_file,
);
$form['sourcefile']['cur_source_checkbox'] = array(
'#type' => 'checkbox',
@@ -224,8 +262,15 @@ function upload_examples_edit_form($form_state)
/************ START OF EXISTING DEPENDENCIES **************/
$dependency_files = array();
- $dependency_q = db_query("SELECT * FROM {textbook_companion_example_dependency} WHERE example_id = %d", $example_data->id);
- while ($dependency_data = db_fetch_object($dependency_q))
+
+ /*$dependency_q = db_query("SELECT * FROM {textbook_companion_example_dependency} WHERE example_id = %d", $example_data->id);*/
+
+ $query = db_select('textbook_companion_example_dependency');
+ $query->fields('textbook_companion_example_dependency');
+ $query->condition('example_id', $example_data->id);
+ $dependency_q = $query->execute();
+
+ while ($dependency_data = $dependency_q->fetchObject())
{
$dependency_files[] = $dependency_data->dependency_id;
}
@@ -242,10 +287,10 @@ function upload_examples_edit_form($form_state)
);
/* existing dependencies */
- $form['existing_depfile']['selected'] = array(
+ /*$form['existing_depfile']['selected'] = array(
'#type' => 'item',
'#title' => t('Existing Dependency Files Selected'),
- '#value' => '<div id="existing_depfile_selected"></div>',
+ '#markup' => '<div id="existing_depfile_selected"></div>',
);
$form['existing_depfile']['dep_book_title'] = array(
@@ -262,11 +307,44 @@ function upload_examples_edit_form($form_state)
'#options_class' => $files_options_class,
'#multiple' => TRUE,
'#default_value' => $dependency_files,
+ );*/
+
+ /* existing dependencies */
+ $form['existing_depfile']['selected'] = array(
+ '#type' => 'item',
+ '#title' => t('Existing Dependency Files Selected'),
+ '#markup' => '<div id="existing_depfile_selected"></div>',
);
- $form['existing_depfile']['dep_upload'] = array(
- '#type' => 'item',
- '#value' => l('Upload New Depedency Files', 'textbook_companion/code/upload_dep'),
+ /* $form['existing_depfile']['dep_book_title'] = array(
+ '#type' => 'select',
+ '#title' => t('Title of the Book'),
+ '#options' => _list_of_book_titles(),
+ );*/
+
+
+
+ $form['existing_depfile']['dep_book'] = array(
+ '#type' => 'item',
+ '#title' => t('Dependency Files'),
+
+ );
+
+ list($files_options, $files_options_class) = _list_of_book_dependency_files();
+ $form['existing_depfile']['dep_chapter_example_files'] = array(
+ '#type' => 'checkboxes',
+ //'#title' => t('Dependency Files'),
+ '#options' => $files_options,
+ '#options_class' => $files_options_class,
+ '#prefix' => '<div id="ckb" style="height:500px;overflow:auto;">',
+ '#suffix' =>'</div>',
+ '#multiple' => TRUE,
+ );
+
+
+ $form['existing_depfile']['dep_upload'] = array(
+ '#type' => 'item',
+ '#markup' => '<hr style="color:red">'. l('Upload New Depedency Files', 'textbook_companion/code/upload_dep'),
);
/************ END OF EXISTING DEPENDENCIES **************/
@@ -281,7 +359,7 @@ function upload_examples_edit_form($form_state)
$form['result']['cur_result1'] = array(
'#type' => 'item',
'#title' => t('Existing Result File 1'),
- '#value' => $result1_file,
+ '#markup' => $result1_file,
);
$form['result']['cur_result1_checkbox'] = array(
'#type' => 'checkbox',
@@ -310,7 +388,7 @@ function upload_examples_edit_form($form_state)
$form['result']['br'] = array(
'#type' => 'item',
- '#value' => "<br />",
+ '#markup' => "<br />",
);
if ($result2_file)
@@ -318,7 +396,7 @@ function upload_examples_edit_form($form_state)
$form['result']['cur_result2'] = array(
'#type' => 'item',
'#title' => t('Existing Result File 2'),
- '#value' => $result2_file,
+ '#markup' => $result2_file,
);
$form['result']['cur_result2_checkbox'] = array(
'#type' => 'checkbox',
@@ -355,7 +433,7 @@ function upload_examples_edit_form($form_state)
$form['xcos']['cur_xcos1'] = array(
'#type' => 'item',
'#title' => t('Existing xcos File 1'),
- '#value' => $xcos1_file,
+ '#markup' => $xcos1_file,
);
$form['xcos']['cur_xcos1_checkbox'] = array(
'#type' => 'checkbox',
@@ -384,7 +462,7 @@ function upload_examples_edit_form($form_state)
$form['xcos']['br'] = array(
'#type' => 'item',
- '#value' => "<br />",
+ '#markup' => "<br />",
);
if ($xcos2_file)
@@ -392,7 +470,7 @@ function upload_examples_edit_form($form_state)
$form['xcos']['cur_xcos2'] = array(
'#type' => 'item',
'#title' => t('Existing xcos File 2'),
- '#value' => $xcos2_file,
+ '#markup' => $xcos2_file,
);
$form['xcos']['cur_xcos2_checkbox'] = array(
'#type' => 'checkbox',
@@ -526,8 +604,17 @@ function upload_examples_edit_form_submit($form, &$form_state)
$example_id = arg(3);
/* get example details */
- $example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE id = %d LIMIT 1", $example_id);
- $example_data = db_fetch_object($example_q);
+
+ /*$example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE id = %d LIMIT 1", $example_id);
+ $example_data = db_fetch_object($example_q);*/
+
+ $query = db_select('textbook_companion_example');
+ $query->fields('textbook_companion_example');
+ $query->condition('id', $example_id);
+ $query->range(0, 1);
+ $example_q = $query->execute();
+ $example_data = $example_q->fetchObject();
+
if (!$example_q)
{
drupal_set_message(t("Invalid example selected."), 'error');
@@ -542,8 +629,16 @@ function upload_examples_edit_form_submit($form, &$form_state)
}
/* get chapter details */
- $chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE id = %d", $example_data->chapter_id);
- $chapter_data = db_fetch_object($chapter_q);
+
+ /*$chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE id = %d", $example_data->chapter_id);
+ $chapter_data = db_fetch_object($chapter_q);*/
+
+ $query = db_select('textbook_companion_chapter');
+ $query->fields('textbook_companion_chapter');
+ $query->condition('id', $example_data->chapter_id);
+ $result = $query->execute();
+ $chapter_data=$result->fetchObject();
+
if (!$chapter_data)
{
drupal_set_message(t("Invalid chapter selected."), 'error');
@@ -552,8 +647,15 @@ function upload_examples_edit_form_submit($form, &$form_state)
}
/* get preference details */
- $preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d", $chapter_data->preference_id);
- $preference_data = db_fetch_object($preference_q);
+
+ /*$preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d", $chapter_data->preference_id);
+ $preference_data = db_fetch_object($preference_q);*/
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('id', $chapter_data->preference_id);
+ $result = $query->execute();
+ $preference_data =$result->fetchObject();
+
if (!$preference_data)
{
drupal_set_message(t("Invalid book selected."), 'error');
@@ -568,8 +670,16 @@ function upload_examples_edit_form_submit($form, &$form_state)
}
/* get proposal details */
- $proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d", $preference_data->proposal_id);
- $proposal_data = db_fetch_object($proposal_q);
+
+ /*$proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d", $preference_data->proposal_id);
+ $proposal_data = db_fetch_object($proposal_q);*/
+
+ $query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal');
+ $query->condition('id', $preference_data->proposal_id);
+ $result = $query->execute();
+ $proposal_data =$result->fetchObject();
+
if (!$proposal_data)
{
drupal_set_message(t("Invalid proposal selected."), 'error');
@@ -599,22 +709,45 @@ function upload_examples_edit_form_submit($form, &$form_state)
mkdir($root_path . $dest_path);
/* updating example caption */
- db_query("UPDATE {textbook_companion_example} SET caption = '%s' WHERE id = %d", $form_state['values']['example_caption'], $example_id);
+
+ /*db_query("UPDATE {textbook_companion_example} SET caption = '%s' WHERE id = %d", $form_state['values']['example_caption'], $example_id);*/
+
+ $query = db_update('textbook_companion_example');
+ $query->fields(array(
+ 'caption' => $form_state['values']['example_caption'],
+ ));
+ $query->condition('id', $example_id);
+ $num_updated = $query->execute();
/* handling dependencies */
- db_query("DELETE FROM {textbook_companion_example_dependency} WHERE example_id = %d", $example_data->id);
+
+ /*db_query("DELETE FROM {textbook_companion_example_dependency} WHERE example_id = %d", $example_data->id);*/
+
+ $query = db_delete('textbook_companion_example_dependency');
+ $query->condition('example_id', $example_data->id);
+ $num_deleted = $query->execute();
+
foreach ($form_state['values']['existing_depfile']['dep_chapter_example_files'] as $row)
{
if ($row > 0)
{
/* insterting into database */
- db_query("INSERT INTO {textbook_companion_example_dependency} (example_id, dependency_id, approval_status, timestamp)
+ /*db_query("INSERT INTO {textbook_companion_example_dependency} (example_id, dependency_id, approval_status, timestamp)
VALUES (%d, %d, %d, %d)",
$example_data->id,
$row,
0,
time()
- );
+ );*/
+ $query = "INSERT INTO {textbook_companion_example_dependency} (example_id, dependency_id, approval_status, timestamp)
+ VALUES (:example_id, :dependency_id, :approval_status, :timestamp)";
+ $args = array(
+ ":example_id"=> $example_data->id,
+ ":dependency_id"=> $row,
+ ":approval_status"=> 0,
+ ":timestamp"=> time(),
+ );
+ $result = db_query($query, $args, array('return' => Database::RETURN_INSERT_ID));
}
}
@@ -622,8 +755,15 @@ function upload_examples_edit_form_submit($form, &$form_state)
$cur_file_id = $form_state['values']['cur_source_file_id'];
if ($cur_file_id > 0)
{
- $file_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE id = %d AND example_id = %d", $cur_file_id, $example_data->id);
- $file_data = db_fetch_object($file_q);
+ /*$file_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE id = %d AND example_id = %d", $cur_file_id, $example_data->id);
+ $file_data = db_fetch_object($file_q);*/
+ $query = db_select('textbook_companion_example_files');
+ $query->fields('textbook_companion_example_files');
+ $query->condition('id', $cur_file_id);
+ $query->condition('example_id', $example_data->id);
+ $result = $query->execute();
+ $file_data =$result->fetchObject();
+
if (!$file_data)
{
drupal_set_message("Error deleting example source file. File not present in database.", 'error');
@@ -657,7 +797,8 @@ function upload_examples_edit_form_submit($form, &$form_state)
if (move_uploaded_file($_FILES['files']['tmp_name']['sourcefile1'], $root_path . $dest_path . $_FILES['files']['name']['sourcefile1']))
{
/* for uploaded files making an entry in the database */
- db_query("INSERT INTO {textbook_companion_example_files} (example_id, filename, filepath, filemime, filesize, filetype, timestamp)
+
+ /*db_query("INSERT INTO {textbook_companion_example_files} (example_id, filename, filepath, filemime, filesize, filetype, timestamp)
VALUES (%d, '%s', '%s', '%s', %d, '%s', %d)",
$example_data->id,
$_FILES['files']['name']['sourcefile1'],
@@ -666,7 +807,29 @@ function upload_examples_edit_form_submit($form, &$form_state)
$_FILES['files']['size']['sourcefile1'],
'S',
time()
- );
+ );*/
+var_dump('ok');
+
+ $query = "INSERT INTO {textbook_companion_example_files} (example_id, filename, filepath, filemime, filesize, filetype, timestamp)
+ VALUES (:example_id, :filename, :filepath, :filemime, :filesize, :filetype,:timestamp)";
+ $args = array(
+ ":example_id"=> $example_data->id,
+ ":filename"=> $_FILES['files']['name']['sourcefile1'],
+ ":filepath"=> $dest_path . $_FILES['files']['name']['sourcefile1'],
+ ":filemime"=> $_FILES['files']['type']['sourcefile1'],
+ ":filesize"=> $_FILES['files']['size']['sourcefile1'],
+ ":filetype"=> 'S',
+ ":timestamp"=> time(),
+ );
+/*var_dump( ":example_id=>". $example_data->id .",". ":filename=>". $_FILES['files']['name']['sourcefile1'] .",".
+ ":filepath=>". $dest_path . $_FILES['files']['name']['sourcefile1'].",".
+ ":filemime=>". $_FILES['files']['type']['sourcefile1'].",".
+ ":filesize=>" .$_FILES['files']['size']['sourcefile1']
+ );die;
+*/
+ $result = db_query($query, $args, array('return' => Database::RETURN_INSERT_ID));
+
+
drupal_set_message($_FILES['files']['name']['sourcefile1'] . ' uploaded successfully.', 'status');
} else {
drupal_set_message('Error uploading file : ' . $dest_path . '/' . $_FILES['files']['name']['sourcefile1'], 'error');
@@ -677,8 +840,15 @@ function upload_examples_edit_form_submit($form, &$form_state)
$cur_file_id = $form_state['values']['cur_result1_file_id'];
if ($cur_file_id > 0)
{
- $file_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE id = %d AND example_id = %d", $cur_file_id, $example_data->id);
- $file_data = db_fetch_object($file_q);
+ /*$file_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE id = %d AND example_id = %d", $cur_file_id, $example_data->id);
+ $file_data = db_fetch_object($file_q);*/
+ $query = db_select('textbook_companion_example_files');
+ $query->fields('textbook_companion_example_files');
+ $query->condition('id',$cur_file_id);
+ $query->condition('example_id', $example_data->id);
+ $result = $query->execute();
+ $file_data =$result->fetchObject();
+
if (!$file_data)
{
drupal_set_message("Error deleting example result 1 file. File not present in database.", 'error');
@@ -712,7 +882,8 @@ function upload_examples_edit_form_submit($form, &$form_state)
if (move_uploaded_file($_FILES['files']['tmp_name']['result1'], $root_path . $dest_path . $_FILES['files']['name']['result1']))
{
/* for uploaded files making an entry in the database */
- db_query("INSERT INTO {textbook_companion_example_files} (example_id, filename, filepath, filemime, filesize, filetype, timestamp)
+
+ /*db_query("INSERT INTO {textbook_companion_example_files} (example_id, filename, filepath, filemime, filesize, filetype, timestamp)
VALUES (%d, '%s', '%s', '%s', %d, '%s', %d)",
$example_data->id,
$_FILES['files']['name']['result1'],
@@ -721,7 +892,20 @@ function upload_examples_edit_form_submit($form, &$form_state)
$_FILES['files']['size']['result1'],
'R',
time()
- );
+ );*/
+
+ $query = "INSERT INTO {textbook_companion_example_files} (example_id, filename, filepath, filemime, filesize, filetype, timestamp) VALUES (:example_id, :filename, :filepath, :filemime, :filesize, :filetype,:timestamp)";
+ $args = array(
+ ":example_id"=> $example_data->id,
+ ":filename"=> $_FILES['files']['name']['result1'],
+ ":filepath"=> $dest_path . $_FILES['files']['name']['result1'],
+ ":filemime"=> $_FILES['files']['type']['result1'],
+ ":filesize"=> $_FILES['files']['size']['result1'],
+ ":filetype"=> 'R',
+ ":timestamp"=> time(),
+ );
+ $result = db_query($query, $args, array('return' => Database::RETURN_INSERT_ID));
+
drupal_set_message($_FILES['files']['name']['result1'] . ' uploaded successfully.', 'status');
} else {
drupal_set_message('Error uploading file : ' . $dest_path . '/' . $_FILES['files']['name']['result1'], 'error');
@@ -732,8 +916,16 @@ function upload_examples_edit_form_submit($form, &$form_state)
$cur_file_id = $form_state['values']['cur_result2_file_id'];
if ($cur_file_id > 0)
{
- $file_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE id = %d AND example_id = %d", $cur_file_id, $example_data->id);
- $file_data = db_fetch_object($file_q);
+ /*$file_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE id = %d AND example_id = %d", $cur_file_id, $example_data->id);
+ $file_data = db_fetch_object($file_q);*/
+
+ $query = db_select('textbook_companion_example_files');
+ $query->fields('textbook_companion_example_files');
+ $query->condition('id', $cur_file_id);
+ $query->condition('example_id', $example_data->id);
+ $result = $query->execute();
+ $file_data =$result->fetchObject();
+
if (!$file_data)
{
drupal_set_message("Error deleting example result 2 file. File not present in database.", 'error');
@@ -767,7 +959,7 @@ function upload_examples_edit_form_submit($form, &$form_state)
if (move_uploaded_file($_FILES['files']['tmp_name']['result2'], $root_path . $dest_path . $_FILES['files']['name']['result2']))
{
/* for uploaded files making an entry in the database */
- db_query("INSERT INTO {textbook_companion_example_files} (example_id, filename, filepath, filemime, filesize, filetype, timestamp)
+ /*db_query("INSERT INTO {textbook_companion_example_files} (example_id, filename, filepath, filemime, filesize, filetype, timestamp)
VALUES (%d, '%s', '%s', '%s', %d, '%s', %d)",
$example_data->id,
$_FILES['files']['name']['result2'],
@@ -776,7 +968,20 @@ function upload_examples_edit_form_submit($form, &$form_state)
$_FILES['files']['size']['result2'],
'R',
time()
- );
+ );*/
+
+ $query = "INSERT INTO {textbook_companion_example_files} (example_id, filename, filepath, filemime, filesize, filetype, timestamp) VALUES (:example_id, :filename, :filepath, :filemime, :filesize, :filetype,:timestamp)";
+ $args = array(
+ ":example_id"=> $example_data->id,
+ ":filename"=> $_FILES['files']['name']['result2'],
+ ":filepath"=> $dest_path . $_FILES['files']['name']['result2'],
+ ":filemime"=> $_FILES['files']['type']['result2'],
+ ":filesize"=> $_FILES['files']['size']['result2'],
+ ":filetype"=> 'R',
+ ":timestamp"=> time(),
+ );
+ $result = db_query($query, $args, array('return' => Database::RETURN_INSERT_ID));
+
drupal_set_message($_FILES['files']['name']['result2'] . ' uploaded successfully.', 'status');
} else {
drupal_set_message('Error uploading file : ' . $dest_path . '/' . $_FILES['files']['name']['result2'], 'error');
@@ -787,8 +992,17 @@ function upload_examples_edit_form_submit($form, &$form_state)
$cur_file_id = $form_state['values']['cur_xcos1_file_id'];
if ($cur_file_id > 0)
{
- $file_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE id = %d AND example_id = %d", $cur_file_id, $example_data->id);
- $file_data = db_fetch_object($file_q);
+ /*$file_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE id = %d AND example_id = %d", $cur_file_id, $example_data->id);
+ $file_data = db_fetch_object($file_q);*/
+
+ $query = db_select('textbook_companion_example_files');
+ $query->fields('textbook_companion_example_files');
+ $query->condition('id', $cur_file_id);
+ $query->condition('example_id', $example_data->id);
+ $result = $query->execute();
+ $file_data =$result->fetchObject();
+
+
if (!$file_data)
{
drupal_set_message("Error deleting example xcos 1 file. File not present in database.", 'error');
@@ -822,7 +1036,8 @@ function upload_examples_edit_form_submit($form, &$form_state)
if (move_uploaded_file($_FILES['files']['tmp_name']['xcos1'], $root_path . $dest_path . $_FILES['files']['name']['xcos1']))
{
/* for uploaded files making an entry in the database */
- db_query("INSERT INTO {textbook_companion_example_files} (example_id, filename, filepath, filemime, filesize, filetype, timestamp)
+
+ /*db_query("INSERT INTO {textbook_companion_example_files} (example_id, filename, filepath, filemime, filesize, filetype, timestamp)
VALUES (%d, '%s', '%s', '%s', %d, '%s', %d)",
$example_data->id,
$_FILES['files']['name']['xcos1'],
@@ -831,7 +1046,20 @@ function upload_examples_edit_form_submit($form, &$form_state)
$_FILES['files']['size']['xcos1'],
'X',
time()
- );
+ );*/
+
+ $query = "INSERT INTO {textbook_companion_example_files} (example_id, filename, filepath, filemime, filesize, filetype, timestamp) VALUES (:example_id, :filename, :filepath, :filemime, :filesize, :filetype,:timestamp)";
+ $args = array(
+ ":example_id"=> $example_data->id,
+ ":filename"=> $_FILES['files']['name']['xcos1'],
+ ":filepath"=> $dest_path . $_FILES['files']['name']['xcos1'],
+ ":filemime"=> $_FILES['files']['type']['xcos1'],
+ ":filesize"=> $_FILES['files']['size']['xcos1'],
+ ":filetype"=>'X',
+ ":timestamp"=> time(),
+ );
+ $result = db_query($query, $args, array('return' => Database::RETURN_INSERT_ID));
+
drupal_set_message($_FILES['files']['name']['xcos1'] . ' uploaded successfully.', 'status');
} else {
drupal_set_message('Error uploading file : ' . $dest_path . '/' . $_FILES['files']['name']['xcos1'], 'error');
@@ -842,8 +1070,16 @@ function upload_examples_edit_form_submit($form, &$form_state)
$cur_file_id = $form_state['values']['cur_xcos2_file_id'];
if ($cur_file_id > 0)
{
- $file_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE id = %d AND example_id = %d", $cur_file_id, $example_data->id);
- $file_data = db_fetch_object($file_q);
+ /*$file_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE id = %d AND example_id = %d", $cur_file_id, $example_data->id);
+ $file_data = db_fetch_object($file_q);*/
+
+ $query = db_select('textbook_companion_example_files');
+ $query->fields('textbook_companion_example_files');
+ $query->condition('id', $cur_file_id);
+ $query->condition('example_id', $example_data->id);
+ $result = $query->execute();
+ $file_data =$result->fetchObject();
+
if (!$file_data)
{
drupal_set_message("Error deleting example xcos 2 file. File not present in database.", 'error');
@@ -877,7 +1113,7 @@ function upload_examples_edit_form_submit($form, &$form_state)
if (move_uploaded_file($_FILES['files']['tmp_name']['xcos2'], $root_path . $dest_path . $_FILES['files']['name']['xcos2']))
{
/* for uploaded files making an entry in the database */
- db_query("INSERT INTO {textbook_companion_example_files} (example_id, filename, filepath, filemime, filesize, filetype, timestamp)
+ /*db_query("INSERT INTO {textbook_companion_example_files} (example_id, filename, filepath, filemime, filesize, filetype, timestamp)
VALUES (%d, '%s', '%s', '%s', %d, '%s', %d)",
$example_data->id,
$_FILES['files']['name']['xcos2'],
@@ -886,7 +1122,20 @@ function upload_examples_edit_form_submit($form, &$form_state)
$_FILES['files']['size']['xcos2'],
'X',
time()
- );
+ );*/
+
+ $query = "INSERT INTO {textbook_companion_example_files} (example_id, filename, filepath, filemime, filesize, filetype, timestamp) VALUES (:example_id, :filename, :filepath, :filemime, :filesize, :filetype,:timestamp)";
+ $args = array(
+ ":example_id"=> $example_data->id,
+ ":filename"=> $_FILES['files']['name']['xcos2'],
+ ":filepath"=> $dest_path . $_FILES['files']['name']['xcos2'],
+ ":filemime"=> $_FILES['files']['type']['xcos2'],
+ ":filesize"=> $_FILES['files']['size']['xcos2'],
+ ":filetype"=>'X',
+ ":timestamp"=> time(),
+ );
+ $result = db_query($query, $args, array('return' => Database::RETURN_INSERT_ID));
+
drupal_set_message($_FILES['files']['name']['xcos2'] . ' uploaded successfully.', 'status');
} else {
drupal_set_message('Error uploading file : ' . $dest_path . '/' . $_FILES['files']['name']['xcos2'], 'error');
@@ -913,8 +1162,18 @@ function edit_chapter_title_form($form_state)
global $user;
/************************ start approve book details ************************/
- $proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE uid = %d ORDER BY id DESC LIMIT 1", $user->uid);
- $proposal_data = db_fetch_object($proposal_q);
+
+ /*$proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE uid = %d ORDER BY id DESC LIMIT 1", $user->uid);
+ $proposal_data = db_fetch_object($proposal_q);*/
+
+ $query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal');
+ $query->condition('uid', $user->uid);
+ $query->orderBy('id', 'DESC');
+ $query->range(0, 1);
+ $result = $query->execute();
+ $proposal_data =$result->fetchObject();
+
if (!$proposal_data)
{
drupal_set_message("Please submit a " . l('proposal', 'proposal') . ".", 'error');
@@ -947,8 +1206,17 @@ function edit_chapter_title_form($form_state)
}
}
- $preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND approval_status = 1 LIMIT 1", $proposal_data->id);
- $preference_data = db_fetch_object($preference_q);
+ /*$preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND approval_status = 1 LIMIT 1", $proposal_data->id);
+ $preference_data = db_fetch_object($preference_q);*/
+
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('proposal_id', $proposal_data->id);
+ $query->condition('approval_status', 1);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $preference_data=$result->fetchObject();
+
if (!$preference_data)
{
drupal_set_message(t('Invalid Book Preference status. Please contact site administrator for further information.'), 'error');
@@ -959,8 +1227,16 @@ function edit_chapter_title_form($form_state)
$chapter_id = arg(4);
- $chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE id = %d AND preference_id = %d", $chapter_id, $preference_data->id);
- $chapter_data = db_fetch_object($chapter_q);
+ /*$chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE id = %d AND preference_id = %d", $chapter_id, $preference_data->id);
+ $chapter_data = db_fetch_object($chapter_q);*/
+
+ $query = db_select('textbook_companion_chapter');
+ $query->fields('textbook_companion_chapter');
+ $query->condition('id', $chapter_id);
+ $query->condition('preference_id', $preference_data->id);
+ $result = $query->execute();
+ $chapter_data =$result->fetchObject();
+
if (!$chapter_data)
{
drupal_set_message(t('Invalid chapter.'), 'error');
@@ -972,18 +1248,18 @@ function edit_chapter_title_form($form_state)
$form['book_details']['book'] = array(
'#type' => 'item',
- '#value' => $preference_data->book,
+ '#markup' => $preference_data->book,
'#title' => t('Title of the Book'),
);
$form['contributor_name'] = array(
'#type' => 'item',
- '#value' => $proposal_data->full_name,
+ '#markup' => $proposal_data->full_name,
'#title' => t('Contributor Name'),
);
$form['number'] = array(
'#type' => 'item',
'#title' => t('Chapter No'),
- '#value' => $chapter_data->number,
+ '#markup' => $chapter_data->number,
);
$form['chapter_title'] = array(
@@ -1017,8 +1293,18 @@ function edit_chapter_title_form_submit($form, &$form_state)
global $user;
/************************ start approve book details ************************/
- $proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE uid = %d ORDER BY id DESC LIMIT 1", $user->uid);
- $proposal_data = db_fetch_object($proposal_q);
+
+ /*$proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE uid = %d ORDER BY id DESC LIMIT 1", $user->uid);
+ $proposal_data = db_fetch_object($proposal_q);*/
+
+ $query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal');
+ $query->condition('uid', $user->uid);
+ $query->orderBy('id', 'DESC');
+ $query->range(0, 1);
+ $result = $query->execute();
+ $proposal_data =$result->fetchObject();
+
if (!$proposal_data)
{
drupal_set_message("Please submit a " . l('proposal', 'proposal') . ".", 'error');
@@ -1051,8 +1337,17 @@ function edit_chapter_title_form_submit($form, &$form_state)
}
}
- $preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND approval_status = 1 LIMIT 1", $proposal_data->id);
- $preference_data = db_fetch_object($preference_q);
+ /*$preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND approval_status = 1 LIMIT 1", $proposal_data->id);
+ $preference_data = db_fetch_object($preference_q);*/
+
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('proposal_id', $proposal_data->id);
+ $query->condition('approval_status', 1);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $preference_data =$result->fetchObject();
+
if (!$preference_data)
{
drupal_set_message(t('Invalid Book Preference status. Please contact site administrator for further information.'), 'error');
@@ -1063,16 +1358,33 @@ function edit_chapter_title_form_submit($form, &$form_state)
$chapter_id = arg(4);
- $chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE id = %d AND preference_id = %d", $chapter_id, $preference_data->id);
- $chapter_data = db_fetch_object($chapter_q);
+ /*$chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE id = %d AND preference_id = %d", $chapter_id, $preference_data->id);
+ $chapter_data = db_fetch_object($chapter_q);*/
+
+ $query = db_select('textbook_companion_chapter');
+ $query->fields('textbook_companion_chapter');
+ $query->condition('id', $chapter_id);
+ $query->condition('preference_id', $preference_data->id);
+ $result = $query->execute();
+ $chapter_data =$result->fetchObject();
+
if (!$chapter_data)
{
drupal_set_message(t('Invalid chapter.'), 'error');
drupal_goto('textbook_companion/code');
return;
}
- db_query("UPDATE {textbook_companion_chapter} SET name = '%s' WHERE id = %d", $form_state['values']['chapter_title'], $chapter_id);
+
+ /*db_query("UPDATE {textbook_companion_chapter} SET name = '%s' WHERE id = %d", $form_state['values']['chapter_title'], $chapter_id);*/
+ $query = db_update('textbook_companion_chapter');
+ $query->fields(array(
+ 'name' => $form_state['values']['chapter_title'],
+ ));
+ $query->condition('id', $chapter_id);
+ $num_updated = $query->execute();
+
drupal_set_message(t('Title of the Chapter updated.'), 'status');
+ drupal_goto('textbook_companion/code');
}
@@ -1083,8 +1395,19 @@ function edit_chapter_title_form_submit($form, &$form_state)
function _list_of_book_titles()
{
$book_titles = array('0' => 'Please select...');
- $book_titles_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE approval_status = 1 OR approval_status = 3 ORDER BY book ASC");
- while ($book_titles_data = db_fetch_object($book_titles_q))
+
+ /*$book_titles_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE approval_status = 1 OR approval_status = 3 ORDER BY book ASC");*/
+
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $or = db_or();
+ $or->condition('approval_status', 1);
+ $or->condition('approval_status', 3);
+ $query->condition($or);
+ $query->orderBy('book', 'ASC');
+ $book_titles_q = $query->execute();
+
+ while ($book_titles_data = $book_titles_q->fetchObject())
{
$book_titles[$book_titles_data->id] = $book_titles_data->book . ' (Written by ' . $book_titles_data->author . ')';
}
@@ -1095,14 +1418,21 @@ function _list_of_book_dependency_files()
{
$book_dependency_files = array();
$book_dependency_files_class = array();
- $book_dependency_files_q = db_query("SELECT * FROM {textbook_companion_dependency_files} ORDER BY filename ASC");
- while ($book_dependency_files_data = db_fetch_object($book_dependency_files_q))
+ /*$book_dependency_files_q = db_query("SELECT * FROM {textbook_companion_dependency_files} ORDER BY filename ASC");*/
+ $query = db_select('textbook_companion_dependency_files', 'tcdp');
+ $query->fields('tcdp');
+ $query->fields('tcp', array('book', 'author','publisher', 'edition', 'year'));
+ $query->leftJoin('textbook_companion_preference', 'tcp', 'tcdp.preference_id = tcp.id');
+ $book_dependency_files_q = $query->execute();
+
+
+ while ($book_dependency_files_data =$book_dependency_files_q->fetchObject())
{
$temp_caption = '';
if ($book_dependency_files_data->caption)
- $temp_caption .= ' (' . $book_dependency_files_data->caption . ')';
- $book_dependency_files[$book_dependency_files_data->id] = l($book_dependency_files_data->filename . $temp_caption, 'download/dependency/' . $book_dependency_files_data->id, array('attributes' => array('class' => $book_dependency_files_data->preference_id)));
+ $temp_caption .= ' ===>[Caption: ' . $book_dependency_files_data->caption . ' ' .', Book: '. $book_dependency_files_data->book .', Author: '. $book_dependency_files_data->author . ', Publisher: '. $book_dependency_files_data->publisher . ', Edition: '. $book_dependency_files_data->edition .', Year: '. $book_dependency_files_data->year.']';
+ $book_dependency_files[$book_dependency_files_data->id] = l($book_dependency_files_data->filename , 'download/dependency/' . $book_dependency_files_data->id, array('attributes' => array('class' => 'title'))). $temp_caption;
$book_dependency_files_class[$book_dependency_files_data->id] = $book_dependency_files_data->preference_id;
}
return array($book_dependency_files, $book_dependency_files_class);
diff --git a/editcodeadmin.inc b/editcodeadmin.inc
index 41f0e83..ac7951f 100755
--- a/editcodeadmin.inc
+++ b/editcodeadmin.inc
@@ -11,8 +11,16 @@ function upload_examples_admin_edit_form($form_state)
$example_id = arg(2);
/* get example details */
- $example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE id = %d LIMIT 1", $example_id);
- $example_data = db_fetch_object($example_q);
+
+ /*$example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE id = %d LIMIT 1", $example_id);
+ $example_data = db_fetch_object($example_q);*/
+ $query = db_select('textbook_companion_example');
+ $query->fields('textbook_companion_example');
+ $query->condition('id', $example_id);
+ $query->range(0, 1);
+ $example_q = $query->execute();
+ $example_data=$example_q->fetchObject();
+
if (!$example_q)
{
drupal_set_message(t("Invalid example selected."), 'error');
@@ -27,8 +35,14 @@ function upload_examples_admin_edit_form($form_state)
$xcos1_file = ""; $xcos1_id = 0;
$xcos2_file = ""; $xcos2_id = 0;
- $example_files_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE example_id = %d", $example_id);
- while ($example_files_data = db_fetch_object($example_files_q))
+ /*$example_files_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE example_id = %d", $example_id);*/
+
+ $query = db_select('textbook_companion_example_files');
+ $query->fields('textbook_companion_example_files');
+ $query->condition('example_id', $example_id);
+ $example_files_q = $query->execute();
+
+ while ($example_files_data = $example_files_q->fetchObject())
{
if ($example_files_data->filetype == "S")
{
@@ -60,8 +74,15 @@ function upload_examples_admin_edit_form($form_state)
}
/* get chapter details */
- $chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE id = %d", $example_data->chapter_id);
- $chapter_data = db_fetch_object($chapter_q);
+
+ /*$chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE id = %d", $example_data->chapter_id);
+ $chapter_data = db_fetch_object($chapter_q);*/
+ $query = db_select('textbook_companion_chapter');
+ $query->fields('textbook_companion_chapter');
+ $query->condition('id', $example_data->chapter_id);
+ $result = $query->execute();
+ $chapter_data =$result->fetchObject();
+
if (!$chapter_data)
{
drupal_set_message(t("Invalid chapter selected."), 'error');
@@ -70,8 +91,16 @@ function upload_examples_admin_edit_form($form_state)
}
/* get preference details */
- $preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d", $chapter_data->preference_id);
- $preference_data = db_fetch_object($preference_q);
+
+ /*$preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d", $chapter_data->preference_id);
+ $preference_data = db_fetch_object($preference_q);*/
+
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('id', $chapter_data->preference_id);
+ $result = $query->execute();
+ $preference_data =$result->fetchObject();
+
if (!$preference_data)
{
drupal_set_message(t("Invalid book selected."), 'error');
@@ -80,8 +109,16 @@ function upload_examples_admin_edit_form($form_state)
}
/* get proposal details */
- $proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d", $preference_data->proposal_id);
- $proposal_data = db_fetch_object($proposal_q);
+
+ /*$proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d", $preference_data->proposal_id);
+ $proposal_data = db_fetch_object($proposal_q);*/
+
+ $query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal');
+ $query->condition('id', $preference_data->proposal_id);
+ $result = $query->execute();
+ $proposal_data =$result->fetchObject();
+
if (!$proposal_data)
{
drupal_set_message(t("Invalid proposal selected."), 'error');
@@ -92,11 +129,11 @@ function upload_examples_admin_edit_form($form_state)
$user_data = user_load($proposal_data->uid);
/* add javascript for automatic book title, check if example uploaded, dependency selection effects */
- $chapter_name_js = " $(document).ready(function() {
+ /* $chapter_name_js = " $(document).ready(function() {
$('#edit-existing-depfile-dep-book-title').change(function() {
var dep_selected = '';
/* showing and hiding relevant files */
- $('.form-checkboxes .option').hide();
+ /* $('.form-checkboxes .option').hide();
$('.form-checkboxes .option').each(function(index) {
var activeClass = $('#edit-existing-depfile-dep-book-title').val();
if ($(this).children().hasClass(activeClass)) {
@@ -107,7 +144,7 @@ function upload_examples_admin_edit_form($form_state)
}
});
/* showing list of already existing dependencies */
- $('#existing_depfile_selected').html(dep_selected);
+ /* $('#existing_depfile_selected').html(dep_selected);
});
$('.form-checkboxes .option').change(function() {
@@ -116,34 +153,34 @@ function upload_examples_admin_edit_form($form_state)
$('#edit-existing-depfile-dep-book-title').trigger('change');
});";
drupal_add_js($chapter_name_js, 'inline', 'header');
-
+*/
$form['#redirect'] = 'code_approval/bulk';
$form['#attributes'] = array('enctype' => "multipart/form-data");
$form['book_details']['book'] = array(
'#type' => 'item',
- '#value' => $preference_data->book,
+ '#markup' => $preference_data->book,
'#title' => t('Title of the Book'),
);
$form['contributor_name'] = array(
'#type' => 'item',
- '#value' => $proposal_data->full_name,
+ '#markup' => $proposal_data->full_name,
'#title' => t('Contributor Name'),
);
$form['number'] = array(
'#type' => 'item',
'#title' => t('Chapter No'),
- '#value' => $chapter_data->number,
+ '#markup' => $chapter_data->number,
);
$form['name'] = array(
'#type' => 'item',
'#title' => t('Title of the Chapter'),
- '#value' => $chapter_data->name,
+ '#markup' => $chapter_data->name,
);
$form['example_number'] = array(
'#type' => 'item',
'#title' => t('Example No'),
- '#value' => $example_data->number,
+ '#markup' => $example_data->number,
);
$form['example_caption'] = array(
'#type' => 'textfield',
@@ -171,7 +208,7 @@ function upload_examples_admin_edit_form($form_state)
$form['sourcefile']['cur_source'] = array(
'#type' => 'item',
'#title' => t('Existing Main or Source File'),
- '#value' => $source_file,
+ '#markup' => $source_file,
);
$form['sourcefile']['cur_source_checkbox'] = array(
'#type' => 'checkbox',
@@ -206,8 +243,14 @@ function upload_examples_admin_edit_form($form_state)
/************ START OF EXISTING DEPENDENCIES **************/
$dependency_files = array();
- $dependency_q = db_query("SELECT * FROM {textbook_companion_example_dependency} WHERE example_id = %d", $example_data->id);
- while ($dependency_data = db_fetch_object($dependency_q))
+
+ /*$dependency_q = db_query("SELECT * FROM {textbook_companion_example_dependency} WHERE example_id = %d", $example_data->id);*/
+ $query = db_select('textbook_companion_example_dependency');
+ $query->fields('textbook_companion_example_dependency');
+ $query->condition('example_id', $example_data->id);
+ $dependency_q = $query->execute();
+
+ while ($dependency_data = $dependency_q->fetchObject())
{
$dependency_files[] = $dependency_data->dependency_id;
}
@@ -227,7 +270,7 @@ function upload_examples_admin_edit_form($form_state)
$form['existing_depfile']['selected'] = array(
'#type' => 'item',
'#title' => t('Existing Dependency Files Selected'),
- '#value' => '<div id="existing_depfile_selected"></div>',
+ '#markup' => '<div id="existing_depfile_selected"></div>',
);
$form['existing_depfile']['dep_book_title'] = array(
@@ -248,7 +291,7 @@ function upload_examples_admin_edit_form($form_state)
$form['existing_depfile']['dep_upload'] = array(
'#type' => 'item',
- '#value' => l('Upload New Depedency Files', 'textbook_companion/code/upload_dep'),
+ '#markup' => l('Upload New Depedency Files', 'textbook_companion/code/upload_dep'),
);
/************ END OF EXISTING DEPENDENCIES **************/
@@ -263,7 +306,7 @@ function upload_examples_admin_edit_form($form_state)
$form['result']['cur_result1'] = array(
'#type' => 'item',
'#title' => t('Existing Result File 1'),
- '#value' => $result1_file,
+ '#markup' => $result1_file,
);
$form['result']['cur_result1_checkbox'] = array(
'#type' => 'checkbox',
@@ -292,7 +335,7 @@ function upload_examples_admin_edit_form($form_state)
$form['result']['br'] = array(
'#type' => 'item',
- '#value' => "<br />",
+ '#markup' => "<br />",
);
if ($result2_file)
@@ -300,7 +343,7 @@ function upload_examples_admin_edit_form($form_state)
$form['result']['cur_result2'] = array(
'#type' => 'item',
'#title' => t('Existing Result File 2'),
- '#value' => $result2_file,
+ '#markup' => $result2_file,
);
$form['result']['cur_result2_checkbox'] = array(
'#type' => 'checkbox',
@@ -337,7 +380,7 @@ function upload_examples_admin_edit_form($form_state)
$form['xcos']['cur_xcos1'] = array(
'#type' => 'item',
'#title' => t('Existing xcos File 1'),
- '#value' => $xcos1_file,
+ '#markup' => $xcos1_file,
);
$form['xcos']['cur_xcos1_checkbox'] = array(
'#type' => 'checkbox',
@@ -366,7 +409,7 @@ function upload_examples_admin_edit_form($form_state)
$form['xcos']['br'] = array(
'#type' => 'item',
- '#value' => "<br />",
+ '#markup' => "<br />",
);
if ($xcos2_file)
@@ -374,7 +417,7 @@ function upload_examples_admin_edit_form($form_state)
$form['xcos']['cur_xcos2'] = array(
'#type' => 'item',
'#title' => t('Existing xcos File 2'),
- '#value' => $xcos2_file,
+ '#markup' => $xcos2_file,
);
$form['xcos']['cur_xcos2_checkbox'] = array(
'#type' => 'checkbox',
@@ -508,8 +551,16 @@ function upload_examples_admin_edit_form_submit($form, &$form_state)
$example_id = arg(2);
/* get example details */
- $example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE id = %d LIMIT 1", $example_id);
- $example_data = db_fetch_object($example_q);
+ /*$example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE id = %d LIMIT 1", $example_id);
+ $example_data = db_fetch_object($example_q);*/
+
+ $query = db_select('textbook_companion_example');
+ $query->fields('textbook_companion_example');
+ $query->condition('id', $example_id);
+ $query->range(0, 1);
+ $example_q = $query->execute();
+ $example_data =$example_q->fetchObject();
+
if (!$example_q)
{
drupal_set_message(t("Invalid example selected."), 'error');
@@ -518,8 +569,16 @@ function upload_examples_admin_edit_form_submit($form, &$form_state)
}
/* get chapter details */
- $chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE id = %d", $example_data->chapter_id);
- $chapter_data = db_fetch_object($chapter_q);
+
+ /*$chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE id = %d", $example_data->chapter_id);
+ $chapter_data = db_fetch_object($chapter_q);*/
+
+ $query = db_select('textbook_companion_chapter');
+ $query->fields('textbook_companion_chapter');
+ $query->condition('id', $example_data->chapter_id);
+ $chapter_q = $query->execute();
+ $chapter_data = $chapter_q->fetchObject();
+
if (!$chapter_data)
{
drupal_set_message(t("Invalid chapter selected."), 'error');
@@ -528,8 +587,16 @@ function upload_examples_admin_edit_form_submit($form, &$form_state)
}
/* get preference details */
- $preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d", $chapter_data->preference_id);
- $preference_data = db_fetch_object($preference_q);
+
+ /*$preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d", $chapter_data->preference_id);
+ $preference_data = db_fetch_object($preference_q);*/
+
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('id', $chapter_data->preference_id);
+ $result = $query->execute();
+ $preference_data =$result->fetchObject();
+
if (!$preference_data)
{
drupal_set_message(t("Invalid book selected."), 'error');
@@ -538,8 +605,15 @@ function upload_examples_admin_edit_form_submit($form, &$form_state)
}
/* get proposal details */
- $proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d", $preference_data->proposal_id);
- $proposal_data = db_fetch_object($proposal_q);
+
+ /*$proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d", $preference_data->proposal_id);
+ $proposal_data = db_fetch_object($proposal_q);*/
+ $query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal');
+ $query->condition('id', $preference_data->proposal_id);
+ $result = $query->execute();
+ $proposal_data =$result->fetchObject();
+
if (!$proposal_data)
{
drupal_set_message(t("Invalid proposal selected."), 'error');
@@ -564,22 +638,46 @@ function upload_examples_admin_edit_form_submit($form, &$form_state)
mkdir($root_path . $dest_path);
/* updating example caption */
- db_query("UPDATE {textbook_companion_example} SET caption = '%s' WHERE id = %d", $form_state['values']['example_caption'], $example_id);
+
+ /*db_query("UPDATE {textbook_companion_example} SET caption = '%s' WHERE id = %d", $form_state['values']['example_caption'], $example_id);*/
+
+ $query = db_update('textbook_companion_example');
+ $query->fields(array(
+ 'caption' => $form_state['values']['example_caption'],
+ ));
+ $query->condition('id', $example_id);
+ $num_updated = $query->execute();
/* handling dependencies */
- db_query("DELETE FROM {textbook_companion_example_dependency} WHERE example_id = %d", $example_data->id);
+
+ /*db_query("DELETE FROM {textbook_companion_example_dependency} WHERE example_id = %d", $example_data->id);*/
+ $query = db_delete('textbook_companion_example_dependency');
+ $query->condition('example_id', $example_data->id);
+ $num_deleted = $query->execute();
+
+
foreach ($form_state['values']['existing_depfile']['dep_chapter_example_files'] as $row)
{
if ($row > 0)
{
/* insterting into database */
- db_query("INSERT INTO {textbook_companion_example_dependency} (example_id, dependency_id, approval_status, timestamp)
+ /*db_query("INSERT INTO {textbook_companion_example_dependency} (example_id, dependency_id, approval_status, timestamp)
VALUES (%d, %d, %d, %d)",
$example_data->id,
$row,
0,
time()
- );
+ );*/
+
+ $query = "INSERT INTO {textbook_companion_example_dependency} (example_id, dependency_id, approval_status, timestamp)
+ VALUES (:example_id, :dependency_id, :approval_status, :timestamp)";
+ $args = array(
+ ":example_id"=> $example_data->id,
+ ":dependency_id"=> $row,
+ ":approval_status"=> 0,
+ "::timestamp"=>time(),
+ );
+ $result = db_query($query, $args, array('return' => Database::RETURN_INSERT_ID));
}
}
@@ -587,8 +685,16 @@ function upload_examples_admin_edit_form_submit($form, &$form_state)
$cur_file_id = $form_state['values']['cur_source_file_id'];
if ($cur_file_id > 0)
{
- $file_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE id = %d AND example_id = %d", $cur_file_id, $example_data->id);
- $file_data = db_fetch_object($file_q);
+ /*$file_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE id = %d AND example_id = %d", $cur_file_id, $example_data->id);
+ $file_data = db_fetch_object($file_q);*/
+
+ $query = db_select('textbook_companion_example_files');
+ $query->fields('textbook_companion_example_files');
+ $query->condition('id', $cur_file_id);
+ $query->condition('example_id', $example_data->id);
+ $result = $query->execute();
+ $file_data =$result->fetchObject();
+
if (!$file_data)
{
drupal_set_message("Error deleting example source file. File not present in database.", 'error');
@@ -622,7 +728,7 @@ function upload_examples_admin_edit_form_submit($form, &$form_state)
if (move_uploaded_file($_FILES['files']['tmp_name']['sourcefile1'], $root_path . $dest_path . $_FILES['files']['name']['sourcefile1']))
{
/* for uploaded files making an entry in the database */
- db_query("INSERT INTO {textbook_companion_example_files} (example_id, filename, filepath, filemime, filesize, filetype, timestamp)
+ /*db_query("INSERT INTO {textbook_companion_example_files} (example_id, filename, filepath, filemime, filesize, filetype, timestamp)
VALUES (%d, '%s', '%s', '%s', %d, '%s', %d)",
$example_data->id,
$_FILES['files']['name']['sourcefile1'],
@@ -631,7 +737,21 @@ function upload_examples_admin_edit_form_submit($form, &$form_state)
$_FILES['files']['size']['sourcefile1'],
'S',
time()
- );
+ );*/
+
+ $query = "INSERT INTO {textbook_companion_example_files} (example_id, filename, filepath, filemime, filesize, filetype, timestamp)
+ VALUES (:example_id, :filename, :filepath, :filemime, :filesize, :filetype, :timestamp)";
+ $args = array(
+ ":example_id"=> $example_data->id,
+ ":filename"=>$_FILES['files']['name']['sourcefile1'],
+ ":filepath"=>$dest_path . $_FILES['files']['name']['sourcefile1'],
+ ":filemime"=> $_FILES['files']['type']['sourcefile1'],
+ ":filesize"=>$_FILES['files']['size']['sourcefile1'],
+ ":filetype"=> 'S',
+ ":timestamp"=>time(),
+ );
+ $result = db_query($query, $args, array('return' => Database::RETURN_INSERT_ID));
+
drupal_set_message($_FILES['files']['name']['sourcefile1'] . ' uploaded successfully.', 'status');
} else {
drupal_set_message('Error uploading file : ' . $dest_path . '/' . $_FILES['files']['name']['sourcefile1'], 'error');
@@ -642,8 +762,17 @@ function upload_examples_admin_edit_form_submit($form, &$form_state)
$cur_file_id = $form_state['values']['cur_result1_file_id'];
if ($cur_file_id > 0)
{
- $file_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE id = %d AND example_id = %d", $cur_file_id, $example_data->id);
- $file_data = db_fetch_object($file_q);
+ /*$file_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE id = %d AND example_id = %d", $cur_file_id, $example_data->id);
+ $file_data = db_fetch_object($file_q);*/
+
+ $query = db_select('textbook_companion_example_files');
+ $query->fields('textbook_companion_example_files');
+ $query->condition('id', $cur_file_id);
+ $query->condition('example_id', $example_data->id);
+ $result = $query->execute();
+ $file_data =$result->fetchObject();
+
+
if (!$file_data)
{
drupal_set_message("Error deleting example result 1 file. File not present in database.", 'error');
@@ -677,7 +806,7 @@ function upload_examples_admin_edit_form_submit($form, &$form_state)
if (move_uploaded_file($_FILES['files']['tmp_name']['result1'], $root_path . $dest_path . $_FILES['files']['name']['result1']))
{
/* for uploaded files making an entry in the database */
- db_query("INSERT INTO {textbook_companion_example_files} (example_id, filename, filepath, filemime, filesize, filetype, timestamp)
+ /* db_query("INSERT INTO {textbook_companion_example_files} (example_id, filename, filepath, filemime, filesize, filetype, timestamp)
VALUES (%d, '%s', '%s', '%s', %d, '%s', %d)",
$example_data->id,
$_FILES['files']['name']['result1'],
@@ -686,7 +815,22 @@ function upload_examples_admin_edit_form_submit($form, &$form_state)
$_FILES['files']['size']['result1'],
'R',
time()
- );
+ );*/
+
+ $query = "INSERT INTO {textbook_companion_example_files} (example_id, filename, filepath, filemime, filesize, filetype, timestamp)
+ VALUES (:example_id, :filename, :filepath, :filemime, :filesize, :filetype, :timestamp)";
+ $args = array(
+ ":example_id"=> $example_data->id,
+ ":filename"=>$_FILES['files']['name']['result1'],
+ ":filepath"=> $dest_path . $_FILES['files']['name']['result1'],
+ ":filemime"=> $_FILES['files']['type']['result1'],
+ ":filesize"=>$_FILES['files']['size']['result1'],
+ ":filetype"=> 'R',
+ ":timestamp"=>time(),
+ );
+ $result = db_query($query, $args, array('return' => Database::RETURN_INSERT_ID));
+
+
drupal_set_message($_FILES['files']['name']['result1'] . ' uploaded successfully.', 'status');
} else {
drupal_set_message('Error uploading file : ' . $dest_path . '/' . $_FILES['files']['name']['result1'], 'error');
@@ -697,8 +841,16 @@ function upload_examples_admin_edit_form_submit($form, &$form_state)
$cur_file_id = $form_state['values']['cur_result2_file_id'];
if ($cur_file_id > 0)
{
- $file_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE id = %d AND example_id = %d", $cur_file_id, $example_data->id);
- $file_data = db_fetch_object($file_q);
+ /*$file_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE id = %d AND example_id = %d", $cur_file_id, $example_data->id);
+ $file_data = db_fetch_object($file_q);*/
+
+ $query = db_select('textbook_companion_example_files');
+ $query->fields('textbook_companion_example_files');
+ $query->condition('id', $cur_file_id);
+ $query->condition('example_id', $example_data->id);
+ $result = $query->execute();
+ $file_data =$result->fetchObject();
+
if (!$file_data)
{
drupal_set_message("Error deleting example result 2 file. File not present in database.", 'error');
@@ -732,7 +884,7 @@ function upload_examples_admin_edit_form_submit($form, &$form_state)
if (move_uploaded_file($_FILES['files']['tmp_name']['result2'], $root_path . $dest_path . $_FILES['files']['name']['result2']))
{
/* for uploaded files making an entry in the database */
- db_query("INSERT INTO {textbook_companion_example_files} (example_id, filename, filepath, filemime, filesize, filetype, timestamp)
+ /*db_query("INSERT INTO {textbook_companion_example_files} (example_id, filename, filepath, filemime, filesize, filetype, timestamp)
VALUES (%d, '%s', '%s', '%s', %d, '%s', %d)",
$example_data->id,
$_FILES['files']['name']['result2'],
@@ -741,7 +893,21 @@ function upload_examples_admin_edit_form_submit($form, &$form_state)
$_FILES['files']['size']['result2'],
'R',
time()
- );
+ );*/
+
+ $query = "INSERT INTO {textbook_companion_example_files} (example_id, filename, filepath, filemime, filesize, filetype, timestamp)
+ VALUES (:example_id, :filename, :filepath, :filemime, :filesize, :filetype, :timestamp)";
+ $args = array(
+ ":example_id"=> $example_data->id,
+ ":filename"=> $_FILES['files']['name']['result2'],
+ ":filepath"=> $dest_path . $_FILES['files']['name']['result2'],
+ ":filemime"=> $_FILES['files']['type']['result2'],
+ ":filesize"=> $_FILES['files']['size']['result2'],
+ ":filetype"=> 'R',
+ ":timestamp"=>time(),
+ );
+ $result = db_query($query, $args, array('return' => Database::RETURN_INSERT_ID));
+
drupal_set_message($_FILES['files']['name']['result2'] . ' uploaded successfully.', 'status');
} else {
drupal_set_message('Error uploading file : ' . $dest_path . '/' . $_FILES['files']['name']['result2'], 'error');
@@ -752,8 +918,16 @@ function upload_examples_admin_edit_form_submit($form, &$form_state)
$cur_file_id = $form_state['values']['cur_xcos1_file_id'];
if ($cur_file_id > 0)
{
- $file_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE id = %d AND example_id = %d", $cur_file_id, $example_data->id);
- $file_data = db_fetch_object($file_q);
+ /*$file_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE id = %d AND example_id = %d", $cur_file_id, $example_data->id);
+ $file_data = db_fetch_object($file_q);*/
+
+ $query = db_select('textbook_companion_example_files');
+ $query->fields('textbook_companion_example_files');
+ $query->condition('id', $cur_file_id);
+ $query->condition('example_id', $example_data->id);
+ $result = $query->execute();
+ $file_data=$result->fetchObject();
+
if (!$file_data)
{
drupal_set_message("Error deleting example xcos 1 file. File not present in database.", 'error');
@@ -787,7 +961,7 @@ function upload_examples_admin_edit_form_submit($form, &$form_state)
if (move_uploaded_file($_FILES['files']['tmp_name']['xcos1'], $root_path . $dest_path . $_FILES['files']['name']['xcos1']))
{
/* for uploaded files making an entry in the database */
- db_query("INSERT INTO {textbook_companion_example_files} (example_id, filename, filepath, filemime, filesize, filetype, timestamp)
+ /*db_query("INSERT INTO {textbook_companion_example_files} (example_id, filename, filepath, filemime, filesize, filetype, timestamp)
VALUES (%d, '%s', '%s', '%s', %d, '%s', %d)",
$example_data->id,
$_FILES['files']['name']['xcos1'],
@@ -796,7 +970,22 @@ function upload_examples_admin_edit_form_submit($form, &$form_state)
$_FILES['files']['size']['xcos1'],
'X',
time()
- );
+ );*/
+
+ $query = "INSERT INTO {textbook_companion_example_files} (example_id, filename, filepath, filemime, filesize, filetype, timestamp)
+ VALUES (:example_id, :filename, :filepath, :filemime, :filesize, :filetype, :timestamp)";
+ $args = array(
+ ":example_id"=> $example_data->id,
+ ":filename"=>$_FILES['files']['name']['xcos1'],
+ ":filepath"=>$dest_path . $_FILES['files']['name']['xcos1'],
+ ":filemime"=>$_FILES['files']['type']['xcos1'],
+ ":filesize"=>$_FILES['files']['size']['xcos1'],
+ ":filetype"=>'X',
+ ":timestamp"=>time(),
+ );
+ $result = db_query($query, $args, array('return' => Database::RETURN_INSERT_ID));
+
+
drupal_set_message($_FILES['files']['name']['xcos1'] . ' uploaded successfully.', 'status');
} else {
drupal_set_message('Error uploading file : ' . $dest_path . '/' . $_FILES['files']['name']['xcos1'], 'error');
@@ -807,8 +996,16 @@ function upload_examples_admin_edit_form_submit($form, &$form_state)
$cur_file_id = $form_state['values']['cur_xcos2_file_id'];
if ($cur_file_id > 0)
{
- $file_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE id = %d AND example_id = %d", $cur_file_id, $example_data->id);
- $file_data = db_fetch_object($file_q);
+ /*$file_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE id = %d AND example_id = %d", $cur_file_id, $example_data->id);
+ $file_data = db_fetch_object($file_q);*/
+
+ $query = db_select('textbook_companion_example_files');
+ $query->fields('textbook_companion_example_files');
+ $query->condition('id', $cur_file_id);
+ $query->condition('example_id', $example_data->id);
+ $result = $query->execute();
+ $file_data =$result->fetchObject();
+
if (!$file_data)
{
drupal_set_message("Error deleting example xcos 2 file. File not present in database.", 'error');
@@ -842,7 +1039,7 @@ function upload_examples_admin_edit_form_submit($form, &$form_state)
if (move_uploaded_file($_FILES['files']['tmp_name']['xcos2'], $root_path . $dest_path . $_FILES['files']['name']['xcos2']))
{
/* for uploaded files making an entry in the database */
- db_query("INSERT INTO {textbook_companion_example_files} (example_id, filename, filepath, filemime, filesize, filetype, timestamp)
+ /*db_query("INSERT INTO {textbook_companion_example_files} (example_id, filename, filepath, filemime, filesize, filetype, timestamp)
VALUES (%d, '%s', '%s', '%s', %d, '%s', %d)",
$example_data->id,
$_FILES['files']['name']['xcos2'],
@@ -851,7 +1048,21 @@ function upload_examples_admin_edit_form_submit($form, &$form_state)
$_FILES['files']['size']['xcos2'],
'X',
time()
- );
+ );*/
+
+ $query = "INSERT INTO {textbook_companion_example_files} (example_id, filename, filepath, filemime, filesize, filetype, timestamp)
+ VALUES (:example_id, :filename, :filepath, :filemime, :filesize, :filetype, :timestamp)";
+ $args = array(
+ ":example_id"=> $example_data->id,
+ ":filename"=>$_FILES['files']['name']['xcos2'],
+ ":filepath"=>$dest_path . $_FILES['files']['name']['xcos2'],
+ ":filemime"=>$_FILES['files']['type']['xcos2'],
+ ":filesize"=>$_FILES['files']['size']['xcos2'],
+ ":filetype"=>'X',
+ ":timestamp"=>time(),
+ );
+ $result = db_query($query, $args, array('return' => Database::RETURN_INSERT_ID));
+
drupal_set_message($_FILES['files']['name']['xcos2'] . ' uploaded successfully.', 'status');
} else {
drupal_set_message('Error uploading file : ' . $dest_path . '/' . $_FILES['files']['name']['xcos2'], 'error');
@@ -875,8 +1086,17 @@ function upload_examples_admin_edit_form_submit($form, &$form_state)
function _list_of_book_titles()
{
$book_titles = array('0' => 'Please select...');
- $book_titles_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE approval_status = 1 OR approval_status = 3 ORDER BY book ASC");
- while ($book_titles_data = db_fetch_object($book_titles_q))
+ /*$book_titles_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE approval_status = 1 OR approval_status = 3 ORDER BY book ASC");*/
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $or = db_or();
+ $or->condition('approval_status', 1);
+ $or->condition('approval_status', 3);
+ $query->condition($or);
+ $query->orderBy('book', 'ASC');
+ $book_titles_q = $query->execute();
+
+ while ($book_titles_data = $book_titles_q->fetchObject())
{
$book_titles[$book_titles_data->id] = $book_titles_data->book . ' (Written by ' . $book_titles_data->author . ')';
}
@@ -887,9 +1107,15 @@ function _list_of_book_dependency_files()
{
$book_dependency_files = array();
$book_dependency_files_class = array();
- $book_dependency_files_q = db_query("SELECT * FROM {textbook_companion_dependency_files} ORDER BY filename ASC");
- while ($book_dependency_files_data = db_fetch_object($book_dependency_files_q))
+ /*$book_dependency_files_q = db_query("SELECT * FROM {textbook_companion_dependency_files} ORDER BY filename ASC");*/
+
+ $query = db_select('textbook_companion_dependency_files');
+ $query->fields('textbook_companion_dependency_files');
+ $query->orderBy('filename', 'ASC');
+ $book_dependency_files_q = $query->execute();
+
+ while ($book_dependency_files_data = $book_dependency_files_q->fetchObject())
{
$temp_caption = '';
if ($book_dependency_files_data->caption)
diff --git a/full_download.inc b/full_download.inc
index a269bd8..fa8c87c 100755
--- a/full_download.inc
+++ b/full_download.inc
@@ -9,52 +9,116 @@ function textbook_companion_download_full_chapter()
$PENDING_PATH = 'PENDING/';
/* get example data */
- $chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE id = %d", $chapter_id);
- $chapter_data = db_fetch_object($chapter_q);
+
+ /*$chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE id = %d", $chapter_id);
+ $chapter_data = db_fetch_object($chapter_q);*/
+
+ $query = db_select('textbook_companion_chapter');
+ $query->fields('textbook_companion_chapter');
+ $query->condition('id', $chapter_id);
+ $chapter_q = $query->execute();
+ $chapter_data =$chapter_q->fetchObject();
+
$CH_PATH = 'CH' . $chapter_data->number . '/';
/* zip filename */
$zip_filename = $root_path . 'zip-' . time() . '-' . rand(0, 999999) . '.zip';
/* creating zip archive on the server */
- $zip = new ZipArchive;
+ $zip = new ZipArchive();
$zip->open($zip_filename, ZipArchive::CREATE);
/* approved examples */
- $example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d AND approval_status = 1", $chapter_id);
- while ($example_row = db_fetch_object($example_q))
+
+ /*$example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d AND approval_status = 1", $chapter_id);*/
+ $query = db_select('textbook_companion_example');
+ $query->fields('textbook_companion_example');
+ $query->condition('chapter_id', $chapter_id);
+ $query->condition('approval_status', 1);
+ $example_q = $query->execute();
+
+ while ($example_row = $example_q->fetchObject())
{
$EX_PATH = 'EX' . $example_row->number . '/';
- $example_files_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE example_id = %d", $example_row->id);
- $example_dependency_files_q = db_query("SELECT * FROM {textbook_companion_example_dependency} WHERE example_id = %d", $example_row->id);
- while ($example_files_row = db_fetch_object($example_files_q))
+
+ /*$example_files_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE example_id = %d", $example_row->id);*/
+
+ $query = db_select('textbook_companion_example_files');
+ $query->fields('textbook_companion_example_files');
+ $query->condition('example_id', $example_row->id);
+ $example_files_q = $query->execute();
+
+ /*$example_dependency_files_q = db_query("SELECT * FROM {textbook_companion_example_dependency} WHERE example_id = %d", $example_row->id);*/
+ $query = db_select('textbook_companion_example_dependency');
+ $query->fields('textbook_companion_example_dependency');
+ $query->condition('example_id', $example_row->id);
+ $example_dependency_files_q = $query->execute();
+
+ while ($example_files_row =$example_files_q->fetchObject())
{
$zip->addFile($root_path . $example_files_row->filepath, $APPROVE_PATH . $CH_PATH . $EX_PATH . $example_files_row->filename);
}
/* dependency files */
- while ($example_dependency_files_row = db_fetch_object($example_dependency_files_q))
+ while ($example_dependency_files_row = $example_dependency_files_q->fetchObject())
{
- $dependency_file_data = db_fetch_object(db_query("SELECT * FROM {textbook_companion_dependency_files} WHERE id = %d LIMIT 1", $example_dependency_files_row->dependency_id));
+ /*$dependency_file_data = db_fetch_object(db_query("SELECT * FROM {textbook_companion_dependency_files} WHERE id = %d LIMIT 1", $example_dependency_files_row->dependency_id));*/
+
+ $query = db_select('textbook_companion_dependency_files');
+ $query->fields('textbook_companion_dependency_files');
+ $query->condition('id', $example_dependency_files_row->dependency_id);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $dependency_file_data=$result->fetchObject();
+
if ($dependency_file_data)
$zip->addFile($root_path . $dependency_file_data->filepath, $APPROVE_PATH . $CH_PATH . $EX_PATH . 'DEPENDENCIES/' . $dependency_file_data->filename);
}
}
/* unapproved examples */
- $example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d AND approval_status = 0", $chapter_id);
- while ($example_row = db_fetch_object($example_q))
+
+ /*$example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d AND approval_status = 0", $chapter_id);*/
+
+ $query = db_select('textbook_companion_example');
+ $query->fields('textbook_companion_example');
+ $query->condition('chapter_id', $chapter_id);
+ $query->condition('approval_status', 0);
+ $example_q = $query->execute();
+
+ while ($example_row =$example_q->fetchObject())
{
$EX_PATH = 'EX' . $example_row->number . '/';
- $example_files_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE example_id = %d", $example_row->id);
- $example_dependency_files_q = db_query("SELECT * FROM {textbook_companion_example_dependency} WHERE example_id = %d", $example_row->id);
- while ($example_files_row = db_fetch_object($example_files_q))
+
+ /*$example_files_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE example_id = %d", $example_row->id);*/
+
+ $query = db_select('textbook_companion_example_files');
+ $query->fields('textbook_companion_example_files');
+ $query->condition('example_id', $example_row->id);
+$ $example_files_q = $query->execute();
+
+ /*$example_dependency_files_q = db_query("SELECT * FROM {textbook_companion_example_dependency} WHERE example_id = %d", $example_row->id);*/
+
+ $query = db_select('textbook_companion_example_dependency');
+ $query->fields('textbook_companion_example_dependency');
+ $query->condition('example_id', $example_row->id);
+ $example_dependency_files_q = $query->execute();
+
+ while ($example_files_row = $example_files_q->fetchObject())
{
$zip->addFile($root_path . $example_files_row->filepath, $PENDING_PATH . $CH_PATH . $EX_PATH . $example_files_row->filename);
}
/* dependency files */
- while ($example_dependency_files_row = db_fetch_object($example_dependency_files_q))
+ while ($example_dependency_files_row = $example_dependency_files_q->fetchObject())
{
- $dependency_file_data = db_fetch_object(db_query("SELECT * FROM {textbook_companion_dependency_files} WHERE id = %d LIMIT 1", $example_dependency_files_row->dependency_id));
+ /*$dependency_file_data = db_fetch_object(db_query("SELECT * FROM {textbook_companion_dependency_files} WHERE id = %d LIMIT 1", $example_dependency_files_row->dependency_id));*/
+
+ $query = db_select('textbook_companion_dependency_files');
+ $query->fields('textbook_companion_dependency_files');
+ $query->condition('id', $example_dependency_files_row->dependency_id);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $dependency_file_data=$result->fetchObject();
+
if ($dependency_file_data)
$zip->addFile($root_path . $dependency_file_data->filepath, $PENDING_PATH . $CH_PATH . $EX_PATH . 'DEPENDENCIES/' . $dependency_file_data->filename);
}
@@ -84,6 +148,7 @@ function textbook_companion_download_full_chapter()
}
}
+
function textbook_companion_download_full_book()
{
$book_id = arg(2);
@@ -91,65 +156,61 @@ function textbook_companion_download_full_book()
$APPROVE_PATH = 'APPROVED/';
$PENDING_PATH = 'PENDING/';
/* get example data */
- $book_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d", $book_id);
- $book_data = db_fetch_object($book_q);
+ $book_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = :book_id", array(':book_id' => $book_id));
+ $book_data = $book_q->fetchObject();
$BK_PATH = $book_data->book . '/';
-
/* zip filename */
$zip_filename = $root_path . 'zip-' . time() . '-' . rand(0, 999999) . '.zip';
-
/* creating zip archive on the server */
$zip = new ZipArchive;
$zip->open($zip_filename, ZipArchive::CREATE);
-
/* approved examples */
- $chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE preference_id = %d", $book_id);
- while ($chapter_row = db_fetch_object($chapter_q))
+ $chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE preference_id = :book_id", array(':book_id' => $book_id));
+ while ($chapter_row = $chapter_q->fetchObject())
{
$CH_PATH = 'CH' . $chapter_row->number . '/';
- $example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d AND approval_status = 1", $chapter_row->id);
- while ($example_row = db_fetch_object($example_q))
+ $example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE chapter_id = :chapter_id AND approval_status = 1", array(':chapter_id'=> $chapter_row->id));
+ while ($example_row = $example_q->fetchObject())
{
$EX_PATH = 'EX' . $example_row->number . '/';
- $example_files_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE example_id = %d", $example_row->id);
- $example_dependency_files_q = db_query("SELECT * FROM {textbook_companion_example_dependency} WHERE example_id = %d", $example_row->id);
- while ($example_files_row = db_fetch_object($example_files_q))
+ $example_files_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE example_id = :example_id", array(':example_id' => $example_row->id));
+ $example_dependency_files_q = db_query("SELECT * FROM {textbook_companion_example_dependency} WHERE example_id = :example_id", array(':example_id' => $example_row->id));
+ while ($example_files_row = $example_files_q->fetchObject())
{
- $zip->addFile($root_path . $example_files_row->filepath, $BK_PATH . $APPROVE_PATH . $CH_PATH . $EX_PATH . $example_files_row->filename);
+ $zip->addFile($root_path . $example_files_row->filepath, $BK_PATH . $APPROVE_PATH . $CH_PATH . $EX_PATH . $example_files_row->filename);
}
/* dependency files */
- while ($example_dependency_files_row = db_fetch_object($example_dependency_files_q))
+ while ($example_dependency_files_row = $example_dependency_files_q->fetchObject())
{
- $dependency_file_data = db_fetch_object(db_query("SELECT * FROM {textbook_companion_dependency_files} WHERE id = %d LIMIT 1", $example_dependency_files_row->dependency_id));
+ $dependency_file_data_query = db_query("SELECT * FROM {textbook_companion_dependency_files} WHERE id = :id LIMIT 1", array(':id' => $example_dependency_files_row->dependency_id));
+ $dependency_file_data = $dependency_file_data_query->fetchObject();
if ($dependency_file_data)
$zip->addFile($root_path . $dependency_file_data->filepath, $BK_PATH . $APPROVE_PATH . $CH_PATH . $EX_PATH . 'DEPENDENCIES/' . $dependency_file_data->filename);
}
}
-
/* unapproved examples */
- $example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d AND approval_status = 0", $chapter_row->id);
- while ($example_row = db_fetch_object($example_q))
+ $example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE chapter_id = :chapter_id AND approval_status = 0",array(':chapter_id' => $chapter_row->id));
+ while ($example_row = $example_q->fetchObject())
{
$EX_PATH = 'EX' . $example_row->number . '/';
- $example_files_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE example_id = %d", $example_row->id);
- $example_dependency_files_q = db_query("SELECT * FROM {textbook_companion_example_dependency} WHERE example_id = %d", $example_row->id);
- while ($example_files_row = db_fetch_object($example_files_q))
+ $example_files_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE example_id = :id",array(':id' => $example_row->id));
+ $example_dependency_files_q = db_query("SELECT * FROM {textbook_companion_example_dependency} WHERE example_id = :id",array(':id' => $example_row->id));
+ while ($example_files_row = $example_files_q->fetchObject())
{
$zip->addFile($root_path . $example_files_row->filepath, $BK_PATH . $PENDING_PATH . $CH_PATH . $EX_PATH . $example_files_row->filename);
}
/* dependency files */
- while ($example_dependency_files_row = db_fetch_object($example_dependency_files_q))
+ while ($example_dependency_files_row = $example_dependency_files_q->fetchObject())
{
- $dependency_file_data = db_fetch_object(db_query("SELECT * FROM {textbook_companion_dependency_files} WHERE id = %d LIMIT 1", $example_dependency_files_row->dependency_id));
+ $dependency_file_data_query = db_query("SELECT * FROM {textbook_companion_dependency_files} WHERE id = :id LIMIT 1", array(':id' => $example_dependency_files_row->dependency_id));
+ $dependency_file_data = $dependency_file_data_query->fetchObject();
if ($dependency_file_data)
- $zip->addFile($root_path . $dependency_file_data->filepath, $BK_PATH . $PENDING_PATH . $CH_PATH . $EX_PATH . 'DEPENDENCIES/' . $dependency_file_data->filename);
- }
+$zip->addFile($root_path . $dependency_file_data->filepath, $BK_PATH . $PENDING_PATH . $CH_PATH . $EX_PATH . 'DEPENDENCIES/' . $dependency_file_data->filename);
}
+ }
}
-
$zip_file_count = $zip->numFiles;
$zip->close();
-
if ($zip_file_count > 0)
{
/* download zip file */
@@ -160,7 +221,7 @@ function textbook_companion_download_full_book()
//header('Expires: 0');
//header('Pragma: no-cache');
//ob_end_flush();
- ob_clean();
+ //ob_clean();
//flush();
readfile($zip_filename);
unlink($zip_filename);
@@ -168,5 +229,5 @@ function textbook_companion_download_full_book()
drupal_set_message("There are no examples in this book to download", 'error');
drupal_goto('code_approval/bulk');
}
-}
+}
diff --git a/general.inc b/general.inc
index d986555..c3e2d14 100755
--- a/general.inc
+++ b/general.inc
@@ -6,8 +6,18 @@ function list_chapters()
global $user;
/************************ start approve book details ************************/
- $proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE uid = %d ORDER BY id DESC LIMIT 1", $user->uid);
- $proposal_data = db_fetch_object($proposal_q);
+
+ /*$proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE uid = %d ORDER BY id DESC LIMIT 1", $user->uid);
+ $proposal_data = db_fetch_object($proposal_q);*/
+
+ $query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal');
+ $query->condition('uid', $user->uid);
+ $query->orderBy('id', 'DESC');
+ $query->range(0, 1);
+ $result = $query->execute();
+ $proposal_data =$result->fetchObject();
+
if (!$proposal_data)
{
drupal_set_message("Please submit a " . l('proposal', 'proposal') . ".", 'error');
@@ -40,8 +50,17 @@ function list_chapters()
}
}
- $preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND approval_status = 1 LIMIT 1", $proposal_data->id);
- $preference_data = db_fetch_object($preference_q);
+ /*$preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND approval_status = 1 LIMIT 1", $proposal_data->id);
+ $preference_data = db_fetch_object($preference_q);*/
+
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('proposal_id', $proposal_data->id);
+ $query->condition('approval_status', 1);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $preference_data =$result->fetchObject();
+
if (!$preference_data)
{
drupal_set_message(t('Invalid Book Preference status. Please contact site administrator for further information.'), 'error');
@@ -57,12 +76,28 @@ function list_chapters()
/* get chapter list */
$chapter_rows = array();
- $chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE preference_id = %d ORDER BY number ASC", $preference_data->id);
- while ($chapter_data = db_fetch_object($chapter_q))
+
+ /*$chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE preference_id = %d ORDER BY number ASC", $preference_data->id);*/
+
+ $query = db_select('textbook_companion_chapter');
+ $query->fields('textbook_companion_chapter');
+ $query->condition('preference_id', $preference_data->id);
+ $query->orderBy('number', 'ASC');
+ $chapter_q = $query->execute();
+
+ while ($chapter_data = $chapter_q->fetchObject())
{
/* get example list */
- $example_q = db_query("SELECT count(*) as example_count FROM {textbook_companion_example} WHERE chapter_id = %d", $chapter_data->id);
- $example_data = db_fetch_object($example_q);
+
+ /* $example_q = db_query("SELECT count(*) as example_count FROM {textbook_companion_example} WHERE chapter_id = %d", $chapter_data->id);
+ $example_data = db_fetch_object($example_q);*/
+
+ $query = db_select('textbook_companion_example');
+ $query->addExpression('count(*)', 'example_count');
+ $query->condition('chapter_id', $chapter_data->id);
+ $result = $query->execute();
+ $example_data =$result->fetchObject();
+
$chapter_rows[] = array($chapter_data->number, $chapter_data->name . ' (' . l('Edit', 'textbook_companion/code/chapter/edit/' . $chapter_data->id) . ')', $example_data->example_count, l('View', 'textbook_companion/code/list_examples/' . $chapter_data->id));
}
@@ -73,8 +108,8 @@ function list_chapters()
return $return_html;
}
- $chapter_header = array('Chapter No.', 'Title of the Chapter', 'Uploaded Examples', 'Actions');
- $return_html .= theme_table($chapter_header, $chapter_rows);
+ $chapter_header = array('Chapter No.', 'Title of the Chapter', 'Uploaded Examples', 'Actions');
+ $return_html .= theme('table', array('header' => $chapter_header, 'rows' => $chapter_rows));
return $return_html;
}
@@ -83,8 +118,18 @@ function list_examples()
global $user;
/************************ start approve book details ************************/
- $proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE uid = %d ORDER BY id DESC LIMIT 1", $user->uid);
- $proposal_data = db_fetch_object($proposal_q);
+
+ /*$proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE uid = %d ORDER BY id DESC LIMIT 1", $user->uid);
+ $proposal_data = db_fetch_object($proposal_q);*/
+
+ $query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal');
+ $query->condition('uid', $user->uid);
+ $query->orderBy('id', 'DESC');
+ $query->range(0, 1);
+ $result = $query->execute();
+ $proposal_data =$result->fetchObject();
+
if (!$proposal_data)
{
drupal_set_message("Please submit a " . l('proposal', 'proposal') . ".", 'error');
@@ -117,8 +162,17 @@ function list_examples()
}
}
- $preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND approval_status = 1 LIMIT 1", $proposal_data->id);
- $preference_data = db_fetch_object($preference_q);
+ /*$preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND approval_status = 1 LIMIT 1", $proposal_data->id);
+ $preference_data = db_fetch_object($preference_q);*/
+
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('proposal_id', $proposal_data->id);
+ $query->condition('approval_status', 1);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $preference_data =$result->fetchObject();
+
if (!$preference_data)
{
drupal_set_message(t('Invalid Book Preference status. Please contact site administrator for further information.'), 'error');
@@ -129,8 +183,17 @@ function list_examples()
/* get chapter details */
$chapter_id = arg(3);
- $chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE id = %d AND preference_id = %d LIMIT 1", $chapter_id, $preference_data->id);
- if ($chapter_data = db_fetch_object($chapter_q))
+
+ /*$chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE id = %d AND preference_id = %d LIMIT 1", $chapter_id, $preference_data->id);*/
+
+ $query = db_select('textbook_companion_chapter');
+ $query->fields('textbook_companion_chapter');
+ $query->condition('id', $chapter_id);
+ $query->condition('preference_id',$preference_data->id);
+ $query->range(0, 1);
+ $chapter_q = $query->execute();
+
+ if ($chapter_data = $chapter_q->fetchObject())
{
$return_html = '<br />';
$return_html .= '<strong>Title of the Book:</strong><br />' . $preference_data->book . '<br /><br />';
@@ -147,11 +210,18 @@ function list_examples()
/* get example list */
$example_rows = array();
- $example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d ORDER BY
+
+ /*$example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d ORDER BY
CAST(SUBSTRING_INDEX(number, '.', 1) AS BINARY) ASC,
CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(number , '.', 2), '.', -1) AS UNSIGNED) ASC,
- CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(number , '.', -1), '.', 1) AS UNSIGNED) ASC", $chapter_id);
- while ($example_data = db_fetch_object($example_q))
+ CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(number , '.', -1), '.', 1) AS UNSIGNED) ASC", $chapter_id);*/
+
+ $query = db_select('textbook_companion_example');
+ $query->fields('textbook_companion_example');
+ $query->condition('chapter_id', $chapter_id);
+ $example_q= $query->execute();
+
+ while ($example_data = $example_q->fetchObject())
{
/* approval status */
$approval_status = '';
@@ -164,8 +234,16 @@ function list_examples()
/* example files */
$example_files = '';
- $example_files_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE example_id = %d ORDER BY filetype", $example_data->id);
- while ($example_files_data = db_fetch_object($example_files_q))
+
+ /*$example_files_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE example_id = %d ORDER BY filetype", $example_data->id);*/
+
+ $query = db_select('textbook_companion_example_files');
+ $query->fields('textbook_companion_example_files');
+ $query->condition('example_id', $example_data->id);
+ $query->orderBy('filetype', 'ASC');
+ $example_files_q = $query->execute();
+
+ while ($example_files_data = $example_files_q->fetchObject())
{
$file_type = '';
switch ($example_files_data->filetype)
@@ -179,11 +257,20 @@ function list_examples()
}
/* dependency files */
$dependency_files = '';
+
$dependency_files_q = db_query("SELECT dependency.id as dependency_id, dependency.filename as dependency_filename
FROM {textbook_companion_example_dependency} example_dependency JOIN {textbook_companion_dependency_files} dependency
ON example_dependency.dependency_id = dependency.id
- WHERE example_dependency.example_id = %d", $example_data->id);
- while ($dependency_files_data = db_fetch_object($dependency_files_q))
+ WHERE example_dependency.example_id = :example_id", array(':example_id' => $example_data->id));
+
+ /*$query = db_select('textbook_companion_example_dependency', 'example_dependency');
+ $query->fields('dependency', array('id', 'filename'));
+ $query->innerJoin('textbook_companion_dependency_files', 'dependency', 'example_dependency.dependency_id = dependency.id');
+ $query->condition('example_dependency.example_id', $example_data->id);
+ $dependency_files_q = $query->execute();*/
+
+
+ while ($dependency_files_data = $dependency_files_q->fetchObject())
{
$dependency_files .= l($dependency_files_data->dependency_filename, 'download/dependency/' . $dependency_files_data->dependency_id) . ' (Dependency)<br />';
}
@@ -198,6 +285,6 @@ function list_examples()
}
$example_header = array('Example No.', 'Caption', 'Status', 'Files', 'Action');
- $return_html .= theme_table($example_header, $example_rows);
+ $return_html .= theme('table',array('header'=>$example_header,'rows'=>$example_rows));
return $return_html;
}
diff --git a/latex.inc b/latex.inc
index 7dfbe83..18d641f 100755
--- a/latex.inc
+++ b/latex.inc
@@ -3,6 +3,10 @@
function textbook_companion_download_book()
{
$preference_id = arg(2);
+// drupal_set_message('This feature is currently unavailabe. We will resumes it shorty.','error');
+//drupal_goto('textbook_run/'. $preference_id);
+
+//exit;
_latex_copy_script_file();
$full_book = arg(3);
if ($full_book == "1")
@@ -26,8 +30,8 @@ function _latex_generate_files($preference_id, $full_book = FALSE)
$eol = "\n";
$sep = "#";
- $preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d", $preference_id);
- $preference_data = db_fetch_object($preference_q);
+ $preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = :id", array(':id' => $preference_id));
+ $preference_data = $preference_q->fetchObject();
if (!$preference_data)
{
drupal_set_message('Invalid book specified.', 'error');
@@ -45,42 +49,50 @@ function _latex_generate_files($preference_id, $full_book = FALSE)
del_book_pdf($preference_data->id);
/* check if book already generated */
+//var_dump(file_exists($dir_path . "book_" . $preference_data->id . ".pdf"));die;
+
if (file_exists($dir_path . "book_" . $preference_data->id . ".pdf"))
{
/* download zip file */
+ ob_clean();
+ header("Pragma: public");
+ header("Expires: 0");
+ header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
+ header("Cache-Control: public");
+ header("Content-Description: File Transfer");
header('Content-Type: application/pdf');
header('Content-disposition: attachment; filename="' . $preference_data->book . '_' . $preference_data->author . '.pdf"');
header('Content-Length: ' . filesize($dir_path . "book_" . $preference_data->id . ".pdf"));
- header("Content-Transfer-Encoding: binary");
- header('Expires: 0');
- header('Pragma: no-cache');
- ob_end_flush();
- ob_clean();
- flush();
+ //header("Content-Transfer-Encoding: binary");
+ //header('Expires: 0');
+ //header('Pragma: no-cache');
+ //ob_end_flush();
+ //ob_clean();
+ //flush();
readfile($dir_path . "book_" . $preference_data->id . ".pdf");
return;
}
- $proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d", $preference_data->proposal_id);
- $proposal_data = db_fetch_object($proposal_q);
+ $proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = :id", array(':id' => $preference_data->proposal_id));
+ $proposal_data = $proposal_q->fetchObject();
if (!$proposal_data)
{
drupal_set_message('Could not fetch contributors information for the book specified.', 'error');
}
$contributor_filedata .= $proposal_data->full_name . $sep . $proposal_data->course . $sep . $proposal_data->branch . $sep . $proposal_data->university . $sep . $proposal_data->faculty . $sep . $proposal_data->reviewer . $eol;
- $chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE preference_id = %d ORDER BY number DESC", $preference_data->id);
- while ($chapter_data = db_fetch_object($chapter_q))
+ $chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE preference_id = :id ORDER BY number DESC", array(':id' => $preference_data->id));
+ while ($chapter_data = $chapter_q->fetchObject())
{
if ($full_book)
- $example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d ORDER BY number DESC", $chapter_data->id);
+ $example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE chapter_id = :id ORDER BY number DESC", array(':id' => $chapter_data->id));
else
- $example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d AND approval_status = 1 ORDER BY number DESC", $chapter_data->id);
- while ($example_data = db_fetch_object($example_q))
+ $example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE chapter_id = :id AND approval_status = 1 ORDER BY number DESC", array(':id' => $chapter_data->id));
+ while ($example_data = $example_q->fetchObject())
{
- $example_files_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE example_id = %d", $example_data->id);
- while ($example_files_data = db_fetch_object($example_files_q))
+ $example_files_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE example_id = :id", array(':id' => $example_data->id));
+ while ($example_files_data = $example_files_q->fetchObject())
{
$latex_filedata .= $chapter_data->number . $sep;
$latex_filedata .= $chapter_data->name . $sep;
@@ -93,11 +105,11 @@ function _latex_generate_files($preference_id, $full_book = FALSE)
$latex_filedata .= $example_files_data->id;
$latex_filedata .= $eol;
}
- $dependency_files_q = db_query("SELECT * FROM {textbook_companion_example_dependency} WHERE example_id = %d", $example_data->id);
- while ($dependency_files_data = db_fetch_object($dependency_files_q))
+ $dependency_files_q = db_query("SELECT * FROM {textbook_companion_example_dependency} WHERE example_id = :id",array(':id' => $example_data->id));
+ while ($dependency_files_data = $dependency_files_q->fetchObject())
{
- $dependency_q = db_query("SELECT * FROM {textbook_companion_dependency_files} WHERE id = %d LIMIT 1", $dependency_files_data->dependency_id);
- if ($dependency_data = db_fetch_object($dependency_q))
+ $dependency_q = db_query("SELECT * FROM {textbook_companion_dependency_files} WHERE id = :id LIMIT 1", array(':id' => $dependency_files_data->dependency_id));
+ if ($dependency_data = $dependency_q->fetchObject())
{
$latex_filedata .= $chapter_data->number . $sep;
$latex_filedata .= $chapter_data->name . $sep;
@@ -117,8 +129,8 @@ function _latex_generate_files($preference_id, $full_book = FALSE)
}
foreach ($depedency_list as $row => $data) {
- $dependency_q = db_query("SELECT * FROM {textbook_companion_dependency_files} WHERE id = %d LIMIT 1", $row);
- if ($dependency_data = db_fetch_object($dependency_q))
+ $dependency_q = db_query("SELECT * FROM {textbook_companion_dependency_files} WHERE id = :id LIMIT 1", array(':id' =>$row));
+ if ($dependency_data = $dependency_q->fetchObject())
{
$latex_dep_filedata .= $dependency_data->filename . $sep;
$latex_dep_filedata .= $dependency_data->filepath . $sep;
@@ -153,6 +165,7 @@ function _latex_generate_files($preference_id, $full_book = FALSE)
$fd = fopen($dir_path . $latex_dep_filename, 'w');
fwrite($fd, $latex_dep_filedata);
fclose($fd);
+//var_dump($dir_path . "book_" . $preference_data->id . ".pdf");die;
if (_latex_run_script($book_filename, $contributor_filename, $latex_filename, $latex_dep_filename, $pdf_filename))
{
@@ -163,11 +176,12 @@ function _latex_generate_files($preference_id, $full_book = FALSE)
header("Content-Transfer-Encoding: binary");
header('Expires: 0');
header('Pragma: no-cache');
+
+
+ @readfile($dir_path . $pdf_filename);
ob_end_flush();
ob_clean();
flush();
-
- readfile($dir_path . $pdf_filename);
} else {
drupal_set_message("Error occurred when generating the PDF version of the Book.", 'error');
}
@@ -191,16 +205,19 @@ function _latex_run_script($book_filename, $contributor_filename, $latex_filenam
chdir("uploads");
chdir("latex");
-
- $sh_command = "./pdf_creator.sh " . $book_filename . " " . $contributor_filename . " " . $latex_filename . " " . $latex_dep_filename;
+//var_dump($book_filename . " " . $contributor_filename . " " . $latex_filename . " " . $latex_dep_filename);die;
+ $sh_command = "./pdf_creator.sh " . $book_filename . " " . $contributor_filename . " " . $latex_filename . " " . $latex_dep_filename . " " . $pdf_filename;
exec($sh_command);
- exec("mv TEX_final.pdf " . $pdf_filename);
-
- if ($ret == 0)
+// var_dump(exec($sh_command));die;
+//exec("mv TEX_final.pdf " , $pdf_filename);
+ // rename('TEX_final.pdf', $pdf_filename);
+//var_dump($pdf_filename);die;
+ if ($ret == 0){
return TRUE;
- else
+ } else{
return FALSE;
}
+}
function textbook_companion_delete_book()
{
@@ -211,3 +228,4 @@ function textbook_companion_delete_book()
return;
}
+
diff --git a/latex/Initial_body b/latex/Initial_body
index c8d3576..f24ec0e 100755
--- a/latex/Initial_body
+++ b/latex/Initial_body
@@ -1,58 +1,59 @@
\nonstopmode
-\documentclass[12pt]{report}
-\usepackage{hyperref}
-\hypersetup{colorlinks=true,linkcolor=blue}
-\usepackage{theorem,graphicx}
-\usepackage{listings,alltt}
-\bibliographystyle{plain}
-
-
-\lstset{ %configuring the display of scilab codes
- tabsize=4,
- language=scilab,
- basicstyle=\ttfamily,
- aboveskip={1\baselineskip},
- showstringspaces=false,
- breaklines=true,
- showspaces=false,
- numbers=left,
- numberstyle=\small,
- stringstyle=\normalfont,
- keywordstyle=\color{red},
- emph={clc, all, gca},
- emphstyle=\color{red},
- commentstyle=\color{blue}\normalfont}
-
-
-% code environment
-{\theorembodyfont{\rmfamily} \newtheorem{codemass}{Scilab code}[chapter]}
-\newenvironment{code}%
-{\begin{codemass}}{\hrule \end{codemass}}
-
-{\theorembodyfont{\rmfamily} \newtheorem{accmass}{Acc}[chapter]}
-\newenvironment{acc-code}%
-{\begin{accmass}}{\end{accmass}}
-
-
-% create listing for code
-
-\newcommand\tcaption[1]
- {\addcontentsline{cod}{section}{\protect\numberline {\thecodemass}#1}}
-\makeatletter \newcommand\listofcode
- {\chapter*{List of Scilab Codes\markboth%
- {\bf List of Scilab Codes}{}}%
-\renewcommand*\l@section{\@dottedtocline{1}{1.5em}{5em}}%
-\addcontentsline{toc}{chapter}{\protect\numberline{List of Scilab Codes}}
-\@starttoc{cod}}
-\newcommand\l@matlab[3]
- {#1 \par\noindent#2, #3 \par}
-\renewcommand\@pnumwidth{2.1em}
-%\makeatother
-
-\makeatletter
-\def\curlable#1{\def\thecodemass{#1}\def\@currentlabel{#1}}
-\makeatother
-
-\newcommand{\coderef}[1]{Exa~\ref{#1}}
-\newcommand{\figref}[1]{Fig.~\ref{#1}}
+\documentclass[12pt]{report}
+\usepackage{hyperref}
+\usepackage{bookmark}
+\hypersetup{colorlinks=true,linkcolor=blue}
+\usepackage{theorem,graphicx}
+\usepackage{listings,alltt}
+\bibliographystyle{plain}
+
+
+\lstset{ %configuring the display of scilab codes
+ tabsize=4,
+ language=scilab,
+ basicstyle=\ttfamily,
+ aboveskip={1\baselineskip},
+ showstringspaces=false,
+ breaklines=true,
+ showspaces=false,
+ numbers=left,
+ numberstyle=\small,
+ stringstyle=\normalfont,
+ keywordstyle=\color{red},
+ emph={clc, all, gca},
+ emphstyle=\color{red},
+ commentstyle=\color{blue}\normalfont}
+
+
+% code environment
+{\theorembodyfont{\rmfamily} \newtheorem{codemass}{Scilab code}[chapter]}
+\newenvironment{code}%
+{\begin{codemass}}{\hrule \end{codemass}}
+
+{\theorembodyfont{\rmfamily} \newtheorem{accmass}{Acc}[chapter]}
+\newenvironment{acc-code}%
+{\begin{accmass}}{\end{accmass}}
+
+
+% create listing for code
+
+\newcommand\tcaption[1]
+ {\addcontentsline{cod}{section}{\protect\numberline {\thecodemass}#1}}
+\makeatletter \newcommand\listofcode
+ {\chapter*{List of Scilab Codes\markboth%
+ {\bf List of Scilab Codes}{}}%
+\renewcommand*\l@section{\@dottedtocline{1}{1.5em}{5em}}%
+\addcontentsline{toc}{chapter}{\protect\numberline{List of Scilab Codes}}
+\@starttoc{cod}}
+\newcommand\l@matlab[3]
+ {#1 \par\noindent#2, #3 \par}
+\renewcommand\@pnumwidth{2.1em}
+%\makeatother
+
+\makeatletter
+\def\curlable#1{\def\thecodemass{#1}\def\@currentlabel{#1}}
+\makeatother
+
+\newcommand{\coderef}[1]{Exa~\ref{#1}}
+\newcommand{\figref}[1]{Fig.~\ref{#1}}
diff --git a/latex/latex_test.sh b/latex/latex_test.sh
index 5d67cb5..4c11be7 100755
--- a/latex/latex_test.sh
+++ b/latex/latex_test.sh
@@ -1,7 +1,7 @@
#!/bin/bash
clear
-Bk_details=$1
-Contrib_details=$2
+CBk_details=$1
+CContrib_details=$2
Data_all=$3
Dep_dat=$4
@@ -24,8 +24,8 @@ fi
IFS_old="$IFS"
-IFS=# read col1 col2 col3 col4 col5 col6 col7 col8 < $Contrib_details;
-IFS=# read colB1 colB2 colB3 colB4 colB5 colB6 colB7 < $Bk_details;
+IFS=# read col1 col2 col3 col4 col5 col6 col7 col8 < "$CContrib_details";
+IFS=# read colB1 colB2 colB3 colB4 colB5 colB6 colB7 < "$CBk_details";
col1=${col1/&/\\&};
col2=${col2/&/\\&};
col3=${col3/&/\\&};
diff --git a/latex/pdf_creator.sh b/latex/pdf_creator.sh
index 2e2cbe0..1276374 100755
--- a/latex/pdf_creator.sh
+++ b/latex/pdf_creator.sh
@@ -1,7 +1,8 @@
-$ cat changedir.sh
+#$ cat changedir.sh
#!/bin/bash
+export PATH=$PATH:/usr/local/texlive/2015/bin/x86_64-linux
-
+#unalias rm
if [ -f TEX_final.tex ]
then
rm TEX_final.*
@@ -13,7 +14,7 @@ fi
./latex_test.sh $1 $2 $3 $4
pdflatex TEX_final.tex > log.txt
pdflatex TEX_final.tex >> log1.txt
-pdflatex TEX_final.tex >> log1.txt
-pdflatex TEX_final.tex >> log1.txt
-
+#pdflatex TEX_final.tex >> log1.txt
+#pdflatex TEX_final.tex >> log1.txt
+mv -v TEX_final.pdf $5 >> log.txt
rm log1.txt
diff --git a/manage_proposal.inc b/manage_proposal.inc
index d6d6028..68f3590 100755
--- a/manage_proposal.inc
+++ b/manage_proposal.inc
@@ -5,8 +5,16 @@ function _proposal_pending()
{
/* get pending proposals to be approved */
$pending_rows = array();
- $pending_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE proposal_status = 0 ORDER BY id DESC");
- while ($pending_data = db_fetch_object($pending_q))
+
+ /*$pending_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE proposal_status = 0 ORDER BY id DESC");*/
+
+ $query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal');
+ $query->condition('proposal_status', 0);
+ $query->orderBy('id', 'DESC');
+ $pending_q = $query->execute();
+
+ while ($pending_data = $pending_q->fetchObject())
{
$pending_rows[$pending_data->id] = array(date('d-m-Y', $pending_data->creation_date), l($pending_data->full_name, 'user/' . $pending_data->uid), date('d-m-Y', $pending_data->completion_date), l('Approve', 'manage_proposal/approve/' . $pending_data->id) . ' | ' . l('Edit', 'manage_proposal/edit/' . $pending_data->id));
}
@@ -19,7 +27,7 @@ function _proposal_pending()
}
$pending_header = array('Date of Submission', 'Contributor Name', 'Date of Completion', 'Action');
- $output = theme_table($pending_header, $pending_rows);
+ $output = theme('table',array('header'=>$pending_header, 'rows'=>$pending_rows));
return $output;
}
@@ -35,16 +43,42 @@ function _proposal_all()
}
/* get pending proposals to be approved */
$proposal_rows = array();
- $proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} ORDER BY id DESC");
- while ($proposal_data = db_fetch_object($proposal_q))
+
+ /*$proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} ORDER BY id DESC");*/
+
+ $query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal');
+ $query->orderBy('id', 'DESC');
+ $proposal_q = $query->execute();
+
+ while ($proposal_data = $proposal_q->fetchObject())
{
/* get preference */
- $preference_q = db_query("SELECT * FROM textbook_companion_preference WHERE proposal_id = %d AND approval_status = 1 LIMIT 1", $proposal_data->id);
- $preference_data = db_fetch_object($preference_q);
+
+ /*$preference_q = db_query("SELECT * FROM textbook_companion_preference WHERE proposal_id = %d AND approval_status = 1 LIMIT 1", $proposal_data->id);
+ $preference_data = db_fetch_object($preference_q);*/
+
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('proposal_id', $proposal_data->id);
+ $query->condition('approval_status', 1);
+ $query->range(0, 1);
+ $preference_q = $query->execute();
+ $preference_data=$preference_q->fetchObject();
+
if(!$preference_data){
- $preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = 1 LIMIT 1", $proposal_data->id);
- $preference_data = db_fetch_object($preference_q);
- }
+
+ /* $preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = 1 LIMIT 1", $proposal_data->id);
+ $preference_data = db_fetch_object($preference_q);*/
+
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('proposal_id', $proposal_data->id);
+ $query->condition('pref_number', 1);
+ $query->range(0, 1);
+ $preference_q = $query->execute();
+ $preference_data =$preference_q->fetchObject();
+ }
$proposal_status = '';
switch ($proposal_data->proposal_status)
@@ -75,7 +109,7 @@ function _proposal_all()
}
$proposal_header = array('Date of Submission', 'Title of the Book', 'Contributor Name', 'Expected Date of Completion', 'Status', 'Action');
- $output = theme_table($proposal_header, $proposal_rows);
+ $output = theme('table',array('header'=>$proposal_header, 'rows'=>$proposal_rows));
return $output;
}
@@ -83,8 +117,17 @@ function _category_all()
{
/* get pending proposals to be approved */
$preference_rows = array();
- $preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE approval_status = 1 ORDER BY id DESC");
- while ($preference_data = db_fetch_object($preference_q))
+
+ /*$preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE approval_status = 1 ORDER BY id DESC");*/
+
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('approval_status', 1);
+ $query->orderBy('id', 'DESC');
+ $preference_q = $query->execute();
+
+
+ while ($preference_data =$preference_q->fetchObject())
{
switch ($preference_data->category)
{
@@ -108,7 +151,7 @@ function _category_all()
}
$preference_header = array('Book', 'ISBN', 'Publisher', 'Edition', 'Year', 'Category', 'Status');
- $output = theme_table($preference_header, $preference_rows);
+ $output = theme('table',array('header'=>$preference_header, 'rows'=>$preference_rows));
return $output;
}
@@ -116,16 +159,24 @@ function _category_all()
/************************** PROPOSAL APPROVAL FORM ****************************/
/******************************************************************************/
-function proposal_approval_form($form_state)
+function proposal_approval_form($form,$form_state)
{
global $user;
/* get current proposal */
$proposal_id = arg(2);
- $result = db_query("SELECT * FROM {textbook_companion_proposal} WHERE proposal_status = 0 and id = %d", $proposal_id);
+
+ /*$result = db_query("SELECT * FROM {textbook_companion_proposal} WHERE proposal_status = 0 and id = %d", $proposal_id);*/
+
+ $query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal');
+ $query->condition('proposal_status', 0);
+ $query->condition('id', $proposal_id);
+ $result = $query->execute();
+
if ($result)
{
- if ($row = db_fetch_object($result))
+ if ($row =$result->fetchObject())
{
/* everything ok */
} else {
@@ -141,79 +192,103 @@ function proposal_approval_form($form_state)
$form['full_name'] = array(
'#type' => 'item',
- '#value' => l($row->full_name, 'user/' . $row->uid),
+ '#markup' => l($row->full_name, 'user/' . $row->uid),
'#title' => t('Contributor Name'),
);
$form['email'] = array(
'#type' => 'item',
- '#value' => user_load($row->uid)->mail,
+ '#markup' => user_load($row->uid)->mail,
'#title' => t('Email'),
);
$form['mobile'] = array(
'#type' => 'item',
- '#value' => $row->mobile,
+ '#markup' => $row->mobile,
'#title' => t('Mobile'),
);
$form['how_project'] = array(
'#type' => 'item',
- '#value' => $row->how_project,
+ '#markup' => $row->how_project,
'#title' => t('How did you come to know about this project'),
);
$form['course'] = array(
'#type' => 'item',
- '#value' => $row->course,
+ '#markup' => $row->course,
'#title' => t('Course'),
);
$form['branch'] = array(
'#type' => 'item',
- '#value' => $row->branch,
+ '#markup' => $row->branch,
'#title' => t('Department/Branch'),
);
$form['university'] = array(
'#type' => 'item',
- '#value' => $row->university,
+ '#markup' => $row->university,
'#title' => t('University/Institute'),
);
+ $form['city'] = array(
+ '#type' => 'item',
+ '#markup' => $row->city,
+ '#title' => t('City'),
+ );
+ $form['pincode'] = array(
+ '#type' => 'item',
+ '#markup' => $row->pincode,
+ '#title' => t('Pincode'),
+ );
+ $form['all_state'] = array(
+ '#type' => 'item',
+ '#markup' => $row->state,
+ '#title' => t('State'),
+ );
$form['faculty'] = array(
'#type' => 'item',
- '#value' => $row->faculty,
+ '#markup' => $row->faculty,
'#title' => t('College Teacher/Professor'),
);
$form['reviewer'] = array(
'#type' => 'item',
- '#value' => $row->reviewer,
+ '#markup' => $row->reviewer,
'#title' => t('Reviewer'),
);
$form['completion_date'] = array(
'#type' => 'item',
- '#value' => date('d-m-Y', $row->completion_date),
+ '#markup' => date('d-m-Y', $row->completion_date),
'#title' => t('Expected Date of Completion'),
);
$form['operating_system'] = array(
'#type' => 'item',
- '#value' => $row->operating_system,
+ '#markup' => $row->operating_system,
'#title' => t('Operating System'),
);
$form['scilab_version'] = array(
'#type' => 'item',
- '#value' => $row->scilab_version,
+ '#markup' => $row->scilab_version,
'#title' => t('Scilab Version'),
);
$form['reference'] = array(
'#type' => 'item',
- '#value' => $row->reference,
+ '#markup' => $row->reference,
'#title' => t('References'),
);
$form['reason'] = array(
'#type' => 'item',
- '#value' => $row->reason,
+ '#markup' => $row->reason,
'#title' => t('Reasons'),
);
/* get book preference */
$preference_rows = array();
- $preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d ORDER BY pref_number ASC", $proposal_id);
- while ($preference_data = db_fetch_object($preference_q))
+
+ $preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = :proposal_id ORDER BY pref_number ASC", array(':proposal_id' => $proposal_id));
+
+ /*$query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('proposal_id', $proposal_id);
+ $query->orderBy('pref_number', 'ASC');
+ $preference_q = $query->execute();*/
+
+
+ while ($preference_data = $preference_q->fetchObject())
{
$preference_rows[$preference_data->id] = $preference_data->book . ' (Written by ' . $preference_data->author . ')';
}
@@ -245,11 +320,16 @@ function proposal_approval_form($form_state)
'#title' => t('Reason for disapproval'),
);
- $form['proposal_id'] = array(
+ $form['proposal_type'] = array(
+ '#type' => 'hidden',
+ '#value' => $row->proposal_type,
+ );
+ $form['proposal_id'] = array(
'#type' => 'hidden',
'#value' => $proposal_id,
);
+
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit')
@@ -268,10 +348,18 @@ function proposal_approval_form_submit($form, &$form_state)
/* get current proposal */
$proposal_id = $form_state['values']['proposal_id'];
- $result = db_query("SELECT * FROM {textbook_companion_proposal} WHERE proposal_status = 0 and id = %d", $proposal_id);
+
+ $result = db_query("SELECT * FROM {textbook_companion_proposal} WHERE proposal_status = 0 and id = :proposal_id",array(':proposal_id' => $proposal_id));
+
+ /*$query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal');
+ $query->condition('proposal_status', 0);
+ $query->condition('id',$proposal_id);
+ $result = $query->execute();*/
+
if ($result)
{
- if ($row = db_fetch_object($result))
+ if ($row = $result->fetchObject())
{
/* everything ok */
} else {
@@ -288,16 +376,48 @@ function proposal_approval_form_submit($form, &$form_state)
/* disapprove */
if ($form_state['values']['disapprove'])
{
- db_query("UPDATE {textbook_companion_proposal} SET approver_uid = %d, approval_date = %d, proposal_status = 2, message = '%s' WHERE id = %d", $user->uid, time(), $form_state['values']['message'], $proposal_id);
- db_query("UPDATE {textbook_companion_preference} SET approval_status = 2 WHERE proposal_id = %d", $proposal_id);
+//var_dump(array(':approver_uid' => $user->uid,':approver_date'=> time(), ':message' => $form_state['values']['message'], ':id' =>$proposal_id));die;
+ db_query("UPDATE {textbook_companion_proposal} SET approver_uid = :approver_uid, approval_date = :approval_date, proposal_status = 2, message = :message WHERE id = :id", array(':approver_uid' => $user->uid,':approval_date'=> time(), ':message' => $form_state['values']['message'], ':id' =>$proposal_id));
+
+ /*$query = db_update('textbook_companion_proposal');
+ $query->fields(array(
+ 'approver_uid' => $user->uid,
+ 'approval_date' => $current_date,
+ 'proposal_status' => 2,
+ 'message' => $form_state['values']['message'],
+ ));
+ $query->condition('id', $proposal_id);
+ $num_updated = $query->execute();
+var_dump($num_updated);die;*/
+ db_query("UPDATE {textbook_companion_preference} SET approval_status = 2 WHERE proposal_id = :id",array(':id' => $proposal_id));
+
+ /*$query = db_update('textbook_companion_preference');
+ $query->fields(array(
+ 'approval_status' => 2,
+ ));
+ $query->condition('proposal_id',$proposal_id);
+ $num_updated = $query->execute();
+*/
/* unlock all the aicte books */
+if($form_state['values']['proposal_type']==0){
$query = "
UPDATE textbook_companion_aicte
SET status = 0, uid = 0, proposal_id = 0, preference_id = 0
- WHERE proposal_id = {$proposal_id}
+ WHERE proposal_id = {:proposal_id}
";
- db_query($query);
+ db_query($query, array(':proposal_id' => $proposal_id));
+
+ /*$query = db_update('textbook_companion_aicte');
+ $query->fields(array(
+ 'status' => 0,
+ 'uid' => 0,
+ 'proposal_id' => 0,
+ 'preference_id' => 0,
+ ));
+ $query->condition('proposal_id', $proposal_id);
+ $num_updated = $query->execute();*/
+}
/* sending email */
$book_user = user_load($row->uid);
$param['proposal_disapproved']['proposal_id'] = $proposal_id;
@@ -313,16 +433,52 @@ function proposal_approval_form_submit($form, &$form_state)
/* get book preference and set the status */
$preference_id = $form_state['values']['book_preference'];
- db_query("UPDATE {textbook_companion_proposal} SET approver_uid = %d, approval_date = %d, proposal_status = 1 WHERE id = %d", $user->uid, time(), $proposal_id);
- db_query("UPDATE {textbook_companion_preference} SET approval_status = 1 WHERE id = %d", $preference_id);
+
+ /*db_query("UPDATE {textbook_companion_proposal} SET approver_uid = %d, approval_date = %d, proposal_status = 1 WHERE id = %d", $user->uid, time(), $proposal_id);*/
+
+ $query = db_update('textbook_companion_proposal');
+ $query->fields(array(
+ 'approver_uid' => $user->uid,
+ 'approval_date' => time(),
+ 'proposal_status' => 1,
+ ));
+ $query->condition('id', $proposal_id);
+ $num_updated = $query->execute();
+
+ /*db_query("UPDATE {textbook_companion_preference} SET approval_status = 1 WHERE id = %d", $preference_id);*/
+
+ $query = db_update('textbook_companion_preference');
+ $query->fields(array(
+ 'approval_status' => 1,
+ ));
+ $query->condition('id', $preference_id);
+ $num_updated = $query->execute();
/* unlock aicte books except the one which was approved out of 3 nos */
- $query = "
+
+ /* $query = "
UPDATE textbook_companion_aicte
SET status = 0, uid = 0, proposal_id = 0, preference_id = 0
WHERE proposal_id = {$proposal_id} AND preference_id != {$preference_id}
";
- db_query($query);
+ db_query($query);*/
+
+ $query = "
+ UPDATE textbook_companion_aicte
+ SET status = 0, uid = 0, proposal_id = 0, preference_id = 0
+ WHERE proposal_id = {:proposal_id} AND preference_id != {:preference_id}
+ ";
+ db_query($query,array(':proposal_id' => $proposal_id, ':preference_id'=> $preference_id));
+ /*$query = db_update('textbook_companion_aicte');
+ $query->fields(array(
+ 'status' => 0,
+ 'uid' => 0,
+ 'proposal_id' => 0,
+ 'preference_id' => 0,
+ ));
+ $query->condition('proposal_id', $proposal_id);
+ $query->condition('preference_id', $preference_id, '<>');
+ $num_updated = $query->execute();
/* sending email */
$book_user = user_load($row->uid);
@@ -348,8 +504,15 @@ function proposal_status_form($form_state)
/* get current proposal */
$proposal_id = arg(2);
- $proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d", $proposal_id);
- if (!$proposal_data = db_fetch_object($proposal_q))
+
+ /*$proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d", $proposal_id);*/
+
+ $query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal');
+ $query->condition('id', $proposal_id);
+ $proposal_q = $query->execute();
+
+ if (!$proposal_data = $proposal_q->fetchObject())
{
drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
drupal_goto('manage_proposal');
@@ -358,74 +521,90 @@ function proposal_status_form($form_state)
$form['full_name'] = array(
'#type' => 'item',
- '#value' => $proposal_data->full_name,
+ '#markup' => $proposal_data->full_name,
'#title' => t('Contributor Name'),
);
$form['email'] = array(
'#type' => 'item',
- '#value' => user_load($proposal_data->uid)->mail,
+ '#markup' => user_load($proposal_data->uid)->mail,
'#title' => t('Email'),
);
$form['mobile'] = array(
'#type' => 'item',
- '#value' => $proposal_data->mobile,
+ '#markup' => $proposal_data->mobile,
'#title' => t('Mobile'),
);
$form['how_project'] = array(
'#type' => 'item',
- '#value' => $proposal_data->how_project,
+ '#markup' => $proposal_data->how_project,
'#title' => t('How did you come to know about this project'),
);
$form['course'] = array(
'#type' => 'item',
- '#value' => $proposal_data->course,
+ '#markup' => $proposal_data->course,
'#title' => t('Course'),
);
$form['branch'] = array(
'#type' => 'item',
- '#value' => $proposal_data->branch,
+ '#markup' => $proposal_data->branch,
'#title' => t('Department/Branch'),
);
$form['university'] = array(
'#type' => 'item',
- '#value' => $proposal_data->university,
+ '#markup' => $proposal_data->university,
'#title' => t('University/Institute'),
);
+ $form['city'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->city,
+ '#title' => t('City'),
+ );
+ $form['pincode'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->pincode,
+ '#title' => t('Pincode'),
+ );
+ $form['all_state'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->state,
+ '#title' => t('State'),
+ );
+
$form['faculty'] = array(
'#type' => 'item',
- '#value' => $proposal_data->faculty,
+ '#markup' => $proposal_data->faculty,
'#title' => t('College Teacher/Professor'),
);
$form['reviewer'] = array(
'#type' => 'item',
- '#value' => $proposal_data->reviewer,
+ '#markup' => $proposal_data->reviewer,
'#title' => t('Reviewer'),
);
$form['completion_date'] = array(
'#type' => 'item',
- '#value' => date('d-m-Y', $proposal_data->completion_date),
+ '#markup' => date('d-m-Y', $proposal_data->completion_date),
'#title' => t('Expected Date of Completion'),
);
$form['operating_system'] = array(
'#type' => 'item',
- '#value' => $proposal_data->operating_system,
+ '#markup' => $proposal_data->operating_system,
'#title' => t('Operating System'),
);
$form['scilab_version'] = array(
'#type' => 'item',
- '#value' => $proposal_data->scilab_version,
+ '#markup' => $proposal_data->scilab_version,
'#title' => t('Scilab Version'),
);
if($proposal_data->proposal_type == 1)
{
$form['reason'] = array(
'#type' => 'item',
- '#value' => $proposal_data->reason,
+ '#markup' => $proposal_data->reason,
'#title' => t('Reason'),
);
$form['reference'] = array(
'#type' => 'item',
- '#value' => $proposal_data->reference,
+ '#markup' => $proposal_data->reference,
'#title' => t('References'),
);
}
@@ -433,8 +612,16 @@ function proposal_status_form($form_state)
/* get book preference */
$preference_html = '<ul>';
- $preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d ORDER BY pref_number ASC", $proposal_id);
- while ($preference_data = db_fetch_object($preference_q))
+
+ /*$preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d ORDER BY pref_number ASC", $proposal_id);*/
+
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('proposal_id', $proposal_id);
+ $query->orderBy('pref_number', 'ASC');
+ $preference_q = $query->execute();
+
+ while ($preference_data =$preference_q->fetchObject())
{
if ($preference_data->approval_status == 1)
$preference_html .= '<li><strong>' . $preference_data->book . ' (Written by ' . $preference_data->author . ') - Approved Book</strong></li>';
@@ -445,7 +632,7 @@ function proposal_status_form($form_state)
$form['book_preference'] = array(
'#type' => 'item',
- '#value' => $preference_html,
+ '#markup' => $preference_html,
'#title' => t('Book Preferences'),
);
@@ -461,14 +648,14 @@ function proposal_status_form($form_state)
}
$form['proposal_status'] = array(
'#type' => 'item',
- '#value' => $proposal_status,
+ '#markup' => $proposal_status,
'#title' => t('Proposal Status'),
);
if ($proposal_data->proposal_status == 2) {
$form['message'] = array(
'#type' => 'item',
- '#value' => $proposal_data->message,
+ '#markup' => $proposal_data->message,
'#title' => t('Reason for disapproval'),
);
}
@@ -486,7 +673,7 @@ function proposal_status_form($form_state)
{
$form['approve'] = array(
'#type' => 'item',
- '#value' => l('Click here', 'manage_proposal/approve/' . $proposal_id),
+ '#markup' => l('Click here', 'manage_proposal/approve/' . $proposal_id),
'#title' => t('Approve'),
);
}
@@ -514,8 +701,15 @@ function proposal_status_form_submit($form, &$form_state)
/* get current proposal */
$proposal_id = $form_state['values']['proposal_id'];
- $proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d", $proposal_id);
- if (!$proposal_data = db_fetch_object($proposal_q))
+
+ /*$proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d", $proposal_id);*/
+
+ $query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal');
+ $query->condition('id', $proposal_id);
+ $proposal_q = $query->execute();
+
+ if (!$proposal_data = $proposal_q->fetchObject())
{
drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
drupal_goto('manage_proposal');
@@ -525,7 +719,15 @@ function proposal_status_form_submit($form, &$form_state)
/* set the book status to completed */
if ($form_state['values']['completed'] == 1)
{
- db_query("UPDATE {textbook_companion_proposal} SET proposal_status = 3 WHERE id = %d", $proposal_id);
+
+ /*db_query("UPDATE {textbook_companion_proposal} SET proposal_status = 3 WHERE id = %d", $proposal_id);*/
+
+ $query = db_update('textbook_companion_proposal');
+ $query->fields(array(
+ 'proposal_status' => 3,
+ ));
+ $query->condition('id', $proposal_id);
+ $num_updated = $query->execute();
/* sending email */
$book_user = user_load($proposal_data->uid);
@@ -552,10 +754,16 @@ function proposal_edit_form($form_state,$nonaicte_book)
/* get current proposal */
$proposal_id = arg(2);
- $proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d", $proposal_id);
+
+ /*$proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d", $proposal_id);*/
+ $query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal');
+ $query->condition('id', $proposal_id);
+ $proposal_q = $query->execute();
+
if ($proposal_q)
{
- $proposal_data = db_fetch_object($proposal_q);
+ $proposal_data = $proposal_q->fetchObject();
if (!$proposal_data)
{
drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
@@ -570,12 +778,38 @@ function proposal_edit_form($form_state,$nonaicte_book)
$user_data = user_load($proposal_data->uid);
- $preference1_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $proposal_id, 1);
- $preference1_data = db_fetch_object($preference1_q);
- $preference2_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $proposal_id, 2);
- $preference2_data = db_fetch_object($preference2_q);
- $preference3_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $proposal_id, 3);
- $preference3_data = db_fetch_object($preference3_q);
+ /* $preference1_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $proposal_id, 1);
+ $preference1_data = db_fetch_object($preference1_q);*/
+
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('proposal_id', $proposal_id);
+ $query->condition('pref_number', 1);
+ $query->range(0, 1);
+ $preference1_q = $query->execute();
+ $preference1_data =$preference1_q->fetchObject();
+
+ /*$preference2_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $proposal_id, 2);
+ $preference2_data = db_fetch_object($preference2_q);*/
+
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('proposal_id', $proposal_id);
+ $query->condition('pref_number', 2);
+ $query->range(0, 1);
+ $preference2_q = $query->execute();
+ $preference2_data =$preference2_q->fetchObject();
+
+ /*$preference3_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $proposal_id, 3);
+ $preference3_data = db_fetch_object($preference3_q);*/
+
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('proposal_id', $proposal_id);
+ $query->condition('pref_number', 3);
+ $query->range(0, 1);
+ $preference3_q = $query->execute();
+ $preference3_data =$preference3_q->fetchObject();
$form['full_name'] = array(
'#type' => 'textfield',
@@ -632,7 +866,7 @@ function proposal_edit_form($form_state,$nonaicte_book)
'Civil Engineering' => 'Civil Engineering',
'Physics' => 'Physics',
'Applied Physics' =>'Applied Physics',
- ' Nuclear Technology and Biotechnology' => ' Nuclear Technology and Biotechnology',
+ 'Nuclear Technology and Biotechnology' => ' Nuclear Technology and Biotechnology',
'Mathematics' => 'Mathematics',
'Others' => 'Others'),
'#required' => TRUE,
@@ -648,23 +882,34 @@ function proposal_edit_form($form_state,$nonaicte_book)
);
$form['city'] = array(
'#type' => 'textfield',
- '#title' => t('City/Village'),
- '#size' => 50,
- '#maxlength' => 50,
+ '#title' => t('City/ Village'),
+ '#size' => 80,
+ '#maxlength' => 150,
'#required' => TRUE,
+ '#attributes' =>array('placeholder' =>'Insert location of your institute/ university....'),
'#default_value' => $proposal_data->city,
- );
- $form['states'] = array(
- '#type' => 'select',
+
+ );
+$form['pincode'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Pincode'),
+ '#size' => 30,
+ '#maxlength' => 6,
+ '#required' => TRUE,
+ '#attributes' =>array('placeholder' =>'Insert pincode of your city/ village....'),
+ '#default_value' => $proposal_data->pincode,
+);
+$form['all_state'] = array(
+ '#type' => 'select',
'#title' => t('State'),
- '#options' => array (
- '' => 'Please select...',
- 'Andhra Pradesh' => 'Andhra Pradesh',
+ '#options' => array(
+ '0' => 'Please select...',
+ 'Andhra Pradesh' => t('Andhra Pradesh'),
'Arunachal Pradesh' => 'Arunachal Pradesh',
'Assam' => 'Assam',
'Bihar' => 'Bihar',
- 'CT' => 'Chhattisgarh',
- 'Chhattisgarh' => 'Goa',
+ 'Chhattisgarh' => 'Chhattisgarh',
+ 'Goa' => 'Goa',
'Gujarat' => 'Gujarat',
'Haryana' => 'Haryana',
'Himachal Pradesh' => 'Himachal Pradesh',
@@ -698,8 +943,10 @@ function proposal_edit_form($form_state,$nonaicte_book)
'Others' => 'Others',
),
'#required' => TRUE,
+ '#tree' => TRUE,
+ '#validated' => TRUE,
'#default_value' => $proposal_data->state,
- );
+);
$form['faculty'] = array(
'#type' => 'textfield',
'#title' => t('College Teacher/Professor'),
@@ -921,15 +1168,8 @@ if($preference3_data){
return $form;
}
-function proposal_edit_form_validate($form, &$form_state, &$nonaicte_book)
-
+function proposal_edit_form_validate($form, &$form_state)
{
- if($form_state['values']['city']== ''){
- form_set_error('city', t('Invalid city/village'));
- }
- if($form_state['values']['state']== ''){
- form_set_error('state', t('Invalid state'));
- }
/* mobile */
if (!preg_match('/^[0-9\ \+]{0,15}$/', $form_state['values']['mobile']))
@@ -997,10 +1237,28 @@ function proposal_edit_form_submit($form, &$form_state)
$proposal_id = $form_state['values']['hidden_proposal_id'];
- $query = "UPDATE {textbook_companion_proposal} SET full_name = '".$form_state['values']['full_name']."', mobile = '".$form_state['values']['mobile']."', how_project = '".$form_state['values']['how_project']."', course = '".$form_state['values']['course']."', branch = '".$form_state['values']['branch']."', university = '".$form_state['values']['university']."', city = '".$form_state['values']['city']."', state = '".$form_state['values']['state']."', faculty = '".$form_state['values']['faculty']."', reviewer = '".$form_state['values']['reviewer']."', completion_date = $completion_date_timestamp, operating_system= '".$form_state['values']['operating_system']."', scilab_version= '".$form_state['values']['scilab_version']."' WHERE id =".$proposal_id;
-
-
- db_query($query);
+ /*$query = "UPDATE {textbook_companion_proposal} SET full_name = '".$form_state['values']['full_name']."', mobile = '".$form_state['values']['mobile']."', how_project = '".$form_state['values']['how_project']."', course = '".$form_state['values']['course']."', branch = '".$form_state['values']['branch']."', university = '".$form_state['values']['university']."', faculty = '".$form_state['values']['faculty']."', reviewer = '".$form_state['values']['reviewer']."', completion_date = $completion_date_timestamp, operating_system= '".$form_state['values']['operating_system']."', scilab_version= '".$form_state['values']['scilab_version']."' WHERE id =".$proposal_id;
+ db_query($query);*/
+
+$query = db_update('textbook_companion_proposal');
+ $query->fields(array(
+ 'full_name' => $form_state['values']['full_name'],
+ 'mobile' => $form_state['values'][ 'mobile'],
+ 'how_project' => $form_state['values']['how_project'],
+ 'course' => $form_state['values']['course'],
+ 'branch' => $form_state['values']['branch'],
+ 'university' => $form_state['values']['university'],
+ 'city' => $form_state['values']['city'],
+ 'pincode' => $form_state['values']['pincode'],
+ 'state' => $form_state['values']['all_state'],
+ 'faculty' => $form_state['values']['faculty'],
+ 'reviewer' => $form_state['values']['reviewer'],
+ 'completion_date' => $completion_date_timestamp,
+ 'operating_system' => $form_state['values']['operating_system'],
+ 'scilab_version' => $form_state['values']['scilab_version'],
+ ));
+ $query->condition('id', $proposal_id);
+ $num_updated = $query->execute();
/*db_query("UPDATE {textbook_companion_proposal} SET full_name = '%s', mobile = '%s', how_project = '%s', course = '%s', branch = '%s', university = '%s', faculty = '%s', reviewer = '%s', completion_date = %d, operating_system= '%s', scilab_version= '%s' WHERE id = %d",
@@ -1017,56 +1275,131 @@ function proposal_edit_form_submit($form, &$form_state)
$form_state['values']['scilab_version'],
$proposal_id); */
- $preference1_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $proposal_id, 1);
- $preference1_data = db_fetch_object($preference1_q);
+
+
+ /*$preference1_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $proposal_id, 1);
+ $preference1_data = db_fetch_object($preference1_q);*/
+
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('proposal_id', $proposal_id);
+ $query->condition('pref_number', 1);
+ $query->range(0, 1);
+ $preference1_q = $query->execute();
+ $preference1_data =$preference1_q->fetchObject();
+
if ($preference1_data)
$preference1_id = $preference1_data->id;
- $preference2_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $proposal_id, 2);
- $preference2_data = db_fetch_object($preference2_q);
+
+ /*$preference2_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $proposal_id, 2);
+ $preference2_data = db_fetch_object($preference2_q);*/
+
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('proposal_id', $proposal_id);
+ $query->condition('pref_number', 2);
+ $query->range(0, 1);
+ $preference2_q = $query->execute();
+ $preference2_data = $preference2_q->fetchObject();
+
if ($preference2_data)
$preference2_id = $preference2_data->id;
- $preference3_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $proposal_id, 3);
- $preference3_data = db_fetch_object($preference3_q);
+
+ /*$preference3_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $proposal_id, 3);
+ $preference3_data = db_fetch_object($preference3_q);*/
+
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('proposal_id', $proposal_id);
+ $query->condition('pref_number', 3);
+ $query->range(0, 1);
+ $preference3_q = $query->execute();
+ $preference3_data =$preference3_q->fetchObject();
+
if ($preference3_data)
$preference3_id = $preference3_data->id;
if ($preference1_data)
{
del_book_pdf($preference1_data->id);
- db_query("UPDATE {textbook_companion_preference} SET book = '%s', author = '%s', isbn = '%s', publisher = '%s', edition = %d, year = %d WHERE id = %d",
+
+ /*db_query("UPDATE {textbook_companion_preference} SET book = '%s', author = '%s', isbn = '%s', publisher = '%s', edition = %d, year = %d WHERE id = %d",
$form_state['values']['book1'],
$form_state['values']['author1'],
$form_state['values']['isbn1'],
$form_state['values']['publisher1'],
$form_state['values']['edition1'],
$form_state['values']['year1'],
- $preference1_id);
+ $preference1_id);*/
+
+ $query = db_update('textbook_companion_preference');
+ $query->fields(array(
+ 'book' => $form_state['values']['book1'],
+ 'author' => $form_state['values']['author1'],
+ 'isbn' => $form_state['values']['isbn1'],
+ 'publisher' => $form_state['values']['publisher1'],
+ 'edition' => $form_state['values']['edition1'],
+ 'year' => $form_state['values']['year1'],
+ ));
+ $query->condition('id', $preference1_id);
+ $num_updated = $query->execute();
+
}
if ($preference2_data)
{
del_book_pdf($preference2_data->id);
- db_query("UPDATE {textbook_companion_preference} SET book = '%s', author = '%s', isbn = '%s', publisher = '%s', edition = %d, year = %d WHERE id = %d",
+
+ /*db_query("UPDATE {textbook_companion_preference} SET book = '%s', author = '%s', isbn = '%s', publisher = '%s', edition = %d, year = %d WHERE id = %d",
$form_state['values']['book2'],
$form_state['values']['author2'],
$form_state['values']['isbn2'],
$form_state['values']['publisher2'],
$form_state['values']['edition2'],
$form_state['values']['year2'],
- $preference2_id);
+ $preference2_id);*/
+
+ $query = db_update('textbook_companion_preference');
+ $query->fields(array(
+ 'book' => $form_state['values']['book2'],
+ 'author' => $form_state['values']['author2'],
+ 'isbn' => $form_state['values']['isbn2'],
+ 'publisher' => $form_state['values']['publisher2'],
+ 'edition' => $form_state['values']['edition2'],
+ 'year' => $form_state['values']['year2'],
+ ));
+ $query->condition('id', $preference2_id);
+ $num_updated = $query->execute();
+
}
if ($preference3_data)
{
del_book_pdf($preference3_data->id);
- db_query("UPDATE {textbook_companion_preference} SET book = '%s', author = '%s', isbn = '%s', publisher = '%s', edition = %d, year = %d WHERE id = %d",
+
+ /*db_query("UPDATE {textbook_companion_preference} SET book = '%s', author = '%s', isbn = '%s', publisher = '%s', edition = %d, year = %d WHERE id = %d",
$form_state['values']['book3'],
$form_state['values']['author3'],
$form_state['values']['isbn3'],
$form_state['values']['publisher3'],
$form_state['values']['edition3'],
$form_state['values']['year3'],
- $preference3_id);
+ $preference3_id);*/
+
+ $query = db_update('textbook_companion_preference');
+ $query->fields(array(
+ 'book' => $form_state['values']['book3'],
+ 'author' => $form_state['values']['author3'],
+ 'isbn' => $form_state['values']['isbn3'],
+ 'publisher' => $form_state['values']['publisher3'],
+ 'edition' => $form_state['values']['edition3'],
+ 'year' => $form_state['values']['year3'],
+ ));
+ $query->condition('id',$preference3_id);
+ $num_updated = $query->execute();
+
+
}
drupal_set_message(t('Proposal Updated'), 'status');
+ drupal_goto('manage_proposal/');
}
@@ -1079,8 +1412,16 @@ function category_edit_form($form_state)
{
/* get current proposal */
$preference_id = arg(3);
- $preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d", $preference_id);
- $preference_data = db_fetch_object($preference_q);
+
+ /*$preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d", $preference_id);
+ $preference_data = db_fetch_object($preference_q);*/
+
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('id', $preference_id);
+ $preference_q = $query->execute();
+ $preference_data = $preference_q->fetchObject();
+
if (!$preference_data)
{
drupal_set_message(t('Invalid book selected. Please try again.'), 'error');
@@ -1091,32 +1432,32 @@ function category_edit_form($form_state)
$form['book'] = array(
'#type' => 'item',
'#title' => t('Title of the book'),
- '#value' => $preference_data->book,
+ '#markup' => $preference_data->book,
);
$form['author'] = array(
'#type' => 'item',
'#title' => t('Author Name'),
- '#value' => $preference_data->author,
+ '#markup' => $preference_data->author,
);
$form['isbn'] = array(
'#type' => 'item',
'#title' => t('ISBN No'),
- '#value' => $preference_data->isbn,
+ '#markup' => $preference_data->isbn,
);
$form['publisher'] = array(
'#type' => 'item',
'#title' => t('Publisher & Place'),
- '#value' => $preference_data->publisher,
+ '#markup' => $preference_data->publisher,
);
$form['edition'] = array(
'#type' => 'item',
'#title' => t('Edition'),
- '#value' => $preference_data->edition,
+ '#markup' => $preference_data->edition,
);
$form['year'] = array(
'#type' => 'item',
'#title' => t('Year of pulication'),
- '#value' => $preference_data->year,
+ '#markup' => $preference_data->year,
);
$form['category'] = array(
@@ -1155,8 +1496,16 @@ function category_edit_form_submit($form, &$form_state)
{
/* get current proposal */
$preference_id = (int)arg(3);
- $preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d", $preference_id);
- $preference_data = db_fetch_object($preference_q);
+
+ /*$preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d", $preference_id);
+ $preference_data = db_fetch_object($preference_q);*/
+
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('id', $preference_id);
+ $preference_q = $query->execute();
+ $preference_data =$preference_q->fetchObject();
+
if (!$preference_data)
{
drupal_set_message(t('Invalid book selected. Please try again.'), 'error');
@@ -1164,7 +1513,15 @@ function category_edit_form_submit($form, &$form_state)
return;
}
- db_query("UPDATE {textbook_companion_preference} SET category = %d WHERE id = %d", $form_state['values']['category'], $preference_data->id);
+ /*db_query("UPDATE {textbook_companion_preference} SET category = %d WHERE id = %d", $form_state['values']['category'], $preference_data->id);*/
+
+ $query = db_update('textbook_companion_preference');
+ $query->fields(array(
+ 'category' => $form_state['values']['category'],
+ ));
+ $query->condition('id', $preference_data->id);
+ $num_updated = $query->execute();
+
drupal_set_message(t('Book Category Updated'), 'status');
drupal_goto('manage_proposal/category');
@@ -1178,9 +1535,17 @@ function _data_entry_proposal_all()
{
/* get pending proposals to be approved */
$proposal_rows = array();
- $preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE approval_status = 1 ORDER BY book ASC");
+
+ /*$preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE approval_status = 1 ORDER BY book ASC");*/
+
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('approval_status', 1);
+ $query->orderBy('book', 'ASC');
+ $preference_q = $query->execute();
+
$sno = 1;
- while ($preference_data = db_fetch_object($preference_q))
+ while ($preference_data = $preference_q->fetchObject())
{
$proposal_rows[] = array($sno++, $preference_data->book, $preference_data->author, $preference_data->isbn, l('Edit', 'dataentry_edit/' . $preference_data->id));
}
@@ -1193,7 +1558,7 @@ function _data_entry_proposal_all()
}
$proposal_header = array('SNO', 'Title of the Book', 'Author', 'ISBN', '');
- $output = theme_table($proposal_header, $proposal_rows);
+ $output = theme('table',array('header'=>$proposal_header,'rows'=>$proposal_rows));
return $output;
}
@@ -1205,12 +1570,18 @@ function dataentry_edit($id = NULL) {
}
}
-function dataentry_edit_form($form_state, $id)
+function dataentry_edit_form($form,$form_state, $id)
{
global $user;
- $preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d", $id);
- $preference_data = db_fetch_object($preference_q);
+ /*$preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d", $id);
+ $preference_data = db_fetch_object($preference_q);*/
+
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('id', $id);
+ $preference_q = $query->execute();
+ $preference_data =$preference_q->fetchObject();
$form['id'] = array(
'#type' => 'hidden',
@@ -1276,7 +1647,20 @@ function dataentry_edit_form($form_state, $id)
function dataentry_edit_form_submit($form, &$form_state)
{
- db_query("UPDATE {textbook_companion_preference} SET book = '%s', author = '%s', isbn = '%s', publisher = '%s', edition = '%s', year = %d WHERE id = %d", $_POST['book'], $_POST['author'], $_POST['isbn'], $_POST['publisher'], $_POST['edition'], $_POST['year'], $_POST['id']);
+ /*db_query("UPDATE {textbook_companion_preference} SET book = '%s', author = '%s', isbn = '%s', publisher = '%s', edition = '%s', year = %d WHERE id = %d", $_POST['book'], $_POST['author'], $_POST['isbn'], $_POST['publisher'], $_POST['edition'], $_POST['year'], $_POST['id']);*/
+
+ $query = db_update('textbook_companion_preference');
+ $query->fields(array(
+ 'book' => $_POST['book'],
+ 'author' => $_POST['author'],
+ 'isbn' => $_POST['isbn'],
+ 'publisher' => $_POST['publisher'],
+ 'edition' => $_POST['edition'],
+ 'year' => $_POST['year'],
+ ));
+ $query->condition('id', $_POST['id']);
+ $num_updated = $query->execute();
+
drupal_set_message('Book details updated successfully');
drupal_goto('dataentry_book');
}
@@ -1285,29 +1669,65 @@ function dataentry_edit_form_submit($form, &$form_state)
function _failed_all($preference_id=0, $confirm="") {
$page_content = "";
if($preference_id && $confirm == "yes"){
- $query = "
+ /*$query = "
SELECT *, pro.id as proposal_id FROM textbook_companion_proposal pro
LEFT JOIN textbook_companion_preference pre ON pre.proposal_id = pro.id
LEFT JOIN users usr ON usr.uid = pro.uid
WHERE pre.id = {$preference_id}
";
$result = db_query($query);
- $row = db_fetch_object($result);
+ $row = db_fetch_object($result);*/
+/*
+ $query = db_select('textbook_companion_proposal', 'pro');
+ $query->fields('pro');
+ $query->fields('pro', array('id'));
+ $query->addField('pro','id','proposal_id');
+ $query->leftJoin('textbook_companion_preference', 'pre', 'pre.proposal_id = pro.id');
+ $query->leftJoin('users', 'usr', 'usr.uid = pro.uid');
+ $query->condition('pre.id', $preference_id);
+ $result = $query->execute();
+ $row =$result->fetchObject();
+*/
+
+ $query = "
+ SELECT *, pro.id as proposal_id FROM textbook_companion_proposal pro
+ LEFT JOIN textbook_companion_preference pre ON pre.proposal_id = pro.id
+ LEFT JOIN users usr ON usr.uid = pro.uid
+ WHERE pre.id = {:preference_id}
+ ";
+ $result = db_query($query, array(':preference_id' => $preference_id ));
+ $row = $result->fetchObject();
/* increment failed_reminder */
- $query = "
+
+ /*$query = "
UPDATE textbook_companion_proposal
SET failed_reminder = failed_reminder + 1
WHERE id = {$row->proposal_id}
";
- db_query($query);
+ db_query($query);*/
+
+ /*$query = db_update('textbook_companion_proposal');
+ $query->fields(array(
+ 'failed_reminder' => 'failed_reminder + 1',
+ ));
+ $query->condition('id', '$row->proposal_id');
+ $num_updated = $query->execute();
+*/
+
+ $query = "
+ UPDATE textbook_companion_proposal
+ SET failed_reminder = failed_reminder + 1
+ WHERE id = {:id}
+ ";
+ db_query($query, array(':id' => $row->proposal_id));
/* sending mail */
$to = $row->mail;
$subject = "Failed to upload the TBC codes on time";
$body = "
<p>
- Dear {$row->name},<br><br>
+ Dear {$row->full_name},<br><br>
This is to inform you that you have failed to upload the TBC codes on time.<br>
Please note that the time you have taken is way past the deadline as well.<br>
Kindly upload the TBC codes on the interface within 5 days from now.<br>
@@ -1317,27 +1737,24 @@ function _failed_all($preference_id=0, $confirm="") {
</p>
";
- $message = array(
- "to" => $to,
- "subject" => $subject,
- "body" => $body,
- "headers" => array(
- "From" => "textbook@scilab.in",
- "Bcc" => "textbook@scilab.in, lavitha89@gmail.com, bhavani.jalkrish@gmail.com, rush2jrp@gmail.com",
- "Content-Type" => "text/html; charset=UTF-8; format=flowed"
- )
- );
- drupal_mail_send($message);
+ $message = $body;
+ //drupal_mail($message);
+ //drupal_mail('', 'standard', $email_to, language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE))
+ $from = variable_get('textbook_companion_from_email', NULL);
+ $bcc = variable_get('textbook_companion_emails_fail_rem_bcc', NULL);
+ fail_rem_send_mail( $from, $to, $bcc, $subject, $message);
drupal_set_message("Reminder sent successfully.");
drupal_goto("manage_proposal/failed");
} else if($preference_id) {
$query = "
SELECT * FROM textbook_companion_preference pre
LEFT JOIN textbook_companion_proposal pro ON pro.id = pre.proposal_id
- WHERE pre.id = {$preference_id}
+ WHERE pre.id = {:preference_id}
";
- $result = db_query($query);
- $row = db_fetch_object($result);
+ $result = db_query($query, array(':preference_id' => $preference_id));
+ /*$row = db_fetch_object($result);*/
+ $row =$result->fetchObject();
+
$page_content .= "Are you sure you want to notify?<br><br>";
$page_content .= "Book: <b>{$row->book}</b><br>";
$page_content .= "Author: <b>{$row->author}</b><br>";
@@ -1346,34 +1763,83 @@ function _failed_all($preference_id=0, $confirm="") {
$page_content .= l("Yes", "manage_proposal/failed/{$preference_id}/yes") . " | ";
$page_content .= l("Cancel", "manage_proposal/failed");
} else {
- $query = "
+
+ /*$query = "
SELECT * FROM textbook_companion_proposal pro
LEFT JOIN textbook_companion_preference pre ON pre.proposal_id = pro.id
LEFT JOIN users usr ON usr.uid = pro.uid
WHERE pro.proposal_status = 1 AND pre.approval_status = 1 AND pro.completion_date < %d
ORDER BY failed_reminder
";
- $result = db_query($query, time());
-
+ $result = db_query($query, time());*/
+ /*
+ $query = db_select('textbook_companion_proposal', 'pro');
+ $query->fields('pro');
+ $query->leftJoin('textbook_companion_preference', 'pre', 'pre.proposal_id = pro.id');
+ $query->leftJoin('users', 'usr', 'usr.uid = pro.uid');
+ $query->condition('pro.proposal_status', 1);
+ $query->condition('pre.approval_status', 1);
+ $query->condition('pro.completion_date', time(), '<');
+ $query->orderBy('failed_reminder', 'ASC');
+ $result = $query->execute();
+*/
+$query = "
+ SELECT * FROM textbook_companion_proposal pro
+ LEFT JOIN textbook_companion_preference pre ON pre.proposal_id = pro.id
+ LEFT JOIN users usr ON usr.uid = pro.uid
+ WHERE pro.proposal_status = 1 AND pre.approval_status = 1 AND pro.completion_date < :completion_date
+ ORDER BY failed_reminder
+ ";
+ $result = db_query($query, array(':completion_date' => time()));
+
$headers = array(
"Date of Submission", "Book", "Contributor Name",
"Expected Completion Date", "Remainders", "Action"
);
$rows = array();
- while ($row = db_fetch_object($result)) {
+ while ($row = $result->fetchObject()) {
$item =array(
date("d-m-Y", $row->creation_date),
"{$row->book}<br><i>by</i> {$row->author}",
- $row->name,
+ $row->full_name,
date("d-m-Y", $row->completion_date),
$row->failed_reminder,
l("Remind", "manage_proposal/failed/{$row->id}")
);
array_push($rows, $item);
}
- $page_content .= theme("table", $headers, $rows);
+ $page_content .= theme('table', array('header' => $headers, 'rows' => $rows ));
+
}
return $page_content;
}
+/**
+ * Simple wrapper function for drupal_mail() to avoid extraneous code.
+ */
+ function fail_rem_send_mail($from, $to, $bcc, $subject, $message) {
+ $my_module = 'textbook_companion';
+ $my_mail_token = microtime();
+ $message = array(
+ 'id' => $my_module . '_' . $my_mail_token,
+ 'to' => $to,
+ 'subject' => $subject,
+ 'body' => array($message),
+ 'headers' => array(
+ 'From' => $from,
+ 'Sender' => $from,
+ 'Return-Path' => $from,
+ 'Bcc' => $bcc,
+ ),
+ );
+ $system = drupal_mail_system($my_module, $my_mail_token);
+ $message = $system->format($message);
+ if ($system->mail($message)) {
+ return TRUE;
+ }
+ else {
+ return FALSE;
+ }
+ }
+
diff --git a/notes.inc b/notes.inc
index 72fbd10..1d36c33 100755
--- a/notes.inc
+++ b/notes.inc
@@ -12,10 +12,16 @@ function book_notes_form($form_state)
/* get current proposal */
$preference_id = arg(2);
$preference_id = (int)$preference_id;
- $result = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d", $preference_id);
+
+ /*$result = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d", $preference_id);*/
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('id', $preference_id);
+ $result = $query->execute();
+
if ($result)
{
- if ($row = db_fetch_object($result))
+ if ($row = $result->fetchObject())
{
/* everything ok */
} else {
@@ -31,17 +37,25 @@ function book_notes_form($form_state)
/* get current notes */
$notes = '';
- $notes_q = db_query("SELECT * FROM {textbook_companion_notes} WHERE preference_id = %d LIMIT 1", $preference_id);
+
+ /*$notes_q = db_query("SELECT * FROM {textbook_companion_notes} WHERE preference_id = %d LIMIT 1", $preference_id);*/
+
+ $query = db_select('textbook_companion_notes');
+ $query->fields('textbook_companion_notes');
+ $query->condition('preference_id', $preference_id);
+ $query->range(0, 1);
+ $notes_q = $query->execute();
+
if ($notes_q)
{
- $notes_data = db_fetch_object($notes_q);
+ $notes_data = $notes_q->fetchObject());
$notes = $notes_data->notes;
}
$book_details = _book_information($preference_id);
$form['book_details'] = array(
'#type' => 'item',
- '#value' => '<span style="color: rgb(128, 0, 0);"><strong>About the Book</strong></span><br />' .
+ '#markup' => '<span style="color: rgb(128, 0, 0);"><strong>About the Book</strong></span><br />' .
'<strong>Author:</strong> ' . $book_details->preference_author . '<br />' .
'<strong>Title of the Book:</strong> ' . $book_details->preference_book . '<br />' .
'<strong>Publisher:</strong> ' . $book_details->preference_publisher . '<br />' .
@@ -77,10 +91,17 @@ function book_notes_form_submit($form, &$form_state)
/* get current proposal */
$preference_id = arg(2);
$preference_id = (int)$preference_id;
- $result = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d", $preference_id);
+
+ /*$result = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d", $preference_id);*/
+
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('id', $preference_id);
+ $result = $query->execute();
+
if ($result)
{
- if ($row = db_fetch_object($result))
+ if ($row = $result->fetchObject())
{
/* everything ok */
} else {
@@ -95,26 +116,63 @@ function book_notes_form_submit($form, &$form_state)
}
/* find existing notes */
- $notes_q = db_query("SELECT * FROM {textbook_companion_notes} WHERE preference_id = %d LIMIT 1", $preference_id);
- $notes_data = db_fetch_object($notes_q);
+
+ /*$notes_q = db_query("SELECT * FROM {textbook_companion_notes} WHERE preference_id = %d LIMIT 1", $preference_id);
+ $notes_data = db_fetch_object($notes_q);*/
+
+ $query = db_select('textbook_companion_notes');
+ $query->fields('textbook_companion_notes');
+ $query->condition('preference_id',$preference_id);
+ $query->range(0, 1);
+ $notes_q = $query->execute();
+ $notes_data =$notes_q->fetchObject();
/* add or update notes in database */
if ($notes_data) {
- db_query("UPDATE {textbook_companion_notes} SET notes = '%s' WHERE id = %d", $form_state['values']['notes'], $notes_data->id);
+
+ /*db_query("UPDATE {textbook_companion_notes} SET notes = '%s' WHERE id = %d", $form_state['values']['notes'], $notes_data->id);*/
+
+ $query = db_update('textbook_companion_notes');
+ $query->fields(array(
+ 'notes' => $form_state['values']['notes'],
+ ));
+ $query->condition('id', $notes_data->id);
+ $num_updated = $query->execute();
+
drupal_set_message('Notes updated successfully.', 'status');
+
} else {
- db_query("INSERT INTO {textbook_companion_notes} (preference_id, notes) VALUES (%d, '%s')", $preference_id, $form_state['values']['notes']);
+
+ /*db_query("INSERT INTO {textbook_companion_notes} (preference_id, notes) VALUES (%d, '%s')", $preference_id, $form_state['values']['notes']);*/
+ $query = "INSERT INTO {textbook_companion_notes} (preference_id, notes) VALUES
+ (:preference_id, :notes)";
+ $args = array(
+ ":preference_id"=>$preference_id,
+ ":notes"=> $form_state['values']['notes'],
+ );
+ $result = db_query($query, $args, array('return' => Database::RETURN_INSERT_ID));
+
drupal_set_message('Notes added successfully.', 'status');
+
}
}
/* return proposal and author information */
function _book_information($preference_id)
{
- $book_data = db_fetch_object(db_query("SELECT
+ /*$book_data = 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", $preference_id));
+ FROM {textbook_companion_proposal} proposal LEFT JOIN {textbook_companion_preference} preference ON proposal.id = preference.proposal_id WHERE preference.id = %d", $preference_id));*/
+
+ $query = db_select('textbook_companion_proposal', 'proposal');
+ $query->fields('preference', array('book', 'author', 'isbn', 'publisher', 'edition', 'year'));
+ $query->fields('proposal', array('full_name', 'faculty', 'reviewer', 'course', 'branch', 'university'));
+ $query->leftJoin('textbook_companion_preference', 'preference', 'proposal.id preference.proposal_id');
+ $query->condition('preference.id', $preference_id);
+ $result = $query->execute();
+ $book_data =$result->fetchObject();
+
return $book_data;
}
diff --git a/pdf/1 b/pdf/1
deleted file mode 100755
index c795012..0000000
--- a/pdf/1
+++ /dev/null
@@ -1,51 +0,0 @@
-<?php
- function _list_all_certificates()
- {
- global $user;
- $uid1 = $user->uid;
-
- $query2 = db_query("SELECT * FROM {textbook_companion_proposal} WHERE proposal_status=3 AND uid=".$user->uid);
- $data2 = db_fetch_object($query2);
- if($data2->id)
- {
- $search_rows = array();
- global $output;
- $output = '';
- $query3 = db_query("SELECT * FROM textbook_companion_preference WHERE approval_status=1 AND proposal_id=".$data2->id);
-
- while ($search_data3 = db_fetch_object($query3))
- {
- $search_rows[] = array($search_data3->isbn,$search_data3->book,$search_data3->author,l('Download Certificate', 'certificate/generate_pdf/'.$search_data3->id));
- }
- if ($search_rows)
- {
- $search_header = array('ISBN', 'Book Name', 'Author', 'Download Certificates');
- $output = theme_table($search_header, $search_rows);
- return $output;
- }
- else
- {
- echo("Error");
- return '';
- }
- }
- else
- {
- $query3 = db_query("SELECT * FROM {textbook_companion_proposal} WHERE uid=".$user->uid);
- $data3 = db_fetch_object($query2);
- var_dump($query3);
- die;
- if($data3)
- {
- drupal_set_message('<strong>Your book is still under Review!</strong>', 'status');
- return '';
- }
- else
- {
- drupal_set_message('<strong>You need to propose a book <a href="/proposal">Book Proposal</a></strong>', 'status');
- return '';
- }
- }
-
-}
-?>
diff --git a/pdf/1/1 FWR/FWR-cache.bak b/pdf/1/1 FWR/FWR-cache.bak
new file mode 100755
index 0000000..9b33bd3
--- /dev/null
+++ b/pdf/1/1 FWR/FWR-cache.bak
@@ -0,0 +1,99 @@
+EESchema-LIBRARY Version 2.3 Date: 12/15/2014 3:57:40 PM
+#encoding utf-8
+#
+# DIODE
+#
+DEF DIODE D 0 40 N N 1 F N
+F0 "D" 0 100 40 H V C CNN
+F1 "DIODE" 0 -100 40 H V C CNN
+$FPLIST
+ D?
+ S*
+$ENDFPLIST
+DRAW
+P 2 0 1 6 50 50 50 -50 N
+P 3 0 1 0 -50 50 50 0 -50 -50 F
+X A 1 -200 0 150 R 40 40 1 1 P
+X K 2 200 0 150 L 40 40 1 1 P
+ENDDRAW
+ENDDEF
+#
+# GND
+#
+DEF ~GND #PWR 0 0 Y Y 1 F P
+F0 "#PWR" 0 0 30 H I C CNN
+F1 "GND" 0 -70 30 H I C CNN
+DRAW
+P 4 0 1 0 -50 0 0 -50 50 0 -50 0 N
+X GND 1 0 0 0 U 30 30 1 1 W N
+ENDDRAW
+ENDDEF
+#
+# PWR_FLAG
+#
+DEF PWR_FLAG #FLG 0 0 N N 1 F P
+F0 "#FLG" 0 270 30 H I C CNN
+F1 "PWR_FLAG" 0 230 30 H V C CNN
+DRAW
+X pwr 1 0 0 0 U 20 20 0 0 w
+P 3 0 1 0 0 0 0 100 0 100 N
+P 5 0 1 0 0 100 -100 150 0 200 100 150 0 100 N
+ENDDRAW
+ENDDEF
+#
+# R
+#
+DEF R R 0 0 N Y 1 F N
+F0 "R" 80 0 50 V V C CNN
+F1 "R" 0 0 50 V V C CNN
+$FPLIST
+ R?
+ SM0603
+ SM0805
+ R?-*
+ SM1206
+$ENDFPLIST
+DRAW
+S -40 150 40 -150 0 1 12 N
+X ~ 1 0 250 100 D 60 60 1 1 P
+X ~ 2 0 -250 100 U 60 60 1 1 P
+ENDDRAW
+ENDDEF
+#
+# sine
+#
+DEF sine v 0 40 Y Y 1 F N
+F0 "v" -200 100 60 H V C CNN
+F1 "sine" -200 -50 60 H V C CNN
+F2 "R1" -300 0 60 H V C CNN
+$FPLIST
+ 1_pin
+$ENDFPLIST
+DRAW
+A -50 0 50 1 1799 0 1 0 N 0 0 -100 0
+A 50 0 50 -1799 -1 0 1 0 N 0 0 100 0
+C 0 0 150 0 1 0 N
+X + 1 0 450 300 D 50 0 1 1 I
+X - 2 0 -450 300 U 50 0 1 1 I
+ENDDRAW
+ENDDEF
+#
+# vplot8_1
+#
+DEF vplot8_1 U 0 40 Y Y 8 F N
+F0 "U" -150 100 50 H V C CNN
+F1 "vplot8_1" 150 100 50 H V C CNN
+DRAW
+C 0 0 100 0 0 0 N
+X + 1 0 -300 200 U 40 40 1 1 I
+X + 2 0 -300 200 U 40 40 2 1 I
+X + 3 0 -300 200 U 40 40 3 1 I
+X + 4 0 -300 200 U 40 40 4 1 I
+X + 5 0 -300 200 U 40 40 5 1 I
+X + 6 0 -300 200 U 40 40 6 1 I
+X + 7 0 -300 200 U 40 40 7 1 I
+X + 8 0 -300 200 U 40 40 8 1 I
+ENDDRAW
+ENDDEF
+#
+#End Library
diff --git a/pdf/1/1 FWR/FWR-cache.lib b/pdf/1/1 FWR/FWR-cache.lib
new file mode 100755
index 0000000..1e3b489
--- /dev/null
+++ b/pdf/1/1 FWR/FWR-cache.lib
@@ -0,0 +1,125 @@
+EESchema-LIBRARY Version 2.3 Date: 12/15/2014 4:18:40 PM
+#encoding utf-8
+#
+# DIODE
+#
+DEF DIODE D 0 40 N N 1 F N
+F0 "D" 0 100 40 H V C CNN
+F1 "DIODE" 0 -100 40 H V C CNN
+$FPLIST
+ D?
+ S*
+$ENDFPLIST
+DRAW
+P 2 0 1 6 50 50 50 -50 N
+P 3 0 1 0 -50 50 50 0 -50 -50 F
+X A 1 -200 0 150 R 40 40 1 1 P
+X K 2 200 0 150 L 40 40 1 1 P
+ENDDRAW
+ENDDEF
+#
+# GND
+#
+DEF ~GND #PWR 0 0 Y Y 1 F P
+F0 "#PWR" 0 0 30 H I C CNN
+F1 "GND" 0 -70 30 H I C CNN
+DRAW
+P 4 0 1 0 -50 0 0 -50 50 0 -50 0 N
+X GND 1 0 0 0 U 30 30 1 1 W N
+ENDDRAW
+ENDDEF
+#
+# PWR_FLAG
+#
+DEF PWR_FLAG #FLG 0 0 N N 1 F P
+F0 "#FLG" 0 270 30 H I C CNN
+F1 "PWR_FLAG" 0 230 30 H V C CNN
+DRAW
+X pwr 1 0 0 0 U 20 20 0 0 w
+P 3 0 1 0 0 0 0 100 0 100 N
+P 5 0 1 0 0 100 -100 150 0 200 100 150 0 100 N
+ENDDRAW
+ENDDEF
+#
+# R
+#
+DEF R R 0 0 N Y 1 F N
+F0 "R" 80 0 50 V V C CNN
+F1 "R" 0 0 50 V V C CNN
+$FPLIST
+ R?
+ SM0603
+ SM0805
+ R?-*
+ SM1206
+$ENDFPLIST
+DRAW
+S -40 150 40 -150 0 1 12 N
+X ~ 1 0 250 100 D 60 60 1 1 P
+X ~ 2 0 -250 100 U 60 60 1 1 P
+ENDDRAW
+ENDDEF
+#
+# sine
+#
+DEF sine v 0 40 Y Y 1 F N
+F0 "v" -200 100 60 H V C CNN
+F1 "sine" -200 -50 60 H V C CNN
+F2 "R1" -300 0 60 H V C CNN
+$FPLIST
+ 1_pin
+$ENDFPLIST
+DRAW
+A -50 0 50 1 1799 0 1 0 N 0 0 -100 0
+A 50 0 50 -1799 -1 0 1 0 N 0 0 100 0
+C 0 0 150 0 1 0 N
+X + 1 0 450 300 D 50 0 1 1 I
+X - 2 0 -450 300 U 50 0 1 1 I
+ENDDRAW
+ENDDEF
+#
+# vplot8
+#
+DEF vplot8 U 0 40 Y Y 8 F N
+F0 "U" -150 100 50 H V C CNN
+F1 "vplot8" 150 100 50 H V C CNN
+DRAW
+C 0 0 100 0 0 0 N
+X + 1 -300 0 200 R 40 40 1 1 O
+X - 9 300 0 200 L 40 40 1 1 O
+X + 2 -300 0 200 R 40 40 2 1 O
+X - 10 300 0 200 L 40 40 2 1 O
+X + 3 -300 0 200 R 40 40 3 1 O
+X - 11 300 0 200 L 40 40 3 1 O
+X + 4 -300 0 200 R 40 40 4 1 O
+X - 12 300 0 200 L 40 40 4 1 O
+X + 5 -300 0 200 R 40 40 5 1 O
+X - 13 300 0 200 L 40 40 5 1 O
+X + 6 -300 0 200 R 40 40 6 1 O
+X - 14 300 0 200 L 40 40 6 1 O
+X + 7 -300 0 200 R 40 40 7 1 O
+X - 15 300 0 200 L 40 40 7 1 O
+X + 8 -300 0 200 R 40 40 8 1 O
+X - 16 300 0 200 L 40 40 8 1 O
+ENDDRAW
+ENDDEF
+#
+# vplot8_1
+#
+DEF vplot8_1 U 0 40 Y Y 8 F N
+F0 "U" -150 100 50 H V C CNN
+F1 "vplot8_1" 150 100 50 H V C CNN
+DRAW
+C 0 0 100 0 0 0 N
+X + 1 0 -300 200 U 40 40 1 1 I
+X + 2 0 -300 200 U 40 40 2 1 I
+X + 3 0 -300 200 U 40 40 3 1 I
+X + 4 0 -300 200 U 40 40 4 1 I
+X + 5 0 -300 200 U 40 40 5 1 I
+X + 6 0 -300 200 U 40 40 6 1 I
+X + 7 0 -300 200 U 40 40 7 1 I
+X + 8 0 -300 200 U 40 40 8 1 I
+ENDDRAW
+ENDDEF
+#
+#End Library
diff --git a/pdf/1/1 FWR/FWR.bak b/pdf/1/1 FWR/FWR.bak
new file mode 100755
index 0000000..258bcc6
--- /dev/null
+++ b/pdf/1/1 FWR/FWR.bak
@@ -0,0 +1,204 @@
+EESchema Schematic File Version 2 date 12/15/2014 3:57:40 PM
+LIBS:power
+LIBS:device
+LIBS:transistors
+LIBS:conn
+LIBS:linear
+LIBS:regul
+LIBS:74xx
+LIBS:cmos4000
+LIBS:adc-dac
+LIBS:memory
+LIBS:xilinx
+LIBS:special
+LIBS:microcontrollers
+LIBS:dsp
+LIBS:microchip
+LIBS:analog_switches
+LIBS:motorola
+LIBS:texas
+LIBS:intel
+LIBS:audio
+LIBS:interface
+LIBS:digital-audio
+LIBS:philips
+LIBS:display
+LIBS:cypress
+LIBS:siliconi
+LIBS:opto
+LIBS:atmel
+LIBS:contrib
+LIBS:valves
+LIBS:analogSpice
+LIBS:analogXSpice
+LIBS:convergenceAidSpice
+LIBS:converterSpice
+LIBS:digitalSpice
+LIBS:digitalXSpice
+LIBS:linearSpice
+LIBS:measurementSpice
+LIBS:portSpice
+LIBS:sourcesSpice
+EELAYER 43 0
+EELAYER END
+$Descr A4 11700 8267
+encoding utf-8
+Sheet 1 1
+Title ""
+Date "15 dec 2014"
+Rev ""
+Comp ""
+Comment1 ""
+Comment2 ""
+Comment3 ""
+Comment4 ""
+$EndDescr
+$Comp
+L VPLOT8_1 U?
+U 1 1 548EB795
+P 3550 4850
+F 0 "U?" H 3400 4950 50 0000 C CNN
+F 1 "VPLOT8_1" H 3700 4950 50 0000 C CNN
+ 1 3550 4850
+ 1 0 0 -1
+$EndComp
+Wire Wire Line
+ 1400 4600 1400 5250
+Connection ~ 3550 5150
+Connection ~ 1550 4850
+Wire Wire Line
+ 4650 4950 4650 5150
+Wire Wire Line
+ 4650 5150 1700 5150
+Wire Wire Line
+ 1400 3700 1400 3450
+Wire Wire Line
+ 1400 3450 2850 3450
+Connection ~ 3650 4100
+Wire Wire Line
+ 3650 4100 4650 4100
+Connection ~ 2850 3900
+Wire Wire Line
+ 2850 3450 2850 3900
+Wire Wire Line
+ 2600 4400 3100 4400
+Wire Wire Line
+ 3500 4400 3650 4400
+Wire Wire Line
+ 3650 4400 3650 3900
+Wire Wire Line
+ 3650 3900 3500 3900
+Wire Wire Line
+ 2600 3900 3100 3900
+Wire Wire Line
+ 2200 3900 2000 3900
+Wire Wire Line
+ 2000 3900 2000 4400
+Wire Wire Line
+ 2000 4400 2200 4400
+Wire Wire Line
+ 2850 4400 2850 4850
+Connection ~ 2850 4400
+Wire Wire Line
+ 2850 4850 1400 4850
+Wire Wire Line
+ 2000 4150 1700 4150
+Connection ~ 2000 4150
+Wire Wire Line
+ 1700 4150 1700 5150
+Wire Wire Line
+ 4650 4100 4650 4450
+Connection ~ 1400 4850
+Connection ~ 3000 5150
+$Comp
+L SINE v1
+U 1 1 548EB552
+P 1400 4150
+F 0 "v1" H 1200 4250 60 0000 C CNN
+F 1 "SINE" H 1200 4100 60 0000 C CNN
+F 2 "R1" H 1100 4150 60 0000 C CNN
+ 1 1400 4150
+ 1 0 0 -1
+$EndComp
+$Comp
+L PWR_FLAG #FLG01
+U 1 1 548EB534
+P 1550 4850
+F 0 "#FLG01" H 1550 5120 30 0001 C CNN
+F 1 "PWR_FLAG" H 1550 5080 30 0000 C CNN
+ 1 1550 4850
+ 1 0 0 -1
+$EndComp
+$Comp
+L VPLOT8_1 U1
+U 2 1 548EB30C
+P 4650 3800
+F 0 "U1" H 4500 3900 50 0000 C CNN
+F 1 "VPLOT8_1" H 4800 3900 50 0000 C CNN
+ 2 4650 3800
+ 1 0 0 -1
+$EndComp
+$Comp
+L VPLOT8_1 U1
+U 1 1 548EB307
+P 1400 3150
+F 0 "U1" H 1250 3250 50 0000 C CNN
+F 1 "VPLOT8_1" H 1550 3250 50 0000 C CNN
+ 1 1400 3150
+ 1 0 0 -1
+$EndComp
+$Comp
+L GND #PWR02
+U 1 1 548EB261
+P 1400 5250
+F 0 "#PWR02" H 1400 5250 30 0001 C CNN
+F 1 "GND" H 1400 5180 30 0001 C CNN
+ 1 1400 5250
+ 1 0 0 -1
+$EndComp
+$Comp
+L R R1
+U 1 1 548EB228
+P 4650 4700
+F 0 "R1" V 4730 4700 50 0000 C CNN
+F 1 "10k" V 4650 4700 50 0000 C CNN
+ 1 4650 4700
+ 1 0 0 -1
+$EndComp
+$Comp
+L DIODE D4
+U 1 1 548EB19F
+P 3300 4400
+F 0 "D4" H 3300 4500 40 0000 C CNN
+F 1 "1n4007" H 3300 4300 40 0000 C CNN
+ 1 3300 4400
+ 1 0 0 -1
+$EndComp
+$Comp
+L DIODE D3
+U 1 1 548EB19B
+P 2400 4400
+F 0 "D3" H 2400 4500 40 0000 C CNN
+F 1 "1n4007" H 2400 4300 40 0000 C CNN
+ 1 2400 4400
+ 1 0 0 -1
+$EndComp
+$Comp
+L DIODE D2
+U 1 1 548EB198
+P 3300 3900
+F 0 "D2" H 3300 4000 40 0000 C CNN
+F 1 "1n4007" H 3300 3800 40 0000 C CNN
+ 1 3300 3900
+ 1 0 0 -1
+$EndComp
+$Comp
+L DIODE D1
+U 1 1 548EB195
+P 2400 3900
+F 0 "D1" H 2400 4000 40 0000 C CNN
+F 1 "1n4007" H 2400 3800 40 0000 C CNN
+ 1 2400 3900
+ 1 0 0 -1
+$EndComp
+$EndSCHEMATC
diff --git a/pdf/1/1 FWR/FWR.cir b/pdf/1/1 FWR/FWR.cir
new file mode 100755
index 0000000..a18fcc7
--- /dev/null
+++ b/pdf/1/1 FWR/FWR.cir
@@ -0,0 +1,16 @@
+* EESchema Netlist Version 1.1 (Spice format) creation date: 12/15/2014 4:07:39 PM
+
+* To exclude a component from the Spice Netlist add [Spice_Netlist_Enabled] user FIELD set to: N
+* To reorder the component spice node sequence add [Spice_Node_Sequence] user FIELD and define sequence: 2,1,0
+
+*Sheet Name:/
+U2 2 3 VPLOT8
+v1 1 0 SINE
+U1 1 VPLOT8_1
+R1 2 3 10k
+D4 0 2 1n4007
+D3 3 0 1n4007
+D2 1 2 1n4007
+D1 3 1 1n4007
+
+.end
diff --git a/pdf/1/1 FWR/FWR.cir.ckt b/pdf/1/1 FWR/FWR.cir.ckt
new file mode 100755
index 0000000..d566c1c
--- /dev/null
+++ b/pdf/1/1 FWR/FWR.cir.ckt
@@ -0,0 +1,14 @@
+* eeschema netlist version 1.1 (spice format) creation date: 12/15/2014 4:07:39 pm
+
+v1 1 0 sine(0 5 50 0 0)
+* Plotting option vplot8_1
+r1 2 3 10k
+d4 0 2 1n4007
+d3 3 0 1n4007
+d2 1 2 1n4007
+d1 3 1 1n4007
+
+.tran 1e-03 100e-03 0e-00
+.plot v(2)-v(3)
+.plot v(1)
+.end
diff --git a/pdf/1/1 FWR/FWR.cir.out b/pdf/1/1 FWR/FWR.cir.out
new file mode 100755
index 0000000..f456fcf
--- /dev/null
+++ b/pdf/1/1 FWR/FWR.cir.out
@@ -0,0 +1,21 @@
+* eeschema netlist version 1.1 (spice format) creation date: 12/15/2014 4:07:39 pm
+
+v1 1 0 sine(0 5 50 0 0)
+* Plotting option vplot8_1
+r1 2 3 10k
+d4 0 2 1n4007
+d3 3 0 1n4007
+d2 1 2 1n4007
+d1 3 1 1n4007
+
+.tran 1e-03 100e-03 0e-00
+
+* Control Statements
+.control
+run
+plot v(2)-v(3)
+plot v(1)
+print allv > plot_data_v.txt
+print alli > plot_data_i.txt
+.endc
+.end
diff --git a/pdf/1/1 FWR/FWR.pro b/pdf/1/1 FWR/FWR.pro
new file mode 100755
index 0000000..c2f9628
--- /dev/null
+++ b/pdf/1/1 FWR/FWR.pro
@@ -0,0 +1,74 @@
+update=12/15/2014 3:34:08 PM
+last_client=eeschema
+[eeschema]
+version=1
+LibDir=
+NetFmt=1
+HPGLSpd=20
+HPGLDm=15
+HPGLNum=1
+offX_A4=0
+offY_A4=0
+offX_A3=0
+offY_A3=0
+offX_A2=0
+offY_A2=0
+offX_A1=0
+offY_A1=0
+offX_A0=0
+offY_A0=0
+offX_A=0
+offY_A=0
+offX_B=0
+offY_B=0
+offX_C=0
+offY_C=0
+offX_D=0
+offY_D=0
+offX_E=0
+offY_E=0
+RptD_X=0
+RptD_Y=100
+RptLab=1
+LabSize=60
+[eeschema/libraries]
+LibName1=power
+LibName2=device
+LibName3=transistors
+LibName4=conn
+LibName5=linear
+LibName6=regul
+LibName7=74xx
+LibName8=cmos4000
+LibName9=adc-dac
+LibName10=memory
+LibName11=xilinx
+LibName12=special
+LibName13=microcontrollers
+LibName14=dsp
+LibName15=microchip
+LibName16=analog_switches
+LibName17=motorola
+LibName18=texas
+LibName19=intel
+LibName20=audio
+LibName21=interface
+LibName22=digital-audio
+LibName23=philips
+LibName24=display
+LibName25=cypress
+LibName26=siliconi
+LibName27=opto
+LibName28=atmel
+LibName29=contrib
+LibName30=valves
+LibName31=C:/FreeEDA/FreeEDA/library/analogSpice
+LibName32=C:/FreeEDA/FreeEDA/library/analogXSpice
+LibName33=C:/FreeEDA/FreeEDA/library/convergenceAidSpice
+LibName34=C:/FreeEDA/FreeEDA/library/converterSpice
+LibName35=C:/FreeEDA/FreeEDA/library/digitalSpice
+LibName36=C:/FreeEDA/FreeEDA/library/digitalXSpice
+LibName37=C:/FreeEDA/FreeEDA/library/linearSpice
+LibName38=C:/FreeEDA/FreeEDA/library/measurementSpice
+LibName39=C:/FreeEDA/FreeEDA/library/portSpice
+LibName40=C:/FreeEDA/FreeEDA/library/sourcesSpice
diff --git a/pdf/1/1 FWR/FWR.proj b/pdf/1/1 FWR/FWR.proj
new file mode 100755
index 0000000..68b75c3
--- /dev/null
+++ b/pdf/1/1 FWR/FWR.proj
@@ -0,0 +1 @@
+schematicFile FWR.sch
diff --git a/pdf/1/1 FWR/FWR.sch b/pdf/1/1 FWR/FWR.sch
new file mode 100755
index 0000000..54699d0
--- /dev/null
+++ b/pdf/1/1 FWR/FWR.sch
@@ -0,0 +1,199 @@
+EESchema Schematic File Version 2 date 12/15/2014 4:18:40 PM
+LIBS:power
+LIBS:device
+LIBS:transistors
+LIBS:conn
+LIBS:linear
+LIBS:regul
+LIBS:74xx
+LIBS:cmos4000
+LIBS:adc-dac
+LIBS:memory
+LIBS:xilinx
+LIBS:special
+LIBS:microcontrollers
+LIBS:dsp
+LIBS:microchip
+LIBS:analog_switches
+LIBS:motorola
+LIBS:texas
+LIBS:intel
+LIBS:audio
+LIBS:interface
+LIBS:digital-audio
+LIBS:philips
+LIBS:display
+LIBS:cypress
+LIBS:siliconi
+LIBS:opto
+LIBS:atmel
+LIBS:contrib
+LIBS:valves
+LIBS:analogSpice
+LIBS:analogXSpice
+LIBS:convergenceAidSpice
+LIBS:converterSpice
+LIBS:digitalSpice
+LIBS:digitalXSpice
+LIBS:linearSpice
+LIBS:measurementSpice
+LIBS:portSpice
+LIBS:sourcesSpice
+LIBS:FWR-cache
+EELAYER 25 0
+EELAYER END
+$Descr A4 11700 8267
+encoding utf-8
+Sheet 1 1
+Title ""
+Date "15 dec 2014"
+Rev ""
+Comp ""
+Comment1 ""
+Comment2 ""
+Comment3 ""
+Comment4 ""
+$EndDescr
+Connection ~ 5200 5050
+Wire Wire Line
+ 5800 5050 2250 5050
+Wire Wire Line
+ 5800 5050 5800 4000
+Connection ~ 3550 5050
+Connection ~ 1950 4750
+Wire Wire Line
+ 5200 4350 5200 4000
+Wire Wire Line
+ 2250 5050 2250 4050
+Connection ~ 2550 4050
+Wire Wire Line
+ 2250 4050 2550 4050
+Wire Wire Line
+ 1950 4750 3400 4750
+Connection ~ 3400 4300
+Wire Wire Line
+ 3400 4750 3400 4300
+Wire Wire Line
+ 2750 4300 2550 4300
+Wire Wire Line
+ 2550 4300 2550 3800
+Wire Wire Line
+ 2550 3800 2750 3800
+Wire Wire Line
+ 3150 3800 3650 3800
+Wire Wire Line
+ 4050 3800 4200 3800
+Wire Wire Line
+ 4200 3800 4200 4300
+Wire Wire Line
+ 4200 4300 4050 4300
+Wire Wire Line
+ 3150 4300 3650 4300
+Wire Wire Line
+ 3400 3800 3400 3350
+Connection ~ 3400 3800
+Wire Wire Line
+ 5200 4000 4200 4000
+Connection ~ 4200 4000
+Wire Wire Line
+ 3400 3350 1950 3350
+Wire Wire Line
+ 1950 3350 1950 3600
+Wire Wire Line
+ 5200 5050 5200 4850
+Connection ~ 2100 4750
+Connection ~ 4100 5050
+Wire Wire Line
+ 1950 4500 1950 5150
+$Comp
+L VPLOT8 U2
+U 1 1 548EB9B9
+P 5500 4000
+F 0 "U2" H 5350 4100 50 0000 C CNN
+F 1 "VPLOT8" H 5650 4100 50 0000 C CNN
+ 1 5500 4000
+ 1 0 0 -1
+$EndComp
+$Comp
+L SINE v1
+U 1 1 548EB552
+P 1950 4050
+F 0 "v1" H 1750 4150 60 0000 C CNN
+F 1 "SINE" H 1750 4000 60 0000 C CNN
+F 2 "R1" H 1650 4050 60 0000 C CNN
+ 1 1950 4050
+ 1 0 0 -1
+$EndComp
+$Comp
+L PWR_FLAG #FLG01
+U 1 1 548EB534
+P 2100 4750
+F 0 "#FLG01" H 2100 5020 30 0001 C CNN
+F 1 "PWR_FLAG" H 2100 4980 30 0000 C CNN
+ 1 2100 4750
+ 1 0 0 -1
+$EndComp
+$Comp
+L VPLOT8_1 U1
+U 1 1 548EB307
+P 1950 3050
+F 0 "U1" H 1800 3150 50 0000 C CNN
+F 1 "VPLOT8_1" H 2100 3150 50 0000 C CNN
+ 1 1950 3050
+ 1 0 0 -1
+$EndComp
+$Comp
+L GND #PWR02
+U 1 1 548EB261
+P 1950 5150
+F 0 "#PWR02" H 1950 5150 30 0001 C CNN
+F 1 "GND" H 1950 5080 30 0001 C CNN
+ 1 1950 5150
+ 1 0 0 -1
+$EndComp
+$Comp
+L R R1
+U 1 1 548EB228
+P 5200 4600
+F 0 "R1" V 5280 4600 50 0000 C CNN
+F 1 "10k" V 5200 4600 50 0000 C CNN
+ 1 5200 4600
+ 1 0 0 -1
+$EndComp
+$Comp
+L DIODE D4
+U 1 1 548EB19F
+P 3850 4300
+F 0 "D4" H 3850 4400 40 0000 C CNN
+F 1 "1n4007" H 3850 4200 40 0000 C CNN
+ 1 3850 4300
+ 1 0 0 -1
+$EndComp
+$Comp
+L DIODE D3
+U 1 1 548EB19B
+P 2950 4300
+F 0 "D3" H 2950 4400 40 0000 C CNN
+F 1 "1n4007" H 2950 4200 40 0000 C CNN
+ 1 2950 4300
+ 1 0 0 -1
+$EndComp
+$Comp
+L DIODE D2
+U 1 1 548EB198
+P 3850 3800
+F 0 "D2" H 3850 3900 40 0000 C CNN
+F 1 "1n4007" H 3850 3700 40 0000 C CNN
+ 1 3850 3800
+ 1 0 0 -1
+$EndComp
+$Comp
+L DIODE D1
+U 1 1 548EB195
+P 2950 3800
+F 0 "D1" H 2950 3900 40 0000 C CNN
+F 1 "1n4007" H 2950 3700 40 0000 C CNN
+ 1 2950 3800
+ 1 0 0 -1
+$EndComp
+$EndSCHEMATC
diff --git a/pdf/1/1 FWR/FWR_last_input.txt b/pdf/1/1 FWR/FWR_last_input.txt
new file mode 100755
index 0000000..3adc58b
--- /dev/null
+++ b/pdf/1/1 FWR/FWR_last_input.txt
@@ -0,0 +1 @@
+v1 1 0 sine(0 5 50 0 0)
diff --git a/pdf/1/1 FWR/analysis b/pdf/1/1 FWR/analysis
new file mode 100755
index 0000000..5bf79dd
--- /dev/null
+++ b/pdf/1/1 FWR/analysis
@@ -0,0 +1 @@
+.tran 1e-03 100e-03 0e-00
diff --git a/pdf/1/1 FWR/eeschema.exe b/pdf/1/1 FWR/eeschema.exe
new file mode 100755
index 0000000..b3b6d28
--- /dev/null
+++ b/pdf/1/1 FWR/eeschema.exe
Binary files differ
diff --git a/pdf/1/1 FWR/libfftw3-3.dll b/pdf/1/1 FWR/libfftw3-3.dll
new file mode 100755
index 0000000..a8f033a
--- /dev/null
+++ b/pdf/1/1 FWR/libfftw3-3.dll
Binary files differ
diff --git a/pdf/1/1 FWR/ngspice.exe b/pdf/1/1 FWR/ngspice.exe
new file mode 100755
index 0000000..e584114
--- /dev/null
+++ b/pdf/1/1 FWR/ngspice.exe
Binary files differ
diff --git a/pdf/1/1 FWR/plot_data_i.txt b/pdf/1/1 FWR/plot_data_i.txt
new file mode 100755
index 0000000..e9e5f02
--- /dev/null
+++ b/pdf/1/1 FWR/plot_data_i.txt
@@ -0,0 +1,116 @@
+* eeschema netlist version 1.1 (spice format) creation date: 12/15/2014 4:07:39 pm
+Transient Analysis Mon Dec 15 16:08:18 2014
+--------------------------------------------------------------------------------
+Index time alli
+--------------------------------------------------------------------------------
+0 0.000000e+000 3.606493e-039
+1 1.000000e-005 -2.17812e-014
+2 2.000000e-005 -4.43227e-014
+3 4.000000e-005 -9.35520e-014
+4 8.000000e-005 -2.38250e-013
+5 1.600000e-004 -1.53691e-012
+6 3.200000e-004 -1.63800e-010
+7 6.400000e-004 -1.73017e-006
+8 1.280000e-003 -7.78645e-005
+9 2.280000e-003 -2.05364e-004
+10 3.280000e-003 -3.03847e-004
+11 4.280000e-003 -3.61390e-004
+12 5.280000e-003 -3.72083e-004
+13 6.280000e-003 -3.34708e-004
+14 7.280000e-003 -2.53135e-004
+15 8.280000e-003 -1.36494e-004
+16 9.280000e-003 -6.87530e-006
+17 1.028000e-002 4.917472e-011
+18 1.128000e-002 7.780236e-005
+19 1.228000e-002 2.054564e-004
+20 1.328000e-002 3.038616e-004
+21 1.428000e-002 3.615052e-004
+22 1.528000e-002 3.721142e-004
+23 1.628000e-002 3.347006e-004
+24 1.728000e-002 2.531279e-004
+25 1.828000e-002 1.364935e-004
+26 1.928000e-002 6.875297e-006
+27 2.028000e-002 -4.91747e-011
+28 2.128000e-002 -7.78024e-005
+29 2.228000e-002 -2.05456e-004
+30 2.328000e-002 -3.03862e-004
+31 2.428000e-002 -3.61505e-004
+32 2.528000e-002 -3.72114e-004
+33 2.628000e-002 -3.34701e-004
+34 2.728000e-002 -2.53128e-004
+35 2.828000e-002 -1.36493e-004
+36 2.928000e-002 -6.87530e-006
+37 3.028000e-002 4.917472e-011
+38 3.128000e-002 7.780236e-005
+39 3.228000e-002 2.054564e-004
+40 3.328000e-002 3.038616e-004
+41 3.428000e-002 3.615052e-004
+42 3.528000e-002 3.721142e-004
+43 3.628000e-002 3.347006e-004
+44 3.728000e-002 2.531279e-004
+45 3.828000e-002 1.364935e-004
+46 3.928000e-002 6.875297e-006
+47 4.028000e-002 -4.91747e-011
+48 4.128000e-002 -7.78024e-005
+49 4.228000e-002 -2.05456e-004
+50 4.328000e-002 -3.03862e-004
+51 4.428000e-002 -3.61505e-004
+52 4.528000e-002 -3.72114e-004
+53 4.628000e-002 -3.34701e-004
+54 4.728000e-002 -2.53128e-004
+
+Index time alli
+--------------------------------------------------------------------------------
+55 4.828000e-002 -1.36493e-004
+56 4.928000e-002 -6.87530e-006
+57 5.028000e-002 4.917472e-011
+58 5.128000e-002 7.780236e-005
+59 5.228000e-002 2.054564e-004
+60 5.328000e-002 3.038616e-004
+61 5.428000e-002 3.615052e-004
+62 5.528000e-002 3.721142e-004
+63 5.628000e-002 3.347006e-004
+64 5.728000e-002 2.531279e-004
+65 5.828000e-002 1.364935e-004
+66 5.928000e-002 6.875297e-006
+67 6.028000e-002 -4.91747e-011
+68 6.128000e-002 -7.78024e-005
+69 6.228000e-002 -2.05456e-004
+70 6.328000e-002 -3.03862e-004
+71 6.428000e-002 -3.61505e-004
+72 6.528000e-002 -3.72114e-004
+73 6.628000e-002 -3.34701e-004
+74 6.728000e-002 -2.53128e-004
+75 6.828000e-002 -1.36493e-004
+76 6.928000e-002 -6.87530e-006
+77 7.028000e-002 4.917472e-011
+78 7.128000e-002 7.780236e-005
+79 7.228000e-002 2.054564e-004
+80 7.328000e-002 3.038616e-004
+81 7.428000e-002 3.615052e-004
+82 7.528000e-002 3.721142e-004
+83 7.628000e-002 3.347006e-004
+84 7.728000e-002 2.531279e-004
+85 7.828000e-002 1.364935e-004
+86 7.928000e-002 6.875297e-006
+87 8.028000e-002 -4.91747e-011
+88 8.128000e-002 -7.78024e-005
+89 8.228000e-002 -2.05456e-004
+90 8.328000e-002 -3.03862e-004
+91 8.428000e-002 -3.61505e-004
+92 8.528000e-002 -3.72114e-004
+93 8.628000e-002 -3.34701e-004
+94 8.728000e-002 -2.53128e-004
+95 8.828000e-002 -1.36493e-004
+96 8.928000e-002 -6.87530e-006
+97 9.028000e-002 4.917472e-011
+98 9.128000e-002 7.780236e-005
+99 9.228000e-002 2.054564e-004
+100 9.328000e-002 3.038616e-004
+101 9.428000e-002 3.615052e-004
+102 9.528000e-002 3.721142e-004
+103 9.628000e-002 3.347006e-004
+104 9.728000e-002 2.531279e-004
+105 9.828000e-002 1.364935e-004
+106 9.928000e-002 6.875297e-006
+107 1.000000e-001 -2.92819e-026
diff --git a/pdf/1/1 FWR/plot_data_v.txt b/pdf/1/1 FWR/plot_data_v.txt
new file mode 100755
index 0000000..a1dee49
--- /dev/null
+++ b/pdf/1/1 FWR/plot_data_v.txt
@@ -0,0 +1,116 @@
+* eeschema netlist version 1.1 (spice format) creation date: 12/15/2014 4:07:39 pm
+Transient Analysis Mon Dec 15 16:08:18 2014
+--------------------------------------------------------------------------------
+Index time V(1) V(2) V(3)
+--------------------------------------------------------------------------------
+0 0.000000e+000 0.000000e+000 5.056840e-019 5.056855e-019
+1 1.000000e-005 1.570794e-002 7.853969e-003 7.853969e-003
+2 2.000000e-005 3.141572e-002 1.570786e-002 1.570786e-002
+3 4.000000e-005 6.283020e-002 3.141510e-002 3.141510e-002
+4 8.000000e-005 1.256505e-001 6.282524e-002 6.282524e-002
+5 1.600000e-004 2.512216e-001 1.256108e-001 1.256108e-001
+6 3.200000e-004 5.018086e-001 2.509051e-001 2.509035e-001
+7 6.400000e-004 9.985499e-001 5.079258e-001 4.906241e-001
+8 1.280000e-003 1.956868e+000 1.367757e+000 5.891118e-001
+9 2.280000e-003 3.282929e+000 2.668283e+000 6.146463e-001
+10 3.280000e-003 4.287633e+000 3.663052e+000 6.245809e-001
+11 4.280000e-003 4.872634e+000 4.243267e+000 6.293674e-001
+12 5.280000e-003 4.980668e+000 4.350749e+000 6.299189e-001
+13 6.280000e-003 4.601159e+000 3.974118e+000 6.270408e-001
+14 7.280000e-003 3.771257e+000 3.151305e+000 6.199516e-001
+15 8.280000e-003 2.572198e+000 1.968567e+000 6.036309e-001
+16 9.280000e-003 1.121354e+000 5.950534e-001 5.263004e-001
+17 1.028000e-002 -4.39256e-001 -2.19628e-001 -2.19628e-001
+18 1.128000e-002 -1.95687e+000 -5.89422e-001 -1.36745e+000
+19 1.228000e-002 -3.28293e+000 -6.14182e-001 -2.66875e+000
+20 1.328000e-002 -4.28763e+000 -6.24509e-001 -3.66312e+000
+21 1.428000e-002 -4.87263e+000 -6.28791e-001 -4.24384e+000
+22 1.528000e-002 -4.98067e+000 -6.29763e-001 -4.35090e+000
+23 1.628000e-002 -4.60116e+000 -6.27077e-001 -3.97408e+000
+24 1.728000e-002 -3.77126e+000 -6.19989e-001 -3.15127e+000
+25 1.828000e-002 -2.57220e+000 -6.03632e-001 -1.96857e+000
+26 1.928000e-002 -1.12135e+000 -5.26300e-001 -5.95053e-001
+27 2.028000e-002 4.392560e-001 2.196282e-001 2.196277e-001
+28 2.128000e-002 1.956868e+000 1.367446e+000 5.894224e-001
+29 2.228000e-002 3.282929e+000 2.668747e+000 6.141822e-001
+30 2.328000e-002 4.287633e+000 3.663125e+000 6.245087e-001
+31 2.428000e-002 4.872634e+000 4.243843e+000 6.287912e-001
+32 2.528000e-002 4.980668e+000 4.350905e+000 6.297631e-001
+33 2.628000e-002 4.601159e+000 3.974083e+000 6.270766e-001
+34 2.728000e-002 3.771257e+000 3.151268e+000 6.199889e-001
+35 2.828000e-002 2.572198e+000 1.968566e+000 6.036315e-001
+36 2.928000e-002 1.121354e+000 5.950534e-001 5.263004e-001
+37 3.028000e-002 -4.39256e-001 -2.19628e-001 -2.19628e-001
+38 3.128000e-002 -1.95687e+000 -5.89422e-001 -1.36745e+000
+39 3.228000e-002 -3.28293e+000 -6.14182e-001 -2.66875e+000
+40 3.328000e-002 -4.28763e+000 -6.24509e-001 -3.66312e+000
+41 3.428000e-002 -4.87263e+000 -6.28791e-001 -4.24384e+000
+42 3.528000e-002 -4.98067e+000 -6.29763e-001 -4.35090e+000
+43 3.628000e-002 -4.60116e+000 -6.27077e-001 -3.97408e+000
+44 3.728000e-002 -3.77126e+000 -6.19989e-001 -3.15127e+000
+45 3.828000e-002 -2.57220e+000 -6.03632e-001 -1.96857e+000
+46 3.928000e-002 -1.12135e+000 -5.26300e-001 -5.95053e-001
+47 4.028000e-002 4.392560e-001 2.196282e-001 2.196277e-001
+48 4.128000e-002 1.956868e+000 1.367446e+000 5.894224e-001
+49 4.228000e-002 3.282929e+000 2.668747e+000 6.141822e-001
+50 4.328000e-002 4.287633e+000 3.663125e+000 6.245087e-001
+51 4.428000e-002 4.872634e+000 4.243843e+000 6.287912e-001
+52 4.528000e-002 4.980668e+000 4.350905e+000 6.297631e-001
+53 4.628000e-002 4.601159e+000 3.974083e+000 6.270766e-001
+54 4.728000e-002 3.771257e+000 3.151268e+000 6.199889e-001
+
+Index time V(1) V(2) V(3)
+--------------------------------------------------------------------------------
+55 4.828000e-002 2.572198e+000 1.968566e+000 6.036315e-001
+56 4.928000e-002 1.121354e+000 5.950534e-001 5.263004e-001
+57 5.028000e-002 -4.39256e-001 -2.19628e-001 -2.19628e-001
+58 5.128000e-002 -1.95687e+000 -5.89422e-001 -1.36745e+000
+59 5.228000e-002 -3.28293e+000 -6.14182e-001 -2.66875e+000
+60 5.328000e-002 -4.28763e+000 -6.24509e-001 -3.66312e+000
+61 5.428000e-002 -4.87263e+000 -6.28791e-001 -4.24384e+000
+62 5.528000e-002 -4.98067e+000 -6.29763e-001 -4.35090e+000
+63 5.628000e-002 -4.60116e+000 -6.27077e-001 -3.97408e+000
+64 5.728000e-002 -3.77126e+000 -6.19989e-001 -3.15127e+000
+65 5.828000e-002 -2.57220e+000 -6.03632e-001 -1.96857e+000
+66 5.928000e-002 -1.12135e+000 -5.26300e-001 -5.95053e-001
+67 6.028000e-002 4.392560e-001 2.196282e-001 2.196277e-001
+68 6.128000e-002 1.956868e+000 1.367446e+000 5.894224e-001
+69 6.228000e-002 3.282929e+000 2.668747e+000 6.141822e-001
+70 6.328000e-002 4.287633e+000 3.663125e+000 6.245087e-001
+71 6.428000e-002 4.872634e+000 4.243843e+000 6.287912e-001
+72 6.528000e-002 4.980668e+000 4.350905e+000 6.297631e-001
+73 6.628000e-002 4.601159e+000 3.974083e+000 6.270766e-001
+74 6.728000e-002 3.771257e+000 3.151268e+000 6.199889e-001
+75 6.828000e-002 2.572198e+000 1.968566e+000 6.036315e-001
+76 6.928000e-002 1.121354e+000 5.950534e-001 5.263004e-001
+77 7.028000e-002 -4.39256e-001 -2.19628e-001 -2.19628e-001
+78 7.128000e-002 -1.95687e+000 -5.89422e-001 -1.36745e+000
+79 7.228000e-002 -3.28293e+000 -6.14182e-001 -2.66875e+000
+80 7.328000e-002 -4.28763e+000 -6.24509e-001 -3.66312e+000
+81 7.428000e-002 -4.87263e+000 -6.28791e-001 -4.24384e+000
+82 7.528000e-002 -4.98067e+000 -6.29763e-001 -4.35090e+000
+83 7.628000e-002 -4.60116e+000 -6.27077e-001 -3.97408e+000
+84 7.728000e-002 -3.77126e+000 -6.19989e-001 -3.15127e+000
+85 7.828000e-002 -2.57220e+000 -6.03632e-001 -1.96857e+000
+86 7.928000e-002 -1.12135e+000 -5.26300e-001 -5.95053e-001
+87 8.028000e-002 4.392560e-001 2.196282e-001 2.196277e-001
+88 8.128000e-002 1.956868e+000 1.367446e+000 5.894224e-001
+89 8.228000e-002 3.282929e+000 2.668747e+000 6.141822e-001
+90 8.328000e-002 4.287633e+000 3.663125e+000 6.245087e-001
+91 8.428000e-002 4.872634e+000 4.243843e+000 6.287912e-001
+92 8.528000e-002 4.980668e+000 4.350905e+000 6.297631e-001
+93 8.628000e-002 4.601159e+000 3.974083e+000 6.270766e-001
+94 8.728000e-002 3.771257e+000 3.151268e+000 6.199889e-001
+95 8.828000e-002 2.572198e+000 1.968566e+000 6.036315e-001
+96 8.928000e-002 1.121354e+000 5.950534e-001 5.263004e-001
+97 9.028000e-002 -4.39256e-001 -2.19628e-001 -2.19628e-001
+98 9.128000e-002 -1.95687e+000 -5.89422e-001 -1.36745e+000
+99 9.228000e-002 -3.28293e+000 -6.14182e-001 -2.66875e+000
+100 9.328000e-002 -4.28763e+000 -6.24509e-001 -3.66312e+000
+101 9.428000e-002 -4.87263e+000 -6.28791e-001 -4.24384e+000
+102 9.528000e-002 -4.98067e+000 -6.29763e-001 -4.35090e+000
+103 9.628000e-002 -4.60116e+000 -6.27077e-001 -3.97408e+000
+104 9.728000e-002 -3.77126e+000 -6.19989e-001 -3.15127e+000
+105 9.828000e-002 -2.57220e+000 -6.03632e-001 -1.96857e+000
+106 9.928000e-002 -1.12135e+000 -5.26300e-001 -5.95053e-001
+107 1.000000e-001 -6.12323e-015 -1.59483e-009 1.594809e-009
diff --git a/pdf/1/1 FWR/python.exe b/pdf/1/1 FWR/python.exe
new file mode 100755
index 0000000..c72f16d
--- /dev/null
+++ b/pdf/1/1 FWR/python.exe
Binary files differ
diff --git a/pdf/1/1 FWR/vcomp100.dll b/pdf/1/1 FWR/vcomp100.dll
new file mode 100755
index 0000000..e23321c
--- /dev/null
+++ b/pdf/1/1 FWR/vcomp100.dll
Binary files differ
diff --git a/pdf/1/1.pdf b/pdf/1/1.pdf
new file mode 100755
index 0000000..79df36a
--- /dev/null
+++ b/pdf/1/1.pdf
Binary files differ
diff --git a/pdf/generate_pdf.inc b/pdf/generate_pdf.inc
index a62b2a3..cec2bcf 100755
--- a/pdf/generate_pdf.inc
+++ b/pdf/generate_pdf.inc
@@ -1,14 +1,15 @@
<?php
+
function generate_pdf()
- {
- require('fpdf/fpdf.php');
+ { $mpath = drupal_get_path('module', 'textbook_companion');
+ require($mpath.'/pdf/fpdf/fpdf.php');
global $user;
$x = $user->uid;
$proposal_id = arg(2);
- $query2 = db_query("SELECT * FROM {textbook_companion_preference} WHERE approval_status=1 AND proposal_id=".$proposal_id);
- $data2 = db_fetch_object($query2);
- $query3 = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id=".$proposal_id);
- $data3 = db_fetch_object($query3);
+ $query2 = db_query("SELECT * FROM {textbook_companion_preference} WHERE approval_status=1 AND proposal_id= :prop_id", array(':prop_id' => $proposal_id));
+ $data2 = $query2->fetchObject();
+ $query3 = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id= :prop_id", array(':prop_id' =>$proposal_id));
+ $data3 = $query3->fetchObject();
//var_dump($data3->gender);
$gender = array('salutation' => 'Mr. /Ms.', 'gender' => 'He/She');
if($data3->gender){
@@ -106,7 +107,29 @@
$pdf->Cell(200,0,' Date: '.$cur_date.'',0,1,'L');
//$pdf->Cell(200,0,' Date: 28th August, 2013',0,1,'L');
$pdf->Cell(200,15,'Email: textbook@scilab.in', 0,1,'L');
- $pdf->Output();
+ $filename = str_replace(' ','-', $data3->full_name).'-Scilab-Textbook-Certificate.pdf';
+
+ $file = $path.'/pdf/temp_certificate/'.$proposal_id.'_'.$filename;
+
+ $pdf->Output($file, 'F');
+
+ header("Content-Type: application/octet-stream");
+ header("Content-Disposition: attachment; filename=" . $filename);
+ header("Content-Type: application/octet-stream");
+ header("Content-Type: application/download");
+ header("Content-Description: File Transfer");
+ header("Content-Length: " . filesize($file));
+ flush(); // this doesn't really matter.
+ $fp = fopen($file, "r");
+ while (!feof($fp))
+ {
+ echo fread($fp, 65536);
+ flush(); // this is essential for large downloads
+ }
+ fclose($fp);
+ unlink($file);
+ drupal_goto('certificate');
+ return;
/*}
else
{
diff --git a/pdf/list_all_certificates.inc b/pdf/list_all_certificates.inc
index 766c1f1..e094d5f 100755
--- a/pdf/list_all_certificates.inc
+++ b/pdf/list_all_certificates.inc
@@ -53,8 +53,8 @@
function _list_all_certificates()
{
global $user;
- $query_id =db_query("SELECT id FROM textbook_companion_proposal WHERE proposal_status=3 AND uid=".$user->uid);
- $exist_id = db_fetch_object($query_id);
+ $query_id =db_query("SELECT id FROM textbook_companion_proposal WHERE proposal_status=3 AND uid= :uid", array(':uid' => $user->uid));
+ $exist_id = $query_id->fetchObject();
if($exist_id->id)
{
if($exist_id->id<3)
@@ -67,8 +67,8 @@ function _list_all_certificates()
$search_rows = array();
global $output;
$output = '';
- $query3 = db_query("SELECT prop.id,pref.isbn,pref.book,pref.author FROM textbook_companion_proposal as prop,textbook_companion_preference as pref WHERE prop.proposal_status=3 AND pref.approval_status=1 AND pref.proposal_id=prop.id AND prop.uid=".$user->uid);
- while ($search_data3 = db_fetch_object($query3))
+ $query3 = db_query("SELECT prop.id,pref.isbn,pref.book,pref.author FROM textbook_companion_proposal as prop,textbook_companion_preference as pref WHERE prop.proposal_status=3 AND pref.approval_status=1 AND pref.proposal_id=prop.id AND prop.uid= :uid",array(':uid' => $user->uid));
+ while ($search_data3 = $query3->fetchObject())
{
if($search_data3->id)
{
@@ -78,7 +78,7 @@ function _list_all_certificates()
if($search_rows)
{
$search_header = array('ISBN', 'Book Name', 'Author', 'Download Certificates');
- $output = theme_table($search_header, $search_rows);
+ $output = theme('table',array('header'=>$search_header, 'rows'=>$search_rows));
return $output;
}
else
diff --git a/run.inc b/run.inc
index d50edb1..1ff73f1 100755
--- a/run.inc
+++ b/run.inc
@@ -1,402 +1,285 @@
-<?php
-// $Id$
-
-function textbook_run_ajax() {
-
- $output = '';
- $example_files = '';
- if(isset($_POST['category']) && isset($_POST['book']) && isset($_POST['chapter']) && isset($_POST['example'])) {
- $output['download'] = l('Download Scilab code for the example', 'download/example/' . $_POST['example']);
- $example_list_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE example_id=".$_POST['example']);
- if ($example_list_q) {
- $example_files_rows = array();
- while ($example_list_data = db_fetch_object($example_list_q)) {
- $example_file_type = '';
- switch ($example_list_data->filetype) {
- case 'S' : $example_file_type = 'Source or Main file'; break;
- case 'R' : $example_file_type = 'Result file'; break;
- case 'X' : $example_file_type = 'xcos file'; break;
- default : $example_file_type = 'Unknown'; break;
- }
- $example_files_rows[] = array(l($example_list_data->filename, 'download/file/' . $example_list_data->id), $example_file_type);
- }
- $dependency_list_q = db_query("SELECT dependency.id as dependency_id, dependency.filename as dependency_filename, dependency.caption as dependency_caption FROM {textbook_companion_example_dependency} example_dependency LEFT JOIN {textbook_companion_dependency_files} dependency ON example_dependency.dependency_id = dependency.id WHERE example_dependency.example_id = %d", $form_state['values']['run']['example']);
- while ($dependency_list_data = db_fetch_object($dependency_list_q)) {
- $example_file_type = 'Dependency file';
- $temp_caption = '';
- if ($dependency_list_data->dependency_caption)
- $temp_caption = ' (' . $dependency_list_data->dependency_caption . ')';
- $example_files_rows[] = array(l($dependency_list_data->dependency_filename, 'download/dependency/' . $dependency_list_data->dependency_id) . $temp_caption, $example_file_type);
- }
-
- /* creating list of files table */
- $example_files_header = array('Filename', 'Type');
- $example_files = theme_table($example_files_header, $example_files_rows);
- }
- $output['files'] = $example_files;
- } elseif(isset($_POST['category']) && isset($_POST['book']) && isset($_POST['chapter'])) {
- $output['download'] = l('Download', 'download/chapter/' . $_POST['chapter']) . ' ' . t('(Download the Scilab codes for all the solved examples from the Chapter)');
- $output['examples'] = _list_of_examples($_POST['chapter']);
- } elseif(isset($_POST['category']) && isset($_POST['book'])) {
- $output['details'] = _html_book_info($_POST['book']);
- $output['download'] = l('Download', 'download/book/' . $_POST['book']) . ' ' . t('(Download the Scilab codes for all the solved examples)');
- $output['downloadpdf'] = l('Download PDF', 'textbook_companion/generate_book/' . $_POST['book']) . ' ' . t('(Download the PDF file containing Scilab codes for all the solved examples)');
- $output['chapters'] = _list_of_chapters($_POST['book']);
- } elseif(isset($_POST['category'])) {
- $output['books'] = _list_of_books($_POST['category']);
- }
-
- echo json_encode($output);
- exit;
-}
-
-
-function textbook_companion_run_form_ajax($form_state, $pref_id = NULL) {
-
- $path = drupal_get_path('module', 'textbook_companion');
- drupal_add_js($path . '/js/jquery-1.7.1.js');
- drupal_add_js($path . '/js/tbc-download.js');
- $category_default_value = 0;
- $book_default_value = 0;
- $book_details = '';
- $book_download = '';
- $book_download_pdf = '';
- $book_books = array(0 => 'Please select book');
- $book_chapters = array(0 => 'Please select chapter');
- $style_param = 'display:none;';
- if($pref_id){
- $query = "select category from textbook_companion_preference where id=".$pref_id;
- $result = db_query($query);
- $row = db_fetch_object($result);
- $category_default_value = $row->category;
- $book_default_value = $pref_id;
- $book_books = _list_of_books($category_default_value);
- $book_details = _html_book_info($pref_id);
- $book_download = l('Download', 'download/book/' . $pref_id) . ' ' . t('(Download the Scilab codes for all the solved examples)');
- $book_download_pdf = l('Download PDF', 'textbook_companion/generate_book/' . $pref_id) . ' ' . t('(Download the PDF file containing Scilab codes for all the solved examples)');
- $book_chapters = _list_of_chapters($pref_id);
- $style_param = 'display:block;';
- }
-
- $form['run'] = array(
- '#type' => 'fieldset',
- '#title' => t('Run Book Example'),
- '#collapsible' => FALSE,
- '#collapsed' => FALSE,
- '#prefix' => '<div id="run-wrapper">',
- '#suffix' => '</div>',
- '#tree' => TRUE,
- );
-
- $form['run']['category'] = array(
- '#type' => 'select',
- '#title' => t('Category'),
- '#options' => array(0 => 'Please select category',
- 1 => 'Fluid Mechanics',
- 2 => 'Control Theory & Control Systems',
- 3 => 'Chemical Engineering',
- 4 => 'Thermodynamics',
- 5 => 'Mechanical Engineering',
- 6 => 'Signal Processing',
- 7 => 'Digital Communications',
- 8 => 'Electrical Technology',
- 9 => 'Mathematics & Pure Science',
- 10 => 'Analog Electronics',
- 11 => 'Digital Electronics',
- 12 => 'Computer Programming',
- 13 => 'Others'
- ),
- '#default_value' => $category_default_value,
- '#tree' => TRUE,
- '#attributes' => array('class' => 'tbc-category'),
- '#suffix' => '<div class="tbc-book-main tbc-book-overall" style="'.$style_param.'">',
- );
- $form['run']['book'] = array(
- '#type' => 'select',
- '#title' => t('Title of the Book'),
- '#options' => $book_books,
- '#default_value' => $book_default_value,
- '#tree' => TRUE,
- '#attributes' => array('class' => 'tbc-book'),
- '#suffix' => '</div>
- <div class="tbc-book-block tbc-book-overall tbc-after-book" style="'.$style_param.'">
- <div class="form-item tbc-book-details">'.$book_details.'</div>
- <div class="form-item tbc-book-download">'.$book_download.'</div>
- <div class="form-item tbc-book-download-pdf">'.$book_download_pdf.'</div>',
- );
- $form['run']['chapter'] = array(
- '#type' => 'select',
- '#title' => t('Title of the Chapter'),
- '#options' => $book_chapters,
- '#default_value' => 0,
- '#tree' => TRUE,
- '#attributes' => array('class' => 'tbc-chapter'),
- '#suffix' => '</div>
- <div class="tbc-chapter-block tbc-book-overall tbc-after-book tbc-after-chapter" style="display:none;">
- <div class="tbc-chapter-download"></div>',
- );
- $form['run']['example'] = array(
- '#type' => 'select',
- '#title' => t('Example No. (Caption)'),
- '#options' => array(0 => 'Please select example'),
- '#default_value' => 0,
- '#tree' => TRUE,
- '#attributes' => array('class' => 'tbc-example'),
- '#suffix' => '</div>
- <div class="tbc-example-block tbc-book-overall tbc-after-book tbc-after-chapter tbc-after-example" style="display:none;">
- <div class="tbc-example-download"></div>
- <div class="tbc-example-files"></div>
- </div></div>',
- );
- /*$form['run']['feedback'] = array(
- '#type' => 'textarea',
- '#title' => t('Feedback on the above example'),
- );
- $form['run']['feedback_submit'] = array(
- '#type' => 'submit',
- '#value' => t('Submit'),
- '#suffix' => '</div></div>',
- );*/
-
- return $form;
-}
-
-function textbook_companion_run_form_ajax_submit($form, &$form_state) {
-
-}
-
-function textbook_companion_run_form($form_state, $pref_id = NULL)
-{
-
- $form['#redirect'] = FALSE;
- $book_default_value = 0;
-
- ahah_helper_register($form, $form_state);
- if (!isset($form_state['storage']['run']['category']))
- {
- $category_default_value = 0;
- if($pref_id){
- $query = "select category from textbook_companion_preference where id=".$pref_id;
- $result = db_query($query);
- $row = db_fetch_object($result);
- $category_default_value = $row->category;
- $book_default_value = $pref_id;
- }
- } else {
- $category_default_value = $form_state['storage']['run']['category'];
- }
- /* default value for ahah fields */
- if (!isset($form_state['storage']['run']['book']))
- {
- /* get the book id from url */
- $url_book_id = (int)arg(1);
- if ($url_book_id)
- {
- /* add javascript for book selected */
- $chapter_name_js = " $(document).ready(function() {
- $('#edit-run-book').val(" . $url_book_id . ");
- $('#edit-run-book').change();
- });";
- drupal_add_js($chapter_name_js, 'inline', 'footer');
- }
- } else {
- $book_default_value = $form_state['storage']['run']['book'];
- }
-
- if (!isset($form_state['storage']['run']['chapter']))
- {
- $chapter_default_value = 0;
- } else {
- if ($form_state['values']['run']['book_hidden'] != $form_state['values']['run']['book'])
- $chapter_default_value = 0;
- else
- $chapter_default_value = $form_state['storage']['run']['chapter'];
- }
-
- if (!isset($form_state['storage']['run']['example']))
- {
- $example_default_value = 0;
- } else {
- if ($form_state['values']['run']['book_hidden'] != $form_state['values']['run']['book'])
- $example_default_value = 0;
- else if ($form_state['values']['run']['chapter_hidden'] != $form_state['values']['run']['chapter'])
- $example_default_value = 0;
- else
- $example_default_value = $form_state['storage']['run']['example'];
- }
-
- $form['run'] = array(
- '#type' => 'fieldset',
- '#title' => t('Run Book Example'),
- '#collapsible' => FALSE,
- '#collapsed' => FALSE,
- '#prefix' => '<div id="run-wrapper">',
- '#suffix' => '</div>',
- '#tree' => TRUE,
- );
- $form['run']['category'] = array(
- '#type' => 'select',
- '#title' => t('Category'),
- '#options' => array(0 => 'Please select',
- 1 => 'Fluid Mechanics',
- 2 => 'Control Theory & Control Systems',
- 3 => 'Chemical Engineering',
- 4 => 'Thermodynamics',
- 5 => 'Mechanical Engineering',
- 6 => 'Signal Processing',
- 7 => 'Digital Communications',
- 8 => 'Electrical Technology',
- 9 => 'Mathematics & Pure Science',
- 10 => 'Analog Electronics',
- 11 => 'Digital Electronics',
- 12 => 'Computer Programming',
- 13 => 'Others'),
- '#default_value' => $category_default_value,
- '#tree' => TRUE,
- '#ahah' => array(
- 'event' => 'change',
- 'effect' => 'none',
- 'path' => ahah_helper_path(array('run')),
- 'wrapper' => 'run-wrapper',
- 'progress' => array(
- 'type' => 'throbber',
- 'message' => t(''),
+<?php
+
+ function textbook_companion_run_form($form, &$form_state) {
+ $url_book_pref_id = (int)arg(1);
+
+ if($url_book_pref_id){
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference', array('category'));
+ $query->condition('id', $url_book_pref_id);
+ $result = $query->execute()->fetchObject();
+ $category_default_value = $result->category;
+ }else{
+ $category_default_value = 0;
+ }
+ if($url_book_pref_id){
+ $form['category'] = array(
+ '#type' => 'select',
+ '#title' => t('Category'),
+ '#options' => _list_of_category(),
+ '#default_value' => $category_default_value,
+ '#ajax' => array(
+ 'callback' => 'ajax_book_list_callback',
),
- ),
- );
- if($category_default_value > 0) {
- $form['run']['book'] = array(
- '#type' => 'select',
- '#title' => t('Title of the Book'),
- '#options' => _list_of_books($category_default_value),
- '#default_value' => $book_default_value,
- '#tree' => TRUE,
- '#ahah' => array(
- 'event' => 'change',
- 'effect' => 'none',
- 'path' => ahah_helper_path(array('run')),
- 'wrapper' => 'run-wrapper',
- 'progress' => array(
- 'type' => 'throbber',
- 'message' => t(''),
- ),
- ),
- );
- }else {
- $book_default_value = 0;
- }
-
- /* hidden form elements */
- $form['run']['book_hidden'] = array(
- '#type' => 'hidden',
- '#value' => $form_state['values']['run']['book'],
- );
-
- /* hidden form elements */
- $form['run']['chapter_hidden'] = array(
- '#type' => 'hidden',
- '#value' => $form_state['values']['run']['chapter'],
- );
-
- if ($book_default_value > 0)
- {
- $book_details = _book_information($book_default_value);
- $form['run']['book_details'] = array(
- '#type' => 'item',
- '#value' => '<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>',
- );
-
- $form['run']['download_book'] = array(
- '#type' => 'item',
- '#value' => l('Download', 'download/book/' . $book_default_value) . ' ' . t('(Download the Scilab codes for all the solved examples)'),
- );
-
- $form['run']['download_book_pdf'] = array(
- '#type' => 'item',
- '#value' => l('Download PDF', 'textbook_companion/generate_book/' . $book_default_value) . ' ' . t('(Download the PDF file containing Scilab codes for all the solved examples)'),
- );
-
- $form['run']['chapter'] = array(
- '#type' => 'select',
- '#title' => t('Title of the Chapter'),
- '#options' => _list_of_chapters($book_default_value),
- '#default_value' => $chapter_default_value,
- '#tree' => TRUE,
- '#ahah' => array(
- 'event' => 'change',
- 'effect' => 'none',
- 'path' => ahah_helper_path(array('run')),
- 'wrapper' => 'run-wrapper',
- 'progress' => array(
- 'type' => 'throbber',
- 'message' => t(''),
- ),
- ),
- );
- if ($chapter_default_value > 0)
- {
- $form['run']['download_chapter'] = array(
+ '#validated' => TRUE,
+ );
+ $book_default_value = $url_book_pref_id;
+ $form['book'] = array(
+ '#type' => 'select',
+ '#title' => t('Title of the book'),
+ '#options' => _list_of_books($category_default_value),
+ '#default_value' => $book_default_value,
+ '#prefix' => '<div id="ajax-book-list-replace">',
+ '#suffix' => '</div>',
+ '#ajax' => array(
+ 'callback' => 'ajax_chapter_list_callback',
+ ),
+ '#validated' => TRUE,
+ '#states' => array('invisible' => array(':input[name="category"]' => array('value' => 0),),),
+ );
+ /*$form['book_details'] = array(
+ '#prefix' => '<div id="ajax-book-details-replace"></div>',
+ '#suffix' => '</div>',
+ '#markup' => '',
+
+ );*/
+ $form['book_details'] = array(
'#type' => 'item',
- '#value' => l('Download', 'download/chapter/' . $chapter_default_value) . ' ' . t('(Download the Scilab codes for all the solved examples from the Chapter)'),
+ '#markup' => '<div id="ajax-book-details-replace">'._html_book_info($book_default_value).'</div>',
);
- $form['run']['example'] = array(
- '#type' => 'select',
- '#title' => t('Example No. (Caption)'),
- '#options' => _list_of_examples($chapter_default_value),
- '#default_value' => $example_default_value,
- '#tree' => TRUE,
- '#ahah' => array(
- 'event' => 'change',
- 'effect' => 'none',
- 'path' => ahah_helper_path(array('run')),
- 'wrapper' => 'run-wrapper',
- 'progress' => array(
- 'type' => 'throbber',
- 'message' => t(''),
- ),
- ),
+ $form['download_book'] = array(
+ '#type' => 'item',
+ '#markup' => '<div id="ajax-download-book-replace">'.l('Download', 'download/book/' . $book_default_value) . ' ' . t('(Download the Scilab codes for all the solved examples)').'</div>',
);
- }
- }
-
- /* hidden form elements */
- $form['run']['update_book'] = array(
- '#type' => 'submit',
- '#value' => t('Update'),
- '#submit' => array('ahah_helper_generic_submit'),
- '#attributes' => array('class' => 'no-js'),
- );
-
- $form['run']['update_chapter'] = array(
- '#type' => 'submit',
- '#value' => t('Update'),
- '#submit' => array('ahah_helper_generic_submit'),
- '#attributes' => array('class' => 'no-js'),
- );
-
- /************ START OF $_POST **************/
- if ($_POST)
- {
- if (($book_default_value > 0) && ($chapter_default_value > 0) && ($example_default_value > 0))
- {
- $example_list_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE example_id = %d", $form_state['values']['run']['example']);
+ $form['download_pdf'] = array(
+ '#type' => 'item',
+ '#markup' => '<div id="ajax-download-book-pdf-replace">'.l('Download PDF', 'textbook_companion/generate_book/' . $book_default_value) . ' ' . t('(Download the PDF file containing Scilab codes for all the solved examples)').'</div>',
+ );
+
+ $form['chapter'] = array(
+ '#type' => 'select',
+ '#title' => t('Title of the chapter'),
+ '#options' => _list_of_chapters($book_default_value),
+ //'#default_value' => isset($form_state['values']['chapter']) ? $form_state['values']['chapter'] : '',
+ '#prefix' => '<div id="ajax-chapter-list-replace">',
+ '#suffix' => '</div>',
+ '#ajax' => array(
+ 'callback' => 'ajax_example_list_callback',
+ ),
+ '#validated' => TRUE,
+ '#states' => array('invisible' => array(':input[name="category"]' => array('value' => 0),),),
+ );
+
+ $form['download_chapter'] = array(
+ '#type' => 'item',
+ '#markup' => '<div id="ajax-download-chapter-replace"></div>',
+ );
+ $example_default_value = isset($form_state['values']['chapter']) ? $form_state['values']['chapter'] : '';
+ $form['examples'] = array(
+ '#type' => 'select',
+ '#title' => t('Example No. (Caption): '),
+ '#options' => _list_of_examples($example_default_value),
+ '#default_value' => isset($form_state['values']['examples']) ? $form_state['values']['examples'] : '',
+ '#prefix' => '<div id="ajax-example-list-replace">',
+ '#suffix' => '</div>',
+ '#ajax' => array(
+ 'callback' => 'ajax_example_files_callback',
+ ),
+ '#states' => array('invisible' => array(':input[name="chapter"]' => array('value' => 0),),),
+ );
+ $form['download_example_code'] = array(
+ '#type' => 'item',
+ '#markup' => '<div id="ajax-download-example-code-replace"></div>',
+ );
+ $form['example_files'] = array(
+ '#type' => 'item',
+ '#markup' => '<div id="ajax-download-example-files-replace"></div>',
+ );
+ }else{
+ $form['category'] = array(
+ '#type' => 'select',
+ '#title' => t('Category'),
+ '#options' => _list_of_category(),
+ '#default_value' => $category_default_value,
+ '#ajax' => array(
+ 'callback' => 'ajax_book_list_callback',
+ ),
+ '#validated' => TRUE,
+ );
+ $form['book'] = array(
+ '#type' => 'select',
+ '#title' => t('Title of the book'),
+ '#options' => _list_of_books($category_default_value),
+ //'#default_value' => isset($form_state['values']['book']) ? $form_state['values']['book'] : 0,
+ '#prefix' => '<div id="ajax-book-list-replace">',
+ '#suffix' => '</div>',
+ '#ajax' => array(
+ 'callback' => 'ajax_chapter_list_callback',
+ ),
+ '#validated' => TRUE,
+ '#states' => array('invisible' => array(':input[name="category"]' => array('value' => 0),),),
+ );
+
+ $form['book_details'] = array(
+ '#type' => 'item',
+ '#markup' => '<div id="ajax-book-details-replace"></div>',
+ );
+ $form['download_book'] = array(
+ '#type' => 'item',
+ '#markup' => '<div id="ajax-download-book-replace"></div>',
+ );
+ $form['download_pdf'] = array(
+ '#type' => 'item',
+ '#markup' => '<div id="ajax-download-book-pdf-replace"></div>',
+ );
+ $book_default_value = isset($form_state['values']['book']) ? $form_state['values']['book'] : '';
+ $form['chapter'] = array(
+ '#type' => 'select',
+ '#title' => t('Title of the chapter'),
+ '#options' => _list_of_chapters($book_default_value),
+ //'#default_value' => isset($form_state['values']['chapter']) ? $form_state['values']['chapter'] : '',
+ '#prefix' => '<div id="ajax-chapter-list-replace">',
+ '#suffix' => '</div>',
+ '#ajax' => array(
+ 'callback' => 'ajax_example_list_callback',
+ ),
+ '#validated' => TRUE,
+ '#states' => array('invisible' => array(':input[name="category"]' => array('value' => 0),),),
+ );
+
+
+ $form['download_chapter'] = array(
+ '#type' => 'item',
+ '#markup' => '<div id="ajax-download-chapter-replace"></div>',
+ );
+ $example_default_value = isset($form_state['values']['chapter']) ? $form_state['values']['chapter'] : '';
+ $form['examples'] = array(
+ '#type' => 'select',
+ '#title' => t('Example No. (Caption): '),
+ '#options' => _list_of_examples($example_default_value),
+ '#default_value' => isset($form_state['values']['examples']) ? $form_state['values']['examples'] : '',
+ '#prefix' => '<div id="ajax-example-list-replace">',
+ '#suffix' => '</div>',
+ '#ajax' => array(
+ 'callback' => 'ajax_example_files_callback',
+ ),
+ '#states' => array('invisible' => array(':input[name="category"]' => array('value' => 0),),),
+ );
+ $form['download_example_code'] = array(
+ '#type' => 'item',
+ '#markup' => '<div id="ajax-download-example-code-replace"></div>',
+ );
+ $form['example_files'] = array(
+ '#type' => 'item',
+ '#markup' => '<div id="ajax-download-example-files-replace"></div>',
+ );
+ }
+
+ return $form;
+
+ }
+/********************* Ajax callback ***************************/
+ function ajax_book_list_callback($form, $form_state) {
+
+ $category_default_value = $form_state['values']['category'];
+ if($category_default_value > 0){
+
+ $form['book']['#options'] = _list_of_books($category_default_value);
+ $commands[] = ajax_command_replace("#ajax-book-list-replace", drupal_render($form['book']));
+ $commands[] = ajax_command_html("#ajax-chapter-list-replace", '');
+ $commands[] = ajax_command_html("#ajax-example-list-replace", '');
+
+ }else{
+
+ $form['book']['#options'] = _list_of_books();
+ $commands[] = ajax_command_replace("#ajax-book-list-replace", drupal_render($form['book']));
+ $commands[] = ajax_command_html("#ajax-book-list-replace", '');
+ $commands[] = ajax_command_html("#ajax-chapter-list-replace", '');
+ $commands[] = ajax_command_html("#ajax-example-list-replace", '');
+ $commands[] = ajax_command_html("#ajax-book-details-replace", '');
+ $commands[] = ajax_command_html("#ajax-download-book-replace", '');
+ $commands[] = ajax_command_html("#ajax-download-book-pdf-replace", '');
+ $commands[] = ajax_command_html("#ajax-download-chapter-replace", '');
+ $commands[] = ajax_command_html("#ajax-download-example-code-replace", '');
+ $commands[] = ajax_command_html("#ajax-download-example-files-replace", '');
+
+ }
+
+ return array('#type' => 'ajax', '#commands' => $commands);
+
+ }
+/*************************************************************************/
+ function ajax_chapter_list_callback($form, $form_state){
+ $book_list_default_value = $form_state['values']['book'];
+
+ if($book_list_default_value > 0){
+ $commands[] = ajax_command_html("#ajax-book-details-replace", _html_book_info($book_list_default_value));
+ $form['chapter']['#options']=_list_of_chapters($book_list_default_value);
+ $commands[] = ajax_command_html("#ajax-download-book-replace", l('Download', 'download/book/' . $book_list_default_value) . ' ' . t('(Download the Scilab codes for all the solved examples)'));
+ $commands[] = ajax_command_html("#ajax-download-book-pdf-replace", l('Download PDF', 'textbook_companion/generate_book/' . $book_list_default_value) . ' ' . t('(Download the PDF file containing Scilab codes for all the solved examples)'));
+ $commands[] = ajax_command_replace("#ajax-chapter-list-replace", drupal_render($form['chapter']));
+ $commands[] = ajax_command_html("#ajax-example-list-replace", '');
+ $commands[] = ajax_command_html("#ajax-download-example-code-replace", '');
+ $commands[] = ajax_command_html("#ajax-download-example-files-replace", '');
+ $commands[] = ajax_command_html("#ajax-download-chapter-replace",'');
+
+ }else{
+
+ $commands[] = ajax_command_html("#ajax-book-details-replace", '');
+ $form['chapter']['#options']=_list_of_chapters();
+ $commands[] = ajax_command_replace("#ajax-chapter-list-replace", drupal_render($form['chapter']));
+ $commands[] = ajax_command_html("#ajax-chapter-list-replace", '');
+ $commands[] = ajax_command_html("#ajax-download-book-replace",'');
+ $commands[] = ajax_command_html("#ajax-download-chapter-replace",'');
+ $commands[] = ajax_command_html("#ajax-download-book-pdf-replace", '');
+
+ $commands[] = ajax_command_html("#ajax-example-list-replace", '');
+ $commands[] = ajax_command_html("#ajax-download-example-code-replace", '');
+ $commands[] = ajax_command_html("#ajax-download-example-files-replace", '');
+ }
+
+ return array('#type' => 'ajax', '#commands' => $commands);
+ }
+
+ function ajax_example_list_callback($form, $form_state){
+
+ $chapter_list_default_value = $form_state['values']['chapter'];
+ if($chapter_list_default_value > 0){
+
+ $form['examples']['#options']= _list_of_examples($chapter_list_default_value);
+ $commands[] = ajax_command_replace("#ajax-example-list-replace", drupal_render($form['examples']));
+ $commands[] = ajax_command_html("#ajax-download-chapter-replace", l('Download', 'download/chapter/' . $chapter_list_default_value) . ' ' . t('(Download the Scilab codes for all the solved examples from the Chapter)'));
+
+ $commands[] = ajax_command_html("#ajax-download-example-code-replace", '');
+ $commands[] = ajax_command_html("#ajax-download-example-files-replace", '');
+
+ }else{
+ $form['examples']['#options']= _list_of_examples();
+ $commands[] = ajax_command_replace("#ajax-example-list-replace", drupal_render($form['examples']));
+ $commands[] = ajax_command_html("#ajax-example-list-replace", '');
+ $commands[] = ajax_command_html("#ajax-download-chapter-replace", '');
+ $commands[] = ajax_command_html("#ajax-download-example-code-replace", '');
+ $commands[] = ajax_command_html("#ajax-download-example-files-replace", '');
+
+ }
+ return array('#type' => 'ajax', '#commands' => $commands);
+ }
+ /*****************************************************/
+ function ajax_example_files_callback($form, $form_state){
+
+
+ $example_list_default_value = $form_state['values']['examples'];
+
+ if($example_list_default_value!=0){
+ // $example_list_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE example_id = %d", $form_state['values']['run']['example']);
+ $query = db_select('textbook_companion_example_files');
+ $query->fields('textbook_companion_example_files');
+ $query->condition('example_id', $example_list_default_value );
+ $example_list_q = $query->execute();
if ($example_list_q)
{
$example_files_rows = array();
- while ($example_list_data = db_fetch_object($example_list_q))
+ while ($example_list_data = $example_list_q->fetchObject())
{
$example_file_type = '';
switch ($example_list_data->filetype)
@@ -410,11 +293,16 @@ function textbook_companion_run_form($form_state, $pref_id = NULL)
}
/* dependency files */
- $dependency_list_q = db_query("SELECT dependency.id as dependency_id, dependency.filename as dependency_filename, dependency.caption as dependency_caption
- FROM {textbook_companion_example_dependency} example_dependency LEFT JOIN {textbook_companion_dependency_files} dependency
- ON example_dependency.dependency_id = dependency.id
- WHERE example_dependency.example_id = %d", $form_state['values']['run']['example']);
- while ($dependency_list_data = db_fetch_object($dependency_list_q))
+ // $dependency_list_q = db_query("SELECT dependency.id as dependency_id, dependency.filename as dependency_filename, dependency.caption as dependency_caption
+ // FROM {textbook_companion_example_dependency} example_dependency LEFT JOIN {textbook_companion_dependency_files} dependency
+ // ON example_dependency.dependency_id = dependency.id
+ // WHERE example_dependency.example_id = %d", $form_state['values']['run']['example']);
+ $query = db_select('textbook_companion_example_dependency', 'example_dependency');
+ $query->fields('dependency', array('id', 'filename', 'caption'));
+ $query->leftJoin('textbook_companion_dependency_files', 'dependency', 'example_dependency.dependency_id = dependency.id');
+ $query->condition('example_dependency.example_id', $form_state['values']['example_list']);
+ $dependency_list_q = $query->execute();
+ while ($dependency_list_data = $dependency_list_q->fetchObject())
{
$example_file_type = 'Dependency file';
$temp_caption = '';
@@ -425,165 +313,193 @@ function textbook_companion_run_form($form_state, $pref_id = NULL)
/* creating list of files table */
$example_files_header = array('Filename', 'Type');
- $example_files = theme_table($example_files_header, $example_files_rows);
- }
- $form['run']['download_example'] = array(
- '#type' => 'item',
- '#value' => l('Download Scilab code for the example', 'download/example/' . $example_default_value),
- );
- $form['run']['example_files'] = array(
- '#type' => 'item',
- '#title' => 'List of example files',
- '#value' => $example_files,
- );
- //$form['run']['submit'] = array(
- // '#type' => 'submit',
- // '#value' => t('Run')
- //);
- if (user_access('create feedback'))
- {
- $form['run']['feedback'] = array(
- '#type' => 'textarea',
- '#title' => t('Feedback on the above example')
- );
- $form['run']['feedback_submit'] = array(
- '#type' => 'submit',
- '#value' => t('Submit')
- );
+ $example_files = theme('table', array('header' => $example_files_header, 'rows' => $example_files_rows));
}
+
+ $commands[] = ajax_command_html("#ajax-download-example-code-replace", l('Download Scilab code for the example', 'download/example/' . $example_list_default_value));
+ $commands[] = ajax_command_html("#ajax-download-example-files-replace", $example_files);
+
+
+
+ }else{
+
+ $commands[] = ajax_command_html("#ajax-download-example-code-replace", '');
+ $commands[] = ajax_command_html("#ajax-download-example-files-replace", '');
+
}
- }
- /************ END OF $_POST **************/
-
- return $form;
-}
-
-function textbook_companion_run_form_submit($form, &$form_state)
-{
- global $user;
-
- if ($form_state['clicked_button']['#value'] == 'Submit')
- {
- if (user_access('create feedback'))
- {
- $example_data = db_fetch_object(db_query("SELECT * FROM {textbook_companion_example} WHERE id = %d", $form_state['values']['run']['example']));
- if (!$example_data)
- {
- drupal_set_message(t('Invalid example selected'), 'error');
- return;
- }
- $chapter_data = db_fetch_object(db_query("SELECT * FROM {textbook_companion_chapter} WHERE id = %d", $example_data->chapter_id));
- if (!$chapter_data)
- {
- drupal_set_message(t('Invalid chapter selected'), 'error');
- return;
- }
- $book_data = db_fetch_object(db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d", $chapter_data->preference_id));
- if (!$book_data)
- {
- drupal_set_message(t('Invalid book selected'), 'error');
- return;
- }
- $proposal_data = db_fetch_object(db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d", $book_data->proposal_id));
- if (!$proposal_data)
- {
- drupal_set_message(t('Invalid proposal selected'), 'error');
- return;
- }
- db_query("INSERT INTO {textbook_companion_feedback} (example_id, uid, feedback, ip_address, timestamp) VALUES (%d, %d, '%s', '%s', %d)",
- $example_data->id,
- $user->uid,
- $form_state['values']['run']['feedback'],
- $_SERVER['REMOTE_ADDR'],
- time());
-
- /* sending email */
- $param['feedback_received']['user_id'] = $user->uid;
- $param['feedback_received']['book_title'] = $book_data->book;
- $param['feedback_received']['chapter_number'] = $chapter_data->number;
- $param['feedback_received']['chapter_title'] = $chapter_data->name;
- $param['feedback_received']['example_no'] = $example_data->number;
- $param['feedback_received']['feedback'] = $form_state['values']['run']['feedback'];
-
- $email_to = $user->mail;
- // . ', ' . user_load($proposal_data->uid)->mail. ', ' . user_load($example_data->approver_uid)->mail;
- if (!drupal_mail('textbook_companion', 'feedback_received', $email_to, language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE))
- drupal_set_message('Error sending email message.', 'error');
-
- drupal_set_message(t('Thank you for your feedback.'), 'status');
- } else {
- drupal_set_message(t('You do not have permission to submit feeback.'), 'error');
+
+ return array('#type' => 'ajax', '#commands' => $commands);
+
+ }
+ /*******************************************************************/
+ function bootstrap_table_format($headers, $rows) {
+ $thead = "";
+ $tbody = "";
+ foreach($headers as $header) {
+ $thead .= "<th>{$header}</th>";
+ }
+ foreach($rows as $row) {
+ $tbody .= "<tr>";
+ foreach($row as $data) {
+ $tbody .= "<td>{$data}</td>";
+ }
+ $tbody .= "</tr>";
+ }
+ $table = "
+ <table class='table table-bordered table-hover' style='margin-left:-140px'>
+ <thead>{$thead}</thead>
+ <tbody>{$tbody}</tbody>
+ </table>
+ ";
+ return $table;
}
- }
-}
-
-function _list_of_books($category_default_value)
-{
- $book_titles = array('0' => 'Please select...');
+
+ /***********************************************************************************/
+
+
+ function _list_of_category()
+ {
+ $category_titles = array(0 => 'Please select category ...',
+ 1 => 'Fluid Mechanics',
+ 2 => 'Control Theory & Control Systems',
+ 3 => 'Chemical Engineering',
+ 4 => 'Thermodynamics',
+ 5 => 'Mechanical Engineering',
+ 6 => 'Signal Processing',
+ 7 => 'Digital Communications',
+ 8 => 'Electrical Technology',
+ 9 => 'Mathematics & Pure Science',
+ 10 => 'Analog Electronics',
+ 11 => 'Digital Electronics',
+ 12 => 'Computer Programming',
+ 13 => 'Others'
+ );
+
+
+ return $category_titles;
+ }
+
+ function _list_of_books($category_default_value)
+ {
+ $book_titles = array(0 => 'Please select ...');
// $book_titles_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE category=".$category_default_value." AND approval_status = 1 OR approval_status = 3 ORDER BY book ASC");
- $book_titles_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE category=".$category_default_value." AND approval_status = 1 AND proposal_id IN (SELECT id FROM textbook_companion_proposal WHERE proposal_status=3) ORDER BY book ASC");
- while ($book_titles_data = db_fetch_object($book_titles_q))
- {
- $book_titles[$book_titles_data->id] = $book_titles_data->book . ' (Written by ' . $book_titles_data->author . ')';
- }
- return $book_titles;
-}
-
-function _list_of_chapters($preference_id = 0)
-{
- $book_chapters = array('0' => 'Please select...');
- $book_chapters_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE preference_id = %d ORDER BY number ASC", $preference_id);
- while ($book_chapters_data = db_fetch_object($book_chapters_q))
- {
- $book_chapters[$book_chapters_data->id] = $book_chapters_data->number . '. ' . $book_chapters_data->name;
- }
- return $book_chapters;
-}
-
-function _list_of_examples($chapter_id = 0)
-{
- $book_examples = array('0' => 'Please select...');
- $book_examples_q = db_query("SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d AND approval_status = 1 ORDER BY
- CAST(SUBSTRING_INDEX(number, '.', 1) AS BINARY) ASC,
- CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(number , '.', 2), '.', -1) AS UNSIGNED) ASC,
- CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(number , '.', -1), '.', 1) AS UNSIGNED) ASC", $chapter_id);
- while ($book_examples_data = db_fetch_object($book_examples_q))
- {
- $book_examples[$book_examples_data->id] = $book_examples_data->number . ' (' . $book_examples_data->caption . ')';
- }
- return $book_examples;
-}
-
-function _book_information($preference_id)
-{
- $book_data = db_fetch_object(db_query("SELECT
+ // $book_titles_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE category=".$category_default_value." AND approval_status = 1 AND proposal_id IN (SELECT id FROM textbook_companion_proposal WHERE proposal_status=3) ORDER BY book ASC");
+// var_dump('ok= '. $category_default_value);
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('category', $category_default_value);
+ $query->condition('approval_status', 1);
+
+ $subquery = db_select('textbook_companion_proposal');
+ $subquery->fields('textbook_companion_proposal', array('id'));
+ $subquery->condition('proposal_status', 3);
+ $query->condition('proposal_id', $subquery, 'IN');
+
+ $query->orderBy('book', 'ASC');
+ $book_titles_q = $query->execute();
+ while ($book_titles_data = $book_titles_q->fetchObject())
+ {
+ $book_titles[$book_titles_data->id] = $book_titles_data->book . ' (Written by ' . $book_titles_data->author . ')';
+ }
+ return $book_titles;
+ }
+
+
+ function _list_of_chapters($preference_id = 0)
+ {
+ $book_chapters = array(0 => 'Please select...');
+ //$book_chapters_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE preference_id = %d ORDER BY number ASC", $preference_id);
+
+ $query = db_select('textbook_companion_chapter');
+ $query->fields('textbook_companion_chapter');
+ $query->condition('preference_id', $preference_id);
+ $query->orderBy('number', 'ASC');
+ $book_chapters_q = $query->execute();
+
+ while ($book_chapters_data = $book_chapters_q->fetchObject())
+ {
+ $book_chapters[$book_chapters_data->id] = $book_chapters_data->number . '. ' . $book_chapters_data->name;
+ }
+ return $book_chapters;
+ }
+
+
+ function _list_of_examples($chapter_id = 0)
+ {
+ $book_examples = array(0 => 'Please select...');
+ //$book_examples_q = db_query("SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d AND approval_status = 1 ORDER BY
+ // CAST(SUBSTRING_INDEX(number, '.', 1) AS BINARY) ASC,
+ // CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(number , '.', 2), '.', -1) AS UNSIGNED) ASC,
+ // CAST(SUBSTRING_INDEX(SUBSTRING_INDEX(number , '.', -1), '.', 1) AS UNSIGNED) ASC", $chapter_id);
+ $query = db_select('textbook_companion_example');
+ $query->fields('textbook_companion_example');
+ $query->condition('chapter_id', $chapter_id);
+ $query->condition('approval_status', 1);
+ //$query->orderBy('', '');
+ $book_examples_q = $query->execute();
+ while ($book_examples_data = $book_examples_q->fetchObject())
+ {
+ $book_examples[$book_examples_data->id] = $book_examples_data->number . ' (' . $book_examples_data->caption . ')';
+ }
+ return $book_examples;
+ }
+
+ function _book_information($preference_id)
+ {
+ /*$book_data = 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", $preference_id));
- return $book_data;
+ FROM {textbook_companion_proposal} proposal LEFT JOIN {textbook_companion_preference} preference ON proposal.id = preference.proposal_id WHERE preference.id = %d", $preference_id));*/
+ $query = db_select('textbook_companion_proposal', 'proposal');
+ $query->fields('preference', array('book', 'author', 'isbn', 'publisher', 'edition', 'year'));
+ $query->fields('proposal', array('full_name', 'faculty', 'reviewer', 'course', 'branch', 'university'));
+ $query->leftJoin('textbook_companion_preference', 'preference', 'proposal.id = preference.proposal_id');
+ $query->condition('preference.id', $preference_id);
+ $book_data = $query->execute()->fetchObject();
+
+ return $book_data;
}
-
-function _html_book_info($preference_id) {
- $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=".$preference_id));
- $html_data = '';
- if($book_details) {
- $html_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>';
- }
-
- return $html_data;
+ function _html_book_info($preference_id) {
+ /*$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=".$preference_id));*/
+ $query = db_select('textbook_companion_proposal', 'proposal');
+ $query->addField('preference','book','preference_book');
+ $query->addField('preference','author','preference_author');
+ $query->addField('preference','isbn','preference_isbn');
+ $query->addField('preference','publisher','preference_publisher');
+ $query->addField('preference','edition','preference_edition');
+ $query->addField('preference','year','preference_year');
+ $query->addField('proposal','full_name','proposal_full_name');
+ $query->addField('proposal','faculty','proposal_faculty');
+ $query->addField('proposal','reviewer','proposal_reviewer');
+ $query->addField('proposal','course','proposal_course');
+ $query->addField('proposal','branch','proposal_branch');
+ $query->addField('proposal','university','proposal_university');
+ $query->fields('proposal', array('full_name', 'faculty', 'reviewer', 'course', 'branch', 'university'));
+ $query->leftJoin('textbook_companion_preference', 'preference', 'proposal.id = preference.proposal_id');
+ $query->fields('preference', array('book', 'author', 'isbn', 'publisher', 'edition', 'year'));
+ $query->condition('preference.id', $preference_id);
+ $book_details = $query->execute()->fetchObject();
+
+ $html_data = '';
+ if($book_details) {
+ $html_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>';
+ }
+
+ return $html_data;
}
+
diff --git a/search.inc b/search.inc
index 9990b8c..80d576d 100755
--- a/search.inc
+++ b/search.inc
@@ -1,9 +1,9 @@
<?php
// $Id$
-function textbook_companion_search_form()
+function textbook_companion_search_form($form,&$form_state)
{
- $form['#redirect'] = FALSE;
+ // $form['#redirect'] = FALSE;
$form['search'] = array(
'#type' => 'textfield',
'#title' => t('Search'),
@@ -24,51 +24,93 @@ function textbook_companion_search_form()
$form['submit'] = array(
'#type' => 'submit',
- '#value' => t('Search')
+ '#value' => t('Search'),
+ '#ajax' => array(
+ 'callback' => 'textbook_companion_search_ajax_callback',
+ ),
);
$form['cancel'] = array(
- '#type' => 'markup',
- '#value' => l(t('Cancel'), ''),
+ '#type' => 'item',
+ '#markup' => l(t('Cancel'), ''),
);
+ $form['search_results'] = array(
+ '#type' => 'item',
+ '#prefix' => '<div id ="search-result">',
+ // '#title' => t('Search results for "') . $_POST['search'] . '"',
+ '#markup' => '',
+ '#suffix' => '</div>',
+ );
- if ($_POST)
- {
- $output = '';
- $search_rows = array();
- $search_query = '';
- if ($_POST['search_by_title'] && $_POST['search_by_author'])
- $search_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE approval_status = 1 AND (book LIKE '%%%s%%' OR author LIKE '%%%s%%')", $_POST['search'], $_POST['search']);
- else if ($_POST['search_by_title'])
- $search_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE approval_status = 1 AND book LIKE '%%%s%%'", $_POST['search']);
- else if ($_POST['search_by_author'])
- $search_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE approval_status = 1 AND author LIKE '%%%s%%'", $_POST['search']);
- else
- drupal_set_message('Please select whether to search by Title and/or Author of the Book.', 'error');
- while ($search_data = db_fetch_object($search_q))
+ return $form;
+}
+function textbook_companion_search_ajax_callback($form,$form_state){
+ if ($form_state['values']['search_by_title'] && $form_state['values']['search_by_author']){
+
+ $search_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE approval_status = 1 AND (book LIKE :book OR author LIKE :author)", array(':book' => '%%'.$form_state['values']['search'].'%%',':author' =>'%%'.$form_state['values']['search'].'%%'));
+while ($search_data = $search_q->fetchObject())
{
- $search_rows[] = array(l($search_data->book, 'textbook_run/' . $search_data->id), $search_data->author);
+ $search_rows[] = array(l($search_data->book, 'textbook_run/' . $search_data->id), $search_data->author);
}
+
if ($search_rows)
{
$search_header = array('Title of the Book', 'Author Name');
- $output .= theme_table($search_header, $search_rows);
- $form['search_results'] = array(
- '#type' => 'item',
- '#title' => t('Search results for "') . $_POST['search'] . '"',
- '#value' => $output,
- );
- } else {
- $form['search_results'] = array(
- '#type' => 'item',
- '#title' => t('Search results for "') . $_POST['search'] . '"',
- '#value' => 'No results found',
- );
+ $output .= theme('table',array('header'=>$search_header, 'rows'=>$search_rows));
+ $form['search_results']['#markup'] = $output;
+ $form['search_results']['#title'] = t('Search results for "') . $_POST['search'] . '"';
+
+ }
+ else{
+ $form['search_results']['#title'] = t('Search results for "') . $_POST['search'] . '" is not available';
+
+ }
+
+ }elseif ($form_state['values']['search_by_title']){
+
+ $search_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE approval_status = 1 AND book LIKE :search",array(':search' => '%%'.$form_state['values']['search'].'%%'));
+
+ }else if ($form_state['values']['search_by_author']){
+
+ $search_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE approval_status = 1 AND author LIKE :search",array(':search' => '%%'.$form_state['values']['search'].'%%'));
+
+}
+/*while ($search_data = $search_q->fetchObject())
+ {
+ $search_rows[] = array(l($search_data->book, 'textbook_run/' . $search_data->id), $search_data->author);
}
- }
- return $form;
+
+ if ($search_rows)
+ {
+ $search_header = array('Title of the Book', 'Author Name');
+ $output .= theme('table',array('header'=>$search_header, 'rows'=>$search_rows));
+ $form_state['search_result'] = $output;
+ }
+ else{
+ $form_state['search_result'] = 'not available';
+
+ }*/
+
+ $commands[] = ajax_command_replace("#search-result", drupal_render($form['search_results']));
+
+ return array('#type' => 'ajax', '#commands' => $commands);
}
+function textbook_search_display($search_q){
+while ($search_data = $search_q->fetchObject())
+ {
+ $search_rows[] = array(l($search_data->book, 'textbook_run/' . $search_data->id), $search_data->author);
+ }
+
+ if ($search_rows)
+ {
+ $search_header = array('Title of the Book', 'Author Name');
+ $output .= theme('table',array('header'=>$search_header, 'rows'=>$search_rows));
+ }
+ else{$output = 'not available'; }
+ return $output;
+
+}
/******************************************************************************/
/**************************** BROWSE BY FORMS *********************************/
/******************************************************************************/
@@ -84,8 +126,16 @@ function textbook_companion_browse_book()
return $return_html;
}
$book_rows = array();
- $book_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE book like '%s%%' AND approval_status = 1", $query_character);
- while ($book_data = db_fetch_object($book_q))
+
+ /*$book_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE book like '%s%%' AND approval_status = 1", $query_character);*/
+
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('book', ''.$query_character.'%%', 'like');
+ $query->condition('approval_status', 1);
+ $book_q = $query->execute();
+
+ while ($book_data = $book_q->fetchObject())
{
$book_rows[] = array(l($book_data->book, 'textbook_run/' . $book_data->id), $book_data->author);
}
@@ -94,7 +144,7 @@ function textbook_companion_browse_book()
$return_html .= "Sorry no books are available with that title";
} else {
$book_header = array('Title of the Book', 'Author Name');
- $return_html .= theme_table($book_header, $book_rows);
+ $return_html .= theme('table',array('headers'=>$book_header,'rows'=> $book_rows));
}
return $return_html;
}
@@ -110,8 +160,17 @@ function textbook_companion_browse_author()
return $return_html;
}
$book_rows = array();
- $book_q = db_query("SELECT pe.book as book, pe.author as author, pe.publisher as publisher, pe.year as year, pe.id as id FROM {textbook_companion_preference} pe RIGHT JOIN {textbook_companion_proposal} po on pe.proposal_id=po.id WHERE po.proposal_status=3 and pe.approval_status = 1", $query_character);
- while ($book_data = db_fetch_object($book_q))
+
+ /*$book_q = db_query("SELECT pe.book as book, pe.author as author, pe.publisher as publisher, pe.year as year, pe.id as id FROM {textbook_companion_preference} pe RIGHT JOIN {textbook_companion_proposal} po on pe.proposal_id=po.id WHERE po.proposal_status=3 and pe.approval_status = 1", $query_character);*/
+
+ $query = db_select('textbook_companion_preference', 'pe');
+ $query->fields('pe', array('book', 'author', 'publisher', 'year', 'id'));
+ $query->rightJoin('textbook_companion_proposal', 'po', 'pe.proposal_id = po.id');
+ $query->condition('po.proposal_status', 3);
+ $query->condition('pe.approval_status', 1);
+ $book_q = $query->execute();
+
+ while ($book_data = $book_q->fetchObject())
{
/* Initial's fix algorithm */
preg_match_all("/{$query_character}[a-z]+/", $book_data->author, $matches);
@@ -145,7 +204,7 @@ function textbook_companion_browse_author()
$return_html .= "Sorry no books are available with that author's name";
} else {
$book_header = array('Title of the Book', 'Author Name');
- $return_html .= theme_table($book_header, $book_rows);
+ $return_html .= theme('table',array('headers'=>$book_header,'rows'=>$book_rows));
}
return $return_html;
}
@@ -163,12 +222,23 @@ function textbook_companion_browse_student()
return $return_html;
}
$book_rows = array();
- $student_q = db_query("
+
+ /*$student_q = db_query("
SELECT po.full_name, 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
WHERE po.proposal_status = 3 AND pe.approval_status = 1 AND full_name LIKE '%s%%'
- ", $query_character);
- while ($student_data = db_fetch_object($student_q))
+ ", $query_character);*/
+
+ $query = db_select('textbook_companion_preference', 'pe');
+ $query->fields('po', array('full_name', 'approval_date'));
+ $query->fields('pe', array('book', 'author', 'publisher', 'year', 'id'));
+ $query->leftJoin('textbook_companion_proposal', 'po', 'pe.proposal_id = po.id');
+ $query->condition('po.proposal_status', 3);
+ $query->condition('pe.approval_status', 1);
+ $query->condition('full_name', ''.$query_character.'%%', 'LIKE');
+ $student_q = $query->execute();
+
+ while ($student_data = $student_q->fetchObject())
{
$book_rows[] = array(l($student_data->book, 'textbook_run/' . $student_data->pe_id), $student_data->full_name);
}
@@ -177,7 +247,7 @@ function textbook_companion_browse_student()
$return_html .= "Sorry no books are available with that student's name";
} else {
$book_header = array('Title of the Book', 'Student Name');
- $return_html .= theme_table($book_header, $book_rows);
+ $return_html .= theme('table',array('headers'=>$book_header, 'rows'=>$book_rows));
}
return $return_html;
}
@@ -197,8 +267,20 @@ function _browse_list($type)
function _list_of_colleges()
{
$college_names = array('0' => '--- select ---');
- $college_names_q = db_query("SELECT DISTINCT university FROM {textbook_companion_proposal} WHERE proposal_status=1 OR proposal_status=3 ORDER BY university ASC");
- while ($college_names_data = db_fetch_object($college_names_q))
+
+ /*$college_names_q = db_query("SELECT DISTINCT university FROM {textbook_companion_proposal} WHERE proposal_status=1 OR proposal_status=3 ORDER BY university ASC");*/
+
+ $query = db_select('textbook_companion_proposal');
+ $query =distinct();
+ $query->fields('university', array(''));
+ $or = db_or();
+ $or->condition('proposal_status', 1);
+ $or->condition('proposal_status', 3);
+ $query->condition($or);
+ $query->orderBy('university', 'ASC');
+ $college_names_q = $query->execute();
+
+ while ($college_names_data = $college_names_q->fetchObject())
{
$college_names[$college_names_data->university] = $college_names_data->university;
}
@@ -206,11 +288,26 @@ function _list_of_colleges()
}
function _list_books_by_college($college) {
- $query = "SELECT pro.full_name, pro.proposal_status, pre.id as preid, pre.book, pre.isbn FROM textbook_companion_proposal pro, textbook_companion_preference pre WHERE pro.university='".$college."' AND (pro.proposal_status=1 OR pro.proposal_status=3) AND pre.proposal_id=pro.id AND pre.approval_status=1";
- $result = db_query($query);
+
+ /*$query = "SELECT pro.full_name, pro.proposal_status, pre.id as preid, pre.book, pre.isbn FROM textbook_companion_proposal pro, textbook_companion_preference pre WHERE pro.university='".$college."' AND (pro.proposal_status=1 OR pro.proposal_status=3) AND pre.proposal_id=pro.id AND pre.approval_status=1";
+ $result = db_query($query);*/
+
+ $query = db_select('textbook_companion_proposal', 'pro');
+ $query->fields('pro', array('full_name', 'proposal_status'));
+ $query->fields('pre', array('id', 'book', 'isbn'));
+ $query->condition('pro.university', $college);
+
+ $or = db_or();
+ $or->condition('pro.proposal_status', 1);
+ $or->condition('pro.proposal_status', 3);
+ $query->condition($or);
+ $query->condition('pre.proposal_id', 'pro.id');
+ $query->condition('pre.approval_status', 1);
+ $result = $query->execute();
+
$output = '<table><tr><th>SNO</th><th>Name</th><th>Book</th><th>ISBN</th><th>Status</th></tr>';
$sno = 1;
- while($row = db_fetch_object($result)) {
+ while($row = $result->fetchObject()) {
if($row->proposal_status == 1) {
$output .= '<tr><td>'.$sno++.'</td><td>'.$row->full_name.'</td><td>'.$row->book.'</td><td>'.str_replace("-", "", $row->isbn).'</td><td style="color: orange;">Approved</td>';
diff --git a/settings.inc b/settings.inc
index e31c8a0..16d1126 100755
--- a/settings.inc
+++ b/settings.inc
@@ -12,6 +12,15 @@ function textbook_companion_settings_form($form_state)
'#required' => TRUE,
'#default_value' => variable_get('textbook_companion_emails', ''),
);
+ $form['bcc_emails_rem'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Notification emails of failed reminder bcc'),
+ '#description' => t('A comma separated list of email addresses to receive notifications emails'),
+ '#size' => 50,
+ '#maxlength' => 255,
+ '#required' => TRUE,
+ '#default_value' => variable_get('textbook_companion_emails_fail_rem_bcc', ''),
+ );
$form['to_emails'] = array(
'#type' => 'textfield',
'#title' => t('Notification emails to all'),
@@ -84,6 +93,7 @@ function textbook_companion_settings_form_validate($form, &$form_state)
function textbook_companion_settings_form_submit($form, &$form_state)
{
variable_set('textbook_companion_emails', $form_state['values']['emails']);
+ variable_set('textbook_companion_emails_fail_rem_bcc', $form_state['values']['bcc_emails_rem']);
variable_set('textbook_companion_emails_all', $form_state['values']['to_emails']);
variable_set('textbook_companion_from_email', $form_state['values']['from_email']);
variable_set('textbook_companion_source_extensions', $form_state['values']['source']);
diff --git a/textbook_companion.info b/textbook_companion.info
index 3294d2d..9dcee2f 100755
--- a/textbook_companion.info
+++ b/textbook_companion.info
@@ -2,5 +2,5 @@ name = Textbook Companion
description = IIT Bombay Textbook Companion project
package = IITB
version = VERSION
-core = 6.x
-dependencies[] = ahah_helper
+core = 7.x
+
diff --git a/textbook_companion.module b/textbook_companion.module
index 119ff33..fb93f01 100755
--- a/textbook_companion.module
+++ b/textbook_companion.module
@@ -322,27 +322,45 @@ function textbook_companion_menu()
'weight' => 5,
);
- $items['textbook_run'] = array(
+ /* $items['textbook_run'] = array(
'title' => 'Download Codes',
'page callback' => 'drupal_get_form',
'page arguments' => array('textbook_companion_run_form_ajax'),
'access arguments' => array('access content'),
'type' => MENU_NORMAL_ITEM,
'file' => 'run.inc',
- );
- $items['textbook_run_ajax'] = array(
+ );*/
+
+ $items['textbook_run'] = array(
+ 'title' => 'Download Codes',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('textbook_companion_run_form'),
+ 'access arguments' => array('access content'),
+ 'type' => MENU_NORMAL_ITEM,
+ 'file' => 'run.inc',
+
+ );
+ /*$items['textbook_run_ajax'] = array(
'page callback' => 'textbook_run_ajax',
'access callback' => TRUE,
'file' => 'run.inc',
- );
- $items['download_codes'] = array(
+ );*/
+ /*$items['download_codes'] = array(
'title' => 'Download Codes',
'page callback' => 'drupal_get_form',
'page arguments' => array('textbook_companion_run_form_ajax'),
'access arguments' => array('access content'),
'type' => MENU_NORMAL_ITEM,
'file' => 'run.inc',
- );
+ );*/
+ $items['download_codes'] = array(
+ 'title' => 'Download Codes',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('textbook_companion_run_form'),
+ 'access arguments' => array('access content'),
+ 'type' => MENU_NORMAL_ITEM,
+ 'file' => 'run.inc',
+ );
/* download callbacks */
$items['download/file'] = array(
@@ -555,17 +573,125 @@ function textbook_companion_menu()
/**
* Implementation of hook_perm().
*/
-function textbook_companion_perm() {
- return array('create book proposal', 'approve book proposal', 'approve code', 'upload code', 'edit uploaded code', 'download code', 'create feedback', 'bulk manage code', 'bulk delete code', 'edit book proposal', 'administer book companion', 'generate book', 'cheque contct form', 'contact_details', 'comment cheque', 'list all certificates', 'generate pdf', 'paper submission form', 'cheque status form' ,'cheque report form' ,'cheque proposal', 'download books to review');
+function textbook_companion_permission() {
+
+return array(
+ "create book proposal" => array(
+ "title" => t("Book Proposal Form"),
+ "description" => t("Book Proposal Form.")
+ ),
+ "approve book proposal" => array(
+ "title" => t("Approve book proposal"),
+ "description" => t("Allows users to approve book proposal.")
+ ),
+ "approve code" => array(
+ "title" => t("Approve code"),
+ "description" => t("Allows users to approve code.")
+ ),
+ "upload code" => array(
+ "title" => t("Upload code"),
+ "description" => t("Allows users to upload code.")
+ ),
+ "edit uploaded code" => array(
+ "title" => t("Edit uploaded code"),
+ "description" => t("Allows users to edit uploaded code.")
+ ),
+ "download code" => array(
+ "title" => t("Download code"),
+ "description" => t("Allows users to download code.")
+ ),
+ "create feedback" => array(
+ "title" => t("Create feedback"),
+ "description" => t("Allows users to create feedback.")
+ ),
+ "bulk manage code" => array(
+ "title" => t("Bulk manage code"),
+ "description" => t("Allows users to manage Bulk code.")
+ ),
+ "bulk delete code" => array(
+ "title" => t("Bulk delete code"),
+ "description" => t("Allows users to delete bulk code.")
+ ),
+ "edit book proposal" => array(
+ "title" => t("Edit book proposal"),
+ "description" => t("Allows users to edit book proposal.")
+ ),
+ "administer book companion" => array(
+ "title" => t("Administer book companion"),
+ "description" => t("Allows users to administer book companion.")
+ ),
+ "generate book" => array(
+ "title" => t("Generate book"),
+ "description" => t("Allows users to generate book.")
+ ),
+ "cheque contct form" => array(
+ "title" => t("Cheque contact form"),
+ "description" => t("Cheque contct form.")
+ ),
+ "contact_details" => array(
+ "title" => t("Contact_details"),
+ "description" => t("Contact_details.")
+ ),
+ "comment cheque" => array(
+ "title" => t("Comment cheque"),
+ "description" => t("Comment cheque.")
+ ),
+ "list all certificates" => array(
+ "title" => t("list all certificates"),
+ "description" => t("Allows users to list all certificates.")
+ ),
+ "generate pdf" => array(
+ "title" => t("Generate pdf"),
+ "description" => t("Allows users to Generate pdf.")
+ ),
+ "paper submission form" => array(
+ "title" => t("paper submission form"),
+ "description" => t("Paper submission form.")
+ ),
+
+ "cheque status form" => array(
+ "title" => t("Cheque status form"),
+ "description" => t("Cheque status form.")
+ ),
+ "cheque report form" => array(
+ "title" => t("Cheque report form"),
+ "description" => t("Cheque report form.")
+ ),
+ "cheque proposal" => array(
+ "title" => t("Cheque proposal"),
+ "description" => t("Cheque proposal.")
+ ),
+ "download books to review" => array(
+ "title" => t("download books to review"),
+ "description" => t("Download books to review.")
+ ),
+ );
+
}
/* Aicte books pickup before the proposal form */
function textbook_companion_aicte_proposal_form($form_state) {
- $query = "
+ /* $query = "
SELECT * FROM textbook_companion_aicte
WHERE status = 0 AND selected = 0
";
- $result = db_query($query);
+ $result = db_query($query);*/
+
+ /* $query = "
+ SELECT * FROM textbook_companion_aicte
+ WHERE status = :status AND selected = :selected
+ ";
+ $args = array(
+ ':status' => 0,
+ ':selected' => 0,
+ );
+ $result = db_query($query,$args); */
+
+ $query = db_select('textbook_companion_aicte');
+ $query->fields('textbook_companion_aicte');
+ $query->condition('status', 0);
+ $query->condition('selected', 0);
+ $result = $query->execute();
$form = array();
$form["wrapper"] = array(
@@ -573,9 +699,10 @@ function textbook_companion_aicte_proposal_form($form_state) {
"#prefix" => "<div id='aicte-form-wrapper'>",
"#suffix" => "</div>",
);
- $num_rows = mysql_num_rows($result);
+ // $num_rows = mysql_num_rows($result);
+ $num_rows = $query->countQuery();
if ($num_rows > 0) {
- while($row = db_fetch_object($result)) {
+ while($row = $result->fetchObject()) {
/* fixing title string */
$title = "";
$edition = "";
@@ -610,15 +737,21 @@ function textbook_companion_aicte_proposal_form($form_state) {
}
function textbook_companion_aicte_proposal_form_validate($form, &$form_state) {
- $query = "
+ /*$query = "
SELECT * FROM textbook_companion_aicte
WHERE status = 0 AND selected = 0
";
- $result = db_query($query);
+ $result = db_query($query);*/
+
+ $query = db_select('textbook_companion_aicte');
+ $query->fields('textbook_companion_aicte');
+ $query->condition('status', 0);
+ $query->condition('selected', 0);
+ $result = $query->execute();
$count = 0;
$selections = array();
- while($row = db_fetch_object($result)) {
+ while($row = $result->fetchObject()) {
if($form_state["values"][$row->id] == 1) {
$count++;
array_push($selections, $row->id);
@@ -635,20 +768,28 @@ function textbook_companion_aicte_proposal_form_validate($form, &$form_state) {
function textbook_companion_aicte_proposal_form_submit($form, &$form_state) {
global $user;
$selections = $form_state["values"]["selections"];
+ var_dump($selections);
variable_set("aicte_".$user->uid, $selections);
drupal_goto("proposal");
}
function textbook_companion_aicte_report_form($form_state) {
- $query = "
+ /*$query = "
SELECT * FROM textbook_companion_aicte
WHERE status = 0
ORDER BY book
";
- $result = db_query($query);
+ $result = db_query($query);*/
+
+ $query = db_select('textbook_companion_aicte');
+ $query->fields('textbook_companion_aicte');
+ $query->condition('status', 0);
+ $query->orderBy('book', 'ASC');
+ $result = $query->execute();
+
$books = array();
$books[0] = "Please select a book";
- while($row = db_fetch_object($result)) {
+ while($row = $result->fetchObject()) {
$books[$row->id] = "{$row->book} ({$row->author})";
}
$form = array();
@@ -687,7 +828,8 @@ function textbook_companion_aicte_report_form($form_state) {
function textbook_companion_aicte_report_form_submit($form, &$form_state) {
$v = $form_state["values"];
- $query = "
+
+ /*$query = "
INSERT INTO textbook_companion_aicte_report
(aicte_id, name, number, email, comment)
VALUES
@@ -695,7 +837,20 @@ function textbook_companion_aicte_report_form_submit($form, &$form_state) {
";
$result = db_query($query,
$v["book"], $v["name"], $v["number"], $v["email"], $v["comment"]
- );
+ );*/
+
+ $query = "INSERT INTO textbook_companion_aicte_report
+ (aicte_id, name, number, email, comment)
+ VALUES (:aicte_id, :name, :number, :email, :comment)";
+ $args = array(
+ ":aicte_id" => $v["book"],
+ ":name" => $v["name"],
+ ":number" => $v["number"],
+ ":email" =>$v["email"],
+ ":comment" => $v["comment"]
+ );
+ $result = db_query($query, $args, array('return' => Database::RETURN_INSERT_ID));
+
drupal_set_message("Thank you for reporting.", "status");
}
@@ -704,11 +859,16 @@ function textbook_companion_aicte_proposal_all() {
$page_content = "";
if (!$user->uid) {
- $query = "
+ /*$query = "
SELECT * FROM textbook_companion_aicte
WHERE status = 0
";
- $result = db_query($query);
+ $result = db_query($query);*/
+
+ $query = db_select('textbook_companion_aicte');
+ $query->fields('textbook_companion_aicte');
+ $query->condition('status', 0);
+ $result = $query->execute();
$page_content .= "<ul>";
$page_content .= "<li>These are the list of books available for <em>Textbook Companion</em> proposal.</li>";
@@ -719,10 +879,10 @@ function textbook_companion_aicte_proposal_all() {
$page_content .= "Search : <input type='text' id='searchtext' style='width:82%'/>";
$page_content .= "<input type='button' value ='clear' id='search_clear'/>";
$page_content .= "<div id='aicte-list-wrapper'>";
- $num_rows = mysql_num_rows($result);
+ $num_rows = $result->rowCount();
if ($num_rows > 0) {
$i = 1;
- while($row = db_fetch_object($result)) {
+ while($row = $result->fetchObject()) {
/* fixing title string */
$title = "";
$edition = "";
@@ -752,9 +912,18 @@ function textbook_companion_aicte_proposal_all() {
}
/* check if user has already submitted a proposal */
- $proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE uid = %d ORDER BY id DESC LIMIT 1", $user->uid);
+
+ /* $proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE uid = %d ORDER BY id DESC LIMIT 1", $user->uid);*/
+
+ $query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal');
+ $query->condition('uid', $user->uid);
+ $query->orderBy('id', 'DESC');
+ $query->range(0, 1);
+ $proposal_q = $query->execute();
+
if ($proposal_q) {
- if ($proposal_data = db_fetch_object($proposal_q)) {
+ if ($proposal_data = $proposal_q->fetchObject()) {
switch ($proposal_data->proposal_status) {
case 0:
drupal_set_message(t('We have already received your proposal. We will get back to you soon.'), 'status');
@@ -788,7 +957,8 @@ function textbook_companion_aicte_proposal_all() {
$page_content .= "Search : <input type='text' id='searchtext' style='width:82%'/>";
$page_content .= "<input type='button' value ='clear' id='search_clear'/>";
//$page_content .= drupal_get_form("textbook_companion_aicte_report_form");
- $page_content .= drupal_get_form("textbook_companion_aicte_proposal_form");
+ $textbook_companion_aicte_proposal_form = drupal_get_form("textbook_companion_aicte_proposal_form");
+ $page_content .= drupal_render($textbook_companion_aicte_proposal_form);
return $page_content;
}
/*non aicte book proposal */
@@ -805,9 +975,18 @@ function textbook_companion_nonaicte_proposal_all() {
}
/* check if user has already submitted a proposal */
- $proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE uid = %d ORDER BY id DESC LIMIT 1", $user->uid);
+
+ /*$proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE uid = %d ORDER BY id DESC LIMIT 1", $user->uid);*/
+
+ $query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal');
+ $query->condition('uid', $user->uid);
+ $query->orderBy('id', 'DESC');
+ $query->range(0, 1);
+ $proposal_q = $query->execute();
+
if ($proposal_q) {
- if ($proposal_data = db_fetch_object($proposal_q)) {
+ if ($proposal_data = $proposal_q->fetchObject()) {
switch ($proposal_data->proposal_status) {
case 0:
drupal_set_message(t('We have already received your proposal. We will get back to you soon.'), 'status');
@@ -834,8 +1013,9 @@ function textbook_companion_nonaicte_proposal_all() {
}
}
- //variable_del("aicte_".$user->uid);
- $page_content .= drupal_get_form("book_proposal_nonaicte_form");
+ //variable_del("aicte_".$user->uid);
+ $book_proposal_nonaicte_form = drupal_get_form("book_proposal_nonaicte_form");
+ $page_content .= drupal_render($book_proposal_nonaicte_form);
return $page_content;
}
@@ -844,18 +1024,24 @@ function textbook_companion_proposal_all() {
global $user;
$page_content = "";
- if (!$user->uid) {
-
- $page_content .= "<ul>";
- $page_content .= "<li>Please <a href='/user'><b><u>Login</u></b></a> to create a proposal.</li>";
- $page_content .= "</ul>";
- return $page_content;
- }
+ // if (!$user->uid) {
+ // drupal_set_message('It is mandatory to login on this website to access the proposal form', 'error');
+ // return;
+ // }
/* check if user has already submitted a proposal */
- $proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE uid = %d ORDER BY id DESC LIMIT 1", $user->uid);
+
+ /*$proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE uid = %d ORDER BY id DESC LIMIT 1", $user->uid);*/
+
+ $query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal');
+ $query->condition('uid', $user->uid);
+ $query->orderBy('id', 'DESC');
+ $query->range(0, 1);
+ $proposal_q = $query->execute();
+
if ($proposal_q) {
- if ($proposal_data = db_fetch_object($proposal_q)) {
+ if ($proposal_data =$proposal_q->fetchObject()) {
switch ($proposal_data->proposal_status) {
case 0:
drupal_set_message(t('We have already received your proposal. We will get back to you soon.'), 'status');
@@ -884,31 +1070,49 @@ function textbook_companion_proposal_all() {
$selections = variable_get("aicte_".$user->uid, "");
if($selections) {
- $selections = implode(",", $selections);
- $query = "
+
+ /*$query = "
SELECT * FROM textbook_companion_aicte
WHERE id IN ({$selections})
";
- $result = db_query($query);
- $row1 = db_fetch_object($result);
- $row2 = db_fetch_object($result);
- $row3 = db_fetch_object($result);
- $page_content .= drupal_get_form("book_proposal_form", $row1, $row2, $row3);
+ $result = db_query($query);*/
+
+ $query = db_select('textbook_companion_aicte');
+ $query->fields('textbook_companion_aicte');
+ $query->condition('id',$selections[0]);
+ $result1 = $query->execute();
+ $row1 = $result1->fetchObject();
+
+ $query = db_select('textbook_companion_aicte');
+ $query->fields('textbook_companion_aicte');
+ $query->condition('id',$selections[1]);
+ $result2 = $query->execute();
+ $row2 = $result2->fetchObject();
+
+ $query = db_select('textbook_companion_aicte');
+ $query->fields('textbook_companion_aicte');
+ $query->condition('id',$selections[2]);
+ $result3 = $query->execute();
+ $row3 = $result3->fetchObject();
+ $book_proposal_form = drupal_get_form("book_proposal_form", $row1, $row2, $row3);
+
+ $page_content .= drupal_render($book_proposal_form);
} else {
- $page_content .= drupal_get_form("book_proposal_form");
- // drupal_goto("aicte_proposal");
+ // $book_proposal_form = drupal_get_form("book_proposal_form");
+ // $page_content .= drupal_render($book_proposal_form);
+ drupal_goto("aicte_proposal");
}
return $page_content;
}
-function book_proposal_form($form_state, $row1=NULL, $row2=NULL, $row3=NULL)
+function book_proposal_form($form,&$form_state, $row1=NULL, $row2=NULL, $row3=NULL)
{
global $user;
$form = array();
$form['imp_notice'] = array(
'#type' => 'item',
- '#value' => '<font color="red"><b>Please fill up this form carefully as the details entered here will be exactly written in the Textbook Companion</b></font>',
+ '#markup' => '<font color="red"><b>Please fill up this form carefully as the details entered here will be exactly written in the Textbook Companion</b></font>',
);
$form['full_name'] = array(
@@ -981,59 +1185,6 @@ function book_proposal_form($form_state, $row1=NULL, $row2=NULL, $row3=NULL)
'#maxlength' => 50,
'#required' => TRUE,
);
- $form['city'] = array(
- '#type' => 'textfield',
- '#title' => t('City/Village'),
- '#size' => 50,
- '#maxlength' => 50,
- '#required' => TRUE,
- );
- $form['states'] = array(
- '#type' => 'select',
- '#title' => t('State'),
- '#options' => array (
- '' => 'Please select....',
- 'Andhra Pradesh' => 'Andhra Pradesh',
- 'Arunachal Pradesh' => 'Arunachal Pradesh',
- 'Assam' => 'Assam',
- 'Bihar' => 'Bihar',
- 'Chhattisgarh' => 'Chhattisgarh',
- 'Goa' => 'Goa',
- 'Gujarat' => 'Gujarat',
- 'Haryana' => 'Haryana',
- 'Himachal Pradesh' => 'Himachal Pradesh',
- 'Jammu & Kashmir' => 'Jammu & Kashmir',
- 'Jharkhand' => 'Jharkhand',
- 'Karnataka' => 'Karnataka',
- 'Kerala' => 'Kerala',
- 'Madhya Pradesh' => 'Madhya Pradesh',
- 'Maharashtra' => 'Maharashtra',
- 'Manipur' => 'Manipur',
- 'Meghalaya' => 'Meghalaya',
- 'Mizoram' => 'Mizoram',
- 'Nagaland' => 'Nagaland',
- 'Odisha' => 'Odisha',
- 'Punjab' => 'Punjab',
- 'Rajasthan' => 'Rajasthan',
- 'Sikkim' => 'Sikkim',
- 'Tamil Nadu' => 'Tamil Nadu',
- 'Telangana' => 'Telangana',
- 'Tripura' => 'Tripura',
- 'Uttarakhand' => 'Uttarakhand',
- 'Uttar Pradesh'=> 'Uttar Pradesh',
- 'West Bengal' => 'West Bengal',
- 'Andaman & Nicobar' => 'Andaman & Nicobar',
- 'Chandigarh' => 'Chandigarh',
- 'Dadra and Nagar Haveli' => 'Dadra and Nagar Haveli',
- 'Daman & Diu' => 'Daman & Diu',
- 'Delhi' => 'Delhi',
- 'Lakshadweep' => 'Lakshadweep',
- 'Puducherry' => 'Puducherry',
- 'Others' => 'Others',
- ),
- '#required' => TRUE,
-
- );
$form['faculty'] = array(
'#type' => 'hidden',
'#value' => 'None',
@@ -1105,7 +1256,7 @@ function book_proposal_form($form_state, $row1=NULL, $row2=NULL, $row3=NULL)
'#size' => 30,
'#maxlength' => 100,
'#required' => TRUE,
- '#value' => $row1->book,
+ '#default_value' => $row1->book,
'#disabled' => ($row1->book?TRUE:FALSE),
);
$form['preference1']['author1'] = array(
@@ -1114,7 +1265,7 @@ function book_proposal_form($form_state, $row1=NULL, $row2=NULL, $row3=NULL)
'#size' => 30,
'#maxlength' => 100,
'#required' => TRUE,
- '#value' => $row1->author,
+ '#default_value' => $row1->author,
'#disabled' => ($row1->author?TRUE:FALSE),
);
$form['preference1']['isbn1'] = array(
@@ -1123,7 +1274,7 @@ function book_proposal_form($form_state, $row1=NULL, $row2=NULL, $row3=NULL)
'#size' => 30,
'#maxlength' => 25,
'#required' => TRUE,
- '#value' => $row1->isbn,
+ '#default_value' => $row1->isbn,
'#disabled' => ($row1->isbn?TRUE:FALSE),
);
$form['preference1']['publisher1'] = array(
@@ -1132,7 +1283,7 @@ function book_proposal_form($form_state, $row1=NULL, $row2=NULL, $row3=NULL)
'#size' => 30,
'#maxlength' => 50,
'#required' => TRUE,
- '#value' => $row1->publisher,
+ '#default_value' => $row1->publisher,
);
$form['preference1']['edition1'] = array(
'#type' => 'textfield',
@@ -1140,7 +1291,7 @@ function book_proposal_form($form_state, $row1=NULL, $row2=NULL, $row3=NULL)
'#size' => 4,
'#maxlength' => 2,
'#required' => TRUE,
- '#value' => $row1->edition,
+ '#default_value' => $row1->edition,
);
$form['preference1']['year1'] = array(
'#type' => 'textfield',
@@ -1148,7 +1299,7 @@ function book_proposal_form($form_state, $row1=NULL, $row2=NULL, $row3=NULL)
'#size' => 4,
'#maxlength' => 4,
'#required' => TRUE,
- '#value' => $row1->year,
+ '#default_value' => $row1->year,
);
$form['preference2'] = array(
'#type' => 'fieldset',
@@ -1162,7 +1313,7 @@ function book_proposal_form($form_state, $row1=NULL, $row2=NULL, $row3=NULL)
'#size' => 30,
'#maxlength' => 100,
'#required' => TRUE,
- '#value' => $row2->book,
+ '#default_value' => $row2->book,
'#disabled' => ($row2->book?TRUE:FALSE),
);
$form['preference2']['author2'] = array(
@@ -1171,7 +1322,7 @@ function book_proposal_form($form_state, $row1=NULL, $row2=NULL, $row3=NULL)
'#size' => 30,
'#maxlength' => 100,
'#required' => TRUE,
- '#value' => $row2->author,
+ '#default_value' => $row2->author,
'#disabled' => ($row2->author?TRUE:FALSE),
);
$form['preference2']['isbn2'] = array(
@@ -1180,7 +1331,7 @@ function book_proposal_form($form_state, $row1=NULL, $row2=NULL, $row3=NULL)
'#size' => 30,
'#maxlength' => 25,
'#required' => TRUE,
- '#value' => $row2->isbn,
+ '#default_value' => $row2->isbn,
'#disabled' => ($row2->isbn?TRUE:FALSE),
);
$form['preference2']['publisher2'] = array(
@@ -1189,7 +1340,7 @@ function book_proposal_form($form_state, $row1=NULL, $row2=NULL, $row3=NULL)
'#size' => 30,
'#maxlength' => 50,
'#required' => TRUE,
- '#value' => $row2->publisher,
+ '#default_value' => $row2->publisher,
);
$form['preference2']['edition2'] = array(
'#type' => 'textfield',
@@ -1197,7 +1348,7 @@ function book_proposal_form($form_state, $row1=NULL, $row2=NULL, $row3=NULL)
'#size' => 4,
'#maxlength' => 2,
'#required' => TRUE,
- '#value' => $row2->edition,
+ '#default_value' => $row2->edition,
);
$form['preference2']['year2'] = array(
'#type' => 'textfield',
@@ -1205,7 +1356,7 @@ function book_proposal_form($form_state, $row1=NULL, $row2=NULL, $row3=NULL)
'#size' => 4,
'#maxlength' => 4,
'#required' => TRUE,
- '#value' => $row2->year,
+ '#default_value' => $row2->year,
);
$form['preference3'] = array(
'#type' => 'fieldset',
@@ -1219,7 +1370,7 @@ function book_proposal_form($form_state, $row1=NULL, $row2=NULL, $row3=NULL)
'#size' => 30,
'#maxlength' => 100,
'#required' => TRUE,
- '#value' => $row3->book,
+ '#default_value' => $row3->book,
'#disabled' => ($row3->book?TRUE:FALSE),
);
$form['preference3']['author3'] = array(
@@ -1228,7 +1379,7 @@ function book_proposal_form($form_state, $row1=NULL, $row2=NULL, $row3=NULL)
'#size' => 30,
'#maxlength' => 100,
'#required' => TRUE,
- '#value' => $row3->author,
+ '#default_value' => $row3->author,
'#disabled' => ($row3->author?TRUE:FALSE),
);
$form['preference3']['isbn3'] = array(
@@ -1237,7 +1388,7 @@ function book_proposal_form($form_state, $row1=NULL, $row2=NULL, $row3=NULL)
'#size' => 30,
'#maxlength' => 25,
'#required' => TRUE,
- '#value' => $row3->isbn,
+ '#default_value' => $row3->isbn,
'#disabled' => ($row3->isbn?TRUE:FALSE),
);
$form['preference3']['publisher3'] = array(
@@ -1246,7 +1397,7 @@ function book_proposal_form($form_state, $row1=NULL, $row2=NULL, $row3=NULL)
'#size' => 30,
'#maxlength' => 50,
'#required' => TRUE,
- '#value' => $row3->publisher,
+ '#default_value' => $row3->publisher,
);
$form['preference3']['edition3'] = array(
'#type' => 'textfield',
@@ -1254,7 +1405,7 @@ function book_proposal_form($form_state, $row1=NULL, $row2=NULL, $row3=NULL)
'#size' => 4,
'#maxlength' => 2,
'#required' => TRUE,
- '#value' => $row3->edition,
+ '#default_value' => $row3->edition,
);
$form['preference3']['year3'] = array(
'#type' => 'textfield',
@@ -1262,7 +1413,7 @@ function book_proposal_form($form_state, $row1=NULL, $row2=NULL, $row3=NULL)
'#size' => 4,
'#maxlength' => 4,
'#required' => TRUE,
- '#value' => $row3->year,
+ '#default_value' => $row3->year,
);
$form['termconditions'] = array(
'#type' => 'checkboxes',
@@ -1276,25 +1427,20 @@ function book_proposal_form($form_state, $row1=NULL, $row2=NULL, $row3=NULL)
'#value' => t('Submit')
);
- /* #value fix for #default_value bug drupal6 */
+ /* #value fix for #default_value bug drupal6
foreach(array("preference1", "preference2", "preference3") as $preference) {
foreach($form[$preference] as $key => $value) {
if(!$form[$preference][$key]["#value"]) {
unset($form[$preference][$key]["#value"]);
}
}
- }
+ }*/
return $form;
}
-function book_proposal_form_validate($form, &$form_state)
+function book_proposal_form_validate($form,&$form_state)
{
-if($form_state['values']['city']== ''){
- form_set_error('city', t('Invalid city/village'));
- }
- if($form_state['values']['state']== ''){
- form_set_error('state', t('Invalid state'));
- }
+
/* mobile */
if (!preg_match('/^[0-9\ \+]{0,15}$/', $form_state['values']['mobile']))
form_set_error('mobile', t('Invalid mobile number'));
@@ -1353,6 +1499,7 @@ if($form_state['values']['city']== ''){
function book_proposal_form_submit($form, &$form_state)
{
+
global $user;
$selections = variable_get("aicte_".$user->uid, "");
@@ -1373,23 +1520,55 @@ function book_proposal_form_submit($form, &$form_state)
}
//var_dump($form_state['values']);
-
- $query = "INSERT INTO {textbook_companion_proposal}
- (uid, approver_uid, full_name, mobile, gender, how_project, course, branch, university, city, state, faculty, reviewer, completion_date, creation_date, approval_date, proposal_status, scilab_version, operating_system, teacher_email) VALUES (".$user->uid.", 0, '".ucwords(strtolower($form_state['values']['full_name']))."', '".$form_state['values']['mobile']."', '".$form_state['values']['gender']."', '".$form_state['values']['how_project']."', '".$form_state['values']['course']."', '".$form_state['values']['branch']."', '".$form_state['values']['university']."', '".$form_state['values']['city']."','".$form_state['values']['state']."' ,'".ucwords(strtolower($form_state['values']['faculty']))."', '".ucwords(strtolower($form_state['values']['reviewer']))."', '".$completion_date_timestamp."', '".time()."', 0, 0, '".$scilab_version."', '".$form_state['values']['operating_system']."', '".$form_state['values']['faculty_email']."')";
+var_dump('okk');
+ /*$query = "INSERT INTO {textbook_companion_proposal}
+ (uid, approver_uid, full_name, mobile, gender, how_project, course, branch, university, faculty, reviewer, completion_date, creation_date, approval_date, proposal_status, scilab_version, operating_system, teacher_email) VALUES (".$user->uid.", 0, '".ucwords(strtolower($form_state['values']['full_name']))."', '".$form_state['values']['mobile']."', '".$form_state['values']['gender']."', '".$form_state['values']['how_project']."', '".$form_state['values']['course']."', '".$form_state['values']['branch']."', '".$form_state['values']['university']."', '".ucwords(strtolower($form_state['values']['faculty']))."', '".ucwords(strtolower($form_state['values']['reviewer']))."', '".$completion_date_timestamp."', '".time()."', 0, 0, '".$scilab_version."', '".$form_state['values']['operating_system']."', '".$form_state['values']['faculty_email']."')";
+
+ $result = db_query($query);*/
+
+
+$query = "INSERT INTO {textbook_companion_proposal}
+ (uid, approver_uid, full_name, mobile, gender, how_project, course, branch, university, faculty, reviewer, completion_date, creation_date, approval_date, proposal_status, scilab_version, operating_system, teacher_email, message) VALUES (:uid, :approver_uid, :full_name, :mobile, :gender, :how_project, :course, :branch, :university, :faculty, :reviewer, :completion_date,
+ :creation_date, :approval_date, :proposal_status, :scilab_version, :operating_system,
+:teacher_email, :message)";
+$args = array(
+ ":uid" => $user->uid,
+ ":approver_uid" => 0,
+ ":full_name" => ucwords(strtolower($form_state['values']['full_name'])),
+ ":mobile" =>$form_state['values']['mobile'],
+ ":gender" => $form_state['values']['gender'],
+ ":how_project" => $form_state['values']['how_project'],
+ ":course" => $form_state['values']['course'],
+ ":branch" => $form_state['values']['branch'],
+ ":university" => $form_state['values']['university'],
+ ":faculty" => ucwords(strtolower($form_state['values']['faculty'])),
+ ":reviewer" => ucwords(strtolower($form_state['values']['reviewer'])),
+ ":completion_date" => $completion_date_timestamp,
+ ":creation_date" => time(),
+ ":approval_date" => 0,
+ ":proposal_status" => 0,
+ ":scilab_version" => $scilab_version,
+ ":operating_system" => $form_state['values']['operating_system'],
+ ":teacher_email" => $form_state['values']['faculty_email'],
+ ":message" => 'None',
+ );
+
+ $result = db_query($query, $args, array('return' => Database::RETURN_INSERT_ID));
+
- $result = db_query($query);
if (!$result)
{
drupal_set_message(t('Error receiving your proposal. Please try again.'), 'error');
return;
}
/* proposal id */
- $proposal_id = db_last_insert_id('textbook_companion_proposal', 'id');
+ // $proposal_id = db_last_insert_id('textbook_companion_proposal', 'id');
+ $proposal_id = $result;
/* inserting first book preference */
if ($form_state['values']['book1'])
{
- $result = db_query("INSERT INTO {textbook_companion_preference}
+ /*$result = db_query("INSERT INTO {textbook_companion_preference}
(proposal_id, pref_number, book, author, isbn, publisher, edition, year, category, approval_status) VALUES
(%d, %d, '%s', '%s', '%s', '%s', '%s', '%s', %d, %d)",
$proposal_id,
@@ -1402,25 +1581,56 @@ function book_proposal_form_submit($form, &$form_state)
$form_state['values']['year1'],
0,
0
- );
+ );*/
+
+ $query = "INSERT INTO {textbook_companion_preference}
+ (proposal_id, pref_number, book, author, isbn, publisher, edition, year, category, approval_status) VALUES (:proposal_id, :pref_number, :book, :author, :isbn, :publisher, :edition, :year, :category, :approval_status)
+ ";
+
+ $args = array(
+ ":proposal_id" => $proposal_id,
+ ":pref_number" => 1,
+ ":book" => ucwords(strtolower($form_state['values']['book1'])),
+ ":author" => ucwords(strtolower($form_state['values']['author1'])),
+ ":isbn" => $form_state['values']['isbn1'],
+ ":publisher" => ucwords(strtolower($form_state['values']['publisher1'])),
+ ":edition" => $form_state['values']['edition1'],
+ ":year" => $form_state['values']['year1'],
+ ":category" => 0,
+ ":approval_status" => 0,
+ );
+ $result = db_query($query, $args, array('return' => Database::RETURN_INSERT_ID));
+
+
if (!$result)
{
drupal_set_message(t('Error receiving your first book preference.'), 'error');
} else {
- $preference_id = db_last_insert_id("textbook_companion_preference", "id");
- $query = "
+
+ //$preference_id = db_last_insert_id("textbook_companion_preference", "id");
+
+ $preference_id = $result;
+
+ /*$query = "
UPDATE textbook_companion_aicte
SET preference_id = {$preference_id}
WHERE id = {$selections[0]}
";
- db_query($query);
+ db_query($query);*/
+
+ $query = db_update('textbook_companion_aicte');
+ $query->fields(array(
+ 'preference_id' => $preference_id,
+ ));
+ $query->condition('id', $selections[0]);
+ $num_updated = $query->execute();
}
}
/* inserting second book preference */
if ($form_state['values']['book2'])
{
- $result = db_query("INSERT INTO {textbook_companion_preference}
+ /*$result = db_query("INSERT INTO {textbook_companion_preference}
(proposal_id, pref_number, book, author, isbn, publisher, edition, year, category, approval_status) VALUES
(%d, %d, '%s', '%s', '%s', '%s', '%s', '%s', %d, %d)",
$proposal_id,
@@ -1434,24 +1644,53 @@ function book_proposal_form_submit($form, &$form_state)
0,
0
);
+*/
+
+ $query = "INSERT INTO {textbook_companion_preference}
+ (proposal_id, pref_number, book, author, isbn, publisher, edition, year, category, approval_status) VALUES (:proposal_id, :pref_number, :book, :author, :isbn, :publisher, :edition, :year, :category, :approval_status)
+ ";
+
+ $args = array(
+ ":proposal_id" => $proposal_id,
+ ":pref_number" => 2,
+ ":book" => ucwords(strtolower($form_state['values']['book2'])),
+ ":author" => ucwords(strtolower($form_state['values']['author2'])),
+ ":isbn" => $form_state['values']['isbn2'],
+ ":publisher" => ucwords(strtolower($form_state['values']['publisher2'])),
+ ":edition" => $form_state['values']['edition2'],
+ ":year" => $form_state['values']['year2'],
+ ":category" => 0,
+ ":approval_status" => 0
+ );
+ $result = db_query($query, $args, array('return' => Database::RETURN_INSERT_ID));
+
if (!$result)
{
drupal_set_message(t('Error receiving your second book preference.'), 'error');
} else {
- $preference_id = db_last_insert_id("textbook_companion_preference", "id");
- $query = "
+
+ //$preference_id = db_last_insert_id("textbook_companion_preference", "id");
+ $preference_id = $result;
+
+ /*$query = "
UPDATE textbook_companion_aicte
SET preference_id = {$preference_id}
WHERE id = {$selections[1]}
";
- db_query($query);
+ db_query($query);*/
+ $query = db_update('textbook_companion_aicte');
+ $query->fields(array(
+ 'preference_id' => $preference_id,
+ ));
+ $query->condition('id', $selections[1]);
+ $num_updated = $query->execute();
}
}
/* inserting third book preference */
if ($form_state['values']['book3'])
{
- $result = db_query("INSERT INTO {textbook_companion_preference}
+ /*$result = db_query("INSERT INTO {textbook_companion_preference}
(proposal_id, pref_number, book, author, isbn, publisher, edition, year, category, approval_status) VALUES
(%d, %d, '%s', '%s', '%s', '%s', '%s', '%s', %d, %d)",
$proposal_id,
@@ -1464,28 +1703,67 @@ function book_proposal_form_submit($form, &$form_state)
$form_state['values']['year3'],
0,
0
- );
+ );*/
+
+ $query = "INSERT INTO {textbook_companion_preference}
+ (proposal_id, pref_number, book, author, isbn, publisher, edition, year, category, approval_status) VALUES (:proposal_id, :pref_number, :book, :author, :isbn, :publisher, :edition, :year, :category, :approval_status)
+ ";
+
+ $args = array(
+ ":proposal_id" => $proposal_id,
+ ":pref_number" => 3,
+ ":book" => ucwords(strtolower($form_state['values']['book3'])),
+ ":author" => ucwords(strtolower($form_state['values']['author3'])),
+ ":isbn" => $form_state['values']['isbn3'],
+ ":publisher" => ucwords(strtolower($form_state['values']['publisher3'])),
+ ":edition" => $form_state['values']['edition3'],
+ ":year" => $form_state['values']['year3'],
+ ":category" => 0,
+ ":approval_status" => 0
+ );
+ $result = db_query($query, $args, array('return' => Database::RETURN_INSERT_ID));
+
if (!$result)
{
drupal_set_message(t('Error receiving your third book preference.'), 'error');
} else {
- $preference_id = db_last_insert_id("textbook_companion_preference", "id");
- $query = "
+ $preference_id = $result;
+
+ /*$query = "
UPDATE textbook_companion_aicte
SET preference_id = {$preference_id}
WHERE id = {$selections[2]}
";
- db_query($query);
+ db_query($query);*/
+
+ $query = db_update('textbook_companion_aicte');
+ $query->fields(array(
+ 'preference_id' => $preference_id,
+ ));
+ $query->condition('id', $selections[2]);
+ $num_updated = $query->execute();
+
}
/* locking the books in the textbook_companion_aicte table */
foreach ($selections as $selection) {
- $query = "
+ /*$query = "
UPDATE textbook_companion_aicte
SET status = 1, uid = {$user->uid}, proposal_id = {$proposal_id}
WHERE id = {$selection} AND status = 0
";
- db_query($query);
+ db_query($query);*/
+
+ $query = db_update('textbook_companion_aicte');
+ $query->fields(array(
+ 'status' => 1,
+ 'uid' => $user->uid,
+ 'proposal_id' => $proposal_id,
+ ));
+ $query->condition('id', $selection);
+ $query->condition('status', 0);
+ $num_updated = $query->execute();
+
}
if (!$result)
{
@@ -1521,18 +1799,57 @@ function textbook_companion_mail($key, &$message, $params)
// bcc to textbook_companion_emails
$message['headers'] += $tbc_bcc_emails;
/* initializing data */
- $proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d LIMIT 1", $params['proposal_received']['proposal_id']);
- $proposal_data = db_fetch_object($proposal_q);
- $preference1_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $params['proposal_received']['proposal_id'], 1);
- $preference1_data = db_fetch_object($preference1_q);
- $preference2_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $params['proposal_received']['proposal_id'], 2);
- $preference2_data = db_fetch_object($preference2_q);
- $preference3_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $params['proposal_received']['proposal_id'], 3);
- $preference3_data = db_fetch_object($preference3_q);
+
+ /*$proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d LIMIT 1", $params['proposal_received']['proposal_id']);
+ $proposal_data = db_fetch_object($proposal_q);*/
+
+ $query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal');
+ $query->condition('id', $params['proposal_received']['proposal_id']);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $proposal_data =$result->fetchObject();
+
+ /*$preference1_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $params['proposal_received']['proposal_id'], 1);
+ $preference1_data = db_fetch_object($preference1_q);*/
+
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('proposal_id',$params['proposal_received']['proposal_id']);
+ $query->condition('pref_number', 1);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $preference1_data =$result->fetchObject();
+
+
+ /*$preference2_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $params['proposal_received']['proposal_id'], 2);
+ $preference2_data = db_fetch_object($preference2_q);*/
+
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('proposal_id', $params['proposal_received']['proposal_id']);
+ $query->condition('pref_number',2);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $preference2_data =$result->fetchObject();
+
+
+ /*$preference3_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $params['proposal_received']['proposal_id'], 3);
+ $preference3_data = db_fetch_object($preference3_q);*/
+
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('proposal_id', $params['proposal_received']['proposal_id']);
+ $query->condition('pref_number', 3);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $preference3_data =$result->fetchObject();
+
+
$user_data = user_load($params['proposal_received']['user_id']);
- $message['subject'] = t('[!site_name] Your book proposal has been received', array('!site_name' => variable_get('site_name', '')), $language->language);
- $message['body'] = t('
+ $message['subject'] = t('[!site_name] Your book proposal has been received', array('!site_name' => variable_get('site_name', '')), array('language' => $language->language));
+ $message['body'] =array('body' => t('
Dear !user_name,
We have received your following book proposal:
@@ -1580,26 +1897,64 @@ The book will not be alloted to you until we receive the sample codes.
Best Wishes,
-!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language);
+!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), array('language' => $language->language)));
break;
case 'proposal_disapproved':
// bcc to textbook_companion_emails
$message['headers'] += $tbc_bcc_emails;
/* initializing data */
- $proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d LIMIT 1", $params['proposal_disapproved']['proposal_id']);
- $proposal_data = db_fetch_object($proposal_q);
- $preference1_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $params['proposal_disapproved']['proposal_id'], 1);
- $preference1_data = db_fetch_object($preference1_q);
- $preference2_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $params['proposal_disapproved']['proposal_id'], 2);
- $preference2_data = db_fetch_object($preference2_q);
- $preference3_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $params['proposal_disapproved']['proposal_id'], 3);
- $preference3_data = db_fetch_object($preference3_q);
+
+ /*$proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d LIMIT 1", $params['proposal_disapproved']['proposal_id']);
+ $proposal_data = db_fetch_object($proposal_q);*/
+
+ $query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal');
+ $query->condition('id', $params['proposal_disapproved']['proposal_id']);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $proposal_data =$result->fetchObject();
+
+ /*$preference1_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $params['proposal_disapproved']['proposal_id'], 1);
+ $preference1_data = db_fetch_object($preference1_q);*/
+
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('proposal_id', $params['proposal_disapproved']['proposal_id']);
+ $query->condition('pref_number', 1);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $preference1_data =$result->fetchObject();
+
+
+ /*$preference2_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $params['proposal_disapproved']['proposal_id'], 2);
+ $preference2_data = db_fetch_object($preference2_q);*/
+
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('proposal_id', $params['proposal_disapproved']['proposal_id']);
+ $query->condition('pref_number', 2);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $preference2_data =$result->fetchObject();
+
+
+ /*$preference3_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $params['proposal_disapproved']['proposal_id'], 3);
+ $preference3_data = db_fetch_object($preference3_q);*/
+
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('proposal_id', $params['proposal_disapproved']['proposal_id']);
+ $query->condition('pref_number', 3);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $preference3_data =$result->fetchObject();
+
$user_data = user_load($params['proposal_disapproved']['user_id']);
- $message['subject'] = t('[!site_name] Your book proposal has been disapproved', array('!site_name' => variable_get('site_name', '')), $language->language);
+ $message['subject'] = t('[!site_name] Your book proposal has been disapproved', array('!site_name' => variable_get('site_name', '')), array('language' => $language->language));
if($proposal_data->proposal_type != 1){
- $message['body'] = t('
+ $message['body'] =array('body' => t('
Dear !user_name,
Your following book proposal has been disapproved:
@@ -1644,11 +1999,11 @@ Year of publication : ' . $preference3_data->year . '
Best Wishes,
-!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language);
+!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), array('language' => $language->language)));
}
else{
//Non AICTE book proposal dissaprove//
-$message['body'] = t('
+$message['body'] = array('body' => t('
Dear !user_name,
Your following book proposal has been disapproved:
@@ -1679,7 +2034,7 @@ Year of publication : ' . $preference1_data->year . '
Best Wishes,
-!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language);
+!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), array('language' => $language->language)));
}
break;
@@ -1688,15 +2043,33 @@ Best Wishes,
// bcc to textbook_companion_emails
$message['headers'] += $tbc_bcc_emails;
/* initializing data */
- $proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d LIMIT 1", $params['proposal_received']['proposal_id']);
- $proposal_data = db_fetch_object($proposal_q);
- $preference1_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $params['proposal_received']['proposal_id'], 1);
- $preference1_data = db_fetch_object($preference1_q);
-
+
+ /*$proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d LIMIT 1", $params['proposal_received']['proposal_id']);
+ $proposal_data = db_fetch_object($proposal_q);*/
+
+ $query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal');
+ $query->condition('id', $params['proposal_received']['proposal_id']);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $proposal_data =$result->fetchObject();
+
+
+ /*$preference1_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $params['proposal_received']['proposal_id'], 1);
+ $preference1_data = db_fetch_object($preference1_q);*/
+
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('proposal_id',$params['proposal_received']['proposal_id']);
+ $query->condition('pref_number', 1);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $preference1_data=$result->fetchObject();
+
$user_data = user_load($params['proposal_received']['user_id']);
- $message['subject'] = t('[!site_name] Your book proposal has been received', array('!site_name' => variable_get('site_name', '')), $language->language);
- $message['body'] = t('
+ $message['subject'] = t('[!site_name] Your book proposal has been received', array('!site_name' => variable_get('site_name', '')),array('language' => $language->language));
+ $message['body'] =array('body' => t('
Dear !user_name,
We have received your following book proposal:
@@ -1729,21 +2102,38 @@ The book will not be alloted to you until we receive the sample codes.
Best Wishes,
-!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language);
+!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), array('language' => $language->language)));
break;
case 'nonaicte_proposal_to_pi':
// bcc to textbook_companion_emails
$message['headers'] += $tbc_bcc_emails;
/* initializing data */
- $proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d LIMIT 1", $params['proposal_received']['proposal_id']);
- $proposal_data = db_fetch_object($proposal_q);
- $preference1_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $params['proposal_received']['proposal_id'], 1);
- $preference1_data = db_fetch_object($preference1_q);
+
+ /*$proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d LIMIT 1", $params['proposal_received']['proposal_id']);
+ $proposal_data = db_fetch_object($proposal_q);*/
+
+ $query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal');
+ $query->condition('id', $params['proposal_received']['proposal_id']);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $proposal_data=$result->fetchObject();
+
+ /* $preference1_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $params['proposal_received']['proposal_id'], 1);
+ $preference1_data = db_fetch_object($preference1_q);*/
+
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('proposal_id', $params['proposal_received']['proposal_id']);
+ $query->condition('pref_number', 1);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $preference1_data=$result->fetchObject();
$user_data = user_load($params['proposal_received']['user_id']);
- $message['subject'] = t('[!site_name] New Non AICTE book suggestion has been received', array('!site_name' => variable_get('site_name', '')), $language->language);
- $message['body'] = t('
+ $message['subject'] = t('[!site_name] New Non AICTE book suggestion has been received', array('!site_name' => variable_get('site_name', '')), array('language' => $language->language));
+ $message['body'] = array('body' => t('
Dear all,
We have received following Non AICTE book suggestion:
@@ -1771,7 +2161,7 @@ Please click here to provide your feedback: http://scilab.in/comments
Best Wishes,
-!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language);
+!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), array('language' => $language->language)));
break;
@@ -1779,14 +2169,33 @@ Best Wishes,
case 'proposal_approved':
// bcc to textbook_companion_emails
$message['headers'] += $tbc_bcc_emails;
- $proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d LIMIT 1", $params['proposal_approved']['proposal_id']);
- $proposal_data = db_fetch_object($proposal_q);
- $approved_preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND approval_status = 1 LIMIT 1", $params['proposal_approved']['proposal_id']);
- $approved_preference_data = db_fetch_object($approved_preference_q);
+
+ /*$proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d LIMIT 1", $params['proposal_approved']['proposal_id']);
+ $proposal_data = db_fetch_object($proposal_q);*/
+
+ $query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal');
+ $query->condition('id', $params['proposal_approved']['proposal_id']);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $proposal_data=$result->fetchObject();
+
+
+ /* $approved_preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND approval_status = 1 LIMIT 1", $params['proposal_approved']['proposal_id']);
+ $approved_preference_data = db_fetch_object($approved_preference_q);*/
+
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('proposal_id', $params['proposal_approved']['proposal_id']);
+ $query->condition('approval_status', 1);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $approved_preference_data=$result->fetchObject();
+
$user_data = user_load($params['proposal_approved']['user_id']);
- $message['subject'] = t('[!site_name] Your book proposal has been approved', array('!site_name' => variable_get('site_name', '')), $language->language);
- $message['body'] = t('
+ $message['subject'] = t('[!site_name] Your book proposal has been approved', array('!site_name' => variable_get('site_name', '')), array('language' => $language->language));
+ $message['body'] =array('body' => t('
Dear !user_name,
Your following book proposal has been approved:
@@ -1816,21 +2225,39 @@ Please contact us by sending an e-mail to textbook@scilab.in in case you wish to
Best Wishes,
-!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language);
+!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name),array('language' => $language->language)));
break;
case 'proposal_completed':
// bcc to textbook_companion_emails
$message['headers'] += $tbc_bcc_emails;
- $proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d LIMIT 1", $params['proposal_completed']['proposal_id']);
- $proposal_data = db_fetch_object($proposal_q);
- $approved_preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND approval_status = 1 LIMIT 1", $params['proposal_completed']['proposal_id']);
- $approved_preference_data = db_fetch_object($approved_preference_q);
+ /*$proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d LIMIT 1", $params['proposal_completed']['proposal_id']);
+ $proposal_data = db_fetch_object($proposal_q);*/
+
+ $query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal');
+ $query->condition('id', $params['proposal_completed']['proposal_id']);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $proposal_data=$result->fetchObject();
+
+ /*$approved_preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND approval_status = 1 LIMIT 1", $params['proposal_completed']['proposal_id']);
+ $approved_preference_data = db_fetch_object($approved_preference_q);*/
+
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('proposal_id', $params['proposal_completed']['proposal_id']);
+ $query->condition('approval_status', 1);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $approved_preference_data=$result->fetchObject();
+
+
$user_data = user_load($params['proposal_completed']['user_id']);
- $message['subject'] = t('[!site_name] Congratulations for completion of the book.', array('!site_name' => variable_get('site_name', '')), $language->language);
- $message['body'] = t('
+ $message['subject'] = t('[!site_name] Congratulations for completion of the book.', array('!site_name' => variable_get('site_name', '')), array('language' => $language->language));
+ $message['body'] =array('body' => t('
Dear !user_name,
Following book has been completed sucessfully by you:
@@ -1860,18 +2287,27 @@ Now you should be able to propose a new book...
Best Wishes,
-!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language);
+!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name),array('language' => $language->language)));
break;
case 'example_uploaded':
// bcc to textbook_companion_emails
$message['headers'] += $tbc_bcc_emails;
- $example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE id = %d LIMIT 1", $params['example_uploaded']['example_id']);
- $example_data = db_fetch_object($example_q);
+
+ /*$example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE id = %d LIMIT 1", $params['example_uploaded']['example_id']);
+ $example_data = db_fetch_object($example_q);*/
+
+ $query = db_select('textbook_companion_example');
+ $query->fields('textbook_companion_example');
+ $query->condition('id', $params['example_uploaded']['example_id']);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $example_data=$result->fetchObject();
+
$user_data = user_load($params['example_uploaded']['user_id']);
- $message['subject'] = t('[!site_name] You have uploaded example', array('!site_name' => variable_get('site_name', '')), $language->language);
- $message['body'] = t('
+ $message['subject'] = t('[!site_name] You have uploaded example', array('!site_name' => variable_get('site_name', '')), array('language' => $language->language));
+ $message['body'] =array('body' => t('
Dear !user_name,
You have uploaded the following example:
@@ -1886,18 +2322,27 @@ The codes cannot be approved unless the convention is followed.
Best Wishes,
-!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language);
+!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), array('language' => $language->language)));
break;
case 'example_updated':
// bcc to textbook_companion_emails
$message['headers'] += $tbc_bcc_emails;
- $example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE id = %d LIMIT 1", $params['example_updated']['example_id']);
- $example_data = db_fetch_object($example_q);
+
+ /*$example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE id = %d LIMIT 1", $params['example_updated']['example_id']);
+ $example_data = db_fetch_object($example_q);*/
+
+ $query = db_select('textbook_companion_example');
+ $query->fields('textbook_companion_example');
+ $query->condition('id', $params['example_updated']['example_id']);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $example_data=$result->fetchObject();
+
$user_data = user_load($params['example_updated']['user_id']);
- $message['subject'] = t('[!site_name] You have updated example', array('!site_name' => variable_get('site_name', '')), $language->language);
- $message['body'] = t('
+ $message['subject'] = t('[!site_name] You have updated example', array('!site_name' => variable_get('site_name', '')), array('language' => $language->language));
+ $message['body'] =array('body' => t('
Dear !user_name,
You have updated the following example:
@@ -1909,18 +2354,27 @@ The example is still under review. You will be notified when it has been approve
Best Wishes,
-!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language);
+!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), array('language' => $language->language)));
break;
case 'example_updated_admin':
// bcc to textbook_companion_emails
$message['headers'] += $tbc_bcc_emails;
- $example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE id = %d LIMIT 1", $params['example_updated_admin']['example_id']);
- $example_data = db_fetch_object($example_q);
+
+ /*$example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE id = %d LIMIT 1", $params['example_updated_admin']['example_id']);
+ $example_data = db_fetch_object($example_q);*/
+
+ $query = db_select('textbook_companion_example');
+ $query->fields('textbook_companion_example');
+ $query->condition('id', $params['example_updated_admin']['example_id']);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $example_data=$result->fetchObject();
+
$user_data = user_load($params['example_updated_admin']['user_id']);
- $message['subject'] = t('[!site_name] Reviewer have updated example', array('!site_name' => variable_get('site_name', '')), $language->language);
- $message['body'] = t('
+ $message['subject'] = t('[!site_name] Reviewer have updated example', array('!site_name' => variable_get('site_name', '')), array('language' => $language->language));
+ $message['body'] = array('body' =>t('
Dear !user_name,
Reviewer have updated the following example:
@@ -1930,18 +2384,28 @@ Caption : ' . $example_data->caption . '
Best Wishes,
-!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language);
+!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name),array('language' => $language->language)));
break;
case 'example_approved':
// bcc to textbook_companion_emails
$message['headers'] += $tbc_bcc_emails;
- $example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE id = %d LIMIT 1", $params['example_approved']['example_id']);
- $example_data = db_fetch_object($example_q);
+
+ /*$example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE id = %d LIMIT 1", $params['example_approved']['example_id']);
+ $example_data = db_fetch_object($example_q);*/
+
+ $query = db_select('textbook_companion_example');
+ $query->fields('textbook_companion_example');
+ $query->condition('id', $params['example_approved']['example_id']);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $example_data=$result->fetchObject();
+
+
$user_data = user_load($params['example_approved']['user_id']);
- $message['subject'] = t('[!site_name] Your uploaded example has been approved', array('!site_name' => variable_get('site_name', '')), $language->language);
- $message['body'] = t('
+ $message['subject'] = t('[!site_name] Your uploaded example has been approved', array('!site_name' => variable_get('site_name', '')), array('language' => $language->language));
+ $message['body'] =array('body' => t('
Dear !user_name,
Your following example has been approved:
@@ -1951,7 +2415,7 @@ Caption : ' . $example_data->caption . '
Best Wishes,
-!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language);
+!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), array('language' => $language->language)));
break;
case 'example_disapproved':
@@ -1959,8 +2423,8 @@ Best Wishes,
$message['headers'] += $tbc_bcc_emails;
$user_data = user_load($params['example_disapproved']['user_id']);
- $message['subject'] = t('[!site_name] Your uploaded example has been disapproved', array('!site_name' => variable_get('site_name', '')), $language->language);
- $message['body'] = t('
+ $message['subject'] = t('[!site_name] Your uploaded example has been disapproved', array('!site_name' => variable_get('site_name', '')), array('language' => $language->language));
+ $message['body'] = array('body' =>t('
Dear !user_name,
Your following example has been disapproved:
@@ -1972,7 +2436,7 @@ Reason for dis-approval : ' . $params['example_disapproved']['message'] . '
Best Wishes,
-!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language);
+!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name),array('language' => $language->language)));
break;
case 'example_deleted_user':
@@ -1980,8 +2444,8 @@ Best Wishes,
$message['headers'] += $tbc_bcc_emails;
$user_data = user_load($params['example_deleted_user']['user_id']);
- $message['subject'] = t('[!site_name] User has deleted pending example', array('!site_name' => variable_get('site_name', '')), $language->language);
- $message['body'] = t('
+ $message['subject'] = t('[!site_name] User has deleted pending example', array('!site_name' => variable_get('site_name', '')), array('language' => $language->language));
+ $message['body'] =array('body' => t('
Dear !user_name,
Your following pending example has been deleted :
@@ -1993,7 +2457,7 @@ Caption : ' . $params['example_deleted_user']['example_caption'] . '
Best Wishes,
-!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language);
+!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), array('language' => $language->language)));
break;
case 'dependency_uploaded':
@@ -2002,8 +2466,8 @@ Best Wishes,
$user_data = user_load($params['dependency_uploaded']['user_id']);
$dependency_files = implode(',', $params['dependency_uploaded']['dependency_names']);
- $message['subject'] = t('[!site_name] You have uploaded dependency file', array('!site_name' => variable_get('site_name', '')), $language->language);
- $message['body'] = t('
+ $message['subject'] = t('[!site_name] You have uploaded dependency file', array('!site_name' => variable_get('site_name', '')), array('language' => $language->language));
+ $message['body'] = array('body' =>t('
Dear !user_name,
You have uploaded following dependency files :
@@ -2011,7 +2475,8 @@ You have uploaded following dependency files :
Best Wishes,
-!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language);
+!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name),
+array('language' => $language->language)));
break;
case 'feedback_received':
@@ -2019,8 +2484,8 @@ Best Wishes,
$message['headers'] += $tbc_bcc_emails;
$user_data = user_load($params['feedback_received']['user_id']);
- $message['subject'] = t('[!site_name] We have received your feedback', array('!site_name' => variable_get('site_name', '')), $language->language);
- $message['body'] = t('
+ $message['subject'] = t('[!site_name] We have received your feedback', array('!site_name' => variable_get('site_name', '')), array('language' => $language->language));
+ $message['body'] = array('body' =>t('
Dear !user_name,
We have received your following feedback
@@ -2034,7 +2499,7 @@ Your feedback :
Best Wishes,
-!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language);
+!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), array('language' => $language->language)));
break;
case 'internshipform':
@@ -2043,8 +2508,8 @@ Best Wishes,
$user_data = user_load($params['internshipform']['user_id']);
- $message['subject'] = t('[!site_name] We have received your feedback', array('!site_name' => variable_get('site_name', '')), $language->language);
- $message['body'] = t('
+ $message['subject'] = t('[!site_name] We have received your feedback', array('!site_name' => variable_get('site_name', '')), array('language' => $language->language));
+ $message['body'] = array('body' =>t('
Dear !user_name,
We have received your Internship Form Application for the book
@@ -2055,7 +2520,7 @@ Example No.: ' . $params['internshipform']['example_no'] . '
Best Wishes,
-!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language);
+!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name),array('language' => $language->language)));
break;
case 'copyrighttransferform':
@@ -2064,8 +2529,8 @@ case 'copyrighttransferform':
$user_data = user_load($params['copyrighttransferform']['user_id']);
- $message['subject'] = t('[!site_name] We have received your feedback', array('!site_name' => variable_get('site_name', '')), $language->language);
- $message['body'] = t('
+ $message['subject'] = t('[!site_name] We have received your feedback', array('!site_name' => variable_get('site_name', '')), array('language' => $language->language));
+ $message['body'] =array('body' => t('
Dear !user_name,
We have received your Copyright Form Application for the book
@@ -2076,7 +2541,7 @@ Example No.: ' . $params['copyrighttransferform']['example_no'] . '
Best Wishes,
-!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language);
+!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name),array('language' => $language->language)));
break;
case 'undertakingform':
@@ -2085,8 +2550,8 @@ case 'undertakingform':
$user_data = user_load($params['undertakingform']['user_id']);
- $message['subject'] = t('[!site_name] We have received your feedback', array('!site_name' => variable_get('site_name', '')), $language->language);
- $message['body'] = t('
+ $message['subject'] = t('[!site_name] We have received your feedback', array('!site_name' => variable_get('site_name', '')), array('language' => $language->language));
+ $message['body'] =array('body' => t('
Dear !user_name,
We have received your Undertaking Form Application for the book
@@ -2097,7 +2562,7 @@ Example No.: ' . $params['undertakingform']['example_no'] . '
Best Wishes,
-!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language);
+!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), array('language' => $language->language)));
break;
@@ -2107,8 +2572,8 @@ case 'remark':
$user_data = user_load($params['remark']['user_id']);
- $message['subject'] = t('[!site_name] A remark has been given.Please check your contact detail form', array('!site_name' => variable_get('site_name', '')), $language->language);
- $message['body'] = t('
+ $message['subject'] = t('[!site_name] A remark has been given.Please check your contact detail form', array('!site_name' => variable_get('site_name', '')), array('language' => $language->language));
+ $message['body'] =array('body' => t('
Dear !user_name,
A Remark has been given.Please check your Contact Detail Form
@@ -2119,7 +2584,7 @@ Example No.: ' . $params['internshipform']['example_no'] . '
Best Wishes,
-!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language);
+!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), array('language' => $language->language)));
break;
case 'cheque_sent':
@@ -2128,8 +2593,8 @@ Best Wishes,
$user_data = user_load($params['cheque_sent']['user_id']);
- $message['subject'] = t('[!site_name] We have received your feedback', array('!site_name' => variable_get('site_name', '')), $language->language);
- $message['body'] = t('
+ $message['subject'] = t('[!site_name] We have received your feedback', array('!site_name' => variable_get('site_name', '')), array('language' => $language->language));
+ $message['body'] =array('body' => t('
Dear !user_name,
We have Sent Cheque for the following book proposed
@@ -2140,7 +2605,7 @@ Example No.: ' . $params['cheque_sent']['example_no'] . '
Best Wishes,
-!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), $language->language);
+!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), array('language' => $language->language)));
break;
@@ -2161,8 +2626,17 @@ function textbook_companion_ajax()
{
$chapter_number = arg(3);
$preference_id = arg(4);
- $chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE number = %d AND preference_id = %d LIMIT 1", $chapter_number, $preference_id);
- if ($chapter_data = db_fetch_object($chapter_q))
+
+ /*$chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE number = %d AND preference_id = %d LIMIT 1", $chapter_number, $preference_id);*/
+
+ $query = db_select('textbook_companion_chapter');
+ $query->fields('textbook_companion_chapter');
+ $query->condition('number', $chapter_number);
+ $query->condition('preference_id', $preference_id);
+ $query->range(0, 1);
+ $chapter_q = $query->execute();
+
+ if ($chapter_data = $chapter_q->fetchObject())
{
echo $chapter_data->name;
return;
@@ -2173,8 +2647,17 @@ function textbook_companion_ajax()
$example_number = arg(5);
$chapter_id = 0;
- $chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE number = %d AND preference_id = %d LIMIT 1", $chapter_number, $preference_id);
- if (!$chapter_data = db_fetch_object($chapter_q))
+
+ /* $chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE number = %d AND preference_id = %d LIMIT 1", $chapter_number, $preference_id);*/
+
+ $query = db_select('textbook_companion_chapter');
+ $query->fields('textbook_companion_chapter');
+ $query->condition('number',$chapter_number);
+ $query->condition('preference_id', $preference_id);
+ $query->range(0, 1);
+ $chapter_q = $query->execute();
+
+ if (!$chapter_data = $chapter_q->fetchObject())
{
echo '';
return;
@@ -2182,8 +2665,16 @@ function textbook_companion_ajax()
$chapter_id = $chapter_data->id;
}
- $example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d AND number = '%s' LIMIT 1", $chapter_id, $example_number);
- if ($example_data = db_fetch_object($example_q))
+ /*$example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d AND number = '%s' LIMIT 1", $chapter_id, $example_number);*/
+
+ $query = db_select('textbook_companion_example');
+ $query->fields('textbook_companion_example');
+ $query->condition('chapter_id', $chapter_id);
+ $query->condition('number', $example_number);
+ $query->range(0, 1);
+ $example_q = $query->execute();
+
+ if ($example_data =$example_q->fetchObject())
{
if ($example_data->approval_status == 1)
echo 'Warning! Example already approved. You cannot upload the same example again.';
@@ -2232,16 +2723,31 @@ function delete_example($example_id)
$root_path = textbook_companion_path();
$status = TRUE;
- $example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE id = %d", $example_id);
- $example_data = db_fetch_object($example_q);
+ /*$example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE id = %d", $example_id);
+ $example_data = db_fetch_object($example_q);*/
+
+ $query = db_select('textbook_companion_example');
+ $query->fields('textbook_companion_example');
+ $query->condition('id', $example_id);
+ $example_q = $query->execute();
+ $example_data =$example_q->fetchObject();
+
if (!$example_data)
{
drupal_set_message(t('Invalid example.'), 'error');
return FALSE;
}
- $chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE id = %d", $example_data->chapter_id);
- $chapter_data = db_fetch_object($chapter_q);
+ /*$chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE id = %d", $example_data->chapter_id);
+ $chapter_data = db_fetch_object($chapter_q);*/
+
+ $query = db_select('textbook_companion_chapter');
+ $query->fields('textbook_companion_chapter');
+ $query->condition('id', $example_data->chapter_id);
+ $chapter_q = $query->execute();
+ $chapter_data=$chapter_q->fetchObject();
+
+
if (!$chapter_data)
{
drupal_set_message(t('Invalid example chapter.'), 'error');
@@ -2249,8 +2755,15 @@ function delete_example($example_id)
}
/* deleting example files */
- $examples_files_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE example_id = %d", $example_id);
- while ($examples_files_data = db_fetch_object($examples_files_q))
+
+ /*$examples_files_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE example_id = %d", $example_id);*/
+
+ $query = db_select('textbook_companion_example_files');
+ $query->fields('textbook_companion_example_files');
+ $query->condition('example_id', $example_id);
+ $examples_files_q = $query->execute();
+
+ while ($examples_files_data =$examples_files_q->fetchObject())
{
if (!file_exists($root_path . $examples_files_data->filepath))
{
@@ -2260,7 +2773,7 @@ function delete_example($example_id)
}
/* removing example file */
- if (!unlink($root_path . $examples_files_data->filepath))
+ if (!drupal_unlink($root_path . $examples_files_data->filepath))
{
$status = FALSE;
drupal_set_message(t('Error deleting !file', array('!file' => $examples_files_data->filepath)), 'error');
@@ -2268,15 +2781,21 @@ function delete_example($example_id)
/* sending email to admins */
$email_to = variable_get('textbook_companion_emails', '');
$param['standard']['subject'] = "[ERROR] Error deleting example file";
- $param['standard']['body'] = "Error deleting example files by " . $user->uid . " at " . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . " :
+ $param['standard']['body'] = array(0 =>"Error deleting example files by " . $user->uid . " at " . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . " :
example id : " . $example_id . "
file id : " . $examples_files_data->id . "
- file path : " . $examples_files_data->filepath;
+ file path : " . $examples_files_data->filepath);
if (!drupal_mail('textbook_companion', 'standard', $email_to, language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE))
drupal_set_message('Error sending email message.', 'error');
} else {
/* deleting example files database entries */
- db_query("DELETE FROM {textbook_companion_example_files} WHERE id = %d", $examples_files_data->id);
+
+ /*db_query("DELETE FROM {textbook_companion_example_files} WHERE id = %d", $examples_files_data->id);*/
+ $query = db_delete('textbook_companion_example_files');
+ $query->condition('id', $examples_files_data->id);
+ $num_deleted = $query->execute();
+
+
}
}
@@ -2286,28 +2805,45 @@ function delete_example($example_id)
/* removing example folder */
$ex_path = $chapter_data->preference_id . '/' . 'CH' . $chapter_data->number . '/' . 'EX' . $example_data->number;
$dir_path = $root_path . $ex_path;
+
+
if (is_dir($dir_path))
{
- if (!rmdir($dir_path))
+ if (!drupal_rmdir($dir_path))
{
+
+
drupal_set_message(t('Error deleting folder !folder', array('!folder' => $dir_path)), 'error');
/* sending email to admins */
$email_to = variable_get('textbook_companion_emails', '');
$param['standard']['subject'] = "[ERROR] Error deleting folder";
- $param['standard']['body'] = "Error deleting folder " . $dir_path . " by " . $user->uid . " at " . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
+ $param['standard']['body'] = array(0 => "Error deleting folder " . $dir_path . " by " . $user->uid . " at " . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
if (!drupal_mail('textbook_companion', 'standard', $email_to, language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE))
drupal_set_message('Error sending email message.', 'error');
return FALSE;
+
+
}
+
} else {
+
+
drupal_set_message(t('Cannot delete example folder. !folder does not exists.', array('!folder' => $dir_path)), 'error');
return FALSE;
}
/* deleting example dependency and exmaple database entries */
- db_query("DELETE FROM {textbook_companion_example_dependency} WHERE example_id = %d", $example_id);
- db_query("DELETE FROM {textbook_companion_example} WHERE id = %d", $example_id);
+
+/*db_query("DELETE FROM {textbook_companion_example_dependency} WHERE example_id = %d", $example_id);*/
+ $query = db_delete('textbook_companion_example_dependency');
+ $query->condition('example_id', $example_id);
+ $num_deleted = $query->execute();
+
+ /*db_query("DELETE FROM {textbook_companion_example} WHERE id = %d", $example_id);*/
+ $query = db_delete('textbook_companion_example');
+ $query->condition('id', $example_id);
+ $num_deleted = $query->execute();
return $status;
}
@@ -2317,8 +2853,15 @@ function delete_chapter($chapter_id)
$status = TRUE;
$root_path = textbook_companion_path();
- $chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE id = %d", $chapter_id);
- $chapter_data = db_fetch_object($chapter_q);
+ /*$chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE id = %d", $chapter_id);
+ $chapter_data = db_fetch_object($chapter_q);*/
+
+ $query = db_select('textbook_companion_chapter');
+ $query->fields('textbook_companion_chapter');
+ $query->condition('id', $chapter_id);
+ $chapter_q = $query->execute();
+ $chapter_data =$chapter_q->fetchObject();
+
if (!$chapter_data)
{
drupal_set_message('Invalid chapter.', 'error');
@@ -2326,8 +2869,15 @@ function delete_chapter($chapter_id)
}
/* deleting examples */
- $example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d", $chapter_id);
- while ($example_data = db_fetch_object($example_q))
+
+ /*$example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d", $chapter_id);*/
+
+ $query = db_select('textbook_companion_example');
+ $query->fields('textbook_companion_example');
+ $query->condition('chapter_id', $chapter_id);
+ $example_q = $query->execute();
+
+ while ($example_data = $example_q->fetchObject())
{
if (!delete_example($example_data->id))
$status = FALSE;
@@ -2353,7 +2903,12 @@ function delete_chapter($chapter_id)
return FALSE;
} else {
/* deleting chapter details from database */
- db_query("DELETE FROM {textbook_companion_chapter} WHERE id = %d", $chapter_id);
+
+ /*db_query("DELETE FROM {textbook_companion_chapter} WHERE id = %d", $chapter_id);*/
+ $query = db_delete('textbook_companion_chapter');
+ $query->condition('id', $chapter_id);
+ $num_deleted = $query->execute();
+
return TRUE;
}
} else {
@@ -2369,8 +2924,14 @@ function delete_book($book_id)
$status = TRUE;
$root_path = textbook_companion_path();
- $preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d", $book_id);
- $preference_data = db_fetch_object($preference_q);
+ /*$preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d", $book_id);
+ $preference_data = db_fetch_object($preference_q);*/
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('id', $book_id);
+ $preference_q = $query->execute();
+ $preference_data =$preference_q->fetchObject();
+
if (!$preference_data)
{
drupal_set_message('Invalid book.', 'error');
@@ -2378,8 +2939,14 @@ function delete_book($book_id)
}
/* delete chapters */
- $chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE preference_id = %d", $preference_data->id);
- while ($chapter_data = db_fetch_object($chapter_q))
+
+ /*$chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE preference_id = %d", $preference_data->id);*/
+ $query = db_select('textbook_companion_chapter');
+ $query->fields('textbook_companion_chapter');
+ $query->condition('preference_id', $preference_data->id);
+ $chapter_q = $query->execute();
+
+ while ($chapter_data = $chapter_q->fetchObject())
{
if (!delete_chapter($chapter_data->id))
{
@@ -2393,8 +2960,15 @@ function delete_file($file_id)
{
$root_path = textbook_companion_path();
- $file_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE id = %d LIMIT 1", $file_id);
- $file_data = db_fetch_object($file_q);
+ /*$file_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE id = %d LIMIT 1", $file_id);*/
+
+ $query = db_select('textbook_companion_example_files');
+ $query->fields('textbook_companion_example_files');
+ $query->condition('id', $file_id);
+ $query->range(0, 1);
+ $file_q = $query->execute();
+
+ $file_data = $file_q->fetchObject();
if (!$file_data)
{
drupal_set_message('Invalid file specified.', 'error');
@@ -2423,7 +2997,12 @@ function delete_file($file_id)
return FALSE;
} else {
/* deleting example files database entries */
- db_query("DELETE FROM {textbook_companion_example_files} WHERE id = %d", $file_id);
+
+ /*db_query("DELETE FROM {textbook_companion_example_files} WHERE id = %d", $file_id);*/
+ $query = db_delete('textbook_companion_example_files');
+ $query->condition('id', $file_id);
+ $num_deleted = $query->execute();
+
return TRUE;
}
}
@@ -2438,7 +3017,7 @@ function book_proposal_nonaicte_form($form_state)
$form = array();
$form['imp_notice'] = array(
'#type' => 'item',
- '#value' => '<font color="red"><b>Please fill up this form carefully as the details entered here will be exactly written in the Textbook Companion and also follow the additional guidelines.</b></font>',
+ '#markup' => '<font color="red"><b>Please fill up this form carefully as the details entered here will be exactly written in the Textbook Companion and also follow the additional guidelines.</b></font>',
);
$form['guidelines'] = array(
'#type' => 'fieldset',
@@ -2450,7 +3029,7 @@ function book_proposal_nonaicte_form($form_state)
$form['guidelines']['book'] = array(
'#type' => 'item',
'#required' => TRUE,
- '#value' => '<ul style="list-style-type:disc;font-weight: normal">
+ '#markup' => '<ul style="list-style-type:disc;font-weight: normal">
<li>All the fields are compulsory</li>
<li>Proof (example: syllabus) to the usage/ popularity of the textbook must be provided in the references box below</li>
<li>Please make sure that the book proposed by you has <b>at least 80</b> examples which include numerical computations and which can be coded in Scilab</li>
@@ -2536,17 +3115,26 @@ function book_proposal_nonaicte_form($form_state)
);
$form['city'] = array(
'#type' => 'textfield',
- '#title' => t('City/Village'),
- '#size' => 50,
- '#maxlength' => 50,
+ '#title' => t('City/ Village'),
+ '#size' => 80,
+ '#maxlength' => 150,
'#required' => TRUE,
- );
- $form['states'] = array(
- '#type' => 'select',
+ '#attributes' =>array('placeholder' =>'Insert location of your institute/ university....'),
+ );
+$form['pincode'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Pincode'),
+ '#size' => 30,
+ '#maxlength' => 6,
+ '#required' => TRUE,
+ '#attributes' =>array('placeholder' =>'Insert pincode of your city/ village....'),
+);
+$form['all_state'] = array(
+ '#type' => 'select',
'#title' => t('State'),
- '#options' => array (
- '' => 'Please select....',
- 'Andhra Pradesh' => 'Andhra Pradesh',
+ '#options' => array(
+ '0' => 'Please select...',
+ 'Andhra Pradesh' => t('Andhra Pradesh'),
'Arunachal Pradesh' => 'Arunachal Pradesh',
'Assam' => 'Assam',
'Bihar' => 'Bihar',
@@ -2585,7 +3173,10 @@ function book_proposal_nonaicte_form($form_state)
'Others' => 'Others',
),
'#required' => TRUE,
- );
+ '#tree' => TRUE,
+ '#validated' => TRUE,
+ );
+
$form['faculty'] = array(
'#type' => 'hidden',
'#value' => 'None',
@@ -2623,6 +3214,7 @@ function book_proposal_nonaicte_form($form_state)
'#maxlength' => 50,
//'#required' => TRUE,
'#description' => t('Specify the Older version used'),
+ '#states' => array('visible' => array(':input[name="version"]' => array('value' => 'olderversion'),),),
);
$form['completion_date'] = array(
'#type' => 'textfield',
@@ -2656,6 +3248,7 @@ function book_proposal_nonaicte_form($form_state)
'#type' => 'textarea',
'#size' => 300,
'#maxlength' => 300,
+ '#states' => array('visible' => array(':input[name="reason[Other reason]"]' => array('checked' => TRUE),),),
//'#required' => FALSE,
);
$form['proposal_type'] = array(
@@ -2683,7 +3276,7 @@ function book_proposal_nonaicte_form($form_state)
'#size' => 30,
'#maxlength' => 100,
'#required' => TRUE,
- '#value' => $row1->book,
+ '#default_value' => $row1->book,
'#disabled' => ($row1->book?TRUE:FALSE),
);
$form['preference1']['author1'] = array(
@@ -2692,7 +3285,7 @@ function book_proposal_nonaicte_form($form_state)
'#size' => 30,
'#maxlength' => 100,
'#required' => TRUE,
- '#value' => $row1->author,
+ '#default_value' => $row1->author,
'#disabled' => ($row1->author?TRUE:FALSE),
);
$form['preference1']['isbn1'] = array(
@@ -2701,7 +3294,7 @@ function book_proposal_nonaicte_form($form_state)
'#size' => 30,
'#maxlength' => 25,
'#required' => TRUE,
- '#value' => $row1->isbn,
+ '#default_value' => $row1->isbn,
'#disabled' => ($row1->isbn?TRUE:FALSE),
);
$form['preference1']['publisher1'] = array(
@@ -2710,7 +3303,7 @@ function book_proposal_nonaicte_form($form_state)
'#size' => 30,
'#maxlength' => 50,
'#required' => TRUE,
- '#value' => $row1->publisher,
+ '#default_value' => $row1->publisher,
);
$form['preference1']['edition1'] = array(
'#type' => 'textfield',
@@ -2718,7 +3311,7 @@ function book_proposal_nonaicte_form($form_state)
'#size' => 4,
'#maxlength' => 2,
'#required' => TRUE,
- '#value' => $row1->edition,
+ '#default_value' => $row1->edition,
);
$form['preference1']['year1'] = array(
'#type' => 'textfield',
@@ -2726,7 +3319,7 @@ function book_proposal_nonaicte_form($form_state)
'#size' => 4,
'#maxlength' => 4,
'#required' => TRUE,
- '#value' => $row1->year,
+ '#default_value' => $row1->year,
);
$form['termconditions'] = array(
@@ -2741,25 +3334,17 @@ function book_proposal_nonaicte_form($form_state)
'#value' => t('Submit')
);
- /* #value fix for #default_value bug drupal6 */
+ /* #value fix for #default_value bug drupal6
foreach(array("preference1") as $preference) {
foreach($form[$preference] as $key => $value) {
if(!$form[$preference][$key]["#value"]) {
unset($form[$preference][$key]["#value"]);
}
}
- }
+ }*/
return $form;
}
-function book_proposal_nonaicte_form_validate($form, &$form_state)
-{
-if($form_state['values']['city']== ''){
- form_set_error('city', t('Invalid city/village'));
- }
- if($form_state['values']['state']== ''){
- form_set_error('state', t('Invalid state'));
- }
-}
+
function book_proposal_nonaicte_form_submit($form, &$form_state)
{
@@ -2802,23 +3387,75 @@ function book_proposal_nonaicte_form_submit($form, &$form_state)
if($form_state['values']['version'] == 'olderversion'){
$scilab_version = $form_state['values']['older'];
}
+
+ //var_dump($form_state['values']);
- $query = "INSERT INTO {textbook_companion_proposal}
- (uid, approver_uid, full_name, mobile, gender, how_project, course, branch, university, faculty, reviewer, reference, completion_date, creation_date, approval_date, proposal_status, scilab_version, operating_system, teacher_email, proposal_type, reason ) VALUES (".$user->uid.", 0, '".ucwords(strtolower($form_state['values']['full_name']))."', '".$form_state['values']['mobile']."', '".$form_state['values']['gender']."', '".$form_state['values']['how_project']."', '".$form_state['values']['course']."', '".$form_state['values']['branch']."', '".$form_state['values']['university']."', '".$form_state['values']['city']."','".$form_state['values']['state']."' ,'".ucwords(strtolower($form_state['values']['faculty']))."', '".ucwords(strtolower($form_state['values']['reviewer']))."', '".$form_state['values']['reference']."', '".$completion_date_timestamp."', '".time()."', 0, 0, '".$scilab_version."', '".$form_state['values']['operating_system']."', '".$form_state['values']['faculty_email']."','".$form_state['values']['proposal_type']."','".$my_reason."')";
+ /*$query = "INSERT INTO {textbook_companion_proposal}
+ (uid, approver_uid, full_name, mobile, gender, how_project, course, branch, university, faculty, reviewer, reference, completion_date, creation_date, approval_date, proposal_status, scilab_version, operating_system, teacher_email, proposal_type, reason ) VALUES (".$user->uid.", 0, '".ucwords(strtolower($form_state['values']['full_name']))."', '".$form_state['values']['mobile']."', '".$form_state['values']['gender']."', '".$form_state['values']['how_project']."', '".$form_state['values']['course']."', '".$form_state['values']['branch']."', '".$form_state['values']['university']."', '".ucwords(strtolower($form_state['values']['faculty']))."', '".ucwords(strtolower($form_state['values']['reviewer']))."', '".strtolower($form_state['values']['reference'])."', '".$completion_date_timestamp."', '".time()."', 0, 0, '".$scilab_version."', '".$form_state['values']['operating_system']."', '".$form_state['values']['faculty_email']."','".$form_state['values']['proposal_type']."','".$my_reason."')";*/
+
+
+
+/*$query = "INSERT INTO {textbook_companion_proposal}
+ (uid, approver_uid, full_name, mobile, gender, how_project, course, branch, university,city, pincode, state, faculty, reviewer, reference, completion_date, creation_date, message, approval_date, proposal_status, scilab_version, operating_system, teacher_email, proposal_type, reason ) VALUES (:uid, :approver_uid, :full_name, :mobile, :gender, :how_project, :course, :branch, :university, :city, :pincode, :state,
+ :faculty, :reviewer, :reference, :expected_completion_date, :creation_date,:message,
+ :approval_date, :proposal_status, :scilab_version, :operating_system, :teacher_email,: proposal_type, :reason)"; */
+
+
+ $query = "
+INSERT INTO {textbook_companion_proposal}
+ (uid, approver_uid, full_name, mobile, gender, how_project, course, branch, university, city, pincode, state, faculty, reviewer, reference, completion_date, creation_date, approval_date, proposal_status, message, scilab_version, operating_system, teacher_email, proposal_type, reason) VALUES (:uid, :approver_uid, :full_name, :mobile, :gender, :how_project, :course, :branch, :university, :city, :pincode, :state,
+:faculty, :reviewer, :reference, :completion_date, :creation_date, :approval_date, :proposal_status, :message, :scilab_version,
+ :operating_system, :teacher_email, :proposal_type, :reason)
+";
+
+ // $result = db_query($query);
+
+
+$args = array(
+ ":uid"=> $user->uid,
+ ":approver_uid"=> 0,
+ ":full_name"=> ucwords(strtolower($form_state['values']['full_name'])),
+ ":mobile"=> $form_state['values']['mobile'],
+ ":gender"=> $form_state['values']['gender'],
+ ":how_project"=> $form_state['values']['how_project'],
+ ":course"=> $form_state['values']['course'],
+ ":branch"=> $form_state['values']['branch'],
+ ":university"=> $form_state['values']['university'],
+ ":city"=> $form_state['values']['city'],
+ ":pincode"=> $form_state['values']['pincode'],
+ ":state"=> $form_state['values']['all_state'],
+ ":faculty"=> ucwords(strtolower($form_state['values']['faculty'])),
+ ":reviewer"=> ucwords(strtolower($form_state['values']['reviewer'])),
+ ":reference"=> strtolower($form_state['values']['reference']),
+ ":completion_date"=> $completion_date_timestamp,
+ ":creation_date"=> time(),
+ ":approval_date"=> time(),
+ ":proposal_status"=> 0,
+ ":message"=> 'None',
+ ":scilab_version"=>$scilab_version,
+ ":operating_system"=>$form_state['values']['operating_system'],
+ ":teacher_email"=>$form_state['values']['faculty_email'],
+ ":proposal_type"=>$form_state['values']['proposal_type'],
+ ":reason"=> $my_reason,
+ );
+var_dump($args);
+ $result = db_query($query, $args, array('return' => Database::RETURN_INSERT_ID));
+
- $result = db_query($query);
if (!$result)
{
drupal_set_message(t('Error receiving your proposal. Please try again.'), 'error');
return;
}
/* proposal id */
- $proposal_id = db_last_insert_id('textbook_companion_proposal', 'id');
+ //$proposal_id = db_last_insert_id('textbook_companion_proposal', 'id');
+ //$proposal_id = db_last_insert_id('textbook_companion_proposal', 'id');
+ $proposal_id = $result;
/* inserting first book preference */
if ($form_state['values']['book1'])
{
- $result = db_query("INSERT INTO {textbook_companion_preference}
+ /*$result = db_query("INSERT INTO {textbook_companion_preference}
(proposal_id, pref_number, book, author, isbn, publisher, edition, year, category, approval_status, nonaicte_book) VALUES
(%d, %d, '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d)",
$proposal_id,
@@ -2832,7 +3469,29 @@ function book_proposal_nonaicte_form_submit($form, &$form_state)
0,
0,
1
- );
+ );*/
+
+
+$query = "INSERT INTO {textbook_companion_preference}
+ (proposal_id, pref_number, book, author, isbn, publisher, edition, year, category, approval_status, nonaicte_book) VALUES
+ (:proposal_id, :pref_number, :book, :author, :isbn, :publisher, :edition, :year, :category, :approval_status, :nonaicte_book)";
+
+$args = array(
+ ":proposal_id"=> $proposal_id,
+ ":pref_number"=> 1,
+ ":book"=> ucwords(strtolower($form_state['values']['book1'])),
+ ":author"=> ucwords(strtolower($form_state['values']['author1'])),
+ ":isbn"=> $form_state['values']['isbn1'],
+ ":publisher"=> ucwords(strtolower($form_state['values']['publisher1'])),
+ ":edition"=> $form_state['values']['edition1'],
+ ":year"=> $form_state['values']['year1'],
+ ":category"=> 0,
+ ":approval_status"=> 0,
+ ":nonaicte_book"=> 1,
+ );
+
+ $result = db_query($query, $args);
+
if (!$result)
{
drupal_set_message(t('Error receiving your first book preference.'), 'error');
@@ -2862,14 +3521,13 @@ function del_book_pdf($book_id)
if (file_exists($dir_path . $pdf_filename))
unlink($dir_path . $pdf_filename);
}
+
function textbook_companion_init(){
- //drupal_add_css('http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css', array('type' => 'external'));
- //drupal_add_js('http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css', array('type' => 'external'));
- //drupal_add_js(drupal_get_path('module', 'textbook_companion') .'/js/jquery-ui.js');
- //drupal_add_js(drupal_get_path('module', 'textbook_companion') .'/js/jquery.js');
+
$path = drupal_get_path('module', 'textbook_companion');
drupal_add_js($path . '/css/textbook_companion.css');
drupal_add_js($path . '/js/textbook_companion.js');
drupal_add_js($path . '/js/jquery-1.7.1.js');
- drupal_add_js($path . '/js/tbc-download.js');
+
}
+