summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--README2
-rw-r--r--README.txt84
-rwxr-xr-xcheque_contact.inc1347
-rwxr-xr-xcheque_manage.inc166
-rwxr-xr-xcode.inc1301
-rwxr-xr-xcode_approval.inc1840
-rw-r--r--css/textbook_companion.css5
-rwxr-xr-xdependency.inc1491
-rwxr-xr-xdependency_approval.inc450
-rwxr-xr-xdownload.inc492
-rwxr-xr-xeditcode.inc2398
-rwxr-xr-xeditcodeadmin.inc1937
-rw-r--r--email.inc1064
-rwxr-xr-xfull_download.inc413
-rwxr-xr-xgeneral.inc506
-rwxr-xr-xlatex.inc394
-rwxr-xr-xmanage_proposal.inc3232
-rwxr-xr-xnotes.inc271
-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.exebin6768128 -> 0 bytes
-rwxr-xr-xpdf/1/1 FWR/libfftw3-3.dllbin2365756 -> 0 bytes
-rwxr-xr-xpdf/1/1 FWR/ngspice.exebin4744192 -> 0 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.exebin26624 -> 0 bytes
-rwxr-xr-xpdf/1/1 FWR/vcomp100.dllbin51024 -> 0 bytes
-rwxr-xr-xpdf/1/1.pdfbin103290 -> 0 bytes
-rwxr-xr-xpdf/generate_pdf.inc351
-rwxr-xr-xpdf/list_all_certificates.inc133
-rw-r--r--pdf/list_all_form_pdf.inc65
-rw-r--r--proposal.inc1970
-rwxr-xr-xrun.inc904
-rwxr-xr-xsearch.inc758
-rwxr-xr-xsettings.inc233
-rwxr-xr-xtextbook_companion.install979
-rwxr-xr-xtextbook_companion.module4837
47 files changed, 14055 insertions, 14556 deletions
diff --git a/.gitignore b/.gitignore
index 6b05a7a..e78b9aa 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,6 +6,7 @@ cache/
files/
sites/*/files
sites/*/private
+file_bck
# Ignore default text files
robots.txt
diff --git a/README b/README
index d7c70f9..0e21ae9 100644
--- a/README
+++ b/README
@@ -1,2 +1,2 @@
-Textbook Companion project for IIT Bombay written in Drupal 7
+Textbook Companion project for FOSSEE, IIT Bombay written in Drupal 7
diff --git a/README.txt b/README.txt
deleted file mode 100644
index 8f9f203..0000000
--- a/README.txt
+++ /dev/null
@@ -1,84 +0,0 @@
-FILENAME : includes/form.api
-LINE No. 1870
-
-----------------------------------------------------------------------------------------------------
-/**
- * Format a checkbox.
- *
- * @param $element
- * An associative array containing the properties of the element.
- * Properties used: title, value, return_value, description, required
- * @return
- * A themed HTML string representing the checkbox.
- *
- * @ingroup themeable
- */
-function theme_checkbox($element) {
- _form_set_class($element, array('form-checkbox'));
- $checkbox = '<input ';
- $checkbox .= 'type="checkbox" ';
- $checkbox .= 'name="'. $element['#name'] .'" ';
- $checkbox .= 'id="'. $element['#id'] .'" ' ;
- $checkbox .= 'class="'. $element['#options_class'] . '" '; /************************* CUSTOM CODE BY PRASHANT SHAH *************************/
- $checkbox .= 'value="'. $element['#return_value'] .'" ';
- $checkbox .= $element['#value'] ? ' checked="checked" ' : ' ';
- $checkbox .= drupal_attributes($element['#attributes']) .' />';
-
- if (!is_null($element['#title'])) {
- $checkbox = '<label class="option ' . $element['#options_class'] . '" for="'. $element['#id'] .'">'. $checkbox .' '. $element['#title'] .'</label>'; /************************* CUSTOM CODE BY PRASHANT SHAH *************************/
- }
-
- unset($element['#title']);
- return theme('form_element', $element, $checkbox);
-}
-
-/**
- * Format a set of checkboxes.
- *
- * @param $element
- * An associative array containing the properties of the element.
- * @return
- * A themed HTML string representing the checkbox set.
- *
- * @ingroup themeable
- */
-function theme_checkboxes($element) {
- $class = 'form-checkboxes';
- if (isset($element['#attributes']['class'])) {
- $class .= ' '. $element['#attributes']['class'];
- }
- $element['#children'] = '<div class="'. $class .'">'. (!empty($element['#children']) ? $element['#children'] : '') .'</div>';
- if ($element['#title'] || $element['#description']) {
- unset($element['#id']);
- return theme('form_element', $element, $element['#children']);
- }
- else {
- return $element['#children'];
- }
-}
-
-function expand_checkboxes($element) {
- $value = is_array($element['#value']) ? $element['#value'] : array();
- $element['#tree'] = TRUE;
- if (count($element['#options']) > 0) {
- if (!isset($element['#default_value']) || $element['#default_value'] == 0) {
- $element['#default_value'] = array();
- }
- foreach ($element['#options'] as $key => $choice) {
- if (!isset($element[$key])) {
- $element[$key] = array(
- '#type' => 'checkbox',
- '#processed' => TRUE,
- '#title' => $choice,
- '#return_value' => $key,
- '#default_value' => isset($value[$key]),
- '#attributes' => $element['#attributes'],
- '#ahah' => isset($element['#ahah']) ? $element['#ahah'] : NULL,
- '#options_class' => $element['#options_class'][$key], /************************* CUSTOM CODE BY PRASHANT SHAH *************************/
- );
- }
- }
- }
- return $element;
-}
-
diff --git a/cheque_contact.inc b/cheque_contact.inc
index c623ef4..093d040 100755
--- a/cheque_contact.inc
+++ b/cheque_contact.inc
@@ -1,336 +1,337 @@
<?php
-
function paper_submission_form($form_state, $proposal_id)
{
- global $user;
- $proposal_id = arg(2);
-
- /* get current proposal */
-
- /*$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 = $preference4_q->fetchObject())
- {
- $form1 = $data->internship_form;
- $form2 = $data->copyright_form;
- $form3 = $data->undertaking_form;
- $form4 = $data->reciept_form;
- }
- else
- {
- $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',
- '#default_value' => $proposal_id,
- );
- $form['internshipform'] = array(
- '#type' => 'checkbox',
- '#title' => t('Recieved Internship Application'),
- '#description' => t('Check if the Internship Application has been recieved.'),
- '#default_value' => $form1,
- );
- $form['copyrighttransferform'] = array(
- '#type' => 'checkbox',
- '#title' => t('Recieved Copyright Transfer Form'),
- '#description' => t('Check if the Copyright Transfer Form has been recieved.'),
- '#default_value' => $form2,
- );
- $form['undertakingform'] = array(
- '#type' => 'checkbox',
- '#title' => t('Recieved Undertaking Form'),
- '#description' => t('Check if the Undertaking Form has been recieved.'),
- '#default_value' => $form3,
- );
- $form['recieptform'] = array(
- '#type' => 'checkbox',
- '#title' => t('Recieved Reciept Form'),
- '#description' => t('Check if the Reciept Form has been recieved.'),
- '#default_value' => $form4,
- );
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Send Email')
- );
- $form['cancel'] = array(
- '#type' => 'markup',
- '#value' => l(t('Cancel'), 'manage_proposal/all'),
+ global $user;
+ $proposal_id = arg(2);
+ /* get current proposal */
+ /*$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 = $preference4_q->fetchObject())
+ {
+ $form1 = $data->internship_form;
+ $form2 = $data->copyright_form;
+ $form3 = $data->undertaking_form;
+ $form4 = $data->reciept_form;
+ } //$data = $preference4_q->fetchObject()
+ else
+ {
+ $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',
+ '#default_value' => $proposal_id
+ );
+ $form['internshipform'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Recieved Internship Application'),
+ '#description' => t('Check if the Internship Application has been recieved.'),
+ '#default_value' => $form1
+ );
+ $form['copyrighttransferform'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Recieved Copyright Transfer Form'),
+ '#description' => t('Check if the Copyright Transfer Form has been recieved.'),
+ '#default_value' => $form2
+ );
+ $form['undertakingform'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Recieved Undertaking Form'),
+ '#description' => t('Check if the Undertaking Form has been recieved.'),
+ '#default_value' => $form3
+ );
+ $form['recieptform'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Recieved Reciept Form'),
+ '#description' => t('Check if the Reciept Form has been recieved.'),
+ '#default_value' => $form4
+ );
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Send Email')
+ );
+ $form['cancel'] = array(
+ '#type' => 'markup',
+ '#value' => l(t('Cancel'), 'manage_proposal/all')
+ );
return $form;
}
-
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 ],
+ '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
- ************************************************/
- if ($form_state['values']['internshipform'] == 1)
- {
- /* sending email */
- $book_user = user_load($proposal_data->uid);
- $param['proposal_completed']['proposal_id'] = $proposal_id;
- $param['proposal_completed']['user_id'] = $proposal_data->uid;
- $email_to = $book_user->mail;
- if (!drupal_mail('textbook_companion', 'internship_form', $email_to , language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE))
- drupal_set_message('Error sending email message.', 'error');
- drupal_set_message('Internship Form for Book proposal has been recieved. User has been notified .', 'status');
- }
- else
- {
- if (!drupal_mail('textbook_companion', 'internship_form_not', $email_to , language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE))
+ /************************************************
+ Check For the Internship Form is checked or not
+ ************************************************/
+ if ($form_state['values']['internshipform'] == 1)
+ {
+ /* sending email */
+ $book_user = user_load($proposal_data->uid);
+ $param['proposal_completed']['proposal_id'] = $proposal_id;
+ $param['proposal_completed']['user_id'] = $proposal_data->uid;
+ $email_to = $book_user->mail;
+ if (!drupal_mail('textbook_companion', 'internship_form', $email_to, language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE))
+ drupal_set_message('Error sending email message.', 'error');
+ drupal_set_message('Internship Form for Book proposal has been recieved. User has been notified .', 'status');
+ } //$form_state['values']['internshipform'] == 1
+ else
+ {
+ if (!drupal_mail('textbook_companion', 'internship_form_not', $email_to, language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE))
drupal_set_message('Error sending email message.', 'error');
drupal_set_message('Internship Form for Book proposal has not been recieved. User has been notified .', 'status');
- }
-
- /************************************************
- Check For the Copyright Form is checked or not
- ************************************************/
+ }
+ /************************************************
+ Check For the Copyright Form is checked or not
+ ************************************************/
+ if ($form_state['values']['copyrighttransferform'] == 1)
+ {
+ /* sending email */
+ $book_user = user_load($proposal_data->uid);
+ $param['proposal_completed']['proposal_id'] = $proposal_id;
+ $param['proposal_completed']['user_id'] = $proposal_data->uid;
+ $email_to = $book_user->mail;
+ if (!drupal_mail('textbook_companion', 'copyrighttransfer_form', $email_to, language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE))
+ drupal_set_message('Error sending email message.', 'error');
+ drupal_set_message('Copyright Form for Book proposal has been recieved. User has been notified .', 'status');
+ } //$form_state['values']['copyrighttransferform'] == 1
+ else
+ {
+ if (!drupal_mail('textbook_companion', 'copyrighttransfer_form_not', $email_to, language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE))
+ drupal_set_message('Error sending email message.', 'error');
+ drupal_set_message('Copyright Transfer Form for Book proposal has not been recieved. User has been notified .', 'status');
+ }
+ /************************************************
+ Check For the Undertaking Form is checked or not
+ ************************************************/
+ if ($form_state['values']['undertakingform'] == 1)
+ {
+ /* sending email */
+ $book_user = user_load($proposal_data->uid);
+ $param['proposal_completed']['proposal_id'] = $proposal_id;
+ $param['proposal_completed']['user_id'] = $proposal_data->uid;
+ $email_to = $book_user->mail;
+ if (!drupal_mail('textbook_companion', 'undertakingform_form', $email_to, language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE))
+ drupal_set_message('Error sending email message.', 'error');
+ drupal_set_message('Undertaking Form for Book proposal has been recieved. User has been notified .', 'status');
+ } //$form_state['values']['undertakingform'] == 1
+ else
+ {
+ if (!drupal_mail('textbook_companion', 'undertakingform_form_not', $email_to, language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE))
+ drupal_set_message('Error sending email message.', 'error');
+ drupal_set_message('Undertaking Form for Book proposal has not been recieved. User has been notified .', 'status');
+ }
+ drupal_set_message(t('Proposal Updated'), 'status');
+}
+/*function proposal_edit_form_validate($form, &$form_state)
+{
+/* mobile */
+/*if (!preg_match('/^[0-9\ \+]{0,15}$/', $form_state['values']['mobile']))
+form_set_error('mobile', t('Invalid mobile number'));
- if ($form_state['values']['copyrighttransferform'] == 1)
- {
- /* sending email */
- $book_user = user_load($proposal_data->uid);
- $param['proposal_completed']['proposal_id'] = $proposal_id;
- $param['proposal_completed']['user_id'] = $proposal_data->uid;
- $email_to = $book_user->mail;
- if (!drupal_mail('textbook_companion', 'copyrighttransfer_form', $email_to , language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE))
- drupal_set_message('Error sending email message.', 'error');
- drupal_set_message('Copyright Form for Book proposal has been recieved. User has been notified .', 'status');
- }
- else
- {
- if (!drupal_mail('textbook_companion', 'copyrighttransfer_form_not', $email_to , language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE))
- drupal_set_message('Error sending email message.', 'error');
- drupal_set_message('Copyright Transfer Form for Book proposal has not been recieved. User has been notified .', 'status');
- }
-
- /************************************************
- Check For the Undertaking Form is checked or not
- ************************************************/
+/* date of completion */
+/*if (!preg_match('/^[0-9]{1,2}-[0-9]{1,2}-[0-9]{4}$/', $form_state['values']['completion_date']))
+form_set_error('completion_date', t('Invalid expected date of completion'));
- if ($form_state['values']['undertakingform'] == 1)
- {
- /* sending email */
- $book_user = user_load($proposal_data->uid);
- $param['proposal_completed']['proposal_id'] = $proposal_id;
- $param['proposal_completed']['user_id'] = $proposal_data->uid;
- $email_to = $book_user->mail;
- if (!drupal_mail('textbook_companion', 'undertakingform_form', $email_to , language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE))
- drupal_set_message('Error sending email message.', 'error');
- drupal_set_message('Undertaking Form for Book proposal has been recieved. User has been notified .', 'status');
- }
- else
- {
- if (!drupal_mail('textbook_companion', 'undertakingform_form_not', $email_to , language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE))
- drupal_set_message('Error sending email message.', 'error');
- drupal_set_message('Undertaking Form for Book proposal has not been recieved. User has been notified .', 'status');
- }
+list($d, $m, $y) = explode('-', $form_state['values']['completion_date']);
+$d = (int)$d; $m = (int)$m; $y = (int)$y;
-drupal_set_message(t('Proposal Updated'), 'status');
-}
+if (!checkdate($m, $d, $y))
+form_set_error('completion_date', t('Invalid expected date of completion'));
+if (mktime(0, 0, 0, $m, $d, $y) <= time())
+form_set_error('completion_date', t('Expected date of completion should be in future'));
-/*function proposal_edit_form_validate($form, &$form_state)
-{
- /* mobile */
- /*if (!preg_match('/^[0-9\ \+]{0,15}$/', $form_state['values']['mobile']))
- form_set_error('mobile', t('Invalid mobile number'));
+/* edition */
+/*if (!preg_match('/^[1-9][0-9]{0,1}$/', $form_state['values']['edition1']))
+form_set_error('edition1', t('Invalid edition for Book Preference 1'));
- /* date of completion */
- /*if (!preg_match('/^[0-9]{1,2}-[0-9]{1,2}-[0-9]{4}$/', $form_state['values']['completion_date']))
- form_set_error('completion_date', t('Invalid expected date of completion'));
+if (!preg_match('/^[1-9][0-9]{0,1}$/', $form_state['values']['edition2']))
+form_set_error('edition2', t('Invalid edition for Book Preference 2'));
+if (!preg_match('/^[1-9][0-9]{0,1}$/', $form_state['values']['edition3']))
+form_set_error('edition3', t('Invalid edition for Book Preference 3'));
- list($d, $m, $y) = explode('-', $form_state['values']['completion_date']);
- $d = (int)$d; $m = (int)$m; $y = (int)$y;
-
- if (!checkdate($m, $d, $y))
- form_set_error('completion_date', t('Invalid expected date of completion'));
-
- if (mktime(0, 0, 0, $m, $d, $y) <= time())
- form_set_error('completion_date', t('Expected date of completion should be in future'));
+/* year of publication */
+/*if (!preg_match('/^[1-3][0-9][0-9][0-9]$/', $form_state['values']['year1']))
+form_set_error('year1', t('Invalid year of pulication for Book Preference 1'));
- /* edition */
- /*if (!preg_match('/^[1-9][0-9]{0,1}$/', $form_state['values']['edition1']))
- form_set_error('edition1', t('Invalid edition for Book Preference 1'));
+if (!preg_match('/^[1-3][0-9][0-9][0-9]$/', $form_state['values']['year2']))
+form_set_error('year2', t('Invalid year of pulication for Book Preference 2'));
- if (!preg_match('/^[1-9][0-9]{0,1}$/', $form_state['values']['edition2']))
- form_set_error('edition2', t('Invalid edition for Book Preference 2'));
- if (!preg_match('/^[1-9][0-9]{0,1}$/', $form_state['values']['edition3']))
- form_set_error('edition3', t('Invalid edition for Book Preference 3'));
+if (!preg_match('/^[1-3][0-9][0-9][0-9]$/', $form_state['values']['year3']))
+form_set_error('year3', t('Invalid year of pulication for Book Preference 3'));
- /* year of publication */
- /*if (!preg_match('/^[1-3][0-9][0-9][0-9]$/', $form_state['values']['year1']))
- form_set_error('year1', t('Invalid year of pulication for Book Preference 1'));
+/* year of publication */
+/*$cur_year = date('Y');
+if ((int)$form_state['values']['year1'] > $cur_year)
+form_set_error('year1', t('Year of pulication should be not in the future for Book Preference 1'));
- if (!preg_match('/^[1-3][0-9][0-9][0-9]$/', $form_state['values']['year2']))
- form_set_error('year2', t('Invalid year of pulication for Book Preference 2'));
+if ((int)$form_state['values']['year2'] > $cur_year)
+form_set_error('year2', t('Year of pulication should be not in the future for Book Preference 2'));
- if (!preg_match('/^[1-3][0-9][0-9][0-9]$/', $form_state['values']['year3']))
- form_set_error('year3', t('Invalid year of pulication for Book Preference 3'));
+if ((int)$form_state['values']['year3'] > $cur_year)
+form_set_error('year3', t('Year of pulication should be not in the future for Book Preference 3'));
- /* year of publication */
- /*$cur_year = date('Y');
- if ((int)$form_state['values']['year1'] > $cur_year)
- form_set_error('year1', t('Year of pulication should be not in the future for Book Preference 1'));
-
- if ((int)$form_state['values']['year2'] > $cur_year)
- form_set_error('year2', t('Year of pulication should be not in the future for Book Preference 2'));
-
- if ((int)$form_state['values']['year3'] > $cur_year)
- form_set_error('year3', t('Year of pulication should be not in the future for Book Preference 3'));
+/* isbn */
+/*if (!preg_match('/^[0-9\-xX]+$/', $form_state['values']['isbn1']))
+form_set_error('isbn1', t('Invalid ISBN for Book Preference 1'));
- /* isbn */
- /*if (!preg_match('/^[0-9\-xX]+$/', $form_state['values']['isbn1']))
- form_set_error('isbn1', t('Invalid ISBN for Book Preference 1'));
-
- if (!preg_match('/^[0-9\-xX]+$/', $form_state['values']['isbn2']))
- form_set_error('isbn2', t('Invalid ISBN for Book Preference 2'));
-
- if (!preg_match('/^[0-9\-xX]+$/', $form_state['values']['isbn3']))
- form_set_error('isbn3', t('Invalid ISBN for Book Preference 3'));
+if (!preg_match('/^[0-9\-xX]+$/', $form_state['values']['isbn2']))
+form_set_error('isbn2', t('Invalid ISBN for Book Preference 2'));
+
+if (!preg_match('/^[0-9\-xX]+$/', $form_state['values']['isbn3']))
+form_set_error('isbn3', t('Invalid ISBN for Book Preference 3'));
return;
}*/
-
-
function cheque_contct_form()
{
global $user;
-
/*$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->fields('textbook_companion_proposal', array(
+ 'id'
+ ));
$query->condition('uid', $user->uid);
$result = $query->execute();
$data = $result->fetchObject();
-
- $form1 = $data->id;
-
- if($user->uid)
- {
+ $form1 = $data->id;
+ if ($user->uid)
+ {
$form['#redirect'] = FALSE;
-
$form['search'] = array(
'#type' => 'textfield',
'#title' => t('Search'),
- '#size' => 48,
+ '#size' => 48
);
-
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Search')
);
-
$form['cancel'] = array(
'#type' => 'markup',
- '#value' => l(t('Cancel'), ''),
+ '#value' => l(t('Cancel'), '')
);
-
$form['submit2'] = array(
'#type' => 'markup',
'#value' => l(t('Generate Report'), 'cheque_contct/report'),
- '#attributes' => array('id' => 'perm_report'),
+ '#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)");*/
$query = db_select('textbook_companion_proposal', 'p');
- $query->join('textbook_companion_cheque','c','p.id = c.proposal_id');
+ $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('c.address_con', 'Submitted');
$search_q = $query->execute();
-
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);
- }
+ {
+ $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
+ );
+ } //$search_data = $search_q->fetchObject()
if ($search_rows)
{
- $search_header = array('Name Of The Student', 'Application Form Status', 'Cheque No', 'Cheque Clearance Date');
- $output .= theme('table',array('header'=>$search_header, 'rows'=>$search_rows));
+ $search_header = array(
+ 'Name Of The Student',
+ 'Application Form Status',
+ 'Cheque No',
+ 'Cheque Clearance Date'
+ );
+ $output .= theme('table', array(
+ 'header' => $search_header,
+ 'rows' => $search_rows
+ ));
$form['search_results'] = array(
'#type' => 'item',
- '#title' => $_POST['search'] ,
- '#markup' => $output,
+ '#title' => $_POST['search'],
+ '#markup' => $output
);
- }
+ } //$search_rows
else
{
$form['search_results'] = array(
'#type' => 'item',
'#title' => t('Search results for "') . $_POST['search'] . '"',
- '#markup' => 'No results found',
+ '#markup' => 'No results found'
);
}
if ($_POST)
- {
+ {
$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']);*/
$query = db_select('textbook_companion_proposal', 'p');
- $query->join('textbook_companion_cheque','c','p.id = c.proposal_id');
+ $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');
+ $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);
- }
+ $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
+ );
+ } //$search_data = $result->fetchObject()
if ($search_rows)
- {
- $search_header = array('Name Of The Student', 'Application Form Status', 'Cheque No', 'Cheque Clearance Date');
- $output .= theme('table',array('header'=>$search_header,'rows'=>$search_rows));
- $form['search_results'] = array(
- '#type' => 'item',
- '#title' => t('Search results for "') . $_POST['search'] . '"',
- '#markup' => $output,
- );
- }
+ {
+ $search_header = array(
+ 'Name Of The Student',
+ 'Application Form Status',
+ 'Cheque No',
+ 'Cheque Clearance Date'
+ );
+ $output .= theme('table', array(
+ 'header' => $search_header,
+ 'rows' => $search_rows
+ ));
+ $form['search_results'] = array(
+ '#type' => 'item',
+ '#title' => t('Search results for "') . $_POST['search'] . '"',
+ '#markup' => $output
+ );
+ } //$search_rows
else
{
- $form['search_results'] = array(
- '#type' => 'item',
- '#title' => t('Search results for "') . $_POST['search'] . '"',
- '#markup' => 'No results found',
- );
+ $form['search_results'] = array(
+ '#type' => 'item',
+ '#title' => t('Search results for "') . $_POST['search'] . '"',
+ '#markup' => 'No results found'
+ );
}
- }
- return $form;
- }
+ } //$_POST
+ return $form;
+ } //$user->uid
else
{
/*$preference5_q = db_query("SELECT * FROM {textbook_companion_paper} WHERE proposal_id=".$form1);
@@ -339,91 +340,90 @@ function cheque_contct_form()
$query->fields('textbook_companion_paper');
$query->condition('proposal_id', $form1);
$result = $query->execute();
- $data1=$result->fetchObject();
-
+ $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);*/
-
$query = db_select('textbook_companion_proposal');
$query->fields('textbook_companion_proposal');
$query->condition('id', $form1);
$result = $query->execute();
- $data_chq=$result->fetchObject();
-
+ $data_chq = $result->fetchObject();
$form9 = $data_chq->full_name;
$form8 = $data->how_project;
$form10 = $data_chq->mobile;
$form11 = $data_chq->course;
$form12 = $data_chq->branch;
$form13 = $data_chq->university;
- if($form2&&$form3&&$form4&&$form5)
+ if ($form2 && $form3 && $form4 && $form5)
{
$form['full_name'] = array(
'#type' => 'textfield',
'#title' => t('Full Name'),
'#size' => 30,
'#maxlength' => 50,
- '#default_value' => $form9,
+ '#default_value' => $form9
);
$form['mobile'] = array(
'#type' => 'textfield',
'#title' => t('Mobile No.'),
'#size' => 30,
'#maxlength' => 15,
- '#default_value' => $form10,
+ '#default_value' => $form10
);
$form['how_project'] = array(
'#type' => 'select',
'#title' => t('How did you come to know about this project'),
- '#options' => array('Scilab Website' => 'Scilab Website',
+ '#options' => array(
+ 'Scilab Website' => 'Scilab Website',
'Friend' => 'Friend',
'Professor/Teacher' => 'Professor/Teacher',
'Mailing List' => 'Mailing List',
'Poster in my/other college' => 'Poster in my/other college',
- 'Others' => 'Others'),
- '#default_value' => $form8,
+ 'Others' => 'Others'
+ ),
+ '#default_value' => $form8
);
$form['course'] = array(
'#type' => 'textfield',
'#title' => t('Course'),
'#size' => 30,
'#maxlength' => 50,
- '#default_value' => $form11,
+ '#default_value' => $form11
);
$form['branch'] = array(
'#type' => 'select',
'#title' => t('Department/Branch'),
- '#options' => array('Electrical Engineering' => 'Electrical Engineering',
- 'Electronics Engineering' => 'Electronics Engineering',
- 'Computer Engineering' => 'Computer Engineering',
- 'Chemical Engineering' => 'Chemical Engineering',
- 'Instrumentation Engineering' => 'Instrumentation Engineering',
- 'Mechanical Engineering' => 'Mechanical Engineering',
- 'Civil Engineering' => 'Civil Engineering',
- 'Physics' => 'Physics',
- 'Mathematics' => 'Mathematics',
- 'Others' => 'Others'),
- '#default_value' => $form12,
- );
-
+ '#options' => array(
+ 'Electrical Engineering' => 'Electrical Engineering',
+ 'Electronics Engineering' => 'Electronics Engineering',
+ 'Computer Engineering' => 'Computer Engineering',
+ 'Chemical Engineering' => 'Chemical Engineering',
+ 'Instrumentation Engineering' => 'Instrumentation Engineering',
+ 'Mechanical Engineering' => 'Mechanical Engineering',
+ 'Civil Engineering' => 'Civil Engineering',
+ 'Physics' => 'Physics',
+ 'Mathematics' => 'Mathematics',
+ 'Others' => 'Others'
+ ),
+ '#default_value' => $form12
+ );
$form['university'] = array(
'#type' => 'textfield',
'#title' => t('University/Institute'),
'#size' => 30,
'#maxlength' => 100,
- '#default_value' => $form13,
+ '#default_value' => $form13
);
$form['addressforcheque'] = array(
'#type' => 'textfield',
'#title' => t('Address For Mailing Cheque'),
//'#required' => TRUE,
'#size' => 30,
- '#maxlength' => 100,
+ '#maxlength' => 100
);
$form['submit'] = array(
'#type' => 'submit',
@@ -433,168 +433,158 @@ function cheque_contct_form()
'#type' => 'markup',
'#value' => t('Cancel')
);
- }
+ } //$form2 && $form3 && $form4 && $form5
if (!$form2)
- {
+ {
drupal_set_message(t('Internship Form has not been recieved.'), 'error');
- }
- if(!$form3)
- {
+ } //!$form2
+ if (!$form3)
+ {
drupal_set_message(t('Copyright Form has not been recieved.'), 'error');
- }
- if(!$form4)
- {
+ } //!$form3
+ if (!$form4)
+ {
drupal_set_message(t('Undertaking Form has not been recieved.'), 'error');
- }
- return $form;
+ } //!$form4
+ return $form;
}
}
-
-
function cheque_status_form($form_state, $proposal_id)
{
global $user;
-
/* get current proposal */
$proposal_id = arg(2);
-
/*$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();
-
+ $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();
-
-
+ $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');
return;
- }
- $form['proposal_id'] =array(
+ } //!$proposal_data = $proposal_q->fetchObject()
+ $form['proposal_id'] = array(
'#type' => 'hidden',
- '#default_value' => $proposal_id,
+ '#default_value' => $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)
+ $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);*/
-
$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));
- }
+ ":proposal_id" => $proposal_id
+ );
+ $result = db_query($query, $args, array(
+ 'return' => Database::RETURN_INSERT_ID
+ ));
+ } //!$empty
$form['candidate_detail'] = array(
'#type' => 'fieldset',
'#title' => t('Candidate Details'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
- '#attributes' => array('id' => 'candidate_detail'),
+ '#attributes' => array(
+ 'id' => 'candidate_detail'
+ )
);
$form['candidate_detail']['full_name'] = array(
'#type' => 'item',
'#markup' => $proposal_data->full_name,
- '#title' => t('Contributor Name'),
+ '#title' => t('Contributor Name')
);
$form['candidate_detail']['email'] = array(
'#type' => 'item',
'#markup' => user_load($proposal_data->uid)->mail,
- '#title' => t('Email'),
+ '#title' => t('Email')
);
$form['candidate_detail']['mobile'] = array(
'#type' => 'item',
'#markup' => $proposal_data->mobile,
- '#title' => t('Mobile'),
+ '#title' => t('Mobile')
);
$form['candidate_detail']['alt_mobile'] = array(
'#type' => 'item',
'#markup' => $proposal_data1->alt_mobno,
- '#title' => t('Alternate Mobile No.'),
+ '#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);*/
-
$query = db_select('textbook_companion_paper');
$query->fields('textbook_companion_paper');
$query->condition('proposal_id', $proposal_id);
$result = $query->execute();
- $form_data=$result->fetchObject();
-
+ $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);*/
$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>';
else
$preference_html .= '<li>' . $preference_data->book . ' (Written by ' . $preference_data->author . ')</li>';
- }
+ } //$preference_data = $preference_q->fetchObject()
$preference_html .= '</ul>';
$form['book_preference_f'] = array(
'#type' => 'fieldset',
'#title' => t('Book Preferences/Application Status'),
'#collapsible' => FALSE,
'#collapsed' => FALSE,
- '#attributes' => array('id' => 'book_preference_f'),
+ '#attributes' => array(
+ 'id' => 'book_preference_f'
+ )
);
$form['book_preference_f']['book_preference'] = array(
'#type' => 'item',
'#markup' => $preference_html,
- '#title' => t('Book Preferences'),
+ '#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);*/
$query = db_select('textbook_companion_cheque');
$query->fields('textbook_companion_cheque');
$query->condition('proposal_id', $proposal_id);
$result = $query->execute();
- $chq_data=$result->fetchObject();
-
+ $chq_data = $result->fetchObject();
$form_html .= '<ul>';
- if($form_data->internship_form)
+ if ($form_data->internship_form)
{
$form_html .= '<li><strong>Internship Application </strong> Form Submitted</li>';
- }
+ } //$form_data->internship_form
else
{
$form_html .= '<li><strong>Internship Application </strong> Form Not Submitted </li>';
}
- if($form_data->copyright_form)
+ if ($form_data->copyright_form)
{
$form_html .= '<li><strong>Copyright Application </strong> Form Submitted</li>';
- }
+ } //$form_data->copyright_form
else
{
$form_html .= '<li><strong>Copyright Application</strong> Form Not Submitted </li>';
}
- if($form_data->undertaking_form)
+ if ($form_data->undertaking_form)
{
$form_html .= '<li><strong>Undertaking Application </strong> Form Submitted</li>';
- }
+ } //$form_data->undertaking_form
else
{
$form_html .= '<li><strong>Undertaking Application</strong> Form Not Submitted </li>';
@@ -603,56 +593,67 @@ function cheque_status_form($form_state, $proposal_id)
$form['book_preference_f']['formsubmit'] = array(
'#type' => 'item',
'#markup' => $form_html,
- '#title' => t('Application Form Status'),
+ '#title' => t('Application Form Status')
);
$form['stu_cheque_details'] = array(
'#type' => 'fieldset',
'#title' => t('Student Cheque Details'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
- '#attributes' => array('id' => 'stu_cheque_details'),
+ '#attributes' => array(
+ 'id' => 'stu_cheque_details'
+ )
);
$form['tea_cheque_details'] = array(
'#type' => 'fieldset',
'#title' => t('Teacher Cheque Details'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
- '#attributes' => array('id' => 'tea_cheque_details'),
+ '#attributes' => array(
+ 'id' => 'tea_cheque_details'
+ )
);
$form['perm_cheque_address'] = array(
'#type' => 'fieldset',
'#title' => t('Permanent Address'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
- '#attributes' => array('id' => 'perm_cheque_address'),
+ '#attributes' => array(
+ 'id' => 'perm_cheque_address'
+ )
);
$form['temp_cheque_address'] = array(
'#type' => 'fieldset',
'#title' => t('Temporary Address'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
- '#attributes' => array('id' => 'temp_cheque_address'),
+ '#attributes' => array(
+ 'id' => 'temp_cheque_address'
+ )
);
$form['cheque_delivery'] = array(
'#type' => 'fieldset',
'#title' => t('Cheque Delivery'),
'#collapsible' => FALSE,
'#collapsed' => FALSE,
- '#attributes' => array('id' => 'cheque_delivery'),
+ '#attributes' => array(
+ 'id' => 'cheque_delivery'
+ )
);
$form['commentf'] = array(
'#type' => 'fieldset',
'#title' => t('Remark'),
'#collapsible' => FALSE,
'#collapsed' => FALSE,
- '#attributes' => array('id' => 'commentf'),
+ '#attributes' => array(
+ 'id' => 'commentf'
+ )
);
/*$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 = '';
$chq3 = '';
@@ -670,7 +671,7 @@ function cheque_status_form($form_state, $proposal_id)
$chq15 = '';
$chq16 = '';
$chq17 = '';
- if($chqe = $chq4_q->fetchObject())
+ if ($chqe = $chq4_q->fetchObject())
{
$chq1 = $chqe->cheque_no;
$chq2 = $chqe->address;
@@ -693,245 +694,250 @@ function cheque_status_form($form_state, $proposal_id)
'#type' => 'textfield',
'#default_value' => $chq1,
'#title' => t('Cheque No'),
- '#size' => 54,
+ '#size' => 54
);
$form['tea_cheque_details']['cheque_no_t'] = array(
'#type' => 'textfield',
'#default_value' => $chq17,
'#title' => t('Cheque No'),
- '#size' => 54,
+ '#size' => 54
);
$form['perm_cheque_address']['chq_address'] = array(
'#type' => 'textarea',
'#default_value' => $chq2,
- '#title' => t('Address Street 1'),
+ '#title' => t('Address Street 1')
);
$form['perm_cheque_address']['chq_address']['#attributes']['readonly'] = 'readonly';
$form['perm_cheque_address']['perm_city'] = array(
'#type' => 'textfield',
'#default_value' => $chq7,
'#title' => t('City'),
- '#size' => 35,
+ '#size' => 35
);
$form['perm_cheque_address']['perm_city']['#attributes']['readonly'] = 'readonly';
$form['perm_cheque_address']['perm_state'] = array(
'#type' => 'textfield',
'#default_value' => $chq8,
'#title' => t('State'),
- '#size' => 35,
+ '#size' => 35
);
$form['perm_cheque_address']['perm_state']['#attributes']['readonly'] = 'readonly';
$form['perm_cheque_address']['perm_pincode'] = array(
'#type' => 'textfield',
'#default_value' => $chq9,
'#title' => t('Zip code'),
- '#size' => 35,
+ '#size' => 35
);
$form['perm_cheque_address']['perm_pincode']['#attributes']['readonly'] = 'readonly';
$form['stu_cheque_details']['cheq_amt'] = array(
'#type' => 'textfield',
'#default_value' => $chq3,
'#title' => t('Cheque Amount'),
- '#size' => 54,
+ '#size' => 54
);
$form['tea_cheque_details']['cheq_amt_t'] = array(
'#type' => 'textfield',
'#default_value' => $chq17,
'#title' => t('Cheque Amount'),
- '#size' => 54,
+ '#size' => 54
);
$form['temp_cheque_address']['temp_chq_address'] = array(
'#type' => 'textarea',
'#default_value' => $chq10,
- '#title' => t('Address Street 1'),
+ '#title' => t('Address Street 1')
);
$form['temp_cheque_address']['temp_chq_address']['#attributes']['readonly'] = 'readonly';
$form['temp_cheque_address']['temp_city'] = array(
'#type' => 'textfield',
'#default_value' => $chq12,
'#title' => t('City'),
- '#size' => 35,
+ '#size' => 35
);
$form['temp_cheque_address']['temp_city']['#attributes']['readonly'] = 'readonly';
$form['temp_cheque_address']['temp_state'] = array(
'#type' => 'textfield',
'#default_value' => $chq13,
'#title' => t('State'),
- '#size' => 35,
+ '#size' => 35
);
$form['temp_cheque_address']['temp_state']['#attributes']['readonly'] = 'readonly';
$form['temp_cheque_address']['temp_pincode'] = array(
'#type' => 'textfield',
'#default_value' => $chq14,
'#title' => t('Zipcode'),
- '#size' => 35,
+ '#size' => 35
);
$form['temp_cheque_address']['temp_pincode']['#attributes']['readonly'] = 'readonly';
- }
+ } //$chqe = $chq4_q->fetchObject()
else
{
$form['stu_cheque_details']['cheque_no'] = array(
'#type' => 'textfield',
'#default_value' => $chq1,
- '#title' => t('Cheque No'),
+ '#title' => t('Cheque No')
);
$form['tea_cheque_details']['cheque_no_t'] = array(
'#type' => 'textfield',
'#default_value' => $chq16,
- '#title' => t('Cheque No'),
+ '#title' => t('Cheque No')
);
$form['perm_cheque_address']['chq_address'] = array(
'#type' => 'textarea',
'#default_value' => $chq2,
- '#title' => t('Address Street 1'),
+ '#title' => t('Address Street 1')
);
$form['perm_cheque_address']['perm_city'] = array(
'#type' => 'textfield',
'#default_value' => $chq7,
'#title' => t('City'),
- '#size' => 35,
+ '#size' => 35
);
$form['perm_cheque_address']['perm_state'] = array(
'#type' => 'textfield',
'#default_value' => $chq8,
'#title' => t('State'),
- '#size' => 35,
+ '#size' => 35
);
$form['perm_cheque_address']['perm_pincode'] = array(
'#type' => 'textfield',
'#default_value' => $chq9,
'#title' => t('Zip code'),
- '#size' => 35,
+ '#size' => 35
);
$form['perm_cheque_address']['same_address'] = array(
'#type' => 'checkbox',
'#title' => t('Same As Permanent Address'),
- '#attributes' => array('onclick' => 'copy_address()'),
- );
+ '#attributes' => array(
+ 'onclick' => 'copy_address()'
+ )
+ );
$form['stu_cheque_details']['cheq_amt'] = array(
'#type' => 'textfield',
'#default_value' => $chq3,
- '#title' => t('Cheque Amount'),
+ '#title' => t('Cheque Amount')
);
$form['tea_cheque_details']['cheq_amt'] = array(
'#type' => 'textfield',
'#default_value' => $chq17,
- '#title' => t('Cheque Amount'),
+ '#title' => t('Cheque Amount')
);
$form['temp_cheque_address']['temp_chq_address'] = array(
'#type' => 'textarea',
'#default_value' => $chq10,
- '#title' => t('Address Street 1'),
+ '#title' => t('Address Street 1')
);
$form['temp_cheque_address']['temp_city'] = array(
'#type' => 'textfield',
'#default_value' => $chq12,
'#title' => t('City'),
- '#size' => 35,
+ '#size' => 35
);
$form['temp_cheque_address']['temp_state'] = array(
'#type' => 'textfield',
'#default_value' => $chq13,
'#title' => t('State'),
- '#size' => 35,
+ '#size' => 35
);
$form['temp_cheque_address']['temp_pincode'] = array(
'#type' => 'textfield',
'#default_value' => $chq14,
'#title' => t('Zip code'),
- '#size' => 35,
+ '#size' => 35
);
$form['temp_cheque_address']['same_address'] = array(
'#type' => 'checkbox',
- '#title' => t('Same As Permanent Address'),
+ '#title' => t('Same As Permanent Address')
);
$form['temp_cheque_address']['same_address'] = array(
'#type' => 'checkbox',
'#title' => t('Same As Permanent Address'),
- '#attributes' => array('onclick' => 'copy_address()'),
- );
- }
- $form['cheque_delivery']['cheque_sent'] = array(
- '#type' => 'checkbox',
- '#title' => t('Cheque Sent'),
- '#default_value' => $chq4,
- '#description' => t('Check if the Cheque has been sent to the user.'),
- '#attributes' => array('id' => 'cheque_sent'),
- );
- $form['cheque_delivery']['cheque_cleared'] = array(
- '#type' => 'checkbox',
- '#title' => t('Cheque Cleared'),
- '#default_value' => $chq5,
- '#description' => t('Check if the Cheque has been <strong>Realised</strong> to the User Account.'),
- '#attributes' => array('id' => 'cheque_cleared'),
- );
- $form['commentf']['comment_cheque'] = array(
- '#type' => 'textarea',
- '#size' => 35,
- '#attributes' => array('id' => 'comment'),
- '#default_value' => $chq15,
- );
- $form['proposal_id'] = array(
- '#type' => 'hidden',
- '#value' => $proposal_id,
- );
-
- /*$preference1_p = db_query("SELECT * FROM {textbook_companion_paper} WHERE proposal_id = %d ORDER BY id ASC", $proposal_id); */
-
+ '#attributes' => array(
+ 'onclick' => 'copy_address()'
+ )
+ );
+ }
+ $form['cheque_delivery']['cheque_sent'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Cheque Sent'),
+ '#default_value' => $chq4,
+ '#description' => t('Check if the Cheque has been sent to the user.'),
+ '#attributes' => array(
+ 'id' => 'cheque_sent'
+ )
+ );
+ $form['cheque_delivery']['cheque_cleared'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Cheque Cleared'),
+ '#default_value' => $chq5,
+ '#description' => t('Check if the Cheque has been <strong>Realised</strong> to the User Account.'),
+ '#attributes' => array(
+ 'id' => 'cheque_cleared'
+ )
+ );
+ $form['commentf']['comment_cheque'] = array(
+ '#type' => 'textarea',
+ '#size' => 35,
+ '#attributes' => array(
+ 'id' => 'comment'
+ ),
+ '#default_value' => $chq15
+ );
+ $form['proposal_id'] = array(
+ '#type' => 'hidden',
+ '#value' => $proposal_id
+ );
+ /*$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');
- return;
- }
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Submit')
- );
- $form['cancel'] = array(
- '#type' => 'markup',
- '#value' => l(t('Cancel'), 'manage_proposal/all'),
- );
- return $form;
+ if (!($proposal_data1 = $preference1_p->fetchObject()))
+ {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('manage_proposal');
+ return;
+ } //!($proposal_data1 = $preference1_p->fetchObject())
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit')
+ );
+ $form['cancel'] = array(
+ '#type' => 'markup',
+ '#value' => l(t('Cancel'), 'manage_proposal/all')
+ );
+ return $form;
}
/*function cheque_status_form_validate($form, &$form_state)
{
- //var_dump(($form_state['values']['stu_cheque_details']['cheque_amt']));
- //die;
- if((!$form_state['values']['cheque_no'])||(!is_numeric($form_state['values']['cheque_no'])))
- {
- form_set_error('cheque_no', t('Invalid Student Cheque No. Please enter a valid cheque no.'));
- return;
- }
- if((!$form_state['values']['cheq_amt'])||(!is_numeric($form_state['values']['cheq_amt'])))
- {
- form_set_error('cheq_amt', t('Invalid Student Amount. Please enter a valid numeric amount.'));
- return;
- }
- if((!$form_state['values']['cheque_no_t'])||(!is_numeric($form_state['values']['cheque_no_t'])))
- {
- form_set_error('cheque_no_t', t('Invalid Teacher Cheque No. Please enter a valid cheque no.'));
- return;
- }
- if((!$form_state['values']['cheq_amt_t'])||(!is_numeric($form_state['values']['cheq_amt_t'])))
- {
- form_set_error('cheq_amt_t', t('Invalid Teacher Amount. Please enter a valid numeric amount.'));
- return;
- }
+//var_dump(($form_state['values']['stu_cheque_details']['cheque_amt']));
+//die;
+if((!$form_state['values']['cheque_no'])||(!is_numeric($form_state['values']['cheque_no'])))
+{
+form_set_error('cheque_no', t('Invalid Student Cheque No. Please enter a valid cheque no.'));
+return;
+}
+if((!$form_state['values']['cheq_amt'])||(!is_numeric($form_state['values']['cheq_amt'])))
+{
+form_set_error('cheq_amt', t('Invalid Student Amount. Please enter a valid numeric amount.'));
+return;
+}
+if((!$form_state['values']['cheque_no_t'])||(!is_numeric($form_state['values']['cheque_no_t'])))
+{
+form_set_error('cheque_no_t', t('Invalid Teacher Cheque No. Please enter a valid cheque no.'));
+return;
+}
+if((!$form_state['values']['cheq_amt_t'])||(!is_numeric($form_state['values']['cheq_amt_t'])))
+{
+form_set_error('cheq_amt_t', t('Invalid Teacher Amount. Please enter a valid numeric amount.'));
+return;
+}
}*/
function cheque_status_form_submit($form, &$form_state)
{
global $user;
- $proposal_id=arg(2);
-
-
+ $proposal_id = arg(2);
/*$query ="UPDATE {textbook_companion_cheque} SET
cheque_no = ".$form_state['values']['cheque_no'].",
cheque_amt = ".$form_state['values']['cheq_amt'].",
@@ -950,158 +956,138 @@ function cheque_status_form_submit($form, &$form_state)
WHERE proposal_id = ".$proposal_id;
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 ],
+ '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 = db_update('textbook_companion_cheque');
$query->fields(array(
- 'cheque_sent' => $form_state[ values ][ cheque_sent ],
+ '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;
$email_to = $book_user->mail;
- if (!drupal_mail('textbook_companion', 'cheque_sent', $email_to , language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE))
+ if (!drupal_mail('textbook_companion', 'cheque_sent', $email_to, language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE))
drupal_set_message('Error sending email message.', 'error');
drupal_set_message('Cheque for Book proposal has been Sent. User has been notified .', 'status');
- }
-
-
+ } //$form_state['values']['cheque_sent'] == 1
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 = db_update('textbook_companion_cheque');
$query->fields(array(
- 'cheque_cleared' => $form_state[ values ][ cheque_cleared ],
+ '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);*/
-
$query = db_update('textbook_companion_cheque');
$query->fields(array(
- 'cheque_dispatch_date' => 'NOW',
+ 'cheque_dispatch_date' => 'NOW'
));
$query->condition('proposal_id', $form_state['values']['proposal_id']);
$num_updated = $query->execute();
- }
-
+ } //$form_state['values']['cheque_cleared'] == 1
/************************************************
- Check For the Remark
+ Check For the Remark
************************************************/
if ($form_state['values']['comment_cheque'])
{
/* sending email */
- $book_user = user_load($proposal_data->uid);
+ $book_user = user_load($proposal_data->uid);
$param['proposal_completed']['proposal_id'] = $proposal_id;
$param['proposal_completed']['user_id'] = $proposal_data->uid;
$email_to = $book_user->mail;
- if (!drupal_mail('textbook_companion', 'remark', $email_to , language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE))
+ if (!drupal_mail('textbook_companion', 'remark', $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('Remark Updated. User has been notified'), 'status');
- }
- else
+ } //$form_state['values']['comment_cheque']
+ else
{
- if (!drupal_mail('textbook_companion', 'remark_not', $email_to , language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE))
+ if (!drupal_mail('textbook_companion', 'remark_not', $email_to, language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE))
drupal_set_message('Error sending email message.', 'error');
- drupal_set_message('No Remarks. User has been notified .', 'status');
+ drupal_set_message('No Remarks. User has been notified .', 'status');
}
}
-function MySQL_NOW(){ return date('Y-m-d'); }
-
+function MySQL_NOW()
+{
+ return date('Y-m-d');
+}
function contact_details($form_state)
{
global $user;
- if(!isset($_REQUEST['msg']))
+ if (!isset($_REQUEST['msg']))
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)
+ $data2 = $result->fetchObject();
+ if (!$data2)
{
drupal_set_message('Fill Up The <a href="proposal">Book Proposal Form</a>', 'error');
return '';
- }
+ } //!$data2
/*$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)
+ $data3 = $result->fetchObject();
+ if (!$data3->approval_status)
{
drupal_set_message('Book Proposal Has Not Been Accpeted .', 'error');
return '';
- }
-
+ } //!$data3->approval_status
$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);*/
-
$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;
+ $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);*/
$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;
@@ -1116,226 +1102,224 @@ function contact_details($form_state)
$form12 = 0;
$form13 = 0;
$form14 = 0;
- $form15 = 0;
-
- if($data = $result->fetchObject())
+ $form15 = 0;
+ if ($data = $result->fetchObject())
{
$form1 = $data->address;
$form8 = $data->alt_mobno;
- $form9 = $data->perm_city;
+ $form9 = $data->perm_city;
$form10 = $data->perm_state;
$form11 = $data->perm_pincode;
- $form12 = $data->temp_chq_address;
+ $form12 = $data->temp_chq_address;
$form13 = $data->temp_city;
$form14 = $data->temp_state;
- $form15 = $data->temp_pincode;
- }
- else
- {
+ $form15 = $data->temp_pincode;
+ } //$data = $result->fetchObject()
+ else
+ {
/*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));
+ ":proposal_id" => $proposal_id
+ );
+ $result = db_query($query, $args, array(
+ 'return' => Database::RETURN_INSERT_ID
+ ));
}
$form['candidate_detail'] = array(
- '#type' => 'fieldset',
- '#value' => $form_html,
- '#title' => t('Candidate Detail'),
- '#attributes' => array('id' => 'candidate_detail'),
+ '#type' => 'fieldset',
+ '#value' => $form_html,
+ '#title' => t('Candidate Detail'),
+ '#attributes' => array(
+ 'id' => 'candidate_detail'
+ )
+ );
+ $form['proposal_id'] = array(
+ '#type' => 'hidden',
+ '#default_value' => $proposal_id
);
- $form['proposal_id'] =array(
- '#type' => 'hidden',
- '#default_value' => $proposal_id,
- );
$form['candidate_detail']['fullname'] = array(
- '#type' => 'textfield',
- '#title' => t('Full Name'),
- '#size' => 48,
- '#default_value' => $full_name,
- );
- $form['candidate_detail']['email'] = array(
- '#type' => 'textfield',
- '#title' => t('Email'),
- '#size' => 48,
- '#value' => $user->mail,
- '#disabled' => TRUE,
- );
+ '#type' => 'textfield',
+ '#title' => t('Full Name'),
+ '#size' => 48,
+ '#default_value' => $full_name
+ );
+ $form['candidate_detail']['email'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Email'),
+ '#size' => 48,
+ '#value' => $user->mail,
+ '#disabled' => TRUE
+ );
$form['candidate_detail']['mobileno1'] = array(
- '#type' => 'textfield',
- '#title' => t('Mobile No'),
- '#size' => 48,
- '#default_value' => $mob_no,
- );
-
- $form['candidate_detail']['mobileno2'] = array(
- '#type' => 'textfield',
- '#title' => t('Alternate Mobile No'),
- '#size' => 48,
- '#default_value' => $form8,
- );
-
+ '#type' => 'textfield',
+ '#title' => t('Mobile No'),
+ '#size' => 48,
+ '#default_value' => $mob_no
+ );
+ $form['candidate_detail']['mobileno2'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Alternate Mobile No'),
+ '#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_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);*/
-
+ $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);*/
$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)
+ $q_data = $result->fetchObject();
+ $form_html .= '<ul>';
+ if ($q_data->internship_form)
{
$form_html .= '<li><strong>Internship Application </strong> Form Submitted</li>';
- }
+ } //$q_data->internship_form
else
{
$form_html .= '<li><strong>Internship Application </strong> Form Not Submitted.<br>Please submit it as soon as possible.</li>';
}
- if($q_data->copyright_form)
+ if ($q_data->copyright_form)
{
$form_html .= '<li><strong>Copyright Application </strong> Form Submitted</li>';
- }
+ } //$q_data->copyright_form
else
{
$form_html .= '<li><strong>Copyright Application</strong> Form Not Submitted.<br>Please submit it as soon as possible.</li>';
}
- if($q_data->undertaking_form)
+ if ($q_data->undertaking_form)
{
$form_html .= '<li><strong>Undertaking Application </strong> Form Submitted</li>';
- }
+ } //$q_data->undertaking_form
else
{
$form_html .= '<li><strong>Undertaking Application</strong> Form Not Submitted.<br>Please submit it as soon as possible.</li>';
}
$form_html .= '</ul>';
$form['Application Status'] = array(
- '#type' => 'fieldset',
- '#value' => $form_html,
- '#title' => t('Application Form Status'),
- '#attributes' => array('id' => 'app_status'),
+ '#type' => 'fieldset',
+ '#value' => $form_html,
+ '#title' => t('Application Form Status'),
+ '#attributes' => array(
+ 'id' => 'app_status'
+ )
+ );
+ $form['perm_cheque_address'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Permanent Address'),
+ '#collapsible' => TRUE,
+ '#collapsed' => FALSE,
+ '#attributes' => array(
+ 'id' => 'perm_cheque_address'
+ )
);
- $form['perm_cheque_address'] = array(
- '#type' => 'fieldset',
- '#title' => t('Permanent Address'),
- '#collapsible' => TRUE,
- '#collapsed' => FALSE,
- '#attributes' => array('id' => 'perm_cheque_address'),
- );
$form['temp_cheque_address'] = array(
- '#type' => 'fieldset',
- '#title' => t('Temporary Address'),
- '#collapsible' => TRUE,
- '#collapsed' => FALSE,
- '#attributes' => array('id' => 'temp_cheque_address'),
+ '#type' => 'fieldset',
+ '#title' => t('Temporary Address'),
+ '#collapsible' => TRUE,
+ '#collapsed' => FALSE,
+ '#attributes' => array(
+ 'id' => 'temp_cheque_address'
+ )
);
- $form['perm_cheque_address']['chq_address'] = array(
+ $form['perm_cheque_address']['chq_address'] = array(
'#type' => 'textarea',
'#title' => t('Address'),
'#size' => 35,
- '#default_value' => $form1,
+ '#default_value' => $form1
);
$form['perm_cheque_address']['perm_city'] = array(
'#type' => 'textfield',
'#default_value' => $form9,
'#title' => t('City'),
- '#size' => 35,
+ '#size' => 35
);
$form['perm_cheque_address']['perm_state'] = array(
'#type' => 'textfield',
'#default_value' => $form10,
'#title' => t('State'),
- '#size' => 35,
+ '#size' => 35
);
$form['perm_cheque_address']['perm_pincode'] = array(
'#type' => 'textfield',
'#default_value' => $form11,
'#title' => t('Zip code'),
- '#size' => 35,
+ '#size' => 35
);
$form['temp_cheque_address']['temp_chq_address'] = array(
'#type' => 'textarea',
'#default_value' => $form12,
'#title' => t('Address'),
- '#size' => 35,
+ '#size' => 35
);
$form['temp_cheque_address']['temp_city'] = array(
'#type' => 'textfield',
'#default_value' => $form13,
'#title' => t('City'),
- '#size' => 35,
+ '#size' => 35
);
$form['temp_cheque_address']['temp_state'] = array(
'#type' => 'textfield',
'#default_value' => $form14,
'#title' => t('State'),
- '#size' => 35,
+ '#size' => 35
);
$form['temp_cheque_address']['temp_pincode'] = array(
'#type' => 'textfield',
'#default_value' => $form15,
'#title' => t('Zip code'),
- '#size' => 35,
+ '#size' => 35
);
$form['temp_cheque_address']['same_address'] = array(
'#type' => 'checkbox',
- '#title' => t('Same As Permanent Address'),
+ '#title' => t('Same As Permanent Address')
);
- if($chq_data->commentf)
- {
+ if ($chq_data->commentf)
+ {
$form['commentu'] = array(
- '#type' => 'fieldset',
- '#title' => t('Remarks'),
- '#collapsible' => FALSE,
- '#collapsed' => FALSE,
- '#attributes' => array('id' => 'comment_cheque'),
- );
- $form['commentu']['comment_cheque'] = array(
- '#type' => 'textarea',
- '#size' => 35,
- '#default_value' => $form16,
+ '#type' => 'fieldset',
+ '#title' => t('Remarks'),
+ '#collapsible' => FALSE,
+ '#collapsed' => FALSE,
+ '#attributes' => array(
+ 'id' => 'comment_cheque'
+ )
);
- }
- $form['commentu']['comment_cheque'] ['#attributes']['readonly'] = 'readonly';
+ $form['commentu']['comment_cheque'] = array(
+ '#type' => 'textarea',
+ '#size' => 35,
+ '#default_value' => $form16
+ );
+ } //$chq_data->commentf
+ $form['commentu']['comment_cheque']['#attributes']['readonly'] = 'readonly';
$form['submit'] = array(
- '#type' => 'submit',
+ '#type' => 'submit',
'#value' => t('Update')
- );
- $form['cancel'] = array(
+ );
+ $form['cancel'] = array(
'#type' => 'markup',
- '#value' => l(t('Cancel'), 'manage_proposal/all'),
+ '#value' => l(t('Cancel'), 'manage_proposal/all')
);
- return $form;
+ return $form;
}
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);*/
-
$query = db_select('textbook_companion_proposal');
$query->fields('textbook_companion_proposal');
$query->condition('uid', $x);
$result = $query->execute();
- $data2=$result->fetchObject();
-
-
+ $data2 = $result->fetchObject();
/*$query ="UPDATE {textbook_companion_cheque} SET
alt_mobno = '".$form_state['values']['mobileno2']."' ,
address = '".$form_state['values']['chq_address']."',
@@ -1349,82 +1333,91 @@ function contact_details_submit($form, &$form_state)
address_con = 'Submitted'
WHERE proposal_id = ".$data2->id;
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',
+ '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);
+ drupal_goto('mycontact', array(
+ 'msg' => 0
+ ), $fragment = NULL, $http_response_code = 302);
}
function copy_address()
{
-
- alert("Hello");
- $form['temp_cheque_address']['temp_chq_address'] = array(
- '#type' => 'textarea',
- '#default_value' => $form['values']['chq_address'],
- '#title' => t('Address Street 1'),
- );
-
- $form['temp_cheque_address']['temp_city'] = array(
- '#type' => 'textfield',
- '#default_value' => $form['values']['perm_city'],
- '#title' => t('City'),
- '#size' => 35,
- );
- $form['temp_cheque_address']['temp_state'] = array(
- '#type' => 'textfield',
- '#default_value' => $form['values']['perm_state'],
- '#title' => t('State'),
- '#size' => 35,
- );
- $form['temp_cheque_address']['temp_pincode'] = array(
- '#type' => 'textfield',
- '#default_value' => $form['values']['perm_pincode'],
- '#title' => t('Zip code'),
- '#size' => 35,
- );
+ alert("Hello");
+ $form['temp_cheque_address']['temp_chq_address'] = array(
+ '#type' => 'textarea',
+ '#default_value' => $form['values']['chq_address'],
+ '#title' => t('Address Street 1')
+ );
+ $form['temp_cheque_address']['temp_city'] = array(
+ '#type' => 'textfield',
+ '#default_value' => $form['values']['perm_city'],
+ '#title' => t('City'),
+ '#size' => 35
+ );
+ $form['temp_cheque_address']['temp_state'] = array(
+ '#type' => 'textfield',
+ '#default_value' => $form['values']['perm_state'],
+ '#title' => t('State'),
+ '#size' => 35
+ );
+ $form['temp_cheque_address']['temp_pincode'] = array(
+ '#type' => 'textfield',
+ '#default_value' => $form['values']['perm_pincode'],
+ '#title' => t('Zip code'),
+ '#size' => 35
+ );
}
-
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)");*/
-
- $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();
-
+ $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 = $search_qx->fetchObject())
{
- $result = array($search_datax->full_name,$search_datax->address_con,$search_datax->cheque_no,$search_datax->cheque_dispatch_date);
- }
- if (!$result) die('Couldn\'t fetch records');
+ $result = array(
+ $search_datax->full_name,
+ $search_datax->address_con,
+ $search_datax->cheque_no,
+ $search_datax->cheque_dispatch_date
+ );
+ } //$search_datax = $search_qx->fetchObject()
+ if (!$result)
+ die('Couldn\'t fetch records');
$num_fields = count($result);
$headers = array();
- for ($i = 0; $i < $num_fields; $i++)
+ for ($i = 0; $i < $num_fields; $i++)
{
- $headers[] = mysql_field_name($result , $i);
- }
-
+ $headers[] = mysql_field_name($result, $i);
+ } //$i = 0; $i < $num_fields; $i++
$row = array();
$fp = fopen('php://output', 'w');
- $search_header = array('Name Of The Student', 'Application Form Status', 'Cheque No', 'Cheque Clearance Date');
+ $search_header = array(
+ 'Name Of The Student',
+ 'Application Form Status',
+ 'Cheque No',
+ 'Cheque Clearance Date'
+ );
fputcsv($fp, $search_header);
if ($fp && $result)
{
@@ -1433,11 +1426,11 @@ function cheque_report_form()
header('Pragma: no-cache');
header('Expires: 0');
fputcsv($fp, $headers);
- while ($row = mysql_fetch_row($result))
+ while ($row = mysql_fetch_row($result))
{
fputcsv($fp, array_values($row));
- }
+ } //$row = mysql_fetch_row($result)
die;
- }
+ } //$fp && $result
}
-?>
+
diff --git a/cheque_manage.inc b/cheque_manage.inc
index 8ddeffb..475fab5 100755
--- a/cheque_manage.inc
+++ b/cheque_manage.inc
@@ -1,87 +1,93 @@
-<?php
+<?php
function cheque_proposal_all()
{
-
-
- $form['#redirect'] = FALSE;
- $form['search_cheque'] = array(
- '#type' => 'textfield',
- '#title' => t('Search'),
- '#size' => 48,
- );
- $form['submit_cheque'] = array(
- '#type' => 'submit',
- '#value' => t('Search')
- );
- $form['cancel_cheque'] = array(
- '#type' => 'markup',
- '#value' => l(t('Cancel'), ''),
- );
-
-
- $count=20;
- /* get pending proposals to be approved */
- $proposal_rows = array();
-
- /*$proposal_q = "SELECT * FROM {textbook_companion_proposal} ORDER BY id DESC";*/
+ $form['#redirect'] = FALSE;
+ $form['search_cheque'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Search'),
+ '#size' => 48
+ );
+ $form['submit_cheque'] = array(
+ '#type' => 'submit',
+ '#value' => t('Search')
+ );
+ $form['cancel_cheque'] = array(
+ '#type' => 'markup',
+ '#value' => l(t('Cancel'), '')
+ );
+ $count = 20;
+ /* get pending proposals to be approved */
+ $proposal_rows = array();
+ /*$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 = 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);*/
-
- $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)
- {
- case 0: $proposal_status = 'Pending'; break;
- case 1: $proposal_status = 'Approved'; break;
- case 2: $proposal_status = 'Dis-approved'; break;
- case 3: $proposal_status = 'Completed'; break;
- default: $proposal_status = 'Unknown'; break;
- }
- $proposal_rows[] = array(date('d-m-Y', $proposal_data->creation_date), l($proposal_data->full_name, 'user/' . $proposal_data->uid), date('d-m-Y', $proposal_data->completion_date), l('Form Submission', 'manage_proposal/paper_submission/' . $proposal_data->id) . ' | ' . l('Cheque Details', 'cheque_contact/status/' . $proposal_data->id));
- }
-
- /* check if there are any pending proposals */
- if (!$proposal_rows)
- {
- drupal_set_message(t('There are no proposals.'), 'status');
- return '';
- }
-
- $proposal_header = array('Date of Submission', 'Contributor Name', 'Expected Date of Completion', 'Status');
- $output = theme('table',array('header' =>$proposal_header,'rows'=>$proposal_rows));
- return $output . theme_pager($count);
- }
- return $form;
-
+ 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);*/
+ $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)
+ {
+ case 0:
+ $proposal_status = 'Pending';
+ break;
+ case 1:
+ $proposal_status = 'Approved';
+ break;
+ case 2:
+ $proposal_status = 'Dis-approved';
+ break;
+ case 3:
+ $proposal_status = 'Completed';
+ break;
+ default:
+ $proposal_status = 'Unknown';
+ break;
+ } //$proposal_data->proposal_status
+ $proposal_rows[] = array(
+ date('d-m-Y', $proposal_data->creation_date),
+ l($proposal_data->full_name, 'user/' . $proposal_data->uid),
+ date('d-m-Y', $proposal_data->completion_date),
+ l('Form Submission', 'manage_proposal/paper_submission/' . $proposal_data->id) . ' | ' . l('Cheque Details', 'cheque_contact/status/' . $proposal_data->id)
+ );
+ } //$proposal_data = $pagerquery->fetchObject()
+ /* check if there are any pending proposals */
+ if (!$proposal_rows)
+ {
+ drupal_set_message(t('There are no proposals.'), 'status');
+ return '';
+ } //!$proposal_rows
+ $proposal_header = array(
+ 'Date of Submission',
+ 'Contributor Name',
+ 'Expected Date of Completion',
+ 'Status'
+ );
+ $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 aa99d85..07d7690 100755
--- a/code.inc
+++ b/code.inc
@@ -1,81 +1,71 @@
<?php
// $Id$
-
function upload_examples()
{
- return drupal_get_form('upload_examples_form');
+ return drupal_get_form('upload_examples_form');
}
-
-function upload_examples_form($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);*/
-
+ 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);*/
$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');
- drupal_goto('');
- }
- if ($proposal_data->proposal_status != 1 && $proposal_data->proposal_status != 4)
- {
- 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');
- drupal_goto('');
- return;
- break;
- case 2:
- drupal_set_message(t('Your proposal has been dis-approved. Please create another proposal ' . l('here', 'proposal') . '.'), 'error');
- drupal_goto('');
- return;
- break;
- case 3:
- drupal_set_message(t('Congratulations! You have completed your last book proposal. You have to create another proposal ' . l('here', 'proposal') . '.'), 'status');
- drupal_goto('');
- return;
- break;
- default:
- drupal_set_message(t('Invalid proposal state. Please contact site administrator for further information.'), 'error');
- drupal_goto('');
- return;
- break;
- }
- }
-
- /*$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);*/
-
+ $proposal_data = $result->fetchObject();
+ if (!$proposal_data)
+ {
+ drupal_set_message("Please submit a " . l('proposal', 'proposal') . ".", 'error');
+ drupal_goto('');
+ } //!$proposal_data
+ if ($proposal_data->proposal_status != 1 && $proposal_data->proposal_status != 4)
+ {
+ 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');
+ drupal_goto('');
+ return;
+ break;
+ case 2:
+ drupal_set_message(t('Your proposal has been dis-approved. Please create another proposal ' . l('here', 'proposal') . '.'), 'error');
+ drupal_goto('');
+ return;
+ break;
+ case 3:
+ drupal_set_message(t('Congratulations! You have completed your last book proposal. You have to create another proposal ' . l('here', 'proposal') . '.'), 'status');
+ drupal_goto('');
+ return;
+ break;
+ default:
+ drupal_set_message(t('Invalid proposal state. Please contact site administrator for further information.'), 'error');
+ drupal_goto('');
+ return;
+ break;
+ } //$proposal_data->proposal_status
+ } //$proposal_data->proposal_status != 1 && $proposal_data->proposal_status != 4
+ /*$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');
- drupal_goto('');
- return;
- }
- /************************ end approve book details **************************/
-
- /* add javascript for automatic book title, check if example uploaded, dependency selection effects */
- $chapter_name_js = "(function ($) {
+ $preference_data = $result->fetchObject();
+ if (!$preference_data)
+ {
+ drupal_set_message(t('Invalid Book Preference status. Please contact site administrator for further information.'), 'error');
+ drupal_goto('');
+ return;
+ } //!$preference_data
+ /************************ end approve book details **************************/
+ /* add javascript for automatic book title, check if example uploaded, dependency selection effects */
+ $chapter_name_js = "(function ($) {
$(document).ready(function(){
@@ -91,7 +81,7 @@ $(document).ready(function(){
$('#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);
}
});
});
@@ -119,251 +109,227 @@ $(document).ready(function(){
});
})(jQuery);";
- drupal_add_js($chapter_name_js, 'inline', 'header');
-
- $form['#attributes'] = array('enctype' => "multipart/form-data");
-
- $form['book_details']['book'] = array(
- '#type' => 'item',
- '#markup' => $preference_data->book,
- '#title' => t('Title of the Book'),
- );
- $form['contributor_name'] = array(
- '#type' => 'item',
- '#markup' => $proposal_data->full_name,
- '#title' => t('Contributor Name'),
- );
- $options = array('' => '(Select)');
- for($i=1;$i<=100;$i++){
- $options[$i] = $i;
- }
- //var_dump($options);
- $form['number'] = array(
- '#type' => 'select',
- '#title' => t('Chapter No'),
- '#options' => $options,
- // '#options' => array('' => '(Select)', '1' => '1', '2', '3', '4', '5', '6', '7', '8', '9', '10',
- // '11', '12', '13', '14', '15', '16', '17', '18', '19', '20',
- // '21', '22', '23', '24', '25', '26', '27', '28', '29', '30',
- // '31', '32', '33', '34', '35', '36', '37', '38', '39', '40',
- // '41', '42', '43', '44', '45', '46', '47', '48', '49', '50'),
- '#multiple' => FALSE,
- '#size' => 1,
- '#required' => TRUE,
- );
- $form['name'] = array(
- '#type' => 'textfield',
- '#title' => t('Title of the Chapter'),
- '#size' => 40,
- '#maxlength' => 255,
- '#required' => TRUE,
- );
- $form['example_number'] = array(
- '#type' => 'textfield',
- '#title' => t('Example No'),
- '#size' => 5,
- '#maxlength' => 10,
- '#description' => t("Example number should be separated by dots only.<br />Example: 1.1.a &nbsp;or&nbsp; 1.1.1"),
- '#required' => TRUE,
- );
- $form['example_caption'] = array(
- '#type' => 'textfield',
- '#title' => t('Caption'),
- '#size' => 40,
- '#maxlength' => 255,
- '#description' => t('Example caption should contain only alphabets, numbers and spaces.'),
- '#required' => TRUE,
- );
- $form['example_warning'] = array(
- '#type' => 'item',
- '#title' => t('You should upload all the files (main or source files, result files, executable file if any)'),
- '#prefix' => '<div style="color:red">',
- '#suffix' => '</div>',
- );
-
- $form['sourcefile'] = array(
- '#type' => 'fieldset',
- '#title' => t('Main or Source Files'),
- '#collapsible' => FALSE,
- '#collapsed' => FALSE,
- );
- $form['sourcefile']['sourcefile1'] = array(
- '#type' => 'file',
- '#title' => t('Upload main or source file'),
- '#size' => 48,
- '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' .
- t('Allowed file extensions : ') . variable_get('textbook_companion_source_extensions', ''),
- );
-
- $form['dep_files'] = array(
- '#type' => 'item',
- '#title' => t('Dependency Files'),
- );
-
- /************ START OF EXISTING DEPENDENCIES **************/
-
- /* existing dependencies */
- $form['existing_depfile'] = array(
- '#type' => 'fieldset',
- '#title' => t('Use Already Existing Dependency Files'),
- '#collapsible' => FALSE,
- '#collapsed' => FALSE,
- '#prefix' => '<div id="existing-depfile-wrapper">',
- '#suffix' => '</div>',
- '#tree' => TRUE,
- );
-
- /* 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_book_title'] = array(
- '#type' => 'select',
- '#title' => t('Title of the Book'),
- '#options' => _list_of_book_titles(),
- );*/
-
- list($files_options, $files_options_class) = _list_of_book_dependency_files($preference_data->id);
-
-$form['existing_depfile']['dep_book'] = array(
- '#type' => 'item',
- '#title' => t('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 **************/
-
- $form['result'] = array(
- '#type' => 'fieldset',
- '#title' => t('Result Files'),
- '#collapsible' => FALSE,
- '#collapsed' => FALSE,
- );
- $form['result']['result1'] = array(
- '#type' => 'file',
- '#title' => t('Upload result file'),
- '#size' => 48,
- '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' .
- t('Allowed file extensions : ') . variable_get('textbook_companion_result_extensions', ''),
- );
- $form['result']['result2'] = array(
- '#type' => 'file',
- '#title' => t('Upload result file'),
- '#size' => 48,
- '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' .
- t('Allowed file extensions : ') . variable_get('textbook_companion_result_extensions', ''),
- );
-
- $form['xcos'] = array(
- '#type' => 'fieldset',
- '#title' => t('XCOS Files'),
- '#collapsible' => FALSE,
- '#collapsed' => FALSE,
- );
- $form['xcos']['xcos1'] = array(
- '#type' => 'file',
- '#title' => t('Upload xcos file'),
- '#size' => 48,
- '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' .
- t('Allowed file extensions : ') . variable_get('textbook_companion_xcos_extensions', ''),
- );
- $form['xcos']['xcos2'] = array(
- '#type' => 'file',
- '#title' => t('Upload xcos file'),
- '#size' => 48,
- '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' .
- t('Allowed file extensions : ') . variable_get('textbook_companion_xcos_extensions', ''),
- );
-
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Submit')
- );
-
- $form['cancel'] = array(
- '#type' => 'markup',
- '#value' => l(t('Cancel'), 'textbook_companion/code'),
- );
- return $form;
+ drupal_add_js($chapter_name_js, 'inline', 'header');
+ $form['#attributes'] = array(
+ 'enctype' => "multipart/form-data"
+ );
+ $form['book_details']['book'] = array(
+ '#type' => 'item',
+ '#markup' => $preference_data->book,
+ '#title' => t('Title of the Book')
+ );
+ $form['contributor_name'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->full_name,
+ '#title' => t('Contributor Name')
+ );
+ $options = array(
+ '' => '(Select)'
+ );
+ for ($i = 1; $i <= 100; $i++)
+ {
+ $options[$i] = $i;
+ } //$i = 1; $i <= 100; $i++
+ //var_dump($options);
+ $form['number'] = array(
+ '#type' => 'select',
+ '#title' => t('Chapter No'),
+ '#options' => $options,
+ // '#options' => array('' => '(Select)', '1' => '1', '2', '3', '4', '5', '6', '7', '8', '9', '10',
+ // '11', '12', '13', '14', '15', '16', '17', '18', '19', '20',
+ // '21', '22', '23', '24', '25', '26', '27', '28', '29', '30',
+ // '31', '32', '33', '34', '35', '36', '37', '38', '39', '40',
+ // '41', '42', '43', '44', '45', '46', '47', '48', '49', '50'),
+ '#multiple' => FALSE,
+ '#size' => 1,
+ '#required' => TRUE
+ );
+ $form['name'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Title of the Chapter'),
+ '#size' => 40,
+ '#maxlength' => 255,
+ '#required' => TRUE
+ );
+ $form['example_number'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Example No'),
+ '#size' => 5,
+ '#maxlength' => 10,
+ '#description' => t("Example number should be separated by dots only.<br />Example: 1.1.a &nbsp;or&nbsp; 1.1.1"),
+ '#required' => TRUE
+ );
+ $form['example_caption'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Caption'),
+ '#size' => 40,
+ '#maxlength' => 255,
+ '#description' => t('Example caption should contain only alphabets, numbers and spaces.'),
+ '#required' => TRUE
+ );
+ $form['example_warning'] = array(
+ '#type' => 'item',
+ '#title' => t('You should upload all the files (main or source files, result files, executable file if any)'),
+ '#prefix' => '<div style="color:red">',
+ '#suffix' => '</div>'
+ );
+ $form['sourcefile'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Main or Source Files'),
+ '#collapsible' => FALSE,
+ '#collapsed' => FALSE
+ );
+ $form['sourcefile']['sourcefile1'] = array(
+ '#type' => 'file',
+ '#title' => t('Upload main or source file'),
+ '#size' => 48,
+ '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' . t('Allowed file extensions : ') . variable_get('textbook_companion_source_extensions', '')
+ );
+ $form['dep_files'] = array(
+ '#type' => 'item',
+ '#title' => t('Dependency Files')
+ );
+ /************ START OF EXISTING DEPENDENCIES **************/
+ /* existing dependencies */
+ $form['existing_depfile'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Use Already Existing Dependency Files'),
+ '#collapsible' => FALSE,
+ '#collapsed' => FALSE,
+ '#prefix' => '<div id="existing-depfile-wrapper">',
+ '#suffix' => '</div>',
+ '#tree' => TRUE
+ );
+ /* 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_book_title'] = array(
+ '#type' => 'select',
+ '#title' => t('Title of the Book'),
+ '#options' => _list_of_book_titles(),
+ );*/
+ list($files_options, $files_options_class) = _list_of_book_dependency_files($preference_data->id);
+ $form['existing_depfile']['dep_book'] = array(
+ '#type' => 'item',
+ '#title' => t('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 **************/
+ $form['result'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Result Files'),
+ '#collapsible' => FALSE,
+ '#collapsed' => FALSE
+ );
+ $form['result']['result1'] = array(
+ '#type' => 'file',
+ '#title' => t('Upload result file'),
+ '#size' => 48,
+ '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' . t('Allowed file extensions : ') . variable_get('textbook_companion_result_extensions', '')
+ );
+ $form['result']['result2'] = array(
+ '#type' => 'file',
+ '#title' => t('Upload result file'),
+ '#size' => 48,
+ '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' . t('Allowed file extensions : ') . variable_get('textbook_companion_result_extensions', '')
+ );
+ $form['xcos'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('XCOS Files'),
+ '#collapsible' => FALSE,
+ '#collapsed' => FALSE
+ );
+ $form['xcos']['xcos1'] = array(
+ '#type' => 'file',
+ '#title' => t('Upload xcos file'),
+ '#size' => 48,
+ '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' . t('Allowed file extensions : ') . variable_get('textbook_companion_xcos_extensions', '')
+ );
+ $form['xcos']['xcos2'] = array(
+ '#type' => 'file',
+ '#title' => t('Upload xcos file'),
+ '#size' => 48,
+ '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' . t('Allowed file extensions : ') . variable_get('textbook_companion_xcos_extensions', '')
+ );
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit')
+ );
+ $form['cancel'] = array(
+ '#type' => 'markup',
+ '#value' => l(t('Cancel'), 'textbook_companion/code')
+ );
+ return $form;
}
-
function upload_examples_form_validate($form, &$form_state)
{
- if (!check_name($form_state['values']['name']))
- form_set_error('name', t('Title of the Chapter can contain only alphabets, numbers and spaces.'));
-
- if (!check_name($form_state['values']['example_caption']))
- form_set_error('example_caption', t('Example Caption can contain only alphabets, numbers and spaces.'));
-
- if (!check_chapter_number($form_state['values']['example_number']))
- form_set_error('example_number', t('Invalid Example Number. Example Number can contain only alphabets and numbers sepereated by dot.'));
-
- if (isset($_FILES['files']))
- {
- /* check if atleast one source or result file is uploaded */
- if ( ! ($_FILES['files']['name']['sourcefile1'] || $_FILES['files']['name']['xcos1']))
- form_set_error('sourcefile1', t('Please upload atleast one main or source file or xcos file.'));
-
- /* check for valid filename extensions */
- foreach ($_FILES['files']['name'] as $file_form_name => $file_name)
- {
- if ($file_name)
- {
- /* checking file type */
- if (strstr($file_form_name, 'source'))
- $file_type = 'S';
- else if (strstr($file_form_name, 'result'))
- $file_type = 'R';
- else if (strstr($file_form_name, 'xcos'))
- $file_type = 'X';
- else
- $file_type = 'U';
-
- $allowed_extensions_str = '';
- switch ($file_type)
- {
- case 'S':
- $allowed_extensions_str = variable_get('textbook_companion_source_extensions', '');
- break;
- case 'R':
- $allowed_extensions_str = variable_get('textbook_companion_result_extensions', '');
- break;
- case 'X':
- $allowed_extensions_str = variable_get('textbook_companion_xcos_extensions', '');
- break;
- }
-
- $allowed_extensions = explode(',' , $allowed_extensions_str);
- $temp_extension = end(explode('.', strtolower($_FILES['files']['name'][$file_form_name])));
- if (!in_array($temp_extension, $allowed_extensions))
- form_set_error($file_form_name, t('Only file with ' . $allowed_extensions_str . ' extensions can be uploaded.'));
- if ($_FILES['files']['size'][$file_form_name] <= 0)
- form_set_error($file_form_name, t('File size cannot be zero.'));
-
- /* check if valid file name */
- if (!textbook_companion_check_valid_filename($_FILES['files']['name'][$file_form_name]))
- form_set_error($file_form_name, t('Invalid file name specified. Only alphabets, numbers and underscore is allowed as a valid filename.'));
- }
- }
- }
-
- /* add javascript again for automatic book title, check if example uploaded, dependency selection effects */
- $chapter_name_js = "(function ($) {
+ if (!check_name($form_state['values']['name']))
+ form_set_error('name', t('Title of the Chapter can contain only alphabets, numbers and spaces.'));
+ if (!check_name($form_state['values']['example_caption']))
+ form_set_error('example_caption', t('Example Caption can contain only alphabets, numbers and spaces.'));
+ if (!check_chapter_number($form_state['values']['example_number']))
+ form_set_error('example_number', t('Invalid Example Number. Example Number can contain only alphabets and numbers sepereated by dot.'));
+ if (isset($_FILES['files']))
+ {
+ /* check if atleast one source or result file is uploaded */
+ if (!($_FILES['files']['name']['sourcefile1'] || $_FILES['files']['name']['xcos1']))
+ form_set_error('sourcefile1', t('Please upload atleast one main or source file or xcos file.'));
+ /* check for valid filename extensions */
+ foreach ($_FILES['files']['name'] as $file_form_name => $file_name)
+ {
+ if ($file_name)
+ {
+ /* checking file type */
+ if (strstr($file_form_name, 'source'))
+ $file_type = 'S';
+ else if (strstr($file_form_name, 'result'))
+ $file_type = 'R';
+ else if (strstr($file_form_name, 'xcos'))
+ $file_type = 'X';
+ else
+ $file_type = 'U';
+ $allowed_extensions_str = '';
+ switch ($file_type)
+ {
+ case 'S':
+ $allowed_extensions_str = variable_get('textbook_companion_source_extensions', '');
+ break;
+ case 'R':
+ $allowed_extensions_str = variable_get('textbook_companion_result_extensions', '');
+ break;
+ case 'X':
+ $allowed_extensions_str = variable_get('textbook_companion_xcos_extensions', '');
+ break;
+ } //$file_type
+ $allowed_extensions = explode(',', $allowed_extensions_str);
+ $temp_extension = end(explode('.', strtolower($_FILES['files']['name'][$file_form_name])));
+ if (!in_array($temp_extension, $allowed_extensions))
+ form_set_error($file_form_name, t('Only file with ' . $allowed_extensions_str . ' extensions can be uploaded.'));
+ if ($_FILES['files']['size'][$file_form_name] <= 0)
+ form_set_error($file_form_name, t('File size cannot be zero.'));
+ /* check if valid file name */
+ if (!textbook_companion_check_valid_filename($_FILES['files']['name'][$file_form_name]))
+ form_set_error($file_form_name, t('Invalid file name specified. Only alphabets, numbers and underscore is allowed as a valid filename.'));
+ } //$file_name
+ } //$_FILES['files']['name'] as $file_form_name => $file_name
+ } //isset($_FILES['files'])
+ /* add javascript again for automatic book title, check if example uploaded, dependency selection effects */
+ $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);
@@ -398,456 +364,427 @@ function upload_examples_form_validate($form, &$form_state)
});
$('#edit-existing-depfile-dep-book-title').trigger('change');
})(jQuery);";
- drupal_add_js($chapter_name_js, 'inline', 'header');
+ drupal_add_js($chapter_name_js, 'inline', 'header');
}
-
-function upload_examples_form_submit($form, &$form_state) {
- global $user;
-
- $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);*/
+function upload_examples_form_submit($form, &$form_state)
+{
+ global $user;
+ $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);*/
$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');
- drupal_goto('');
- }
- if ($proposal_data->proposal_status != 1 && $proposal_data->proposal_status != 4)
- {
- 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');
- drupal_goto('');
- return;
- break;
- case 2:
- drupal_set_message(t('Your proposal has been dis-approved. Please create another proposal ' . l('here', 'proposal') . '.'), 'error');
- drupal_goto('');
- return;
- break;
- case 3:
- drupal_set_message(t('Congratulations! You have completed your last book proposal. You have to create another proposal ' . l('here', 'textbook_companion/proposal') . '.'), 'status');
- drupal_goto('');
- return;
- break;
- default:
- drupal_set_message(t('Invalid proposal state. Please contact site administrator for further information.'), 'error');
- drupal_goto('');
- return;
- break;
- }
- }
-
- /*$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);*/
-
+ $proposal_data = $result->fetchObject();
+ if (!$proposal_data)
+ {
+ drupal_set_message("Please submit a " . l('proposal', 'proposal') . ".", 'error');
+ drupal_goto('');
+ } //!$proposal_data
+ if ($proposal_data->proposal_status != 1 && $proposal_data->proposal_status != 4)
+ {
+ 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');
+ drupal_goto('');
+ return;
+ break;
+ case 2:
+ drupal_set_message(t('Your proposal has been dis-approved. Please create another proposal ' . l('here', 'proposal') . '.'), 'error');
+ drupal_goto('');
+ return;
+ break;
+ case 3:
+ drupal_set_message(t('Congratulations! You have completed your last book proposal. You have to create another proposal ' . l('here', 'textbook_companion/proposal') . '.'), 'status');
+ drupal_goto('');
+ return;
+ break;
+ default:
+ drupal_set_message(t('Invalid proposal state. Please contact site administrator for further information.'), 'error');
+ drupal_goto('');
+ return;
+ break;
+ } //$proposal_data->proposal_status
+ } //$proposal_data->proposal_status != 1 && $proposal_data->proposal_status != 4
+ /*$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');
- drupal_goto('');
- return;
- }
- /************************ end approve book details **************************/
-
- $preference_id = $preference_data->id;
-
- $dest_path = $preference_id . '/';
- if (!is_dir($root_path . $dest_path))
- mkdir($root_path . $dest_path);
-
- /* 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']);*/
-
+ $preference_data = $result->fetchObject();
+ if (!$preference_data)
+ {
+ drupal_set_message(t('Invalid Book Preference status. Please contact site administrator for further information.'), 'error');
+ drupal_goto('');
+ return;
+ } //!$preference_data
+ /************************ end approve book details **************************/
+ $preference_id = $preference_data->id;
+ $dest_path = $preference_id . '/';
+ if (!is_dir($root_path . $dest_path))
+ mkdir($root_path . $dest_path);
+ /* 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']);*/
$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')",
- $preference_id,
- $form_state['values']['number'],
- $form_state['values']['name']
- );
- $chapter_id = db_last_insert_id('textbook_companion_chapter', 'id'); */
-
+ if (!$chapter_row = $chapter_result->fetchObject())
+ {
+ /*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'); */
$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);*/
- $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']);*/
-
+ ":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;
+ } //!$chapter_row = $chapter_result->fetchObject()
+ else
+ {
+ $chapter_id = $chapter_row->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']);*/
$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)
- {
- drupal_set_message(t("Example already approved. Cannot overwrite it."), 'error');
- drupal_goto('textbook_companion/code');
- return;
- } else if ($cur_example_d->approval_status == 0) {
- drupal_set_message(t("Example is under pending review. Delete the example and reupload it."), 'error');
- drupal_goto('textbook_companion/code');
- return;
- } else {
- drupal_set_message(t("Error uploading example. Please contact administrator."), 'error');
- drupal_goto('textbook_companion/code');
- return;
- }
- }
-
- /* creating directories */
- $dest_path .= 'CH' . $form_state['values']['number'] . '/';
- if (!is_dir($root_path . $dest_path))
- mkdir($root_path . $dest_path);
-
- $dest_path .= 'EX' . $form_state['values']['example_number'] . '/';
- if (!is_dir($root_path . $dest_path))
- 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)",
- $chapter_id,
- $form_state['values']['example_number'],
- $form_state['values']['example_caption'],
- 0,
- time()
- );
- $example_id = db_last_insert_id('textbook_companion_example', 'id');*/
-
+ if ($cur_example_d = $cur_example_q->fetchObject())
+ {
+ if ($cur_example_d->approval_status == 1)
+ {
+ drupal_set_message(t("Example already approved. Cannot overwrite it."), 'error');
+ drupal_goto('textbook_companion/code');
+ return;
+ } //$cur_example_d->approval_status == 1
+ else if ($cur_example_d->approval_status == 0)
+ {
+ drupal_set_message(t("Example is under pending review. Delete the example and reupload it."), 'error');
+ drupal_goto('textbook_companion/code');
+ return;
+ } //$cur_example_d->approval_status == 0
+ else
+ {
+ drupal_set_message(t("Error uploading example. Please contact administrator."), 'error');
+ drupal_goto('textbook_companion/code');
+ return;
+ }
+ } //$cur_example_d = $cur_example_q->fetchObject()
+ /* creating directories */
+ $dest_path .= 'CH' . $form_state['values']['number'] . '/';
+ if (!is_dir($root_path . $dest_path))
+ mkdir($root_path . $dest_path);
+ $dest_path .= 'EX' . $form_state['values']['example_number'] . '/';
+ if (!is_dir($root_path . $dest_path))
+ 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)",
+ $chapter_id,
+ $form_state['values']['example_number'],
+ $form_state['values']['example_caption'],
+ 0,
+ time()
+ );
+ $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)
- {
- if ($row > 0)
- {
- /* insterting into database */
-
- /*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)
+ $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)
+ {
+ if ($row > 0)
+ {
+ /* insterting into database */
+ /*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));
- }
- }
-
- /* uploading files */
- foreach ($_FILES['files']['name'] as $file_form_name => $file_name)
- {
- if ($file_name)
- {
- /* checking file type */
- if (strstr($file_form_name, 'source'))
- $file_type = 'S';
- else if (strstr($file_form_name, 'result'))
- $file_type = 'R';
- else if (strstr($file_form_name, 'xcos'))
- $file_type = 'X';
- else
- $file_type = 'U';
-
- if (file_exists($root_path . $dest_path . $_FILES['files']['name'][$file_form_name]))
- {
- drupal_set_message(t("Error uploading file. File !filename already exists.", array('!filename' => $_FILES['files']['name'][$file_form_name])), 'error');
- return;
- }
-
- /* uploading file */
- 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)
- VALUES (%d, '%s', '%s', '%s', %d, '%s', %d)",
- $example_id,
- $_FILES['files']['name'][$file_form_name],
- $dest_path . $_FILES['files']['name'][$file_form_name],
- $_FILES['files']['type'][$file_form_name],
- $_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)
+ ":example_id" => $example_id,
+ ":dependency_id" => $row,
+ ":approval_status" => 0,
+ ":timestamp" => time()
+ );
+ $result = db_query($query, $args, array(
+ 'return' => Database::RETURN_INSERT_ID
+ ));
+ } //$row > 0
+ } //$form_state['values']['existing_depfile']['dep_chapter_example_files'] as $row
+ /* uploading files */
+ foreach ($_FILES['files']['name'] as $file_form_name => $file_name)
+ {
+ if ($file_name)
+ {
+ /* checking file type */
+ if (strstr($file_form_name, 'source'))
+ $file_type = 'S';
+ else if (strstr($file_form_name, 'result'))
+ $file_type = 'R';
+ else if (strstr($file_form_name, 'xcos'))
+ $file_type = 'X';
+ else
+ $file_type = 'U';
+ if (file_exists($root_path . $dest_path . $_FILES['files']['name'][$file_form_name]))
+ {
+ drupal_set_message(t("Error uploading file. File !filename already exists.", array(
+ '!filename' => $_FILES['files']['name'][$file_form_name]
+ )), 'error');
+ return;
+ } //file_exists($root_path . $dest_path . $_FILES['files']['name'][$file_form_name])
+ /* uploading file */
+ 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)
+ VALUES (%d, '%s', '%s', '%s', %d, '%s', %d)",
+ $example_id,
+ $_FILES['files']['name'][$file_form_name],
+ $dest_path . $_FILES['files']['name'][$file_form_name],
+ $_FILES['files']['type'][$file_form_name],
+ $_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(),
+ $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');
- }
- }
- }
- drupal_set_message('Example uploaded successfully.', 'status');
-
- /* sending email */
- $email_to = $user->mail;
- $from = variable_get('textbook_companion_from_email', '');
- $bcc= variable_get('textbook_companion_emails', '');
- $cc=variable_get('textbook_companion_cc_emails', '');
- $params['example_uploaded']['example_id'] = $example_id;
- $params['example_uploaded']['user_id'] = $user->uid;
- $params['example_uploaded']['headers']=array('From'=>$from,'MIME-Version'=> '1.0',
- 'Content-Type'=> 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
- 'Content-Transfer-Encoding' => '8Bit',
- 'X-Mailer'=> 'Drupal','Cc' => $cc, 'Bcc' => $bcc);
-
- if (!drupal_mail('textbook_companion', 'example_uploaded', $email_to, language_default(), $params, $from, TRUE))
- drupal_set_message('Error sending email message.', 'error');
-
- drupal_goto('textbook_companion/code');
+ $result = db_query($query, $args, array(
+ 'return' => Database::RETURN_INSERT_ID
+ ));
+ drupal_set_message($file_name . ' uploaded successfully.', 'status');
+ } //move_uploaded_file($_FILES['files']['tmp_name'][$file_form_name], $root_path . $dest_path . $_FILES['files']['name'][$file_form_name])
+ else
+ {
+ drupal_set_message('Error uploading file : ' . $dest_path . '/' . $file_name, 'error');
+ }
+ } //$file_name
+ } //$_FILES['files']['name'] as $file_form_name => $file_name
+ drupal_set_message('Example uploaded successfully.', 'status');
+ /* sending email */
+ $email_to = $user->mail;
+ $from = variable_get('textbook_companion_from_email', '');
+ $bcc = variable_get('textbook_companion_emails', '');
+ $cc = variable_get('textbook_companion_cc_emails', '');
+ $params['example_uploaded']['example_id'] = $example_id;
+ $params['example_uploaded']['user_id'] = $user->uid;
+ $params['example_uploaded']['headers'] = array(
+ 'From' => $from,
+ 'MIME-Version' => '1.0',
+ 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
+ 'Content-Transfer-Encoding' => '8Bit',
+ 'X-Mailer' => 'Drupal',
+ 'Cc' => $cc,
+ 'Bcc' => $bcc
+ );
+ if (!drupal_mail('textbook_companion', 'example_uploaded', $email_to, language_default(), $params, $from, TRUE))
+ drupal_set_message('Error sending email message.', 'error');
+ drupal_goto('textbook_companion/code');
}
-
/******************************************************************************/
/***************************** DELETE EXAMPLE *********************************/
/******************************************************************************/
-
function _upload_examples_delete()
{
- global $user;
- $root_path = textbook_companion_path();
- $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);*/
+ global $user;
+ $root_path = textbook_companion_path();
+ $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);*/
$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');
- drupal_goto('textbook_companion/code');
- return;
- }
- if ($example_data->approval_status != 0)
- {
- drupal_set_message('You cannnot delete an example after it has been approved. Please contact site administrator if you want to delete this example.', 'error');
- drupal_goto('textbook_companion/code');
- 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);*/
+ $example_data = $result->fetchObject();
+ if (!$example_data)
+ {
+ drupal_set_message('Invalid example.', 'error');
+ drupal_goto('textbook_companion/code');
+ return;
+ } //!$example_data
+ if ($example_data->approval_status != 0)
+ {
+ drupal_set_message('You cannnot delete an example after it has been approved. Please contact site administrator if you want to delete this example.', 'error');
+ drupal_goto('textbook_companion/code');
+ return;
+ } //$example_data->approval_status != 0
+ /*$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->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');
- drupal_goto('textbook_companion/code');
- 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);*/
+ $chapter_data = $result->fetchObject();
+ if (!$chapter_data)
+ {
+ drupal_set_message('You do not have permission to delete this example.', 'error');
+ drupal_goto('textbook_companion/code');
+ return;
+ } //!$chapter_data
+ /*$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');
- drupal_goto('textbook_companion/code');
- 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);*/
-
+ $preference_data = $result->fetchObject();
+ if (!$preference_data)
+ {
+ drupal_set_message('You do not have permission to delete this example.', 'error');
+ drupal_goto('textbook_companion/code');
+ return;
+ } //!$preference_data
+ /*$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');
- drupal_goto('textbook_companion/code');
- return;
- }
-
- /* deleting example files */
- if (delete_example($example_data->id))
- {
- drupal_set_message('Example deleted.', 'status');
-
- /* sending email */
- $email_to = $user->mail;
- $from = variable_get('textbook_companion_from_email', '');
- $bcc= variable_get('textbook_companion_emails', '');
- $cc=variable_get('textbook_companion_cc_emails', '');
- $params['example_deleted_user']['book_title'] = $preference_data->book;
- $params['example_deleted_user']['chapter_title'] = $chapter_data->name;
- $params['example_deleted_user']['example_number'] = $example_data->number;
- $params['example_deleted_user']['example_caption'] = $example_data->caption;
- $params['example_deleted_user']['user_id'] = $user->uid;
- $params['example_deleted_user']['headers']=array('From'=>$from,'MIME-Version'=> '1.0',
- 'Content-Type'=> 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
- 'Content-Transfer-Encoding' => '8Bit',
- 'X-Mailer'=> 'Drupal','Cc' => $cc, 'Bcc' => $bcc);
-
- if (!drupal_mail('textbook_companion', 'example_deleted_user', $email_to, language_default(), $params, $from, TRUE))
- drupal_set_message('Error sending email message.', 'error');
- } else {
- drupal_set_message('Error deleting example.', 'status');
- }
-
- drupal_goto('textbook_companion/code');
- return;
+ $proposal_data = $result->fetchObject();
+ if (!$proposal_data)
+ {
+ drupal_set_message('You do not have permission to delete this example.', 'error');
+ drupal_goto('textbook_companion/code');
+ return;
+ } //!$proposal_data
+ /* deleting example files */
+ if (delete_example($example_data->id))
+ {
+ drupal_set_message('Example deleted.', 'status');
+ /* sending email */
+ $email_to = $user->mail;
+ $from = variable_get('textbook_companion_from_email', '');
+ $bcc = variable_get('textbook_companion_emails', '');
+ $cc = variable_get('textbook_companion_cc_emails', '');
+ $params['example_deleted_user']['book_title'] = $preference_data->book;
+ $params['example_deleted_user']['chapter_title'] = $chapter_data->name;
+ $params['example_deleted_user']['example_number'] = $example_data->number;
+ $params['example_deleted_user']['example_caption'] = $example_data->caption;
+ $params['example_deleted_user']['user_id'] = $user->uid;
+ $params['example_deleted_user']['headers'] = array(
+ 'From' => $from,
+ 'MIME-Version' => '1.0',
+ 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
+ 'Content-Transfer-Encoding' => '8Bit',
+ 'X-Mailer' => 'Drupal',
+ 'Cc' => $cc,
+ 'Bcc' => $bcc
+ );
+ if (!drupal_mail('textbook_companion', 'example_deleted_user', $email_to, language_default(), $params, $from, TRUE))
+ drupal_set_message('Error sending email message.', 'error');
+ } //delete_example($example_data->id)
+ else
+ {
+ drupal_set_message('Error deleting example.', 'status');
+ }
+ drupal_goto('textbook_companion/code');
+ return;
}
-
/******************************************************************************/
/************************** GENERAL FUNCTIONS *********************************/
/******************************************************************************/
-
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");*/
-
+ $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");*/
$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;
+ while ($book_titles_data = $book_titles_q->fetchObject())
+ {
+ $book_titles[$book_titles_data->id] = $book_titles_data->book . ' (Written by ' . $book_titles_data->author . ')';
+ } //$book_titles_data = $book_titles_q->fetchObject()
+ return $book_titles;
}
-
function _list_of_book_dependency_files($book_id)
{
- global $user;
- $book_dependency_files = array();
- $book_dependency_files_class = array();
-
- $query = db_select('textbook_companion_dependency_files');
- $query->fields('textbook_companion_dependency_files');
- $query->condition('preference_id', $book_id);
- $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){
- $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);
+ global $user;
+ $book_dependency_files = array();
+ $book_dependency_files_class = array();
+ $query = db_select('textbook_companion_dependency_files');
+ $query->fields('textbook_companion_dependency_files');
+ $query->condition('preference_id', $book_id);
+ $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)
+ {
+ $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;
+ } //$book_dependency_files_data->caption
+ } //$book_dependency_files_data = $book_dependency_files_q->fetchObject()
+ return array(
+ $book_dependency_files,
+ $book_dependency_files_class
+ );
}
-
diff --git a/code_approval.inc b/code_approval.inc
index a86c1ea..d315228 100755
--- a/code_approval.inc
+++ b/code_approval.inc
@@ -1,1044 +1,1064 @@
<?php
// $Id$
-
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");*/
-
+ /* 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");*/
$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->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 = $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);*/
-
- $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);*/
-
- $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));
- }
-
- /* check if there are any pending proposals */
- if (!$rows)
- {
- drupal_set_message(t('There are no pending proposals'), 'status');
- return '';
- }
-
- $header = array('Title of the Book', 'Chapter Number', 'Title of the Chapter', 'Contributor Name', 'Actions');
- $output = theme('table',array('header'=>$header,'rows'=>$rows));
- return $output;
+ if (!$pending_chapter_q)
+ {
+ drupal_set_message(t('There are no pending code approvals.'), 'status');
+ return '';
+ } //!$pending_chapter_q
+ $rows = array();
+ 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);*/
+ $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);*/
+ $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)
+ );
+ } //$row = $pending_chapter_q->fetchObject()
+ /* check if there are any pending proposals */
+ if (!$rows)
+ {
+ drupal_set_message(t('There are no pending proposals'), 'status');
+ return '';
+ } //!$rows
+ $header = array(
+ 'Title of the Book',
+ 'Chapter Number',
+ 'Title of the Chapter',
+ 'Contributor Name',
+ 'Actions'
+ );
+ $output = theme('table', array(
+ 'header' => $header,
+ 'rows' => $rows
+ ));
+ return $output;
}
-
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);*/
-
+ /* 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);*/
$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);*/
-
- $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);*/
-
- $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');
- return;
- }
-
- $form['#tree'] = TRUE;
-
- $form['contributor'] = array(
- '#type' => 'item',
- '#markup' => $proposal_data->full_name,
- '#title' => t('Contributor Name'),
- );
-
- $form['book_details']['book'] = array(
- '#type' => 'item',
- '#markup' => $preference_data->book,
- '#title' => t('Title of the Book'),
- );
-
- $form['book_details']['number'] = array(
- '#type' => 'item',
- '#markup' => $pending_chapter_data->number,
- '#title' => t('Chapter Number'),
- );
-
- $form['book_details']['name'] = array(
- '#type' => 'item',
- '#markup' => $pending_chapter_data->name,
- '#title' => t('Title of the Chapter'),
- );
-
- $form['book_details']['back_to_list'] = array(
- '#type' => 'item',
- '#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);*/
-
+ 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);*/
+ $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);*/
+ $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();
+ } //$pending_chapter_data = $pending_chapter_q->fetchObject()
+ else
+ {
+ drupal_set_message(t('Invalid chapter selected.'), 'error');
+ drupal_goto('code_approval');
+ return;
+ }
+ $form['#tree'] = TRUE;
+ $form['contributor'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->full_name,
+ '#title' => t('Contributor Name')
+ );
+ $form['book_details']['book'] = array(
+ '#type' => 'item',
+ '#markup' => $preference_data->book,
+ '#title' => t('Title of the Book')
+ );
+ $form['book_details']['number'] = array(
+ '#type' => 'item',
+ '#markup' => $pending_chapter_data->number,
+ '#title' => t('Chapter Number')
+ );
+ $form['book_details']['name'] = array(
+ '#type' => 'item',
+ '#markup' => $pending_chapter_data->name,
+ '#title' => t('Title of the Chapter')
+ );
+ $form['book_details']['back_to_list'] = array(
+ '#type' => 'item',
+ '#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);*/
$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',
- '#collapsible' => FALSE,
- '#collapsed' => TRUE,
- );
- $form['example_details'][$example_data->id]['example_number'] = array(
- '#type' => 'item',
- '#markup' => $example_data->number,
- '#title' => t('Example Number'),
- );
-
- $form['example_details'][$example_data->id]['example_caption'] = array(
- '#type' => 'item',
- '#markup' => $example_data->caption,
- '#title' => t('Example Caption'),
- );
-
- $form['example_details'][$example_data->id]['download'] = array(
- '#type' => 'markup',
- '#markup' => l('Download Example', 'download/example/' . $example_data->id),
- );
-
- $form['example_details'][$example_data->id]['approved'] = array(
- '#type' => 'radios',
- '#options' => array('Approved', 'Dis-approved'),
- );
-
- $form['example_details'][$example_data->id]['message'] = array(
- '#type' => 'textfield',
- '#title' => t('Reason for dis-approval'),
- );
-
- $form['example_details'][$example_data->id]['example_id'] = array(
- '#type' => 'hidden',
- '#value' => $example_data->id,
- );
- }
-
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Submit')
- );
- return $form;
+ while ($example_data = $example_q->fetchObject())
+ {
+ $form['example_details'][$example_data->id] = array(
+ '#type' => 'fieldset',
+ '#collapsible' => FALSE,
+ '#collapsed' => TRUE
+ );
+ $form['example_details'][$example_data->id]['example_number'] = array(
+ '#type' => 'item',
+ '#markup' => $example_data->number,
+ '#title' => t('Example Number')
+ );
+ $form['example_details'][$example_data->id]['example_caption'] = array(
+ '#type' => 'item',
+ '#markup' => $example_data->caption,
+ '#title' => t('Example Caption')
+ );
+ $form['example_details'][$example_data->id]['download'] = array(
+ '#type' => 'markup',
+ '#markup' => l('Download Example', 'download/example/' . $example_data->id)
+ );
+ $form['example_details'][$example_data->id]['approved'] = array(
+ '#type' => 'radios',
+ '#options' => array(
+ 'Approved',
+ 'Dis-approved'
+ )
+ );
+ $form['example_details'][$example_data->id]['message'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Reason for dis-approval')
+ );
+ $form['example_details'][$example_data->id]['example_id'] = array(
+ '#type' => 'hidden',
+ '#value' => $example_data->id
+ );
+ } //$example_data = $example_q->fetchObject()
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit')
+ );
+ return $form;
}
-
function code_approval_form_submit($form, &$form_state)
{
- global $user;
-
- 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);*/
- $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']);*/
-
- $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;
- $from = variable_get('textbook_companion_from_email', '');
- $bcc= variable_get('textbook_companion_emails', '');
- $cc=variable_get('textbook_companion_cc_emails', '');
- $params['example_approved']['example_id'] = $ex_data['example_id'];
- $params['example_approved']['user_id'] = $user_data->uid;
- $params['example_approved']['headers']=array('From'=>$from,'MIME-Version'=> '1.0',
- 'Content-Type'=> 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
- 'Content-Transfer-Encoding' => '8Bit',
- 'X-Mailer'=> 'Drupal','Cc' => $cc, 'Bcc' => $bcc);
-
- if (!drupal_mail('textbook_companion', 'example_approved', $email_to, language_default(), $params, $from, TRUE))
- drupal_set_message('Error sending email message.', 'error');
-
- } else if ($ex_data['approved'] == "1") {
- if (delete_example($ex_data['example_id']))
- {
- /* sending email */
- $email_to = $user_data->mail;
- $from = variable_get('textbook_companion_from_email', '');
- $bcc= variable_get('textbook_companion_emails', '');
- $cc=variable_get('textbook_companion_cc_emails', '');
- $params['example_disapproved']['preference_id'] = $chapter_data->preference_id;
- $params['example_disapproved']['chapter_id'] = $example_data->chapter_id;
- $params['example_disapproved']['example_number'] = $example_data->number;
- $params['example_disapproved']['example_caption'] = $example_data->caption;
- $params['example_disapproved']['user_id'] = $user_data->uid;
- $params['example_disapproved']['message'] = $ex_data['message'];
- $params['example_disapproved']['headers']=array('From'=>$from,'MIME-Version'=> '1.0',
- 'Content-Type'=> 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
- 'Content-Transfer-Encoding' => '8Bit',
- 'X-Mailer'=> 'Drupal','Cc' => $cc, 'Bcc' => $bcc);
-
- if (!drupal_mail('textbook_companion', 'example_disapproved', $email_to, language_default(), $params, $from, TRUE))
- drupal_set_message('Error sending email message.', 'error');
- } else {
- drupal_set_message('Error disapproving and deleting example. Please contact administrator.', 'error');
- }
- }
- }
- drupal_set_message('Updated successfully.', 'status');
- drupal_goto('code_approval');
+ global $user;
+ 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);*/
+ $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']);*/
+ $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;
+ $from = variable_get('textbook_companion_from_email', '');
+ $bcc = variable_get('textbook_companion_emails', '');
+ $cc = variable_get('textbook_companion_cc_emails', '');
+ $params['example_approved']['example_id'] = $ex_data['example_id'];
+ $params['example_approved']['user_id'] = $user_data->uid;
+ $params['example_approved']['headers'] = array(
+ 'From' => $from,
+ 'MIME-Version' => '1.0',
+ 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
+ 'Content-Transfer-Encoding' => '8Bit',
+ 'X-Mailer' => 'Drupal',
+ 'Cc' => $cc,
+ 'Bcc' => $bcc
+ );
+ if (!drupal_mail('textbook_companion', 'example_approved', $email_to, language_default(), $params, $from, TRUE))
+ drupal_set_message('Error sending email message.', 'error');
+ } //$ex_data['approved'] == "0"
+ else if ($ex_data['approved'] == "1")
+ {
+ if (delete_example($ex_data['example_id']))
+ {
+ /* sending email */
+ $email_to = $user_data->mail;
+ $from = variable_get('textbook_companion_from_email', '');
+ $bcc = variable_get('textbook_companion_emails', '');
+ $cc = variable_get('textbook_companion_cc_emails', '');
+ $params['example_disapproved']['preference_id'] = $chapter_data->preference_id;
+ $params['example_disapproved']['chapter_id'] = $example_data->chapter_id;
+ $params['example_disapproved']['example_number'] = $example_data->number;
+ $params['example_disapproved']['example_caption'] = $example_data->caption;
+ $params['example_disapproved']['user_id'] = $user_data->uid;
+ $params['example_disapproved']['message'] = $ex_data['message'];
+ $params['example_disapproved']['headers'] = array(
+ 'From' => $from,
+ 'MIME-Version' => '1.0',
+ 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
+ 'Content-Transfer-Encoding' => '8Bit',
+ 'X-Mailer' => 'Drupal',
+ 'Cc' => $cc,
+ 'Bcc' => $bcc
+ );
+ if (!drupal_mail('textbook_companion', 'example_disapproved', $email_to, language_default(), $params, $from, TRUE))
+ drupal_set_message('Error sending email message.', 'error');
+ } //delete_example($ex_data['example_id'])
+ else
+ {
+ drupal_set_message('Error disapproving and deleting example. Please contact administrator.', 'error');
+ }
+ } //$ex_data['approved'] == "1"
+ } //$form_state['values']['example_details'] as $ex_id => $ex_data
+ drupal_set_message('Updated successfully.', 'status');
+ drupal_goto('code_approval');
}
-
-
-
/******************************************************************************/
/********************************* BULK APPROVAL ******************************/
/******************************************************************************/
-
-function bulk_approval_form($form,$form_state)
+function bulk_approval_form($form, $form_state)
{
$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',
- '#markup' => '<div id="ajax_selected_book"></div>',
- );
- $form['download_pdf'] = array(
- '#type' => 'item',
- '#markup' => '<div id="ajax_selected_book_pdf"></div>',
- );
- $form['regenrate_book'] = array(
- '#type' => 'item',
- '#markup' => '<div id="ajax_selected_book_regenerate_pdf"></div>',
- );
- $form['notes_book'] = array(
- '#type' => 'item',
- '#markup' => '<div id="ajax_selected_book_notes"></div>',
- );
-
- $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' => _ajax_bulk_get_chapter_list($selected),
- //'#default_value' => $chapter_default_value,
- '#prefix' => '<div id="ajax_select_chapter_list">',
+ $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',
+ '#markup' => '<div id="ajax_selected_book"></div>'
+ );
+ $form['download_pdf'] = array(
+ '#type' => 'item',
+ '#markup' => '<div id="ajax_selected_book_pdf"></div>'
+ );
+ $form['regenrate_book'] = array(
+ '#type' => 'item',
+ '#markup' => '<div id="ajax_selected_book_regenerate_pdf"></div>'
+ );
+ $form['notes_book'] = array(
+ '#type' => 'item',
+ '#markup' => '<div id="ajax_selected_book_notes"></div>'
+ );
+ $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' => _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),),),
- );
-
- $form['download_chapter'] = array(
- '#type' => 'item',
- '#markup' => '<div id="ajax_download_chapter"></div>',
- );
-
- $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' => _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',
- ),
- );
-
- $form['download_example'] = array(
- '#type' => 'item',
- '#markup' => '<div id="ajax_download_selected_example"></div>',
- );
- $form['edit_example'] = array(
- '#type' => 'item',
- '#markup' => '<div id="ajax_edit_selected_example"></div>',
- );
-
- $form['example_files'] = array(
- '#type' => 'item',
- '#markup' => '',
- '#prefix' => '<div id="ajax_example_files_list">',
- '#suffix' => '</div>',
-
- );
-
- $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['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Submit'),
- '#validate' => array('bulk_approval_submit_validate'),
- '#states' => array('invisible' => array(':input[name="book"]' => array('value' => 0),),),
- );
-
-
- return $form;
+ // '#tree' => TRUE,
+ '#ajax' => array(
+ 'callback' => 'ajax_bulk_example_list_callback'
+ ),
+ '#states' => array(
+ 'invisible' => array(
+ ':input[name="book"]' => array(
+ 'value' => 0
+ )
+ )
+ )
+ );
+ $form['download_chapter'] = array(
+ '#type' => 'item',
+ '#markup' => '<div id="ajax_download_chapter"></div>'
+ );
+ $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' => _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'
+ )
+ );
+ $form['download_example'] = array(
+ '#type' => 'item',
+ '#markup' => '<div id="ajax_download_selected_example"></div>'
+ );
+ $form['edit_example'] = array(
+ '#type' => 'item',
+ '#markup' => '<div id="ajax_edit_selected_example"></div>'
+ );
+ $form['example_files'] = array(
+ '#type' => 'item',
+ '#markup' => '',
+ '#prefix' => '<div id="ajax_example_files_list">',
+ '#suffix' => '</div>'
+ );
+ $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['submit'] = array(
+ '#type' => '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_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']['book'])
del_book_pdf($form_state['values']['book']);
-
if (user_access('bulk manage code'))
{
- 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']['book']);*/
-
+ 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']['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);*/
-
- $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 = array(0=> t('Your all the uploaded examples for the book have been approved.'));
-
- } 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']['book']);*/
+ 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);*/
+ $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();
+ } //$chapter_data = $chapter_q->fetchObject()
+ drupal_set_message(t('Approved Entire Book.'), 'status');
+ /* email */
+ $email_subject = t('Your uploaded examples have been approved');
+ $email_body = array(
+ 0 => t('Your all the uploaded examples for the book have been approved.')
+ );
+ } //($form_state['values']['book_actions'] == 1) && ($form_state['values']['chapter_actions'] == 0) && ($form_state['values']['example_actions'] == 0)
+ 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']['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);*/
+ while ($chapter_data = $chapter_q->fetchObject())
+ {
+ /*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,
+ '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 = 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']['book_actions'] == 3) && ($form_state['values']['chapter_actions']== 0) && ($form_state['values']['example_actions'] == 0)) {
-
+ } //$chapter_data = $chapter_q->fetchObject()
+ drupal_set_message(t('Pending Review Entire Book.'), 'status');
+ /* email */
+ $email_subject = t('Your uploaded examples have been marked as pending');
+ $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.')
+ );
+ } //($form_state['values']['book_actions'] == 2) && ($form_state['values']['chapter_actions'] == 0) && ($form_state['values']['example_actions'] == 0)
+ 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'))
- {
- drupal_set_message(t('You do not have permission to Bulk Dis-Approved and Deleted Entire Book.'), 'error');
- return;
- }
-
- if (delete_book($form_state['values']['book']))
- {
- drupal_set_message(t('Dis-Approved and Deleted Entire Book.'), 'status');
- } else {
- drupal_set_message(t('Error Dis-Approving and Deleting Entire Book.'), 'error');
- }
-
- /* email */
- $email_subject = t('Your uploaded examples 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.
+ {
+ drupal_set_message(t('You do not have permission to Bulk Dis-Approved and Deleted Entire Book.'), 'error');
+ return;
+ } //!user_access('bulk delete code')
+ if (delete_book($form_state['values']['book']))
+ {
+ drupal_set_message(t('Dis-Approved and Deleted Entire Book.'), 'status');
+ } //delete_book($form_state['values']['book'])
+ else
+ {
+ drupal_set_message(t('Error Dis-Approving and Deleting Entire Book.'), 'error');
+ }
+ /* email */
+ $email_subject = t('Your uploaded examples 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']['message']));
-
- } 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'))
- {
- drupal_set_message(t('You do not have permission to Bulk Delete Entire Book Including Proposal.'), 'error');
- return;
- }
-
- /* check if dependency files are present */
- /*$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');
+' . $form_state['values']['message'])
+ );
+ } //($form_state['values']['book_actions'] == 3) && ($form_state['values']['chapter_actions'] == 0) && ($form_state['values']['example_actions'] == 0)
+ 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'))
+ {
+ drupal_set_message(t('You do not have permission to Bulk Delete Entire Book Including Proposal.'), 'error');
+ return;
+ } //!user_access('bulk delete code')
+ /* check if dependency files are present */
+ /*$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']['book']))
- {
- drupal_set_message(t('Dis-Approved and Deleted Entire Book examples.'), 'status');
-
- $dir_path = $root_path . $form_state['values']['book'];
- if (is_dir($dir_path))
- {
- $res = rmdir($dir_path);
- if (!$res)
- {
- drupal_set_message(t("Cannot delete Book directory : " . $dir_path . ". Please contact administrator."), 'error');
- return;
- }
- } else {
- drupal_set_message(t("Book directory not present : " . $dir_path . ". Skipping deleting book directory."), 'status');
- }
-
- /* deleting preference and proposal */
- /*$preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d", $form_state['values']['book']);
- $preference_data = db_fetch_object($preference_q);
-*/
-
+
+ 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']['book']))
+ {
+ drupal_set_message(t('Dis-Approved and Deleted Entire Book examples.'), 'status');
+ $dir_path = $root_path . $form_state['values']['book'];
+ if (is_dir($dir_path))
+ {
+ $res = rmdir($dir_path);
+ if (!$res)
+ {
+ drupal_set_message(t("Cannot delete Book directory : " . $dir_path . ". Please contact administrator."), 'error');
+ return;
+ } //!$res
+ } //is_dir($dir_path)
+ else
+ {
+ drupal_set_message(t("Book directory not present : " . $dir_path . ". Skipping deleting book directory."), 'status');
+ }
+ /* deleting preference and proposal */
+ /*$preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d", $form_state['values']['book']);
+ $preference_data = db_fetch_object($preference_q);
+ */
$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);*/
+ $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);*/
+ /*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');
-
- /* email */
- $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.
+ drupal_set_message(t('Deleted Book Proposal.'), 'status');
+ /* email */
+ $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']['message']));
-
- } else {
- drupal_set_message(t('Error Dis-Approving and Deleting Entire Book.'), 'error');
- }
-
- } 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']);*/
-
+' . $form_state['values']['message'])
+ );
+ } //delete_book($form_state['values']['book'])
+ else
+ {
+ drupal_set_message(t('Error Dis-Approving and Deleting Entire Book.'), 'error');
+ }
+ } //($form_state['values']['book_actions'] == 4) && ($form_state['values']['chapter_actions'] == 0) && ($form_state['values']['example_actions'] == 0)
+ 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,
- ));
+ 'approval_status' => 1,
+ 'approver_uid' => $user->uid
+ ));
$query->condition('chapter_id', $form_state['values']['chapter']);
$query->condition('approval_status', 0);
$num_updated = $query->execute();
-
- drupal_set_message(t('Approved Entire Chapter.'), 'status');
-
- /* email */
- $email_subject = t('Your uploaded examples 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)) {
-
- /*db_query("UPDATE {textbook_companion_example} SET approval_status = 0 WHERE chapter_id = %d", $form_state['values']['chapter']);*/
-
+ drupal_set_message(t('Approved Entire Chapter.'), 'status');
+ /* email */
+ $email_subject = t('Your uploaded examples have been approved');
+ $email_body = array(
+ 0 => t('Your all the uploaded examples for the chapter have been approved.')
+ );
+ } //($form_state['values']['book_actions'] == 0) && ($form_state['values']['chapter_actions'] == 1) && ($form_state['values']['example_actions'] == 0)
+ else if (($form_state['values']['book_actions'] == 0) && ($form_state['values']['chapter_actions'] == 2) && ($form_state['values']['example_actions'] == 0))
+ {
+ /*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,
+ 'approval_status' => 0
));
$query->condition('chapter_id', $form_state['values']['chapter']);
$num_updated = $query->execute();
-
- 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 = array(0 => t('Your all the uploaded examples for the chapter have been marked as pending to be review.'));
-
- } 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'))
- {
- drupal_set_message(t('You do not have permission to Bulk Dis-Approved and Deleted Entire Chapter.'), 'error');
- return;
- }
-
- if (delete_chapter($form_state['values']['chapter']))
- {
- drupal_set_message(t('Dis-Approved and Deleted Entire Chapter.'), 'status');
- } else {
- drupal_set_message(t('Error Dis-Approving and Deleting Entire Chapter.'), 'error');
- }
-
- /* email */
- $email_subject = t('Your uploaded example have been marked as dis-approved');
- $email_body = array(0 => t('Your uploaded example for the entire chapter have been marked as dis-approved.
+ 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 = array(
+ 0 => t('Your all the uploaded examples for the chapter have been marked as pending to be review.')
+ );
+ } //($form_state['values']['book_actions'] == 0) && ($form_state['values']['chapter_actions'] == 2) && ($form_state['values']['example_actions'] == 0)
+ 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'))
+ {
+ drupal_set_message(t('You do not have permission to Bulk Dis-Approved and Deleted Entire Chapter.'), 'error');
+ return;
+ } //!user_access('bulk delete code')
+ if (delete_chapter($form_state['values']['chapter']))
+ {
+ drupal_set_message(t('Dis-Approved and Deleted Entire Chapter.'), 'status');
+ } //delete_chapter($form_state['values']['chapter'])
+ else
+ {
+ drupal_set_message(t('Error Dis-Approving and Deleting Entire Chapter.'), 'error');
+ }
+ /* email */
+ $email_subject = t('Your uploaded example 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']['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']);*/
-
+' . $form_state['values']['message'])
+ );
+ } //($form_state['values']['book_actions'] == 0) && ($form_state['values']['chapter_actions'] == 3) && ($form_state['values']['example_actions'] == 0)
+ 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']);*/
$query = db_update('textbook_companion_example');
$query->fields(array(
- 'approval_status' => 1,
- 'approver_uid' => $user->uid,
+ 'approval_status' => 1,
+ 'approver_uid' => $user->uid
));
$query->condition('id', $form_state['values']['example']);
$num_updated = $query->execute();
-
- drupal_set_message(t('Example approved.'), 'status');
-
- /* email */
- $email_subject = t('Your uploaded example has been approved');
- $email_body = array(0 => t('Your uploaded example has been approved.'));
-
- } 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']);*/
-
+ drupal_set_message(t('Example approved.'), 'status');
+ /* email */
+ $email_subject = t('Your uploaded example has been approved');
+ $email_body = array(
+ 0 => t('Your uploaded example has been approved.')
+ );
+ } //($form_state['values']['book_actions'] == 0) && ($form_state['values']['chapter_actions'] == 0) && ($form_state['values']['example_actions'] == 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,
+ 'approval_status' => 0
));
$query->condition('id', $form_state['values']['example']);
$num_updated = $query->execute();
-
- drupal_set_message(t('Example marked as Pending Review.'), 'status');
-
- /* email */
- $email_subject = t('Your uploaded example has been marked as pending');
- $email_body = array( 0 => t('Your uploaded example has been marked as pending to be review.'));
-
- } 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']['example']))
- {
- drupal_set_message(t('Example Dis-Approved and Deleted.'), 'status');
- } else {
- drupal_set_message(t('Error Dis-Approving and Deleting Example.'), 'error');
- }
-
- /* email */
- $email_subject = t('Your uploaded example has been marked as dis-approved');
- $email_body = array(0 => t('Your uploaded example has been marked as dis-approved.
+ drupal_set_message(t('Example marked as Pending Review.'), 'status');
+ /* email */
+ $email_subject = t('Your uploaded example has been marked as pending');
+ $email_body = array(
+ 0 => t('Your uploaded example has been marked as pending to be review.')
+ );
+ } //($form_state['values']['book_actions'] == 0) && ($form_state['values']['chapter_actions'] == 0) && ($form_state['values']['example_actions'] == 2)
+ 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']['example']))
+ {
+ drupal_set_message(t('Example Dis-Approved and Deleted.'), 'status');
+ } //delete_example($form_state['values']['example'])
+ else
+ {
+ drupal_set_message(t('Error Dis-Approving and Deleting Example.'), 'error');
+ }
+ /* email */
+ $email_subject = 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']['message']));
-
- }
-
- /****** sending email when everything done ******/
- if ($email_subject)
- {
- $email_to = $user->mail;
- $params['standard']['subject'] = $email_subject;
- $params['standard']['body'] = $email_body;
- if (!drupal_mail('textbook_companion', 'standard', $email_to, language_default(), $params, variable_get('textbook_companion_from_email', NULL), TRUE))
- drupal_set_message('Error sending email message.', 'error');
- }
-
- } else {
- drupal_set_message(t('You do not have permission to bulk manage code.'), 'error');
- }
- }
+' . $form_state['values']['message'])
+ );
+ } //($form_state['values']['book_actions'] == 0) && ($form_state['values']['chapter_actions'] == 0) && ($form_state['values']['example_actions'] == 3)
+ /****** sending email when everything done ******/
+ if ($email_subject)
+ {
+ $email_to = $user->mail;
+ $params['standard']['subject'] = $email_subject;
+ $params['standard']['body'] = $email_body;
+ if (!drupal_mail('textbook_companion', 'standard', $email_to, language_default(), $params, variable_get('textbook_companion_from_email', NULL), TRUE))
+ drupal_set_message('Error sending email message.', 'error');
+ } //$email_subject
+ } //user_access('bulk manage code')
+ else
+ {
+ drupal_set_message(t('You do not have permission to bulk manage code.'), 'error');
+ }
+ } //$form_state['clicked_button']['#value'] == 'Submit'
}
-
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");*/
-
+ $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");*/
$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;
+ while ($book_titles_data = $book_titles_q->fetchObject())
+ {
+ $book_titles[$book_titles_data->id] = $book_titles_data->book . ' (Written by ' . $book_titles_data->author . ')';
+ } //$book_titles_data = $book_titles_q->fetchObject()
+ return $book_titles;
}
-
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);*/
+ $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;
+ while ($book_chapters_data = $book_chapters_q->fetchObject())
+ {
+ $book_chapters[$book_chapters_data->id] = $book_chapters_data->number . '. ' . $book_chapters_data->name;
+ } //$book_chapters_data = $book_chapters_q->fetchObject()
+ return $book_chapters;
}
-
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
- 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->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;
+ $book_examples = array(
+ '0' => 'Please select...'
+ );
+ /*$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);*/
+ $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 . ')';
+ } //$book_examples_data = $book_examples_q->fetchObject()
+ 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;
+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']));
+ } //$book_default_value > 0
+ 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']));
}
- /****************************** 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);
+ 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']));
+ } //$chapter_default_value > 0
+ 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', '');
}
-
- 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'] = '' ;
+ 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_list_data->filetype
+ $example_files_rows[] = array(
+ l($example_list_data->filename, 'download/file/' . $example_list_data->id),
+ $example_file_type
+ );
+ } //$example_list_data = $example_list_q->fetchObject()
+ /* 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
+ );
+ } //$dependency_list_data = $dependency_list_q->fetchObject()
+ /* 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', '' );
-
- }
- 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_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);
+ } //$example_list_q
+ } //$example_list_default_value > 0
+ 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', '');
}
- function ajax_bulk_chapter_actions_callback(){
+ 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);
-
-
- }
+ // $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/css/textbook_companion.css b/css/textbook_companion.css
index ae35e79..dc343ea 100644
--- a/css/textbook_companion.css
+++ b/css/textbook_companion.css
@@ -118,3 +118,8 @@ fieldset input[type="text"]
-o-border-radius: 5px;
border-radius: 5px;
}
+.book_prefrences{
+width:100%;
+margin-left:4%;
+margin-top: -3%;
+}
diff --git a/dependency.inc b/dependency.inc
index 5d6b3cc..960cd6f 100755
--- a/dependency.inc
+++ b/dependency.inc
@@ -1,887 +1,810 @@
<?php
// $Id$
-
-function upload_dependency_form($form,&$form_state)
+function upload_dependency_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);*/
-
+ 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);*/
$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', 'book_proposal') . ".", 'error');
- drupal_goto('');
- }
- if ($proposal_data->proposal_status != 1 && $proposal_data->proposal_status != 4)
- {
- 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');
- drupal_goto('');
- return;
- break;
- case 2:
- drupal_set_message(t('Your proposal has been dis-approved. Please create another proposal ' . l('here', 'book_proposal') . '.'), 'error');
- drupal_goto('');
- return;
- break;
- case 3:
- drupal_set_message(t('Congratulations! You have completed your last book proposal. You have to create another proposal ' . l('here', 'book_proposal') . '.'), 'status');
- drupal_goto('');
- return;
- break;
- default:
- drupal_set_message(t('Invalid proposal state. Please contact site administrator for further information.'), 'error');
- drupal_goto('');
- return;
- break;
- }
- }
-
- /*$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);*/
+ $proposal_data = $result->fetchObject();
+ if (!$proposal_data)
+ {
+ drupal_set_message("Please submit a " . l('proposal', 'book_proposal') . ".", 'error');
+ drupal_goto('');
+ } //!$proposal_data
+ if ($proposal_data->proposal_status != 1 && $proposal_data->proposal_status != 4)
+ {
+ 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');
+ drupal_goto('');
+ return;
+ break;
+ case 2:
+ drupal_set_message(t('Your proposal has been dis-approved. Please create another proposal ' . l('here', 'book_proposal') . '.'), 'error');
+ drupal_goto('');
+ return;
+ break;
+ case 3:
+ drupal_set_message(t('Congratulations! You have completed your last book proposal. You have to create another proposal ' . l('here', 'book_proposal') . '.'), 'status');
+ drupal_goto('');
+ return;
+ break;
+ default:
+ drupal_set_message(t('Invalid proposal state. Please contact site administrator for further information.'), 'error');
+ drupal_goto('');
+ return;
+ break;
+ } //$proposal_data->proposal_status
+ } //$proposal_data->proposal_status != 1 && $proposal_data->proposal_status != 4
+ /*$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');
- drupal_goto('');
- return;
- }
- /************************ end approve book details **************************/
-
- $form['#attributes'] = array('enctype' => "multipart/form-data");
-
- $form['book_details']['book'] = array(
- '#type' => 'item',
- '#markup' => $preference_data->book,
- '#title' => t('Title of the Book'),
- );
- $form['contributor_name'] = array(
- '#type' => 'item',
- '#markup' => $proposal_data->full_name,
- '#title' => t('Contributor Name'),
- );
-
- $form['existing_depfile'] = array(
- '#type' => 'item',
- '#markup' => _list_existing_dependency($preference_data->id),
- '#title' => t('List of existing dependency files for this book'),
- );
-
- $form['depfile'] = array(
- '#type' => 'fieldset',
- '#title' => t('Upload Dependency Files'),
- '#collapsible' => FALSE,
- '#collapsed' => FALSE,
- );
- $form['depfile']['depfile1'] = array(
- '#type' => 'file',
- '#title' => t('Upload dependency file'),
- '#description' => t("Allowed file extensions : ") . variable_get('textbook_companion_dependency_extensions', ''),
- );
- $form['depfile']['depfile1_caption'] = array(
- '#type' => 'textfield',
- '#title' => t('Caption for dependency file'),
- '#size' => 15,
- '#maxlength' => 100,
- '#required' => TRUE,
- );
- $form['depfile']['depfile1_description'] = array(
- '#type' => 'textarea',
- '#title' => t('Brief Description of the dependency file'),
- );
-
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Submit')
- );
-
- $form['cancel'] = array(
- '#type' => 'markup',
- '#value' => l(t('Back'), 'textbook_companion/code/upload'),
- );
- return $form;
+ $preference_data = $result->fetchObject();
+ if (!$preference_data)
+ {
+ drupal_set_message(t('Invalid Book Preference status. Please contact site administrator for further information.'), 'error');
+ drupal_goto('');
+ return;
+ } //!$preference_data
+ /************************ end approve book details **************************/
+ $form['#attributes'] = array(
+ 'enctype' => "multipart/form-data"
+ );
+ $form['book_details']['book'] = array(
+ '#type' => 'item',
+ '#markup' => $preference_data->book,
+ '#title' => t('Title of the Book')
+ );
+ $form['contributor_name'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->full_name,
+ '#title' => t('Contributor Name')
+ );
+ $form['existing_depfile'] = array(
+ '#type' => 'item',
+ '#markup' => _list_existing_dependency($preference_data->id),
+ '#title' => t('List of existing dependency files for this book')
+ );
+ $form['depfile'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Upload Dependency Files'),
+ '#collapsible' => FALSE,
+ '#collapsed' => FALSE
+ );
+ $form['depfile']['depfile1'] = array(
+ '#type' => 'file',
+ '#title' => t('Upload dependency file'),
+ '#description' => t("Allowed file extensions : ") . variable_get('textbook_companion_dependency_extensions', '')
+ );
+ $form['depfile']['depfile1_caption'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Caption for dependency file'),
+ '#size' => 15,
+ '#maxlength' => 100,
+ '#required' => TRUE
+ );
+ $form['depfile']['depfile1_description'] = array(
+ '#type' => 'textarea',
+ '#title' => t('Brief Description of the dependency file')
+ );
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit')
+ );
+ $form['cancel'] = array(
+ '#type' => 'markup',
+ '#value' => l(t('Back'), 'textbook_companion/code/upload')
+ );
+ return $form;
}
-
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);*/
-
+ 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);*/
$query = db_select('textbook_companion_proposal', 'pro');
- $query->fields('pro', array('id', 'full_name'));
- $query->fields('pre', array('id', 'book'));
+ $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']))
- {
- /* check for valid filename extensions */
- $allowed_extensions = explode(',' , variable_get('textbook_companion_dependency_extensions', ''));
- foreach ($_FILES['files']['name'] as $file_form_name => $file_name)
- {
- if ($file_name)
- {
- $temp_extension = end(explode('.', strtolower($_FILES['files']['name'][$file_form_name])));
- if (!in_array($temp_extension, $allowed_extensions))
- form_set_error($file_form_name, t('Only ' . variable_get('textbook_companion_dependency_extensions', '') . ' extensions can be uploaded.'));
- if ($_FILES['files']['size'][$file_form_name] <= 0)
- 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]));*/
-
- $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.'));
-
- /* check if valid file name */
- if (!textbook_companion_check_valid_filename($_FILES['files']['name'][$file_form_name]))
- form_set_error($file_form_name, t('Invalid file name specified. Only alphabets, numbers and underscore is allowed as a valid filename.'));
- }
- }
- }
+ $book_data = $result->fetchObject();
+ if (isset($_FILES['files']))
+ {
+ /* check for valid filename extensions */
+ $allowed_extensions = explode(',', variable_get('textbook_companion_dependency_extensions', ''));
+ foreach ($_FILES['files']['name'] as $file_form_name => $file_name)
+ {
+ if ($file_name)
+ {
+ $temp_extension = end(explode('.', strtolower($_FILES['files']['name'][$file_form_name])));
+ if (!in_array($temp_extension, $allowed_extensions))
+ form_set_error($file_form_name, t('Only ' . variable_get('textbook_companion_dependency_extensions', '') . ' extensions can be uploaded.'));
+ if ($_FILES['files']['size'][$file_form_name] <= 0)
+ 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]));*/
+ $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.'));
+ /* check if valid file name */
+ if (!textbook_companion_check_valid_filename($_FILES['files']['name'][$file_form_name]))
+ form_set_error($file_form_name, t('Invalid file name specified. Only alphabets, numbers and underscore is allowed as a valid filename.'));
+ } //$file_name
+ } //$_FILES['files']['name'] as $file_form_name => $file_name
+ } //isset($_FILES['files'])
}
-
-function upload_dependency_form_submit($form, &$form_state) {
- global $user;
-
- $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);*/
-
+function upload_dependency_form_submit($form, &$form_state)
+{
+ global $user;
+ $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);*/
$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', 'book_proposal') . ".", 'error');
- drupal_goto('');
- }
- if ($proposal_data->proposal_status != 1 && $proposal_data->proposal_status != 4)
- {
- 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');
- drupal_goto('');
- return;
- break;
- case 2:
- drupal_set_message(t('Your proposal has been dis-approved. Please create another proposal ' . l('here', 'book_proposal') . '.'), 'error');
- drupal_goto('');
- return;
- break;
- case 3:
- drupal_set_message(t('Congratulations! You have completed your last book proposal. You have to create another proposal ' . l('here', 'book_proposal') . '.'), 'status');
- drupal_goto('');
- return;
- break;
- default:
- drupal_set_message(t('Invalid proposal state. Please contact site administrator for further information.'), 'error');
- drupal_goto('');
- return;
- break;
- }
- }
-
- /*$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);*/
-
+ $proposal_data = $result->fetchObject();
+ if (!$proposal_data)
+ {
+ drupal_set_message("Please submit a " . l('proposal', 'book_proposal') . ".", 'error');
+ drupal_goto('');
+ } //!$proposal_data
+ if ($proposal_data->proposal_status != 1 && $proposal_data->proposal_status != 4)
+ {
+ 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');
+ drupal_goto('');
+ return;
+ break;
+ case 2:
+ drupal_set_message(t('Your proposal has been dis-approved. Please create another proposal ' . l('here', 'book_proposal') . '.'), 'error');
+ drupal_goto('');
+ return;
+ break;
+ case 3:
+ drupal_set_message(t('Congratulations! You have completed your last book proposal. You have to create another proposal ' . l('here', 'book_proposal') . '.'), 'status');
+ drupal_goto('');
+ return;
+ break;
+ default:
+ drupal_set_message(t('Invalid proposal state. Please contact site administrator for further information.'), 'error');
+ drupal_goto('');
+ return;
+ break;
+ } //$proposal_data->proposal_status
+ } //$proposal_data->proposal_status != 1 && $proposal_data->proposal_status != 4
+ /*$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');
- drupal_goto('');
- return;
- }
-
- $preference_id = $preference_data->id;
-
- $dest_path = $preference_id . '/';
- if (!is_dir($root_path . $dest_path))
- mkdir($root_path . $dest_path);
-
- $dest_path .= 'DEPENDENCIES' . '/';
- if (!is_dir($root_path . $dest_path))
- mkdir($root_path . $dest_path);
-
- /* uploading dependencies */
- $file_upload_counter = 0;
- $dependency_ids = array();
- $dependency_names = array();
-
- foreach ($_FILES['files']['name'] as $file_form_name => $file_name)
- {
- if ($file_name)
- {
- /* uploading file */
- 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)
- VALUES (%d, '%s', '%s', '%s', %d, '%s', '%s', %d)",
- $preference_id,
- $_FILES['files']['name'][$file_form_name],
- $dest_path . $_FILES['files']['name'][$file_form_name],
- $_FILES['files']['type'][$file_form_name],
- $_FILES['files']['size'][$file_form_name],
- $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)
+ $preference_data = $result->fetchObject();
+ if (!$preference_data)
+ {
+ drupal_set_message(t('Invalid Book Preference status. Please contact site administrator for further information.'), 'error');
+ drupal_goto('');
+ return;
+ } //!$preference_data
+ $preference_id = $preference_data->id;
+ $dest_path = $preference_id . '/';
+ if (!is_dir($root_path . $dest_path))
+ mkdir($root_path . $dest_path);
+ $dest_path .= 'DEPENDENCIES' . '/';
+ if (!is_dir($root_path . $dest_path))
+ mkdir($root_path . $dest_path);
+ /* uploading dependencies */
+ $file_upload_counter = 0;
+ $dependency_ids = array();
+ $dependency_names = array();
+ foreach ($_FILES['files']['name'] as $file_form_name => $file_name)
+ {
+ if ($file_name)
+ {
+ /* uploading file */
+ 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)
+ VALUES (%d, '%s', '%s', '%s', %d, '%s', '%s', %d)",
+ $preference_id,
+ $_FILES['files']['name'][$file_form_name],
+ $dest_path . $_FILES['files']['name'][$file_form_name],
+ $_FILES['files']['type'][$file_form_name],
+ $_FILES['files']['size'][$file_form_name],
+ $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(),
+ $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[]=$result;
-
- $dependency_names[] = $_FILES['files']['name'][$file_form_name];
- $file_upload_counter++;
- } else {
- drupal_set_message('Error uploading dependency : ' . $dest_path . '/' . $_FILES['files']['name'][$file_form_name], 'error');
- }
- }
- }
-
- if ($file_upload_counter > 0)
- {
- drupal_set_message('Dependencies uploaded successfully.', 'status');
-
- /* sending email */
- $params['dependency_uploaded']['user_id'] = $user->uid;
- $params['dependency_uploaded']['dependency_names'] = $dependency_names;
-
- $email_to = $user->mail;
- if (!drupal_mail('textbook_companion', 'dependency_uploaded', $email_to, language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE))
- drupal_set_message('Error sending email message.', 'error');
- }
-
- drupal_goto('textbook_companion/code/upload_dep');
+ $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[] = $result;
+ $dependency_names[] = $_FILES['files']['name'][$file_form_name];
+ $file_upload_counter++;
+ } //move_uploaded_file($_FILES['files']['tmp_name'][$file_form_name], $root_path . $dest_path . $_FILES['files']['name'][$file_form_name])
+ else
+ {
+ drupal_set_message('Error uploading dependency : ' . $dest_path . '/' . $_FILES['files']['name'][$file_form_name], 'error');
+ }
+ } //$file_name
+ } //$_FILES['files']['name'] as $file_form_name => $file_name
+ if ($file_upload_counter > 0)
+ {
+ drupal_set_message('Dependencies uploaded successfully.', 'status');
+ /* sending email */
+ $params['dependency_uploaded']['user_id'] = $user->uid;
+ $params['dependency_uploaded']['dependency_names'] = $dependency_names;
+ $email_to = $user->mail;
+ if (!drupal_mail('textbook_companion', 'dependency_uploaded', $email_to, language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE))
+ drupal_set_message('Error sending email message.', 'error');
+ } //$file_upload_counter > 0
+ drupal_goto('textbook_companion/code/upload_dep');
}
-
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);*/
-
+ // $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 = 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();
-
- $headers = array(
- "File", "Action",
- );
- $rows = array();
- while($row = $result->fetchObject()) {
- $item = array(
- l($row->filename . $temp_caption, 'download/dependency/' . $row->id),
- l("Edit", "textbook_companion/code/edit_dep/{$row->id}")
- . " | " . l("Delete","textbook_companion/code/delete_dep/{$row->id}")
- );
- array_push($rows, $item);
- }
- $return_html .= theme("table",array("headers"=>$headers, "rows"=>$rows));
- return $return_html;
+ $headers = array(
+ "File",
+ "Action"
+ );
+ $rows = array();
+ while ($row = $result->fetchObject())
+ {
+ $item = array(
+ l($row->filename . $temp_caption, 'download/dependency/' . $row->id),
+ l("Edit", "textbook_companion/code/edit_dep/{$row->id}") . " | " . l("Delete", "textbook_companion/code/delete_dep/{$row->id}")
+ );
+ array_push($rows, $item);
+ } //$row = $result->fetchObject()
+ $return_html .= theme("table", array(
+ "headers" => $headers,
+ "rows" => $rows
+ ));
+ return $return_html;
}
-
/******************** edit dependency section ********************/
-
-function edit_dependency_form($form_state, $dependency_id=0)
+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);*/
-
+ 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);*/
$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');
- drupal_goto('');
- }
- if ($proposal_data->proposal_status != 1 && $proposal_data->proposal_status != 4)
- {
- 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');
- drupal_goto('');
- return;
- break;
- case 2:
- drupal_set_message(t('Your proposal has been dis-approved. Please create another proposal ' . l('here', 'proposal') . '.'), 'error');
- drupal_goto('');
- return;
- break;
- case 3:
- drupal_set_message(t('Congratulations! You have completed your last book proposal. You have to create another proposal ' . l('here', 'proposal') . '.'), 'status');
- drupal_goto('');
- return;
- break;
- default:
- drupal_set_message(t('Invalid proposal state. Please contact site administrator for further information.'), 'error');
- drupal_goto('');
- return;
- break;
- }
- }
-
- /*$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);*/
-
+ $proposal_data = $result->fetchObject();
+ if (!$proposal_data)
+ {
+ drupal_set_message("Please submit a " . l('proposal', 'proposal') . ".", 'error');
+ drupal_goto('');
+ } //!$proposal_data
+ if ($proposal_data->proposal_status != 1 && $proposal_data->proposal_status != 4)
+ {
+ 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');
+ drupal_goto('');
+ return;
+ break;
+ case 2:
+ drupal_set_message(t('Your proposal has been dis-approved. Please create another proposal ' . l('here', 'proposal') . '.'), 'error');
+ drupal_goto('');
+ return;
+ break;
+ case 3:
+ drupal_set_message(t('Congratulations! You have completed your last book proposal. You have to create another proposal ' . l('here', 'proposal') . '.'), 'status');
+ drupal_goto('');
+ return;
+ break;
+ default:
+ drupal_set_message(t('Invalid proposal state. Please contact site administrator for further information.'), 'error');
+ drupal_goto('');
+ return;
+ break;
+ } //$proposal_data->proposal_status
+ } //$proposal_data->proposal_status != 1 && $proposal_data->proposal_status != 4
+ /*$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');
- drupal_goto('');
- return;
- }
- /************************ end approve book details **************************/
- /* fetching the default values */
-
- /*$query = "
- SELECT * FROM {textbook_companion_dependency_files}
- WHERE id = {$dependency_id}
- ";
- $result = db_query($query);
- $row = db_fetch_object($result);*/
-
+ $preference_data = $result->fetchObject();
+ if (!$preference_data)
+ {
+ drupal_set_message(t('Invalid Book Preference status. Please contact site administrator for further information.'), 'error');
+ drupal_goto('');
+ return;
+ } //!$preference_data
+ /************************ end approve book details **************************/
+ /* fetching the default values */
+ /*$query = "
+ SELECT * FROM {textbook_companion_dependency_files}
+ WHERE id = {$dependency_id}
+ ";
+ $result = db_query($query);
+ $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");
-
- $form['depfile'] = array(
- '#type' => 'fieldset',
- '#title' => t('Upload New Dependency File'),
- '#collapsible' => FALSE,
- '#collapsed' => FALSE,
- );
- $form['depfile']['depfile1'] = array(
- '#type' => 'file',
- '#title' => t('Upload dependency file'),
- '#description' => t("Allowed file extensions : ") . variable_get('textbook_companion_dependency_extensions', ''),
- );
- $form['depfile']['depfile1_caption'] = array(
- '#type' => 'textfield',
- '#title' => t('Caption for dependency file'),
- '#size' => 15,
- '#maxlength' => 100,
- '#required' => TRUE,
- "#default_value" => $row->caption,
- );
- $form['depfile']['depfile1_description'] = array(
- '#type' => 'textarea',
- '#title' => t('Brief Description of the dependency file'),
- "#default_value" => $row->description,
- );
-
- $form["dependency_id"] = array(
- "#type" => "hidden",
- "#value" => $dependency_id
- );
-
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Submit')
- );
-
- $form['cancel'] = array(
- '#type' => 'markup',
- '#value' => l(t('Back'), 'textbook_companion/code/upload_dep'),
- );
- return $form;
+ $row = $result->fetchObject();
+ $form['#attributes'] = array(
+ 'enctype' => "multipart/form-data"
+ );
+ $form['depfile'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Upload New Dependency File'),
+ '#collapsible' => FALSE,
+ '#collapsed' => FALSE
+ );
+ $form['depfile']['depfile1'] = array(
+ '#type' => 'file',
+ '#title' => t('Upload dependency file'),
+ '#description' => t("Allowed file extensions : ") . variable_get('textbook_companion_dependency_extensions', '')
+ );
+ $form['depfile']['depfile1_caption'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Caption for dependency file'),
+ '#size' => 15,
+ '#maxlength' => 100,
+ '#required' => TRUE,
+ "#default_value" => $row->caption
+ );
+ $form['depfile']['depfile1_description'] = array(
+ '#type' => 'textarea',
+ '#title' => t('Brief Description of the dependency file'),
+ "#default_value" => $row->description
+ );
+ $form["dependency_id"] = array(
+ "#type" => "hidden",
+ "#value" => $dependency_id
+ );
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit')
+ );
+ $form['cancel'] = array(
+ '#type' => 'markup',
+ '#value' => l(t('Back'), 'textbook_companion/code/upload_dep')
+ );
+ return $form;
}
-
function edit_dependency_form_validate($form, &$form_state)
{
- global $user;
-
- if (isset($_FILES['files']))
- {
- /* check for valid filename extensions */
- $allowed_extensions = explode(',' , variable_get('textbook_companion_dependency_extensions', ''));
- foreach ($_FILES['files']['name'] as $file_form_name => $file_name)
- {
- if ($file_name)
- {
- $temp_extension = end(explode('.', strtolower($_FILES['files']['name'][$file_form_name])));
- if (!in_array($temp_extension, $allowed_extensions))
- form_set_error($file_form_name, t('Only ' . variable_get('textbook_companion_dependency_extensions', '') . ' extensions can be uploaded.'));
- if ($_FILES['files']['size'][$file_form_name] <= 0)
- 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' 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.'));
-
- /* check if valid file name */
- if (!textbook_companion_check_valid_filename($_FILES['files']['name'][$file_form_name]))
- form_set_error($file_form_name, t('Invalid file name specified. Only alphabets, numbers and underscore is allowed as a valid filename.'));
- }
- }
- }
+ global $user;
+ if (isset($_FILES['files']))
+ {
+ /* check for valid filename extensions */
+ $allowed_extensions = explode(',', variable_get('textbook_companion_dependency_extensions', ''));
+ foreach ($_FILES['files']['name'] as $file_form_name => $file_name)
+ {
+ if ($file_name)
+ {
+ $temp_extension = end(explode('.', strtolower($_FILES['files']['name'][$file_form_name])));
+ if (!in_array($temp_extension, $allowed_extensions))
+ form_set_error($file_form_name, t('Only ' . variable_get('textbook_companion_dependency_extensions', '') . ' extensions can be uploaded.'));
+ if ($_FILES['files']['size'][$file_form_name] <= 0)
+ 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' 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.'));
+ /* check if valid file name */
+ if (!textbook_companion_check_valid_filename($_FILES['files']['name'][$file_form_name]))
+ form_set_error($file_form_name, t('Invalid file name specified. Only alphabets, numbers and underscore is allowed as a valid filename.'));
+ } //$file_name
+ } //$_FILES['files']['name'] as $file_form_name => $file_name
+ } //isset($_FILES['files'])
}
-
-function edit_dependency_form_submit($form, &$form_state) {
- global $user;
-
- $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);*/
-
+function edit_dependency_form_submit($form, &$form_state)
+{
+ global $user;
+ $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);*/
$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');
- drupal_goto('');
- }
- if ($proposal_data->proposal_status != 1 && $proposal_data->proposal_status != 4)
- {
- 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');
- drupal_goto('');
- return;
- break;
- case 2:
- drupal_set_message(t('Your proposal has been dis-approved. Please create another proposal ' . l('here', 'proposal') . '.'), 'error');
- drupal_goto('');
- return;
- break;
- case 3:
- drupal_set_message(t('Congratulations! You have completed your last book proposal. You have to create another proposal ' . l('here', 'proposal') . '.'), 'status');
- drupal_goto('');
- return;
- break;
- default:
- drupal_set_message(t('Invalid proposal state. Please contact site administrator for further information.'), 'error');
- drupal_goto('');
- return;
- break;
- }
- }
-
- /*$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);*/
-
+ $proposal_data = $result->fetchObject();
+ if (!$proposal_data)
+ {
+ drupal_set_message("Please submit a " . l('proposal', 'proposal') . ".", 'error');
+ drupal_goto('');
+ } //!$proposal_data
+ if ($proposal_data->proposal_status != 1 && $proposal_data->proposal_status != 4)
+ {
+ 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');
+ drupal_goto('');
+ return;
+ break;
+ case 2:
+ drupal_set_message(t('Your proposal has been dis-approved. Please create another proposal ' . l('here', 'proposal') . '.'), 'error');
+ drupal_goto('');
+ return;
+ break;
+ case 3:
+ drupal_set_message(t('Congratulations! You have completed your last book proposal. You have to create another proposal ' . l('here', 'proposal') . '.'), 'status');
+ drupal_goto('');
+ return;
+ break;
+ default:
+ drupal_set_message(t('Invalid proposal state. Please contact site administrator for further information.'), 'error');
+ drupal_goto('');
+ return;
+ break;
+ } //$proposal_data->proposal_status
+ } //$proposal_data->proposal_status != 1 && $proposal_data->proposal_status != 4
+ /*$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');
- drupal_goto('');
- return;
- }
-
- $preference_id = $preference_data->id;
-
- $dest_path = $preference_id . '/';
- if (!is_dir($root_path . $dest_path))
- mkdir($root_path . $dest_path);
-
- $dest_path .= 'DEPENDENCIES' . '/';
- if (!is_dir($root_path . $dest_path))
- mkdir($root_path . $dest_path);
-
- /* uploading dependencies */
- $file_upload_counter = 0;
- $dependency_ids = array();
- $dependency_names = array();
-
- /* deleting old dependency file if the filename changed */
-
- /*$query = "
- SELECT * FROM textbook_companion_dependency_files
- WHERE id = %d
- ";
- $result = db_query($query, $form_state["values"]["dependency_id"]);
- $row = db_fetch_object($result);*/
-
+ $preference_data = $result->fetchObject();
+ if (!$preference_data)
+ {
+ drupal_set_message(t('Invalid Book Preference status. Please contact site administrator for further information.'), 'error');
+ drupal_goto('');
+ return;
+ } //!$preference_data
+ $preference_id = $preference_data->id;
+ $dest_path = $preference_id . '/';
+ if (!is_dir($root_path . $dest_path))
+ mkdir($root_path . $dest_path);
+ $dest_path .= 'DEPENDENCIES' . '/';
+ if (!is_dir($root_path . $dest_path))
+ mkdir($root_path . $dest_path);
+ /* uploading dependencies */
+ $file_upload_counter = 0;
+ $dependency_ids = array();
+ $dependency_names = array();
+ /* deleting old dependency file if the filename changed */
+ /*$query = "
+ SELECT * FROM textbook_companion_dependency_files
+ WHERE id = %d
+ ";
+ $result = db_query($query, $form_state["values"]["dependency_id"]);
+ $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);
- }
-
- foreach ($_FILES['files']['name'] as $file_form_name => $file_name)
- {
- if ($file_name)
- {
- /*
- * uploading file
- * file will be overwritten if same name
- */
- 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(
- "UPDATE {textbook_companion_dependency_files} SET
- filename = '%s', filepath = '%s', filemime = '%s', filesize = %d,
- caption = '%s', description = '%s', timestamp = %s
- WHERE id = %d",
- $_FILES['files']['name'][$file_form_name],
- $dest_path . $_FILES['files']['name'][$file_form_name],
- $_FILES['files']['type'][$file_form_name],
- $_FILES['files']['size'][$file_form_name],
- $form_state['values'][$file_form_name . '_caption'],
- $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');
- $dependency_names[] = $_FILES['files']['name'][$file_form_name];
- $file_upload_counter++;
- } else {
- drupal_set_message('Error uploading dependency : ' . $dest_path . '/' . $_FILES['files']['name'][$file_form_name], 'error');
- }
- }
- }
-
- if ($file_upload_counter > 0)
- {
- drupal_set_message('Dependencies uploaded successfully.', 'status');
-
- /* sending email */
- $from = variable_get('textbook_companion_from_email', '');
- $bcc= variable_get('textbook_companion_emails', '');
- $cc=variable_get('textbook_companion_cc_emails', '');
- $params['dependency_uploaded']['user_id'] = $user->uid;
- $params['dependency_uploaded']['dependency_names'] = $dependency_names;
- $params['dependency_uploaded']['headers']=array('From'=>$from,'MIME-Version'=> '1.0',
- 'Content-Type'=> 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
- 'Content-Transfer-Encoding' => '8Bit',
- 'X-Mailer'=> 'Drupal','Cc' => $cc, 'Bcc' => $bcc);
-
- $email_to = $user->mail;
- if (!drupal_mail('textbook_companion', 'dependency_uploaded', $email_to, language_default(), $params, $from, TRUE))
- drupal_set_message('Error sending email message.', 'error');
- }
-
- drupal_goto('textbook_companion/code/upload_dep');
+ if ($row->filename != $_FILES["files"]["name"][$file_form_name] && $_FILES["files"]["name"][$file_form_name])
+ {
+ unlink($root_path . $dest_path . $row->filename);
+ } //$row->filename != $_FILES["files"]["name"][$file_form_name] && $_FILES["files"]["name"][$file_form_name]
+ foreach ($_FILES['files']['name'] as $file_form_name => $file_name)
+ {
+ if ($file_name)
+ {
+ /*
+ * uploading file
+ * file will be overwritten if same name
+ */
+ 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(
+ "UPDATE {textbook_companion_dependency_files} SET
+ filename = '%s', filepath = '%s', filemime = '%s', filesize = %d,
+ caption = '%s', description = '%s', timestamp = %s
+ WHERE id = %d",
+ $_FILES['files']['name'][$file_form_name],
+ $dest_path . $_FILES['files']['name'][$file_form_name],
+ $_FILES['files']['type'][$file_form_name],
+ $_FILES['files']['size'][$file_form_name],
+ $form_state['values'][$file_form_name . '_caption'],
+ $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');
+ $dependency_names[] = $_FILES['files']['name'][$file_form_name];
+ $file_upload_counter++;
+ } //move_uploaded_file($_FILES['files']['tmp_name'][$file_form_name], $root_path . $dest_path . $_FILES['files']['name'][$file_form_name])
+ else
+ {
+ drupal_set_message('Error uploading dependency : ' . $dest_path . '/' . $_FILES['files']['name'][$file_form_name], 'error');
+ }
+ } //$file_name
+ } //$_FILES['files']['name'] as $file_form_name => $file_name
+ if ($file_upload_counter > 0)
+ {
+ drupal_set_message('Dependencies uploaded successfully.', 'status');
+ /* sending email */
+ $from = variable_get('textbook_companion_from_email', '');
+ $bcc = variable_get('textbook_companion_emails', '');
+ $cc = variable_get('textbook_companion_cc_emails', '');
+ $params['dependency_uploaded']['user_id'] = $user->uid;
+ $params['dependency_uploaded']['dependency_names'] = $dependency_names;
+ $params['dependency_uploaded']['headers'] = array(
+ 'From' => $from,
+ 'MIME-Version' => '1.0',
+ 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
+ 'Content-Transfer-Encoding' => '8Bit',
+ 'X-Mailer' => 'Drupal',
+ 'Cc' => $cc,
+ 'Bcc' => $bcc
+ );
+ $email_to = $user->mail;
+ if (!drupal_mail('textbook_companion', 'dependency_uploaded', $email_to, language_default(), $params, $from, TRUE))
+ drupal_set_message('Error sending email message.', 'error');
+ } //$file_upload_counter > 0
+ drupal_goto('textbook_companion/code/upload_dep');
}
-
-function edit_dependency($dependency_id = 0) {
- if($dependency_id){
- $page_content = "";
- $page_content .= drupal_get_form("edit_dependency_form", $dependency_id);
- return $page_content;
- } else {
- drupal_goto("textbook_companion/code/upload_dep");
- }
+function edit_dependency($dependency_id = 0)
+{
+ if ($dependency_id)
+ {
+ $page_content = "";
+ $page_content .= drupal_get_form("edit_dependency_form", $dependency_id);
+ return $page_content;
+ } //$dependency_id
+ else
+ {
+ drupal_goto("textbook_companion/code/upload_dep");
+ }
}
-
/******************** delete dependency section ********************/
-
-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);*/
-
+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);*/
$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', 'book_proposal') . ".", 'error');
- drupal_goto('');
- }
- if ($proposal_data->proposal_status != 1 && $proposal_data->proposal_status != 4)
- {
- 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');
- drupal_goto('');
- return;
- break;
- case 2:
- drupal_set_message(t('Your proposal has been dis-approved. Please create another proposal ' . l('here', 'book_proposal') . '.'), 'error');
- drupal_goto('');
- return;
- break;
- case 3:
- drupal_set_message(t('Congratulations! You have completed your last book proposal. You have to create another proposal ' . l('here', 'book_proposal') . '.'), 'status');
- drupal_goto('');
- return;
- break;
- default:
- drupal_set_message(t('Invalid proposal state. Please contact site administrator for further information.'), 'error');
- drupal_goto('');
- return;
- break;
- }
- }
-
- /*$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);*/
-
+ $proposal_data = $result->fetchObject();
+ if (!$proposal_data)
+ {
+ drupal_set_message("Please submit a " . l('proposal', 'book_proposal') . ".", 'error');
+ drupal_goto('');
+ } //!$proposal_data
+ if ($proposal_data->proposal_status != 1 && $proposal_data->proposal_status != 4)
+ {
+ 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');
+ drupal_goto('');
+ return;
+ break;
+ case 2:
+ drupal_set_message(t('Your proposal has been dis-approved. Please create another proposal ' . l('here', 'book_proposal') . '.'), 'error');
+ drupal_goto('');
+ return;
+ break;
+ case 3:
+ drupal_set_message(t('Congratulations! You have completed your last book proposal. You have to create another proposal ' . l('here', 'book_proposal') . '.'), 'status');
+ drupal_goto('');
+ return;
+ break;
+ default:
+ drupal_set_message(t('Invalid proposal state. Please contact site administrator for further information.'), 'error');
+ drupal_goto('');
+ return;
+ break;
+ } //$proposal_data->proposal_status
+ } //$proposal_data->proposal_status != 1 && $proposal_data->proposal_status != 4
+ /*$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');
- drupal_goto('');
- return;
- }
- /************************ end approve book details **************************/
- $page_content = "";
- if($dependency_id && $confirm == "yes") {
- /* removing the dependency file from filesystem */
-
- /*$query = "
- SELECT * FROM {textbook_companion_dependency_files}
- WHERE id = {$dependency_id}
- ";
- $result = db_query($query);
- $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();
- $dest_path = $row->preference_id . '/';
- $dest_path .= 'DEPENDENCIES' . '/';
- unlink($root_path . $dest_path . $row->filename);
-
- /* deleting entry in textbook_companion_dependency_files */
-
- /*$query = "
- DELETE FROM {textbook_companion_dependency_files}
- WHERE id = {$dependency_id}
- ";
- 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 = "
- DELETE FROM {textbook_companion_example_dependency}
- WHERE dependency_id = {$dependency_id}
- ";
- 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");
- } else {
- drupal_set_message("Cannot delete other users dependency.", "error");
- drupal_goto("textbook_companion/code/upload_dep");
- }
- } else if($dependency_id) {
- /*$query = "
- SELECT * FROM {textbook_companion_dependency_files}
- WHERE id = %d
- ";
- $result = db_query($query, $dependency_id);
- $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) {
- $page_content .= "Are you sure you want to delete this dependency?<br><br>";
- $page_content .= "Dependency filename: <b>{$row->filename}</b><br><br>";
-
- /* fetching the examples linked to this dependency */
-
- /*$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);*/
-
- $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 = $result->fetchObject()) {
- $list .= "<li>Example {$row->number}</li>";
- }
- if($list) {
- $page_content .= "List of examples linking to this dependency are:";
- $page_content .= "<ul>{$list}</ul>";
- }
- $page_content .= l("Delete dependency", "textbook_companion/code/delete_dep/{$dependency_id}/yes");
- $page_content .= " | ";
- $page_content .= l("Cancel", "textbook_companion/code/upload_dep");
- } else {
- drupal_set_message("Cannot delete other users dependency.", "error");
- drupal_goto("textbook_companion/code/upload_dep");
- }
- } else {
- drupal_goto("textbook_companion/code/upload_dep");
- }
- return $page_content;
+ $preference_data = $result->fetchObject();
+ if (!$preference_data)
+ {
+ drupal_set_message(t('Invalid Book Preference status. Please contact site administrator for further information.'), 'error');
+ drupal_goto('');
+ return;
+ } //!$preference_data
+ /************************ end approve book details **************************/
+ $page_content = "";
+ if ($dependency_id && $confirm == "yes")
+ {
+ /* removing the dependency file from filesystem */
+ /*$query = "
+ SELECT * FROM {textbook_companion_dependency_files}
+ WHERE id = {$dependency_id}
+ ";
+ $result = db_query($query);
+ $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();
+ $dest_path = $row->preference_id . '/';
+ $dest_path .= 'DEPENDENCIES' . '/';
+ unlink($root_path . $dest_path . $row->filename);
+ /* deleting entry in textbook_companion_dependency_files */
+ /*$query = "
+ DELETE FROM {textbook_companion_dependency_files}
+ WHERE id = {$dependency_id}
+ ";
+ 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 = "
+ DELETE FROM {textbook_companion_example_dependency}
+ WHERE dependency_id = {$dependency_id}
+ ";
+ 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");
+ } //$preference_data->id == $row->preference_id
+ else
+ {
+ drupal_set_message("Cannot delete other users dependency.", "error");
+ drupal_goto("textbook_companion/code/upload_dep");
+ }
+ } //$dependency_id && $confirm == "yes"
+ else if ($dependency_id)
+ {
+ /*$query = "
+ SELECT * FROM {textbook_companion_dependency_files}
+ WHERE id = %d
+ ";
+ $result = db_query($query, $dependency_id);
+ $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)
+ {
+ $page_content .= "Are you sure you want to delete this dependency?<br><br>";
+ $page_content .= "Dependency filename: <b>{$row->filename}</b><br><br>";
+ /* fetching the examples linked to this dependency */
+ /*$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);*/
+ $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 = $result->fetchObject())
+ {
+ $list .= "<li>Example {$row->number}</li>";
+ } //$row = $result->fetchObject()
+ if ($list)
+ {
+ $page_content .= "List of examples linking to this dependency are:";
+ $page_content .= "<ul>{$list}</ul>";
+ } //$list
+ $page_content .= l("Delete dependency", "textbook_companion/code/delete_dep/{$dependency_id}/yes");
+ $page_content .= " | ";
+ $page_content .= l("Cancel", "textbook_companion/code/upload_dep");
+ } //$preference_data->id == $row->preference_id
+ else
+ {
+ drupal_set_message("Cannot delete other users dependency.", "error");
+ drupal_goto("textbook_companion/code/upload_dep");
+ }
+ } //$dependency_id
+ else
+ {
+ drupal_goto("textbook_companion/code/upload_dep");
+ }
+ return $page_content;
}
diff --git a/dependency_approval.inc b/dependency_approval.inc
index c2d8ab7..80bd261 100755
--- a/dependency_approval.inc
+++ b/dependency_approval.inc
@@ -1,262 +1,240 @@
<?php
-
/******************************************************************************/
/**************************** DEPNDENCY APPROVAL ******************************/
/******************************************************************************/
-
function textbook_companion_dependency_approval_form($form_state)
{
- // $form['#redirect'] = FALSE;
-
- // ahah_helper_register($form, $form_state);
-
- /* default value for ahah fields */
- // if (!isset($form_state['storage']['run']['dependency']))
- // {
- // $dependency_default_value = 0;
- // } else {
- // $dependency_default_value = $form_state['storage']['run']['dependency'];
- // }
-
- $form['run'] = array(
- '#type' => 'fieldset',
- '#title' => t('Manage Dependency'),
- '#collapsible' => FALSE,
- '#collapsed' => FALSE,
- '#prefix' => '<div id="run-wrapper">',
- '#suffix' => '</div>',
- '#tree' => TRUE,
- );
-
- $form['run']['dependency'] = array(
- '#type' => 'select',
- '#title' => t('Dependency'),
- '#options' => _textbook_companion_list_of_dependencies(),
- '#default_value' => $dependency_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(''),
- // ),
- // ),
- );
-
- // $example_list = array();
- /************ START OF $_POST **************/
- /*
- if ($_POST)
- {
- if ($dependency_default_value > 0)
- {
- $example_id_q = db_query("SELECT * FROM {textbook_companion_example_dependency} WHERE dependency_id = %d", $dependency_default_value);
- 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_list[] = array($example_data->number, $chapter_data->number . ' . ' . $chapter_data->name, $preference_data->book);
- }
- $example_list_header = array('Code', 'Chapter', 'Book');
- $example = theme_table($example_list_header, $example_list);
-
- if ($example_list) {
- $form['run']['example_dependency'] = array(
- '#type' => 'item',
- '#value' => $example,
- );
- $form['run']['example_dependency_message'] = array(
- '#type' => 'item',
- '#value' => 'Please unlink the dependency from the above example before deleting it',
- );
- }
- }
- }
- */
-
- /* hidden form elements */
- // $form['run']['dependency_hidden'] = array(
- // '#type' => 'hidden',
- // '#value' => $form_state['values']['run']['dependency'],
- // );
-
- // if (!$example_list && $dependency_default_value > 0)
- // {
- $form['run']['delete_dependency'] = array(
- '#type' => 'checkbox',
- '#title' => t('Delete Dependency'),
- );
- $form['run']['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Submit')
- );
- // }
-
- return $form;
+ // $form['#redirect'] = FALSE;
+ // ahah_helper_register($form, $form_state);
+ /* default value for ahah fields */
+ // if (!isset($form_state['storage']['run']['dependency']))
+ // {
+ // $dependency_default_value = 0;
+ // } else {
+ // $dependency_default_value = $form_state['storage']['run']['dependency'];
+ // }
+ $form['run'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Manage Dependency'),
+ '#collapsible' => FALSE,
+ '#collapsed' => FALSE,
+ '#prefix' => '<div id="run-wrapper">',
+ '#suffix' => '</div>',
+ '#tree' => TRUE
+ );
+ $form['run']['dependency'] = array(
+ '#type' => 'select',
+ '#title' => t('Dependency'),
+ '#options' => _textbook_companion_list_of_dependencies(),
+ '#default_value' => $dependency_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(''),
+ // ),
+ // ),
+ );
+ // $example_list = array();
+ /************ START OF $_POST **************/
+ /*
+ if ($_POST)
+ {
+ if ($dependency_default_value > 0)
+ {
+ $example_id_q = db_query("SELECT * FROM {textbook_companion_example_dependency} WHERE dependency_id = %d", $dependency_default_value);
+ 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_list[] = array($example_data->number, $chapter_data->number . ' . ' . $chapter_data->name, $preference_data->book);
+ }
+ $example_list_header = array('Code', 'Chapter', 'Book');
+ $example = theme_table($example_list_header, $example_list);
+
+ if ($example_list) {
+ $form['run']['example_dependency'] = array(
+ '#type' => 'item',
+ '#value' => $example,
+ );
+ $form['run']['example_dependency_message'] = array(
+ '#type' => 'item',
+ '#value' => 'Please unlink the dependency from the above example before deleting it',
+ );
+ }
+ }
+ }
+ */
+ /* hidden form elements */
+ // $form['run']['dependency_hidden'] = array(
+ // '#type' => 'hidden',
+ // '#value' => $form_state['values']['run']['dependency'],
+ // );
+ // if (!$example_list && $dependency_default_value > 0)
+ // {
+ $form['run']['delete_dependency'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Delete Dependency')
+ );
+ $form['run']['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit')
+ );
+ // }
+ return $form;
}
-
-
function textbook_companion_dependency_approval_form_submit($form, &$form_state)
{
- global $user;
- $root_path = textbook_companion_path();
-
- if ($form_state['clicked_button']['#value'] == 'Submit')
- {
- if (user_access('bulk manage code'))
- {
- 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']);*/
-
- $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',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');
-
- } else {
- if (textbook_companion_delete_dependency($form_state['values']['run']['dependency']))
- {
- drupal_set_message('Dependency deleted' , 'status');
-
- /* email */
- $email_subject = t('Dependency deleted');
- $email_body = t('Dependency deleted : .') . $form_state['values']['run']['dependency'];
- $email_to = $user->mail;
- $param['standard']['subject'] = $email_subject;
- $param['standard']['body'] = $email_body;
- if (!drupal_mail('textbook_companion', 'standard', $email_to, language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE))
- drupal_set_message('Error sending email message.', 'error');
- }
- }
- }
- }
- }
+ global $user;
+ $root_path = textbook_companion_path();
+ if ($form_state['clicked_button']['#value'] == 'Submit')
+ {
+ if (user_access('bulk manage code'))
+ {
+ 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']);*/
+ $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_id_data = $example_id_q->fetchObject()
+ $example_list_header = array(
+ 'Book',
+ 'Chapter',
+ 'Code'
+ );
+ $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');
+ } //$example_data = $example_q->fetchObject()
+ else
+ {
+ if (textbook_companion_delete_dependency($form_state['values']['run']['dependency']))
+ {
+ drupal_set_message('Dependency deleted', 'status');
+ /* email */
+ $email_subject = t('Dependency deleted');
+ $email_body = t('Dependency deleted : .') . $form_state['values']['run']['dependency'];
+ $email_to = $user->mail;
+ $param['standard']['subject'] = $email_subject;
+ $param['standard']['body'] = $email_body;
+ if (!drupal_mail('textbook_companion', 'standard', $email_to, language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE))
+ drupal_set_message('Error sending email message.', 'error');
+ } //textbook_companion_delete_dependency($form_state['values']['run']['dependency'])
+ }
+ } //$form_state['values']['run']['delete_dependency'] == "1"
+ } //user_access('bulk manage code')
+ } //$form_state['clicked_button']['#value'] == 'Submit'
}
-
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");*/
-
+ $dependencies = array(
+ '0' => 'Please select...'
+ );
+ /*$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 . ')';
- }
- return $dependencies;
+ while ($dependency_data = $dependency_q->fetchObject())
+ {
+ $dependencies[$dependency_data->id] = $dependency_data->filename . ' (' . $dependency_data->filepath . ')';
+ } //$dependency_data = $dependency_q->fetchObject()
+ return $dependencies;
}
-
function textbook_companion_delete_dependency($dependency_id)
{
- global $user;
- $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);*/
-
+ global $user;
+ $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);*/
$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');
- return FALSE;
- }
-
- if (!file_exists($root_path . $dependency_files_data->filepath))
- {
- drupal_set_message(t('Error deleting !file. File does not exists.', array('!file' => $dependency_files_data->filepath)), 'error');
- return FALSE;
- }
-
- /* removing dependency file */
- if (!unlink($root_path . $dependency_files_data->filepath))
- {
- $status = FALSE;
- drupal_set_message(t('Error deleting !file', array('!file' => $dependency_files_data->filepath)), 'error');
-
- /* sending email to admins */
- $email_to = variable_get('textbook_companion_emails', '');
- $param['standard']['subject'] = "[ERROR] Error deleting dependency file";
- $param['standard']['body'] = "Error deleting dependency files by " . $user->uid . " at " . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . " :
+ $dependency_files_data = $result->fetchObject();
+ if (!$dependency_files_data)
+ {
+ drupal_set_message(t('Invalid dependency.'), 'error');
+ return FALSE;
+ } //!$dependency_files_data
+ if (!file_exists($root_path . $dependency_files_data->filepath))
+ {
+ drupal_set_message(t('Error deleting !file. File does not exists.', array(
+ '!file' => $dependency_files_data->filepath
+ )), 'error');
+ return FALSE;
+ } //!file_exists($root_path . $dependency_files_data->filepath)
+ /* removing dependency file */
+ if (!unlink($root_path . $dependency_files_data->filepath))
+ {
+ $status = FALSE;
+ drupal_set_message(t('Error deleting !file', array(
+ '!file' => $dependency_files_data->filepath
+ )), 'error');
+ /* sending email to admins */
+ $email_to = variable_get('textbook_companion_emails', '');
+ $param['standard']['subject'] = "[ERROR] Error deleting dependency file";
+ $param['standard']['body'] = "Error deleting dependency files by " . $user->uid . " at " . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . " :
dependency id : " . $dependency_id . "
- file id : " . $dependency_files_data->id . "
+ file id : " . $dependency_files_data->id . "
file path : " . $dependency_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 dependency files database entries */
-
- /*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;
+ 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');
+ } //!unlink($root_path . $dependency_files_data->filepath)
+ else
+ {
+ /* deleting dependency files database entries */
+ /*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 e4d2a5d..d33ad1a 100755
--- a/download.inc
+++ b/download.inc
@@ -1,321 +1,293 @@
<?php
// $Id$
-
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_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);*/
$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));
- readfile($root_path . $example_file_data->filepath);
+ $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));
+ readfile($root_path . $example_file_data->filepath);
}
-
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_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);*/
$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));
- ob_clean();
- readfile($root_path . $dependency_file_data->filepath);
- exit;
+ $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));
+ ob_clean();
+ readfile($root_path . $dependency_file_data->filepath);
+ exit;
}
-
function textbook_companion_download_example()
{
- $example_id = arg(2);
- $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);*/
+ $example_id = arg(2);
+ $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);*/
$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);*/
+ $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);*/
+ $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);*/
+ /*$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 . '/';
-
- /* 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);
-
- 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 = $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));*/
-
- $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);
- }
- $zip_file_count = $zip->numFiles;
- $zip->close();
-
- if ($zip_file_count > 0)
- {
- /* download zip file */
- header('Content-Type: application/zip');
- header('Content-disposition: attachment; filename="EX' . $example_data->number . '.zip"');
- header('Content-Length: ' . filesize($zip_filename));
- readfile($zip_filename);
- unlink($zip_filename);
- } else {
- drupal_set_message("There are no files in this examples to download", 'error');
- drupal_goto('textbook_run');
- }
+ $EX_PATH = 'EX' . $example_data->number . '/';
+ /* 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);
+ while ($example_files_row = $example_files_q->fetchObject())
+ {
+ $zip->addFile($root_path . $example_files_row->filepath, $EX_PATH . $example_files_row->filename);
+ } //$example_files_row = $example_files_q->fetchObject()
+ /* dependency files */
+ 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));*/
+ $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);
+ } //$example_dependency_files_row = $example_dependency_files_q->fetchObject()
+ $zip_file_count = $zip->numFiles;
+ $zip->close();
+ if ($zip_file_count > 0)
+ {
+ /* download zip file */
+ header('Content-Type: application/zip');
+ header('Content-disposition: attachment; filename="EX' . $example_data->number . '.zip"');
+ header('Content-Length: ' . filesize($zip_filename));
+ readfile($zip_filename);
+ unlink($zip_filename);
+ } //$zip_file_count > 0
+ else
+ {
+ drupal_set_message("There are no files in this examples to download", 'error');
+ drupal_goto('textbook_run');
+ }
}
-
function textbook_companion_download_chapter()
{
- $chapter_id = arg(2);
- // var_dump($chapter_id);die;
- $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_id = arg(2);
+ // var_dump($chapter_id);die;
+ $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);*/
$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->open($zip_filename, ZipArchive::CREATE);
-
- /*$example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d AND approval_status = 1", $chapter_id);*/
-
+ $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->open($zip_filename, ZipArchive::CREATE);
+ /*$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);*/
-
- $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 = $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));*/
-
- $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);
- }
- }
- $zip_file_count = $zip->numFiles;
- $zip->close();
-
- if ($zip_file_count > 0)
- {
- /* download zip file */
- header('Content-Type: application/zip');
- header('Content-disposition: attachment; filename="CH' . $chapter_data->number . '.zip"');
- header('Content-Length: ' . filesize($zip_filename));
- readfile($zip_filename);
- unlink($zip_filename);
- } else {
- drupal_set_message("There are no examples in this chapter to download", 'error');
- drupal_goto('textbook_run');
- }
+ 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);*/
+ $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);
+ } //$example_files_row = $example_files_q->fetchObject()
+ /* dependency files */
+ 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));*/
+ $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);
+ } //$example_dependency_files_row = $example_dependency_files_q->fetchObject()
+ } //$example_row = $example_q->fetchObject()
+ $zip_file_count = $zip->numFiles;
+ $zip->close();
+ if ($zip_file_count > 0)
+ {
+ /* download zip file */
+ header('Content-Type: application/zip');
+ header('Content-disposition: attachment; filename="CH' . $chapter_data->number . '.zip"');
+ header('Content-Length: ' . filesize($zip_filename));
+ readfile($zip_filename);
+ unlink($zip_filename);
+ } //$zip_file_count > 0
+ else
+ {
+ drupal_set_message("There are no examples in this chapter to download", 'error');
+ drupal_goto('textbook_run');
+ }
}
-
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 = :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 = :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 = :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 = :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 = $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 = :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 */
- global $user;
- if($user->uid){
- header('Content-Type: application/zip');
- header('Content-disposition: attachment; filename="' . str_replace(' ','_',($book_data->book)) . '.zip"');
- header('Content-Length: ' . filesize($zip_filename));
- ob_clean();
- readfile($zip_filename);
- unlink($zip_filename);
- }else{
- header('Content-Type: application/zip');
- header('Content-disposition: attachment; filename="' . str_replace(' ','_',($book_data->book)) . '.zip"');
- header('Content-Length: ' . filesize($zip_filename));
- header("Content-Transfer-Encoding: binary");
- header('Expires: 0');
- header('Pragma: no-cache');
- ob_end_flush();
- ob_clean();
- flush();
- readfile($zip_filename);
- unlink($zip_filename);
- }
- } else {
- drupal_set_message("There are no examples in this book to download", 'error');
- drupal_goto('textbook_run');
- }
+ $book_id = arg(2);
+ $root_path = textbook_companion_path();
+ /* get example data */
+ $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 = :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 = :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 = :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);
+ } //$example_files_row = $example_files_q->fetchObject()
+ /* dependency files */
+ 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);
+ } //$example_dependency_files_row = $example_dependency_files_q->fetchObject()
+ $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);
+ } //$row = $result->fetchObject()
+ } //$example_row = $example_q->fetchObject()
+ } //$chapter_row = $chapter_q->fetchObject()
+ $zip_file_count = $zip->numFiles;
+ $zip->close();
+ if ($zip_file_count > 0)
+ {
+ /* download zip file */
+ global $user;
+ if ($user->uid)
+ {
+ header('Content-Type: application/zip');
+ header('Content-disposition: attachment; filename="' . str_replace(' ', '_', ($book_data->book)) . '.zip"');
+ header('Content-Length: ' . filesize($zip_filename));
+ ob_clean();
+ readfile($zip_filename);
+ unlink($zip_filename);
+ } //$user->uid
+ else
+ {
+ header('Content-Type: application/zip');
+ header('Content-disposition: attachment; filename="' . str_replace(' ', '_', ($book_data->book)) . '.zip"');
+ header('Content-Length: ' . filesize($zip_filename));
+ header("Content-Transfer-Encoding: binary");
+ header('Expires: 0');
+ header('Pragma: no-cache');
+ ob_end_flush();
+ ob_clean();
+ flush();
+ readfile($zip_filename);
+ unlink($zip_filename);
+ }
+ } //$zip_file_count > 0
+ else
+ {
+ drupal_set_message("There are no examples in this book to download", 'error');
+ drupal_goto('textbook_run');
+ }
}
-
function textbook_companion_download_sample_code()
{
- $proposal_id = arg(2);
- $root_path = textbook_companion_samplecode_path();
-
+ $proposal_id = arg(2);
+ $root_path = textbook_companion_samplecode_path();
$query = db_select('textbook_companion_proposal');
$query->fields('textbook_companion_proposal');
$query->condition('id', $proposal_id);
$query->range(0, 1);
$result = $query->execute();
-
- $example_file_data =$result->fetchObject();
- $samplecodename=substr($example_file_data->samplefilepath, strrpos($example_file_data->samplefilepath, '/') + 1);
- header('Content-Type: application/zip');
- header('Content-disposition: attachment; filename="'.$samplecodename.'"');
- header('Content-Length: ' . filesize($root_path . $example_file_data->samplefilepath));
- ob_clean();
- readfile($root_path . $example_file_data->samplefilepath);
+ $example_file_data = $result->fetchObject();
+ $samplecodename = substr($example_file_data->samplefilepath, strrpos($example_file_data->samplefilepath, '/') + 1);
+ header('Content-Type: application/zip');
+ header('Content-disposition: attachment; filename="' . $samplecodename . '"');
+ header('Content-Length: ' . filesize($root_path . $example_file_data->samplefilepath));
+ ob_clean();
+ readfile($root_path . $example_file_data->samplefilepath);
}
diff --git a/editcode.inc b/editcode.inc
index f1b35d5..cbd806b 100755
--- a/editcode.inc
+++ b/editcode.inc
@@ -1,152 +1,140 @@
<?php
// $Id$
-
/******************************************************************************/
/***************************** EDIT EXAMPLE ***********************************/
/******************************************************************************/
-
-function upload_examples_edit_form($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);*/
-
+ 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);*/
$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');
- drupal_goto('');
- return;
- }
- if ($example_data->approval_status != 0)
- {
- drupal_set_message(t("You cannot edit an example after it has been approved or dis-approved. Please contact site administrator if you want to edit this example."), 'error');
- drupal_goto('');
- return;
- }
-
- /* get examples files */
- $source_file = ""; $source_id = 0;
- $result1_file = ""; $result1_id = 0;
- $result2_file = ""; $result2_id = 0;
- $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);*/
+ $example_data = $example_q->fetchObject();
+ if (!$example_q)
+ {
+ drupal_set_message(t("Invalid example selected."), 'error');
+ drupal_goto('');
+ return;
+ } //!$example_q
+ if ($example_data->approval_status != 0)
+ {
+ drupal_set_message(t("You cannot edit an example after it has been approved or dis-approved. Please contact site administrator if you want to edit this example."), 'error');
+ drupal_goto('');
+ return;
+ } //$example_data->approval_status != 0
+ /* get examples files */
+ $source_file = "";
+ $source_id = 0;
+ $result1_file = "";
+ $result1_id = 0;
+ $result2_file = "";
+ $result2_id = 0;
+ $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);*/
$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")
- {
- $source_file = l($example_files_data->filename, 'download/file/' . $example_files_data->id);
- $source_file_id = $example_files_data->id;
- }
- if ($example_files_data->filetype == "R")
- {
- if (strlen($result1_file) == 0)
- {
- $result1_file = l($example_files_data->filename, 'download/file/' . $example_files_data->id);
- $result1_file_id = $example_files_data->id;
- } else {
- $result2_file = l($example_files_data->filename, 'download/file/' . $example_files_data->id);
- $result2_file_id = $example_files_data->id;
- }
- }
- if ($example_files_data->filetype == "X")
- {
- if (strlen($xcos1_file) <= 0)
- {
- $xcos1_file = l($example_files_data->filename, 'download/file/' . $example_files_data->id);
- $xcos1_file_id = $example_files_data->id;
- } else {
- $xcos2_file = l($example_files_data->filename, 'download/file/' . $example_files_data->id);
- $xcos2_file_id = $example_files_data->id;
- }
- }
- }
-
- /* 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);*/
+ while ($example_files_data = $example_files_q->fetchObject())
+ {
+ if ($example_files_data->filetype == "S")
+ {
+ $source_file = l($example_files_data->filename, 'download/file/' . $example_files_data->id);
+ $source_file_id = $example_files_data->id;
+ } //$example_files_data->filetype == "S"
+ if ($example_files_data->filetype == "R")
+ {
+ if (strlen($result1_file) == 0)
+ {
+ $result1_file = l($example_files_data->filename, 'download/file/' . $example_files_data->id);
+ $result1_file_id = $example_files_data->id;
+ } //strlen($result1_file) == 0
+ else
+ {
+ $result2_file = l($example_files_data->filename, 'download/file/' . $example_files_data->id);
+ $result2_file_id = $example_files_data->id;
+ }
+ } //$example_files_data->filetype == "R"
+ if ($example_files_data->filetype == "X")
+ {
+ if (strlen($xcos1_file) <= 0)
+ {
+ $xcos1_file = l($example_files_data->filename, 'download/file/' . $example_files_data->id);
+ $xcos1_file_id = $example_files_data->id;
+ } //strlen($xcos1_file) <= 0
+ else
+ {
+ $xcos2_file = l($example_files_data->filename, 'download/file/' . $example_files_data->id);
+ $xcos2_file_id = $example_files_data->id;
+ }
+ } //$example_files_data->filetype == "X"
+ } //$example_files_data = $example_files_q->fetchObject()
+ /* 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);*/
$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');
- drupal_goto('');
- return;
- }
-
- /* 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);*/
+ $chapter_data = $result->fetchObject();
+ if (!$chapter_data)
+ {
+ drupal_set_message(t("Invalid chapter selected."), 'error');
+ drupal_goto('');
+ return;
+ } //!$chapter_data
+ /* 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);*/
$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');
- drupal_goto('');
- return;
- }
- if ($preference_data->approval_status != 1)
- {
- drupal_set_message(t("Cannot edit example. Either the book proposal has not been approved or it has been rejected."), 'error');
- drupal_goto('');
- return;
- }
-
- /* 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);*/
+ $preference_data = $result->fetchObject();
+ if (!$preference_data)
+ {
+ drupal_set_message(t("Invalid book selected."), 'error');
+ drupal_goto('');
+ return;
+ } //!$preference_data
+ if ($preference_data->approval_status != 1)
+ {
+ drupal_set_message(t("Cannot edit example. Either the book proposal has not been approved or it has been rejected."), 'error');
+ drupal_goto('');
+ return;
+ } //$preference_data->approval_status != 1
+ /* 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);*/
$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');
- drupal_goto('');
- return;
- }
- if ($proposal_data->uid != $user->uid)
- {
- drupal_set_message(t("You do not have permissions to edit this example."), 'error');
- drupal_goto('');
- return;
- }
-
- $user_data = user_load($proposal_data->uid);
-
- /* add javascript for automatic book title, check if example uploaded, dependency selection effects */
- $chapter_name_js = " (function ($) {
+ if (!$proposal_data)
+ {
+ drupal_set_message(t("Invalid proposal selected."), 'error');
+ drupal_goto('');
+ return;
+ } //!$proposal_data
+ if ($proposal_data->uid != $user->uid)
+ {
+ drupal_set_message(t("You do not have permissions to edit this example."), 'error');
+ drupal_goto('');
+ return;
+ } //$proposal_data->uid != $user->uid
+ $user_data = user_load($proposal_data->uid);
+ /* add javascript for automatic book title, check if example uploaded, dependency selection effects */
+ $chapter_name_js = " (function ($) {
$(document).ready(function() {
$('#edit-existing-depfile-dep-book-title').change(function() {
var dep_selected = '';
@@ -171,396 +159,398 @@ function upload_examples_edit_form($form,$form_state)
$('#edit-existing-depfile-dep-book-title').trigger('change');
});
})(jQuery);";
- drupal_add_js($chapter_name_js, 'inline', 'header');
-
- $form['#redirect'] = 'textbook_companion/code';
- $form['#attributes'] = array('enctype' => "multipart/form-data");
-
- $form['book_details']['book'] = array(
- '#type' => 'item',
- '#markup' => $preference_data->book,
- '#title' => t('Title of the Book'),
- );
- $form['contributor_name'] = array(
- '#type' => 'item',
- '#markup' => $proposal_data->full_name,
- '#title' => t('Contributor Name'),
- );
- $form['number'] = array(
- '#type' => 'item',
- '#title' => t('Chapter No'),
- '#markup' => $chapter_data->number,
- );
- $form['name'] = array(
- '#type' => 'item',
- '#title' => t('Title of the Chapter'),
- '#markup' => $chapter_data->name,
- );
- $form['example_number'] = array(
- '#type' => 'item',
- '#title' => t('Example No'),
- '#markup' => $example_data->number,
- );
- $form['example_caption'] = array(
- '#type' => 'textfield',
- '#title' => t('Caption'),
- '#size' => 40,
- '#maxlength' => 255,
- '#required' => TRUE,
- '#default_value' => $example_data->caption,
- );
- $form['example_warning'] = array(
- '#type' => 'item',
- '#title' => t('You should upload all the files (main or source files, result files, executable file if any)'),
- '#prefix' => '<div style="color:red">',
- '#suffix' => '</div>',
- );
-
- $form['sourcefile'] = array(
- '#type' => 'fieldset',
- '#title' => t('Main or Source Files'),
- '#collapsible' => FALSE,
- '#collapsed' => FALSE,
- );
- if ($source_file)
- {
- $form['sourcefile']['cur_source'] = array(
- '#type' => 'item',
- '#title' => t('Existing Main or Source File'),
- '#markup' => $source_file,
- );
- $form['sourcefile']['cur_source_checkbox'] = array(
- '#type' => 'checkbox',
- '#title' => t('Delete Existing Main or Source File'),
- '#description' => 'Check to delete the existing Main or Source file.',
- );
- $form['sourcefile']['sourcefile1'] = array(
- '#type' => 'file',
- '#title' => t('Upload New Main or Source File'),
- '#size' => 48,
- '#description' => t("Upload new Main or Source file above if you want to replace the existing file. Leave blank if you want to keep using the existing file. <br />") .
- t('Allowed file extensions : ') . variable_get('textbook_companion_source_extensions', ''),
- );
- $form['sourcefile']['cur_source_file_id'] = array(
- '#type' => 'hidden',
- '#value' => $source_file_id,
- );
- } else {
- $form['sourcefile']['sourcefile1'] = array(
- '#type' => 'file',
- '#title' => t('Upload New Main or Source File'),
- '#size' => 48,
- '#description' => t('Allowed file extensions : ') . variable_get('textbook_companion_source_extensions', ''),
- );
- }
-
- $form['dep_files'] = array(
- '#type' => 'item',
- '#title' => t('Dependency Files'),
- );
-
- /************ START OF EXISTING DEPENDENCIES **************/
-
- $dependency_files = array();
-
- /*$dependency_q = db_query("SELECT * FROM {textbook_companion_example_dependency} WHERE example_id = %d", $example_data->id);*/
-
+ drupal_add_js($chapter_name_js, 'inline', 'header');
+ $form['#redirect'] = 'textbook_companion/code';
+ $form['#attributes'] = array(
+ 'enctype' => "multipart/form-data"
+ );
+ $form['book_details']['book'] = array(
+ '#type' => 'item',
+ '#markup' => $preference_data->book,
+ '#title' => t('Title of the Book')
+ );
+ $form['contributor_name'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->full_name,
+ '#title' => t('Contributor Name')
+ );
+ $form['number'] = array(
+ '#type' => 'item',
+ '#title' => t('Chapter No'),
+ '#markup' => $chapter_data->number
+ );
+ $form['name'] = array(
+ '#type' => 'item',
+ '#title' => t('Title of the Chapter'),
+ '#markup' => $chapter_data->name
+ );
+ $form['example_number'] = array(
+ '#type' => 'item',
+ '#title' => t('Example No'),
+ '#markup' => $example_data->number
+ );
+ $form['example_caption'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Caption'),
+ '#size' => 40,
+ '#maxlength' => 255,
+ '#required' => TRUE,
+ '#default_value' => $example_data->caption
+ );
+ $form['example_warning'] = array(
+ '#type' => 'item',
+ '#title' => t('You should upload all the files (main or source files, result files, executable file if any)'),
+ '#prefix' => '<div style="color:red">',
+ '#suffix' => '</div>'
+ );
+ $form['sourcefile'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Main or Source Files'),
+ '#collapsible' => FALSE,
+ '#collapsed' => FALSE
+ );
+ if ($source_file)
+ {
+ $form['sourcefile']['cur_source'] = array(
+ '#type' => 'item',
+ '#title' => t('Existing Main or Source File'),
+ '#markup' => $source_file
+ );
+ $form['sourcefile']['source_file_action_note'] = array(
+ '#type' => 'item',
+ '#title' => t('Note:'),
+ '#markup' => t("<Strong style='color:red' >Use Replace option to upload your corrected code. Do not delete the example if your book is under review, you can always edit and upload it by the Replace option.</strong>")
+ );
+ $form['sourcefile']['source_file_action'] = array(
+ '#type' => 'radios',
+ '#options' => array(
+ '1' => "Replace Existing Main or Source File<br>",
+ '2' => "Delete Existing Main or Source File"
+ ),
+ '#title' => t('Select Action'),
+ '#required' => TRUE
+ );
+ $form['sourcefile']['sourcefile1'] = array(
+ '#type' => 'file',
+ '#title' => t('Upload New Main or Source File'),
+ '#size' => 48,
+ '#description' => t("<Strong style='color:red' >Upload new Main or Source file above, if you want to replace the existing file. Leave blank if you want to keep using the existing file.</strong> <br />") . t('Allowed file extensions : ') . variable_get('textbook_companion_source_extensions', ''),
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="source_file_action"]' => array(
+ 'value' => '1'
+ )
+ )
+ )
+ );
+ /*
+ $form['sourcefile']['cur_source_checkbox'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Delete Existing Main or Source File'),
+ '#description' => 'Check to delete the existing Main or Source file.',
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="source_file_action"]' => array('value' => '2'),
+ ),
+ ),
+ );
+ */
+ $form['sourcefile']['cur_source_file_id'] = array(
+ '#type' => 'hidden',
+ '#value' => $source_file_id
+ );
+ } //$source_file
+ else
+ {
+ $form['sourcefile']['sourcefile1'] = array(
+ '#type' => 'file',
+ '#title' => t('Upload New Main or Source File'),
+ '#size' => 48,
+ '#description' => t('Allowed file extensions : ') . variable_get('textbook_companion_source_extensions', '')
+ );
+ }
+ $form['dep_files'] = array(
+ '#type' => 'item',
+ '#title' => t('Dependency Files')
+ );
+ /************ START OF EXISTING DEPENDENCIES **************/
+ $dependency_files = array();
+ /*$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;
- }
-
- /* existing dependencies */
- $form['existing_depfile'] = array(
- '#type' => 'fieldset',
- '#title' => t('Use Already Existing Dependency Files'),
- '#collapsible' => FALSE,
- '#collapsed' => FALSE,
- '#prefix' => '<div id="existing-depfile-wrapper">',
- '#suffix' => '</div>',
- '#tree' => TRUE,
- );
-
- /* 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_book_title'] = array(
- '#type' => 'select',
- '#title' => t('Title of the Book'),
- '#options' => _list_of_book_titles(),
- );
-
- 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,
- '#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_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 **************/
-
- $form['result'] = array(
- '#type' => 'fieldset',
- '#title' => t('Result Files'),
- '#collapsible' => FALSE,
- '#collapsed' => FALSE,
- );
- if ($result1_file)
- {
- $form['result']['cur_result1'] = array(
- '#type' => 'item',
- '#title' => t('Existing Result File 1'),
- '#markup' => $result1_file,
- );
- $form['result']['cur_result1_checkbox'] = array(
- '#type' => 'checkbox',
- '#title' => t('Delete Existing Result File 1'),
- '#description' => 'Check to delete the existing Result file.',
- );
- $form['result']['result1'] = array(
- '#type' => 'file',
- '#title' => t('Upload New Result File 1'),
- '#size' => 48,
- '#description' => t("Upload new Result file above if you want to replace the existing file, leave blank if you want to keep using the existing file. <br />") .
- t('Allowed file extensions : ') . variable_get('textbook_companion_result_extensions', ''),
- );
- $form['result']['cur_result1_file_id'] = array(
- '#type' => 'hidden',
- '#value' => $result1_file_id,
- );
- } else {
- $form['result']['result1'] = array(
- '#type' => 'file',
- '#title' => t('Upload New Result File 1'),
- '#size' => 48,
- '#description' => t('Allowed file extensions : ') . variable_get('textbook_companion_result_extensions', ''),
- );
- }
-
- $form['result']['br'] = array(
- '#type' => 'item',
- '#markup' => "<br />",
- );
-
- if ($result2_file)
- {
- $form['result']['cur_result2'] = array(
- '#type' => 'item',
- '#title' => t('Existing Result File 2'),
- '#markup' => $result2_file,
- );
- $form['result']['cur_result2_checkbox'] = array(
- '#type' => 'checkbox',
- '#title' => t('Delete Existing Result File 2'),
- '#description' => 'Check to delete the existing Result file.',
- );
- $form['result']['result2'] = array(
- '#type' => 'file',
- '#title' => t('Upload New Result file 2'),
- '#size' => 48,
- '#description' => t("Upload new Result file above if you want to replace the existing file. Leave blank if you want to keep using the existing file. <br />") .
- t('Allowed file extensions : ') . variable_get('textbook_companion_result_extensions', ''),
- );
- $form['result']['cur_result2_file_id'] = array(
- '#type' => 'hidden',
- '#value' => $result2_file_id,
- );
- } else {
- $form['result']['result2'] = array(
- '#type' => 'file',
- '#title' => t('Upload New Result file 2'),
- '#size' => 48,
- '#description' => t('Allowed file extensions : ') . variable_get('textbook_companion_result_extensions', ''),
- );
- }
- $form['xcos'] = array(
- '#type' => 'fieldset',
- '#title' => t('XCOS Files'),
- '#collapsible' => FALSE,
- '#collapsed' => FALSE,
- );
- if ($xcos1_file)
- {
- $form['xcos']['cur_xcos1'] = array(
- '#type' => 'item',
- '#title' => t('Existing xcos File 1'),
- '#markup' => $xcos1_file,
- );
- $form['xcos']['cur_xcos1_checkbox'] = array(
- '#type' => 'checkbox',
- '#title' => t('Delete Existing xcos File 1'),
- '#description' => 'Check to delete the existing xcos file.',
- );
- $form['xcos']['xcos1'] = array(
- '#type' => 'file',
- '#title' => t('Upload New xcos file 1'),
- '#size' => 48,
- '#description' => t("Upload new xcos file above if you want to replace the existing file. Leave blank if you want to keep using the existing file. <br />") .
- t('Allowed file extensions : ') . variable_get('textbook_companion_xcos_extensions', ''),
- );
- $form['sourcefile']['cur_xcos1_file_id'] = array(
- '#type' => 'hidden',
- '#value' => $xcos1_file_id,
- );
- } else {
- $form['xcos']['xcos1'] = array(
- '#type' => 'file',
- '#title' => t('Upload New xcos file 1'),
- '#size' => 48,
- '#description' => t('Allowed file extensions : ') . variable_get('textbook_companion_xcos_extensions', ''),
- );
- }
-
- $form['xcos']['br'] = array(
- '#type' => 'item',
- '#markup' => "<br />",
- );
-
- if ($xcos2_file)
- {
- $form['xcos']['cur_xcos2'] = array(
- '#type' => 'item',
- '#title' => t('Existing xcos File 2'),
- '#markup' => $xcos2_file,
- );
- $form['xcos']['cur_xcos2_checkbox'] = array(
- '#type' => 'checkbox',
- '#title' => t('Delete Existing xcos File 2'),
- '#description' => 'Check to delete the existing xcos file.',
- );
- $form['xcos']['xcos2'] = array(
- '#type' => 'file',
- '#title' => t('Upload New xcos file 2'),
- '#size' => 48,
- '#description' => t("Upload new xcos file above if you want to replace the existing file. Leave blank if you want to keep using the existing file. <br />") .
- t('Allowed file extensions : ') . variable_get('textbook_companion_xcos_extensions', ''),
- );
- $form['xcos']['cur_xcos2_file_id'] = array(
- '#type' => 'hidden',
- '#value' => $xcos2_file_id,
- );
- } else {
- $form['xcos']['xcos2'] = array(
- '#type' => 'file',
- '#title' => t('Upload New xcos file 2'),
- '#size' => 48,
- '#description' => t('Allowed file extensions : ') . variable_get('textbook_companion_xcos_extensions', ''),
- );
- }
-
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Submit')
- );
-
- $form['cancel'] = array(
- '#type' => 'markup',
- '#value' => l(t('Cancel'), 'textbook_companion/code'),
- );
- return $form;
+ while ($dependency_data = $dependency_q->fetchObject())
+ {
+ $dependency_files[] = $dependency_data->dependency_id;
+ } //$dependency_data = $dependency_q->fetchObject()
+ /* existing dependencies */
+ $form['existing_depfile'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Use Already Existing Dependency Files'),
+ '#collapsible' => FALSE,
+ '#collapsed' => FALSE,
+ '#prefix' => '<div id="existing-depfile-wrapper">',
+ '#suffix' => '</div>',
+ '#tree' => TRUE
+ );
+ /* 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_book_title'] = array(
+ '#type' => 'select',
+ '#title' => t('Title of the Book'),
+ '#options' => _list_of_book_titles(),
+ );
+
+ 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,
+ '#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_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 **************/
+ $form['result'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Result Files'),
+ '#collapsible' => FALSE,
+ '#collapsed' => FALSE
+ );
+ if ($result1_file)
+ {
+ $form['result']['cur_result1'] = array(
+ '#type' => 'item',
+ '#title' => t('Existing Result File 1'),
+ '#markup' => $result1_file
+ );
+ $form['result']['cur_result1_checkbox'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Delete Existing Result File 1'),
+ '#description' => 'Check to delete the existing Result file.'
+ );
+ $form['result']['result1'] = array(
+ '#type' => 'file',
+ '#title' => t('Upload New Result File 1'),
+ '#size' => 48,
+ '#description' => t("Upload new Result file above if you want to replace the existing file, leave blank if you want to keep using the existing file. <br />") . t('Allowed file extensions : ') . variable_get('textbook_companion_result_extensions', '')
+ );
+ $form['result']['cur_result1_file_id'] = array(
+ '#type' => 'hidden',
+ '#value' => $result1_file_id
+ );
+ } //$result1_file
+ else
+ {
+ $form['result']['result1'] = array(
+ '#type' => 'file',
+ '#title' => t('Upload New Result File 1'),
+ '#size' => 48,
+ '#description' => t('Allowed file extensions : ') . variable_get('textbook_companion_result_extensions', '')
+ );
+ }
+ $form['result']['br'] = array(
+ '#type' => 'item',
+ '#markup' => "<br />"
+ );
+ if ($result2_file)
+ {
+ $form['result']['cur_result2'] = array(
+ '#type' => 'item',
+ '#title' => t('Existing Result File 2'),
+ '#markup' => $result2_file
+ );
+ $form['result']['cur_result2_checkbox'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Delete Existing Result File 2'),
+ '#description' => 'Check to delete the existing Result file.'
+ );
+ $form['result']['result2'] = array(
+ '#type' => 'file',
+ '#title' => t('Upload New Result file 2'),
+ '#size' => 48,
+ '#description' => t("Upload new Result file above if you want to replace the existing file. Leave blank if you want to keep using the existing file. <br />") . t('Allowed file extensions : ') . variable_get('textbook_companion_result_extensions', '')
+ );
+ $form['result']['cur_result2_file_id'] = array(
+ '#type' => 'hidden',
+ '#value' => $result2_file_id
+ );
+ } //$result2_file
+ else
+ {
+ $form['result']['result2'] = array(
+ '#type' => 'file',
+ '#title' => t('Upload New Result file 2'),
+ '#size' => 48,
+ '#description' => t('Allowed file extensions : ') . variable_get('textbook_companion_result_extensions', '')
+ );
+ }
+ $form['xcos'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('XCOS Files'),
+ '#collapsible' => FALSE,
+ '#collapsed' => FALSE
+ );
+ if ($xcos1_file)
+ {
+ $form['xcos']['cur_xcos1'] = array(
+ '#type' => 'item',
+ '#title' => t('Existing xcos File 1'),
+ '#markup' => $xcos1_file
+ );
+ $form['xcos']['cur_xcos1_checkbox'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Delete Existing xcos File 1'),
+ '#description' => 'Check to delete the existing xcos file.'
+ );
+ $form['xcos']['xcos1'] = array(
+ '#type' => 'file',
+ '#title' => t('Upload New xcos file 1'),
+ '#size' => 48,
+ '#description' => t("Upload new xcos file above if you want to replace the existing file. Leave blank if you want to keep using the existing file. <br />") . t('Allowed file extensions : ') . variable_get('textbook_companion_xcos_extensions', '')
+ );
+ $form['sourcefile']['cur_xcos1_file_id'] = array(
+ '#type' => 'hidden',
+ '#value' => $xcos1_file_id
+ );
+ } //$xcos1_file
+ else
+ {
+ $form['xcos']['xcos1'] = array(
+ '#type' => 'file',
+ '#title' => t('Upload New xcos file 1'),
+ '#size' => 48,
+ '#description' => t('Allowed file extensions : ') . variable_get('textbook_companion_xcos_extensions', '')
+ );
+ }
+ $form['xcos']['br'] = array(
+ '#type' => 'item',
+ '#markup' => "<br />"
+ );
+ if ($xcos2_file)
+ {
+ $form['xcos']['cur_xcos2'] = array(
+ '#type' => 'item',
+ '#title' => t('Existing xcos File 2'),
+ '#markup' => $xcos2_file
+ );
+ $form['xcos']['cur_xcos2_checkbox'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Delete Existing xcos File 2'),
+ '#description' => 'Check to delete the existing xcos file.'
+ );
+ $form['xcos']['xcos2'] = array(
+ '#type' => 'file',
+ '#title' => t('Upload New xcos file 2'),
+ '#size' => 48,
+ '#description' => t("Upload new xcos file above if you want to replace the existing file. Leave blank if you want to keep using the existing file. <br />") . t('Allowed file extensions : ') . variable_get('textbook_companion_xcos_extensions', '')
+ );
+ $form['xcos']['cur_xcos2_file_id'] = array(
+ '#type' => 'hidden',
+ '#value' => $xcos2_file_id
+ );
+ } //$xcos2_file
+ else
+ {
+ $form['xcos']['xcos2'] = array(
+ '#type' => 'file',
+ '#title' => t('Upload New xcos file 2'),
+ '#size' => 48,
+ '#description' => t('Allowed file extensions : ') . variable_get('textbook_companion_xcos_extensions', '')
+ );
+ }
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit')
+ );
+ $form['cancel'] = array(
+ '#type' => 'markup',
+ '#value' => l(t('Cancel'), 'textbook_companion/code')
+ );
+ return $form;
}
-
function upload_examples_edit_form_validate($form, &$form_state)
{
- if (!check_name($form_state['values']['example_caption']))
- form_set_error('example_caption', t('Example Caption can contain only alphabets, numbers and spaces.'));
-
- if (isset($_FILES['files']))
- {
- /* check for valid filename extensions */
- foreach ($_FILES['files']['name'] as $file_form_name => $file_name)
- {
- if ($file_name)
- {
- /* checking file type */
- if (strstr($file_form_name, 'source'))
- $file_type = 'S';
- else if (strstr($file_form_name, 'result'))
- $file_type = 'R';
- else if (strstr($file_form_name, 'xcos'))
- $file_type = 'X';
- else
- $file_type = 'U';
-
- $allowed_extensions_str = '';
- switch ($file_type)
- {
- case 'S':
- $allowed_extensions_str = variable_get('textbook_companion_source_extensions', '');
- break;
- case 'R':
- $allowed_extensions_str = variable_get('textbook_companion_result_extensions', '');
- break;
- case 'X':
- $allowed_extensions_str = variable_get('textbook_companion_xcos_extensions', '');
- break;
- }
-
- $allowed_extensions = explode(',' , $allowed_extensions_str);
- $temp_extension = end(explode('.', strtolower($_FILES['files']['name'][$file_form_name])));
- if (!in_array($temp_extension, $allowed_extensions))
- form_set_error($file_form_name, t('Only file with ' . $allowed_extensions_str . ' extensions can be uploaded.'));
- if ($_FILES['files']['size'][$file_form_name] <= 0)
- form_set_error($file_form_name, t('File size cannot be zero.'));
-
- /* check if valid file name */
- if (!textbook_companion_check_valid_filename($_FILES['files']['name'][$file_form_name]))
- form_set_error($file_form_name, t('Invalid file name specified. Only alphabets, numbers and underscore is allowed as a valid filename.'));
- }
- }
- }
-
- /* add javascript again for automatic book title, check if example uploaded, dependency selection effects */
- $chapter_name_js = " $(document).ready(function() {
+ if (!check_name($form_state['values']['example_caption']))
+ form_set_error('example_caption', t('Example Caption can contain only alphabets, numbers and spaces.'));
+ if (isset($_FILES['files']))
+ {
+ /* check for valid filename extensions */
+ foreach ($_FILES['files']['name'] as $file_form_name => $file_name)
+ {
+ if ($file_name)
+ {
+ /* checking file type */
+ if (strstr($file_form_name, 'source'))
+ $file_type = 'S';
+ else if (strstr($file_form_name, 'result'))
+ $file_type = 'R';
+ else if (strstr($file_form_name, 'xcos'))
+ $file_type = 'X';
+ else
+ $file_type = 'U';
+ $allowed_extensions_str = '';
+ switch ($file_type)
+ {
+ case 'S':
+ $allowed_extensions_str = variable_get('textbook_companion_source_extensions', '');
+ break;
+ case 'R':
+ $allowed_extensions_str = variable_get('textbook_companion_result_extensions', '');
+ break;
+ case 'X':
+ $allowed_extensions_str = variable_get('textbook_companion_xcos_extensions', '');
+ break;
+ } //$file_type
+ $allowed_extensions = explode(',', $allowed_extensions_str);
+ $temp_extension = end(explode('.', strtolower($_FILES['files']['name'][$file_form_name])));
+ if (!in_array($temp_extension, $allowed_extensions))
+ form_set_error($file_form_name, t('Only file with ' . $allowed_extensions_str . ' extensions can be uploaded.'));
+ if ($_FILES['files']['size'][$file_form_name] <= 0)
+ form_set_error($file_form_name, t('File size cannot be zero.'));
+ /* check if valid file name */
+ if (!textbook_companion_check_valid_filename($_FILES['files']['name'][$file_form_name]))
+ form_set_error($file_form_name, t('Invalid file name specified. Only alphabets, numbers and underscore is allowed as a valid filename.'));
+ } //$file_name
+ } //$_FILES['files']['name'] as $file_form_name => $file_name
+ } //isset($_FILES['files'])
+ /* add javascript again for automatic book title, check if example uploaded, dependency selection effects */
+ $chapter_name_js = " $(document).ready(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);
@@ -595,809 +585,748 @@ function upload_examples_edit_form_validate($form, &$form_state)
});
$('#edit-existing-depfile-dep-book-title').trigger('change');
});";
- drupal_add_js($chapter_name_js, 'inline', 'header');
+ drupal_add_js($chapter_name_js, 'inline', 'header');
}
-
function upload_examples_edit_form_submit($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);*/
-
+ 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);*/
$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');
- drupal_goto('');
- return;
- }
- if ($example_data->approval_status != 0)
- {
- drupal_set_message(t("You cannot edit an example after it has been approved or dis-approved. Please contact site administrator if you want to edit this example."), 'error');
- drupal_goto('');
- return;
- }
-
- /* 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);*/
-
+ if (!$example_q)
+ {
+ drupal_set_message(t("Invalid example selected."), 'error');
+ drupal_goto('');
+ return;
+ } //!$example_q
+ if ($example_data->approval_status != 0)
+ {
+ drupal_set_message(t("You cannot edit an example after it has been approved or dis-approved. Please contact site administrator if you want to edit this example."), 'error');
+ drupal_goto('');
+ return;
+ } //$example_data->approval_status != 0
+ /* 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);*/
$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');
- drupal_goto('');
- return;
- }
-
- /* 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);*/
+ $chapter_data = $result->fetchObject();
+ if (!$chapter_data)
+ {
+ drupal_set_message(t("Invalid chapter selected."), 'error');
+ drupal_goto('');
+ return;
+ } //!$chapter_data
+ /* 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);*/
$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');
- drupal_goto('');
- return;
- }
- if ($preference_data->approval_status != 1)
- {
- drupal_set_message(t("Cannot edit example. Either the book proposal has not been approved or it has been rejected."), 'error');
- drupal_goto('');
- return;
- }
-
- /* 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);*/
-
+ $preference_data = $result->fetchObject();
+ if (!$preference_data)
+ {
+ drupal_set_message(t("Invalid book selected."), 'error');
+ drupal_goto('');
+ return;
+ } //!$preference_data
+ if ($preference_data->approval_status != 1)
+ {
+ drupal_set_message(t("Cannot edit example. Either the book proposal has not been approved or it has been rejected."), 'error');
+ drupal_goto('');
+ return;
+ } //$preference_data->approval_status != 1
+ /* 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);*/
$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');
- drupal_goto('');
- return;
- }
- if ($proposal_data->uid != $user->uid)
- {
- drupal_set_message(t("You do not have permissions to edit this example."), 'error');
- drupal_goto('');
- return;
- }
-
- /* creating directories */
- $root_path = textbook_companion_path();
-
- $dest_path = $preference_data->id . '/';
- if (!is_dir($root_path . $dest_path))
- mkdir($root_path . $dest_path);
-
- $dest_path .= 'CH' . $chapter_data->number . '/';
- if (!is_dir($root_path . $dest_path))
- mkdir($root_path . $dest_path);
-
- $dest_path .= 'EX' . $example_data->number . '/';
- if (!is_dir($root_path . $dest_path))
- 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);*/
-
+ $proposal_data = $result->fetchObject();
+ if (!$proposal_data)
+ {
+ drupal_set_message(t("Invalid proposal selected."), 'error');
+ drupal_goto('');
+ return;
+ } //!$proposal_data
+ if ($proposal_data->uid != $user->uid)
+ {
+ drupal_set_message(t("You do not have permissions to edit this example."), 'error');
+ drupal_goto('');
+ return;
+ } //$proposal_data->uid != $user->uid
+ /* creating directories */
+ $root_path = textbook_companion_path();
+ $dest_path = $preference_data->id . '/';
+ if (!is_dir($root_path . $dest_path))
+ mkdir($root_path . $dest_path);
+ $dest_path .= 'CH' . $chapter_data->number . '/';
+ if (!is_dir($root_path . $dest_path))
+ mkdir($root_path . $dest_path);
+ $dest_path .= 'EX' . $example_data->number . '/';
+ if (!is_dir($root_path . $dest_path))
+ 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);*/
$query = db_update('textbook_companion_example');
$query->fields(array(
- 'caption' => $form_state['values']['example_caption'],
+ '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);*/
-
+ /* handling dependencies */
+ /*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)
- 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)
+ 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)
+ 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(),
+ ":example_id" => $example_data->id,
+ ":dependency_id" => $row,
+ ":approval_status" => 0,
+ ":timestamp" => time()
);
- $result = db_query($query, $args, array('return' => Database::RETURN_INSERT_ID));
- }
- }
-
- /* handle source file */
- $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);*/
- $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');
- return;
- }
- if (($form_state['values']['cur_source_checkbox'] == 1) && (!$_FILES['files']['name']['sourcefile1']))
- {
- if (!delete_file($cur_file_id))
- {
- drupal_set_message("Error deleting example source file.", 'error');
- return;
- }
- }
- }
- if ($_FILES['files']['name']['sourcefile1'])
- {
- if ($cur_file_id > 0)
- {
- if (!delete_file($cur_file_id))
- {
- drupal_set_message("Error removing previous example source file.", 'error');
- return;
- }
- }
- if (file_exists($root_path . $dest_path . $_FILES['files']['name']['sourcefile1']))
- {
- drupal_set_message(t("Error uploading source file. File !filename already exists.", array('!filename' => $_FILES['files']['name']['sourcefile1'])), 'error');
- return;
- }
- /* uploading file */
- 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)
- VALUES (%d, '%s', '%s', '%s', %d, '%s', %d)",
- $example_data->id,
- $_FILES['files']['name']['sourcefile1'],
- $dest_path . $_FILES['files']['name']['sourcefile1'],
- $_FILES['files']['type']['sourcefile1'],
- $_FILES['files']['size']['sourcefile1'],
- 'S',
- time()
- );*/
-var_dump('ok');
-
- $query = "INSERT INTO {textbook_companion_example_files} (example_id, filename, filepath, filemime, filesize, filetype, timestamp)
+ $result = db_query($query, $args, array(
+ 'return' => Database::RETURN_INSERT_ID
+ ));
+ } //$row > 0
+ } //$form_state['values']['existing_depfile']['dep_chapter_example_files'] as $row
+ /* handle source file */
+ $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);*/
+ $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');
+ return;
+ } //!$file_data
+ if (($form_state['values']['source_file_action'] == 2) && (!$_FILES['files']['name']['sourcefile1']))
+ {
+ if (!delete_file($cur_file_id))
+ {
+ drupal_set_message("Error deleting example source file.", 'error');
+ return;
+ } //!delete_file($cur_file_id)
+ } //($form_state['values']['cur_source_checkbox'] == 1) && (!$_FILES['files']['name']['sourcefile1'])
+ } //$cur_file_id > 0
+ if ($_FILES['files']['name']['sourcefile1'])
+ {
+ if ($cur_file_id > 0)
+ {
+ if (!delete_file($cur_file_id))
+ {
+ drupal_set_message("Error removing previous example source file.", 'error');
+ return;
+ } //!delete_file($cur_file_id)
+ } //$cur_file_id > 0
+ if (file_exists($root_path . $dest_path . $_FILES['files']['name']['sourcefile1']))
+ {
+ drupal_set_message(t("Error uploading source file. File !filename already exists.", array(
+ '!filename' => $_FILES['files']['name']['sourcefile1']
+ )), 'error');
+ return;
+ } //file_exists($root_path . $dest_path . $_FILES['files']['name']['sourcefile1'])
+ /* uploading file */
+ 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)
+ VALUES (%d, '%s', '%s', '%s', %d, '%s', %d)",
+ $example_data->id,
+ $_FILES['files']['name']['sourcefile1'],
+ $dest_path . $_FILES['files']['name']['sourcefile1'],
+ $_FILES['files']['type']['sourcefile1'],
+ $_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(),
+ ":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');
- }
- }
-
- /* handle result1 file */
- $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);*/
- $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');
- return;
- }
- if (($form_state['values']['cur_result1_checkbox'] == 1) && (!$_FILES['files']['name']['result1']))
- {
- if (!delete_file($cur_file_id))
- {
- drupal_set_message("Error deleting example result 1 file.", 'error');
- return;
- }
- }
- }
- if ($_FILES['files']['name']['result1'])
- {
- if ($cur_file_id > 0)
- {
- if (!delete_file($cur_file_id))
- {
- drupal_set_message("Error removing previous example result 1 file.", 'error');
- return;
- }
- }
- if (file_exists($root_path . $dest_path . $_FILES['files']['name']['result1']))
- {
- drupal_set_message(t("Error uploading result 1 file. File !filename already exists.", array('!filename' => $_FILES['files']['name']['result1'])), 'error');
- return;
- }
- /* uploading file */
- 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)
- VALUES (%d, '%s', '%s', '%s', %d, '%s', %d)",
- $example_data->id,
- $_FILES['files']['name']['result1'],
- $dest_path . $_FILES['files']['name']['result1'],
- $_FILES['files']['type']['result1'],
- $_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)";
+ /*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');
+ } //move_uploaded_file($_FILES['files']['tmp_name']['sourcefile1'], $root_path . $dest_path . $_FILES['files']['name']['sourcefile1'])
+ else
+ {
+ drupal_set_message('Error uploading file : ' . $dest_path . '/' . $_FILES['files']['name']['sourcefile1'], 'error');
+ }
+ } //$_FILES['files']['name']['sourcefile1']
+ /* handle result1 file */
+ $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);*/
+ $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');
+ return;
+ } //!$file_data
+ if (($form_state['values']['cur_result1_checkbox'] == 1) && (!$_FILES['files']['name']['result1']))
+ {
+ if (!delete_file($cur_file_id))
+ {
+ drupal_set_message("Error deleting example result 1 file.", 'error');
+ return;
+ } //!delete_file($cur_file_id)
+ } //($form_state['values']['cur_result1_checkbox'] == 1) && (!$_FILES['files']['name']['result1'])
+ } //$cur_file_id > 0
+ if ($_FILES['files']['name']['result1'])
+ {
+ if ($cur_file_id > 0)
+ {
+ if (!delete_file($cur_file_id))
+ {
+ drupal_set_message("Error removing previous example result 1 file.", 'error');
+ return;
+ } //!delete_file($cur_file_id)
+ } //$cur_file_id > 0
+ if (file_exists($root_path . $dest_path . $_FILES['files']['name']['result1']))
+ {
+ drupal_set_message(t("Error uploading result 1 file. File !filename already exists.", array(
+ '!filename' => $_FILES['files']['name']['result1']
+ )), 'error');
+ return;
+ } //file_exists($root_path . $dest_path . $_FILES['files']['name']['result1'])
+ /* uploading file */
+ 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)
+ VALUES (%d, '%s', '%s', '%s', %d, '%s', %d)",
+ $example_data->id,
+ $_FILES['files']['name']['result1'],
+ $dest_path . $_FILES['files']['name']['result1'],
+ $_FILES['files']['type']['result1'],
+ $_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(),
+ ":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');
- }
- }
-
- /* handle result2 file */
- $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);*/
-
- $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');
- return;
- }
- if (($form_state['values']['cur_result2_checkbox'] == 1) && (!$_FILES['files']['name']['result2']))
- {
- if (!delete_file($cur_file_id))
- {
- drupal_set_message("Error deleting example result 2 file.", 'error');
- return;
- }
- }
- }
- if ($_FILES['files']['name']['result2'])
- {
- if ($cur_file_id > 0)
- {
- if (!delete_file($cur_file_id))
- {
- drupal_set_message("Error removing previous example result 2 file.", 'error');
- return;
- }
- }
- if (file_exists($root_path . $dest_path . $_FILES['files']['name']['result2']))
- {
- drupal_set_message(t("Error uploading result 2 file. File !filename already exists.", array('!filename' => $_FILES['files']['name']['result2'])), 'error');
- return;
- }
- /* uploading file */
- 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)
- VALUES (%d, '%s', '%s', '%s', %d, '%s', %d)",
- $example_data->id,
- $_FILES['files']['name']['result2'],
- $dest_path . $_FILES['files']['name']['result2'],
- $_FILES['files']['type']['result2'],
- $_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)";
+ $result = db_query($query, $args, array(
+ 'return' => Database::RETURN_INSERT_ID
+ ));
+ drupal_set_message($_FILES['files']['name']['result1'] . ' uploaded successfully.', 'status');
+ } //move_uploaded_file($_FILES['files']['tmp_name']['result1'], $root_path . $dest_path . $_FILES['files']['name']['result1'])
+ else
+ {
+ drupal_set_message('Error uploading file : ' . $dest_path . '/' . $_FILES['files']['name']['result1'], 'error');
+ }
+ } //$_FILES['files']['name']['result1']
+ /* handle result2 file */
+ $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);*/
+ $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');
+ return;
+ } //!$file_data
+ if (($form_state['values']['cur_result2_checkbox'] == 1) && (!$_FILES['files']['name']['result2']))
+ {
+ if (!delete_file($cur_file_id))
+ {
+ drupal_set_message("Error deleting example result 2 file.", 'error');
+ return;
+ } //!delete_file($cur_file_id)
+ } //($form_state['values']['cur_result2_checkbox'] == 1) && (!$_FILES['files']['name']['result2'])
+ } //$cur_file_id > 0
+ if ($_FILES['files']['name']['result2'])
+ {
+ if ($cur_file_id > 0)
+ {
+ if (!delete_file($cur_file_id))
+ {
+ drupal_set_message("Error removing previous example result 2 file.", 'error');
+ return;
+ } //!delete_file($cur_file_id)
+ } //$cur_file_id > 0
+ if (file_exists($root_path . $dest_path . $_FILES['files']['name']['result2']))
+ {
+ drupal_set_message(t("Error uploading result 2 file. File !filename already exists.", array(
+ '!filename' => $_FILES['files']['name']['result2']
+ )), 'error');
+ return;
+ } //file_exists($root_path . $dest_path . $_FILES['files']['name']['result2'])
+ /* uploading file */
+ 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)
+ VALUES (%d, '%s', '%s', '%s', %d, '%s', %d)",
+ $example_data->id,
+ $_FILES['files']['name']['result2'],
+ $dest_path . $_FILES['files']['name']['result2'],
+ $_FILES['files']['type']['result2'],
+ $_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(),
+ ":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');
- }
- }
-
- /* handle xcos1 file */
- $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);*/
-
- $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');
- return;
- }
- if (($form_state['values']['cur_xcos1_checkbox'] == 1) && (!$_FILES['files']['name']['xcos1']))
- {
- if (!delete_file($cur_file_id))
- {
- drupal_set_message("Error deleting example xcos 1 file.", 'error');
- return;
- }
- }
- }
- if ($_FILES['files']['name']['xcos1'])
- {
- if ($cur_file_id > 0)
- {
- if (!delete_file($cur_file_id))
- {
- drupal_set_message("Error removing previous example xcos 1 file.", 'error');
- return;
- }
- }
- if (file_exists($root_path . $dest_path . $_FILES['files']['name']['xcos1']))
- {
- drupal_set_message(t("Error uploading xcos 1 file. File !filename already exists.", array('!filename' => $_FILES['files']['name']['xcos1'])), 'error');
- return;
- }
- /* uploading file */
- 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)
- VALUES (%d, '%s', '%s', '%s', %d, '%s', %d)",
- $example_data->id,
- $_FILES['files']['name']['xcos1'],
- $dest_path . $_FILES['files']['name']['xcos1'],
- $_FILES['files']['type']['xcos1'],
- $_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)";
+ $result = db_query($query, $args, array(
+ 'return' => Database::RETURN_INSERT_ID
+ ));
+ drupal_set_message($_FILES['files']['name']['result2'] . ' uploaded successfully.', 'status');
+ } //move_uploaded_file($_FILES['files']['tmp_name']['result2'], $root_path . $dest_path . $_FILES['files']['name']['result2'])
+ else
+ {
+ drupal_set_message('Error uploading file : ' . $dest_path . '/' . $_FILES['files']['name']['result2'], 'error');
+ }
+ } //$_FILES['files']['name']['result2']
+ /* handle xcos1 file */
+ $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);*/
+ $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');
+ return;
+ } //!$file_data
+ if (($form_state['values']['cur_xcos1_checkbox'] == 1) && (!$_FILES['files']['name']['xcos1']))
+ {
+ if (!delete_file($cur_file_id))
+ {
+ drupal_set_message("Error deleting example xcos 1 file.", 'error');
+ return;
+ } //!delete_file($cur_file_id)
+ } //($form_state['values']['cur_xcos1_checkbox'] == 1) && (!$_FILES['files']['name']['xcos1'])
+ } //$cur_file_id > 0
+ if ($_FILES['files']['name']['xcos1'])
+ {
+ if ($cur_file_id > 0)
+ {
+ if (!delete_file($cur_file_id))
+ {
+ drupal_set_message("Error removing previous example xcos 1 file.", 'error');
+ return;
+ } //!delete_file($cur_file_id)
+ } //$cur_file_id > 0
+ if (file_exists($root_path . $dest_path . $_FILES['files']['name']['xcos1']))
+ {
+ drupal_set_message(t("Error uploading xcos 1 file. File !filename already exists.", array(
+ '!filename' => $_FILES['files']['name']['xcos1']
+ )), 'error');
+ return;
+ } //file_exists($root_path . $dest_path . $_FILES['files']['name']['xcos1'])
+ /* uploading file */
+ 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)
+ VALUES (%d, '%s', '%s', '%s', %d, '%s', %d)",
+ $example_data->id,
+ $_FILES['files']['name']['xcos1'],
+ $dest_path . $_FILES['files']['name']['xcos1'],
+ $_FILES['files']['type']['xcos1'],
+ $_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(),
+ ":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');
- }
- }
-
- /* handle xcos2 file */
- $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);*/
-
- $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');
- return;
- }
- if (($form_state['values']['cur_xcos2_checkbox'] == 1) && (!$_FILES['files']['name']['xcos2']))
- {
- if (!delete_file($cur_file_id))
- {
- drupal_set_message("Error deleting example xcos 2 file.", 'error');
- return;
- }
- }
- }
- if ($_FILES['files']['name']['xcos2'])
- {
- if ($cur_file_id > 0)
- {
- if (!delete_file($cur_file_id))
- {
- drupal_set_message("Error removing previous example xcos 2 file.", 'error');
- return;
- }
- }
- if (file_exists($root_path . $dest_path . $_FILES['files']['name']['xcos2']))
- {
- drupal_set_message(t("Error uploading xcos 2 file. File !filename already exists.", array('!filename' => $_FILES['files']['name']['xcos2'])), 'error');
- return;
- }
- /* uploading file */
- 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)
- VALUES (%d, '%s', '%s', '%s', %d, '%s', %d)",
- $example_data->id,
- $_FILES['files']['name']['xcos2'],
- $dest_path . $_FILES['files']['name']['xcos2'],
- $_FILES['files']['type']['xcos2'],
- $_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)";
+ $result = db_query($query, $args, array(
+ 'return' => Database::RETURN_INSERT_ID
+ ));
+ drupal_set_message($_FILES['files']['name']['xcos1'] . ' uploaded successfully.', 'status');
+ } //move_uploaded_file($_FILES['files']['tmp_name']['xcos1'], $root_path . $dest_path . $_FILES['files']['name']['xcos1'])
+ else
+ {
+ drupal_set_message('Error uploading file : ' . $dest_path . '/' . $_FILES['files']['name']['xcos1'], 'error');
+ }
+ } //$_FILES['files']['name']['xcos1']
+ /* handle xcos2 file */
+ $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);*/
+ $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');
+ return;
+ } //!$file_data
+ if (($form_state['values']['cur_xcos2_checkbox'] == 1) && (!$_FILES['files']['name']['xcos2']))
+ {
+ if (!delete_file($cur_file_id))
+ {
+ drupal_set_message("Error deleting example xcos 2 file.", 'error');
+ return;
+ } //!delete_file($cur_file_id)
+ } //($form_state['values']['cur_xcos2_checkbox'] == 1) && (!$_FILES['files']['name']['xcos2'])
+ } //$cur_file_id > 0
+ if ($_FILES['files']['name']['xcos2'])
+ {
+ if ($cur_file_id > 0)
+ {
+ if (!delete_file($cur_file_id))
+ {
+ drupal_set_message("Error removing previous example xcos 2 file.", 'error');
+ return;
+ } //!delete_file($cur_file_id)
+ } //$cur_file_id > 0
+ if (file_exists($root_path . $dest_path . $_FILES['files']['name']['xcos2']))
+ {
+ drupal_set_message(t("Error uploading xcos 2 file. File !filename already exists.", array(
+ '!filename' => $_FILES['files']['name']['xcos2']
+ )), 'error');
+ return;
+ } //file_exists($root_path . $dest_path . $_FILES['files']['name']['xcos2'])
+ /* uploading file */
+ 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)
+ VALUES (%d, '%s', '%s', '%s', %d, '%s', %d)",
+ $example_data->id,
+ $_FILES['files']['name']['xcos2'],
+ $dest_path . $_FILES['files']['name']['xcos2'],
+ $_FILES['files']['type']['xcos2'],
+ $_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(),
+ ":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');
- }
- }
-
- /* sending email */
- $email_to = $user->mail;
- $param['example_updated']['example_id'] = $example_id;
- $param['example_updated']['user_id'] = $user->uid;
- if (!drupal_mail('textbook_companion', 'example_updated', $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("Example successfully udpated."), 'status');
+ $result = db_query($query, $args, array(
+ 'return' => Database::RETURN_INSERT_ID
+ ));
+ drupal_set_message($_FILES['files']['name']['xcos2'] . ' uploaded successfully.', 'status');
+ } //move_uploaded_file($_FILES['files']['tmp_name']['xcos2'], $root_path . $dest_path . $_FILES['files']['name']['xcos2'])
+ else
+ {
+ drupal_set_message('Error uploading file : ' . $dest_path . '/' . $_FILES['files']['name']['xcos2'], 'error');
+ }
+ } //$_FILES['files']['name']['xcos2']
+ /* sending email */
+ $email_to = $user->mail;
+ $param['example_updated']['example_id'] = $example_id;
+ $param['example_updated']['user_id'] = $user->uid;
+ if (!drupal_mail('textbook_companion', 'example_updated', $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("Example successfully udpated."), 'status');
}
-
-
/******************************************************************************/
/**************************** EDIT CHAPTER TITLE ******************************/
/******************************************************************************/
-
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);*/
-
+ 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);*/
$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');
- drupal_goto('textbook_companion/code');
- }
- if ($proposal_data->proposal_status != 1 && $proposal_data->proposal_status != 4)
- {
- 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');
- drupal_goto('textbook_companion/code');
- return;
- break;
- case 2:
- drupal_set_message(t('Your proposal has been dis-approved. Please create another proposal ' . l('here', 'proposal') . '.'), 'error');
- drupal_goto('textbook_companion/code');
- return;
- break;
- case 3:
- drupal_set_message(t('Congratulations! You have completed your last book proposal. You have to create another proposal ' . l('here', 'proposal') . '.'), 'status');
- drupal_goto('textbook_companion/code');
- return;
- break;
- default:
- drupal_set_message(t('Invalid proposal state. Please contact site administrator for further information.'), 'error');
- drupal_goto('textbook_companion/code');
- return;
- break;
- }
- }
-
- /*$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);*/
-
+ $proposal_data = $result->fetchObject();
+ if (!$proposal_data)
+ {
+ drupal_set_message("Please submit a " . l('proposal', 'proposal') . ".", 'error');
+ drupal_goto('textbook_companion/code');
+ } //!$proposal_data
+ if ($proposal_data->proposal_status != 1 && $proposal_data->proposal_status != 4)
+ {
+ 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');
+ drupal_goto('textbook_companion/code');
+ return;
+ break;
+ case 2:
+ drupal_set_message(t('Your proposal has been dis-approved. Please create another proposal ' . l('here', 'proposal') . '.'), 'error');
+ drupal_goto('textbook_companion/code');
+ return;
+ break;
+ case 3:
+ drupal_set_message(t('Congratulations! You have completed your last book proposal. You have to create another proposal ' . l('here', 'proposal') . '.'), 'status');
+ drupal_goto('textbook_companion/code');
+ return;
+ break;
+ default:
+ drupal_set_message(t('Invalid proposal state. Please contact site administrator for further information.'), 'error');
+ drupal_goto('textbook_companion/code');
+ return;
+ break;
+ } //$proposal_data->proposal_status
+ } //$proposal_data->proposal_status != 1 && $proposal_data->proposal_status != 4
+ /*$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');
- drupal_goto('textbook_companion/code');
- return;
- }
- /************************ end approve book details **************************/
-
- $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);*/
-
+ $preference_data = $result->fetchObject();
+ if (!$preference_data)
+ {
+ drupal_set_message(t('Invalid Book Preference status. Please contact site administrator for further information.'), 'error');
+ drupal_goto('textbook_companion/code');
+ return;
+ } //!$preference_data
+ /************************ end approve book details **************************/
+ $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);*/
$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;
- }
-
- $form['#redirect'] = 'textbook_companion/code';
-
- $form['book_details']['book'] = array(
- '#type' => 'item',
- '#markup' => $preference_data->book,
- '#title' => t('Title of the Book'),
- );
- $form['contributor_name'] = array(
- '#type' => 'item',
- '#markup' => $proposal_data->full_name,
- '#title' => t('Contributor Name'),
- );
- $form['number'] = array(
- '#type' => 'item',
- '#title' => t('Chapter No'),
- '#markup' => $chapter_data->number,
- );
-
- $form['chapter_title'] = array(
- '#type' => 'textfield',
- '#title' => t('Title of the Chapter'),
- '#size' => 40,
- '#maxlength' => 255,
- '#required' => TRUE,
- '#default_value' => $chapter_data->name,
- );
-
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Submit')
- );
- $form['cancel'] = array(
- '#type' => 'markup',
- '#value' => l(t('Cancel'), 'textbook_companion/code'),
- );
- return $form;
+ $chapter_data = $result->fetchObject();
+ if (!$chapter_data)
+ {
+ drupal_set_message(t('Invalid chapter.'), 'error');
+ drupal_goto('textbook_companion/code');
+ return;
+ } //!$chapter_data
+ $form['#redirect'] = 'textbook_companion/code';
+ $form['book_details']['book'] = array(
+ '#type' => 'item',
+ '#markup' => $preference_data->book,
+ '#title' => t('Title of the Book')
+ );
+ $form['contributor_name'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->full_name,
+ '#title' => t('Contributor Name')
+ );
+ $form['number'] = array(
+ '#type' => 'item',
+ '#title' => t('Chapter No'),
+ '#markup' => $chapter_data->number
+ );
+ $form['chapter_title'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Title of the Chapter'),
+ '#size' => 40,
+ '#maxlength' => 255,
+ '#required' => TRUE,
+ '#default_value' => $chapter_data->name
+ );
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit')
+ );
+ $form['cancel'] = array(
+ '#type' => 'markup',
+ '#value' => l(t('Cancel'), 'textbook_companion/code')
+ );
+ return $form;
}
-
function edit_chapter_title_form_validate($form, &$form_state)
{
- if (!check_name($form_state['values']['chapter_title']))
- form_set_error('chapter_title', t('Title of the Chapter can contain only alphabets, numbers and spaces.'));
+ if (!check_name($form_state['values']['chapter_title']))
+ form_set_error('chapter_title', t('Title of the Chapter can contain only alphabets, numbers and spaces.'));
}
-
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);*/
-
+ 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);*/
$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');
- drupal_goto('textbook_companion/code');
- }
- if ($proposal_data->proposal_status != 1 && $proposal_data->proposal_status != 4)
- {
- 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');
- drupal_goto('textbook_companion/code');
- return;
- break;
- case 2:
- drupal_set_message(t('Your proposal has been dis-approved. Please create another proposal ' . l('here', 'proposal') . '.'), 'error');
- drupal_goto('textbook_companion/code');
- return;
- break;
- case 3:
- drupal_set_message(t('Congratulations! You have completed your last book proposal. You have to create another proposal ' . l('here', 'proposal') . '.'), 'status');
- drupal_goto('textbook_companion/code');
- return;
- break;
- default:
- drupal_set_message(t('Invalid proposal state. Please contact site administrator for further information.'), 'error');
- drupal_goto('textbook_companion/code');
- return;
- break;
- }
- }
-
- /*$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);*/
-
+ $proposal_data = $result->fetchObject();
+ if (!$proposal_data)
+ {
+ drupal_set_message("Please submit a " . l('proposal', 'proposal') . ".", 'error');
+ drupal_goto('textbook_companion/code');
+ } //!$proposal_data
+ if ($proposal_data->proposal_status != 1 && $proposal_data->proposal_status != 4)
+ {
+ 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');
+ drupal_goto('textbook_companion/code');
+ return;
+ break;
+ case 2:
+ drupal_set_message(t('Your proposal has been dis-approved. Please create another proposal ' . l('here', 'proposal') . '.'), 'error');
+ drupal_goto('textbook_companion/code');
+ return;
+ break;
+ case 3:
+ drupal_set_message(t('Congratulations! You have completed your last book proposal. You have to create another proposal ' . l('here', 'proposal') . '.'), 'status');
+ drupal_goto('textbook_companion/code');
+ return;
+ break;
+ default:
+ drupal_set_message(t('Invalid proposal state. Please contact site administrator for further information.'), 'error');
+ drupal_goto('textbook_companion/code');
+ return;
+ break;
+ } //$proposal_data->proposal_status
+ } //$proposal_data->proposal_status != 1 && $proposal_data->proposal_status != 4
+ /*$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');
- drupal_goto('textbook_companion/code');
- return;
- }
- /************************ end approve book details **************************/
-
- $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);*/
-
+ $preference_data = $result->fetchObject();
+ if (!$preference_data)
+ {
+ drupal_set_message(t('Invalid Book Preference status. Please contact site administrator for further information.'), 'error');
+ drupal_goto('textbook_companion/code');
+ return;
+ } //!$preference_data
+ /************************ end approve book details **************************/
+ $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);*/
$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);*/
+ $chapter_data = $result->fetchObject();
+ if (!$chapter_data)
+ {
+ drupal_set_message(t('Invalid chapter.'), 'error');
+ drupal_goto('textbook_companion/code');
+ return;
+ } //!$chapter_data
+ /*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'],
+ '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');
+ drupal_set_message(t('Title of the Chapter updated.'), 'status');
+ drupal_goto('textbook_companion/code');
}
-
-
/******************************************************************************/
/************************** GENERAL FUNCTIONS *********************************/
/******************************************************************************/
-
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");*/
-
+ $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");*/
$query = db_select('textbook_companion_preference');
$query->fields('textbook_companion_preference');
$or = db_or();
@@ -1406,35 +1335,42 @@ function _list_of_book_titles()
$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;
+ while ($book_titles_data = $book_titles_q->fetchObject())
+ {
+ $book_titles[$book_titles_data->id] = $book_titles_data->book . ' (Written by ' . $book_titles_data->author . ')';
+ } //$book_titles_data = $book_titles_q->fetchObject()
+ return $book_titles;
}
-
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");*/
+ $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");*/
$query = db_select('textbook_companion_dependency_files', 'tcdp');
$query->fields('tcdp');
- $query->fields('tcp', array('book', 'author','publisher', 'edition', 'year'));
+ $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 .= ' ===>[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);
+ while ($book_dependency_files_data = $book_dependency_files_q->fetchObject())
+ {
+ $temp_caption = '';
+ if ($book_dependency_files_data->caption)
+ $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;
+ } //$book_dependency_files_data = $book_dependency_files_q->fetchObject()
+ return array(
+ $book_dependency_files,
+ $book_dependency_files_class
+ );
}
-
diff --git a/editcodeadmin.inc b/editcodeadmin.inc
index b1903de..02f2259 100755
--- a/editcodeadmin.inc
+++ b/editcodeadmin.inc
@@ -1,513 +1,482 @@
<?php
// $Id$
-
/******************************************************************************/
/***************************** EDIT EXAMPLE ***********************************/
/******************************************************************************/
-
function upload_examples_admin_edit_form($form, $form_state)
{
- global $user;
- $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);*/
+ global $user;
+ $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);*/
$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');
- drupal_goto('');
- return;
- }
-
- /* get examples files */
- $source_file = ""; $source_id = 0;
- $result1_file = ""; $result1_id = 0;
- $result2_file = ""; $result2_id = 0;
- $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);*/
-
+ $example_data = $example_q->fetchObject();
+ if (!$example_q)
+ {
+ drupal_set_message(t("Invalid example selected."), 'error');
+ drupal_goto('');
+ return;
+ } //!$example_q
+ /* get examples files */
+ $source_file = "";
+ $source_id = 0;
+ $result1_file = "";
+ $result1_id = 0;
+ $result2_file = "";
+ $result2_id = 0;
+ $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);*/
$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")
- {
- $source_file = l($example_files_data->filename, 'download/file/' . $example_files_data->id);
- $source_file_id = $example_files_data->id;
- }
- if ($example_files_data->filetype == "R")
- {
- if (strlen($result1_file) == 0)
- {
- $result1_file = l($example_files_data->filename, 'download/file/' . $example_files_data->id);
- $result1_file_id = $example_files_data->id;
- } else {
- $result2_file = l($example_files_data->filename, 'download/file/' . $example_files_data->id);
- $result2_file_id = $example_files_data->id;
- }
- }
- if ($example_files_data->filetype == "X")
- {
- if (strlen($xcos1_file) <= 0)
- {
- $xcos1_file = l($example_files_data->filename, 'download/file/' . $example_files_data->id);
- $xcos1_file_id = $example_files_data->id;
- } else {
- $xcos2_file = l($example_files_data->filename, 'download/file/' . $example_files_data->id);
- $xcos2_file_id = $example_files_data->id;
- }
- }
- }
-
- /* 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);*/
+ $example_files_q = $query->execute();
+ while ($example_files_data = $example_files_q->fetchObject())
+ {
+ if ($example_files_data->filetype == "S")
+ {
+ $source_file = l($example_files_data->filename, 'download/file/' . $example_files_data->id);
+ $source_file_id = $example_files_data->id;
+ } //$example_files_data->filetype == "S"
+ if ($example_files_data->filetype == "R")
+ {
+ if (strlen($result1_file) == 0)
+ {
+ $result1_file = l($example_files_data->filename, 'download/file/' . $example_files_data->id);
+ $result1_file_id = $example_files_data->id;
+ } //strlen($result1_file) == 0
+ else
+ {
+ $result2_file = l($example_files_data->filename, 'download/file/' . $example_files_data->id);
+ $result2_file_id = $example_files_data->id;
+ }
+ } //$example_files_data->filetype == "R"
+ if ($example_files_data->filetype == "X")
+ {
+ if (strlen($xcos1_file) <= 0)
+ {
+ $xcos1_file = l($example_files_data->filename, 'download/file/' . $example_files_data->id);
+ $xcos1_file_id = $example_files_data->id;
+ } //strlen($xcos1_file) <= 0
+ else
+ {
+ $xcos2_file = l($example_files_data->filename, 'download/file/' . $example_files_data->id);
+ $xcos2_file_id = $example_files_data->id;
+ }
+ } //$example_files_data->filetype == "X"
+ } //$example_files_data = $example_files_q->fetchObject()
+ /* 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);*/
$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');
- drupal_goto('');
- return;
- }
-
- /* 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);*/
-
+ $chapter_data = $result->fetchObject();
+ if (!$chapter_data)
+ {
+ drupal_set_message(t("Invalid chapter selected."), 'error');
+ drupal_goto('');
+ return;
+ } //!$chapter_data
+ /* 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);*/
$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');
- drupal_goto('');
- return;
- }
-
- /* 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);*/
-
+ $preference_data = $result->fetchObject();
+ if (!$preference_data)
+ {
+ drupal_set_message(t("Invalid book selected."), 'error');
+ drupal_goto('');
+ return;
+ } //!$preference_data
+ /* 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);*/
$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');
- drupal_goto('');
- return;
- }
-
- $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() {
- $('#edit-existing-depfile-dep-book-title').change(function() {
- var dep_selected = '';
- /* showing and hiding relevant files */
- /* $('.form-checkboxes .option').hide();
- $('.form-checkboxes .option').each(function(index) {
- var activeClass = $('#edit-existing-depfile-dep-book-title').val();
- if ($(this).children().hasClass(activeClass)) {
- $(this).show();
- }
- if ($(this).children().attr('checked') == true) {
- dep_selected += $(this).children().next().text() + '<br />';
- }
- });
- /* showing list of already existing dependencies */
- /* $('#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');
- });";
- 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',
- '#markup' => $preference_data->book,
- '#title' => t('Title of the Book'),
- );
- $form['contributor_name'] = array(
- '#type' => 'item',
- '#markup' => $proposal_data->full_name,
- '#title' => t('Contributor Name'),
- );
- $form['number'] = array(
- '#type' => 'item',
- '#title' => t('Chapter No'),
- '#markup' => $chapter_data->number,
- );
- $form['name'] = array(
- '#type' => 'item',
- '#title' => t('Title of the Chapter'),
- '#markup' => $chapter_data->name,
- );
- $form['example_number'] = array(
- '#type' => 'item',
- '#title' => t('Example No'),
- '#markup' => $example_data->number,
- );
- $form['example_caption'] = array(
- '#type' => 'textfield',
- '#title' => t('Caption'),
- '#size' => 40,
- '#maxlength' => 255,
- '#required' => TRUE,
- '#default_value' => $example_data->caption,
- );
- $form['example_warning'] = array(
- '#type' => 'item',
- '#title' => t('You should upload all the files (main or source files, result files, executable file if any)'),
- '#prefix' => '<div style="color:red">',
- '#suffix' => '</div>',
- );
-
- $form['sourcefile'] = array(
- '#type' => 'fieldset',
- '#title' => t('Main or Source Files'),
- '#collapsible' => FALSE,
- '#collapsed' => FALSE,
- );
- if ($source_file)
- {
- $form['sourcefile']['cur_source'] = array(
- '#type' => 'item',
- '#title' => t('Existing Main or Source File'),
- '#markup' => $source_file,
- );
- $form['sourcefile']['cur_source_checkbox'] = array(
- '#type' => 'checkbox',
- '#title' => t('Delete Existing Main or Source File'),
- '#description' => 'Check to delete the existing Main or Source file.',
- );
- $form['sourcefile']['sourcefile1'] = array(
- '#type' => 'file',
- '#title' => t('Upload New Main or Source File'),
- '#size' => 48,
- '#description' => t("Upload new Main or Source file above if you want to replace the existing file. Leave blank if you want to keep using the existing file. <br />") .
- t('Allowed file extensions : ') . variable_get('textbook_companion_source_extensions', ''),
- );
- $form['sourcefile']['cur_source_file_id'] = array(
- '#type' => 'hidden',
- '#value' => $source_file_id,
- );
- } else {
- $form['sourcefile']['sourcefile1'] = array(
- '#type' => 'file',
- '#title' => t('Upload New Main or Source File'),
- '#size' => 48,
- '#description' => t('Allowed file extensions : ') . variable_get('textbook_companion_source_extensions', ''),
- );
- }
-
- $form['dep_files'] = array(
- '#type' => 'item',
- '#title' => t('Dependency Files'),
- );
-
- /************ START OF EXISTING DEPENDENCIES **************/
-
- $dependency_files = array();
-
- /*$dependency_q = db_query("SELECT * FROM {textbook_companion_example_dependency} WHERE example_id = %d", $example_data->id);*/
+ $proposal_data = $result->fetchObject();
+ if (!$proposal_data)
+ {
+ drupal_set_message(t("Invalid proposal selected."), 'error');
+ drupal_goto('');
+ return;
+ } //!$proposal_data
+ $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() {
+ $('#edit-existing-depfile-dep-book-title').change(function() {
+ var dep_selected = '';
+ /* showing and hiding relevant files */
+ /* $('.form-checkboxes .option').hide();
+ $('.form-checkboxes .option').each(function(index) {
+ var activeClass = $('#edit-existing-depfile-dep-book-title').val();
+ if ($(this).children().hasClass(activeClass)) {
+ $(this).show();
+ }
+ if ($(this).children().attr('checked') == true) {
+ dep_selected += $(this).children().next().text() + '<br />';
+ }
+ });
+ /* showing list of already existing dependencies */
+ /* $('#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');
+ });";
+ 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',
+ '#markup' => $preference_data->book,
+ '#title' => t('Title of the Book')
+ );
+ $form['contributor_name'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->full_name,
+ '#title' => t('Contributor Name')
+ );
+ $form['number'] = array(
+ '#type' => 'item',
+ '#title' => t('Chapter No'),
+ '#markup' => $chapter_data->number
+ );
+ $form['name'] = array(
+ '#type' => 'item',
+ '#title' => t('Title of the Chapter'),
+ '#markup' => $chapter_data->name
+ );
+ $form['example_number'] = array(
+ '#type' => 'item',
+ '#title' => t('Example No'),
+ '#markup' => $example_data->number
+ );
+ $form['example_caption'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Caption'),
+ '#size' => 40,
+ '#maxlength' => 255,
+ '#required' => TRUE,
+ '#default_value' => $example_data->caption
+ );
+ $form['example_warning'] = array(
+ '#type' => 'item',
+ '#title' => t('You should upload all the files (main or source files, result files, executable file if any)'),
+ '#prefix' => '<div style="color:red">',
+ '#suffix' => '</div>'
+ );
+ $form['sourcefile'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Main or Source Files'),
+ '#collapsible' => FALSE,
+ '#collapsed' => FALSE
+ );
+ if ($source_file)
+ {
+ $form['sourcefile']['cur_source'] = array(
+ '#type' => 'item',
+ '#title' => t('Existing Main or Source File'),
+ '#markup' => $source_file
+ );
+ $form['sourcefile']['cur_source_checkbox'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Delete Existing Main or Source File'),
+ '#description' => 'Check to delete the existing Main or Source file.'
+ );
+ $form['sourcefile']['sourcefile1'] = array(
+ '#type' => 'file',
+ '#title' => t('Upload New Main or Source File'),
+ '#size' => 48,
+ '#description' => t("Upload new Main or Source file above if you want to replace the existing file. Leave blank if you want to keep using the existing file. <br />") . t('Allowed file extensions : ') . variable_get('textbook_companion_source_extensions', '')
+ );
+ $form['sourcefile']['cur_source_file_id'] = array(
+ '#type' => 'hidden',
+ '#value' => $source_file_id
+ );
+ } //$source_file
+ else
+ {
+ $form['sourcefile']['sourcefile1'] = array(
+ '#type' => 'file',
+ '#title' => t('Upload New Main or Source File'),
+ '#size' => 48,
+ '#description' => t('Allowed file extensions : ') . variable_get('textbook_companion_source_extensions', '')
+ );
+ }
+ $form['dep_files'] = array(
+ '#type' => 'item',
+ '#title' => t('Dependency Files')
+ );
+ /************ START OF EXISTING DEPENDENCIES **************/
+ $dependency_files = array();
+ /*$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;
- }
-
- /* existing dependencies */
- $form['existing_depfile'] = array(
- '#type' => 'fieldset',
- '#title' => t('Use Already Existing Dependency Files'),
- '#collapsible' => FALSE,
- '#collapsed' => FALSE,
- '#prefix' => '<div id="existing-depfile-wrapper">',
- '#suffix' => '</div>',
- '#tree' => TRUE,
- );
-
- /* 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_book_title'] = array(
- '#type' => 'select',
- '#title' => t('Title of the Book'),
- '#options' => _list_of_book_titles(),
- );
-
- 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,
- '#multiple' => TRUE,
- '#default_value' => $dependency_files,
- );
-
- $form['existing_depfile']['dep_upload'] = array(
- '#type' => 'item',
- '#markup' => l('Upload New Depedency Files', 'textbook_companion/code/upload_dep'),
- );
- /************ END OF EXISTING DEPENDENCIES **************/
-
- $form['result'] = array(
- '#type' => 'fieldset',
- '#title' => t('Result Files'),
- '#collapsible' => FALSE,
- '#collapsed' => FALSE,
- );
- if ($result1_file)
- {
- $form['result']['cur_result1'] = array(
- '#type' => 'item',
- '#title' => t('Existing Result File 1'),
- '#markup' => $result1_file,
- );
- $form['result']['cur_result1_checkbox'] = array(
- '#type' => 'checkbox',
- '#title' => t('Delete Existing Result File 1'),
- '#description' => 'Check to delete the existing Result file.',
- );
- $form['result']['result1'] = array(
- '#type' => 'file',
- '#title' => t('Upload New Result File 1'),
- '#size' => 48,
- '#description' => t("Upload new Result file above if you want to replace the existing file, leave blank if you want to keep using the existing file. <br />") .
- t('Allowed file extensions : ') . variable_get('textbook_companion_result_extensions', ''),
- );
- $form['result']['cur_result1_file_id'] = array(
- '#type' => 'hidden',
- '#value' => $result1_file_id,
- );
- } else {
- $form['result']['result1'] = array(
- '#type' => 'file',
- '#title' => t('Upload New Result File 1'),
- '#size' => 48,
- '#description' => t('Allowed file extensions : ') . variable_get('textbook_companion_result_extensions', ''),
- );
- }
-
- $form['result']['br'] = array(
- '#type' => 'item',
- '#markup' => "<br />",
- );
-
- if ($result2_file)
- {
- $form['result']['cur_result2'] = array(
- '#type' => 'item',
- '#title' => t('Existing Result File 2'),
- '#markup' => $result2_file,
- );
- $form['result']['cur_result2_checkbox'] = array(
- '#type' => 'checkbox',
- '#title' => t('Delete Existing Result File 2'),
- '#description' => 'Check to delete the existing Result file.',
- );
- $form['result']['result2'] = array(
- '#type' => 'file',
- '#title' => t('Upload New Result file 2'),
- '#size' => 48,
- '#description' => t("Upload new Result file above if you want to replace the existing file. Leave blank if you want to keep using the existing file. <br />") .
- t('Allowed file extensions : ') . variable_get('textbook_companion_result_extensions', ''),
- );
- $form['result']['cur_result2_file_id'] = array(
- '#type' => 'hidden',
- '#value' => $result2_file_id,
- );
- } else {
- $form['result']['result2'] = array(
- '#type' => 'file',
- '#title' => t('Upload New Result file 2'),
- '#size' => 48,
- '#description' => t('Allowed file extensions : ') . variable_get('textbook_companion_result_extensions', ''),
- );
- }
- $form['xcos'] = array(
- '#type' => 'fieldset',
- '#title' => t('XCOS Files'),
- '#collapsible' => FALSE,
- '#collapsed' => FALSE,
- );
- if ($xcos1_file)
- {
- $form['xcos']['cur_xcos1'] = array(
- '#type' => 'item',
- '#title' => t('Existing xcos File 1'),
- '#markup' => $xcos1_file,
- );
- $form['xcos']['cur_xcos1_checkbox'] = array(
- '#type' => 'checkbox',
- '#title' => t('Delete Existing xcos File 1'),
- '#description' => 'Check to delete the existing xcos file.',
- );
- $form['xcos']['xcos1'] = array(
- '#type' => 'file',
- '#title' => t('Upload New xcos file 1'),
- '#size' => 48,
- '#description' => t("Upload new xcos file above if you want to replace the existing file. Leave blank if you want to keep using the existing file. <br />") .
- t('Allowed file extensions : ') . variable_get('textbook_companion_xcos_extensions', ''),
- );
- $form['sourcefile']['cur_xcos1_file_id'] = array(
- '#type' => 'hidden',
- '#value' => $xcos1_file_id,
- );
- } else {
- $form['xcos']['xcos1'] = array(
- '#type' => 'file',
- '#title' => t('Upload New xcos file 1'),
- '#size' => 48,
- '#description' => t('Allowed file extensions : ') . variable_get('textbook_companion_xcos_extensions', ''),
- );
- }
-
- $form['xcos']['br'] = array(
- '#type' => 'item',
- '#markup' => "<br />",
- );
-
- if ($xcos2_file)
- {
- $form['xcos']['cur_xcos2'] = array(
- '#type' => 'item',
- '#title' => t('Existing xcos File 2'),
- '#markup' => $xcos2_file,
- );
- $form['xcos']['cur_xcos2_checkbox'] = array(
- '#type' => 'checkbox',
- '#title' => t('Delete Existing xcos File 2'),
- '#description' => 'Check to delete the existing xcos file.',
- );
- $form['xcos']['xcos2'] = array(
- '#type' => 'file',
- '#title' => t('Upload New xcos file 2'),
- '#size' => 48,
- '#description' => t("Upload new xcos file above if you want to replace the existing file. Leave blank if you want to keep using the existing file. <br />") .
- t('Allowed file extensions : ') . variable_get('textbook_companion_xcos_extensions', ''),
- );
- $form['xcos']['cur_xcos2_file_id'] = array(
- '#type' => 'hidden',
- '#value' => $xcos2_file_id,
- );
- } else {
- $form['xcos']['xcos2'] = array(
- '#type' => 'file',
- '#title' => t('Upload New xcos file 2'),
- '#size' => 48,
- '#description' => t('Allowed file extensions : ') . variable_get('textbook_companion_xcos_extensions', ''),
- );
- }
-
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Submit')
- );
-
- $form['cancel'] = array(
- '#type' => 'markup',
- '#value' => l(t('Cancel'), 'textbook_companion/code'),
- );
- return $form;
+ while ($dependency_data = $dependency_q->fetchObject())
+ {
+ $dependency_files[] = $dependency_data->dependency_id;
+ } //$dependency_data = $dependency_q->fetchObject()
+ /* existing dependencies */
+ $form['existing_depfile'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Use Already Existing Dependency Files'),
+ '#collapsible' => FALSE,
+ '#collapsed' => FALSE,
+ '#prefix' => '<div id="existing-depfile-wrapper">',
+ '#suffix' => '</div>',
+ '#tree' => TRUE
+ );
+ /* 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_book_title'] = array(
+ '#type' => 'select',
+ '#title' => t('Title of the Book'),
+ '#options' => _list_of_book_titles()
+ );
+ 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,
+ '#multiple' => TRUE,
+ '#default_value' => $dependency_files
+ );
+ $form['existing_depfile']['dep_upload'] = array(
+ '#type' => 'item',
+ '#markup' => l('Upload New Depedency Files', 'textbook_companion/code/upload_dep')
+ );
+ /************ END OF EXISTING DEPENDENCIES **************/
+ $form['result'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Result Files'),
+ '#collapsible' => FALSE,
+ '#collapsed' => FALSE
+ );
+ if ($result1_file)
+ {
+ $form['result']['cur_result1'] = array(
+ '#type' => 'item',
+ '#title' => t('Existing Result File 1'),
+ '#markup' => $result1_file
+ );
+ $form['result']['cur_result1_checkbox'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Delete Existing Result File 1'),
+ '#description' => 'Check to delete the existing Result file.'
+ );
+ $form['result']['result1'] = array(
+ '#type' => 'file',
+ '#title' => t('Upload New Result File 1'),
+ '#size' => 48,
+ '#description' => t("Upload new Result file above if you want to replace the existing file, leave blank if you want to keep using the existing file. <br />") . t('Allowed file extensions : ') . variable_get('textbook_companion_result_extensions', '')
+ );
+ $form['result']['cur_result1_file_id'] = array(
+ '#type' => 'hidden',
+ '#value' => $result1_file_id
+ );
+ } //$result1_file
+ else
+ {
+ $form['result']['result1'] = array(
+ '#type' => 'file',
+ '#title' => t('Upload New Result File 1'),
+ '#size' => 48,
+ '#description' => t('Allowed file extensions : ') . variable_get('textbook_companion_result_extensions', '')
+ );
+ }
+ $form['result']['br'] = array(
+ '#type' => 'item',
+ '#markup' => "<br />"
+ );
+ if ($result2_file)
+ {
+ $form['result']['cur_result2'] = array(
+ '#type' => 'item',
+ '#title' => t('Existing Result File 2'),
+ '#markup' => $result2_file
+ );
+ $form['result']['cur_result2_checkbox'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Delete Existing Result File 2'),
+ '#description' => 'Check to delete the existing Result file.'
+ );
+ $form['result']['result2'] = array(
+ '#type' => 'file',
+ '#title' => t('Upload New Result file 2'),
+ '#size' => 48,
+ '#description' => t("Upload new Result file above if you want to replace the existing file. Leave blank if you want to keep using the existing file. <br />") . t('Allowed file extensions : ') . variable_get('textbook_companion_result_extensions', '')
+ );
+ $form['result']['cur_result2_file_id'] = array(
+ '#type' => 'hidden',
+ '#value' => $result2_file_id
+ );
+ } //$result2_file
+ else
+ {
+ $form['result']['result2'] = array(
+ '#type' => 'file',
+ '#title' => t('Upload New Result file 2'),
+ '#size' => 48,
+ '#description' => t('Allowed file extensions : ') . variable_get('textbook_companion_result_extensions', '')
+ );
+ }
+ $form['xcos'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('XCOS Files'),
+ '#collapsible' => FALSE,
+ '#collapsed' => FALSE
+ );
+ if ($xcos1_file)
+ {
+ $form['xcos']['cur_xcos1'] = array(
+ '#type' => 'item',
+ '#title' => t('Existing xcos File 1'),
+ '#markup' => $xcos1_file
+ );
+ $form['xcos']['cur_xcos1_checkbox'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Delete Existing xcos File 1'),
+ '#description' => 'Check to delete the existing xcos file.'
+ );
+ $form['xcos']['xcos1'] = array(
+ '#type' => 'file',
+ '#title' => t('Upload New xcos file 1'),
+ '#size' => 48,
+ '#description' => t("Upload new xcos file above if you want to replace the existing file. Leave blank if you want to keep using the existing file. <br />") . t('Allowed file extensions : ') . variable_get('textbook_companion_xcos_extensions', '')
+ );
+ $form['sourcefile']['cur_xcos1_file_id'] = array(
+ '#type' => 'hidden',
+ '#value' => $xcos1_file_id
+ );
+ } //$xcos1_file
+ else
+ {
+ $form['xcos']['xcos1'] = array(
+ '#type' => 'file',
+ '#title' => t('Upload New xcos file 1'),
+ '#size' => 48,
+ '#description' => t('Allowed file extensions : ') . variable_get('textbook_companion_xcos_extensions', '')
+ );
+ }
+ $form['xcos']['br'] = array(
+ '#type' => 'item',
+ '#markup' => "<br />"
+ );
+ if ($xcos2_file)
+ {
+ $form['xcos']['cur_xcos2'] = array(
+ '#type' => 'item',
+ '#title' => t('Existing xcos File 2'),
+ '#markup' => $xcos2_file
+ );
+ $form['xcos']['cur_xcos2_checkbox'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Delete Existing xcos File 2'),
+ '#description' => 'Check to delete the existing xcos file.'
+ );
+ $form['xcos']['xcos2'] = array(
+ '#type' => 'file',
+ '#title' => t('Upload New xcos file 2'),
+ '#size' => 48,
+ '#description' => t("Upload new xcos file above if you want to replace the existing file. Leave blank if you want to keep using the existing file. <br />") . t('Allowed file extensions : ') . variable_get('textbook_companion_xcos_extensions', '')
+ );
+ $form['xcos']['cur_xcos2_file_id'] = array(
+ '#type' => 'hidden',
+ '#value' => $xcos2_file_id
+ );
+ } //$xcos2_file
+ else
+ {
+ $form['xcos']['xcos2'] = array(
+ '#type' => 'file',
+ '#title' => t('Upload New xcos file 2'),
+ '#size' => 48,
+ '#description' => t('Allowed file extensions : ') . variable_get('textbook_companion_xcos_extensions', '')
+ );
+ }
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit')
+ );
+ $form['cancel'] = array(
+ '#type' => 'markup',
+ '#value' => l(t('Cancel'), 'textbook_companion/code')
+ );
+ return $form;
}
-
function upload_examples_admin_edit_form_validate($form, &$form_state)
{
- if (!check_name($form_state['values']['example_caption']))
- form_set_error('example_caption', t('Example Caption can contain only alphabets, numbers and spaces.'));
-
- if (isset($_FILES['files']))
- {
- /* check for valid filename extensions */
- foreach ($_FILES['files']['name'] as $file_form_name => $file_name)
- {
- if ($file_name)
- {
- /* checking file type */
- if (strstr($file_form_name, 'source'))
- $file_type = 'S';
- else if (strstr($file_form_name, 'result'))
- $file_type = 'R';
- else if (strstr($file_form_name, 'xcos'))
- $file_type = 'X';
- else
- $file_type = 'U';
-
- $allowed_extensions_str = '';
- switch ($file_type)
- {
- case 'S':
- $allowed_extensions_str = variable_get('textbook_companion_source_extensions', '');
- break;
- case 'R':
- $allowed_extensions_str = variable_get('textbook_companion_result_extensions', '');
- break;
- case 'X':
- $allowed_extensions_str = variable_get('textbook_companion_xcos_extensions', '');
- break;
- }
-
- $allowed_extensions = explode(',' , $allowed_extensions_str);
- $temp_extension = end(explode('.', strtolower($_FILES['files']['name'][$file_form_name])));
- if (!in_array($temp_extension, $allowed_extensions))
- form_set_error($file_form_name, t('Only file with ' . $allowed_extensions_str . ' extensions can be uploaded.'));
- if ($_FILES['files']['size'][$file_form_name] <= 0)
- form_set_error($file_form_name, t('File size cannot be zero.'));
-
- /* check if valid file name */
- if (!textbook_companion_check_valid_filename($_FILES['files']['name'][$file_form_name]))
- form_set_error($file_form_name, t('Invalid file name specified. Only alphabets, numbers and underscore is allowed as a valid filename.'));
- }
- }
- }
-
- /* add javascript again for automatic book title, check if example uploaded, dependency selection effects */
- $chapter_name_js = " $(document).ready(function() {
+ if (!check_name($form_state['values']['example_caption']))
+ form_set_error('example_caption', t('Example Caption can contain only alphabets, numbers and spaces.'));
+ if (isset($_FILES['files']))
+ {
+ /* check for valid filename extensions */
+ foreach ($_FILES['files']['name'] as $file_form_name => $file_name)
+ {
+ if ($file_name)
+ {
+ /* checking file type */
+ if (strstr($file_form_name, 'source'))
+ $file_type = 'S';
+ else if (strstr($file_form_name, 'result'))
+ $file_type = 'R';
+ else if (strstr($file_form_name, 'xcos'))
+ $file_type = 'X';
+ else
+ $file_type = 'U';
+ $allowed_extensions_str = '';
+ switch ($file_type)
+ {
+ case 'S':
+ $allowed_extensions_str = variable_get('textbook_companion_source_extensions', '');
+ break;
+ case 'R':
+ $allowed_extensions_str = variable_get('textbook_companion_result_extensions', '');
+ break;
+ case 'X':
+ $allowed_extensions_str = variable_get('textbook_companion_xcos_extensions', '');
+ break;
+ } //$file_type
+ $allowed_extensions = explode(',', $allowed_extensions_str);
+ $temp_extension = end(explode('.', strtolower($_FILES['files']['name'][$file_form_name])));
+ if (!in_array($temp_extension, $allowed_extensions))
+ form_set_error($file_form_name, t('Only file with ' . $allowed_extensions_str . ' extensions can be uploaded.'));
+ if ($_FILES['files']['size'][$file_form_name] <= 0)
+ form_set_error($file_form_name, t('File size cannot be zero.'));
+ /* check if valid file name */
+ if (!textbook_companion_check_valid_filename($_FILES['files']['name'][$file_form_name]))
+ form_set_error($file_form_name, t('Invalid file name specified. Only alphabets, numbers and underscore is allowed as a valid filename.'));
+ } //$file_name
+ } //$_FILES['files']['name'] as $file_form_name => $file_name
+ } //isset($_FILES['files'])
+ /* add javascript again for automatic book title, check if example uploaded, dependency selection effects */
+ $chapter_name_js = " $(document).ready(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);
@@ -542,551 +511,526 @@ function upload_examples_admin_edit_form_validate($form, &$form_state)
});
$('#edit-existing-depfile-dep-book-title').trigger('change');
});";
- drupal_add_js($chapter_name_js, 'inline', 'header');
+ drupal_add_js($chapter_name_js, 'inline', 'header');
}
-
function upload_examples_admin_edit_form_submit($form, &$form_state)
{
- global $user;
- $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);*/
-
+ global $user;
+ $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);*/
$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');
- drupal_goto('');
- return;
- }
-
- /* 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);*/
-
+ $example_data = $example_q->fetchObject();
+ if (!$example_q)
+ {
+ drupal_set_message(t("Invalid example selected."), 'error');
+ drupal_goto('');
+ return;
+ } //!$example_q
+ /* 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);*/
$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');
- drupal_goto('');
- return;
- }
-
- /* 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);*/
-
+ if (!$chapter_data)
+ {
+ drupal_set_message(t("Invalid chapter selected."), 'error');
+ drupal_goto('');
+ return;
+ } //!$chapter_data
+ /* 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);*/
$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');
- drupal_goto('');
- return;
- }
-
- /* 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);*/
+ $preference_data = $result->fetchObject();
+ if (!$preference_data)
+ {
+ drupal_set_message(t("Invalid book selected."), 'error');
+ drupal_goto('');
+ return;
+ } //!$preference_data
+ /* 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);*/
$query = db_select('textbook_companion_proposal');
$query->fields('textbook_companion_proposal');
- $query->condition('id', $preference_data->proposal_id);
+ $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');
- drupal_goto('');
- return;
- }
- $user_data = user_load($proposal_data->uid);
-
- /* creating directories */
- $root_path = textbook_companion_path();
-
- $dest_path = $preference_data->id . '/';
- if (!is_dir($root_path . $dest_path))
- mkdir($root_path . $dest_path);
-
- $dest_path .= 'CH' . $chapter_data->number . '/';
- if (!is_dir($root_path . $dest_path))
- mkdir($root_path . $dest_path);
-
- $dest_path .= 'EX' . $example_data->number . '/';
- if (!is_dir($root_path . $dest_path))
- 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);*/
-
+ $proposal_data = $result->fetchObject();
+ if (!$proposal_data)
+ {
+ drupal_set_message(t("Invalid proposal selected."), 'error');
+ drupal_goto('');
+ return;
+ } //!$proposal_data
+ $user_data = user_load($proposal_data->uid);
+ /* creating directories */
+ $root_path = textbook_companion_path();
+ $dest_path = $preference_data->id . '/';
+ if (!is_dir($root_path . $dest_path))
+ mkdir($root_path . $dest_path);
+ $dest_path .= 'CH' . $chapter_data->number . '/';
+ if (!is_dir($root_path . $dest_path))
+ mkdir($root_path . $dest_path);
+ $dest_path .= 'EX' . $example_data->number . '/';
+ if (!is_dir($root_path . $dest_path))
+ 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);*/
$query = db_update('textbook_companion_example');
$query->fields(array(
- 'caption' => $form_state['values']['example_caption'],
+ '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);*/
+ /* handling dependencies */
+ /*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)
- 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)
+ 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)
+ 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));
- }
- }
-
- /* handle source file */
- $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);*/
-
- $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');
- return;
- }
- if (($form_state['values']['cur_source_checkbox'] == 1) && (!$_FILES['files']['name']['sourcefile1']))
- {
- if (!delete_file($cur_file_id))
- {
- drupal_set_message("Error deleting example source file.", 'error');
- return;
- }
- }
- }
- if ($_FILES['files']['name']['sourcefile1'])
- {
- if ($cur_file_id > 0)
- {
- if (!delete_file($cur_file_id))
- {
- drupal_set_message("Error removing previous example source file.", 'error');
- return;
- }
- }
- if (file_exists($root_path . $dest_path . $_FILES['files']['name']['sourcefile1']))
- {
- drupal_set_message(t("Error uploading source file. File !filename already exists.", array('!filename' => $_FILES['files']['name']['sourcefile1'])), 'error');
- return;
- }
- /* uploading file */
- 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)
- VALUES (%d, '%s', '%s', '%s', %d, '%s', %d)",
- $example_data->id,
- $_FILES['files']['name']['sourcefile1'],
- $dest_path . $_FILES['files']['name']['sourcefile1'],
- $_FILES['files']['type']['sourcefile1'],
- $_FILES['files']['size']['sourcefile1'],
- 'S',
- time()
- );*/
-
- $query = "INSERT INTO {textbook_companion_example_files} (example_id, filename, filepath, filemime, filesize, filetype, timestamp)
+ ":example_id" => $example_data->id,
+ ":dependency_id" => $row,
+ ":approval_status" => 0,
+ "::timestamp" => time()
+ );
+ $result = db_query($query, $args, array(
+ 'return' => Database::RETURN_INSERT_ID
+ ));
+ } //$row > 0
+ } //$form_state['values']['existing_depfile']['dep_chapter_example_files'] as $row
+ /* handle source file */
+ $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);*/
+ $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');
+ return;
+ } //!$file_data
+ if (($form_state['values']['cur_source_checkbox'] == 1) && (!$_FILES['files']['name']['sourcefile1']))
+ {
+ if (!delete_file($cur_file_id))
+ {
+ drupal_set_message("Error deleting example source file.", 'error');
+ return;
+ } //!delete_file($cur_file_id)
+ } //($form_state['values']['cur_source_checkbox'] == 1) && (!$_FILES['files']['name']['sourcefile1'])
+ } //$cur_file_id > 0
+ if ($_FILES['files']['name']['sourcefile1'])
+ {
+ if ($cur_file_id > 0)
+ {
+ if (!delete_file($cur_file_id))
+ {
+ drupal_set_message("Error removing previous example source file.", 'error');
+ return;
+ } //!delete_file($cur_file_id)
+ } //$cur_file_id > 0
+ if (file_exists($root_path . $dest_path . $_FILES['files']['name']['sourcefile1']))
+ {
+ drupal_set_message(t("Error uploading source file. File !filename already exists.", array(
+ '!filename' => $_FILES['files']['name']['sourcefile1']
+ )), 'error');
+ return;
+ } //file_exists($root_path . $dest_path . $_FILES['files']['name']['sourcefile1'])
+ /* uploading file */
+ 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)
+ VALUES (%d, '%s', '%s', '%s', %d, '%s', %d)",
+ $example_data->id,
+ $_FILES['files']['name']['sourcefile1'],
+ $dest_path . $_FILES['files']['name']['sourcefile1'],
+ $_FILES['files']['type']['sourcefile1'],
+ $_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');
- }
- }
-
- /* handle result1 file */
- $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);*/
-
- $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');
- return;
- }
- if (($form_state['values']['cur_result1_checkbox'] == 1) && (!$_FILES['files']['name']['result1']))
- {
- if (!delete_file($cur_file_id))
- {
- drupal_set_message("Error deleting example result 1 file.", 'error');
- return;
- }
- }
- }
- if ($_FILES['files']['name']['result1'])
- {
- if ($cur_file_id > 0)
- {
- if (!delete_file($cur_file_id))
- {
- drupal_set_message("Error removing previous example result 1 file.", 'error');
- return;
- }
- }
- if (file_exists($root_path . $dest_path . $_FILES['files']['name']['result1']))
- {
- drupal_set_message(t("Error uploading result 1 file. File !filename already exists.", array('!filename' => $_FILES['files']['name']['result1'])), 'error');
- return;
- }
- /* uploading file */
- 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)
- VALUES (%d, '%s', '%s', '%s', %d, '%s', %d)",
- $example_data->id,
- $_FILES['files']['name']['result1'],
- $dest_path . $_FILES['files']['name']['result1'],
- $_FILES['files']['type']['result1'],
- $_FILES['files']['size']['result1'],
- 'R',
- time()
- );*/
-
- $query = "INSERT INTO {textbook_companion_example_files} (example_id, filename, filepath, filemime, filesize, filetype, timestamp)
+ ":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');
+ } //move_uploaded_file($_FILES['files']['tmp_name']['sourcefile1'], $root_path . $dest_path . $_FILES['files']['name']['sourcefile1'])
+ else
+ {
+ drupal_set_message('Error uploading file : ' . $dest_path . '/' . $_FILES['files']['name']['sourcefile1'], 'error');
+ }
+ } //$_FILES['files']['name']['sourcefile1']
+ /* handle result1 file */
+ $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);*/
+ $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');
+ return;
+ } //!$file_data
+ if (($form_state['values']['cur_result1_checkbox'] == 1) && (!$_FILES['files']['name']['result1']))
+ {
+ if (!delete_file($cur_file_id))
+ {
+ drupal_set_message("Error deleting example result 1 file.", 'error');
+ return;
+ } //!delete_file($cur_file_id)
+ } //($form_state['values']['cur_result1_checkbox'] == 1) && (!$_FILES['files']['name']['result1'])
+ } //$cur_file_id > 0
+ if ($_FILES['files']['name']['result1'])
+ {
+ if ($cur_file_id > 0)
+ {
+ if (!delete_file($cur_file_id))
+ {
+ drupal_set_message("Error removing previous example result 1 file.", 'error');
+ return;
+ } //!delete_file($cur_file_id)
+ } //$cur_file_id > 0
+ if (file_exists($root_path . $dest_path . $_FILES['files']['name']['result1']))
+ {
+ drupal_set_message(t("Error uploading result 1 file. File !filename already exists.", array(
+ '!filename' => $_FILES['files']['name']['result1']
+ )), 'error');
+ return;
+ } //file_exists($root_path . $dest_path . $_FILES['files']['name']['result1'])
+ /* uploading file */
+ 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)
+ VALUES (%d, '%s', '%s', '%s', %d, '%s', %d)",
+ $example_data->id,
+ $_FILES['files']['name']['result1'],
+ $dest_path . $_FILES['files']['name']['result1'],
+ $_FILES['files']['type']['result1'],
+ $_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');
- }
- }
-
- /* handle result2 file */
- $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);*/
-
- $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');
- return;
- }
- if (($form_state['values']['cur_result2_checkbox'] == 1) && (!$_FILES['files']['name']['result2']))
- {
- if (!delete_file($cur_file_id))
- {
- drupal_set_message("Error deleting example result 2 file.", 'error');
- return;
- }
- }
- }
- if ($_FILES['files']['name']['result2'])
- {
- if ($cur_file_id > 0)
- {
- if (!delete_file($cur_file_id))
- {
- drupal_set_message("Error removing previous example result 2 file.", 'error');
- return;
- }
- }
- if (file_exists($root_path . $dest_path . $_FILES['files']['name']['result2']))
- {
- drupal_set_message(t("Error uploading result 2 file. File !filename already exists.", array('!filename' => $_FILES['files']['name']['result2'])), 'error');
- return;
- }
- /* uploading file */
- 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)
- VALUES (%d, '%s', '%s', '%s', %d, '%s', %d)",
- $example_data->id,
- $_FILES['files']['name']['result2'],
- $dest_path . $_FILES['files']['name']['result2'],
- $_FILES['files']['type']['result2'],
- $_FILES['files']['size']['result2'],
- 'R',
- time()
- );*/
-
- $query = "INSERT INTO {textbook_companion_example_files} (example_id, filename, filepath, filemime, filesize, filetype, timestamp)
+ ":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');
+ } //move_uploaded_file($_FILES['files']['tmp_name']['result1'], $root_path . $dest_path . $_FILES['files']['name']['result1'])
+ else
+ {
+ drupal_set_message('Error uploading file : ' . $dest_path . '/' . $_FILES['files']['name']['result1'], 'error');
+ }
+ } //$_FILES['files']['name']['result1']
+ /* handle result2 file */
+ $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);*/
+ $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');
+ return;
+ } //!$file_data
+ if (($form_state['values']['cur_result2_checkbox'] == 1) && (!$_FILES['files']['name']['result2']))
+ {
+ if (!delete_file($cur_file_id))
+ {
+ drupal_set_message("Error deleting example result 2 file.", 'error');
+ return;
+ } //!delete_file($cur_file_id)
+ } //($form_state['values']['cur_result2_checkbox'] == 1) && (!$_FILES['files']['name']['result2'])
+ } //$cur_file_id > 0
+ if ($_FILES['files']['name']['result2'])
+ {
+ if ($cur_file_id > 0)
+ {
+ if (!delete_file($cur_file_id))
+ {
+ drupal_set_message("Error removing previous example result 2 file.", 'error');
+ return;
+ } //!delete_file($cur_file_id)
+ } //$cur_file_id > 0
+ if (file_exists($root_path . $dest_path . $_FILES['files']['name']['result2']))
+ {
+ drupal_set_message(t("Error uploading result 2 file. File !filename already exists.", array(
+ '!filename' => $_FILES['files']['name']['result2']
+ )), 'error');
+ return;
+ } //file_exists($root_path . $dest_path . $_FILES['files']['name']['result2'])
+ /* uploading file */
+ 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)
+ VALUES (%d, '%s', '%s', '%s', %d, '%s', %d)",
+ $example_data->id,
+ $_FILES['files']['name']['result2'],
+ $dest_path . $_FILES['files']['name']['result2'],
+ $_FILES['files']['type']['result2'],
+ $_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');
- }
- }
-
- /* handle xcos1 file */
- $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);*/
-
- $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');
- return;
- }
- if (($form_state['values']['cur_xcos1_checkbox'] == 1) && (!$_FILES['files']['name']['xcos1']))
- {
- if (!delete_file($cur_file_id))
- {
- drupal_set_message("Error deleting example xcos 1 file.", 'error');
- return;
- }
- }
- }
- if ($_FILES['files']['name']['xcos1'])
- {
- if ($cur_file_id > 0)
- {
- if (!delete_file($cur_file_id))
- {
- drupal_set_message("Error removing previous example xcos 1 file.", 'error');
- return;
- }
- }
- if (file_exists($root_path . $dest_path . $_FILES['files']['name']['xcos1']))
- {
- drupal_set_message(t("Error uploading xcos 1 file. File !filename already exists.", array('!filename' => $_FILES['files']['name']['xcos1'])), 'error');
- return;
- }
- /* uploading file */
- 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)
- VALUES (%d, '%s', '%s', '%s', %d, '%s', %d)",
- $example_data->id,
- $_FILES['files']['name']['xcos1'],
- $dest_path . $_FILES['files']['name']['xcos1'],
- $_FILES['files']['type']['xcos1'],
- $_FILES['files']['size']['xcos1'],
- 'X',
- time()
- );*/
-
- $query = "INSERT INTO {textbook_companion_example_files} (example_id, filename, filepath, filemime, filesize, filetype, timestamp)
+ ":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');
+ } //move_uploaded_file($_FILES['files']['tmp_name']['result2'], $root_path . $dest_path . $_FILES['files']['name']['result2'])
+ else
+ {
+ drupal_set_message('Error uploading file : ' . $dest_path . '/' . $_FILES['files']['name']['result2'], 'error');
+ }
+ } //$_FILES['files']['name']['result2']
+ /* handle xcos1 file */
+ $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);*/
+ $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');
+ return;
+ } //!$file_data
+ if (($form_state['values']['cur_xcos1_checkbox'] == 1) && (!$_FILES['files']['name']['xcos1']))
+ {
+ if (!delete_file($cur_file_id))
+ {
+ drupal_set_message("Error deleting example xcos 1 file.", 'error');
+ return;
+ } //!delete_file($cur_file_id)
+ } //($form_state['values']['cur_xcos1_checkbox'] == 1) && (!$_FILES['files']['name']['xcos1'])
+ } //$cur_file_id > 0
+ if ($_FILES['files']['name']['xcos1'])
+ {
+ if ($cur_file_id > 0)
+ {
+ if (!delete_file($cur_file_id))
+ {
+ drupal_set_message("Error removing previous example xcos 1 file.", 'error');
+ return;
+ } //!delete_file($cur_file_id)
+ } //$cur_file_id > 0
+ if (file_exists($root_path . $dest_path . $_FILES['files']['name']['xcos1']))
+ {
+ drupal_set_message(t("Error uploading xcos 1 file. File !filename already exists.", array(
+ '!filename' => $_FILES['files']['name']['xcos1']
+ )), 'error');
+ return;
+ } //file_exists($root_path . $dest_path . $_FILES['files']['name']['xcos1'])
+ /* uploading file */
+ 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)
+ VALUES (%d, '%s', '%s', '%s', %d, '%s', %d)",
+ $example_data->id,
+ $_FILES['files']['name']['xcos1'],
+ $dest_path . $_FILES['files']['name']['xcos1'],
+ $_FILES['files']['type']['xcos1'],
+ $_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');
- }
- }
-
- /* handle xcos2 file */
- $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);*/
-
- $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');
- return;
- }
- if (($form_state['values']['cur_xcos2_checkbox'] == 1) && (!$_FILES['files']['name']['xcos2']))
- {
- if (!delete_file($cur_file_id))
- {
- drupal_set_message("Error deleting example xcos 2 file.", 'error');
- return;
- }
- }
- }
- if ($_FILES['files']['name']['xcos2'])
- {
- if ($cur_file_id > 0)
- {
- if (!delete_file($cur_file_id))
- {
- drupal_set_message("Error removing previous example xcos 2 file.", 'error');
- return;
- }
- }
- if (file_exists($root_path . $dest_path . $_FILES['files']['name']['xcos2']))
- {
- drupal_set_message(t("Error uploading xcos 2 file. File !filename already exists.", array('!filename' => $_FILES['files']['name']['xcos2'])), 'error');
- return;
- }
- /* uploading file */
- 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)
- VALUES (%d, '%s', '%s', '%s', %d, '%s', %d)",
- $example_data->id,
- $_FILES['files']['name']['xcos2'],
- $dest_path . $_FILES['files']['name']['xcos2'],
- $_FILES['files']['type']['xcos2'],
- $_FILES['files']['size']['xcos2'],
- 'X',
- time()
- );*/
-
- $query = "INSERT INTO {textbook_companion_example_files} (example_id, filename, filepath, filemime, filesize, filetype, timestamp)
+ ":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');
+ } //move_uploaded_file($_FILES['files']['tmp_name']['xcos1'], $root_path . $dest_path . $_FILES['files']['name']['xcos1'])
+ else
+ {
+ drupal_set_message('Error uploading file : ' . $dest_path . '/' . $_FILES['files']['name']['xcos1'], 'error');
+ }
+ } //$_FILES['files']['name']['xcos1']
+ /* handle xcos2 file */
+ $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);*/
+ $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');
+ return;
+ } //!$file_data
+ if (($form_state['values']['cur_xcos2_checkbox'] == 1) && (!$_FILES['files']['name']['xcos2']))
+ {
+ if (!delete_file($cur_file_id))
+ {
+ drupal_set_message("Error deleting example xcos 2 file.", 'error');
+ return;
+ } //!delete_file($cur_file_id)
+ } //($form_state['values']['cur_xcos2_checkbox'] == 1) && (!$_FILES['files']['name']['xcos2'])
+ } //$cur_file_id > 0
+ if ($_FILES['files']['name']['xcos2'])
+ {
+ if ($cur_file_id > 0)
+ {
+ if (!delete_file($cur_file_id))
+ {
+ drupal_set_message("Error removing previous example xcos 2 file.", 'error');
+ return;
+ } //!delete_file($cur_file_id)
+ } //$cur_file_id > 0
+ if (file_exists($root_path . $dest_path . $_FILES['files']['name']['xcos2']))
+ {
+ drupal_set_message(t("Error uploading xcos 2 file. File !filename already exists.", array(
+ '!filename' => $_FILES['files']['name']['xcos2']
+ )), 'error');
+ return;
+ } //file_exists($root_path . $dest_path . $_FILES['files']['name']['xcos2'])
+ /* uploading file */
+ 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)
+ VALUES (%d, '%s', '%s', '%s', %d, '%s', %d)",
+ $example_data->id,
+ $_FILES['files']['name']['xcos2'],
+ $dest_path . $_FILES['files']['name']['xcos2'],
+ $_FILES['files']['type']['xcos2'],
+ $_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');
- }
- }
-
- /* sending email */
- $email_to = $user_data->mail;
- $param['example_updated_admin']['example_id'] = $example_id;
- $param['example_updated_admin']['user_id'] = $proposal_data->uid;
- if (!drupal_mail('textbook_companion', 'example_updated_admin', $email_to, language_default(), $params, variable_get('textbook_companion_from_email', NULL), TRUE))
- drupal_set_message('Error sending email message.', 'error');
-
- drupal_set_message(t("Example successfully udpated."), 'status');
+ ":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');
+ } //move_uploaded_file($_FILES['files']['tmp_name']['xcos2'], $root_path . $dest_path . $_FILES['files']['name']['xcos2'])
+ else
+ {
+ drupal_set_message('Error uploading file : ' . $dest_path . '/' . $_FILES['files']['name']['xcos2'], 'error');
+ }
+ } //$_FILES['files']['name']['xcos2']
+ /* sending email */
+ $email_to = $user_data->mail;
+ $param['example_updated_admin']['example_id'] = $example_id;
+ $param['example_updated_admin']['user_id'] = $proposal_data->uid;
+ if (!drupal_mail('textbook_companion', 'example_updated_admin', $email_to, language_default(), $params, variable_get('textbook_companion_from_email', NULL), TRUE))
+ drupal_set_message('Error sending email message.', 'error');
+ drupal_set_message(t("Example successfully udpated."), 'status');
}
-
/******************************************************************************/
/************************** GENERAL FUNCTIONS *********************************/
/******************************************************************************/
-
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");*/
+ $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");*/
$query = db_select('textbook_companion_preference');
$query->fields('textbook_companion_preference');
$or = db_or();
@@ -1095,34 +1039,31 @@ function _list_of_book_titles()
$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;
+ while ($book_titles_data = $book_titles_q->fetchObject())
+ {
+ $book_titles[$book_titles_data->id] = $book_titles_data->book . ' (Written by ' . $book_titles_data->author . ')';
+ } //$book_titles_data = $book_titles_q->fetchObject()
+ return $book_titles;
}
-
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");*/
-
+ $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");*/
$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)
- $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);
- $book_dependency_files_class[$book_dependency_files_data->id] = $book_dependency_files_data->preference_id;
- }
- return array($book_dependency_files, $book_dependency_files_class);
+ 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);
+ $book_dependency_files_class[$book_dependency_files_data->id] = $book_dependency_files_data->preference_id;
+ } //$book_dependency_files_data = $book_dependency_files_q->fetchObject()
+ return array(
+ $book_dependency_files,
+ $book_dependency_files_class
+ );
}
-
diff --git a/email.inc b/email.inc
new file mode 100644
index 0000000..03e415e
--- /dev/null
+++ b/email.inc
@@ -0,0 +1,1064 @@
+<?php
+/**
+ * Implementation of hook_mail().
+ */
+function textbook_companion_mail($key, &$message, $params)
+{
+ global $user;
+ $language = $message['language'];
+ /*$tbc_bcc_emails = array(
+ 'Bcc' => variable_get('textbook_companion_emails', ''),
+ );*/
+ switch ($key)
+ {
+ case 'proposal_received':
+ // 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);*/
+ $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();
+ $samplecodefilename = "";
+ if (strlen($proposal_data->samplefilepath) >= 5)
+ {
+ $samplecodefilename = substr($proposal_data->samplefilepath, strrpos($proposal_data->samplefilepath, '/') + 1);
+ } //strlen($proposal_data->samplefilepath) >= 5
+ else
+ {
+ $samplecodefilename = "Not provided";
+ }
+ /*$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 = "
+ SELECT * FROM list_of_category loc
+ JOIN textbook_companion_preference tcp ON loc.category_id = tcp.category
+ WHERE proposal_id = :proposal_id AND pref_number = :pref_number LIMIT 1
+ ";
+ $args = array(
+ ':proposal_id' => $params['proposal_received']['proposal_id'],
+ ':pref_number' => 1
+ );
+ $preference1_q = db_query($query, $args);
+ $preference1_data = $preference1_q->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 = "
+ SELECT * FROM list_of_category loc
+ JOIN textbook_companion_preference tcp ON loc.category_id = tcp.category
+ WHERE proposal_id = :proposal_id AND pref_number = :pref_number LIMIT 1
+ ";
+ $args = array(
+ ':proposal_id' => $params['proposal_received']['proposal_id'],
+ ':pref_number' => 2
+ );
+ $preference2_q = db_query($query, $args);
+ $preference2_data = $preference2_q->fetchObject();
+ if($preference2_data->book){
+ $book_preference2 = '
+Book Preference 2 :-
+Title of the book : ' . $preference2_data->book . '
+Author name : ' . $preference2_data->author . '
+ISBN No. : ' . $preference2_data->isbn . '
+Publisher and Place : ' . $preference2_data->publisher . '
+Edition : ' . $preference2_data->edition . '
+Year of publication : ' . $preference2_data->year . '
+Category : ' . $preference2_data->category_name . '
+';
+ }
+ $query = "
+ SELECT * FROM list_of_category loc
+ JOIN textbook_companion_preference tcp ON loc.category_id = tcp.category
+ WHERE proposal_id = :proposal_id AND pref_number = :pref_number LIMIT 1
+ ";
+ $args = array(
+ ':proposal_id' => $params['proposal_received']['proposal_id'],
+ ':pref_number' => 3
+ );
+ $preference3_q = db_query($query, $args);
+ $preference3_data = $preference3_q->fetchObject();
+ if($preference3_data->book){
+ $book_preference3 = '
+Book Preference 3 :-
+Title of the book : ' . $preference3_data->book . '
+Author name : ' . $preference3_data->author . '
+ISBN No. : ' . $preference3_data->isbn . '
+Publisher and Place : ' . $preference3_data->publisher . '
+Edition : ' . $preference3_data->edition . '
+Year of publication : ' . $preference3_data->year . '
+Category : ' . $preference3_data->category_name . '
+';
+ }
+ /*$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['headers'] = $params['proposal_received']['headers'];
+ $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:
+
+Full Name : ' . $proposal_data->full_name . '
+Email : ' . $user_data->mail . '
+Mobile : ' . $proposal_data->mobile . '
+Course : ' . $proposal_data->course . '
+Department/Branch : ' . $proposal_data->branch . '
+University/Institute : ' . $proposal_data->university . '
+College Teacher / Professor : ' . $proposal_data->faculty . '
+Reviewer : ' . $proposal_data->reviewer . '
+Expected date of completion : ' . date('d-m-Y', $proposal_data->proposed_completion_date) . '
+
+Your Book Preferences :
+
+Book Preference 1 :-
+Title of the book : ' . $preference1_data->book . '
+Author name : ' . $preference1_data->author . '
+ISBN No. : ' . $preference1_data->isbn . '
+Publisher and Place : ' . $preference1_data->publisher . '
+Edition : ' . $preference1_data->edition . '
+Year of publication : ' . $preference1_data->year . '
+Category : ' . $preference1_data->category_name . '
+'. ' '.
+$book_preference2
+.' '.
+$book_preference2
+.'
+
+Uploaded Sample Code : ' . $samplecodefilename . '
+
+Your proposal is under review and you will soon receive an email from us regarding the same.
+
+Best Wishes,
+
+Scilab TBC Team,
+FOSSEE, IIT Bombay', 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);*/
+ $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();
+ if($preference2_data->book){
+ $book_preference2 = '
+Book Preference 2 :-
+Title of the book : ' . $preference2_data->book . '
+Author name : ' . $preference2_data->author . '
+ISBN No. : ' . $preference2_data->isbn . '
+Publisher and Place : ' . $preference2_data->publisher . '
+Edition : ' . $preference2_data->edition . '
+Year of publication : ' . $preference2_data->year . '
+Category : ' . $preference2_data->category_name . '
+';
+ }
+ /*$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();
+ if($preference3_data->book){
+ $book_preference3 = '
+Book Preference 3 :-
+Title of the book : ' . $preference3_data->book . '
+Author name : ' . $preference3_data->author . '
+ISBN No. : ' . $preference3_data->isbn . '
+Publisher and Place : ' . $preference3_data->publisher . '
+Edition : ' . $preference3_data->edition . '
+Year of publication : ' . $preference3_data->year . '
+Category : ' . $preference3_data->category_name . '
+';
+ }
+ $user_data = user_load($params['proposal_disapproved']['user_id']);
+ $message['headers'] = $params['proposal_disapproved']['headers'];
+ $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'] = array(
+ 'body' => t('
+Dear !user_name,
+
+Your following book proposal has been disapproved:
+
+Reason for disapproval: ' . $proposal_data->message . '
+
+Full Name : ' . $proposal_data->full_name . '
+Email : ' . $user_data->mail . '
+Mobile : ' . $proposal_data->mobile . '
+Course : ' . $proposal_data->course . '
+Department/Branch : ' . $proposal_data->branch . '
+University/Institute : ' . $proposal_data->university . '
+College Teacher / Professor : ' . $proposal_data->faculty . '
+Reviewer : ' . $proposal_data->reviewer . '
+Expected date of completion : ' . date('d-m-Y', $proposal_data->proposed_completion_date) . '
+
+Your Book Preferences :
+
+Book Preference 1 :-
+Title of the book : ' . $preference1_data->book . '
+Author name : ' . $preference1_data->author . '
+ISBN No. : ' . $preference1_data->isbn . '
+Publisher and Place : ' . $preference1_data->publisher . '
+Edition : ' . $preference1_data->edition . '
+Year of publication : ' . $preference1_data->year . '
+Category : ' . $preference1_data->category_name . ''.
+
+$book_preference2
+.' '.
+$book_preference2
+.'
+
+Best Wishes,
+
+Scilab TBC Team,
+FOSSEE, IIT Bombay', array(
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name
+ ), array(
+ 'language' => $language->language
+ ))
+ );
+ } //$proposal_data->proposal_type != 1
+ else
+ {
+ //Non AICTE book proposal dissaprove//
+ $message['body'] = array(
+ 'body' => t('
+Dear !user_name,
+
+Your following book proposal has been disapproved:
+
+Reason for disapproval: ' . $proposal_data->message . '
+
+Full Name : ' . $proposal_data->full_name . '
+Email : ' . $user_data->mail . '
+Mobile : ' . $proposal_data->mobile . '
+Course : ' . $proposal_data->course . '
+Department/Branch : ' . $proposal_data->branch . '
+University/Institute : ' . $proposal_data->university . '
+College Teacher / Professor : ' . $proposal_data->faculty . '
+Reviewer : ' . $proposal_data->reviewer . '
+Expected date of completion : ' . date('d-m-Y', $proposal_data->completion_date) . '
+
+Your Book Preferences :
+
+Book Preference :-
+Title of the book : ' . $preference1_data->book . '
+Author name : ' . $preference1_data->author . '
+ISBN No. : ' . $preference1_data->isbn . '
+Publisher and Place : ' . $preference1_data->publisher . '
+Edition : ' . $preference1_data->edition . '
+Year of publication : ' . $preference1_data->year . '
+
+
+
+Best Wishes,
+
+Scilab TBC Team,
+FOSSEE, IIT Bombay', array(
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name
+ ), array(
+ 'language' => $language->language
+ ))
+ );
+ }
+ break;
+ /* Non AICTE Book Proposal */
+ case 'nonaicte_proposal_received':
+ // 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);*/
+ $query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal');
+ $query->condition('id', $params['nonaicte_proposal_received']['proposal_id']);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $proposal_data = $result->fetchObject();
+ $samplecodefilename = "";
+ if (strlen($proposal_data->samplefilepath) >= 5)
+ {
+ $samplecodefilename = substr($proposal_data->samplefilepath, strrpos($proposal_data->samplefilepath, '/') + 1);
+ } //strlen($proposal_data->samplefilepath) >= 5
+ else
+ {
+ $samplecodefilename = "Not provided";
+ }
+ $query = "
+ SELECT * FROM list_of_category loc
+ JOIN textbook_companion_preference tcp ON loc.category_id = tcp.category
+ WHERE proposal_id = :proposal_id AND pref_number = :pref_number LIMIT 1
+ ";
+ $args = array(
+ ':proposal_id' => $params['nonaicte_proposal_received']['proposal_id'],
+ ':pref_number' => 1
+ );
+ $preference1_q = db_query($query, $args);
+ $preference1_data = $preference1_q->fetchObject();
+ $user_data = user_load($params['nonaicte_proposal_received']['user_id']);
+ $message['headers'] = $params['nonaicte_proposal_received']['headers'];
+ $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:
+
+Full Name : ' . $proposal_data->full_name . '
+Email : ' . $user_data->mail . '
+Mobile : ' . $proposal_data->mobile . '
+Course : ' . $proposal_data->course . '
+Department/Branch : ' . $proposal_data->branch . '
+University/Institute : ' . $proposal_data->university . '
+College Teacher / Professor : ' . $proposal_data->faculty . '
+Reviewer : ' . $proposal_data->reviewer . '
+Expected date of completion : ' . date('d-m-Y', $proposal_data->proposed_completion_date) . '
+
+Your Non AICTE Book Preferences:
+
+Book Preference :-
+Title of the book : ' . $preference1_data->book . '
+Author name : ' . $preference1_data->author . '
+ISBN No. : ' . $preference1_data->isbn . '
+Publisher and Place : ' . $preference1_data->publisher . '
+Edition : ' . $preference1_data->edition . '
+Year of publication : ' . $preference1_data->year . '
+Category : ' . $preference1_data->category_name . '
+
+
+Uploaded Sample Code : ' . $samplecodefilename . '
+
+Your proposal is under review and you will soon receive an email from us regarding the same.
+
+Best Wishes,
+
+Scilab TBC Team,
+FOSSEE, IIT Bombay', array(
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name
+ ), array(
+ 'language' => $language->language
+ ))
+ );
+ break;
+ case 'nonaicte_proposal_to_pi':
+ /************ fetch proposal data ****************/
+ $query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal');
+ $query->condition('id', $params['nonaicte_proposal_received']['proposal_id']);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $proposal_data = $result->fetchObject();
+ /************ fetch book preference data ****************/
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('proposal_id', $params['nonaicte_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['nonaicte_proposal_received']['user_id']);
+ $message['headers'] = $params['nonaicte_proposal_received']['headers'];
+ $message['subject'] = t('[!site_name] New Non AICTE book suggestion has been received', array(
+ '!site_name' => variable_get('site_name', '')
+ ), array(
+ 'language' => $language->language
+ ));
+ /******************* Email Template for not aicte book suggestion **************************/
+ $message['body'] = array(
+ 'body' => t('
+Dear all,
+
+We have received following Non AICTE book suggestion:
+
+Full Name : ' . $proposal_data->full_name . '
+University/Institute :' . $proposal_data->university . '
+
+
+Reason(s): ' . $proposal_data->reason . '
+
+
+Your Non AICTE Book Preference :
+
+Title of the book : ' . $preference1_data->book . '
+Author name : ' . $preference1_data->author . '
+ISBN No. : ' . $preference1_data->isbn . '
+Publisher and Place : ' . $preference1_data->publisher . '
+Edition : ' . $preference1_data->edition . '
+Year of publication : ' . $preference1_data->year . '
+
+Reference :- ' . $proposal_data->reference
+ //Please click here to provide your feedback: http://scilab.in/comments
+ . '
+
+Best Wishes,
+
+Scilab TBC Team,
+FOSSEE, IIT Bombay', array(
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name
+ ), array(
+ 'language' => $language->language
+ ))
+ );
+ break;
+ case 'proposal_approved':
+ $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();
+ $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['headers'] = $params['proposal_approved']['headers'];
+ $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:
+
+Full Name : ' . $proposal_data->full_name . '
+Email : ' . $user_data->mail . '
+Mobile : ' . $proposal_data->mobile . '
+Course : ' . $proposal_data->course . '
+Department/Branch : ' . $proposal_data->branch . '
+University/Institute : ' . $proposal_data->university . '
+College Teacher / Professor : ' . $proposal_data->faculty . '
+Reviewer : ' . $proposal_data->reviewer . '
+Expected date of completion : ' . date('d-m-Y', $proposal_data->proposed_completion_date) . '
+
+Title of the book : ' . $approved_preference_data->book . '
+Author name : ' . $approved_preference_data->author . '
+ISBN No. : ' . $approved_preference_data->isbn . '
+Publisher and Place : ' . $approved_preference_data->publisher . '
+Edition : ' . $approved_preference_data->edition . '
+Year of publication : ' . $approved_preference_data->year . '
+
+According the new Textbook Companion procedure, a student doing a textbook companion is not required to have a mentor. For more details check the links given below.
+http://scilab.in/tbc_honorarium
+http://scilab.in/Textbook_Companion_Internship
+
+Please contact us by sending an e-mail to textbook@scilab.in in case you wish to cancel this book proposal.
+
+Best Wishes,
+
+Scilab TBC Team,
+FOSSEE, IIT Bombay', 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);*/
+ $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['headers'] = $params['proposal_completed']['headers'];
+ $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:
+
+Full Name : ' . $proposal_data->full_name . '
+Email : ' . $user_data->mail . '
+Mobile : ' . $proposal_data->mobile . '
+Course : ' . $proposal_data->course . '
+Department/Branch : ' . $proposal_data->branch . '
+University/Institute : ' . $proposal_data->university . '
+College Teacher / Professor : ' . $proposal_data->faculty . '
+Reviewer : ' . $proposal_data->reviewer . '
+Proposed date of completion : ' . date('d-m-Y', $proposal_data->proposed_completion_date) . '
+Actual date of completion : ' . date('d-m-Y', $proposal_data->completion_date) . '
+
+Title of the book : ' . $approved_preference_data->book . '
+Author name : ' . $approved_preference_data->author . '
+ISBN No. : ' . $approved_preference_data->isbn . '
+Publisher and Place : ' . $approved_preference_data->publisher . '
+Edition : ' . $approved_preference_data->edition . '
+Year of publication : ' . $approved_preference_data->year . '
+
+Your book is now available at following link to download.
+
+http://scilab.in/textbook_run/' . $approved_preference_data->id . '
+
+Now you should be able to propose a new book...
+
+Best Wishes,
+
+Scilab TBC Team,
+FOSSEE, IIT Bombay', 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);*/
+ $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();
+ $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();
+ $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();
+ $user_data = user_load($params['example_uploaded']['user_id']);
+ $message['headers'] = $params['example_uploaded']['headers'];
+ $message['subject'] = t('[!site_name] You have uploaded example for Textbook Companion', array(
+ '!site_name' => variable_get('site_name', '')
+ ), array(
+ 'language' => $language->language
+ ));
+ $message['body'] = array(
+ 'body' => t('
+Dear !user_name,
+
+You have uploaded the following solution :
+
+Title of the book : ' . $preference_data->book . '
+Title of the chapter : ' . $chapter_data->name . '
+Example number : ' . $example_data->number . '
+Caption : ' . $example_data->caption . '
+
+You shall be notified after the solution is reviewed
+
+Best Wishes,
+
+Scilab TBC Team,
+FOSSEE, IIT Bombay', 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);*/
+ $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();
+ $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();
+ $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();
+ $user_data = user_load($params['example_updated']['user_id']);
+ $message['headers'] = $params['example_updated']['headers'];
+ $message['subject'] = t('[!site_name] You have updated example for Textbook Companion', 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:
+
+Title of the book : ' . $preference_data->book . '
+Title of the chapter : ' . $chapter_data->name . '
+Example number : ' . $example_data->number . '
+Caption : ' . $example_data->caption . '
+
+The example is still under review. You will be notified when it has been approved.
+
+Best Wishes,
+
+Scilab TBC Team,
+FOSSEE, IIT Bombay', 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);*/
+ $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', '')
+ ), array(
+ 'language' => $language->language
+ ));
+ $message['body'] = array(
+ 'body' => t('
+Dear !user_name,
+
+Reviewer have updated the following example:
+
+Example number : ' . $example_data->number . '
+Caption : ' . $example_data->caption . '
+
+Best Wishes,
+
+Scilab TBC Team,
+FOSSEE, IIT Bombay', 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);*/
+ $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['headers'] = $params['example_approved']['headers'];
+ $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:
+
+Example number : ' . $example_data->number . '
+Caption : ' . $example_data->caption . '
+
+Best Wishes,
+
+Scilab TBC Team,
+FOSSEE, IIT Bombay', array(
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name
+ ), array(
+ 'language' => $language->language
+ ))
+ );
+ break;
+ case 'example_disapproved':
+ // bcc to textbook_companion_emails
+ $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', '')
+ ), array(
+ 'language' => $language->language
+ ));
+ $message['body'] = array(
+ 'body' => t('
+Dear !user_name,
+
+Your following example has been disapproved:
+
+Example number : ' . $params['example_disapproved']['example_number'] . '
+Caption : ' . $params['example_disapproved']['example_caption'] . '
+
+Reason for dis-approval : ' . $params['example_disapproved']['message'] . '
+
+Best Wishes,
+
+Scilab TBC Team,
+FOSSEE, IIT Bombay', array(
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name
+ ), array(
+ 'language' => $language->language
+ ))
+ );
+ break;
+ case 'example_deleted_user':
+ // bcc to textbook_companion_emails
+ // $message['headers'] += $tbc_bcc_emails;
+ $user_data = user_load($params['example_deleted_user']['user_id']);
+ $message['headers'] = $params['example_deleted_user']['headers'];
+ $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 :
+
+Title of the Book : ' . $params['example_deleted_user']['book_title'] . '
+Title of the Chapter : ' . $params['example_deleted_user']['chapter_title'] . '
+Example number : ' . $params['example_deleted_user']['example_number'] . '
+Caption : ' . $params['example_deleted_user']['example_caption'] . '
+
+Best Wishes,
+
+Scilab TBC Team,
+FOSSEE, IIT Bombay', array(
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name
+ ), array(
+ 'language' => $language->language
+ ))
+ );
+ break;
+ case 'dependency_uploaded':
+ // bcc to textbook_companion_emails
+ //$message['headers'] += $tbc_bcc_emails;
+ $user_data = user_load($params['dependency_uploaded']['user_id']);
+ $message['headers'] = $params['example_deleted_user']['headers'];
+ $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', '')
+ ), array(
+ 'language' => $language->language
+ ));
+ $message['body'] = array(
+ 'body' => t('
+Dear !user_name,
+
+You have uploaded following dependency files :
+ ' . $dependency_files . '
+
+Best Wishes,
+
+Scilab TBC Team,
+FOSSEE, IIT Bombay', array(
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name
+ ), array(
+ 'language' => $language->language
+ ))
+ );
+ break;
+ case 'feedback_received':
+ // bcc to textbook_companion_emails
+ // $message['headers'] += $tbc_bcc_emails;
+ $message['headers'] = $params['feedback_received']['headers'];
+ $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', '')
+ ), array(
+ 'language' => $language->language
+ ));
+ $message['body'] = array(
+ 'body' => t('
+Dear !user_name,
+
+We have received your following feedback
+
+Title of the Book: ' . $params['feedback_received']['book_title'] . '
+Title of the Chapter: ' . $params['feedback_received']['chapter_number'] . ' ' . $params['feedback_received']['chapter_title'] . '
+Example No.: ' . $params['feedback_received']['example_no'] . '
+
+Your feedback :
+' . $params['feedback_received']['feedback'] . '
+
+Best Wishes,
+
+Scilab TBC Team,
+FOSSEE, IIT Bombay', array(
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name
+ ), array(
+ 'language' => $language->language
+ ))
+ );
+ break;
+ case 'internshipform':
+ // bcc to textbook_companion_emails
+ //$message['headers'] += $tbc_bcc_emails;
+ $message['headers'] = $params['internshipform']['headers'];
+ $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', '')
+ ), array(
+ 'language' => $language->language
+ ));
+ $message['body'] = array(
+ 'body' => t('
+Dear !user_name,
+
+We have received your Internship Form Application for the book
+
+Title of the Book: ' . $params['internshipform']['book_title'] . '
+Title of the Chapter: ' . $params['internshipform']['chapter_number'] . ' ' . $params['internshipform']['chapter_title'] . '
+Example No.: ' . $params['internshipform']['example_no'] . '
+
+Best Wishes,
+
+Scilab TBC Team,
+FOSSEE, IIT Bombay', array(
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name
+ ), array(
+ 'language' => $language->language
+ ))
+ );
+ break;
+ case 'copyrighttransferform':
+ // bcc to textbook_companion_emails
+ //$message['headers'] += $tbc_bcc_emails;
+ $message['headers'] = $params['copyrighttransferform']['headers'];
+ $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', '')
+ ), array(
+ 'language' => $language->language
+ ));
+ $message['body'] = array(
+ 'body' => t('
+Dear !user_name,
+
+We have received your Copyright Form Application for the book
+
+Title of the Book: ' . $params['copyrighttransferform']['book_title'] . '
+Title of the Chapter: ' . $params['copyrighttransferform']['chapter_number'] . ' ' . $params['copyrighttransferform']['chapter_title'] . '
+Example No.: ' . $params['copyrighttransferform']['example_no'] . '
+
+Best Wishes,
+
+Scilab TBC Team,
+FOSSEE, IIT Bombay', array(
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name
+ ), array(
+ 'language' => $language->language
+ ))
+ );
+ break;
+ case 'undertakingform':
+ // bcc to textbook_companion_emails
+ //$message['headers'] += $tbc_bcc_emails;
+ $message['headers'] = $params['undertakingform']['headers'];
+ $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', '')
+ ), array(
+ 'language' => $language->language
+ ));
+ $message['body'] = array(
+ 'body' => t('
+Dear !user_name,
+
+We have received your Undertaking Form Application for the book
+
+Title of the Book: ' . $params['undertakingform']['book_title'] . '
+Title of the Chapter: ' . $params['undertakingform']['chapter_number'] . ' ' . $params['undertakingform']['chapter_title'] . '
+Example No.: ' . $params['undertakingform']['example_no'] . '
+
+Best Wishes,
+
+Scilab TBC Team,
+FOSSEE, IIT Bombay', array(
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name
+ ), array(
+ 'language' => $language->language
+ ))
+ );
+ break;
+ case 'remark':
+ // bcc to textbook_companion_emails
+ //$message['headers'] += $tbc_bcc_emails;
+ $user_data = user_load($params['remark']['user_id']);
+ $message['headers'] = $params['remark']['headers'];
+ $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
+
+Title of the Book: ' . $params['internshipform']['book_title'] . '
+Title of the Chapter: ' . $params['internshipform']['chapter_number'] . ' ' . $params['internshipform']['chapter_title'] . '
+Example No.: ' . $params['internshipform']['example_no'] . '
+
+Best Wishes,
+
+Scilab TBC Team,
+FOSSEE, IIT Bombay', array(
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name
+ ), array(
+ 'language' => $language->language
+ ))
+ );
+ break;
+ case 'cheque_sent':
+ // bcc to textbook_companion_emails
+ // $message['headers'] += $tbc_bcc_emails;
+ $user_data = user_load($params['cheque_sent']['user_id']);
+ $message['headers'] = $params['cheque_sent']['headers'];
+ $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
+
+Title of the Book: ' . $params['cheque_sent']['book_title'] . '
+Title of the Chapter: ' . $params['cheque_sent']['chapter_number'] . ' ' . $params['cheque_sent']['chapter_title'] . '
+Example No.: ' . $params['cheque_sent']['example_no'] . '
+
+Best Wishes,
+
+Scilab TBC Team,
+FOSSEE, IIT Bombay', array(
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name
+ ), array(
+ 'language' => $language->language
+ ))
+ );
+ break;
+ case 'standard':
+ // bcc to textbook_companion_emails
+ //$message['headers'] += $tbc_bcc_emails;
+ $message['headers'] = $params['standard']['headers'];
+ $message['subject'] = $params['standard']['subject'];
+ $message['body'] = $params['standard']['body'];
+ break;
+ } //$key
+}
diff --git a/full_download.inc b/full_download.inc
index 68c79ff..0895bd2 100755
--- a/full_download.inc
+++ b/full_download.inc
@@ -1,233 +1,224 @@
<?php
// $Id$
-
function textbook_companion_download_full_chapter()
{
- $chapter_id = arg(2);
- $root_path = textbook_companion_path();
- $APPROVE_PATH = 'APPROVED/';
- $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_id = arg(2);
+ $root_path = textbook_companion_path();
+ $APPROVE_PATH = 'APPROVED/';
+ $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);*/
$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->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);*/
+ $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->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);*/
$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);*/
-
- $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 = $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));*/
-
- $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 = $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);*/
+ $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);
+ } //$example_files_row = $example_files_q->fetchObject()
+ /* dependency files */
+ 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));*/
+ $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);
+ } //$example_dependency_files_row = $example_dependency_files_q->fetchObject()
+ } //$example_row = $example_q->fetchObject()
+ /* unapproved examples */
+ /*$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);*/
-
- $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 = $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));*/
-
- $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);
- }
- }
-
- $zip_file_count = $zip->numFiles;
- $zip->close();
-
- if ($zip_file_count > 0)
- {
- /* download zip file */
- header('Content-Type: application/zip');
- header('Content-disposition: attachment; filename="CH' . $chapter_data->number . '.zip"');
- header('Content-Length: ' . filesize($zip_filename));
- header("Content-Transfer-Encoding: binary");
- header('Expires: 0');
- header('Pragma: no-cache');
- ob_end_flush();
- ob_clean();
- flush();
-
- readfile($zip_filename);
- unlink($zip_filename);
- } else {
- drupal_set_message("There are no examples in this chapter to download", 'error');
- drupal_goto('code_approval/bulk');
- }
+ 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);*/
+ $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);
+ } //$example_files_row = $example_files_q->fetchObject()
+ /* dependency files */
+ 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));*/
+ $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);
+ } //$example_dependency_files_row = $example_dependency_files_q->fetchObject()
+ } //$example_row = $example_q->fetchObject()
+ $zip_file_count = $zip->numFiles;
+ $zip->close();
+ if ($zip_file_count > 0)
+ {
+ /* download zip file */
+ header('Content-Type: application/zip');
+ header('Content-disposition: attachment; filename="CH' . $chapter_data->number . '.zip"');
+ header('Content-Length: ' . filesize($zip_filename));
+ header("Content-Transfer-Encoding: binary");
+ header('Expires: 0');
+ header('Pragma: no-cache');
+ ob_end_flush();
+ ob_clean();
+ flush();
+ readfile($zip_filename);
+ unlink($zip_filename);
+ } //$zip_file_count > 0
+ else
+ {
+ drupal_set_message("There are no examples in this chapter to download", 'error');
+ drupal_goto('code_approval/bulk');
+ }
}
-
-
function textbook_companion_download_full_book()
{
- $book_id = arg(2);
- $root_path = textbook_companion_path();
- $APPROVE_PATH = 'APPROVED/';
- $PENDING_PATH = 'PENDING/';
- /* get example data */
- $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 = :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 = :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 = :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);
- }
- /* dependency files */
- while ($example_dependency_files_row = $example_dependency_files_q->fetchObject())
- {
- $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 = :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 = :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 = $example_dependency_files_q->fetchObject())
- {
- $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_file_count = $zip->numFiles;
- $zip->close();
- if ($zip_file_count > 0)
- {
- /* download zip file */
- header('Content-Type: application/zip');
- header('Content-disposition: attachment; filename="' . $book_data->book . '.zip"');
- header('Content-Length: ' . filesize($zip_filename));
- //header("Content-Transfer-Encoding: binary");
- //header('Expires: 0');
- //header('Pragma: no-cache');
- //ob_end_flush();
- ob_end_clean();
- //flush();
- readfile($zip_filename);
- unlink($zip_filename);
- } else {
- drupal_set_message("There are no examples in this book to download", 'error');
- drupal_goto('code_approval/bulk');
- }
-
+ $book_id = arg(2);
+ $root_path = textbook_companion_path();
+ $APPROVE_PATH = 'APPROVED/';
+ $PENDING_PATH = 'PENDING/';
+ /* get example data */
+ $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 = :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 = :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 = :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);
+ } //$example_files_row = $example_files_q->fetchObject()
+ /* dependency files */
+ while ($example_dependency_files_row = $example_dependency_files_q->fetchObject())
+ {
+ $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);
+ } //$example_dependency_files_row = $example_dependency_files_q->fetchObject()
+ } //$example_row = $example_q->fetchObject()
+ /* unapproved examples */
+ $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 = :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);
+ } //$example_files_row = $example_files_q->fetchObject()
+ /* dependency files */
+ while ($example_dependency_files_row = $example_dependency_files_q->fetchObject())
+ {
+ $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);
+ } //$example_dependency_files_row = $example_dependency_files_q->fetchObject()
+ } //$example_row = $example_q->fetchObject()
+ } //$chapter_row = $chapter_q->fetchObject()
+ $zip_file_count = $zip->numFiles;
+ $zip->close();
+ if ($zip_file_count > 0)
+ {
+ /* download zip file */
+ header('Content-Type: application/zip');
+ header('Content-disposition: attachment; filename="' . $book_data->book . '.zip"');
+ header('Content-Length: ' . filesize($zip_filename));
+ //header("Content-Transfer-Encoding: binary");
+ //header('Expires: 0');
+ //header('Pragma: no-cache');
+ //ob_end_flush();
+ ob_end_clean();
+ //flush();
+ readfile($zip_filename);
+ unlink($zip_filename);
+ } //$zip_file_count > 0
+ else
+ {
+ 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 c3e2d14..792d9df 100755
--- a/general.inc
+++ b/general.inc
@@ -1,290 +1,308 @@
<?php
// $Id$
-
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);*/
-
+ 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);*/
$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');
- drupal_goto('');
- }
- if ($proposal_data->proposal_status != 1 && $proposal_data->proposal_status != 4)
- {
- 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');
- drupal_goto('');
- return;
- break;
- case 2:
- drupal_set_message(t('Your proposal has been dis-approved. Please create another proposal ' . l('here', 'proposal') . '.'), 'error');
- drupal_goto('');
- return;
- break;
- case 3:
- drupal_set_message(t('Congratulations! You have completed your last book proposal. You have to create another proposal ' . l('here', 'proposal') . '.'), 'status');
- drupal_goto('');
- return;
- break;
- default:
- drupal_set_message(t('Invalid proposal state. Please contact site administrator for further information.'), 'error');
- drupal_goto('');
- return;
- break;
- }
- }
-
- /*$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);*/
-
+ $proposal_data = $result->fetchObject();
+ if (!$proposal_data)
+ {
+ drupal_set_message("Please submit a " . l('proposal', 'proposal') . ".", 'error');
+ drupal_goto('');
+ } //!$proposal_data
+ if ($proposal_data->proposal_status != 1 && $proposal_data->proposal_status != 4)
+ {
+ 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');
+ drupal_goto('');
+ return;
+ break;
+ case 2:
+ drupal_set_message(t('Your proposal has been dis-approved. Please create another proposal ' . l('here', 'proposal') . '.'), 'error');
+ drupal_goto('');
+ return;
+ break;
+ case 3:
+ drupal_set_message(t('Congratulations! You have completed your last book proposal. You have to create another proposal ' . l('here', 'proposal') . '.'), 'status');
+ drupal_goto('');
+ return;
+ break;
+ default:
+ drupal_set_message(t('Invalid proposal state. Please contact site administrator for further information.'), 'error');
+ drupal_goto('');
+ return;
+ break;
+ } //$proposal_data->proposal_status
+ } //$proposal_data->proposal_status != 1 && $proposal_data->proposal_status != 4
+ /*$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');
- drupal_goto('');
- return;
- }
- /************************ end approve book details **************************/
-
- $return_html = '<br />';
- $return_html .= '<strong>Title of the Book:</strong><br />' . $preference_data->book . '<br /><br />';
- $return_html .= '<strong>Contributor Name:</strong><br />' . $proposal_data->full_name . '<br /><br />';
- $return_html .= l('Upload Example Code', 'textbook_companion/code/upload') . '<br />';
-
- /* 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);*/
-
+ $preference_data = $result->fetchObject();
+ if (!$preference_data)
+ {
+ drupal_set_message(t('Invalid Book Preference status. Please contact site administrator for further information.'), 'error');
+ drupal_goto('');
+ return;
+ } //!$preference_data
+ /************************ end approve book details **************************/
+ $return_html = '<br />';
+ $return_html .= '<strong>Title of the Book:</strong><br />' . $preference_data->book . '<br /><br />';
+ $return_html .= '<strong>Contributor Name:</strong><br />' . $proposal_data->full_name . '<br /><br />';
+ $return_html .= l('Upload Example Code', 'textbook_companion/code/upload') . '<br />';
+ /* 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);*/
$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);*/
-
- $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));
- }
-
- /* check if there are any chapters */
- if (!$chapter_rows)
- {
- drupal_set_message(t('No uploads found.'), 'status');
- return $return_html;
- }
-
- $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;
+ 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);*/
+ $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)
+ );
+ } //$chapter_data = $chapter_q->fetchObject()
+ /* check if there are any chapters */
+ if (!$chapter_rows)
+ {
+ drupal_set_message(t('No uploads found.'), 'status');
+ return $return_html;
+ } //!$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;
}
-
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);*/
-
+ 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);*/
$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');
- drupal_goto('');
- }
- if ($proposal_data->proposal_status != 1 && $proposal_data->proposal_status != 4)
- {
- 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');
- drupal_goto('');
- return;
- break;
- case 2:
- drupal_set_message(t('Your proposal has been dis-approved. Please create another proposal ' . l('here', 'proposal') . '.'), 'error');
- drupal_goto('');
- return;
- break;
- case 3:
- drupal_set_message(t('Congratulations! You have completed your last book proposal. You have to create another proposal ' . l('here', 'proposal') . '.'), 'status');
- drupal_goto('');
- return;
- break;
- default:
- drupal_set_message(t('Invalid proposal state. Please contact site administrator for further information.'), 'error');
- drupal_goto('');
- return;
- break;
- }
- }
-
- /*$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);*/
-
+ $proposal_data = $result->fetchObject();
+ if (!$proposal_data)
+ {
+ drupal_set_message("Please submit a " . l('proposal', 'proposal') . ".", 'error');
+ drupal_goto('');
+ } //!$proposal_data
+ if ($proposal_data->proposal_status != 1 && $proposal_data->proposal_status != 4)
+ {
+ 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');
+ drupal_goto('');
+ return;
+ break;
+ case 2:
+ drupal_set_message(t('Your proposal has been dis-approved. Please create another proposal ' . l('here', 'proposal') . '.'), 'error');
+ drupal_goto('');
+ return;
+ break;
+ case 3:
+ drupal_set_message(t('Congratulations! You have completed your last book proposal. You have to create another proposal ' . l('here', 'proposal') . '.'), 'status');
+ drupal_goto('');
+ return;
+ break;
+ default:
+ drupal_set_message(t('Invalid proposal state. Please contact site administrator for further information.'), 'error');
+ drupal_goto('');
+ return;
+ break;
+ } //$proposal_data->proposal_status
+ } //$proposal_data->proposal_status != 1 && $proposal_data->proposal_status != 4
+ /*$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');
- drupal_goto('');
- return;
- }
- /************************ end approve book details **************************/
-
- /* 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);*/
-
+ $preference_data = $result->fetchObject();
+ if (!$preference_data)
+ {
+ drupal_set_message(t('Invalid Book Preference status. Please contact site administrator for further information.'), 'error');
+ drupal_goto('');
+ return;
+ } //!$preference_data
+ /************************ end approve book details **************************/
+ /* 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);*/
$query = db_select('textbook_companion_chapter');
$query->fields('textbook_companion_chapter');
$query->condition('id', $chapter_id);
- $query->condition('preference_id',$preference_data->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 />';
- $return_html .= '<strong>Contributor Name:</strong><br />' . $proposal_data->full_name . '<br /><br />';
- $return_html .= '<strong>Chapter Number:</strong><br />' . $chapter_data->number . '<br /><br />';
- $return_html .= '<strong>Title of the Chapter:</strong><br />' . $chapter_data->name . '<br />';
- } else {
- drupal_set_message(t('Invalid chapter.'), 'error');
- drupal_goto('textbook_companion/code');
- return;
- }
-
- $return_html .= '<br />' . l('Back to Chapter List', 'textbook_companion/code');
-
- /* get example list */
- $example_rows = array();
-
- /*$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);*/
-
+ if ($chapter_data = $chapter_q->fetchObject())
+ {
+ $return_html = '<br />';
+ $return_html .= '<strong>Title of the Book:</strong><br />' . $preference_data->book . '<br /><br />';
+ $return_html .= '<strong>Contributor Name:</strong><br />' . $proposal_data->full_name . '<br /><br />';
+ $return_html .= '<strong>Chapter Number:</strong><br />' . $chapter_data->number . '<br /><br />';
+ $return_html .= '<strong>Title of the Chapter:</strong><br />' . $chapter_data->name . '<br />';
+ } //$chapter_data = $chapter_q->fetchObject()
+ else
+ {
+ drupal_set_message(t('Invalid chapter.'), 'error');
+ drupal_goto('textbook_companion/code');
+ return;
+ }
+ $return_html .= '<br />' . l('Back to Chapter List', 'textbook_companion/code');
+ /* get example list */
+ $example_rows = array();
+ /*$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);*/
$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 = '';
- switch ($example_data->approval_status)
- {
- case 0: $approval_status = 'Pending'; break;
- case 1: $approval_status = 'Approved'; break;
- case 2: $approval_status = 'Rejected'; break;
- }
-
- /* 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);*/
-
- $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)
- {
- case 'S': $file_type = 'Main or Source'; break;
- case 'R': $file_type = 'Result'; break;
- case 'X': $file_type = 'xcos'; break;
- default:
- }
- $example_files .= l($example_files_data->filename, 'download/file/' . $example_files_data->id) . ' (' . $file_type . ')<br />';
- }
- /* dependency files */
- $dependency_files = '';
-
- $dependency_files_q = db_query("SELECT dependency.id as dependency_id, dependency.filename as dependency_filename
+ $example_q = $query->execute();
+ while ($example_data = $example_q->fetchObject())
+ {
+ /* approval status */
+ $approval_status = '';
+ switch ($example_data->approval_status)
+ {
+ case 0:
+ $approval_status = 'Pending';
+ break;
+ case 1:
+ $approval_status = 'Approved';
+ break;
+ case 2:
+ $approval_status = 'Rejected';
+ break;
+ } //$example_data->approval_status
+ /* 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);*/
+ $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)
+ {
+ case 'S':
+ $file_type = 'Main or Source';
+ break;
+ case 'R':
+ $file_type = 'Result';
+ break;
+ case 'X':
+ $file_type = 'xcos';
+ break;
+ default:
+ } //$example_files_data->filetype
+ $example_files .= l($example_files_data->filename, 'download/file/' . $example_files_data->id) . ' (' . $file_type . ')<br />';
+ } //$example_files_data = $example_files_q->fetchObject()
+ /* 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 = :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 />';
- }
- $example_files .= $dependency_files;
-
- if ($example_data->approval_status == 0)
- {
- $example_rows[] = array('data' => array($example_data->number, $example_data->caption, $approval_status, $example_files, l('Edit', 'textbook_companion/code/edit/' . $example_data->id) . ' | ' . l('Delete', 'textbook_companion/code/delete/' . $example_data->id, array('attributes' => array('onClick' => 'return confirm("Are you sure you want to delete the example?")')))), 'valign' => 'top');
- } else {
- $example_rows[] = array('data' => array($example_data->number, $example_data->caption, $approval_status, $example_files, l('Download', 'download/example/' . $example_data->id)), 'valign' => 'top');
- }
- }
-
- $example_header = array('Example No.', 'Caption', 'Status', 'Files', 'Action');
- $return_html .= theme('table',array('header'=>$example_header,'rows'=>$example_rows));
- return $return_html;
-}
+ 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 />';
+ } //$dependency_files_data = $dependency_files_q->fetchObject()
+ $example_files .= $dependency_files;
+ if ($example_data->approval_status == 0)
+ {
+ $example_rows[] = array(
+ 'data' => array(
+ $example_data->number,
+ $example_data->caption,
+ $approval_status,
+ $example_files,
+ l('Edit', 'textbook_companion/code/edit/' . $example_data->id)
+ /*l('Edit', 'textbook_companion/code/edit/' . $example_data->id) . ' | ' . l('Delete', 'textbook_companion/code/delete/' . $example_data->id, array(
+ 'attributes' => array(
+ 'onClick' => 'return confirm("Are you sure you want to delete the example?")'
+ )
+ ))*/
+ ),
+ 'valign' => 'top'
+ );
+ } //$example_data->approval_status == 0
+ else
+ {
+ $example_rows[] = array(
+ 'data' => array(
+ $example_data->number,
+ $example_data->caption,
+ $approval_status,
+ $example_files,
+ l('Download', 'download/example/' . $example_data->id)
+ ),
+ 'valign' => 'top'
+ );
+ }
+ } //$example_data = $example_q->fetchObject()
+ $example_header = array(
+ 'Example No.',
+ 'Caption',
+ 'Status',
+ 'Files',
+ 'Action'
+ );
+ $return_html .= theme('table', array(
+ 'header' => $example_header,
+ 'rows' => $example_rows
+ ));
+ return $return_html;
+}
diff --git a/latex.inc b/latex.inc
index 18d641f..942989d 100755
--- a/latex.inc
+++ b/latex.inc
@@ -1,64 +1,56 @@
<?php
-
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")
- _latex_generate_files($preference_id, TRUE);
- else
- _latex_generate_files($preference_id, FALSE);
+ $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")
+ _latex_generate_files($preference_id, TRUE);
+ else
+ _latex_generate_files($preference_id, FALSE);
}
-
function _latex_generate_files($preference_id, $full_book = FALSE)
{
- $root_path = textbook_companion_path();
- $dir_path = $root_path . "latex/";
-
- $book_filedata = "";
- $contributor_filedata = "";
- $latex_filedata = "";
- $latex_dep_filedata = "";
-
- $depedency_list = array();
-
- $eol = "\n";
- $sep = "#";
-
- $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');
- drupal_goto('');
- }
- if ($preference_data->approval_status == 0)
- {
- drupal_set_message('Book proposal is still in pending review.', 'error');
- drupal_goto('');
- }
- $book_filedata = $preference_data->book . $sep . $preference_data->author . $sep . $preference_data->isbn . $sep . $preference_data->publisher . $sep . $preference_data->edition . $sep . $preference_data->year . $eol;
-
- /* regenerate book if full book selected */
- if ($full_book)
- 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();
+ $root_path = textbook_companion_path();
+ $dir_path = $root_path . "latex/";
+ $book_filedata = "";
+ $contributor_filedata = "";
+ $latex_filedata = "";
+ $latex_dep_filedata = "";
+ $depedency_list = array();
+ $eol = "\n";
+ $sep = "#";
+ $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');
+ drupal_goto('');
+ } //!$preference_data
+ if ($preference_data->approval_status == 0)
+ {
+ drupal_set_message('Book proposal is still in pending review.', 'error');
+ drupal_goto('');
+ } //$preference_data->approval_status == 0
+ $book_filedata = $preference_data->book . $sep . $preference_data->author . $sep . $preference_data->isbn . $sep . $preference_data->publisher . $sep . $preference_data->edition . $sep . $preference_data->year . $eol;
+ /* regenerate book if full book selected */
+ if ($full_book)
+ 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 PDF 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("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"');
@@ -69,156 +61,174 @@ function _latex_generate_files($preference_id, $full_book = FALSE)
//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 = :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 = :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 = :id ORDER BY number DESC", array(':id' => $chapter_data->id));
- else
- $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 = :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;
- $latex_filedata .= $example_data->number . $sep;
- $latex_filedata .= $example_data->caption . $sep;
- $latex_filedata .= $example_files_data->filename . $sep;
- $latex_filedata .= $example_files_data->filepath . $sep;
- $latex_filedata .= $example_files_data->filetype . $sep;
- $latex_filedata .= $sep;
- $latex_filedata .= $example_files_data->id;
- $latex_filedata .= $eol;
- }
- $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 = :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;
- $latex_filedata .= $example_data->number . $sep;
- $latex_filedata .= $example_data->caption . $sep;
- $latex_filedata .= $dependency_data->filename . $sep;
- $latex_filedata .= $dependency_data->filepath . $sep;
- $latex_filedata .= 'D' . $sep;
- $latex_filedata .= $dependency_data->caption . $sep;
- $latex_filedata .= $dependency_data->id;
- $latex_filedata .= $eol;
-
- $depedency_list[$dependency_data->id] = "D";
- }
- }
- }
- }
-
- foreach ($depedency_list as $row => $data) {
- $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;
- $latex_dep_filedata .= $dependency_data->caption . $sep;
- $latex_dep_filedata .= $dependency_data->id;
- $latex_dep_filedata .= $eol;
- }
- }
-
- /**************************** WRITE TO FILES ********************************/
- $download_filename = $preference_data->book . "_" . $preference_data->author;
- $book_filename = "tmp_" . $preference_data->id . "_book.txt";
- $contributor_filename = "tmp_" . $preference_data->id . "_contributor.txt";
- $latex_filename = "tmp_" . $preference_data->id . "_data.txt";
- $latex_dep_filename = "tmp_" . $preference_data->id . "_dep_data.txt";
- $pdf_filename = "book_" . $preference_data->id . ".pdf";
-
- // $book_filedata = str_replace("&", "\&", $book_filedata);
- $fb = fopen($dir_path . $book_filename, 'w');
- fwrite($fb, $book_filedata);
- fclose($fb);
-
- // $contributor_filedata = str_replace("&", "\&", $contributor_filedata);
- $fc = fopen($dir_path . $contributor_filename, 'w');
- fwrite($fc, $contributor_filedata);
- fclose($fc);
-
- $fl = fopen($dir_path . $latex_filename, 'w');
- fwrite($fl, $latex_filedata);
- fclose($fl);
-
- $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))
- {
- /* download zip file */
- header('Content-Type: application/pdf');
- header('Content-disposition: attachment; filename="' . $preference_data->book . '_' . $preference_data->author . '.pdf"');
- header('Content-Length: ' . filesize($dir_path . $pdf_filename));
- header("Content-Transfer-Encoding: binary");
- header('Expires: 0');
- header('Pragma: no-cache');
-
-
- @readfile($dir_path . $pdf_filename);
- ob_end_flush();
- ob_clean();
- flush();
- } else {
+ } //file_exists($dir_path . "book_" . $preference_data->id . ".pdf")
+ $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');
+ } //!$proposal_data
+ $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 = :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 = :id ORDER BY number DESC", array(
+ ':id' => $chapter_data->id
+ ));
+ else
+ $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 = :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;
+ $latex_filedata .= $example_data->number . $sep;
+ $latex_filedata .= $example_data->caption . $sep;
+ $latex_filedata .= $example_files_data->filename . $sep;
+ $latex_filedata .= $example_files_data->filepath . $sep;
+ $latex_filedata .= $example_files_data->filetype . $sep;
+ $latex_filedata .= $sep;
+ $latex_filedata .= $example_files_data->id;
+ $latex_filedata .= $eol;
+ } //$example_files_data = $example_files_q->fetchObject()
+ $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 = :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;
+ $latex_filedata .= $example_data->number . $sep;
+ $latex_filedata .= $example_data->caption . $sep;
+ $latex_filedata .= $dependency_data->filename . $sep;
+ $latex_filedata .= $dependency_data->filepath . $sep;
+ $latex_filedata .= 'D' . $sep;
+ $latex_filedata .= $dependency_data->caption . $sep;
+ $latex_filedata .= $dependency_data->id;
+ $latex_filedata .= $eol;
+ $depedency_list[$dependency_data->id] = "D";
+ } //$dependency_data = $dependency_q->fetchObject()
+ } //$dependency_files_data = $dependency_files_q->fetchObject()
+ } //$example_data = $example_q->fetchObject()
+ } //$chapter_data = $chapter_q->fetchObject()
+ foreach ($depedency_list as $row => $data)
+ {
+ $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;
+ $latex_dep_filedata .= $dependency_data->caption . $sep;
+ $latex_dep_filedata .= $dependency_data->id;
+ $latex_dep_filedata .= $eol;
+ } //$dependency_data = $dependency_q->fetchObject()
+ } //$depedency_list as $row => $data
+ /**************************** WRITE TO FILES ********************************/
+ $download_filename = $preference_data->book . "_" . $preference_data->author;
+ $book_filename = "tmp_" . $preference_data->id . "_book.txt";
+ $contributor_filename = "tmp_" . $preference_data->id . "_contributor.txt";
+ $latex_filename = "tmp_" . $preference_data->id . "_data.txt";
+ $latex_dep_filename = "tmp_" . $preference_data->id . "_dep_data.txt";
+ $pdf_filename = "book_" . $preference_data->id . ".pdf";
+ // $book_filedata = str_replace("&", "\&", $book_filedata);
+ $fb = fopen($dir_path . $book_filename, 'w');
+ fwrite($fb, $book_filedata);
+ fclose($fb);
+ // $contributor_filedata = str_replace("&", "\&", $contributor_filedata);
+ $fc = fopen($dir_path . $contributor_filename, 'w');
+ fwrite($fc, $contributor_filedata);
+ fclose($fc);
+ $fl = fopen($dir_path . $latex_filename, 'w');
+ fwrite($fl, $latex_filedata);
+ fclose($fl);
+ $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))
+ {
+ /* download PDF file */
+ if (filesize($dir_path . $pdf_filename) == TRUE)
+ {
+ 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 . $pdf_filename));
+ header("Content-Transfer-Encoding: binary");
+ header('Expires: 0');
+ header('Pragma: no-cache');
+ @readfile($dir_path . $pdf_filename);
+ ob_end_flush();
+ ob_clean();
+ flush();
+ } //filesize($dir_path . $pdf_filename) == TRUE
+ else
+ {
+ drupal_set_message("Error occurred when generating the PDF version of the Book.", 'error');
+ drupal_goto('textbook_run/' . $preference_data->id);
+ }
+ } //_latex_run_script($book_filename, $contributor_filename, $latex_filename, $latex_dep_filename, $pdf_filename)
+ else
+ {
drupal_set_message("Error occurred when generating the PDF version of the Book.", 'error');
}
-
- /*********************** DELETING TEMPORARY FILES ***************************/
- /* regenerate book if full book selected */
- if ($full_book)
- del_book_pdf($preference_data->id);
+ /*********************** DELETING TEMPORARY FILES ***************************/
+ /* regenerate book if full book selected */
+ if ($full_book)
+ del_book_pdf($preference_data->id);
}
-
function _latex_copy_script_file()
{
- exec("cp ./" . drupal_get_path('module', 'textbook_companion') . "/latex/* ./uploads/latex");
- exec("chmod u+x ./uploads/latex/*.sh");
+ exec("cp ./" . drupal_get_path('module', 'textbook_companion') . "/latex/* ./uploads/latex");
+ exec("chmod u+x ./uploads/latex/*.sh");
}
-
function _latex_run_script($book_filename, $contributor_filename, $latex_filename, $latex_dep_filename, $pdf_filename)
{
- $root_path = textbook_companion_path();
- $ret = 0;
-
- chdir("uploads");
- chdir("latex");
-//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);
-// 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{
- return FALSE;
-}
+ $root_path = textbook_companion_path();
+ $ret = 0;
+ chdir("uploads");
+ chdir("latex");
+ //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);
+ // 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;
+ } //$ret == 0
+ else
+ {
+ return FALSE;
+ }
}
-
function textbook_companion_delete_book()
{
$book_id = arg(2);
@@ -227,5 +237,3 @@ function textbook_companion_delete_book()
drupal_goto('code_approval/bulk');
return;
}
-
-
diff --git a/manage_proposal.inc b/manage_proposal.inc
index 0cd070d..0b2ac3f 100755
--- a/manage_proposal.inc
+++ b/manage_proposal.inc
@@ -1,1317 +1,1493 @@
<?php
-// $Id$
-
+// You can find all functions regarding manage proposal
+/*
+textbook companion proposal table column "proposal_status" field values means
+0 = 'Pending';
+1 = 'Approved';
+2 = 'Dis-approved';
+3 = 'Completed';
+4 = 'External';
+5 = 'Unknown';
+*/
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");*/
-
+ /* 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");*/
$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));
- }
-
- /* check if there are any pending proposals */
- if (!$pending_rows)
- {
- drupal_set_message(t('There are no pending proposals.'), 'status');
- return '';
- }
-
- $pending_header = array('Date of Submission', 'Contributor Name', 'Date of Completion', 'Action');
- $output = theme('table',array('header'=>$pending_header, 'rows'=>$pending_rows));
- return $output;
+ 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->proposed_completion_date),
+ l('Approve', 'manage_proposal/approve/' . $pending_data->id) . ' | ' . l('Edit', 'manage_proposal/edit/' . $pending_data->id)
+ );
+ } //$pending_data = $pending_q->fetchObject()
+ /* check if there are any pending proposals */
+ if (!$pending_rows)
+ {
+ drupal_set_message(t('There are no pending proposals.'), 'status');
+ return '';
+ } //!$pending_rows
+ $pending_header = array(
+ 'Date of Submission',
+ 'Contributor Name',
+ 'Proposed Date of Completion',
+ 'Action'
+ );
+ $output = theme('table', array(
+ 'header' => $pending_header,
+ 'rows' => $pending_rows
+ ));
+ return $output;
}
-
function _proposal_all()
{
- function _tbc_ext($status, $preference_id) {
- if($status == "Approved") {
- return " | " . l("ER", "tbc_external_review/add_book/" . $preference_id);
- }
- else {
- return "";
- }
- }
- /* get pending proposals to be approved */
- $proposal_rows = array();
-
- /*$proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} ORDER BY id DESC");*/
-
+ function _tbc_ext($status, $preference_id)
+ {
+ if ($status == "Approved")
+ {
+ return " | " . l("ER", "tbc_external_review/add_book/" . $preference_id);
+ } //$status == "Approved"
+ else
+ {
+ return "";
+ }
+ }
+ /* get pending proposals to be approved */
+ $proposal_rows = array();
+ /*$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);*/
-
- $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);*/
-
- $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)
- {
- case 0: $proposal_status = 'Pending'; break;
- case 1: $proposal_status = 'Approved'; break;
- case 2: $proposal_status = 'Dis-approved'; break;
- case 3: $proposal_status = 'Completed'; break;
- case 4: $proposal_status = 'External'; break;
- default: $proposal_status = 'Unknown'; break;
- }
-
- $proposal_rows[] = array(
- date('d-m-Y', $proposal_data->creation_date),
- "{$preference_data->book} <br> <em>by {$preference_data->author}</em>",
- l($proposal_data->full_name, 'user/' . $proposal_data->uid),
- date('d-m-Y', $proposal_data->completion_date),
- $proposal_status,
- l('Status', 'manage_proposal/status/' . $proposal_data->id) . ' | ' . l('Edit', 'manage_proposal/edit/' . $proposal_data->id) . _tbc_ext($proposal_status, $preference_data->id)
- );
- }
-
- /* check if there are any pending proposals */
- if (!$proposal_rows)
- {
- drupal_set_message(t('There are no proposals.'), 'status');
- return '';
- }
-
- $proposal_header = array('Date of Submission', 'Title of the Book', 'Contributor Name', 'Expected Date of Completion', 'Status', 'Action');
- $output = theme('table',array('header'=>$proposal_header, 'rows'=>$proposal_rows));
- return $output;
+ 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);*/
+ $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);*/
+ $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();
+ } //!$preference_data
+ $proposal_status = '';
+ switch ($proposal_data->proposal_status)
+ {
+ case 0:
+ $proposal_status = 'Pending';
+ break;
+ case 1:
+ $proposal_status = 'Approved';
+ break;
+ case 2:
+ $proposal_status = 'Dis-approved';
+ break;
+ case 3:
+ $proposal_status = 'Completed';
+ break;
+ case 4:
+ $proposal_status = 'External';
+ break;
+ default:
+ $proposal_status = 'Unknown';
+ break;
+ } //$proposal_data->proposal_status
+ $proposal_rows[] = array(
+ date('d-m-Y', $proposal_data->creation_date),
+ "{$preference_data->book} <br> <em>by {$preference_data->author}</em>",
+ l($proposal_data->full_name, 'user/' . $proposal_data->uid),
+ date('d-m-Y', $proposal_data->proposed_completion_date),
+ date('d-m-Y', $proposal_data->completion_date),
+ $proposal_status,
+ l('Status', 'manage_proposal/status/' . $proposal_data->id) . ' | ' . l('Edit', 'manage_proposal/edit/' . $proposal_data->id) . _tbc_ext($proposal_status, $preference_data->id)
+ );
+ } //$proposal_data = $proposal_q->fetchObject()
+ /* check if there are any pending proposals */
+ if (!$proposal_rows)
+ {
+ drupal_set_message(t('There are no proposals.'), 'status');
+ return '';
+ } //!$proposal_rows
+ $proposal_header = array(
+ 'Date of Submission',
+ 'Title of the Book',
+ 'Contributor Name',
+ 'Proposed Date of Completion',
+ 'Actual Date of Completion',
+ 'Status',
+ 'Action'
+ );
+ $output = theme('table', array(
+ 'header' => $proposal_header,
+ 'rows' => $proposal_rows
+ ));
+ return $output;
}
-
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");*/
-
+ /* 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");*/
$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)
- {
- case 0: $category_data = 'Not Selected'; break;
- case 1: $category_data = 'Fluid Mechanics'; break;
- case 2: $category_data = 'Control Theory & Control Systems'; break;
- case 3: $category_data = 'Chemical Engineering'; break;
- case 4: $category_data = 'Thermodynamics'; break;
- case 5: $category_data = 'Mechanical Engineering'; break;
- case 6: $category_data = 'Signal Processing'; break;
- case 7: $category_data = 'Digital Communications'; break;
- case 8: $category_data = 'Electrical Technology'; break;
- case 9: $category_data = 'Mathematics & Pure Science'; break;
- case 10: $category_data = 'Analog Electronics'; break;
- case 11: $category_data = 'Digital Electronics'; break;
- case 12: $category_data = 'Computer Programming'; break;
- case 13: $category_data = 'Others'; break;
- default: $category_data = 'Unknown'; break;
- }
- $preference_rows[] = array($preference_data->book ."<br> <i>by " .$preference_data->author."</i>", $preference_data->isbn, $preference_data->publisher, $preference_data->edition, $preference_data->year, $category_data, l('Edit', 'manage_proposal/category/edit/' . $preference_data->id));
- }
-
- $preference_header = array('Book', 'ISBN', 'Publisher', 'Edition', 'Year', 'Category', 'Status');
- $output = theme('table',array('header'=>$preference_header, 'rows'=>$preference_rows));
- return $output;
+ while ($preference_data = $preference_q->fetchObject())
+ {
+ switch ($preference_data->category)
+ {
+ case 0:
+ $category_data = 'Not Selected';
+ break;
+ case 1:
+ $category_data = 'Fluid Mechanics';
+ break;
+ case 2:
+ $category_data = 'Control Theory & Control Systems';
+ break;
+ case 3:
+ $category_data = 'Chemical Engineering';
+ break;
+ case 4:
+ $category_data = 'Thermodynamics';
+ break;
+ case 5:
+ $category_data = 'Mechanical Engineering';
+ break;
+ case 6:
+ $category_data = 'Signal Processing';
+ break;
+ case 7:
+ $category_data = 'Digital Communications';
+ break;
+ case 8:
+ $category_data = 'Electrical Technology';
+ break;
+ case 9:
+ $category_data = 'Mathematics & Pure Science';
+ break;
+ case 10:
+ $category_data = 'Analog Electronics';
+ break;
+ case 11:
+ $category_data = 'Digital Electronics';
+ break;
+ case 12:
+ $category_data = 'Computer Programming';
+ break;
+ case 13:
+ $category_data = 'Others';
+ break;
+ default:
+ $category_data = 'Unknown';
+ break;
+ } //$preference_data->category
+ $preference_rows[] = array(
+ $preference_data->book . "<br> <i>by " . $preference_data->author . "</i>",
+ $preference_data->isbn,
+ $preference_data->publisher,
+ $preference_data->edition,
+ $preference_data->year,
+ $category_data,
+ l('Edit', 'manage_proposal/category/edit/' . $preference_data->id)
+ );
+ } //$preference_data = $preference_q->fetchObject()
+ $preference_header = array(
+ 'Book',
+ 'ISBN',
+ 'Publisher',
+ 'Edition',
+ 'Year',
+ 'Category',
+ 'Status'
+ );
+ $output = theme('table', array(
+ 'header' => $preference_header,
+ 'rows' => $preference_rows
+ ));
+ return $output;
}
-
/******************************************************************************/
/************************** PROPOSAL APPROVAL FORM ****************************/
/******************************************************************************/
-
-function proposal_approval_form($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);*/
-
+ 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);*/
$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 =$result->fetchObject())
- {
- /* everything ok */
- } else {
- drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
- drupal_goto('manage_proposal');
- return;
- }
- } else {
- drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
- drupal_goto('manage_proposal');
- return;
- }
-
- $form['full_name'] = array(
- '#type' => 'item',
- '#markup' => l($row->full_name, 'user/' . $row->uid),
- '#title' => t('Contributor Name'),
- );
- $form['email'] = array(
- '#type' => 'item',
- '#markup' => user_load($row->uid)->mail,
- '#title' => t('Email'),
- );
- $form['mobile'] = array(
- '#type' => 'item',
- '#markup' => $row->mobile,
- '#title' => t('Mobile'),
- );
- $form['how_project'] = array(
- '#type' => 'item',
- '#markup' => $row->how_project,
- '#title' => t('How did you come to know about this project'),
- );
- $form['course'] = array(
- '#type' => 'item',
- '#markup' => $row->course,
- '#title' => t('Course'),
- );
- $form['branch'] = array(
- '#type' => 'item',
- '#markup' => $row->branch,
- '#title' => t('Department/Branch'),
- );
- $form['university'] = array(
- '#type' => 'item',
- '#markup' => $row->university,
- '#title' => t('University/Institute'),
- );
- $form['city'] = array(
- '#type' => 'item',
- '#markup' => $row->city,
- '#title' => t('City'),
- );
- $form['all_state'] = array(
- '#type' => 'item',
- '#markup' => $row->state,
- '#title' => t('State'),
- );
- $form['country'] = array(
- '#type' => 'item',
- '#markup' => $row->country,
- '#title' => t('Country'),
- );
- $form['pincode'] = array(
- '#type' => 'item',
- '#markup' => $row->pincode,
- '#title' => t('Pincode'),
- );
- $form['faculty'] = array(
- '#type' => 'item',
- '#markup' => $row->faculty,
- '#title' => t('College Teacher/Professor'),
- );
- $form['reviewer'] = array(
- '#type' => 'item',
- '#markup' => $row->reviewer,
- '#title' => t('Reviewer'),
- );
- $form['completion_date'] = array(
- '#type' => 'item',
- '#markup' => date('d-m-Y', $row->completion_date),
- '#title' => t('Expected Date of Completion'),
- );
- $form['operating_system'] = array(
- '#type' => 'item',
- '#markup' => $row->operating_system,
- '#title' => t('Operating System'),
- );
- $form['scilab_version'] = array(
- '#type' => 'item',
- '#markup' => $row->scilab_version,
- '#title' => t('Scilab Version'),
- );
- /************************** reference link filter *******************/
- $url = '~(?:(https?)://([^\s<]+)|(www\.[^\s<]+?\.[^\s<]+))(?<![\.,:])~i';
- $reference = preg_replace($url, '<a href="$0" target="_blank" title="$0">$0</a>', $row->reference);
-/******************************/
- $form['reference'] = array(
- '#type' => 'item',
- '#markup' => $reference,
- '#title' => t('References'),
- );
- $form['reason'] = array(
- '#type' => 'item',
- '#markup' => $row->reason,
- '#title' => t('Reasons'),
- );
-
- /* get book preference */
- $preference_rows = array();
-
- // $preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = :proposal_id ORDER BY pref_number ASC", array(':proposal_id' => $proposal_id));
- $preference_q = db_query(" SELECT * FROM list_of_category loc
+ if ($result)
+ {
+ if ($row = $result->fetchObject())
+ {
+ /* everything ok */
+ } //$row = $result->fetchObject()
+ else
+ {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('manage_proposal');
+ return;
+ }
+ } //$result
+ else
+ {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('manage_proposal');
+ return;
+ }
+ $form['full_name'] = array(
+ '#type' => 'item',
+ '#markup' => l($row->full_name, 'user/' . $row->uid),
+ '#title' => t('Contributor Name')
+ );
+ $form['email'] = array(
+ '#type' => 'item',
+ '#markup' => user_load($row->uid)->mail,
+ '#title' => t('Email')
+ );
+ $form['mobile'] = array(
+ '#type' => 'item',
+ '#markup' => $row->mobile,
+ '#title' => t('Mobile')
+ );
+ $form['how_project'] = array(
+ '#type' => 'item',
+ '#markup' => $row->how_project,
+ '#title' => t('How did you come to know about this project')
+ );
+ $form['course'] = array(
+ '#type' => 'item',
+ '#markup' => $row->course,
+ '#title' => t('Course')
+ );
+ $form['branch'] = array(
+ '#type' => 'item',
+ '#markup' => $row->branch,
+ '#title' => t('Department/Branch')
+ );
+ $form['university'] = array(
+ '#type' => 'item',
+ '#markup' => $row->university,
+ '#title' => t('University/Institute')
+ );
+ $form['city'] = array(
+ '#type' => 'item',
+ '#markup' => $row->city,
+ '#title' => t('City')
+ );
+ $form['all_state'] = array(
+ '#type' => 'item',
+ '#markup' => $row->state,
+ '#title' => t('State')
+ );
+ $form['country'] = array(
+ '#type' => 'item',
+ '#markup' => $row->country,
+ '#title' => t('Country')
+ );
+ $form['pincode'] = array(
+ '#type' => 'item',
+ '#markup' => $row->pincode,
+ '#title' => t('Pincode')
+ );
+ $form['faculty'] = array(
+ '#type' => 'item',
+ '#markup' => $row->faculty,
+ '#title' => t('College Teacher/Professor')
+ );
+ $form['reviewer'] = array(
+ '#type' => 'item',
+ '#markup' => $row->reviewer,
+ '#title' => t('Reviewer')
+ );
+ $form['proposed_completion_date'] = array(
+ '#type' => 'item',
+ '#markup' => date('d-m-Y', $row->proposed_completion_date),
+ '#title' => t('Proposed Date of Completion')
+ );
+ $form['completion_date'] = array(
+ '#type' => 'item',
+ '#markup' => date('d-m-Y', $row->completion_date),
+ '#title' => t('Actual Date of Completion')
+ );
+ $form['operating_system'] = array(
+ '#type' => 'item',
+ '#markup' => $row->operating_system,
+ '#title' => t('Operating System')
+ );
+ $form['scilab_version'] = array(
+ '#type' => 'item',
+ '#markup' => $row->scilab_version,
+ '#title' => t('Scilab Version')
+ );
+ /************************** reference link filter *******************/
+ $url = '~(?:(https?)://([^\s<]+)|(www\.[^\s<]+?\.[^\s<]+))(?<![\.,:])~i';
+ $reference = preg_replace($url, '<a href="$0" target="_blank" title="$0">$0</a>', $row->reference);
+ /******************************/
+ $form['reference'] = array(
+ '#type' => 'item',
+ '#markup' => $reference,
+ '#title' => t('References')
+ );
+ $form['reason'] = array(
+ '#type' => 'item',
+ '#markup' => $row->reason,
+ '#title' => t('Reasons')
+ );
+ /* get book preference */
+ $preference_rows = array();
+ // $preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = :proposal_id ORDER BY pref_number ASC", array(':proposal_id' => $proposal_id));
+ $preference_q = db_query(" SELECT * FROM list_of_category loc
JOIN textbook_companion_preference tcp ON loc.category_id = tcp.category
WHERE proposal_id = :proposal_id ORDER BY pref_number ASC
-",array(':proposal_id' => $proposal_id));
+", 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())
- {
-
- $category_data = _tbc_list_of_category($preference_data->category);
- foreach ($category_data as $cat){
- $preference_rows[$preference_data->id] = $preference_data->book . ' (Written by ' . $preference_data->author . ')</br>[Category: '.$cat.']</br>';
- }
- }
- if($row->proposal_type == 1){
- $form['book_preference'] = array(
- '#type' => 'radios',
- '#options' => $preference_rows,
- '#title' => t('Book Preferences'),
- '#required' => TRUE,
-
- );
- }
- else{
- $form['book_preference'] = array(
- '#type' => 'radios',
- '#title' => t('Book Preferences'),
- '#options' => $preference_rows,
- '#required' => TRUE,
- );}
- if($row->samplefilepath !="None"){
- $form['samplecode'] = array(
- '#type' => 'markup',
- '#markup' => l('Click here to download sample code', 'download/samplecode/' . $proposal_id)."<br><br>" ,
- );
- }
-
- $form['disapprove'] = array(
- '#type' => 'checkbox',
- '#title' => t('Disapprove all the above book preferences'),
-
- );
-
- $form['message'] = array(
- '#type' => 'textarea',
- '#title' => t('Reason for disapproval'),
- );
-
- $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')
- );
-
- $form['cancel'] = array(
- '#type' => 'markup',
- '#value' => l(t('Cancel'), 'manage_proposal'),
- );
- return $form;
+ while ($preference_data = $preference_q->fetchObject())
+ {
+ $category_data = _tbc_list_of_category($preference_data->category);
+ foreach ($category_data as $cat)
+ {
+ $preference_rows[$preference_data->id] = '
+ <table class="book_prefrences">
+ <tr class="even">
+ <td><strong>Book</strong></td>
+ <td>' . $preference_data->book . '</td>
+ </tr>
+ <tr class="odd">
+ <td><strong>Author</strong></td>
+ <td>' . $preference_data->author . '</td>
+ </tr>
+ <tr class="even">
+ <td><strong>Edition</strong></td>
+ <td>' . $preference_data->edition . '</td>
+ </tr>
+ <tr class="odd">
+ <td><strong>Publisher</strong></td>
+ <td>' . $preference_data->publisher . '</td>
+ </tr>
+ <tr class="even">
+ <td><strong>Year</strong></td>
+ <td>' . $preference_data->year . '</td>
+ </tr>
+ <tr class="odd">
+ <td><strong>ISBN</strong></td>
+ <td>' . $preference_data->isbn . '</td>
+ </tr>
+ <tr class="even">
+ <td><strong>Category</strong></td>
+ <td>' . $cat . '</td>
+ </tr>
+ </table><br><br>
+ ';
+ } //$category_data as $cat
+ } //$preference_data = $preference_q->fetchObject()
+ if ($row->proposal_type == 1)
+ {
+ $form['book_preference'] = array(
+ '#type' => 'radios',
+ '#options' => $preference_rows,
+ '#title' => t('Book Preferences'),
+ '#required' => TRUE
+ );
+ } //$row->proposal_type == 1
+ else
+ {
+ $form['book_preference'] = array(
+ '#type' => 'radios',
+ '#title' => t('Book Preferences'),
+ '#options' => $preference_rows,
+ '#required' => TRUE
+ );
+ }
+ if ($row->samplefilepath != "None")
+ {
+ $form['samplecode'] = array(
+ '#type' => 'markup',
+ '#markup' => l('Click here to download sample code', 'download/samplecode/' . $proposal_id) . "<br><br>"
+ );
+ } //$row->samplefilepath != "None"
+ $form['disapprove'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Disapprove all the above book preferences')
+ );
+ $form['message'] = array(
+ '#type' => 'textarea',
+ '#title' => t('Reason for disapproval'),
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="disapprove"]' => array(
+ 'checked' => TRUE
+ )
+ ),
+ 'required' => array(
+ ':input[name="disapprove"]' => array(
+ 'checked' => TRUE
+ )
+ )
+ )
+ );
+ $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')
+ );
+ $form['cancel'] = array(
+ '#type' => 'markup',
+ '#value' => l(t('Cancel'), 'manage_proposal')
+ );
+ return $form;
}
-
function proposal_approval_form_submit($form, &$form_state)
{
- global $user;
-
- /* get current proposal */
- $proposal_id = $form_state['values']['proposal_id'];
-
- $result = db_query("SELECT * FROM {textbook_companion_proposal} WHERE proposal_status = 0 and id = :proposal_id",array(':proposal_id' => $proposal_id));
-
- if ($result)
- {
- if ($row = $result->fetchObject())
- {
- /* everything ok */
- } else {
- drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
- drupal_goto('manage_proposal');
- return;
- }
- } else {
- drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
- drupal_goto('manage_proposal');
- return;
- }
-
- /* disapprove */
- if ($form_state['values']['disapprove'])
- {
-//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));
-
- db_query("UPDATE {textbook_companion_preference} SET approval_status = 2 WHERE proposal_id = :id",array(':id' => $proposal_id));
-
- /* unlock all the aicte books */
-if($form_state['values']['proposal_type']==0){
- $query = "
+ global $user;
+ /* get current proposal */
+ $proposal_id = $form_state['values']['proposal_id'];
+ $result = db_query("SELECT * FROM {textbook_companion_proposal} WHERE proposal_status = 0 and id = :proposal_id", array(
+ ':proposal_id' => $proposal_id
+ ));
+ if ($result)
+ {
+ if ($row = $result->fetchObject())
+ {
+ /* everything ok */
+ } //$row = $result->fetchObject()
+ else
+ {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('manage_proposal');
+ return;
+ }
+ } //$result
+ else
+ {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('manage_proposal');
+ return;
+ }
+ /* disapprove */
+ if ($form_state['values']['disapprove'])
+ {
+ //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
+ ));
+ db_query("UPDATE {textbook_companion_preference} SET approval_status = 2 WHERE proposal_id = :id", array(
+ ':id' => $proposal_id
+ ));
+ /* 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}
";
- db_query($query, array(':proposal_id' => $proposal_id));
-
-
- }
- /* sending email */
- $book_user = user_load($row->uid);
- $email_to = $book_user->mail;
- $from = variable_get('textbook_companion_from_email', '');
- $bcc= variable_get('textbook_companion_emails', '');
- $cc=variable_get('textbook_companion_cc_emails', '');
- $params['proposal_disapproved']['proposal_id'] = $proposal_id;
- $params['proposal_disapproved']['user_id'] = $row->uid;
- $params['proposal_disapproved']['headers']=array('From'=>$from,'MIME-Version'=> '1.0',
- 'Content-Type'=> 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
- 'Content-Transfer-Encoding' => '8Bit',
- 'X-Mailer'=> 'Drupal','Cc' => $cc, 'Bcc' => $bcc);
-
-
- if (!drupal_mail('textbook_companion', 'proposal_disapproved', $email_to , language_default(), $params,$from, TRUE))
- drupal_set_message('Error sending email message.', 'error');
-
- drupal_set_message('Book proposal dis-approved. User has been notified of the dis-approval.', 'error');
- drupal_goto('manage_proposal');
- return;
- }
-
- /* get book preference and set the status */
- $preference_id = $form_state['values']['book_preference'];
-
-
+ db_query($query, array(
+ ':proposal_id' => $proposal_id
+ ));
+ } //$form_state['values']['proposal_type'] == 0
+ /* sending email */
+ $book_user = user_load($row->uid);
+ $email_to = $book_user->mail;
+ $from = variable_get('textbook_companion_from_email', '');
+ $bcc = variable_get('textbook_companion_emails', '');
+ $cc = variable_get('textbook_companion_cc_emails', '');
+ $params['proposal_disapproved']['proposal_id'] = $proposal_id;
+ $params['proposal_disapproved']['user_id'] = $row->uid;
+ $params['proposal_disapproved']['headers'] = array(
+ 'From' => $from,
+ 'MIME-Version' => '1.0',
+ 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
+ 'Content-Transfer-Encoding' => '8Bit',
+ 'X-Mailer' => 'Drupal',
+ 'Cc' => $cc,
+ 'Bcc' => $bcc
+ );
+ if (!drupal_mail('textbook_companion', 'proposal_disapproved', $email_to, language_default(), $params, $from, TRUE))
+ drupal_set_message('Error sending email message.', 'error');
+ drupal_set_message('Book proposal dis-approved. User has been notified of the dis-approval.', 'error');
+ drupal_goto('manage_proposal');
+ return;
+ } //$form_state['values']['disapprove']
+ /* get book preference and set the status */
+ $preference_id = $form_state['values']['book_preference'];
$query = db_update('textbook_companion_proposal');
$query->fields(array(
- 'approver_uid' => $user->uid,
- 'approval_date' => time(),
- 'proposal_status' => 1,
- ));
+ '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);*/
-
+ /*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,
+ 'approval_status' => 1
));
$query->condition('id', $preference_id);
$num_updated = $query->execute();
-
- $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));
-
- /* sending email */
- $book_user = user_load($row->uid);
- $email_to = $book_user->mail;
- $from = variable_get('textbook_companion_from_email', '');
- $bcc = variable_get('textbook_companion_emails', '');
- $cc=variable_get('textbook_companion_cc_emails', '');
- $params['proposal_approved']['proposal_id'] = $proposal_id;
- $params['proposal_approved']['user_id'] = $row->uid;
- $params['proposal_approved']['headers']=array('From'=>$from,'MIME-Version'=> '1.0',
- 'Content-Type'=> 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
- 'Content-Transfer-Encoding' => '8Bit',
- 'X-Mailer'=> 'Drupal','Cc' => $cc, 'Bcc' => $bcc);
-
- if (!drupal_mail('textbook_companion', 'proposal_approved', $email_to , language_default(), $params, $from, TRUE))
- drupal_set_message('Error sending email message.', 'error');
-
- drupal_set_message('Book proposal approved. User has been notified of the approval', 'status');
- drupal_goto('manage_proposal');
- return;
+ db_query($query, array(
+ ':proposal_id' => $proposal_id,
+ ':preference_id' => $preference_id
+ ));
+ /* sending email */
+ $book_user = user_load($row->uid);
+ $email_to = $book_user->mail;
+ $from = variable_get('textbook_companion_from_email', '');
+ $bcc = variable_get('textbook_companion_emails', '');
+ $cc = variable_get('textbook_companion_cc_emails', '');
+ $params['proposal_approved']['proposal_id'] = $proposal_id;
+ $params['proposal_approved']['user_id'] = $row->uid;
+ $params['proposal_approved']['headers'] = array(
+ 'From' => $from,
+ 'MIME-Version' => '1.0',
+ 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
+ 'Content-Transfer-Encoding' => '8Bit',
+ 'X-Mailer' => 'Drupal',
+ 'Cc' => $cc,
+ 'Bcc' => $bcc
+ );
+ if (!drupal_mail('textbook_companion', 'proposal_approved', $email_to, language_default(), $params, $from, TRUE))
+ drupal_set_message('Error sending email message.', 'error');
+ drupal_set_message('Book proposal approved. User has been notified of the approval', 'status');
+ drupal_goto('manage_proposal');
+ return;
}
-
-
/******************************************************************************/
/*************************** PROPOSAL STATUS FORM *****************************/
/******************************************************************************/
-
-function proposal_status_form($form,&$form_state)
+function proposal_status_form($form, &$form_state)
{
- global $user;
-
- /* get current proposal */
- $proposal_id = arg(2);
-
- /*$proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d", $proposal_id);*/
-
+ global $user;
+ /* get current proposal */
+ $proposal_id = arg(2);
+ /*$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');
- return;
- }
-
- $form['full_name'] = array(
- '#type' => 'item',
- '#markup' => $proposal_data->full_name,
- '#title' => t('Contributor Name'),
- );
- $form['email'] = array(
- '#type' => 'item',
- '#markup' => user_load($proposal_data->uid)->mail,
- '#title' => t('Email'),
- );
- $form['mobile'] = array(
- '#type' => 'item',
- '#markup' => $proposal_data->mobile,
- '#title' => t('Mobile'),
- );
- $form['how_project'] = array(
- '#type' => 'item',
- '#markup' => $proposal_data->how_project,
- '#title' => t('How did you come to know about this project'),
- );
- $form['course'] = array(
- '#type' => 'item',
- '#markup' => $proposal_data->course,
- '#title' => t('Course'),
- );
- $form['branch'] = array(
- '#type' => 'item',
- '#markup' => $proposal_data->branch,
- '#title' => t('Department/Branch'),
- );
- $form['university'] = array(
- '#type' => 'item',
- '#markup' => $proposal_data->university,
- '#title' => t('University/Institute'),
- );
- $form['city'] = array(
- '#type' => 'item',
- '#markup' => $proposal_data->city,
- '#title' => t('City'),
- );
- $form['all_state'] = array(
- '#type' => 'item',
- '#markup' => $proposal_data->state,
- '#title' => t('State'),
- );
- $form['country'] = array(
- '#type' => 'item',
- '#markup' => $proposal_data->country,
- '#title' => t('Country'),
- );
- $form['pincode'] = array(
- '#type' => 'item',
- '#markup' => $proposal_data->pincode,
- '#title' => t('Pincode'),
- );
- $form['faculty'] = array(
- '#type' => 'item',
- '#markup' => $proposal_data->faculty,
- '#title' => t('College Teacher/Professor'),
- );
- $form['reviewer'] = array(
- '#type' => 'item',
- '#markup' => $proposal_data->reviewer,
- '#title' => t('Reviewer'),
- );
- $form['completion_date'] = array(
- '#type' => 'item',
- '#markup' => date('d-m-Y', $proposal_data->completion_date),
- '#title' => t('Expected Date of Completion'),
- );
- $form['operating_system'] = array(
- '#type' => 'item',
- '#markup' => $proposal_data->operating_system,
- '#title' => t('Operating System'),
- );
- $form['scilab_version'] = array(
- '#type' => 'item',
- '#markup' => $proposal_data->scilab_version,
- '#title' => t('Scilab Version'),
- );
- if($proposal_data->proposal_type == 1)
- {
- $form['reason'] = array(
- '#type' => 'item',
- '#markup' => $proposal_data->reason,
- '#title' => t('Reason'),
- );
- $form['reference'] = array(
- '#type' => 'item',
- '#markup' => $proposal_data->reference,
- '#title' => t('References'),
- );
- }
-
- /* get book preference */
- $preference_html = '<ul>';
-
+ if (!$proposal_data = $proposal_q->fetchObject())
+ {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('manage_proposal');
+ return;
+ } //!$proposal_data = $proposal_q->fetchObject()
+ $form['full_name'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->full_name,
+ '#title' => t('Contributor Name')
+ );
+ $form['email'] = array(
+ '#type' => 'item',
+ '#markup' => user_load($proposal_data->uid)->mail,
+ '#title' => t('Email')
+ );
+ $form['mobile'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->mobile,
+ '#title' => t('Mobile')
+ );
+ $form['how_project'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->how_project,
+ '#title' => t('How did you come to know about this project')
+ );
+ $form['course'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->course,
+ '#title' => t('Course')
+ );
+ $form['branch'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->branch,
+ '#title' => t('Department/Branch')
+ );
+ $form['university'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->university,
+ '#title' => t('University/Institute')
+ );
+ $form['city'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->city,
+ '#title' => t('City')
+ );
+ $form['all_state'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->state,
+ '#title' => t('State')
+ );
+ $form['country'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->country,
+ '#title' => t('Country')
+ );
+ $form['pincode'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->pincode,
+ '#title' => t('Pincode')
+ );
+ $form['faculty'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->faculty,
+ '#title' => t('College Teacher/Professor')
+ );
+ $form['reviewer'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->reviewer,
+ '#title' => t('Reviewer')
+ );
+ $form['proposed_completion_date'] = array(
+ '#type' => 'item',
+ '#markup' => date('d-m-Y', $proposal_data->proposed_completion_date),
+ '#title' => t('Proposed Date of Completion')
+ );
+ $form['completion_date'] = array(
+ '#type' => 'item',
+ '#markup' => date('d-m-Y', $proposal_data->completion_date),
+ '#title' => t('Actual Date of Completion')
+ );
+ $form['operating_system'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->operating_system,
+ '#title' => t('Operating System')
+ );
+ $form['scilab_version'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->scilab_version,
+ '#title' => t('Scilab Version')
+ );
+ if ($proposal_data->proposal_type == 1)
+ {
+ $form['reason'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->reason,
+ '#title' => t('Reason')
+ );
+ $form['reference'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->reference,
+ '#title' => t('References')
+ );
+ } //$proposal_data->proposal_type == 1
+ /* get book preference */
+ $preference_html = '<ul>';
$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>';
- else
- $preference_html .= '<li>' . $preference_data->book . ' (Written by ' . $preference_data->author . ')</li>';
- }
- $preference_html .= '</ul>';
-
- $form['book_preference'] = array(
- '#type' => 'item',
- '#markup' => $preference_html,
- '#title' => t('Book Preferences'),
- );
-
- $proposal_status = '';
- switch ($proposal_data->proposal_status)
- {
- case 0: $proposal_status = t('Pending'); break;
- case 1: $proposal_status = t('Approved'); break;
- case 2: $proposal_status = t('Dis-approved'); break;
- case 3: $proposal_status = t('Completed'); break;
- case 4: $proposal_status = t('External'); break;
- default: $proposal_status = t('Unkown'); break;
- }
- $form['proposal_status'] = array(
- '#type' => 'item',
- '#markup' => $proposal_status,
- '#title' => t('Proposal Status'),
- );
-
- if ($proposal_data->proposal_status == 2) {
- $form['message'] = array(
- '#type' => 'item',
- '#markup' => $proposal_data->message,
- '#title' => t('Reason for disapproval'),
- );
- }
-
- if ($proposal_data->proposal_status == 1 || $proposal_data->proposal_status == 4)
- {
- $form['completed'] = array(
- '#type' => 'checkbox',
- '#title' => t('Completed'),
- '#description' => t('Check if user has completed all the book examples.'),
- );
- }
-
- if ($proposal_data->proposal_status == 0)
- {
- $form['approve'] = array(
- '#type' => 'item',
- '#markup' => l('Click here', 'manage_proposal/approve/' . $proposal_id),
- '#title' => t('Approve'),
- );
- }
-
- $form['proposal_id'] = array(
- '#type' => 'hidden',
- '#value' => $proposal_id,
- );
-
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Submit')
- );
-
- $form['cancel'] = array(
- '#type' => 'markup',
- '#value' => l(t('Cancel'), 'manage_proposal/all'),
- );
- return $form;
+ 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>';
+ else
+ $preference_html .= '<li>' . $preference_data->book . ' (Written by ' . $preference_data->author . ')</li>';
+ } //$preference_data = $preference_q->fetchObject()
+ $preference_html .= '</ul>';
+ $form['book_preference'] = array(
+ '#type' => 'item',
+ '#markup' => $preference_html,
+ '#title' => t('Book Preferences')
+ );
+ $proposal_status = '';
+ switch ($proposal_data->proposal_status)
+ {
+ case 0:
+ $proposal_status = t('Pending');
+ break;
+ case 1:
+ $proposal_status = t('Approved');
+ break;
+ case 2:
+ $proposal_status = t('Dis-approved');
+ break;
+ case 3:
+ $proposal_status = t('Completed');
+ break;
+ case 4:
+ $proposal_status = t('External');
+ break;
+ default:
+ $proposal_status = t('Unkown');
+ break;
+ } //$proposal_data->proposal_status
+ $form['proposal_status'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_status,
+ '#title' => t('Proposal Status')
+ );
+ if ($proposal_data->proposal_status == 2)
+ {
+ $form['message'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->message,
+ '#title' => t('Reason for disapproval')
+ );
+ } //$proposal_data->proposal_status == 2
+ if ($proposal_data->proposal_status == 1 || $proposal_data->proposal_status == 4)
+ {
+ $form['completed'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Completed'),
+ '#description' => t('Check if user has completed all the book examples.')
+ );
+ } //$proposal_data->proposal_status == 1 || $proposal_data->proposal_status == 4
+ if ($proposal_data->proposal_status == 0)
+ {
+ $form['approve'] = array(
+ '#type' => 'item',
+ '#markup' => l('Click here', 'manage_proposal/approve/' . $proposal_id),
+ '#title' => t('Approve')
+ );
+ } //$proposal_data->proposal_status == 0
+ $form['proposal_id'] = array(
+ '#type' => 'hidden',
+ '#value' => $proposal_id
+ );
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit')
+ );
+ $form['cancel'] = array(
+ '#type' => 'markup',
+ '#value' => l(t('Cancel'), 'manage_proposal/all')
+ );
+ return $form;
}
-
function proposal_status_form_submit($form, &$form_state)
{
- global $user;
-
- /* get current proposal */
- $proposal_id = $form_state['values']['proposal_id'];
-
- /*$proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d", $proposal_id);*/
-
+ global $user;
+ /* get current proposal */
+ $proposal_id = $form_state['values']['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_data = $proposal_q->fetchObject())
- {
- drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
- drupal_goto('manage_proposal');
- return;
- }
-
- /* 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);*/
-
- $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);
- $params['proposal_completed']['proposal_id'] = $proposal_id;
- $params['proposal_completed']['user_id'] = $proposal_data->uid;
- $email_to = $book_user->mail;
- if (!drupal_mail('textbook_companion', 'proposal_completed', $email_to , language_default(), $params, variable_get('textbook_companion_from_email', NULL), TRUE))
- drupal_set_message('Error sending email message.', 'error');
-
- drupal_set_message('Congratulations! Book proposal has been marked as completed. User has been notified of the completion.', 'status');
- }
- drupal_goto('manage_proposal');
- return;
+ if (!$proposal_data = $proposal_q->fetchObject())
+ {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('manage_proposal');
+ return;
+ } //!$proposal_data = $proposal_q->fetchObject()
+ /* 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);*/
+ $query = db_update('textbook_companion_proposal');
+ $query->fields(array(
+ 'proposal_status' => 3,
+ 'completion_date' => time()
+ ));
+ $query->condition('id', $proposal_id);
+ $num_updated = $query->execute();
+ /* sending email */
+ $book_user = user_load($proposal_data->uid);
+ $from = variable_get('textbook_companion_from_email', '');
+ $bcc = variable_get('textbook_companion_emails', '');
+ $cc = variable_get('textbook_companion_cc_emails', '');
+ $email_to = $book_user->mail;
+ $params['proposal_completed']['proposal_id'] = $proposal_id;
+ $params['proposal_completed']['user_id'] = $proposal_data->uid;
+ $params['proposal_completed']['headers'] = array(
+ 'From' => $from,
+ 'MIME-Version' => '1.0',
+ 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
+ 'Content-Transfer-Encoding' => '8Bit',
+ 'X-Mailer' => 'Drupal',
+ 'Cc' => $cc,
+ 'Bcc' => $bcc
+ );
+ if (!drupal_mail('textbook_companion', 'proposal_completed', $email_to, language_default(), $params, $from, TRUE))
+ drupal_set_message('Error sending email message.', 'error');
+ drupal_set_message('Congratulations! Book proposal has been marked as completed. User has been notified of the completion.', 'status');
+ } //$form_state['values']['completed'] == 1
+ drupal_goto('manage_proposal');
+ return;
}
-
-
/******************************************************************************/
/**************************** PROPOSAL EDIT FORM ******************************/
/******************************************************************************/
-
-function proposal_edit_form($form, $form_state,$nonaicte_book)
+function proposal_edit_form($form, &$form_state, $nonaicte_book)
{
- global $user;
-
- /* get current proposal */
- $proposal_id = arg(2);
-
+ global $user;
+ /* get current proposal */
+ $proposal_id = arg(2);
$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 = $proposal_q->fetchObject();
- if (!$proposal_data)
- {
- drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
- drupal_goto('manage_proposal');
- return;
- }
- } else {
- drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
- drupal_goto('manage_proposal');
- return;
- }
-
- $user_data = user_load($proposal_data->uid);
-
+ if ($proposal_q)
+ {
+ $proposal_data = $proposal_q->fetchObject();
+ if (!$proposal_data)
+ {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('manage_proposal');
+ return;
+ } //!$proposal_data
+ } //$proposal_q
+ else
+ {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('manage_proposal');
+ return;
+ }
+ $user_data = user_load($proposal_data->uid);
$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();
-
+ $preference1_data = $preference1_q->fetchObject();
$query = db_select('textbook_companion_preference');
$query->fields('textbook_companion_preference');
$query->condition('proposal_id', $proposal_id);
- $query->condition('pref_number', 2);
+ $query->condition('pref_number', 2);
$query->range(0, 1);
$preference2_q = $query->execute();
- $preference2_data =$preference2_q->fetchObject();
-
+ $preference2_data = $preference2_q->fetchObject();
$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',
- '#title' => t('Full Name'),
- '#size' => 30,
- '#maxlength' => 50,
- '#required' => TRUE,
- '#default_value' => $proposal_data->full_name,
- );
- $form['email_id'] = array(
- '#type' => 'textfield',
- '#title' => t('Email'),
- '#size' => 30,
- '#value' => $user_data->mail,
- '#disabled' => TRUE,
- );
- $form['mobile'] = array(
- '#type' => 'textfield',
- '#title' => t('Mobile No.'),
- '#size' => 30,
- '#maxlength' => 15,
- '#required' => TRUE,
- '#default_value' => $proposal_data->mobile,
- );
- /*$form['how_project'] = array(
- '#type' => 'select',
- '#title' => t('How did you come to know about this project'),
- '#options' => array('Scilab Website' => 'Scilab Website',
- 'Friend' => 'Friend',
- 'Professor/Teacher' => 'Professor/Teacher',
- 'Mailing List' => 'Mailing List',
- 'Poster in my/other college' => 'Poster in my/other college',
- 'Others' => 'Others'),
- '#required' => TRUE,
- '#default_value' => $proposal_data->how_project,
- );*/
- $form['course'] = array(
- '#type' => 'textfield',
- '#title' => t('Course'),
- '#size' => 30,
- '#maxlength' => 50,
- '#required' => TRUE,
- '#default_value' => $proposal_data->course,
- );
- $form['branch'] = array(
- '#type' => 'select',
- '#title' => t('Department/Branch'),
- '#options' => _tbc_list_of_departments(),
- '#required' => TRUE,
- '#default_value' => $proposal_data->branch,
- );
- $form['university'] = array(
- '#type' => 'textfield',
- '#title' => t('University/Institute'),
- '#size' => 30,
- '#maxlength' => 100,
- '#required' => TRUE,
- '#default_value' => $proposal_data->university,
- );
-$form['country'] = array(
- '#type' => 'select',
- '#title' => t('Country'),
- '#options' => array(
- 'India' => 'India',
- 'Others' => 'Others',
- ),
- '#required' => TRUE,
- '#tree' => TRUE,
- '#validated' => TRUE,
- '#default_value' => $proposal_data->country,
- );
- $form['other_country'] = array(
- '#type' => 'textfield',
- '#title' => t('Other than India'),
- '#size' => 100,
- '#attributes' =>array('placeholder' => t('Enter your country name')),
- '#default_value' => $proposal_data->country,
- '#states' => array(
- 'visible' => array(
- ':input[name="country"]' => array('value' => 'Others'),
- ),
- ),
- );
- $form['other_state'] = array(
- '#type' => 'textfield',
- '#title' => t('State other than India'),
- '#size' => 100,
- '#attributes' =>array('placeholder' => t('Enter your state/region name')),
- '#default_value' => $proposal_data->state,
- '#states' => array(
- 'visible' => array(
- ':input[name="country"]' => array('value' => 'Others'),
- ),
- ),
- );
- $form['other_city'] = array(
- '#type' => 'textfield',
- '#title' => t('City other than India'),
- '#size' => 100,
- '#attributes' =>array('placeholder' => t('Enter your city name')),
- '#default_value' => $proposal_data->city,
- '#states' => array(
- 'visible' => array(
- ':input[name="country"]' => array('value' => 'Others'),
- ),
- ),
- );
- $form['all_state'] = array(
- '#type' => 'select',
- '#title' => t('State'),
- '#options' => _tbc_list_of_states(),
- '#validated' => TRUE,
- '#default_value' => $proposal_data->state,
- '#states' => array(
- 'visible' => array(
- ':input[name="country"]' => array('value' => 'India'),
- ),
- ),
- );
- $form['city'] = array(
- '#type' => 'select',
- '#title' => t('City'),
- '#options' => _tbc_list_of_cities(),
- '#default_value' => $proposal_data->city,
- '#states' => array(
- 'visible' => array(
- ':input[name="country"]' => array('value' => 'India'),
- ),
- ),
- );
- $form['pincode'] = array(
- '#type' => 'textfield',
- '#title' => t('Pincode'),
- '#size' => 30,
- '#maxlength' => 6,
- '#default_value' => $proposal_data->pincode,
- '#required' => False,
- '#attributes' =>array('placeholder' =>'Enter pincode....'),
- );
- $form['faculty'] = array(
- '#type' => 'textfield',
- '#title' => t('College Teacher/Professor'),
- '#size' => 30,
- '#maxlength' => 100,
- '#required' => TRUE,
- '#default_value' => $proposal_data->faculty,
- );
- $form['reviewer'] = array(
- '#type' => 'textfield',
- '#title' => t('Reviewer'),
- '#size' => 30,
- '#maxlength' => 100,
- '#default_value' => $proposal_data->reviewer,
- );
- $form['completion_date'] = array(
- '#type' => 'textfield',
- '#title' => t('Expected Date of Completion'),
- '#description' => t('Input date format should be DD-MM-YYYY. Eg: 23-03-2011'),
- '#size' => 10,
- '#maxlength' => 10,
- '#default_value' => date('d-m-Y', $proposal_data->completion_date),
- );
- list($scilab, $version) = explode(' ', $proposal_data->scilab_version);
- $scilab_version = $version;
- $form['version'] = array(
- '#type' => 'textfield',
- '#title' => t('Scilab Version'),
- '#size' => 10,
- '#maxlength' => 20,
- '#default_value' => $scilab_version,
- );
- $form['operating_system'] = array(
- '#type' => 'textfield',
- '#title' => t('Operating System'),
- '#size' => 30,
- '#maxlength' => 50,
- '#default_value' => $proposal_data->operating_system,
- );
- $form['preference1'] = array(
- '#type' => 'fieldset',
- '#title' => t('Book Preference 1'),
- '#collapsible' => TRUE,
- '#collapsed' => FALSE,
- );
- $form['preference1']['book1'] = array(
- '#type' => 'textfield',
- '#title' => t('Title of the book'),
- '#size' => 30,
- '#maxlength' => 100,
- '#required' => TRUE,
- '#default_value' => $preference1_data->book,
- );
- $form['preference1']['author1'] = array(
- '#type' => 'textfield',
- '#title' => t('Author Name'),
- '#size' => 30,
- '#maxlength' => 100,
- '#required' => TRUE,
- '#default_value' => $preference1_data->author,
- );
- $form['preference1']['isbn1'] = array(
- '#type' => 'textfield',
- '#title' => t('ISBN No'),
- '#size' => 30,
- '#maxlength' => 25,
- '#required' => TRUE,
- '#default_value' => $preference1_data->isbn,
- );
- $form['preference1']['publisher1'] = array(
- '#type' => 'textfield',
- '#title' => t('Publisher & Place'),
- '#size' => 30,
- '#maxlength' => 50,
- '#required' => TRUE,
- '#default_value' => $preference1_data->publisher,
- );
- $form['preference1']['edition1'] = array(
- '#type' => 'textfield',
- '#title' => t('Edition'),
- '#size' => 4,
- '#maxlength' => 2,
- '#required' => TRUE,
- '#default_value' => $preference1_data->edition,
- );
- $form['preference1']['year1'] = array(
- '#type' => 'textfield',
- '#title' => t('Year of pulication'),
- '#size' => 4,
- '#maxlength' => 4,
- '#required' => TRUE,
- '#default_value' => $preference1_data->year,
- );
- $form['preference1']['book_category_1'] = array(
- '#type' => 'select',
- '#title' => t('Category'),
- '#options' => _tbc_list_of_category(),
- '#required' => TRUE,
- '#default_value' => $preference1_data->category,
- );
- if($preference2_data){
- $form['preference2'] = array(
- '#type' => 'fieldset',
- '#title' => t('Book Preference 2'),
- '#collapsible' => TRUE,
- '#collapsed' => FALSE,
- );
- $form['preference2']['book2'] = array(
- '#type' => 'textfield',
- '#title' => t('Title of the book'),
- '#size' => 30,
- '#maxlength' => 100,
- '#required' => TRUE,
- '#default_value' => $preference2_data->book,
- );
- $form['preference2']['author2'] = array(
- '#type' => 'textfield',
- '#title' => t('Author Name'),
- '#size' => 30,
- '#maxlength' => 100,
- '#required' => TRUE,
- '#default_value' => $preference2_data->author,
- );
- $form['preference2']['isbn2'] = array(
- '#type' => 'textfield',
- '#title' => t('ISBN No'),
- '#size' => 30,
- '#maxlength' => 25,
- '#required' => TRUE,
- '#default_value' => $preference2_data->isbn,
- );
- $form['preference2']['publisher2'] = array(
- '#type' => 'textfield',
- '#title' => t('Publisher & Place'),
- '#size' => 30,
- '#maxlength' => 50,
- '#required' => TRUE,
- '#default_value' => $preference2_data->publisher,
- );
- $form['preference2']['edition2'] = array(
- '#type' => 'textfield',
- '#title' => t('Edition'),
- '#size' => 4,
- '#maxlength' => 2,
- '#required' => TRUE,
- '#default_value' => $preference2_data->edition,
- );
- $form['preference2']['year2'] = array(
- '#type' => 'textfield',
- '#title' => t('Year of pulication'),
- '#size' => 4,
- '#maxlength' => 4,
- '#required' => TRUE,
- '#default_value' => $preference2_data->year,
- );
- $form['preference2']['book_category_2'] = array(
- '#type' => 'select',
- '#title' => t('Category'),
- '#options' => _tbc_list_of_category(),
- '#required' => TRUE,
- '#default_value' => $preference2_data->category,
- );
-}
-if($preference3_data){
- $form['preference3'] = array(
- '#type' => 'fieldset',
- '#title' => t('Book Preference 3'),
- '#collapsible' => TRUE,
- '#collapsed' => FALSE,
- );
- $form['preference3']['book3'] = array(
- '#type' => 'textfield',
- '#title' => t('Title of the book'),
- '#size' => 30,
- '#maxlength' => 100,
- '#required' => TRUE,
- '#default_value' => $preference3_data->book,
- );
- $form['preference3']['author3'] = array(
- '#type' => 'textfield',
- '#title' => t('Author Name'),
- '#size' => 30,
- '#maxlength' => 100,
- '#required' => TRUE,
- '#default_value' => $preference3_data->author,
- );
- $form['preference3']['isbn3'] = array(
- '#type' => 'textfield',
- '#title' => t('ISBN No'),
- '#size' => 30,
- '#maxlength' => 25,
- '#required' => TRUE,
- '#default_value' => $preference3_data->isbn,
- );
- $form['preference3']['publisher3'] = array(
- '#type' => 'textfield',
- '#title' => t('Publisher & Place'),
- '#size' => 30,
- '#maxlength' => 50,
- '#required' => TRUE,
- '#default_value' => $preference3_data->publisher,
- );
- $form['preference3']['edition3'] = array(
- '#type' => 'textfield',
- '#title' => t('Edition'),
- '#size' => 4,
- '#maxlength' => 2,
- '#required' => TRUE,
- '#default_value' => $preference3_data->edition,
- );
- $form['preference3']['year3'] = array(
- '#type' => 'textfield',
- '#title' => t('Year of pulication'),
- '#size' => 4,
- '#maxlength' => 4,
- '#required' => TRUE,
- '#default_value' => $preference3_data->year,
- );
- $form['preference3']['book_category_3'] = array(
- '#type' => 'select',
- '#title' => t('Category'),
- '#options' => _tbc_list_of_category(),
- '#required' => TRUE,
- '#default_value' => $preference3_data->category,
- );
-}
-
- /* hidden fields */
- $form['hidden_proposal_id'] = array(
- '#type' => 'hidden',
- '#value' => $proposal_id,
- );
-
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Submit')
- );
- $form['cancel'] = array(
- '#type' => 'markup',
- '#value' => l(t('Cancel'), 'manage_proposal'),
- );
- return $form;
+ $preference3_data = $preference3_q->fetchObject();
+ $form['full_name'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Full Name'),
+ '#size' => 30,
+ '#maxlength' => 50,
+ '#required' => TRUE,
+ '#default_value' => $proposal_data->full_name
+ );
+ $form['email_id'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Email'),
+ '#size' => 30,
+ '#value' => $user_data->mail,
+ '#disabled' => TRUE
+ );
+ $form['mobile'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Mobile No.'),
+ '#size' => 30,
+ '#maxlength' => 15,
+ '#required' => TRUE,
+ '#default_value' => $proposal_data->mobile
+ );
+ /*$form['how_project'] = array(
+ '#type' => 'select',
+ '#title' => t('How did you come to know about this project'),
+ '#options' => array('Scilab Website' => 'Scilab Website',
+ 'Friend' => 'Friend',
+ 'Professor/Teacher' => 'Professor/Teacher',
+ 'Mailing List' => 'Mailing List',
+ 'Poster in my/other college' => 'Poster in my/other college',
+ 'Others' => 'Others'),
+ '#required' => TRUE,
+ '#default_value' => $proposal_data->how_project,
+ );*/
+ $form['course'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Course'),
+ '#size' => 30,
+ '#maxlength' => 50,
+ '#required' => TRUE,
+ '#default_value' => $proposal_data->course
+ );
+ $form['branch'] = array(
+ '#type' => 'select',
+ '#title' => t('Department/Branch'),
+ '#options' => _tbc_list_of_departments(),
+ '#required' => TRUE,
+ '#default_value' => $proposal_data->branch
+ );
+ $form['university'] = array(
+ '#type' => 'textfield',
+ '#title' => t('University/Institute'),
+ '#size' => 30,
+ '#maxlength' => 100,
+ '#required' => TRUE,
+ '#default_value' => $proposal_data->university
+ );
+ $form['country'] = array(
+ '#type' => 'select',
+ '#title' => t('Country'),
+ '#options' => array(
+ 'India' => 'India',
+ 'Others' => 'Others'
+ ),
+ '#required' => TRUE,
+ '#tree' => TRUE,
+ '#validated' => TRUE,
+ '#default_value' => $proposal_data->country
+ );
+ $form['other_country'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Other than India'),
+ '#size' => 100,
+ '#attributes' => array(
+ 'placeholder' => t('Enter your country name')
+ ),
+ '#default_value' => $proposal_data->country,
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="country"]' => array(
+ 'value' => 'Others'
+ )
+ )
+ )
+ );
+ $form['other_state'] = array(
+ '#type' => 'textfield',
+ '#title' => t('State other than India'),
+ '#size' => 100,
+ '#attributes' => array(
+ 'placeholder' => t('Enter your state/region name')
+ ),
+ '#default_value' => $proposal_data->state,
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="country"]' => array(
+ 'value' => 'Others'
+ )
+ )
+ )
+ );
+ $form['other_city'] = array(
+ '#type' => 'textfield',
+ '#title' => t('City other than India'),
+ '#size' => 100,
+ '#attributes' => array(
+ 'placeholder' => t('Enter your city name')
+ ),
+ '#default_value' => $proposal_data->city,
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="country"]' => array(
+ 'value' => 'Others'
+ )
+ )
+ )
+ );
+ $form['all_state'] = array(
+ '#type' => 'select',
+ '#title' => t('State'),
+ '#options' => _tbc_list_of_states(),
+ '#validated' => TRUE,
+ '#default_value' => $proposal_data->state,
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="country"]' => array(
+ 'value' => 'India'
+ )
+ )
+ )
+ );
+ $form['city'] = array(
+ '#type' => 'select',
+ '#title' => t('City'),
+ '#options' => _tbc_list_of_cities(),
+ '#default_value' => $proposal_data->city,
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="country"]' => array(
+ 'value' => 'India'
+ )
+ )
+ )
+ );
+ $form['pincode'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Pincode'),
+ '#size' => 30,
+ '#maxlength' => 6,
+ '#default_value' => $proposal_data->pincode,
+ '#required' => False,
+ '#attributes' => array(
+ 'placeholder' => 'Enter pincode....'
+ )
+ );
+ $form['faculty'] = array(
+ '#type' => 'textfield',
+ '#title' => t('College Teacher/Professor'),
+ '#size' => 30,
+ '#maxlength' => 100,
+ '#required' => TRUE,
+ '#default_value' => $proposal_data->faculty
+ );
+ $form['reviewer'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Reviewer'),
+ '#size' => 30,
+ '#maxlength' => 100,
+ '#default_value' => $proposal_data->reviewer
+ );
+ $form['completion_date'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Expected Date of Completion'),
+ '#description' => t('Input date format should be DD-MM-YYYY. Eg: 23-03-2011'),
+ '#size' => 10,
+ '#maxlength' => 10,
+ '#default_value' => date('d-m-Y', $proposal_data->completion_date)
+ );
+ $form['proposed_completion_date'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Proposed Date of Completion'),
+ '#description' => t('Input date format should be DD-MM-YYYY. Eg: 23-03-2011'),
+ '#size' => 10,
+ '#maxlength' => 10,
+ '#default_value' => date('d-m-Y', $proposal_data->proposed_completion_date)
+ );
+ list($scilab, $version) = explode(' ', $proposal_data->scilab_version);
+ $scilab_version = $version;
+ $form['version'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Scilab Version'),
+ '#size' => 10,
+ '#maxlength' => 20,
+ '#default_value' => $scilab_version
+ );
+ $form['operating_system'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Operating System'),
+ '#size' => 30,
+ '#maxlength' => 50,
+ '#default_value' => $proposal_data->operating_system
+ );
+ $form['preference1'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Book Preference 1'),
+ '#collapsible' => TRUE,
+ '#collapsed' => FALSE
+ );
+ $form['preference1']['book1'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Title of the book'),
+ '#size' => 30,
+ '#maxlength' => 100,
+ '#required' => TRUE,
+ '#default_value' => $preference1_data->book
+ );
+ $form['preference1']['author1'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Author Name'),
+ '#size' => 30,
+ '#maxlength' => 100,
+ '#required' => TRUE,
+ '#default_value' => $preference1_data->author
+ );
+ $form['preference1']['isbn1'] = array(
+ '#type' => 'textfield',
+ '#title' => t('ISBN No'),
+ '#size' => 30,
+ '#maxlength' => 25,
+ '#required' => TRUE,
+ '#default_value' => $preference1_data->isbn
+ );
+ $form['preference1']['publisher1'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Publisher & Place'),
+ '#size' => 30,
+ '#maxlength' => 50,
+ '#required' => TRUE,
+ '#default_value' => $preference1_data->publisher
+ );
+ $form['preference1']['edition1'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Edition'),
+ '#size' => 4,
+ '#maxlength' => 2,
+ '#required' => TRUE,
+ '#default_value' => $preference1_data->edition
+ );
+ $form['preference1']['year1'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Year of pulication'),
+ '#size' => 4,
+ '#maxlength' => 4,
+ '#required' => TRUE,
+ '#default_value' => $preference1_data->year
+ );
+ $form['preference1']['book_category_1'] = array(
+ '#type' => 'select',
+ '#title' => t('Category'),
+ '#options' => _tbc_list_of_category(),
+ '#required' => TRUE,
+ '#default_value' => $preference1_data->category
+ );
+ if ($preference2_data)
+ {
+ $form['preference2'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Book Preference 2'),
+ '#collapsible' => TRUE,
+ '#collapsed' => FALSE
+ );
+ $form['preference2']['book2'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Title of the book'),
+ '#size' => 30,
+ '#maxlength' => 100,
+ '#required' => TRUE,
+ '#default_value' => $preference2_data->book
+ );
+ $form['preference2']['author2'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Author Name'),
+ '#size' => 30,
+ '#maxlength' => 100,
+ '#required' => TRUE,
+ '#default_value' => $preference2_data->author
+ );
+ $form['preference2']['isbn2'] = array(
+ '#type' => 'textfield',
+ '#title' => t('ISBN No'),
+ '#size' => 30,
+ '#maxlength' => 25,
+ '#required' => TRUE,
+ '#default_value' => $preference2_data->isbn
+ );
+ $form['preference2']['publisher2'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Publisher & Place'),
+ '#size' => 30,
+ '#maxlength' => 50,
+ '#required' => TRUE,
+ '#default_value' => $preference2_data->publisher
+ );
+ $form['preference2']['edition2'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Edition'),
+ '#size' => 4,
+ '#maxlength' => 2,
+ '#required' => TRUE,
+ '#default_value' => $preference2_data->edition
+ );
+ $form['preference2']['year2'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Year of pulication'),
+ '#size' => 4,
+ '#maxlength' => 4,
+ '#required' => TRUE,
+ '#default_value' => $preference2_data->year
+ );
+ $form['preference2']['book_category_2'] = array(
+ '#type' => 'select',
+ '#title' => t('Category'),
+ '#options' => _tbc_list_of_category(),
+ '#required' => TRUE,
+ '#default_value' => $preference2_data->category
+ );
+ } //$preference2_data
+ if ($preference3_data)
+ {
+ $form['preference3'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Book Preference 3'),
+ '#collapsible' => TRUE,
+ '#collapsed' => FALSE
+ );
+ $form['preference3']['book3'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Title of the book'),
+ '#size' => 30,
+ '#maxlength' => 100,
+ '#required' => TRUE,
+ '#default_value' => $preference3_data->book
+ );
+ $form['preference3']['author3'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Author Name'),
+ '#size' => 30,
+ '#maxlength' => 100,
+ '#required' => TRUE,
+ '#default_value' => $preference3_data->author
+ );
+ $form['preference3']['isbn3'] = array(
+ '#type' => 'textfield',
+ '#title' => t('ISBN No'),
+ '#size' => 30,
+ '#maxlength' => 25,
+ '#required' => TRUE,
+ '#default_value' => $preference3_data->isbn
+ );
+ $form['preference3']['publisher3'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Publisher & Place'),
+ '#size' => 30,
+ '#maxlength' => 50,
+ '#required' => TRUE,
+ '#default_value' => $preference3_data->publisher
+ );
+ $form['preference3']['edition3'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Edition'),
+ '#size' => 4,
+ '#maxlength' => 2,
+ '#required' => TRUE,
+ '#default_value' => $preference3_data->edition
+ );
+ $form['preference3']['year3'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Year of pulication'),
+ '#size' => 4,
+ '#maxlength' => 4,
+ '#required' => TRUE,
+ '#default_value' => $preference3_data->year
+ );
+ $form['preference3']['book_category_3'] = array(
+ '#type' => 'select',
+ '#title' => t('Category'),
+ '#options' => _tbc_list_of_category(),
+ '#required' => TRUE,
+ '#default_value' => $preference3_data->category
+ );
+ } //$preference3_data
+ /* hidden fields */
+ $form['hidden_proposal_id'] = array(
+ '#type' => 'hidden',
+ '#value' => $proposal_id
+ );
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit')
+ );
+ $form['cancel'] = array(
+ '#type' => 'markup',
+ '#value' => l(t('Cancel'), 'manage_proposal')
+ );
+ return $form;
}
-
function proposal_edit_form_validate($form, &$form_state)
{
- /* version */
- if (!preg_match('/^\d+(?:\.\d+)+/', $form_state['values']['version']))
- form_set_error('version', t('Please enter correct version in speacifed format'));
- /* mobile */
- if (!preg_match('/^[0-9\ \+]{0,15}$/', $form_state['values']['mobile']))
- form_set_error('mobile', t('Invalid mobile number'));
-
- /* date of completion */
- if (!preg_match('/^[0-9]{1,2}-[0-9]{1,2}-[0-9]{4}$/', $form_state['values']['completion_date']))
- form_set_error('completion_date', t('Invalid expected date of completion'));
-
- list($d, $m, $y) = explode('-', $form_state['values']['completion_date']);
- $d = (int)$d; $m = (int)$m; $y = (int)$y;
- if (!checkdate($m, $d, $y))
- form_set_error('completion_date', t('Invalid expected date of completion'));
- //if (mktime(0, 0, 0, $m, $d, $y) <= time())
- //form_set_error('completion_date', t('Expected date of completion should be in future'));
-
- /* edition */
- if (!preg_match('/^[1-9][0-9]{0,1}$/', $form_state['values']['edition1']))
- form_set_error('edition1', t('Invalid edition for Book Preference 1'));
- if($form_state['values']['edition2']){
- if (!preg_match('/^[1-9][0-9]{0,1}$/', $form_state['values']['edition2']))
- form_set_error('edition2', t('Invalid edition for Book Preference 2'));
- if (!preg_match('/^[1-9][0-9]{0,1}$/', $form_state['values']['edition3']))
- form_set_error('edition3', t('Invalid edition for Book Preference 3'));
-}
-
-
- /* year of publication */
- if (!preg_match('/^[1-3][0-9][0-9][0-9]$/', $form_state['values']['year1']))
- form_set_error('year1', t('Invalid year of pulication for Book Preference 1'));
- if($form_state['values']['edition2']){
- if (!preg_match('/^[1-3][0-9][0-9][0-9]$/', $form_state['values']['year2']))
- form_set_error('year2', t('Invalid year of pulication for Book Preference 2'));
- if (!preg_match('/^[1-3][0-9][0-9][0-9]$/', $form_state['values']['year3']))
- form_set_error('year3', t('Invalid year of pulication for Book Preference 3'));
-}
-
- /* year of publication */
- $cur_year = date('Y');
- if ((int)$form_state['values']['year1'] > $cur_year)
- form_set_error('year1', t('Year of pulication should be not in the future for Book Preference 1'));
- if ((int)$form_state['values']['year2'] > $cur_year)
- form_set_error('year2', t('Year of pulication should be not in the future for Book Preference 2'));
- if ((int)$form_state['values']['year3'] > $cur_year)
- form_set_error('year3', t('Year of pulication should be not in the future for Book Preference 3'));
-
- /* isbn */
- if (!preg_match('/^[0-9\-xX]+$/', $form_state['values']['isbn1']))
- form_set_error('isbn1', t('Invalid ISBN for Book Preference 1'));
- if($form_state['values']['edition2']){
- if (!preg_match('/^[0-9\-xX]+$/', $form_state['values']['isbn2']))
- form_set_error('isbn2', t('Invalid ISBN for Book Preference 2'));
- if (!preg_match('/^[0-9\-xX]+$/', $form_state['values']['isbn3']))
- form_set_error('isbn3', t('Invalid ISBN for Book Preference 3'));
-}
-
-if($form_state['values']['country']=='Others'){
- if($form_state['values']['other_country']== ''){
- form_set_error('other_country', t('Enter country name'));
- // $form_state['values']['country'] = $form_state['values']['other_country'];
- }else{
- $form_state['values']['country'] = $form_state['values']['other_country'];
- }
- if($form_state['values']['other_state']== ''){
- form_set_error('other_state', t('Enter state name'));
- // $form_state['values']['country'] = $form_state['values']['other_country'];
- }else{
- $form_state['values']['all_state'] = $form_state['values']['other_state'];
- }
- if($form_state['values']['other_city']== ''){
- form_set_error('other_city', t('Enter city name'));
- // $form_state['values']['country'] = $form_state['values']['other_country'];
- }else{
- $form_state['values']['city'] = $form_state['values']['other_city'];
- }
- }else{
- if($form_state['values']['country']== ''){
- form_set_error('country', t('Select country name'));
- // $form_state['values']['country'] = $form_state['values']['other_country'];
- }
- if($form_state['values']['all_state']== ''){
- form_set_error('all_state', t('Select state name'));
- // $form_state['values']['country'] = $form_state['values']['other_country'];
- }
- if($form_state['values']['city']== ''){
- form_set_error('city', t('Select city name'));
- // $form_state['values']['country'] = $form_state['values']['other_country'];
- }
-
-
- }
-
-
-
- return;
+ /* version */
+ if (!preg_match('/^\d+(?:\.\d+)+/', $form_state['values']['version']))
+ form_set_error('version', t('Please enter correct version in speacifed format'));
+ /* mobile */
+ if (!preg_match('/^[0-9\ \+]{0,15}$/', $form_state['values']['mobile']))
+ form_set_error('mobile', t('Invalid mobile number'));
+ /* date of completion */
+ if (!preg_match('/^[0-9]{1,2}-[0-9]{1,2}-[0-9]{4}$/', $form_state['values']['completion_date']))
+ form_set_error('completion_date', t('Invalid expected date of completion'));
+ list($d, $m, $y) = explode('-', $form_state['values']['completion_date']);
+ $d = (int) $d;
+ $m = (int) $m;
+ $y = (int) $y;
+ if (!checkdate($m, $d, $y))
+ form_set_error('completion_date', t('Invalid expected date of completion'));
+ //if (mktime(0, 0, 0, $m, $d, $y) <= time())
+ //form_set_error('completion_date', t('Expected date of completion should be in future'));
+ /* edition */
+ if (!preg_match('/^[1-9][0-9]{0,1}$/', $form_state['values']['edition1']))
+ form_set_error('edition1', t('Invalid edition for Book Preference 1'));
+ if ($form_state['values']['book2'])
+ {
+ if (!preg_match('/^[1-9][0-9]{0,1}$/', $form_state['values']['edition2']))
+ {
+ form_set_error('edition2', t('Invalid edition for Book Preference 2'));
+ } //!preg_match('/^[1-9][0-9]{0,1}$/', $form_state['values']['edition2'])
+ } //$form_state['values']['book2']
+ if ($form_state['values']['book3'])
+ {
+ if (!preg_match('/^[1-9][0-9]{0,1}$/', $form_state['values']['edition3']))
+ {
+ form_set_error('edition3', t('Invalid edition for Book Preference 3'));
+ } //!preg_match('/^[1-9][0-9]{0,1}$/', $form_state['values']['edition3'])
+ } //$form_state['values']['book3']
+ /* year of publication */
+ if (!preg_match('/^[1-3][0-9][0-9][0-9]$/', $form_state['values']['year1']))
+ form_set_error('year1', t('Invalid year of pulication for Book Preference 1'));
+ if ($form_state['values']['book2'])
+ {
+ if (!preg_match('/^[1-3][0-9][0-9][0-9]$/', $form_state['values']['year2']))
+ {
+ form_set_error('year2', t('Invalid year of pulication for Book Preference 2'));
+ } //!preg_match('/^[1-3][0-9][0-9][0-9]$/', $form_state['values']['year2'])
+ } //$form_state['values']['book2']
+ if ($form_state['values']['book3'])
+ {
+ if (!preg_match('/^[1-3][0-9][0-9][0-9]$/', $form_state['values']['year3']))
+ {
+ form_set_error('year3', t('Invalid year of pulication for Book Preference 3'));
+ } //!preg_match('/^[1-3][0-9][0-9][0-9]$/', $form_state['values']['year3'])
+ } //$form_state['values']['book3']
+ /* year of publication */
+ $cur_year = date('Y');
+ if ((int) $form_state['values']['year1'] > $cur_year)
+ form_set_error('year1', t('Year of pulication should be not in the future for Book Preference 1'));
+ if ($form_state['values']['book2'])
+ {
+ if ((int) $form_state['values']['year2'] > $cur_year)
+ {
+ form_set_error('year2', t('Year of pulication should be not in the future for Book Preference 2'));
+ } //(int) $form_state['values']['year2'] > $cur_year
+ } //$form_state['values']['book2']
+ if ($form_state['values']['book3'])
+ {
+ if ((int) $form_state['values']['year3'] > $cur_year)
+ {
+ form_set_error('year3', t('Year of pulication should be not in the future for Book Preference 3'));
+ } //(int) $form_state['values']['year3'] > $cur_year
+ } //$form_state['values']['book3']
+ /* isbn */
+ if (!preg_match('/^[0-9\-xX]+$/', $form_state['values']['isbn1']))
+ form_set_error('isbn1', t('Invalid ISBN for Book Preference 1'));
+ if ($form_state['values']['book2'])
+ {
+ if (!preg_match('/^[0-9\-xX]+$/', $form_state['values']['isbn2']))
+ {
+ form_set_error('isbn2', t('Invalid ISBN for Book Preference 2'));
+ } //!preg_match('/^[0-9\-xX]+$/', $form_state['values']['isbn2'])
+ } //$form_state['values']['book2']
+ if ($form_state['values']['book3'])
+ {
+ if (!preg_match('/^[0-9\-xX]+$/', $form_state['values']['isbn3']))
+ {
+ form_set_error('isbn3', t('Invalid ISBN for Book Preference 3'));
+ } //!preg_match('/^[0-9\-xX]+$/', $form_state['values']['isbn3'])
+ } //$form_state['values']['book3']
+ if ($form_state['values']['country'] == 'Others')
+ {
+ if ($form_state['values']['other_country'] == '')
+ {
+ form_set_error('other_country', t('Enter country name'));
+ // $form_state['values']['country'] = $form_state['values']['other_country'];
+ } //$form_state['values']['other_country'] == ''
+ else
+ {
+ $form_state['values']['country'] = $form_state['values']['other_country'];
+ }
+ if ($form_state['values']['other_state'] == '')
+ {
+ form_set_error('other_state', t('Enter state name'));
+ // $form_state['values']['country'] = $form_state['values']['other_country'];
+ } //$form_state['values']['other_state'] == ''
+ else
+ {
+ $form_state['values']['all_state'] = $form_state['values']['other_state'];
+ }
+ if ($form_state['values']['other_city'] == '')
+ {
+ form_set_error('other_city', t('Enter city name'));
+ // $form_state['values']['country'] = $form_state['values']['other_country'];
+ } //$form_state['values']['other_city'] == ''
+ else
+ {
+ $form_state['values']['city'] = $form_state['values']['other_city'];
+ }
+ } //$form_state['values']['country'] == 'Others'
+ else
+ {
+ if ($form_state['values']['country'] == '')
+ {
+ form_set_error('country', t('Select country name'));
+ // $form_state['values']['country'] = $form_state['values']['other_country'];
+ } //$form_state['values']['country'] == ''
+ if ($form_state['values']['all_state'] == '')
+ {
+ form_set_error('all_state', t('Select state name'));
+ // $form_state['values']['country'] = $form_state['values']['other_country'];
+ } //$form_state['values']['all_state'] == ''
+ if ($form_state['values']['city'] == '')
+ {
+ form_set_error('city', t('Select city name'));
+ // $form_state['values']['country'] = $form_state['values']['other_country'];
+ } //$form_state['values']['city'] == ''
+ }
+ return;
}
-/***************** proposal edit from ********************/
+/***************** proposal edit from submit ********************/
function proposal_edit_form_submit($form, &$form_state)
{
- /* completion date to timestamp */
- list($d, $m, $y) = explode('-', $form_state['values']['completion_date']);
- $completion_date_timestamp = mktime(0, 0, 0, $m, $d, $y);
- $scilab_version = 'scilab ' . $form_state['values']['version'];
- $proposal_id = $form_state['values']['hidden_proposal_id'];
- $scilab_version = 'scilab ' . $form_state['values']['version'];
-
-$query = db_update('textbook_companion_proposal');
+ /* completion date to timestamp */
+ list($d, $m, $y) = explode('-', $form_state['values']['completion_date']);
+ $completion_date_timestamp = mktime(0, 0, 0, $m, $d, $y);
+ list($d, $m, $y) = explode('-', $form_state['values']['proposed_completion_date']);
+ $proposed_completion_date_timestamp = mktime(0, 0, 0, $m, $d, $y);
+ $scilab_version = 'scilab ' . $form_state['values']['version'];
+ $proposal_id = $form_state['values']['hidden_proposal_id'];
+ $scilab_version = 'scilab ' . $form_state['values']['version'];
+ $query = db_update('textbook_companion_proposal');
$query->fields(array(
- 'full_name' => $form_state['values']['full_name'],
- 'mobile' => $form_state['values'][ 'mobile'],
- 'course' => $form_state['values']['course'],
- 'branch' => $form_state['values']['branch'],
- 'university' => $form_state['values']['university'],
- 'country' => $form_state['values']['country'],
- 'city' => $form_state['values']['city'],
- 'pincode' => $form_state['values']['pincode'],
- 'state' => $form_state['values']['all_state'],
+ 'full_name' => $form_state['values']['full_name'],
+ 'mobile' => $form_state['values']['mobile'],
+ 'course' => $form_state['values']['course'],
+ 'branch' => $form_state['values']['branch'],
+ 'university' => $form_state['values']['university'],
+ 'country' => $form_state['values']['country'],
+ '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' => $scilab_version,
- ));
+ 'reviewer' => $form_state['values']['reviewer'],
+ 'completion_date' => $completion_date_timestamp,
+ 'operating_system' => $form_state['values']['operating_system'],
+ 'scilab_version' => $scilab_version,
+ 'proposed_completion_date' => $proposed_completion_date_timestamp,
+ ));
$query->condition('id', $proposal_id);
$num_updated = $query->execute();
-
$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;
-
+ $preference1_data = $preference1_q->fetchObject();
+ if ($preference1_data)
+ $preference1_id = $preference1_data->id;
$query = db_select('textbook_companion_preference');
$query->fields('textbook_companion_preference');
$query->condition('proposal_id', $proposal_id);
@@ -1319,346 +1495,328 @@ $query = db_update('textbook_companion_proposal');
$query->range(0, 1);
$preference2_q = $query->execute();
$preference2_data = $preference2_q->fetchObject();
-
- if ($preference2_data)
- $preference2_id = $preference2_data->id;
-
+ if ($preference2_data)
+ $preference2_id = $preference2_data->id;
$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);
-
- $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'],
- 'category' => $form_state['values']['book_category_1'],
- ));
- $query->condition('id', $preference1_id);
- $num_updated = $query->execute();
-
- }
- if ($preference2_data)
- {
- del_book_pdf($preference2_data->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'],
- 'category' => $form_state['values']['book_category_2'],
- ));
- $query->condition('id', $preference2_id);
- $num_updated = $query->execute();
-
- }
- if ($preference3_data)
- {
- del_book_pdf($preference3_data->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'],
- 'category' => $form_state['values']['book_category_3'],
- ));
- $query->condition('id',$preference3_id);
- $num_updated = $query->execute();
-
- }
- drupal_set_message(t('Proposal Updated'), 'status');
- drupal_goto('manage_proposal/');
+ $preference3_data = $preference3_q->fetchObject();
+ if ($preference3_data)
+ $preference3_id = $preference3_data->id;
+ if ($preference1_data)
+ {
+ del_book_pdf($preference1_data->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'],
+ 'category' => $form_state['values']['book_category_1']
+ ));
+ $query->condition('id', $preference1_id);
+ $num_updated = $query->execute();
+ } //$preference1_data
+ if ($preference2_data)
+ {
+ del_book_pdf($preference2_data->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'],
+ 'category' => $form_state['values']['book_category_2']
+ ));
+ $query->condition('id', $preference2_id);
+ $num_updated = $query->execute();
+ } //$preference2_data
+ if ($preference3_data)
+ {
+ del_book_pdf($preference3_data->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'],
+ 'category' => $form_state['values']['book_category_3']
+ ));
+ $query->condition('id', $preference3_id);
+ $num_updated = $query->execute();
+ } //$preference3_data
+ drupal_set_message(t('Proposal Updated'), 'status');
+ drupal_goto('manage_proposal/');
}
-
/******************************************************************************/
/**************************** CATEGORY EDIT FORM ******************************/
/******************************************************************************/
-
function category_edit_form($form, &$form_state)
{
- /* get current proposal */
- $preference_id = arg(3);
-
+ /* get current proposal */
+ $preference_id = arg(3);
$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');
drupal_goto('manage_proposal/category');
return;
- }
-
- $form['book'] = array(
- '#type' => 'item',
- '#title' => t('Title of the book'),
- '#markup' => $preference_data->book,
- );
- $form['author'] = array(
- '#type' => 'item',
- '#title' => t('Author Name'),
- '#markup' => $preference_data->author,
- );
- $form['isbn'] = array(
- '#type' => 'item',
- '#title' => t('ISBN No'),
- '#markup' => $preference_data->isbn,
- );
- $form['publisher'] = array(
- '#type' => 'item',
- '#title' => t('Publisher & Place'),
- '#markup' => $preference_data->publisher,
- );
- $form['edition'] = array(
- '#type' => 'item',
- '#title' => t('Edition'),
- '#markup' => $preference_data->edition,
- );
- $form['year'] = array(
- '#type' => 'item',
- '#title' => t('Year of pulication'),
- '#markup' => $preference_data->year,
- );
-
- $form['category'] = array(
- '#type' => 'select',
- '#title' => t('Category'),
- '#options' => _tbc_list_of_category(),
- '#required' => TRUE,
- '#default_value' => $preference_data->category,
- );
-
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Submit')
- );
- $form['cancel'] = array(
- '#type' => 'markup',
- '#value' => l(t('Cancel'), 'manage_proposal/category'),
- );
- return $form;
+ } //!$preference_data
+ $form['book'] = array(
+ '#type' => 'item',
+ '#title' => t('Title of the book'),
+ '#markup' => $preference_data->book
+ );
+ $form['author'] = array(
+ '#type' => 'item',
+ '#title' => t('Author Name'),
+ '#markup' => $preference_data->author
+ );
+ $form['isbn'] = array(
+ '#type' => 'item',
+ '#title' => t('ISBN No'),
+ '#markup' => $preference_data->isbn
+ );
+ $form['publisher'] = array(
+ '#type' => 'item',
+ '#title' => t('Publisher & Place'),
+ '#markup' => $preference_data->publisher
+ );
+ $form['edition'] = array(
+ '#type' => 'item',
+ '#title' => t('Edition'),
+ '#markup' => $preference_data->edition
+ );
+ $form['year'] = array(
+ '#type' => 'item',
+ '#title' => t('Year of pulication'),
+ '#markup' => $preference_data->year
+ );
+ $form['category'] = array(
+ '#type' => 'select',
+ '#title' => t('Category'),
+ '#options' => _tbc_list_of_category(),
+ '#required' => TRUE,
+ '#default_value' => $preference_data->category
+ );
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit')
+ );
+ $form['cancel'] = array(
+ '#type' => 'markup',
+ '#value' => l(t('Cancel'), 'manage_proposal/category')
+ );
+ return $form;
}
-
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);*/
-
+ /* 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);*/
$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();
-
+ $preference_data = $preference_q->fetchObject();
if (!$preference_data)
{
drupal_set_message(t('Invalid book selected. Please try again.'), 'error');
drupal_goto('manage_proposal/category');
return;
- }
-
- /*db_query("UPDATE {textbook_companion_preference} SET category = %d WHERE id = %d", $form_state['values']['category'], $preference_data->id);*/
-
+ } //!$preference_data
+ /*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'],
+ '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');
+ drupal_set_message(t('Book Category Updated'), 'status');
+ drupal_goto('manage_proposal/category');
}
-
/****************************************************************/
/* Data entry forms */
/****************************************************************/
-
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");*/
-
+ /* 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");*/
$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 = $preference_q->fetchObject())
- {
- $proposal_rows[] = array($sno++, $preference_data->book, $preference_data->author, $preference_data->isbn, l('Edit', 'dataentry_edit/' . $preference_data->id));
- }
-
- /* check if there are any pending proposals */
- if (!$proposal_rows)
- {
- drupal_set_message(t('There are no proposals.'), 'status');
- return '';
- }
-
- $proposal_header = array('SNO', 'Title of the Book', 'Author', 'ISBN', '');
- $output = theme('table',array('header'=>$proposal_header,'rows'=>$proposal_rows));
- return $output;
+ $sno = 1;
+ 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)
+ );
+ } //$preference_data = $preference_q->fetchObject()
+ /* check if there are any pending proposals */
+ if (!$proposal_rows)
+ {
+ drupal_set_message(t('There are no proposals.'), 'status');
+ return '';
+ } //!$proposal_rows
+ $proposal_header = array(
+ 'SNO',
+ 'Title of the Book',
+ 'Author',
+ 'ISBN',
+ ''
+ );
+ $output = theme('table', array(
+ 'header' => $proposal_header,
+ 'rows' => $proposal_rows
+ ));
+ return $output;
}
-
-function dataentry_edit($id = NULL) {
- if($id) {
+function dataentry_edit($id = NULL)
+{
+ if ($id)
+ {
return drupal_get_form('dataentry_edit_form', $id);
- }else {
+ } //$id
+ else
+ {
return 'Access denied';
}
}
-
-function dataentry_edit_form($form,&$form_state, $id)
+function dataentry_edit_form($form, &$form_state, $id)
{
- global $user;
-
+ global $user;
$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',
- '#required' => TRUE,
- '#value' => $id,
- );
- $form['book'] = array(
- '#type' => 'textfield',
- '#title' => t('Title of the book'),
- '#size' => 30,
- '#maxlength' => 100,
- '#required' => TRUE,
- '#default_value' => $preference_data->book,
- );
- $form['author'] = array(
- '#type' => 'textfield',
- '#title' => t('Author Name'),
- '#size' => 30,
- '#maxlength' => 100,
- '#required' => TRUE,
- '#default_value' => $preference_data->author,
- );
- $form['isbn'] = array(
- '#type' => 'textfield',
- '#title' => t('ISBN No'),
- '#size' => 30,
- '#maxlength' => 25,
- '#required' => TRUE,
- '#attribute' => array('readonly' => 'readonly'),
- '#default_value' => $preference_data->isbn,
- );
- $form['publisher'] = array(
- '#type' => 'textfield',
- '#title' => t('Publisher & Place'),
- '#size' => 30,
- '#maxlength' => 50,
- '#required' => TRUE,
- '#default_value' => $preference_data->publisher,
- );
- $form['edition'] = array(
- '#type' => 'textfield',
- '#title' => t('Edition'),
- '#size' => 4,
- '#maxlength' => 2,
- '#required' => TRUE,
- '#default_value' => $preference_data->edition,
- );
- $form['year'] = array(
- '#type' => 'textfield',
- '#title' => t('Year of pulication'),
- '#size' => 4,
- '#maxlength' => 4,
- '#required' => TRUE,
- '#default_value' => $preference_data->year,
- );
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Submit')
- );
-
- return $form;
+ $preference_data = $preference_q->fetchObject();
+ $form['id'] = array(
+ '#type' => 'hidden',
+ '#required' => TRUE,
+ '#value' => $id
+ );
+ $form['book'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Title of the book'),
+ '#size' => 30,
+ '#maxlength' => 100,
+ '#required' => TRUE,
+ '#default_value' => $preference_data->book
+ );
+ $form['author'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Author Name'),
+ '#size' => 30,
+ '#maxlength' => 100,
+ '#required' => TRUE,
+ '#default_value' => $preference_data->author
+ );
+ $form['isbn'] = array(
+ '#type' => 'textfield',
+ '#title' => t('ISBN No'),
+ '#size' => 30,
+ '#maxlength' => 25,
+ '#required' => TRUE,
+ '#attribute' => array(
+ 'readonly' => 'readonly'
+ ),
+ '#default_value' => $preference_data->isbn
+ );
+ $form['publisher'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Publisher & Place'),
+ '#size' => 30,
+ '#maxlength' => 50,
+ '#required' => TRUE,
+ '#default_value' => $preference_data->publisher
+ );
+ $form['edition'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Edition'),
+ '#size' => 4,
+ '#maxlength' => 2,
+ '#required' => TRUE,
+ '#default_value' => $preference_data->edition
+ );
+ $form['year'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Year of pulication'),
+ '#size' => 4,
+ '#maxlength' => 4,
+ '#required' => TRUE,
+ '#default_value' => $preference_data->year
+ );
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit')
+ );
+ return $form;
}
-
function dataentry_edit_form_submit($form, &$form_state)
{
- $query = db_update('textbook_companion_preference');
+ $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'],
+ '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');
+ drupal_set_message('Book details updated successfully');
+ drupal_goto('dataentry_book');
}
-
-
-function _failed_all($preference_id=0, $confirm="") {
- $page_content = "";
- if($preference_id && $confirm == "yes"){
-
- $query = "
+function _failed_all($preference_id = 0, $confirm = "")
+{
+ $page_content = "";
+ if ($preference_id && $confirm == "yes")
+ {
+ $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 = "
+ $result = db_query($query, array(
+ ':preference_id' => $preference_id
+ ));
+ $row = $result->fetchObject();
+ /* increment failed_reminder */
+ $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 = "
+ 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->full_name},<br><br>
This is to inform you that you have failed to upload the TBC codes on time.<br>
@@ -1669,92 +1827,104 @@ function _failed_all($preference_id=0, $confirm="") {
Scilab Team
</p>
";
-
- $message = $body;
- //drupal_mail($message);
- //drupal_mail('', 'standard', $email_to, language_default(), $params, 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 = "
+ $message = $body;
+ //drupal_mail($message);
+ //drupal_mail('', 'standard', $email_to, language_default(), $params, 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");
+ } //$preference_id && $confirm == "yes"
+ 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}
";
- $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>";
- $page_content .= "Contributor: <b>{$row->full_name}</b><br>";
- $page_content .= "Expected Completion Date: <b>" . date("d-m-Y", $row->completion_date) . "</b><br><br>";
- $page_content .= l("Yes", "manage_proposal/failed/{$preference_id}/yes") . " | ";
- $page_content .= l("Cancel", "manage_proposal/failed");
- } else {
-
-
-$query = "
+ $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>";
+ $page_content .= "Contributor: <b>{$row->full_name}</b><br>";
+ $page_content .= "Expected Completion Date: <b>" . date("d-m-Y", $row->completion_date) . "</b><br><br>";
+ $page_content .= l("Yes", "manage_proposal/failed/{$preference_id}/yes") . " | ";
+ $page_content .= l("Cancel", "manage_proposal/failed");
+ } //$preference_id
+ else
+ {
+ $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 = $result->fetchObject()) {
- $item =array(
- date("d-m-Y", $row->creation_date),
- "{$row->book}<br><i>by</i> {$row->author}",
- $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', array('header' => $headers, 'rows' => $rows ));
-
- }
-
- return $page_content;
+ $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 = $result->fetchObject())
+ {
+ $item = array(
+ date("d-m-Y", $row->creation_date),
+ "{$row->book}<br><i>by</i> {$row->author}",
+ $row->full_name,
+ date("d-m-Y", $row->completion_date),
+ $row->failed_reminder,
+ l("Remind", "manage_proposal/failed/{$row->id}")
+ );
+ array_push($rows, $item);
+ } //$row = $result->fetchObject()
+ $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;
- }
- }
-
+ * 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;
+ } //$system->mail($message)
+ else
+ {
+ return FALSE;
+ }
+}
diff --git a/notes.inc b/notes.inc
index 1d36c33..aa3a2ca 100755
--- a/notes.inc
+++ b/notes.inc
@@ -1,178 +1,165 @@
<?php
// $Id$
-
/******************************************************************************/
/***************************** BOOK NOTES *************************************/
/******************************************************************************/
-
function book_notes_form($form_state)
{
- global $user;
-
- /* 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);*/
+ global $user;
+ /* 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);*/
$query = db_select('textbook_companion_preference');
$query->fields('textbook_companion_preference');
$query->condition('id', $preference_id);
$result = $query->execute();
-
- if ($result)
- {
- if ($row = $result->fetchObject())
- {
- /* everything ok */
- } else {
- drupal_set_message(t('Invalid book selected. Please try again.'), 'error');
- drupal_goto('code_approval/bulk');
- return;
- }
- } else {
- drupal_set_message(t('Invalid book selected. Please try again.'), 'error');
- drupal_goto('code_approval/bulk');
- return;
- }
-
- /* get current notes */
- $notes = '';
-
- /*$notes_q = db_query("SELECT * FROM {textbook_companion_notes} WHERE preference_id = %d LIMIT 1", $preference_id);*/
-
+ if ($result)
+ {
+ if ($row = $result->fetchObject())
+ {
+ /* everything ok */
+ } //$row = $result->fetchObject()
+ else
+ {
+ drupal_set_message(t('Invalid book selected. Please try again.'), 'error');
+ drupal_goto('code_approval/bulk');
+ return;
+ }
+ } //$result
+ else
+ {
+ drupal_set_message(t('Invalid book selected. Please try again.'), 'error');
+ drupal_goto('code_approval/bulk');
+ return;
+ }
+ /* get current notes */
+ $notes = '';
+ /*$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 = $notes_q->fetchObject());
- $notes = $notes_data->notes;
- }
-
- $book_details = _book_information($preference_id);
- $form['book_details'] = array(
- '#type' => 'item',
- '#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 />' .
- '<strong>Year:</strong> ' . $book_details->preference_year . '<br />' .
- '<strong>Edition:</strong> ' . $book_details->preference_edition . '<br /><br />' .
- '<span style="color: rgb(128, 0, 0);"><strong>About the Contributor</strong></span><br />' .
- '<strong>Contributor Name:</strong> ' . $book_details->proposal_full_name . ', ' . $book_details->proposal_course . ', ' . $book_details->proposal_branch . ', ' . $book_details->proposal_university . '<br />',
- );
-
- $form['notes'] = array(
- '#type' => 'textarea',
- '#rows' => 20,
- '#title' => t('Notes for Reviewers'),
- '#default_value' => $notes,
- );
-
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Submit')
- );
-
- $form['cancel'] = array(
- '#type' => 'markup',
- '#value' => l(t('Back'), 'code_approval/bulk'),
- );
- return $form;
+ if ($notes_q)
+ {
+ $notes_data = $notes_q->fetchObject();
+ $notes = $notes_data->notes;
+ } //$notes_q
+ $book_details = _book_information($preference_id);
+ $form['book_details'] = array(
+ '#type' => 'item',
+ '#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 />' . '<strong>Year:</strong> ' . $book_details->preference_year . '<br />' . '<strong>Edition:</strong> ' . $book_details->preference_edition . '<br /><br />' . '<span style="color: rgb(128, 0, 0);"><strong>About the Contributor</strong></span><br />' . '<strong>Contributor Name:</strong> ' . $book_details->proposal_full_name . ', ' . $book_details->proposal_course . ', ' . $book_details->proposal_branch . ', ' . $book_details->proposal_university . '<br />'
+ );
+ $form['notes'] = array(
+ '#type' => 'textarea',
+ '#rows' => 20,
+ '#title' => t('Notes for Reviewers'),
+ '#default_value' => $notes
+ );
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit')
+ );
+ $form['cancel'] = array(
+ '#type' => 'markup',
+ '#value' => l(t('Back'), 'code_approval/bulk')
+ );
+ return $form;
}
-
function book_notes_form_submit($form, &$form_state)
{
- global $user;
-
- /* 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);*/
-
+ global $user;
+ /* 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);*/
$query = db_select('textbook_companion_preference');
$query->fields('textbook_companion_preference');
$query->condition('id', $preference_id);
$result = $query->execute();
-
- if ($result)
- {
- if ($row = $result->fetchObject())
- {
- /* everything ok */
- } else {
- drupal_set_message(t('Invalid book selected. Please try again.'), 'error');
- drupal_goto('code_approval/bulk');
- return;
- }
- } else {
- drupal_set_message(t('Invalid book selected. Please try again.'), 'error');
- drupal_goto('code_approval/bulk');
- return;
- }
-
- /* 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);*/
-
+ if ($result)
+ {
+ if ($row = $result->fetchObject())
+ {
+ /* everything ok */
+ } //$row = $result->fetchObject()
+ else
+ {
+ drupal_set_message(t('Invalid book selected. Please try again.'), 'error');
+ drupal_goto('code_approval/bulk');
+ return;
+ }
+ } //$result
+ else
+ {
+ drupal_set_message(t('Invalid book selected. Please try again.'), 'error');
+ drupal_goto('code_approval/bulk');
+ return;
+ }
+ /* 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);*/
$query = db_select('textbook_companion_notes');
$query->fields('textbook_companion_notes');
- $query->condition('preference_id',$preference_id);
+ $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);*/
-
- $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']);*/
- $query = "INSERT INTO {textbook_companion_notes} (preference_id, notes) VALUES
+ $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);*/
+ $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');
+ } //$notes_data
+ else
+ {
+ /*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');
-
- }
+ $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 */
+/* return proposal and author information */
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));*/
-
+ /*$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));*/
$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->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;
+ $book_data = $result->fetchObject();
+ return $book_data;
}
-
diff --git a/pdf/1/1 FWR/FWR-cache.bak b/pdf/1/1 FWR/FWR-cache.bak
deleted file mode 100755
index 9b33bd3..0000000
--- a/pdf/1/1 FWR/FWR-cache.bak
+++ /dev/null
@@ -1,99 +0,0 @@
-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
deleted file mode 100755
index 1e3b489..0000000
--- a/pdf/1/1 FWR/FWR-cache.lib
+++ /dev/null
@@ -1,125 +0,0 @@
-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
deleted file mode 100755
index 258bcc6..0000000
--- a/pdf/1/1 FWR/FWR.bak
+++ /dev/null
@@ -1,204 +0,0 @@
-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
deleted file mode 100755
index a18fcc7..0000000
--- a/pdf/1/1 FWR/FWR.cir
+++ /dev/null
@@ -1,16 +0,0 @@
-* 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
deleted file mode 100755
index d566c1c..0000000
--- a/pdf/1/1 FWR/FWR.cir.ckt
+++ /dev/null
@@ -1,14 +0,0 @@
-* 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
deleted file mode 100755
index f456fcf..0000000
--- a/pdf/1/1 FWR/FWR.cir.out
+++ /dev/null
@@ -1,21 +0,0 @@
-* 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
deleted file mode 100755
index c2f9628..0000000
--- a/pdf/1/1 FWR/FWR.pro
+++ /dev/null
@@ -1,74 +0,0 @@
-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
deleted file mode 100755
index 68b75c3..0000000
--- a/pdf/1/1 FWR/FWR.proj
+++ /dev/null
@@ -1 +0,0 @@
-schematicFile FWR.sch
diff --git a/pdf/1/1 FWR/FWR.sch b/pdf/1/1 FWR/FWR.sch
deleted file mode 100755
index 54699d0..0000000
--- a/pdf/1/1 FWR/FWR.sch
+++ /dev/null
@@ -1,199 +0,0 @@
-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
deleted file mode 100755
index 3adc58b..0000000
--- a/pdf/1/1 FWR/FWR_last_input.txt
+++ /dev/null
@@ -1 +0,0 @@
-v1 1 0 sine(0 5 50 0 0)
diff --git a/pdf/1/1 FWR/analysis b/pdf/1/1 FWR/analysis
deleted file mode 100755
index 5bf79dd..0000000
--- a/pdf/1/1 FWR/analysis
+++ /dev/null
@@ -1 +0,0 @@
-.tran 1e-03 100e-03 0e-00
diff --git a/pdf/1/1 FWR/eeschema.exe b/pdf/1/1 FWR/eeschema.exe
deleted file mode 100755
index b3b6d28..0000000
--- a/pdf/1/1 FWR/eeschema.exe
+++ /dev/null
Binary files differ
diff --git a/pdf/1/1 FWR/libfftw3-3.dll b/pdf/1/1 FWR/libfftw3-3.dll
deleted file mode 100755
index a8f033a..0000000
--- a/pdf/1/1 FWR/libfftw3-3.dll
+++ /dev/null
Binary files differ
diff --git a/pdf/1/1 FWR/ngspice.exe b/pdf/1/1 FWR/ngspice.exe
deleted file mode 100755
index e584114..0000000
--- a/pdf/1/1 FWR/ngspice.exe
+++ /dev/null
Binary files differ
diff --git a/pdf/1/1 FWR/plot_data_i.txt b/pdf/1/1 FWR/plot_data_i.txt
deleted file mode 100755
index e9e5f02..0000000
--- a/pdf/1/1 FWR/plot_data_i.txt
+++ /dev/null
@@ -1,116 +0,0 @@
-* 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
deleted file mode 100755
index a1dee49..0000000
--- a/pdf/1/1 FWR/plot_data_v.txt
+++ /dev/null
@@ -1,116 +0,0 @@
-* 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
deleted file mode 100755
index c72f16d..0000000
--- a/pdf/1/1 FWR/python.exe
+++ /dev/null
Binary files differ
diff --git a/pdf/1/1 FWR/vcomp100.dll b/pdf/1/1 FWR/vcomp100.dll
deleted file mode 100755
index e23321c..0000000
--- a/pdf/1/1 FWR/vcomp100.dll
+++ /dev/null
Binary files differ
diff --git a/pdf/1/1.pdf b/pdf/1/1.pdf
deleted file mode 100755
index 79df36a..0000000
--- a/pdf/1/1.pdf
+++ /dev/null
Binary files differ
diff --git a/pdf/generate_pdf.inc b/pdf/generate_pdf.inc
index cec2bcf..97eee5b 100755
--- a/pdf/generate_pdf.inc
+++ b/pdf/generate_pdf.inc
@@ -1,140 +1,223 @@
<?php
-
- function generate_pdf()
- { $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= :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){
- if($data3->gender == 'M'){
- $gender = array('salutation' => 'Mr.', 'gender' => 'He');
-
- }else{
- $gender = array('salutation' => 'Ms.', 'gender' => 'She');
- }
- }
- //die;
- /*if($data3->proposal_status == 3)
- {*/
- $pdf=new FPDF('L', 'mm', 'Letter');
- if (!$pdf)
- {
- echo "Error!";
- }
- $pdf->AddPage();
-
- $pdf->SetMargins(18,1,18);
-
- $pdf->Line(7.0,7.0,270.0,7.0);
- $pdf->Line(7.0,7.0,7.0,210.0);
- $pdf->Line(270.0,210.0,270.0,7.0);
- $pdf->Line(7.0,210.0,270.0,210.0);
-
- $pdf->Image("/Sites/scilab_in_2015/sites/default/files/scilab_logo.png", 10, 9, 0, 15);
- $path = drupal_get_path('module', 'textbook_companion');
- $pdf->Image($path."/pdf/images/fossee.png", 228, 9, 0, 15);
-
- $pdf->SetFont('Arial','B',25);
- $pdf->Ln(30);
- $pdf->Cell(240,8,'Certificate', 0,1,'C');
- $pdf->Ln(5);
- $pdf->SetFont('Arial','B',12);
- $pdf->Cell(240,8,'Textbook Companion', '0','1','C');
-
- $pdf->Ln(20);
- //$pdf->Cell(240,8,'IIT Bombay', '0','1','C');
-
- $pdf->SetFont('Arial','',12);
- if(strtolower($data3->branch)!="others")
+function generate_pdf()
+{
+ $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= :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)
+ {
+ if ($data3->gender == 'M')
{
- $pdf->MultiCell(240,8,'This is to certify that '.$gender['salutation']." ".$data3->full_name.' from the Department of '.$data3->branch.', '.$data3->university.' has successfully completed Internship under Scilab Textbook Companion for a duration equivalent to six weeks. '.$gender['gender'].' has coded, in Scilab, all the solved examples of the allotted textbook: '.$data2->book.' by '.$data2->author.'.', 0);
- }
+ $gender = array(
+ 'salutation' => 'Mr.',
+ 'gender' => 'He'
+ );
+ } //$data3->gender == 'M'
else
{
- $pdf->MultiCell(240,8,'This is to certify that '.$gender['salutation']." ".$data3->full_name.' from '.$data3->university.' has successfully completed training under Scilab Textbook Companion for a duration equivalent to six weeks. '.$gender['gender'].' has coded, in Scilab, all the solved examples of the allotted textbook: '.$data2->book.' by '.$data2->author.'.', 0);
- } $pdf->Cell(10,10,'The work done is available at ', '0','0','L');
-
- $pdf->SetX(75);
- $pdf->SetFont('','U');
- $pdf->SetTextColor(0,0,255);
- $pdf->write(10,'http://scilab.in','http://scilab.in');
- $pdf->SetFont('','');
- $pdf->SetTextColor(0,0,0);
- $pdf->write(10,'.','.');
-
- $pdf->Ln(10);
-
- $pdf->SetFont('Arial','',12);
- $pdf->SetTextColor(0,0,0);
- $pdf->Cell(10,10,'This work was funded by the FOSSEE project, IIT Bombay (for more details visit', '0','0','L');
-
- $pdf->SetX(170);
- $pdf->SetFont('','U');
- $pdf->SetTextColor(0,0,255);
- $pdf->write(10,'http://fossee.in','http://fossee.in');
-
- $pdf->SetX(198);
- $pdf->SetFont('','');
- $pdf->SetTextColor(0,0,0);
- $pdf->write(10,').');
-
- $pdf->SetY(-50);
-
- $pdf->SetX(209);
- $pdf->SetTextColor(0,0,0);
- $pdf->SetFont('','B');
- $pdf->Image($path."/pdf/images/sign.png", 212, 151, 0, 15);
- //$pdf->SetX(206);
- $pdf->Cell(0,7,'Prof. Madhu Belur', 0,1,'L');
- $pdf->SetX(195);
- $pdf->Cell(0,7,'Principal Investigator - FOSSEE',0,1,'L');
- $pdf->SetX(195);
- $pdf->Cell(0,7,' Dept. of Electrical Engineering', 0,1,'L');
-
- $pdf->SetX(216);
- $pdf->Cell(0,7,'IIT Bombay', 0,1,'L');
-
- $cur_date=date('jS F, Y');
- $pdf->SetY(180);
- $pdf->SetFont('','');
- $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');
- $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;
- /*}
+ $gender = array(
+ 'salutation' => 'Ms.',
+ 'gender' => 'She'
+ );
+ }
+ } //$data3->gender
+ $pdf = new FPDF('L', 'mm', 'Letter');
+ if (!$pdf)
+ {
+ echo "Error!";
+ } //!$pdf
+ $pdf->AddPage();
+ $pdf->SetMargins(18, 1, 18);
+ $pdf->Line(7.0, 7.0, 270.0, 7.0);
+ $pdf->Line(7.0, 7.0, 7.0, 210.0);
+ $pdf->Line(270.0, 210.0, 270.0, 7.0);
+ $pdf->Line(7.0, 210.0, 270.0, 210.0);
+ $pdf->Image("/Sites/scilab_in_2015/sites/default/files/scilab_logo.png", 10, 9, 0, 15);
+ $path = drupal_get_path('module', 'textbook_companion');
+ $pdf->Image($path . "/pdf/images/fossee.png", 228, 9, 0, 15);
+ $pdf->SetFont('Arial', 'B', 25);
+ $pdf->Ln(30);
+ $pdf->Cell(240, 8, 'Certificate', 0, 1, 'C');
+ $pdf->Ln(5);
+ $pdf->SetFont('Arial', 'B', 12);
+ $pdf->Cell(240, 8, 'Textbook Companion', '0', '1', 'C');
+ $pdf->Ln(20);
+ //$pdf->Cell(240,8,'IIT Bombay', '0','1','C');
+ $pdf->SetFont('Arial', '', 12);
+ if (strtolower($data3->branch) != "others")
+ {
+ $pdf->MultiCell(240, 8, 'This is to certify that ' . $gender['salutation'] . " " . $data3->full_name . ' from the Department of ' . $data3->branch . ', ' . $data3->university . ' has successfully completed Internship under Scilab Textbook Companion for a duration equivalent to six weeks. ' . $gender['gender'] . ' has coded, in Scilab, all the solved examples of the allotted textbook: ' . $data2->book . ' by ' . $data2->author . '.', 0);
+ } //strtolower($data3->branch) != "others"
+ else
+ {
+ $pdf->MultiCell(240, 8, 'This is to certify that ' . $gender['salutation'] . " " . $data3->full_name . ' from ' . $data3->university . ' has successfully completed training under Scilab Textbook Companion for a duration equivalent to six weeks. ' . $gender['gender'] . ' has coded, in Scilab, all the solved examples of the allotted textbook: ' . $data2->book . ' by ' . $data2->author . '.', 0);
+ }
+ $pdf->Cell(10, 10, 'The work done is available at ', '0', '0', 'L');
+ $pdf->SetX(75);
+ $pdf->SetFont('', 'U');
+ $pdf->SetTextColor(0, 0, 255);
+ $pdf->write(10, 'http://scilab.in', 'http://scilab.in');
+ $pdf->SetFont('', '');
+ $pdf->SetTextColor(0, 0, 0);
+ $pdf->write(10, '.', '.');
+ $pdf->Ln(10);
+ $pdf->SetFont('Arial', '', 12);
+ $pdf->SetTextColor(0, 0, 0);
+ $pdf->Cell(10, 10, 'This work was funded by the FOSSEE project, IIT Bombay (for more details visit', '0', '0', 'L');
+ $pdf->SetX(170);
+ $pdf->SetFont('', 'U');
+ $pdf->SetTextColor(0, 0, 255);
+ $pdf->write(10, 'http://fossee.in', 'http://fossee.in');
+ $pdf->SetX(198);
+ $pdf->SetFont('', '');
+ $pdf->SetTextColor(0, 0, 0);
+ $pdf->write(10, ').');
+ $pdf->SetY(-50);
+ $pdf->SetX(209);
+ $pdf->SetTextColor(0, 0, 0);
+ $pdf->SetFont('', 'B');
+ $pdf->Image($path . "/pdf/images/sign.png", 212, 151, 0, 15);
+ //$pdf->SetX(206);
+ $pdf->Cell(0, 7, 'Prof. Madhu Belur', 0, 1, 'L');
+ $pdf->SetX(195);
+ $pdf->Cell(0, 7, 'Principal Investigator - FOSSEE', 0, 1, 'L');
+ $pdf->SetX(195);
+ $pdf->Cell(0, 7, ' Dept. of Electrical Engineering', 0, 1, 'L');
+ $pdf->SetX(216);
+ $pdf->Cell(0, 7, 'IIT Bombay', 0, 1, 'L');
+ $cur_date = date('jS F, Y');
+ $pdf->SetY(180);
+ $pdf->SetFont('', '');
+ $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');
+ $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
+ } //!feof($fp)
+ fclose($fp);
+ unlink($file);
+ drupal_goto('certificate');
+ return;
+}
+function generate_form_pdf()
+{
+ $mpath = drupal_get_path('module', 'textbook_companion');
+ require($mpath . '/pdf/fpdf/fpdf.php');
+ global $user;
+ $x = $user->uid;
+ $proposal_id = arg(3);
+ $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)
+ {
+ if ($data3->gender == 'M')
+ {
+ $gender = array(
+ 'salutation' => 'Mr.',
+ 'gender' => 'He'
+ );
+ } //$data3->gender == 'M'
else
{
- drupal_set_message('Your Book Is Still Under Review.', 'status');
- }*/
-}
-?>
-
+ $gender = array(
+ 'salutation' => 'Ms.',
+ 'gender' => 'She'
+ );
+ }
+ } //$data3->gender
+ $pdf = new FPDF('P', 'mm', 'Letter');
+ if (!$pdf)
+ {
+ echo "Error!";
+ } //!$pdf
+ $pdf->AddPage();
+ $path = drupal_get_path('module', 'textbook_companion');
+ $pdf->SetFont('Arial', 'B', 25);
+ $pdf->Ln(30);
+ $pdf->Cell(200, 8, 'Copyright Transfer Form', 0, 1, 'C');
+ $pdf->Ln(20);
+ $pdf->SetFont('Arial', '', 12);
+ $pdf->MultiCell(200, 8, 'I hereby transfer the copyrights of the Scilab Textbook Companion for ' . $data2->book . ' ( Author: ' . $data2->author . ', Edition: ' . $data2->edition . ', Publisher: ' . $data2->publisher . ', Year: ' . $data2->year . ') to FOSSEE Project, IIT Bombay.', 0);
+ $pdf->Ln(10);
+ $pdf->MultiCell(200, 8, 'I understand that the FOSSEE project will release the Textbook Companion under the Creative Commons (CC) license.');
+ $pdf->SetX(75);
+ $pdf->SetFont('', 'U');
+ $pdf->SetTextColor(0, 0, 255);
+ $pdf->SetFont('', '');
+ $pdf->SetTextColor(0, 0, 0);
+ $pdf->SetFont('', '');
+ $pdf->SetTextColor(0, 0, 0);
+ $pdf->SetY(-10);
+ $pdf->SetX(209);
+ $cur_date = date('jS F, Y');
+ $pdf->SetY(140);
+ $pdf->SetFont('', '');
+ $pdf->Ln(0);
+ $pdf->Cell(200, 0, ' Date: ' . $cur_date . '', 0, 1, 'L');
+ $pdf->Cell(200, 20, ' Place: _________________', 0, 1, 'L');
+ $pdf->SetY(140);
+ $pdf->SetX(120);
+ $pdf->Cell(180, 0, 'Signature: _________________', 0, 1, 'L');
+ $pdf->SetY(144);
+ $pdf->SetX(120);
+ $pdf->multicell(140, 14, 'Name: ' . $gender['salutation'] . ' ' . $data3->full_name . '', 0, '');
+ $filename = str_replace(' ', '-', $data3->full_name) . '-Scilab-Textbook-Companion-copyright-form.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
+ } //!feof($fp)
+ fclose($fp);
+ unlink($file);
+ drupal_goto('Summer_Internship_Forms/copyright-form');
+ return;
+}
diff --git a/pdf/list_all_certificates.inc b/pdf/list_all_certificates.inc
index e094d5f..a3dc24a 100755
--- a/pdf/list_all_certificates.inc
+++ b/pdf/list_all_certificates.inc
@@ -1,97 +1,62 @@
<?php
-/* function _list_all_certificates()
+function _list_all_certificates()
+{
+ global $user;
+ $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)
{
- 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)
- /*while($data2 = db_fetch_object($query2))
- {*/
- /* if($data2->id)
+ if ($exist_id->id < 3)
+ {
+ drupal_set_message('<strong>You need to propose a book <a href="http://www.scilab.in/book_proposal">Book Proposal</a></strong> or if you have already proposed then your book is under reviewing process', 'status');
+ return '';
+ } //$exist_id->id < 3
+ else
{
- $search_rows = array();
- global $output;
+ $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($query3);
- if($data3)
+ $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())
{
- 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 '';
- }
- }
-//}
-} */
-
-function _list_all_certificates()
- {
- global $user;
- $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)
+ if ($search_data3->id)
+ {
+ $search_rows[] = array(
+ $search_data3->isbn,
+ $search_data3->book,
+ $search_data3->author,
+ l('Download Certificate', 'certificate/generate_pdf/' . $search_data3->id)
+ );
+ } //$search_data3->id
+ } //$search_data3 = $query3->fetchObject()
+ if ($search_rows)
{
- drupal_set_message('<strong>You need to propose a book <a href="/proposal">Book Proposal</a></strong>', 'status');
- return '';
- }
+ $search_header = array(
+ 'ISBN',
+ 'Book Name',
+ 'Author',
+ 'Download Certificates'
+ );
+ $output = theme('table', array(
+ 'header' => $search_header,
+ 'rows' => $search_rows
+ ));
+ return $output;
+ } //$search_rows
else
{
- $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= :uid",array(':uid' => $user->uid));
- while ($search_data3 = $query3->fetchObject())
- {
- if($search_data3->id)
- {
- $search_rows[] = array($search_data3->isbn,$search_data3->book,$search_data3->author,l('Download Certificate', 'certificate/generate_pdf/'.$search_data3->id));
+ echo ("Error");
+ return '';
}
}
- if($search_rows)
- {
- $search_header = array('ISBN', 'Book Name', 'Author', 'Download Certificates');
- $output = theme('table',array('header'=>$search_header, 'rows'=>$search_rows));
- return $output;
- }
- else
- {
- echo("Error");
- return '';
- }
- }
- }
+ } //$exist_id->id
else
{
- drupal_set_message('<strong>You need to propose a book <a href="/proposal">Book Proposal</a></strong>', 'status');
- return '';
+ drupal_set_message('<strong>You need to propose a book <a href="http://www.scilab.in/book_proposal">Book Proposal</a></strong> or if you have already proposed then your book is under reviewing process', 'status');
+ return '';
}
-}
-?>
+}
diff --git a/pdf/list_all_form_pdf.inc b/pdf/list_all_form_pdf.inc
new file mode 100644
index 0000000..1cb07f8
--- /dev/null
+++ b/pdf/list_all_form_pdf.inc
@@ -0,0 +1,65 @@
+<?php
+//Used to generate forms dynamiclay
+function _list_all_copyright_forms()
+{
+ global $user;
+ $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)
+ {
+ drupal_set_message('<strong>You need to propose a book <a href="http://www.scilab.in/book_proposal">Book Proposal</a></strong> or if you have already proposed then your book is under reviewing process', 'status');
+ return '';
+ } //$exist_id->id < 3
+ else
+ {
+ $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= :uid", array(
+ ':uid' => $user->uid
+ ));
+ while ($search_data3 = $query3->fetchObject())
+ {
+ if ($search_data3->id)
+ {
+ $search_rows[] = array(
+ $search_data3->isbn,
+ $search_data3->book,
+ $search_data3->author,
+ l('Download Copyright Form', 'Summer_Internship_Forms/copyright-form/generate_pdf/' . $search_data3->id)
+ );
+ } //$search_data3->id
+ } //$search_data3 = $query3->fetchObject()
+ if ($search_rows)
+ {
+ $search_header = array(
+ 'ISBN',
+ 'Book Name',
+ 'Author',
+ 'Download Copyright Form'
+ );
+ $output = theme('table', array(
+ 'header' => $search_header,
+ 'rows' => $search_rows
+ ));
+ return $output;
+ } //$search_rows
+ else
+ {
+ echo ("Error");
+ return '';
+ }
+ }
+ } //$exist_id->id
+ else
+ {
+ drupal_set_message('<strong>You need to propose a book <a href="http://www.scilab.in/book_proposal">Book Proposal</a></strong> or if you have already proposed then your book is under reviewing process', 'status');
+ return '';
+ }
+}
+
+
diff --git a/proposal.inc b/proposal.inc
new file mode 100644
index 0000000..e04eba3
--- /dev/null
+++ b/proposal.inc
@@ -0,0 +1,1970 @@
+<?php
+/* Aicte books pickup before the proposal form */
+function textbook_companion_aicte_proposal_form($form, &$form_state)
+{
+ /*********** fetch aicte book data ********************/
+ $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(
+ "#type" => "fieldset",
+ "#prefix" => "<div id='aicte-form-wrapper'>",
+ "#suffix" => "</div>"
+ );
+ $num_rows = $result->rowCount();
+ if ($num_rows > 0)
+ {
+ while ($row = $result->fetchObject())
+ {
+ /* fixing title string */
+ $title = "";
+ $edition = "";
+ $year = "";
+ $title = "{$row->book} by {$row->author}";
+ if ($row->edition)
+ {
+ $edition = "<i>ed</i>: {$row->edition}";
+ } //$row->edition
+ if ($row->year)
+ {
+ if ($row->edition)
+ {
+ $year = ", <i>pub</i>: {$row->year}";
+ } //$row->edition
+ else
+ {
+ $year = "<i>pub</i>: {$row->year}";
+ }
+ } //$row->year
+ if ($edition or $year)
+ {
+ $title .= "({$edition} {$year})";
+ } //$edition or $year
+ $form["wrapper"][$row->id] = array(
+ "#type" => "checkbox",
+ "#title" => $title,
+ "#prefix" => "<div class='title'>",
+ "#suffix" => "</div>"
+ );
+ } //$row = $result->fetchObject()
+ } //$num_rows > 0
+ $form["submit"] = array(
+ "#type" => "submit",
+ "#value" => "Submit Book Selections"
+ );
+ return $form;
+}
+function textbook_companion_aicte_proposal_form_validate($form, &$form_state)
+{
+ $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 = $result->fetchObject())
+ {
+ if ($form_state["values"][$row->id] == 1)
+ {
+ $count++;
+ array_push($selections, $row->id);
+ } //$form_state["values"][$row->id] == 1
+ } //$row = $result->fetchObject()
+ /* user can choose only 3 books to propose */
+ if ($count != variable_get('textbook_companion_book_preferences', ''))
+ {
+ form_set_error("", "Please select only <strong>1</strong> book. You currently selected <strong>{$count}</strong>");
+ } //$count > 3
+ elseif ($count == 0)
+ {
+
+ form_set_error("", "Please select only <strong>1</strong> book. You currently selected <strong>{$count}</strong>");
+
+ } //$count == 0
+ else
+ {
+ $form_state["values"]["selections"] = $selections;
+ }
+}
+/* AICTE Book list proposal form submit */
+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");
+}
+/************* AICTE book report form **************/
+function textbook_companion_aicte_report_form($from, &$form_state)
+{
+ $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 = $result->fetchObject())
+ {
+ $books[$row->id] = "{$row->book} ({$row->author})";
+ } //$row = $result->fetchObject()
+ $form = array();
+ $form["name"] = array(
+ "#type" => "textfield",
+ "#title" => "Name",
+ "#description" => t("Please enter your name.")
+ );
+ $form["email"] = array(
+ "#type" => "textfield",
+ "#title" => "Email",
+ "#description" => t("Please enter your valid email id.")
+ );
+ $form["number"] = array(
+ "#type" => "textfield",
+ "#title" => "Number",
+ "#description" => t("Please enter your valid phone number.")
+ );
+ $form["book"] = array(
+ "#type" => "select",
+ "#title" => "AICTE Book",
+ "#description" => t("Please select a book."),
+ "#options" => $books
+ );
+ $form["comment"] = array(
+ "#type" => "textarea",
+ "#title" => "Any other comment?",
+ "#description" => t("Please enter your query (if any)")
+ );
+ $form["submit"] = array(
+ "#type" => "submit",
+ "#value" => "Submit"
+ );
+ return $form;
+}
+/************* AICTE book report form submit **************/
+function textbook_companion_aicte_report_form_submit($form, &$form_state)
+{
+ $v = $form_state["values"];
+ $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");
+}
+/************* AICTE book list selection **************/
+function textbook_companion_aicte_proposal_all()
+{
+ global $user;
+ $page_content = "";
+ if (!$user->uid)
+ {
+ $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>";
+ $page_content .= "<li>Please <a href='/user'><b><u>Login</u></b></a> to create a proposal.</li>";
+ //$page_content .= "<li>Unable to propose particular book: <a id='aicte-report' href='#'>Click here</a></li>";
+ //$page_content .= "<li>Do not wish to propose any of the below books: <a id='aicte-report' href='http://fossee.in/feedback/scilab-aicte' target = _blank>Click here</a></li>";
+ $page_content .= "</ul>";
+ $page_content .= "Search : <input type='text' id='searchtext' onkeyup='searchbookFunction()' style='width:82%'/>";
+ $page_content .= "<input type='button' value ='clear' id='search_clear'/>";
+ $page_content .= "<div id='aicte-list-wrapper'>";
+ $num_rows = $result->rowCount();
+ if ($num_rows > 0)
+ {
+ $i = 1;
+ while ($row = $result->fetchObject())
+ {
+ /* fixing title string */
+ $title = "";
+ $edition = "";
+ $year = "";
+ $title = "{$row->book} by {$row->author}";
+ if ($row->edition)
+ {
+ $edition = "<i>ed</i>: {$row->edition}";
+ } //$row->edition
+ if ($row->year)
+ {
+ if ($row->edition)
+ {
+ $year = ", <i>pub</i>: {$row->year}";
+ } //$row->edition
+ else
+ {
+ $year = "<i>pub</i>: {$row->year}";
+ }
+ } //$row->year
+ if ($edition or $year)
+ {
+ $title .= "({$edition} {$year})";
+ } //$edition or $year
+ $page_content .= "<div class='title'>{$i}) {$title}</div>";
+ $i++;
+ } //$row = $result->fetchObject()
+ } //$num_rows > 0
+ $page_content .= "</div>";
+ /* adding aicte report form */
+ //$page_content .= drupal_get_form("textbook_companion_aicte_report_form");
+ return $page_content;
+ } //!$user->uid
+ /* check if user has already submitted a proposal */
+ $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 = $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');
+ drupal_goto('');
+ return;
+ break;
+ case 1:
+ drupal_set_message(t('Your proposal has been approved. Please go to ' . l('Code Submission', 'textbook_companion/code') . ' to upload your code'), 'status');
+ drupal_goto('');
+ return;
+ break;
+ case 2:
+ drupal_set_message(t('Your proposal has been dis-approved. Please create another proposal below.'), 'error');
+ break;
+ case 3:
+ drupal_set_message(t('Congratulations! You have completed your last book proposal. You can create another proposal below.'), 'status');
+ break;
+ default:
+ drupal_set_message(t('Invalid proposal state. Please contact site administrator for further information.'), 'error');
+ drupal_goto('');
+ return;
+ break;
+ } //$proposal_data->proposal_status
+ } //$proposal_data = $proposal_q->fetchObject()
+ } //$proposal_q
+ variable_del("aicte_" . $user->uid);
+ $page_content .= "<h5><b>* Below is the list of AICTE recommended textbooks which you may propose. Select any one to continue:</b></h5></br>";
+ //$page_content .= "Unable to propose particular book: <a id='aicte-report' href='#'>Click here</a></br></br>";
+ //$page_content .= "Do not wish to propose any of the below books: <a id='aicte-report' href='http://fossee.in/feedback/scilab-aicte' target = _blank>Click here</a></br></br>";
+ $page_content .= "Search : <input type='text' id='searchtext' style='width:90%'/>";
+ $page_content .= "<br><br><center><input type='button' value ='clear' id='search_clear'/></center>";
+ $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 *******************/
+function textbook_companion_nonaicte_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;
+ } //!$user->uid
+ /* 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);*/
+ $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 = $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');
+ drupal_goto('');
+ return;
+ break;
+ case 1:
+ drupal_set_message(t('Your proposal has been approved. Please go to ' . l('Code Submission', 'textbook_companion/code') . ' to upload your code'), 'status');
+ drupal_goto('');
+ return;
+ break;
+ case 2:
+ drupal_set_message(t('Your proposal has been dis-approved. Please create another proposal below.'), 'error');
+ break;
+ case 3:
+ drupal_set_message(t('Congratulations! You have completed your last book proposal. You can create another proposal below.'), 'status');
+ break;
+ default:
+ drupal_set_message(t('Invalid proposal state. Please contact site administrator for further information.'), 'error');
+ drupal_goto('');
+ return;
+ break;
+ } //$proposal_data->proposal_status
+ } //$proposal_data = $proposal_q->fetchObject()
+ } //$proposal_q
+ //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;
+}
+/* Textbook Companion Proposal */
+function textbook_companion_proposal_all()
+{
+ global $user;
+ $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 **************/
+ $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 = $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');
+ drupal_goto('');
+ return;
+ break;
+ case 1:
+ drupal_set_message(t('Your proposal has been approved. Please go to ' . l('Code Submission', 'textbook_companion/code') . ' to upload your code'), 'status');
+ drupal_goto('');
+ return;
+ break;
+ case 2:
+ drupal_set_message(t('Your proposal has been dis-approved. Please create another proposal below.'), 'error');
+ break;
+ case 3:
+ drupal_set_message(t('Congratulations! You have completed your last book proposal. You can create another proposal below.'), 'status');
+ break;
+ default:
+ drupal_set_message(t('Invalid proposal state. Please contact site administrator for further information.'), 'error');
+ drupal_goto('');
+ return;
+ break;
+ } //$proposal_data->proposal_status
+ } //$proposal_data = $proposal_q->fetchObject()
+ } //$proposal_q
+ $selections = variable_get("aicte_" . $user->uid, "");
+ if ($selections)
+ {
+ $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);
+ } //$selections
+ else
+ {
+ // $book_proposal_form = drupal_get_form("book_proposal_form");
+ // $page_content .= drupal_render($book_proposal_form);
+ drupal_goto("aicte_proposal");
+ }
+ return $page_content;
+}
+/* AICTE book proposal form */
+function book_proposal_form($form, &$form_state, $row1 = NULL, $row2 = NULL, $row3 = NULL)
+{
+ global $user;
+ $form = array();
+ $form['imp_notice'] = array(
+ '#type' => 'item',
+ '#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(
+ '#type' => 'textfield',
+ '#title' => t('Full Name'),
+ '#size' => 30,
+ '#maxlength' => 50,
+ '#required' => TRUE
+ );
+ $form['email_id'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Email'),
+ '#size' => 30,
+ '#value' => $user->mail,
+ '#disabled' => TRUE
+ );
+ $form['mobile'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Mobile No.'),
+ '#size' => 30,
+ '#maxlength' => 15,
+ '#required' => TRUE
+ );
+ $form['gender'] = array(
+ '#type' => 'radios',
+ '#title' => t('Gender'),
+ '#options' => array(
+ 'M' => 'Male',
+ 'F' => 'Female'
+ ),
+ '#required' => TRUE
+ );
+ /*$form['how_project'] = array(
+ '#type' => 'select',
+ '#title' => t('How did you come to know about this project'),
+ '#options' => array('Scilab Website' => 'Scilab Website',
+ 'Friend' => 'Friend',
+ 'Professor/Teacher' => 'Professor/Teacher',
+ 'Mailing List' => 'Mailing List',
+ 'Poster in my/other college' => 'Poster in my/other college',
+ 'Others' => 'Others'),
+ '#required' => TRUE,
+ );*/
+ $form['course'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Course'),
+ '#size' => 30,
+ '#maxlength' => 50,
+ '#required' => TRUE
+ );
+ $form['branch'] = array(
+ '#type' => 'select',
+ '#title' => t('Department/Branch'),
+ '#options' => _tbc_list_of_departments(),
+ '#required' => TRUE
+ );
+ $form['university'] = array(
+ '#type' => 'textfield',
+ '#title' => t('University/Institute'),
+ '#size' => 30,
+ '#maxlength' => 50,
+ '#required' => TRUE
+ );
+ $form['country'] = array(
+ '#type' => 'select',
+ '#title' => t('Country'),
+ '#options' => array(
+ 'India' => 'India',
+ 'Others' => 'Others'
+ ),
+ '#required' => TRUE,
+ '#tree' => TRUE,
+ '#validated' => TRUE
+ );
+ $form['other_country'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Other than India'),
+ '#size' => 100,
+ '#attributes' => array(
+ 'placeholder' => t('Enter your country name')
+ ),
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="country"]' => array(
+ 'value' => 'Others'
+ )
+ )
+ )
+ );
+ $form['other_state'] = array(
+ '#type' => 'textfield',
+ '#title' => t('State other than India'),
+ '#size' => 100,
+ '#attributes' => array(
+ 'placeholder' => t('Enter your state/region name')
+ ),
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="country"]' => array(
+ 'value' => 'Others'
+ )
+ )
+ )
+ );
+ $form['other_city'] = array(
+ '#type' => 'textfield',
+ '#title' => t('City other than India'),
+ '#size' => 100,
+ '#attributes' => array(
+ 'placeholder' => t('Enter your city name')
+ ),
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="country"]' => array(
+ 'value' => 'Others'
+ )
+ )
+ )
+ );
+ $form['all_state'] = array(
+ '#type' => 'select',
+ '#title' => t('State'),
+ '#options' => _tbc_list_of_states(),
+ '#validated' => TRUE,
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="country"]' => array(
+ 'value' => 'India'
+ )
+ )
+ )
+ );
+ $form['city'] = array(
+ '#type' => 'select',
+ '#title' => t('City'),
+ '#options' => _tbc_list_of_cities(),
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="country"]' => array(
+ 'value' => 'India'
+ )
+ )
+ )
+ );
+ $form['pincode'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Pincode'),
+ '#size' => 30,
+ '#maxlength' => 6,
+ '#required' => False,
+ '#attributes' => array(
+ 'placeholder' => 'Enter pincode....'
+ )
+ );
+ $form['faculty'] = array(
+ '#type' => 'hidden',
+ '#value' => 'None',
+ '#title' => t('College Teacher/Professor'),
+ '#size' => 30,
+ '#maxlength' => 50,
+ '#required' => TRUE
+ );
+ $form['faculty_email'] = array(
+ '#type' => 'hidden',
+ '#value' => 'None',
+ '#title' => t('Teacher/Professor Email Id'),
+ '#default_value' => '@email.com',
+ '#size' => 30,
+ '#maxlength' => 50
+ );
+ $form['reviewer'] = array(
+ '#type' => 'hidden',
+ '#value' => 'None',
+ '#title' => t('Reviewer'),
+ '#size' => 30,
+ '#maxlength' => 50
+ );
+ $form['completion_date'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Expected Date of Completion'),
+ '#description' => t('Input date format should be DD-MM-YYYY. Eg: 23-03-2011'),
+ '#size' => 10,
+ '#maxlength' => 10
+ );
+ $form['operating_system'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Operating System'),
+ '#required' => TRUE,
+ '#size' => 30,
+ '#maxlength' => 50
+ );
+ $form['version'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Scilab Version'),
+ '#description' => t('Input version format should be like 5.4 or 5.4.1'),
+ '#size' => 10,
+ '#required' => TRUE,
+ '#maxlength' => 20
+ );
+ $form['preference1'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Book Preference 1'),
+ '#collapsible' => TRUE,
+ '#collapsed' => FALSE
+ );
+ $form['preference1']['book1'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Title of the book'),
+ '#size' => 30,
+ '#maxlength' => 100,
+ '#required' => TRUE,
+ '#default_value' => $row1->book,
+ '#disabled' => ($row1->book ? TRUE : FALSE)
+ );
+ $form['preference1']['author1'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Author Name'),
+ '#size' => 30,
+ '#maxlength' => 100,
+ '#required' => TRUE,
+ '#default_value' => $row1->author,
+ '#disabled' => ($row1->author ? TRUE : FALSE)
+ );
+ $form['preference1']['isbn1'] = array(
+ '#type' => 'textfield',
+ '#title' => t('ISBN No'),
+ '#size' => 30,
+ '#maxlength' => 25,
+ '#required' => TRUE,
+ '#default_value' => $row1->isbn,
+ '#disabled' => ($row1->isbn ? TRUE : FALSE)
+ );
+ $form['preference1']['publisher1'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Publisher & Place'),
+ '#size' => 30,
+ '#maxlength' => 50,
+ '#required' => TRUE,
+ '#default_value' => $row1->publisher
+ );
+ $form['preference1']['edition1'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Edition'),
+ '#size' => 4,
+ '#maxlength' => 2,
+ '#required' => TRUE,
+ '#default_value' => $row1->edition
+ );
+ $form['preference1']['year1'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Year of pulication'),
+ '#size' => 4,
+ '#maxlength' => 4,
+ '#required' => TRUE,
+ '#default_value' => $row1->year
+ );
+ $form['preference1']['book_category_1'] = array(
+ '#type' => 'select',
+ '#title' => t('Category'),
+ '#options' => _tbc_list_of_category(),
+ '#required' => TRUE
+ );
+ if ($row2 != NULL)
+ {
+ $form['preference2'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Book Preference 2'),
+ '#collapsible' => TRUE,
+ '#collapsed' => FALSE
+ );
+ $form['preference2']['book2'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Title of the book'),
+ '#size' => 30,
+ '#maxlength' => 100,
+ '#required' => TRUE,
+ '#default_value' => $row2->book,
+ '#disabled' => ($row2->book ? TRUE : FALSE)
+ );
+ $form['preference2']['author2'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Author Name'),
+ '#size' => 30,
+ '#maxlength' => 100,
+ '#required' => TRUE,
+ '#default_value' => $row2->author,
+ '#disabled' => ($row2->author ? TRUE : FALSE)
+ );
+ $form['preference2']['isbn2'] = array(
+ '#type' => 'textfield',
+ '#title' => t('ISBN No'),
+ '#size' => 30,
+ '#maxlength' => 25,
+ '#required' => TRUE,
+ '#default_value' => $row2->isbn,
+ '#disabled' => ($row2->isbn ? TRUE : FALSE)
+ );
+ $form['preference2']['publisher2'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Publisher & Place'),
+ '#size' => 30,
+ '#maxlength' => 50,
+ '#required' => TRUE,
+ '#default_value' => $row2->publisher
+ );
+ $form['preference2']['edition2'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Edition'),
+ '#size' => 4,
+ '#maxlength' => 2,
+ '#required' => TRUE,
+ '#default_value' => $row2->edition
+ );
+ $form['preference2']['year2'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Year of pulication'),
+ '#size' => 4,
+ '#maxlength' => 4,
+ '#required' => TRUE,
+ '#default_value' => $row2->year
+ );
+ $form['preference2']['book_category_2'] = array(
+ '#type' => 'select',
+ '#title' => t('Category'),
+ '#options' => _tbc_list_of_category(),
+ '#required' => TRUE
+ );
+ } //$row2 != NULL
+ if ($row3 != NULL)
+ {
+ $form['preference3'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Book Preference 3'),
+ '#collapsible' => TRUE,
+ '#collapsed' => FALSE
+ );
+ $form['preference3']['book3'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Title of the book'),
+ '#size' => 30,
+ '#maxlength' => 100,
+ '#required' => TRUE,
+ '#default_value' => $row3->book,
+ '#disabled' => ($row3->book ? TRUE : FALSE)
+ );
+ $form['preference3']['author3'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Author Name'),
+ '#size' => 30,
+ '#maxlength' => 100,
+ '#required' => TRUE,
+ '#default_value' => $row3->author,
+ '#disabled' => ($row3->author ? TRUE : FALSE)
+ );
+ $form['preference3']['isbn3'] = array(
+ '#type' => 'textfield',
+ '#title' => t('ISBN No'),
+ '#size' => 30,
+ '#maxlength' => 25,
+ '#required' => TRUE,
+ '#default_value' => $row3->isbn,
+ '#disabled' => ($row3->isbn ? TRUE : FALSE)
+ );
+ $form['preference3']['publisher3'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Publisher & Place'),
+ '#size' => 30,
+ '#maxlength' => 50,
+ '#required' => TRUE,
+ '#default_value' => $row3->publisher
+ );
+ $form['preference3']['edition3'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Edition'),
+ '#size' => 4,
+ '#maxlength' => 2,
+ '#required' => TRUE,
+ '#default_value' => $row3->edition
+ );
+ $form['preference3']['year3'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Year of pulication'),
+ '#size' => 4,
+ '#maxlength' => 4,
+ '#required' => TRUE,
+ '#default_value' => $row3->year
+ );
+ $form['preference3']['book_category_3'] = array(
+ '#type' => 'select',
+ '#title' => t('Category'),
+ '#options' => _tbc_list_of_category(),
+ '#required' => TRUE
+ );
+ } //$row3 != NULL
+ $form['samplefile'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('<span class="form-required form-item" title="This field is required.">Sample Source Files *</span>'),
+ '#collapsible' => FALSE,
+ '#collapsed' => FALSE
+ );
+ $form['samplefile']['samplefile1'] = array(
+ '#type' => 'file',
+ '#title' => t('Upload sample source file'),
+ '#size' => 48,
+ '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' . t('<span style="color:red;">Allowed file extensions : ') . variable_get('textbook_companion_sample_source_file_extensions', '') . '</span>'
+ );
+ $form['termconditions'] = array(
+ '#type' => 'checkboxes',
+ '#title' => t('Terms And Conditions'),
+ '#options' => array(
+ 'status' => t('<a href="/term-and-conditions" target="_blank">I agree to the Terms and Conditions</a>')
+ ),
+ '#required' => TRUE
+ );
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit')
+ );
+ return $form;
+}
+/******************** AICTE book proposal from validate *****************************/
+function book_proposal_form_validate($form, &$form_state)
+{
+ /* mobile */
+ if (!preg_match('/^[0-9\ \+]{0,15}$/', $form_state['values']['mobile']))
+ form_set_error('mobile', t('Invalid mobile number'));
+ /* date of completion */
+ if (!preg_match('/^[0-9]{1,2}-[0-9]{1,2}-[0-9]{4}$/', $form_state['values']['completion_date']))
+ form_set_error('completion_date', t('Invalid expected date of completion'));
+ list($d, $m, $y) = explode('-', $form_state['values']['completion_date']);
+ $d = (int) $d;
+ $m = (int) $m;
+ $y = (int) $y;
+ if (!checkdate($m, $d, $y))
+ form_set_error('completion_date', t('Invalid expected date of completion'));
+ if (mktime(0, 0, 0, $m, $d, $y) <= time())
+ form_set_error('completion_date', t('Expected date of completion should be in future'));
+ /* edition */
+ if (!preg_match('/^[1-9][0-9]{0,1}$/', $form_state['values']['edition1']))
+ form_set_error('edition1', t('Invalid edition for Book Preference 1'));
+ if ($form_state['values']['book2'])
+ {
+ if (!preg_match('/^[1-9][0-9]{0,1}$/', $form_state['values']['edition2']))
+ {
+ form_set_error('edition2', t('Invalid edition for Book Preference 2'));
+ } //!preg_match('/^[1-9][0-9]{0,1}$/', $form_state['values']['edition2'])
+ } //$form_state['values']['book2']
+ if ($form_state['values']['book3'])
+ {
+ if (!preg_match('/^[1-9][0-9]{0,1}$/', $form_state['values']['edition3']))
+ {
+ form_set_error('edition3', t('Invalid edition for Book Preference 3'));
+ } //!preg_match('/^[1-9][0-9]{0,1}$/', $form_state['values']['edition3'])
+ } //$form_state['values']['book3']
+ /* year of publication */
+ if (!preg_match('/^[1-3][0-9][0-9][0-9]$/', $form_state['values']['year1']))
+ form_set_error('year1', t('Invalid year of pulication for Book Preference 1'));
+ if ($form_state['values']['book2'])
+ {
+ if (!preg_match('/^[1-3][0-9][0-9][0-9]$/', $form_state['values']['year2']))
+ {
+ form_set_error('year2', t('Invalid year of pulication for Book Preference 2'));
+ } //!preg_match('/^[1-3][0-9][0-9][0-9]$/', $form_state['values']['year2'])
+ } //$form_state['values']['book2']
+ if ($form_state['values']['book3'])
+ {
+ if (!preg_match('/^[1-3][0-9][0-9][0-9]$/', $form_state['values']['year3']))
+ {
+ form_set_error('year3', t('Invalid year of pulication for Book Preference 3'));
+ } //!preg_match('/^[1-3][0-9][0-9][0-9]$/', $form_state['values']['year3'])
+ } //$form_state['values']['book3']
+ /* year of publication */
+ $cur_year = date('Y');
+ if ((int) $form_state['values']['year1'] > $cur_year)
+ form_set_error('year1', t('Year of pulication should be not in the future for Book Preference 1'));
+ if ($form_state['values']['book2'])
+ {
+ if ((int) $form_state['values']['year2'] > $cur_year)
+ {
+ form_set_error('year2', t('Year of pulication should be not in the future for Book Preference 2'));
+ } //(int) $form_state['values']['year2'] > $cur_year
+ } //$form_state['values']['book2']
+ if ($form_state['values']['book3'])
+ {
+ if ((int) $form_state['values']['year3'] > $cur_year)
+ {
+ form_set_error('year3', t('Year of pulication should be not in the future for Book Preference 3'));
+ } //(int) $form_state['values']['year3'] > $cur_year
+ } //$form_state['values']['book3']
+ /* isbn */
+ if (!preg_match('/^[0-9\-xX]+$/', $form_state['values']['isbn1']))
+ form_set_error('isbn1', t('Invalid ISBN for Book Preference 1'));
+ if ($form_state['values']['book2'])
+ {
+ if (!preg_match('/^[0-9\-xX]+$/', $form_state['values']['isbn2']))
+ {
+ form_set_error('isbn2', t('Invalid ISBN for Book Preference 2'));
+ } //!preg_match('/^[0-9\-xX]+$/', $form_state['values']['isbn2'])
+ } //$form_state['values']['book2']
+ if ($form_state['values']['book3'])
+ {
+ if (!preg_match('/^[0-9\-xX]+$/', $form_state['values']['isbn3']))
+ {
+ form_set_error('isbn3', t('Invalid ISBN for Book Preference 3'));
+ } //!preg_match('/^[0-9\-xX]+$/', $form_state['values']['isbn3'])
+ } //$form_state['values']['book3']
+ /* version */
+ if (!preg_match('/^\d+(?:\.\d+)+/', $form_state['values']['version']))
+ form_set_error('version', t('Please enter correct version in given format'));
+ /* country */
+ if ($form_state['values']['country'] == 'Others')
+ {
+ if ($form_state['values']['other_country'] == '')
+ {
+ form_set_error('other_country', t('Enter country name'));
+ } //$form_state['values']['other_country'] == ''
+ else
+ {
+ $form_state['values']['country'] = $form_state['values']['other_country'];
+ }
+ if ($form_state['values']['other_state'] == '')
+ {
+ form_set_error('other_state', t('Enter state name'));
+ } //$form_state['values']['other_state'] == ''
+ else
+ {
+ $form_state['values']['all_state'] = $form_state['values']['other_state'];
+ }
+ if ($form_state['values']['other_city'] == '')
+ {
+ form_set_error('other_city', t('Enter city name'));
+ } //$form_state['values']['other_city'] == ''
+ else
+ {
+ $form_state['values']['city'] = $form_state['values']['other_city'];
+ }
+ } //$form_state['values']['country'] == 'Others'
+ else
+ {
+ if ($form_state['values']['country'] == '')
+ {
+ form_set_error('country', t('Select country name'));
+ } //$form_state['values']['country'] == ''
+ if ($form_state['values']['all_state'] == '')
+ {
+ form_set_error('all_state', t('Select state name'));
+ } //$form_state['values']['all_state'] == ''
+ if ($form_state['values']['city'] == '')
+ {
+ form_set_error('city', t('Select city name'));
+ } //$form_state['values']['city'] == ''
+ }
+ if (isset($_FILES['files']))
+ {
+ /* check if atleast one source or result file is uploaded */
+ if (!($_FILES['files']['name']['samplefile1']))
+ form_set_error('samplefile1', t('Please upload sample code main or source file.'));
+ /* check for valid filename extensions */
+ foreach ($_FILES['files']['name'] as $file_form_name => $file_name)
+ {
+ if ($file_name)
+ {
+ /* checking file type */
+ if (strstr($file_form_name, 'sample'))
+ $file_type = 'S';
+ else
+ $file_type = 'U';
+ $allowed_extensions_str = '';
+ switch ($file_type)
+ {
+ case 'S':
+ $allowed_extensions_str = variable_get('textbook_companion_sample_source_file_extensions', '');
+ break;
+ } //$file_type
+ $allowed_extensions = explode(',', $allowed_extensions_str);
+ $allowd_file = strtolower($_FILES['files']['name'][$file_form_name]);
+ $allowd_files = explode('.', $allowd_file);
+ $temp_extension = end($allowd_files);
+ if (!in_array($temp_extension, $allowed_extensions))
+ form_set_error($file_form_name, t('Only file with ' . $allowed_extensions_str . ' extensions can be uploaded.'));
+ if ($_FILES['files']['size'][$file_form_name] <= 0)
+ form_set_error($file_form_name, t('File size cannot be zero.'));
+ /* check if valid file name */
+ if (!textbook_companion_check_valid_filename($_FILES['files']['name'][$file_form_name]))
+ form_set_error($file_form_name, t('Invalid file name specified. Only alphabets and numbers are allowed as a valid filename.'));
+ } //$file_name
+ } //$_FILES['files']['name'] as $file_form_name => $file_name
+ } //isset($_FILES['files'])
+ return;
+}
+function book_proposal_form_submit($form, &$form_state)
+{
+ global $user;
+ $selections = variable_get("aicte_" . $user->uid, "");
+ $root_path = textbook_companion_samplecode_path();
+ if (!$user->uid)
+ {
+ drupal_set_message('It is mandatory to login on this website to access the proposal form', 'error');
+ return;
+ } //!$user->uid
+ /* completion date to timestamp */
+ list($d, $m, $y) = explode('-', $form_state['values']['completion_date']);
+ $completion_date_timestamp = mktime(0, 0, 0, $m, $d, $y);
+ $scilab_version = 'scilab ' . $form_state['values']['version'];
+ $query = "INSERT INTO {textbook_companion_proposal}
+ (uid, approver_uid, full_name, mobile, gender, how_project, course, branch, university, country, city, pincode, state, faculty, reviewer, completion_date, creation_date, approval_date, proposal_status, scilab_version, operating_system, teacher_email, message, samplefilepath,proposed_completion_date) VALUES (:uid, :approver_uid, :full_name, :mobile, :gender, :how_project, :course, :branch, :university, :country, :city, :pincode, :state, :faculty, :reviewer, :completion_date,
+ :creation_date, :approval_date, :proposal_status, :scilab_version, :operating_system,
+:teacher_email, :message, :samplefilepath,:proposed_completion_date)";
+ $args = array(
+ ":uid" => $user->uid,
+ ":approver_uid" => 0,
+ ":full_name" => _tbc_sentence_case($form_state['values']['full_name']),
+ ":mobile" => $form_state['values']['mobile'],
+ ":gender" => $form_state['values']['gender'],
+ ":how_project" => 'Not available',
+ ":course" => _tbc_sentence_case($form_state['values']['course']),
+ ":branch" => $form_state['values']['branch'],
+ ":university" => _tbc_sentence_case($form_state['values']['university']),
+ ":country" => $form_state['values']['country'],
+ ":city" => $form_state['values']['city'],
+ ":pincode" => $form_state['values']['pincode'],
+ ":state" => $form_state['values']['all_state'],
+ ":faculty" => _tbc_sentence_case($form_state['values']['faculty']),
+ ":reviewer" => _tbc_sentence_case($form_state['values']['reviewer']),
+ ":completion_date" => $completion_date_timestamp,
+ ":creation_date" => time(),
+ ":approval_date" => 0,
+ ":proposal_status" => 0,
+ ":scilab_version" => $scilab_version,
+ ":operating_system" => _tbc_sentence_case($form_state['values']['operating_system']),
+ ":teacher_email" => $form_state['values']['faculty_email'],
+ ":message" => 'None',
+ ":samplefilepath" => "",
+ ":proposed_completion_date" => $completion_date_timestamp
+ );
+ $result = db_query($query, $args, array(
+ 'return' => Database::RETURN_INSERT_ID
+ ));
+ $dest_path = $result . '/';
+ if (!is_dir($root_path . $dest_path))
+ mkdir($root_path . $dest_path);
+ /* uploading files */
+ foreach ($_FILES['files']['name'] as $file_form_name => $file_name)
+ {
+ if ($file_name)
+ {
+ /* checking file type */
+ $file_type = 'S';
+ if (file_exists($root_path . $dest_path . $_FILES['files']['name'][$file_form_name]))
+ {
+ drupal_set_message(t("Error uploading file. File !filename already exists.", array(
+ '!filename' => $_FILES['files']['name'][$file_form_name]
+ )), 'error');
+ return;
+ } //file_exists($root_path . $dest_path . $_FILES['files']['name'][$file_form_name])
+ /* uploading file */
+ if (move_uploaded_file($_FILES['files']['tmp_name'][$file_form_name], $root_path . $dest_path . $_FILES['files']['name'][$file_form_name]))
+ {
+ $query = "UPDATE {textbook_companion_proposal} SET samplefilepath = :samplefilepath WHERE id = :id";
+ $args = array(
+ ":samplefilepath" => $dest_path . $_FILES['files']['name'][$file_form_name],
+ ":id" => $result
+ );
+ $updateresult = db_query($query, $args);
+ drupal_set_message($file_name . ' uploaded successfully.', 'status');
+ } //move_uploaded_file($_FILES['files']['tmp_name'][$file_form_name], $root_path . $dest_path . $_FILES['files']['name'][$file_form_name])
+ else
+ {
+ drupal_set_message('Error uploading file : ' . $dest_path . '/' . $file_name, 'error');
+ }
+ } //$file_name
+ } //$_FILES['files']['name'] as $file_form_name => $file_name
+ if (!$result)
+ {
+ drupal_set_message(t('Error receiving your proposal. Please try again.'), 'error');
+ return;
+ } //!$result
+ /* proposal id */
+ // $proposal_id = db_last_insert_id('textbook_companion_proposal', 'id');
+ $proposal_id = $result;
+ /* inserting first book preference */
+ if ($form_state['values']['book1'])
+ {
+ $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" => _tbc_sentence_case($form_state['values']['book1']),
+ ":author" => _tbc_sentence_case($form_state['values']['author1']),
+ ":isbn" => $form_state['values']['isbn1'],
+ ":publisher" => _tbc_sentence_case($form_state['values']['publisher1']),
+ ":edition" => $form_state['values']['edition1'],
+ ":year" => $form_state['values']['year1'],
+ ":category" => $form_state['values']['book_category_1'],
+ ":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');
+ } //!$result
+ else
+ {
+ //$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);*/
+ $query = db_update('textbook_companion_aicte');
+ $query->fields(array(
+ 'preference_id' => $preference_id
+ ));
+ $query->condition('id', $selections[0]);
+ $num_updated = $query->execute();
+ }
+ } //$form_state['values']['book1']
+ /* inserting second book preference */
+ if ($form_state['values']['book2'])
+ {
+ /*$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,
+ 2,
+ ucwords(strtolower($form_state['values']['book2'])),
+ ucwords(strtolower($form_state['values']['author2'])),
+ $form_state['values']['isbn2'],
+ ucwords(strtolower($form_state['values']['publisher2'])),
+ $form_state['values']['edition2'],
+ $form_state['values']['year2'],
+ 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" => _tbc_sentence_case($form_state['values']['book2']),
+ ":author" => _tbc_sentence_case($form_state['values']['author2']),
+ ":isbn" => $form_state['values']['isbn2'],
+ ":publisher" => _tbc_sentence_case($form_state['values']['publisher2']),
+ ":edition" => $form_state['values']['edition2'],
+ ":year" => $form_state['values']['year2'],
+ ":category" => $form_state['values']['book_category_2'],
+ ":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');
+ } //!$result
+ else
+ {
+ //$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);*/
+ $query = db_update('textbook_companion_aicte');
+ $query->fields(array(
+ 'preference_id' => $preference_id
+ ));
+ $query->condition('id', $selections[1]);
+ $num_updated = $query->execute();
+ }
+ } //$form_state['values']['book2']
+ /* inserting third book preference */
+ if ($form_state['values']['book3'])
+ {
+ $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" => _tbc_sentence_case($form_state['values']['book3']),
+ ":author" => _tbc_sentence_case($form_state['values']['author3']),
+ ":isbn" => $form_state['values']['isbn3'],
+ ":publisher" => _tbc_sentence_case($form_state['values']['publisher3']),
+ ":edition" => $form_state['values']['edition3'],
+ ":year" => $form_state['values']['year3'],
+ ":category" => $form_state['values']['book_category_3'],
+ ":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');
+ } //!$result
+ else
+ {
+ $preference_id = $result;
+ /*$query = "
+ UPDATE textbook_companion_aicte
+ SET preference_id = {$preference_id}
+ WHERE id = {$selections[2]}
+ ";
+ 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 = "
+ UPDATE textbook_companion_aicte
+ SET status = 1, uid = {$user->uid}, proposal_id = {$proposal_id}
+ WHERE id = {$selection} AND status = 0
+ ";
+ 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();
+ } //$selections as $selection
+ if (!$result)
+ {
+ drupal_set_message(t('Error receiving your third book preference.'), 'error');
+ } //!$result
+ } //$form_state['values']['book3']
+ /* sending email */
+ $email_to = $user->mail;
+ $from = variable_get('textbook_companion_from_email', '');
+ $bcc = variable_get('textbook_companion_emails', '');
+ $cc = variable_get('textbook_companion_cc_emails', '');
+ $params['proposal_received']['proposal_id'] = $proposal_id;
+ $params['proposal_received']['user_id'] = $user->uid;
+ $params['proposal_received']['headers'] = array(
+ 'From' => $from,
+ 'MIME-Version' => '1.0',
+ 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
+ 'Content-Transfer-Encoding' => '8Bit',
+ 'X-Mailer' => 'Drupal',
+ 'Cc' => $cc,
+ 'Bcc' => $bcc
+ );
+ if (!drupal_mail('textbook_companion', 'proposal_received', $email_to, language_default(), $params, $from, TRUE))
+ drupal_set_message('Error sending email message.', 'error');
+ drupal_set_message(t('We have received you book proposal. We will get back to you soon.'), 'status');
+ drupal_goto('');
+}
+/* AJAX CALLS */
+function textbook_companion_ajax()
+{
+ $query_type = arg(2);
+ if ($query_type == 'chapter_title')
+ {
+ $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);*/
+ $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;
+ } //$chapter_data = $chapter_q->fetchObject()
+ } //$query_type == 'chapter_title'
+ else if ($query_type == 'example_exists')
+ {
+ $chapter_number = arg(3);
+ $preference_id = arg(4);
+ $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);*/
+ $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;
+ } //!$chapter_data = $chapter_q->fetchObject()
+ else
+ {
+ $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);*/
+ $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.';
+ else
+ echo 'Warning! Example already uploaded. Delete the example and reupload it.';
+ return;
+ } //$example_data = $example_q->fetchObject()
+ } //$query_type == 'example_exists'
+ echo '';
+}
+/* Non aicte book proposal form */
+function book_proposal_nonaicte_form($form, &$form_state)
+{
+ global $user;
+ $form = array();
+ $form['imp_notice'] = array(
+ '#type' => 'item',
+ '#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',
+ '#title' => t('Guidelines'),
+ '#attributes' => array(
+ 'style' => 'font-weight: bold'
+ ),
+ '#collapsible' => TRUE,
+ '#collapsed' => FALSE
+ );
+ $form['guidelines']['book'] = array(
+ '#type' => 'item',
+ '#required' => TRUE,
+ '#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>
+ <li>If the book has less than 80 examples the <a href="tbc_honorarium" target="_blank">honorarium</a> will be provided on a pro-rata basis </li>
+ <li>Make sure the book you propose is not already an <a href="aicte_proposal" target="_blank">AICTE recommended book</a>, <a href="Completed_Books" target="_blank">completed book</a>
+ or a <a href="Books_Progress" target="_blank">book in progress</a> </li>
+ <li>You will be intimated about the approval or rejection of your suggestion via e-mail</li>
+
+</ul> '
+ );
+ $form['full_name'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Full Name'),
+ '#size' => 30,
+ '#maxlength' => 50,
+ '#required' => TRUE
+ );
+ $form['email_id'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Email'),
+ '#size' => 30,
+ '#value' => $user->mail,
+ '#disabled' => TRUE
+ );
+ $form['mobile'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Mobile No.'),
+ '#size' => 30,
+ '#maxlength' => 15,
+ '#required' => TRUE
+ );
+ $form['gender'] = array(
+ '#type' => 'radios',
+ '#title' => t('Gender'),
+ '#options' => array(
+ 'M' => 'Male',
+ 'F' => 'Female'
+ ),
+ '#required' => TRUE
+ );
+ /*$form['how_project'] = array(
+ '#type' => 'select',
+ '#title' => t('How did you come to know about this project'),
+ '#options' => array('Scilab Website' => 'Scilab Website',
+ 'Friend' => 'Friend',
+ 'Professor/Teacher' => 'Professor/Teacher',
+ 'Mailing List' => 'Mailing List',
+ 'Poster in my/other college' => 'Poster in my/other college',
+ 'Others' => 'Others'),
+ '#required' => TRUE,
+ );*/
+ $form['course'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Course'),
+ '#size' => 30,
+ '#maxlength' => 50,
+ '#required' => TRUE
+ );
+ $form['branch'] = array(
+ '#type' => 'select',
+ '#title' => t('Department/Branch'),
+ '#options' => _tbc_list_of_departments(),
+ '#required' => TRUE
+ );
+ $form['university'] = array(
+ '#type' => 'textfield',
+ '#title' => t('University/Institute'),
+ '#size' => 30,
+ '#maxlength' => 50,
+ '#required' => TRUE
+ );
+ $form['country'] = array(
+ '#type' => 'select',
+ '#title' => t('Country'),
+ '#options' => array(
+ 'India' => 'India',
+ 'Others' => 'Others'
+ ),
+ '#required' => TRUE,
+ '#tree' => TRUE,
+ '#validated' => TRUE
+ );
+ $form['other_country'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Other than India'),
+ '#size' => 100,
+ '#attributes' => array(
+ 'placeholder' => t('Enter your country name')
+ ),
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="country"]' => array(
+ 'value' => 'Others'
+ )
+ )
+ )
+ );
+ $form['other_state'] = array(
+ '#type' => 'textfield',
+ '#title' => t('State other than India'),
+ '#size' => 100,
+ '#attributes' => array(
+ 'placeholder' => t('Enter your state/region name')
+ ),
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="country"]' => array(
+ 'value' => 'Others'
+ )
+ )
+ )
+ );
+ $form['other_city'] = array(
+ '#type' => 'textfield',
+ '#title' => t('City other than India'),
+ '#size' => 100,
+ '#attributes' => array(
+ 'placeholder' => t('Enter your city name')
+ ),
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="country"]' => array(
+ 'value' => 'Others'
+ )
+ )
+ )
+ );
+ $form['all_state'] = array(
+ '#type' => 'select',
+ '#title' => t('State'),
+ '#options' => _tbc_list_of_states(),
+ '#validated' => TRUE,
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="country"]' => array(
+ 'value' => 'India'
+ )
+ )
+ )
+ );
+ $form['city'] = array(
+ '#type' => 'select',
+ '#title' => t('City'),
+ '#options' => _tbc_list_of_cities(),
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="country"]' => array(
+ 'value' => 'India'
+ )
+ )
+ )
+ );
+ $form['pincode'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Pincode'),
+ '#size' => 30,
+ '#maxlength' => 6,
+ '#required' => False,
+ '#attributes' => array(
+ 'placeholder' => 'Enter pincode....'
+ )
+ );
+ $form['faculty'] = array(
+ '#type' => 'hidden',
+ '#value' => 'None',
+ '#title' => t('College Teacher/Professor'),
+ '#size' => 30,
+ '#maxlength' => 50,
+ '#required' => TRUE
+ );
+ $form['faculty_email'] = array(
+ '#type' => 'hidden',
+ '#value' => 'None',
+ '#title' => t('Teacher/Professor Email Id'),
+ '#default_value' => '@email.com',
+ '#size' => 30,
+ '#maxlength' => 50
+ );
+ $form['reviewer'] = array(
+ '#type' => 'hidden',
+ '#value' => 'None',
+ '#title' => t('Reviewer'),
+ '#size' => 30,
+ '#maxlength' => 50
+ );
+ $form['version'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Scilab Version'),
+ '#description' => t('Input version format should be like 5.4 or 5.4.1'),
+ '#size' => 10,
+ '#required' => TRUE,
+ '#maxlength' => 20
+ );
+ $form['completion_date'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Expected Date of Completion'),
+ '#description' => t('Input date format should be DD-MM-YYYY. Eg: 23-03-2011'),
+ '#size' => 10,
+ '#maxlength' => 10,
+ '#required' => TRUE
+ );
+ $form['operating_system'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Operating System'),
+ '#required' => TRUE,
+ '#size' => 30,
+ '#maxlength' => 50
+ );
+ $reason = array(
+ 'Used in more than one University' => t('Used in more than one University'),
+ 'The book has multiple editions' => t('The book has multiple editions'),
+ 'Extremely useful' => t('Extremely useful'),
+ 'Other reason' => t('Any other reason state below')
+ );
+ $form['reason'] = array(
+ '#type' => 'checkboxes',
+ '#title' => t('Reasons'),
+ '#options' => $reason,
+ '#required' => TRUE
+ );
+ $form['other_reason'] = array(
+ '#type' => 'textarea',
+ '#size' => 300,
+ '#maxlength' => 300,
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="reason[Other reason]"]' => array(
+ 'checked' => TRUE
+ )
+ )
+ )
+ //'#required' => FALSE,
+ );
+ $form['proposal_type'] = array(
+ '#type' => 'hidden',
+ '#default_value' => '1',
+ '#required' => FALSE
+ );
+ $form['reference'] = array(
+ '#type' => 'textarea',
+ '#title' => t('Reference'),
+ '#required' => TRUE,
+ '#size' => 1000,
+ '#attributes' => array(
+ 'placeholder' => 'Links of the syllabus must be provided....'
+ )
+ );
+ $form['preference1'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Book Preference'),
+ '#collapsible' => TRUE,
+ '#collapsed' => FALSE
+ );
+ $form['preference1']['book1'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Title of the book'),
+ '#size' => 30,
+ '#maxlength' => 100,
+ '#required' => TRUE,
+ '#default_value' => $row1->book,
+ '#disabled' => ($row1->book ? TRUE : FALSE)
+ );
+ $form['preference1']['author1'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Author Name'),
+ '#size' => 30,
+ '#maxlength' => 100,
+ '#required' => TRUE,
+ '#default_value' => $row1->author,
+ '#disabled' => ($row1->author ? TRUE : FALSE)
+ );
+ $form['preference1']['isbn1'] = array(
+ '#type' => 'textfield',
+ '#title' => t('ISBN No'),
+ '#size' => 30,
+ '#maxlength' => 25,
+ '#required' => TRUE,
+ '#default_value' => $row1->isbn,
+ '#disabled' => ($row1->isbn ? TRUE : FALSE)
+ );
+ $form['preference1']['publisher1'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Publisher & Place'),
+ '#size' => 30,
+ '#maxlength' => 50,
+ '#required' => TRUE,
+ '#default_value' => $row1->publisher
+ );
+ $form['preference1']['edition1'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Edition'),
+ '#size' => 4,
+ '#maxlength' => 2,
+ '#required' => TRUE,
+ '#default_value' => $row1->edition
+ );
+ $form['preference1']['year1'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Year of pulication'),
+ '#size' => 4,
+ '#maxlength' => 4,
+ '#required' => TRUE,
+ '#default_value' => $row1->year
+ );
+ $form['preference1']['book_category_1'] = array(
+ '#type' => 'select',
+ '#title' => t('Category'),
+ '#options' => _tbc_list_of_category(),
+ '#required' => TRUE
+ );
+ $form['samplefile'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('<span class="form-required form-item" title="This field is required.">Sample Source Files *</span>'),
+ '#collapsible' => FALSE,
+ '#collapsed' => FALSE
+ );
+ $form['samplefile']['samplefile1'] = array(
+ '#type' => 'file',
+ '#title' => t('Upload sample source file'),
+ '#size' => 48,
+ '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' . t('<span style="color:red;">Allowed file extensions : ') . variable_get('textbook_companion_sample_source_file_extensions', '') . '</span>'
+ );
+ $form['termconditions'] = array(
+ '#type' => 'checkboxes',
+ '#title' => t('Terms And Conditions'),
+ '#options' => array(
+ 'status' => t('<a href="term-and-conditions" target="_blank">I agree to the Terms and Conditions</a>')
+ ),
+ '#required' => TRUE
+ );
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit')
+ );
+ return $form;
+}
+function book_proposal_nonaicte_form_validate($form, &$form_state)
+{
+ /* mobile */
+ if (!preg_match('/^[0-9\ \+]{0,15}$/', $form_state['values']['mobile']))
+ form_set_error('mobile', t('Invalid mobile number'));
+ /* date of completion */
+ if (!preg_match('/^[0-9]{1,2}-[0-9]{1,2}-[0-9]{4}$/', $form_state['values']['completion_date']))
+ form_set_error('completion_date', t('Invalid expected date of completion'));
+ list($d, $m, $y) = explode('-', $form_state['values']['completion_date']);
+ $d = (int) $d;
+ $m = (int) $m;
+ $y = (int) $y;
+ if (!checkdate($m, $d, $y))
+ form_set_error('completion_date', t('Invalid expected date of completion'));
+ if (mktime(0, 0, 0, $m, $d, $y) <= time())
+ form_set_error('completion_date', t('Expected date of completion should be in future'));
+ /* edition */
+ if (!preg_match('/^[1-9][0-9]{0,1}$/', $form_state['values']['edition1']))
+ form_set_error('edition1', t('Invalid edition for Book Preference 1'));
+ /* year of publication */
+ if (!preg_match('/^[1-3][0-9][0-9][0-9]$/', $form_state['values']['year1']))
+ form_set_error('year1', t('Invalid year of pulication for Book Preference 1'));
+ /* year of publication */
+ $cur_year = date('Y');
+ if ((int) $form_state['values']['year1'] > $cur_year)
+ form_set_error('year1', t('Year of pulication should be not in the future for Book Preference 1'));
+ /* isbn */
+ if (!preg_match('/^[0-9\-xX]+$/', $form_state['values']['isbn1']))
+ form_set_error('isbn1', t('Invalid ISBN for Book Preference 1'));
+ if (!preg_match('/^\d+(?:\.\d+)+/', $form_state['values']['version']))
+ form_set_error('version', t('Please enter correct version in speacifed format'));
+ if ($form_state['values']['country'] == 'Others')
+ {
+ if ($form_state['values']['other_country'] == '')
+ {
+ form_set_error('other_country', t('Enter country name'));
+ // $form_state['values']['country'] = $form_state['values']['other_country'];
+ } //$form_state['values']['other_country'] == ''
+ else
+ {
+ $form_state['values']['country'] = $form_state['values']['other_country'];
+ }
+ if ($form_state['values']['other_state'] == '')
+ {
+ form_set_error('other_state', t('Enter state name'));
+ // $form_state['values']['country'] = $form_state['values']['other_country'];
+ } //$form_state['values']['other_state'] == ''
+ else
+ {
+ $form_state['values']['all_state'] = $form_state['values']['other_state'];
+ }
+ if ($form_state['values']['other_city'] == '')
+ {
+ form_set_error('other_city', t('Enter city name'));
+ // $form_state['values']['country'] = $form_state['values']['other_country'];
+ } //$form_state['values']['other_city'] == ''
+ else
+ {
+ $form_state['values']['city'] = $form_state['values']['other_city'];
+ }
+ } //$form_state['values']['country'] == 'Others'
+ else
+ {
+ if ($form_state['values']['country'] == '')
+ {
+ form_set_error('country', t('Select country name'));
+ // $form_state['values']['country'] = $form_state['values']['other_country'];
+ } //$form_state['values']['country'] == ''
+ if ($form_state['values']['all_state'] == '')
+ {
+ form_set_error('all_state', t('Select state name'));
+ // $form_state['values']['country'] = $form_state['values']['other_country'];
+ } //$form_state['values']['all_state'] == ''
+ if ($form_state['values']['city'] == '')
+ {
+ form_set_error('city', t('Select city name'));
+ // $form_state['values']['country'] = $form_state['values']['other_country'];
+ } //$form_state['values']['city'] == ''
+ }
+ if (isset($_FILES['files']))
+ {
+ /* check if atleast one source or result file is uploaded */
+ if (!($_FILES['files']['name']['samplefile1']))
+ form_set_error('samplefile1', t('Please upload sample code main or source file.'));
+ /* check for valid filename extensions */
+ foreach ($_FILES['files']['name'] as $file_form_name => $file_name)
+ {
+ if ($file_name)
+ {
+ /* checking file type */
+ if (strstr($file_form_name, 'sample'))
+ $file_type = 'S';
+ else
+ $file_type = 'U';
+ $allowed_extensions_str = '';
+ switch ($file_type)
+ {
+ case 'S':
+ $allowed_extensions_str = variable_get('textbook_companion_sample_source_file_extensions', '');
+ break;
+ } //$file_type
+ $allowed_extensions = explode(',', $allowed_extensions_str);
+ $allowd_file = strtolower($_FILES['files']['name'][$file_form_name]);
+ $temp_extension = end(explode('.', $allowd_file));
+ if (!in_array($temp_extension, $allowed_extensions))
+ form_set_error($file_form_name, t('Only file with ' . $allowed_extensions_str . ' extensions can be uploaded.'));
+ if ($_FILES['files']['size'][$file_form_name] <= 0)
+ form_set_error($file_form_name, t('File size cannot be zero.'));
+ /* check if valid file name */
+ if (!textbook_companion_check_valid_filename($_FILES['files']['name'][$file_form_name]))
+ form_set_error($file_form_name, t('Invalid file name specified. Only alphabets and numbers are allowed as a valid filename.'));
+ } //$file_name
+ } //$_FILES['files']['name'] as $file_form_name => $file_name
+ } //isset($_FILES['files'])
+ return;
+}
+function book_proposal_nonaicte_form_submit($form, &$form_state)
+{
+ global $user;
+ $root_path = textbook_companion_samplecode_path();
+ $selections = variable_get("aicte_" . $user->uid, "");
+ $tbc_to_emails = variable_get("textbook_companion_emails_all");
+ if (!$user->uid)
+ {
+ drupal_set_message('It is mandatory to login on this website to access the proposal form', 'error');
+ return;
+ } //!$user->uid
+ /* completion date to timestamp */
+ list($d, $m, $y) = explode('-', $form_state['values']['completion_date']);
+ $completion_date_timestamp = mktime(0, 0, 0, $m, $d, $y);
+ /* Reasons for suggesting a book*/
+ if (isset($_POST['reason']))
+ {
+ if (!($form_state['values']['other_reason']))
+ {
+ $my_reason = implode(", ", $_POST['reason']);
+ } //!($form_state['values']['other_reason'])
+ else
+ {
+ $my_reason = implode(", ", $_POST['reason']);
+ $my_reason = $my_reason . "-" . " " . $form_state['values']['other_reason'];
+ }
+ } //isset($_POST['reason'])
+ /************************************/
+ $scilab_version = 'scilab ' . $form_state['values']['version'];
+ $query = "
+INSERT INTO {textbook_companion_proposal}
+ (uid, approver_uid, full_name, mobile, gender, how_project, course, branch, university, country, city, pincode, state, faculty, reviewer, reference, completion_date, creation_date, approval_date, proposal_status, message, scilab_version, operating_system, teacher_email, proposal_type, reason, samplefilepath,proposed_completion_date) VALUES (:uid, :approver_uid, :full_name, :mobile, :gender, :how_project, :course, :branch, :university, :country, :city, :pincode, :state,
+:faculty, :reviewer, :reference, :completion_date, :creation_date, :approval_date, :proposal_status, :message, :scilab_version,
+ :operating_system, :teacher_email, :proposal_type, :reason, :samplefilepath,:proposed_completion_date)
+";
+ // $result = db_query($query);
+ $args = array(
+ ":uid" => $user->uid,
+ ":approver_uid" => 0,
+ ":full_name" => _tbc_sentence_case($form_state['values']['full_name']),
+ ":mobile" => $form_state['values']['mobile'],
+ ":gender" => $form_state['values']['gender'],
+ ":how_project" => 'Not available',
+ ":course" => $form_state['values']['course'],
+ ":branch" => $form_state['values']['branch'],
+ ":university" => $form_state['values']['university'],
+ ":country" => $form_state['values']['country'],
+ ":city" => $form_state['values']['city'],
+ ":pincode" => $form_state['values']['pincode'],
+ ":state" => $form_state['values']['all_state'],
+ ":faculty" => _tbc_sentence_case($form_state['values']['faculty']),
+ ":reviewer" => _tbc_sentence_case($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" => _tbc_sentence_case($form_state['values']['operating_system']),
+ ":teacher_email" => $form_state['values']['faculty_email'],
+ ":proposal_type" => $form_state['values']['proposal_type'],
+ ":reason" => $my_reason,
+ ":samplefilepath" => "",
+ ":proposed_completion_date" => $completion_date_timestamp
+ );
+ $result = db_query($query, $args, array(
+ 'return' => Database::RETURN_INSERT_ID
+ ));
+ $dest_path = $result . '/';
+ if (!is_dir($root_path . $dest_path))
+ {
+ mkdir($root_path . $dest_path);
+ } //!is_dir($root_path . $dest_path)
+ /* uploading files */
+ foreach ($_FILES['files']['name'] as $file_form_name => $file_name)
+ {
+ if ($file_name)
+ {
+ /* checking file type */
+ $file_type = 'S';
+ if (file_exists($root_path . $dest_path . $_FILES['files']['name'][$file_form_name]))
+ {
+ drupal_set_message(t("Error uploading file. File !filename already exists.", array(
+ '!filename' => $_FILES['files']['name'][$file_form_name]
+ )), 'error');
+ return;
+ } //file_exists($root_path . $dest_path . $_FILES['files']['name'][$file_form_name])
+ /* uploading file */
+ if (move_uploaded_file($_FILES['files']['tmp_name'][$file_form_name], $root_path . $dest_path . $_FILES['files']['name'][$file_form_name]))
+ {
+ $query = "UPDATE {textbook_companion_proposal} SET samplefilepath = :samplefilepath WHERE id = :id";
+ $args = array(
+ ":samplefilepath" => $dest_path . $_FILES['files']['name'][$file_form_name],
+ ":id" => $result
+ );
+ $updateresult = db_query($query, $args);
+ drupal_set_message($file_name . ' uploaded successfully.', 'status');
+ } //move_uploaded_file($_FILES['files']['tmp_name'][$file_form_name], $root_path . $dest_path . $_FILES['files']['name'][$file_form_name])
+ else
+ {
+ drupal_set_message('Error uploading file : ' . $dest_path . $file_name, 'error');
+ }
+ } //$file_name
+ } //$_FILES['files']['name'] as $file_form_name => $file_name
+ if (!$result)
+ {
+ drupal_set_message(t('Error receiving your proposal. Please try again.'), 'error');
+ return;
+ } //!$result
+ /* proposal id */
+ $proposal_id = $result;
+ /* inserting first book preference */
+ if ($form_state['values']['book1'])
+ {
+ $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" => _tbc_sentence_case($form_state['values']['book1']),
+ ":author" => _tbc_sentence_case($form_state['values']['author1']),
+ ":isbn" => $form_state['values']['isbn1'],
+ ":publisher" => _tbc_sentence_case($form_state['values']['publisher1']),
+ ":edition" => $form_state['values']['edition1'],
+ ":year" => $form_state['values']['year1'],
+ ":category" => $form_state['values']['book_category_1'],
+ ":approval_status" => 0,
+ ":nonaicte_book" => 1
+ );
+ $result = db_query($query, $args);
+ if (!$result)
+ {
+ drupal_set_message(t('Error receiving your first book preference.'), 'error');
+ } //!$result
+ } //$form_state['values']['book1']
+ /* sending email */
+ $email_to = $user->mail;
+ $from = variable_get('textbook_companion_from_email', '');
+ $bcc = variable_get('textbook_companion_emails', '');
+ $cc = variable_get('textbook_companion_cc_emails', '');
+ $params['nonaicte_proposal_received']['proposal_id'] = $proposal_id;
+ $params['nonaicte_proposal_received']['user_id'] = $user->uid;
+ $params['nonaicte_proposal_received']['headers'] = array(
+ 'From' => $from,
+ 'MIME-Version' => '1.0',
+ 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
+ 'Content-Transfer-Encoding' => '8Bit',
+ 'X-Mailer' => 'Drupal',
+ 'Cc' => $cc,
+ 'Bcc' => $bcc
+ );
+ if (!drupal_mail('textbook_companion', 'nonaicte_proposal_received', $email_to, language_default(), $params, $from, TRUE))
+ drupal_set_message('Error sending email message.', 'error');
+ drupal_set_message(t('We have received your book proposal. We will get back to you soon.'), 'status');
+ drupal_goto('');
+}
diff --git a/run.inc b/run.inc
index 1ff73f1..28d135c 100755
--- a/run.inc
+++ b/run.inc
@@ -1,505 +1,583 @@
-<?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){
+<?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;
+ } //$url_book_pref_id
+ 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',
+ 'callback' => 'ajax_book_list_callback'
),
- '#validated' => TRUE,
+ '#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,
+ '#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',
- ),
+ 'callback' => 'ajax_chapter_list_callback'
+ ),
'#validated' => TRUE,
- '#states' => array('invisible' => array(':input[name="category"]' => array('value' => 0),),),
+ '#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' => '',
-
+ '#prefix' => '<div id="ajax-book-details-replace"></div>',
+ '#suffix' => '</div>',
+ '#markup' => '',
+
);*/
$form['book_details'] = array(
- '#type' => 'item',
- '#markup' => '<div id="ajax-book-details-replace">'._html_book_info($book_default_value).'</div>',
- );
+ '#type' => 'item',
+ '#markup' => '<div id="ajax-book-details-replace">' . _html_book_info($book_default_value) . '</div>'
+ );
$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>',
- );
- $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>',
- );
-
+ '#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>'
+ );
+ $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),
+ '#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',
- ),
+ 'callback' => 'ajax_example_list_callback'
+ ),
'#validated' => TRUE,
- '#states' => array('invisible' => array(':input[name="category"]' => array('value' => 0),),),
+ '#states' => array(
+ 'invisible' => array(
+ ':input[name="category"]' => array(
+ 'value' => 0
+ )
+ )
+ )
);
-
$form['download_chapter'] = array(
- '#type' => 'item',
- '#markup' => '<div id="ajax-download-chapter-replace"></div>',
- );
+ '#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),
+ '#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),),),
+ '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{
+ '#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>'
+ );
+ } //$url_book_pref_id
+ 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',
+ 'callback' => 'ajax_book_list_callback'
),
- '#validated' => TRUE,
+ '#validated' => TRUE
);
$form['book'] = array(
'#type' => 'select',
'#title' => t('Title of the book'),
- '#options' => _list_of_books($category_default_value),
+ '#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',
- ),
+ 'callback' => 'ajax_chapter_list_callback'
+ ),
'#validated' => TRUE,
- '#states' => array('invisible' => array(':input[name="category"]' => array('value' => 0),),),
+ '#states' => array(
+ 'invisible' => array(
+ ':input[name="category"]' => array(
+ 'value' => 0
+ )
+ )
+ )
);
-
$form['book_details'] = array(
- '#type' => 'item',
- '#markup' => '<div id="ajax-book-details-replace"></div>',
- );
+ '#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>',
- );
+ '#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),
+ '#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',
- ),
+ 'callback' => 'ajax_example_list_callback'
+ ),
'#validated' => TRUE,
- '#states' => array('invisible' => array(':input[name="category"]' => array('value' => 0),),),
+ '#states' => array(
+ 'invisible' => array(
+ ':input[name="category"]' => array(
+ 'value' => 0
+ )
+ )
+ )
);
-
-
$form['download_chapter'] = array(
- '#type' => 'item',
- '#markup' => '<div id="ajax-download-chapter-replace"></div>',
- );
+ '#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),
+ '#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),),),
+ '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;
-
- }
+ '#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_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", '');
+ } //$category_default_value > 0
+ 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 = $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']['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 = '';
- 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));
- }
-
- $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", '');
-
- }
-
- 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 = "
+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", '');
+ } //$book_list_default_value > 0
+ 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", '');
+ } //$chapter_list_default_value > 0
+ 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 = $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_list_data->filetype
+ $example_files_rows[] = array(
+ l($example_list_data->filename, 'download/file/' . $example_list_data->id),
+ $example_file_type
+ );
+ } //$example_list_data = $example_list_q->fetchObject()
+ /* 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']);
+ $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 = '';
+ 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
+ );
+ } //$dependency_list_data = $dependency_list_q->fetchObject()
+ /* creating list of files table */
+ $example_files_header = array(
+ 'Filename',
+ 'Type'
+ );
+ $example_files = theme('table', array(
+ 'header' => $example_files_header,
+ 'rows' => $example_files_rows
+ ));
+ } //$example_list_q
+ $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);
+ } //$example_list_default_value != 0
+ else
+ {
+ $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 bootstrap_table_format($headers, $rows)
+{
+ $thead = "";
+ $tbody = "";
+ foreach ($headers as $header)
+ {
+ $thead .= "<th>{$header}</th>";
+ } //$headers as $header
+ foreach ($rows as $row)
+ {
+ $tbody .= "<tr>";
+ foreach ($row as $data)
+ {
+ $tbody .= "<td>{$data}</td>";
+ } //$row as $data
+ $tbody .= "</tr>";
+ } //$rows as $row
+ $table = "
<table class='table table-bordered table-hover' style='margin-left:-140px'>
<thead>{$thead}</thead>
<tbody>{$tbody}</tbody>
</table>
";
- return $table;
- }
-
- /***********************************************************************************/
-
-
- 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");
-// 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)
+ return $table;
+}
+/***********************************************************************************/
+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");
+ // 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 . ')';
+ } //$book_titles_data = $book_titles_q->fetchObject()
+ 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;
+ } //$book_chapters_data = $book_chapters_q->fetchObject()
+ 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 . ')';
+ } //$book_examples_data = $book_examples_q->fetchObject()
+ 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));*/
+ $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));*/
+ $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)
+ {
+ if ($book_details->proposal_faculty == "None")
{
- $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)
+ $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>' . '<li><strong>ISBN:</strong> ' . $book_details->preference_isbn . '</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>Reviewer: </strong>' . $book_details->proposal_reviewer . '</li>' . '</ul></td></tr>' . '</table>';
+ } //$book_details->proposal_faculty == "None"
+ else
{
- $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;
+ $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>' . '<li><strong>ISBN:</strong> ' . $book_details->preference_isbn . '</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>';
}
-
- 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));*/
- $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));*/
- $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;
+ } //$book_details
+ return $html_data;
}
-
diff --git a/search.inc b/search.inc
index 76b38df..00de58b 100755
--- a/search.inc
+++ b/search.inc
@@ -1,316 +1,422 @@
<?php
// $Id$
-
-function textbook_companion_search_form($form,&$form_state)
+function textbook_companion_search_form($form, &$form_state)
{
- // $form['#redirect'] = FALSE;
- $form['search'] = array(
- '#type' => 'textfield',
- '#title' => t('Search'),
- '#size' => 48,
- );
-
- $form['sort_by'] = array(
- '#type' => 'radios',
- '#default_value' => TRUE,
- '#title' => t('Sort by'),
- '#options' => array('title'=>t('Title'),'author'=>t('Author'),'contributor'=>t('Contributor')),
- '#default_value' => 'title',
- );
-
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Search'),
- '#ajax' => array(
- 'callback' => 'textbook_companion_search_ajax_callback',
+ // $form['#redirect'] = FALSE;
+ $form['search'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Search'),
+ '#size' => 48
+ );
+ $form['sort_by'] = array(
+ '#type' => 'radios',
+ '#default_value' => TRUE,
+ '#title' => t('Sort by'),
+ '#options' => array(
+ 'title' => t('Title'),
+ 'author' => t('Author'),
+ 'contributor' => t('Contributor')
),
- );
- $form['cancel'] = array(
- '#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>',
- );
-
- return $form;
+ '#default_value' => 'title'
+ );
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Search'),
+ '#ajax' => array(
+ 'callback' => 'textbook_companion_search_ajax_callback'
+ )
+ );
+ $form['cancel'] = array(
+ '#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>'
+ );
+ return $form;
}
-function textbook_companion_search_ajax_callback($form,$form_state){
- if ($form_state['values']['sort_by'] == 'title' ){
- $search_q = db_query("
+function textbook_companion_search_ajax_callback($form, $form_state)
+{
+ if ($form_state['values']['sort_by'] == 'title')
+ {
+ $search_q = db_query("
SELECT pe.id AS pref_id, 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
(book LIKE :book OR author LIKE :author OR po.full_name LIKE :contributor) ORDER BY pe.book ASC
- ",
- array(":book" => '%%'.trim($form_state['values']['search']).'%%',
- ":author" => '%%'.trim($form_state['values']['search']).'%%',
- ":contributor" => '%%'.trim($form_state['values']['search']).'%%'
- ));
-
-while ($search_data = $search_q->fetchObject())
- {
- $search_rows[] = array(l($search_data->book, 'textbook_run/' . $search_data->pref_id), $search_data->author, $search_data->full_name);
- }
-
- if ($search_rows)
- {
- $search_header = array('Title of the Book', 'Author Name', 'Contributor');
- $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']['sort_by'] =='author'){
- $search_q = db_query("
+ ", array(
+ ":book" => '%%' . trim($form_state['values']['search']) . '%%',
+ ":author" => '%%' . trim($form_state['values']['search']) . '%%',
+ ":contributor" => '%%' . trim($form_state['values']['search']) . '%%'
+ ));
+ while ($search_data = $search_q->fetchObject())
+ {
+ $search_rows[] = array(
+ l($search_data->book, 'textbook_run/' . $search_data->pref_id),
+ $search_data->author,
+ $search_data->full_name
+ );
+ } //$search_data = $search_q->fetchObject()
+ if ($search_rows)
+ {
+ $search_header = array(
+ 'Title of the Book',
+ 'Author Name',
+ 'Contributor'
+ );
+ $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'] . '"';
+ } //$search_rows
+ else
+ {
+ $form['search_results']['#title'] = t('Search results for "') . $_POST['search'] . '" is not available';
+ }
+ } //$form_state['values']['sort_by'] == 'title'
+ elseif ($form_state['values']['sort_by'] == 'author')
+ {
+ $search_q = db_query("
SELECT pe.id AS pref_id, 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
(book LIKE :book OR author LIKE :author OR po.full_name LIKE :contributor) ORDER BY author ASC
- ",
- array(":book" => '%%'.trim($form_state['values']['search']).'%%',
- ":author" => '%%'.trim($form_state['values']['search']).'%%',
- ":contributor" => '%%'.trim($form_state['values']['search']).'%%'
- ));
-while ($search_data = $search_q->fetchObject())
- {
- $search_rows[] = array($search_data->author,l($search_data->book, 'textbook_run/' . $search_data->pref_id), $search_data->full_name);
- }
-
- if ($search_rows)
- {
- $search_header = array('Author Name', 'Title of the Book', 'Contributor');
- $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';
-
- }
-
- }else if ($form_state['values']['sort_by']== 'contributor'){
- $search_q = db_query("
+ ", array(
+ ":book" => '%%' . trim($form_state['values']['search']) . '%%',
+ ":author" => '%%' . trim($form_state['values']['search']) . '%%',
+ ":contributor" => '%%' . trim($form_state['values']['search']) . '%%'
+ ));
+ while ($search_data = $search_q->fetchObject())
+ {
+ $search_rows[] = array(
+ $search_data->author,
+ l($search_data->book, 'textbook_run/' . $search_data->pref_id),
+ $search_data->full_name
+ );
+ } //$search_data = $search_q->fetchObject()
+ if ($search_rows)
+ {
+ $search_header = array(
+ 'Author Name',
+ 'Title of the Book',
+ 'Contributor'
+ );
+ $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'] . '"';
+ } //$search_rows
+ else
+ {
+ $form['search_results']['#title'] = t('Search results for "') . $_POST['search'] . '" is not available';
+ }
+ } //$form_state['values']['sort_by'] == 'author'
+ else if ($form_state['values']['sort_by'] == 'contributor')
+ {
+ $search_q = db_query("
SELECT pe.id AS pref_id, 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
(book LIKE :book OR author LIKE :author OR po.full_name LIKE :contributor) ORDER BY po.full_name ASC
- ",
- array(":book" => '%%'.trim($form_state['values']['search']).'%%',
- ":author" => '%%'.trim($form_state['values']['search']).'%%',
- ":contributor" => '%%'.trim($form_state['values']['search']).'%%'
- ));
-while ($search_data = $search_q->fetchObject())
- {
- $search_rows[] = array($search_data->full_name, l($search_data->book, 'textbook_run/' . $search_data->pref_id), $search_data->author);
- }
-
- if ($search_rows)
- {
- $search_header = array('Contributor', 'Title of the Book', 'Author Name');
- $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';
-
- }
-}
- $commands[] = ajax_command_replace("#search-result", drupal_render($form['search_results']));
-
- return array('#type' => 'ajax', '#commands' => $commands);
+ ", array(
+ ":book" => '%%' . trim($form_state['values']['search']) . '%%',
+ ":author" => '%%' . trim($form_state['values']['search']) . '%%',
+ ":contributor" => '%%' . trim($form_state['values']['search']) . '%%'
+ ));
+ while ($search_data = $search_q->fetchObject())
+ {
+ $search_rows[] = array(
+ $search_data->full_name,
+ l($search_data->book, 'textbook_run/' . $search_data->pref_id),
+ $search_data->author
+ );
+ } //$search_data = $search_q->fetchObject()
+ if ($search_rows)
+ {
+ $search_header = array(
+ 'Contributor',
+ 'Title of the Book',
+ 'Author Name'
+ );
+ $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'] . '"';
+ } //$search_rows
+ else
+ {
+ $form['search_results']['#title'] = t('Search results for "') . $_POST['search'] . '" is not available';
+ }
+ } //$form_state['values']['sort_by'] == 'contributor'
+ $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;
-
-
+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
+ );
+ } //$search_data = $search_q->fetchObject()
+ if ($search_rows)
+ {
+ $search_header = array(
+ 'Title of the Book',
+ 'Author Name'
+ );
+ $output .= theme('table', array(
+ 'header' => $search_header,
+ 'rows' => $search_rows
+ ));
+ } //$search_rows
+ else
+ {
+ $output = 'not available';
+ }
+ return $output;
}
/******************************************************************************/
/**************************** BROWSE BY FORMS *********************************/
/******************************************************************************/
-
function textbook_companion_browse_book()
{
- $return_html = _browse_list('book');
- $return_html .= '<br /><br />';
- $query_character = arg(2);
- if (!$query_character) {
- /* all books */
- $return_html .= "Please select the starting character of the title of the 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);*/
-
+ $return_html = _browse_list('book');
+ $return_html .= '<br /><br />';
+ $query_character = arg(2);
+ if (!$query_character)
+ {
+ /* all books */
+ $return_html .= "Please select the starting character of the title of the book";
+ return $return_html;
+ } //!$query_character
+ $book_rows = array();
+ /*$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('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);
- }
- if (!$book_rows)
- {
- $return_html .= "Sorry no books are available with that title";
- } else {
- $book_header = array('Title of the Book', 'Author Name');
- $return_html .= theme('table',array('headers'=>$book_header,'rows'=> $book_rows));
- }
- return $return_html;
+ while ($book_data = $book_q->fetchObject())
+ {
+ $book_rows[] = array(
+ l($book_data->book, 'textbook_run/' . $book_data->id),
+ $book_data->author
+ );
+ } //$book_data = $book_q->fetchObject()
+ if (!$book_rows)
+ {
+ $return_html .= "Sorry no books are available with that title";
+ } //!$book_rows
+ else
+ {
+ $book_header = array(
+ 'Title of the Book',
+ 'Author Name'
+ );
+ $return_html .= theme('table', array(
+ 'headers' => $book_header,
+ 'rows' => $book_rows
+ ));
+ }
+ return $return_html;
}
-
function textbook_companion_browse_author()
{
- $return_html = _browse_list('author');
- $return_html .= '<br /><br />';
- $query_character = arg(2);
- if (!$query_character) {
- /* all books */
- $return_html .= "Please select the starting character of the author's name";
- 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);*/
-
+ $return_html = _browse_list('author');
+ $return_html .= '<br /><br />';
+ $query_character = arg(2);
+ if (!$query_character)
+ {
+ /* all books */
+ $return_html .= "Please select the starting character of the author's name";
+ return $return_html;
+ } //!$query_character
+ $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);*/
$query = db_select('textbook_companion_preference', 'pe');
- $query->fields('pe', array('book', 'author', 'publisher', 'year', 'id'));
+ $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);
-
- if (count($matches) > 0) {
- /* Remove the word "And"/i from the match array and make match bold */
- if (count($matches[0]) > 0) {
-
- foreach ($matches[0] as $key => $value) {
-
- if (strtolower($value) == "and") {
- unset($matches[$key]);
- }
- else {
- $matches[0][$key] = "<b>" . $value . "</b>";
- $book_data->author = str_replace($value, $matches[0][$key], $book_data->author);
- }
- }
- }
-
- /* Check count of matches after removing And */
- if (count($matches[0]) > 0) {
- $book_rows[] = array(l($book_data->book, 'textbook_run/' . $book_data->id), $book_data->author);
- }
- }
- }
-
-
- if (!$book_rows)
- {
- $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',array('headers'=>$book_header,'rows'=>$book_rows));
- }
- return $return_html;
+ while ($book_data = $book_q->fetchObject())
+ {
+ /* Initial's fix algorithm */
+ preg_match_all("/{$query_character}[a-z]+/", $book_data->author, $matches);
+ if (count($matches) > 0)
+ {
+ /* Remove the word "And"/i from the match array and make match bold */
+ if (count($matches[0]) > 0)
+ {
+ foreach ($matches[0] as $key => $value)
+ {
+ if (strtolower($value) == "and")
+ {
+ unset($matches[$key]);
+ } //strtolower($value) == "and"
+ else
+ {
+ $matches[0][$key] = "<b>" . $value . "</b>";
+ $book_data->author = str_replace($value, $matches[0][$key], $book_data->author);
+ }
+ } //$matches[0] as $key => $value
+ } //count($matches[0]) > 0
+ /* Check count of matches after removing And */
+ if (count($matches[0]) > 0)
+ {
+ $book_rows[] = array(
+ l($book_data->book, 'textbook_run/' . $book_data->id),
+ $book_data->author
+ );
+ } //count($matches[0]) > 0
+ } //count($matches) > 0
+ } //$book_data = $book_q->fetchObject()
+ if (!$book_rows)
+ {
+ $return_html .= "Sorry no books are available with that author's name";
+ } //!$book_rows
+ else
+ {
+ $book_header = array(
+ 'Title of the Book',
+ 'Author Name'
+ );
+ $return_html .= theme('table', array(
+ 'headers' => $book_header,
+ 'rows' => $book_rows
+ ));
+ }
+ return $return_html;
}
-
function textbook_companion_browse_student()
{
- $return_html = _browse_list('student');
- $return_html .= '<br /><br />';
- $query_character = arg(2);
- //print $query_character;
- //die();
- if (!$query_character) {
- /* all books */
- $return_html .= "Please select the starting character of the student's name";
- return $return_html;
- }
- $book_rows = array();
-
- /*$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);*/
-
+ $return_html = _browse_list('student');
+ $return_html .= '<br /><br />';
+ $query_character = arg(2);
+ //print $query_character;
+ //die();
+ if (!$query_character)
+ {
+ /* all books */
+ $return_html .= "Please select the starting character of the student's name";
+ return $return_html;
+ } //!$query_character
+ $book_rows = array();
+ /*$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);*/
$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->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');
+ $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);
- }
- if (!$book_rows)
- {
- $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',array('headers'=>$book_header, 'rows'=>$book_rows));
- }
- return $return_html;
+ while ($student_data = $student_q->fetchObject())
+ {
+ $book_rows[] = array(
+ l($student_data->book, 'textbook_run/' . $student_data->pe_id),
+ $student_data->full_name
+ );
+ } //$student_data = $student_q->fetchObject()
+ if (!$book_rows)
+ {
+ $return_html .= "Sorry no books are available with that student's name";
+ } //!$book_rows
+ else
+ {
+ $book_header = array(
+ 'Title of the Book',
+ 'Student Name'
+ );
+ $return_html .= theme('table', array(
+ 'headers' => $book_header,
+ 'rows' => $book_rows
+ ));
+ }
+ return $return_html;
}
-
function _browse_list($type)
{
- $return_html = '';
- $char_list = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');
- foreach ($char_list as $char_name)
- {
- $return_html .= l($char_name, 'textbook_search/' . $type . '/' . $char_name);
- if ($char_name != 'Z')
- $return_html .= ' | ';
- }
- return '<div id="filter-links">' . $return_html . "</div>";
+ $return_html = '';
+ $char_list = array(
+ 'A',
+ 'B',
+ 'C',
+ 'D',
+ 'E',
+ 'F',
+ 'G',
+ 'H',
+ 'I',
+ 'J',
+ 'K',
+ 'L',
+ 'M',
+ 'N',
+ 'O',
+ 'P',
+ 'Q',
+ 'R',
+ 'S',
+ 'T',
+ 'U',
+ 'V',
+ 'W',
+ 'X',
+ 'Y',
+ 'Z'
+ );
+ foreach ($char_list as $char_name)
+ {
+ $return_html .= l($char_name, 'textbook_search/' . $type . '/' . $char_name);
+ if ($char_name != 'Z')
+ $return_html .= ' | ';
+ } //$char_list as $char_name
+ return '<div id="filter-links">' . $return_html . "</div>";
}
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");
-
+ $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");
/*$query = db_select('textbook_companion_proposal');
$query =distinct();
$query->fields('university', array(''));
@@ -319,25 +425,28 @@ function _list_of_colleges()
$or->condition('proposal_status', 3);
$query->condition($or);
$query->orderBy('university', 'ASC');*/
- $college_names_q = $college_names_q->execute();
-
- while ($college_names_data = $college_names_q->fetchObject())
- {
- $college_names[$college_names_data->university] = $college_names_data->university;
- }
- return $college_names;
+ $college_names_q = $college_names_q->execute();
+ while ($college_names_data = $college_names_q->fetchObject())
+ {
+ $college_names[$college_names_data->university] = $college_names_data->university;
+ } //$college_names_data = $college_names_q->fetchObject()
+ return $college_names;
}
-
-function _list_books_by_college($college) {
-
+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 = db_select('textbook_companion_proposal', 'pro');
- $query->fields('pro', array('full_name', 'proposal_status'));
- $query->fields('pre', array('id', 'book', 'isbn'));
+ $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);
@@ -345,68 +454,63 @@ function _list_books_by_college($college) {
$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 = $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>';
- }else {
- $output .= '<tr><td>'.$sno++.'</td><td>'.$row->full_name.'</td><td><a target="_blank" href="'.base_path().'textbook_run/'.$row->preid.'">'.$row->book.'</a></td><td>'.str_replace("-", "", $row->isbn).'</td><td style="color: green;">Completed</td>';
+ 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>';
+ } //$row->proposal_status == 1
+ else
+ {
+ $output .= '<tr><td>' . $sno++ . '</td><td>' . $row->full_name . '</td><td><a target="_blank" href="' . base_path() . 'textbook_run/' . $row->preid . '">' . $row->book . '</a></td><td>' . str_replace("-", "", $row->isbn) . '</td><td style="color: green;">Completed</td>';
}
$output .= '</tr>';
- }
-
+ } //$row = $result->fetchObject()
return $output;
}
-
-function textbook_companion_browse_college_form($form, $form_state) {
- $form = array();
-
- //ahah_helper_register($form, $form_state);
-
-
- if (!isset($form_state['storage']['college_info']['college'])) {
- $usage_default_value = '0';
- }
- else {
- $usage_default_value = $form_state['storage']['college_info']['college'];
- }
-
- $form['college_info'] = array(
- '#type' => 'fieldset',
- '#prefix' => '<div id="college-info-wrapper">',
- '#suffix' => '</div>',
- '#tree' => TRUE,
- );
- $form['college_info']['college'] = array(
- '#type' => 'select',
- '#title' => t('College Name'),
- '#options' => _list_of_colleges(),
- '#default_value' => $usage_default_value,
- /* '#ahah' => array(
- 'event' => 'change',
- 'path' => ahah_helper_path(array('college_info')),
- 'wrapper' => 'college-info-wrapper',
- ),*/
- );
-
-
- if ($usage_default_value != '0') {
- $form['college_info']['book_details'] = array(
+function textbook_companion_browse_college_form($form, $form_state)
+{
+ $form = array();
+ //ahah_helper_register($form, $form_state);
+ if (!isset($form_state['storage']['college_info']['college']))
+ {
+ $usage_default_value = '0';
+ } //!isset($form_state['storage']['college_info']['college'])
+ else
+ {
+ $usage_default_value = $form_state['storage']['college_info']['college'];
+ }
+ $form['college_info'] = array(
+ '#type' => 'fieldset',
+ '#prefix' => '<div id="college-info-wrapper">',
+ '#suffix' => '</div>',
+ '#tree' => TRUE
+ );
+ $form['college_info']['college'] = array(
+ '#type' => 'select',
+ '#title' => t('College Name'),
+ '#options' => _list_of_colleges(),
+ '#default_value' => $usage_default_value
+ /* '#ahah' => array(
+ 'event' => 'change',
+ 'path' => ahah_helper_path(array('college_info')),
+ 'wrapper' => 'college-info-wrapper',
+ ),*/
+ );
+ if ($usage_default_value != '0')
+ {
+ $form['college_info']['book_details'] = array(
'#type' => 'item',
'#value' => _list_books_by_college($usage_default_value)
);
- }
-
- return $form;
+ } //$usage_default_value != '0'
+ return $form;
}
-
-function textbook_companion_browse_college_form_validate($form, &$form_state) {
-
+function textbook_companion_browse_college_form_validate($form, &$form_state)
+{
}
-
-function textbook_companion_browse_college_form_submit($form, &$form_state) {
-
+function textbook_companion_browse_college_form_submit($form, &$form_state)
+{
}
diff --git a/settings.inc b/settings.inc
index 865a549..ed4eccd 100755
--- a/settings.inc
+++ b/settings.inc
@@ -1,123 +1,130 @@
<?php
// $Id$
-
-function textbook_companion_settings_form($form_state)
+function textbook_companion_settings_form($form,&$form_state)
{
- $form['emails'] = array(
- '#type' => 'textfield',
- '#title' => t('Notification emails'),
- '#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', ''),
- );
- $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'),
- '#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_all', ''),
- );
-$form['cc_emails'] = array(
- '#type' => 'textfield',
- '#title' => t('(Cc) Notification emails'),
- '#description' => t('Specify emails id for Cc option of mail system with comma separated'),
- '#size' => 50,
- '#maxlength' => 255,
- '#required' => TRUE,
- '#default_value' => variable_get('textbook_companion_cc_emails', ''),
- );
- $form['from_email'] = array(
- '#type' => 'textfield',
- '#title' => t('Outgoing from email address'),
- '#description' => t('Email address to be display in the from field of all outgoing messages'),
- '#size' => 50,
- '#maxlength' => 255,
- '#required' => TRUE,
- '#default_value' => variable_get('textbook_companion_from_email', ''),
- );
-
- $form['extensions']['source'] = array(
- '#type' => 'textfield',
- '#title' => t('Allowed source file extensions'),
- '#description' => t('A comma separated list WITHOUT SPACE of source file extensions that are permitted to be uploaded on the server'),
- '#size' => 50,
- '#maxlength' => 255,
- '#required' => TRUE,
- '#default_value' => variable_get('textbook_companion_source_extensions', ''),
- );
- $form['extensions']['sample_source_file'] = array(
- '#type' => 'textfield',
- '#title' => t('Allowed sample source file extensions'),
- '#description' => t('A comma separated list WITHOUT SPACE of source file extensions that are permitted to be uploaded on the server'),
- '#size' => 50,
- '#maxlength' => 255,
- '#required' => TRUE,
- '#default_value' => variable_get('textbook_companion_sample_source_file_extensions', ''),
- );
- $form['extensions']['dependency'] = array(
- '#type' => 'textfield',
- '#title' => t('Allowed dependency file extensions'),
- '#description' => t('A comma separated list WITHOUT SPACE of dependency file extensions that are permitted to be uploaded on the server'),
- '#size' => 50,
- '#maxlength' => 255,
- '#required' => TRUE,
- '#default_value' => variable_get('textbook_companion_dependency_extensions', ''),
- );
- $form['extensions']['result'] = array(
- '#type' => 'textfield',
- '#title' => t('Allowed result file extensions'),
- '#description' => t('A comma separated list WITHOUT SPACE of result file extensions that are permitted to be uploaded on the server'),
- '#size' => 50,
- '#maxlength' => 255,
- '#required' => TRUE,
- '#default_value' => variable_get('textbook_companion_result_extensions', ''),
- );
- $form['extensions']['xcos'] = array(
- '#type' => 'textfield',
- '#title' => t('Allowed xcos file extensions'),
- '#description' => t('A comma separated list WITHOUT SPACE of xcos file extensions that are permitted to be uploaded on the server'),
- '#size' => 50,
- '#maxlength' => 255,
- '#required' => TRUE,
- '#default_value' => variable_get('textbook_companion_xcos_extensions', ''),
- );
-
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Submit')
- );
- return $form;
+ $form['emails'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Notification emails'),
+ '#description' => t('A comma separated list of email addresses to receive notifications emails [bcc]'),
+ '#size' => 50,
+ '#maxlength' => 255,
+ '#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'),
+ '#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_all', '')
+ );
+ $form['cc_emails'] = array(
+ '#type' => 'textfield',
+ '#title' => t('(Cc) Notification emails'),
+ '#description' => t('Specify emails id for CC option of mail system with comma separated'),
+ '#size' => 50,
+ '#maxlength' => 255,
+ '#required' => TRUE,
+ '#default_value' => variable_get('textbook_companion_cc_emails', '')
+ );
+ $form['from_email'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Outgoing from email address'),
+ '#description' => t('Email address to be display in the from field of all outgoing messages'),
+ '#size' => 50,
+ '#maxlength' => 255,
+ '#required' => TRUE,
+ '#default_value' => variable_get('textbook_companion_from_email', '')
+ );
+ $form['extensions']['source'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Allowed source file extensions'),
+ '#description' => t('A comma separated list WITHOUT SPACE of source file extensions that are permitted to be uploaded on the server'),
+ '#size' => 50,
+ '#maxlength' => 255,
+ '#required' => TRUE,
+ '#default_value' => variable_get('textbook_companion_source_extensions', '')
+ );
+ $form['extensions']['sample_source_file'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Allowed sample source file extensions'),
+ '#description' => t('A comma separated list WITHOUT SPACE of source file extensions that are permitted to be uploaded on the server'),
+ '#size' => 50,
+ '#maxlength' => 255,
+ '#required' => TRUE,
+ '#default_value' => variable_get('textbook_companion_sample_source_file_extensions', '')
+ );
+ $form['extensions']['dependency'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Allowed dependency file extensions'),
+ '#description' => t('A comma separated list WITHOUT SPACE of dependency file extensions that are permitted to be uploaded on the server'),
+ '#size' => 50,
+ '#maxlength' => 255,
+ '#required' => TRUE,
+ '#default_value' => variable_get('textbook_companion_dependency_extensions', '')
+ );
+ $form['extensions']['result'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Allowed result file extensions'),
+ '#description' => t('A comma separated list WITHOUT SPACE of result file extensions that are permitted to be uploaded on the server'),
+ '#size' => 50,
+ '#maxlength' => 255,
+ '#required' => TRUE,
+ '#default_value' => variable_get('textbook_companion_result_extensions', '')
+ );
+ $form['extensions']['xcos'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Allowed xcos file extensions'),
+ '#description' => t('A comma separated list WITHOUT SPACE of xcos file extensions that are permitted to be uploaded on the server'),
+ '#size' => 50,
+ '#maxlength' => 255,
+ '#required' => TRUE,
+ '#default_value' => variable_get('textbook_companion_xcos_extensions', '')
+ );
+ $form['book_prefences'] = array(
+ '#type' => 'select',
+ '#title' => t('Number of books in proposal required'),
+ '#options' => array(
+ '1' => '1',
+ '2' => '2',
+ '3' => '3'
+ ),
+ '#required' => TRUE,
+ '#default_value' => variable_get('textbook_companion_book_preferences', '')
+ );
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit')
+ );
+ return $form;
}
-
function textbook_companion_settings_form_validate($form, &$form_state)
{
- return;
+ return;
}
-
function textbook_companion_settings_form_submit($form, &$form_state)
{
- variable_set('textbook_companion_emails', $form_state['values']['emails']);
- variable_set('textbook_companion_cc_emails', $form_state['values']['cc_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']);
- variable_set('textbook_companion_sample_source_file_extensions', $form_state['values']['sample_source_file']);
- variable_set('textbook_companion_dependency_extensions', $form_state['values']['dependency']);
- variable_set('textbook_companion_result_extensions', $form_state['values']['result']);
- variable_set('textbook_companion_xcos_extensions', $form_state['values']['xcos']);
- drupal_set_message(t('Settings updated'), 'status');
+ variable_set('textbook_companion_emails', $form_state['values']['emails']);
+ variable_set('textbook_companion_cc_emails', $form_state['values']['cc_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']);
+ variable_set('textbook_companion_sample_source_file_extensions', $form_state['values']['sample_source_file']);
+ variable_set('textbook_companion_dependency_extensions', $form_state['values']['dependency']);
+ variable_set('textbook_companion_result_extensions', $form_state['values']['result']);
+ variable_set('textbook_companion_xcos_extensions', $form_state['values']['xcos']);
+ variable_set('textbook_companion_book_preferences', $form_state['values']['book_prefences']);
+ drupal_set_message(t('Settings updated'), 'status');
}
diff --git a/textbook_companion.install b/textbook_companion.install
index dad05a8..9ecd14a 100755
--- a/textbook_companion.install
+++ b/textbook_companion.install
@@ -1,501 +1,512 @@
<?php
// $Id$
-
/**
* Implementation of hook_install().
*/
-function textbook_companion_install() {
- // Create tables.
- drupal_install_schema('textbook_companion');
- variable_set('textbook_companion_emails', '');
- variable_set('textbook_companion_from_email', '');
- variable_set('textbook_companion_source_extensions', '');
- variable_set('textbook_companion_dependency_extensions', '');
- variable_set('textbook_companion_result_extensions', '');
- variable_set('textbook_companion_xcos_extensions', '');
+function textbook_companion_install()
+{
+ // Create tables.
+ drupal_install_schema('textbook_companion');
+ variable_set('textbook_companion_emails', '');
+ variable_set('textbook_companion_from_email', '');
+ variable_set('textbook_companion_source_extensions', '');
+ variable_set('textbook_companion_dependency_extensions', '');
+ variable_set('textbook_companion_result_extensions', '');
+ variable_set('textbook_companion_xcos_extensions', '');
}
-
/**
* Implementation of hook_uninstall().
*/
-function textbook_companion_uninstall() {
- // Remove tables.
- drupal_uninstall_schema('textbook_companion');
- // Remove variables
- variable_del('textbook_companion_emails');
- variable_del('textbook_companion_from_email');
- variable_del('textbook_companion_source_extensions');
- variable_del('textbook_companion_dependency_extensions');
- variable_del('textbook_companion_result_extensions');
- variable_del('textbook_companion_xcos_extensions');
+function textbook_companion_uninstall()
+{
+ // Remove tables.
+ drupal_uninstall_schema('textbook_companion');
+ // Remove variables
+ variable_del('textbook_companion_emails');
+ variable_del('textbook_companion_from_email');
+ variable_del('textbook_companion_source_extensions');
+ variable_del('textbook_companion_dependency_extensions');
+ variable_del('textbook_companion_result_extensions');
+ variable_del('textbook_companion_xcos_extensions');
}
-
/**
* Implementation of hook_schema().
*/
-function textbook_companion_schema() {
-
- /* proposal */
- $schema['textbook_companion_proposal'] = array(
- 'description' => t('TODO: please describe this table!'),
- 'fields' => array(
- 'id' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'serial',
- 'not null' => TRUE,
- ),
- 'uid' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'int',
- 'not null' => TRUE,
- ),
- 'approver_uid' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'int',
- 'not null' => TRUE,
- ),
- 'full_name' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'varchar',
- 'length' => '50',
- 'not null' => TRUE,
- ),
- 'mobile' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'varchar',
- 'length' => '15',
- 'not null' => TRUE,
- ),
- 'how_project' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'varchar',
- 'length' => '50',
- 'not null' => TRUE,
- ),
- 'course' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'varchar',
- 'length' => '50',
- 'not null' => TRUE,
- ),
- 'branch' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'varchar',
- 'length' => '50',
- 'not null' => TRUE,
- ),
- 'university' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'varchar',
- 'length' => '100',
- 'not null' => TRUE,
- ),
- 'faculty' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'varchar',
- 'length' => '100',
- 'not null' => TRUE,
- ),
- 'reviewer' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'varchar',
- 'length' => '100',
- 'not null' => TRUE,
- ),
- 'completion_date' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'int',
- 'not null' => TRUE,
- ),
- 'creation_date' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'int',
- 'not null' => TRUE,
- ),
- 'approval_date' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'int',
- 'not null' => TRUE,
- ),
- 'proposal_status' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'int',
- 'not null' => TRUE,
- ),
- 'message' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'text',
- 'size' => 'medium',
- 'not null' => TRUE,
- ),
- ),
- 'primary key' => array('id'),
- 'unique keys' => array(
- 'id' => array('id')
- ),
- );
-
- /* book preference */
- $schema['textbook_companion_preference'] = array(
- 'description' => t('TODO: please describe this table!'),
- 'fields' => array(
- 'id' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'serial',
- 'not null' => TRUE,
- ),
- 'proposal_id' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'int',
- 'not null' => TRUE,
- ),
- 'pref_number' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'int',
- 'not null' => TRUE,
- ),
- 'book' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'varchar',
- 'length' => '100',
- 'not null' => TRUE,
- ),
- 'author' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'varchar',
- 'length' => '100',
- 'not null' => TRUE,
- ),
- 'isbn' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'varchar',
- 'length' => '25',
- 'not null' => TRUE,
- ),
- 'publisher' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'varchar',
- 'length' => '50',
- 'not null' => TRUE,
- ),
- 'edition' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'varchar',
- 'length' => '2',
- 'not null' => TRUE,
- ),
- 'year' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'int',
- 'not null' => TRUE,
- ),
+function textbook_companion_schema()
+{
+ /* proposal */
+ $schema['textbook_companion_proposal'] = array(
+ 'description' => t('TODO: please describe this table!'),
+ 'fields' => array(
+ 'id' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'serial',
+ 'not null' => TRUE
+ ),
+ 'uid' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE
+ ),
+ 'approver_uid' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE
+ ),
+ 'full_name' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '50',
+ 'not null' => TRUE
+ ),
+ 'mobile' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '15',
+ 'not null' => TRUE
+ ),
+ 'how_project' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '50',
+ 'not null' => TRUE
+ ),
+ 'course' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '50',
+ 'not null' => TRUE
+ ),
+ 'branch' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '50',
+ 'not null' => TRUE
+ ),
+ 'university' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '100',
+ 'not null' => TRUE
+ ),
+ 'faculty' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '100',
+ 'not null' => TRUE
+ ),
+ 'reviewer' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '100',
+ 'not null' => TRUE
+ ),
+ 'completion_date' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE
+ ),
+ 'creation_date' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE
+ ),
+ 'approval_date' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE
+ ),
+ 'proposal_status' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE
+ ),
+ 'message' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'text',
+ 'size' => 'medium',
+ 'not null' => TRUE
+ )
+ ),
+ 'primary key' => array(
+ 'id'
+ ),
+ 'unique keys' => array(
+ 'id' => array(
+ 'id'
+ )
+ )
+ );
+ /* book preference */
+ $schema['textbook_companion_preference'] = array(
+ 'description' => t('TODO: please describe this table!'),
+ 'fields' => array(
+ 'id' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'serial',
+ 'not null' => TRUE
+ ),
+ 'proposal_id' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE
+ ),
+ 'pref_number' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE
+ ),
+ 'book' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '100',
+ 'not null' => TRUE
+ ),
+ 'author' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '100',
+ 'not null' => TRUE
+ ),
+ 'isbn' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '25',
+ 'not null' => TRUE
+ ),
+ 'publisher' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '50',
+ 'not null' => TRUE
+ ),
+ 'edition' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '2',
+ 'not null' => TRUE
+ ),
+ 'year' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE
+ ),
'category' => array(
'description' => t('TODO: please describe this field!'),
'type' => 'int',
- 'not null' => TRUE,
- ),
- 'approval_status' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'int',
- 'not null' => TRUE,
- ),
- ),
- 'primary key' => array('id'),
- 'unique keys' => array(
- 'id' => array('id')
- ),
- );
-
- /* chapter */
- $schema['textbook_companion_chapter'] = array(
- 'description' => t('TODO: please describe this table!'),
- 'fields' => array(
- 'id' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'serial',
- 'not null' => TRUE,
- ),
- 'preference_id' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'int',
- 'not null' => TRUE,
- ),
- 'number' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'int',
- 'not null' => TRUE,
- ),
- 'name' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'varchar',
- 'length' => '255',
- 'not null' => TRUE,
- ),
- ),
- 'primary key' => array('id'),
- );
-
- /* examples */
- $schema['textbook_companion_example'] = array(
- 'description' => t('TODO: please describe this table!'),
- 'fields' => array(
- 'id' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'serial',
- 'not null' => TRUE,
- ),
- 'chapter_id' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'int',
- 'not null' => TRUE,
- ),
- 'approver_uid' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'int',
- 'not null' => TRUE,
- ),
- 'number' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'varchar',
- 'length' => '10',
- 'not null' => TRUE,
- ),
- 'caption' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'varchar',
- 'length' => '255',
- 'not null' => TRUE,
- ),
- 'approval_date' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'int',
- 'not null' => TRUE,
- ),
- 'approval_status' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'int',
- 'not null' => TRUE,
- ),
- 'timestamp' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'int',
- 'not null' => TRUE,
- ),
- ),
- 'primary key' => array('id'),
- );
-
- /* example files */
- $schema['textbook_companion_example_files'] = array(
- 'description' => t('TODO: please describe this table!'),
- 'fields' => array(
- 'id' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'serial',
- 'not null' => TRUE,
- ),
- 'example_id' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'int',
- 'not null' => TRUE,
- ),
- 'filename' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'varchar',
- 'length' => '255',
- 'not null' => TRUE,
- ),
- 'filepath' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'varchar',
- 'length' => '500',
- 'not null' => TRUE,
- ),
- 'filemime' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'varchar',
- 'length' => '255',
- 'not null' => TRUE,
- ),
- 'filesize' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'int',
- 'not null' => TRUE,
- ),
- 'filetype' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'varchar',
- 'length' => '1',
- 'not null' => TRUE,
- ),
- 'caption' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'varchar',
- 'length' => '100',
- 'not null' => TRUE,
- ),
- 'timestamp' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'int',
- 'not null' => TRUE,
- ),
- ),
- 'primary key' => array('id'),
- );
-
- /* dependency files */
- $schema['textbook_companion_dependency_files'] = array(
- 'description' => t('TODO: please describe this table!'),
- 'fields' => array(
- 'id' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'serial',
- 'not null' => TRUE,
- ),
- 'preference_id' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'int',
- 'not null' => TRUE,
- ),
- 'filename' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'varchar',
- 'length' => '255',
- 'not null' => TRUE,
- ),
- 'filepath' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'varchar',
- 'length' => '500',
- 'not null' => TRUE,
- ),
- 'filemime' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'varchar',
- 'length' => '255',
- 'not null' => TRUE,
- ),
- 'filesize' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'int',
- 'not null' => TRUE,
- ),
- 'caption' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'varchar',
- 'length' => '100',
- 'not null' => TRUE,
- ),
- 'description' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'text',
- 'size' => 'medium',
- 'not null' => TRUE,
- ),
- 'timestamp' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'int',
- 'not null' => TRUE,
- ),
- ),
- 'primary key' => array('id'),
- );
-
- /* example - dependency files links */
- $schema['textbook_companion_example_dependency'] = array(
- 'description' => t('TODO: please describe this table!'),
- 'fields' => array(
- 'id' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'serial',
- 'not null' => TRUE,
- ),
- 'example_id' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'int',
- 'not null' => TRUE,
- ),
- 'dependency_id' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'int',
- 'not null' => TRUE,
- ),
- 'approval_status' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'int',
- 'not null' => TRUE,
- ),
- 'timestamp' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'int',
- 'not null' => TRUE,
- ),
- ),
- 'primary key' => array('id'),
- );
-
- $schema['textbook_companion_notes'] = array(
- 'description' => t('TODO: please describe this table!'),
- 'fields' => array(
- 'id' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'serial',
- 'not null' => TRUE,
- ),
- 'preference_id' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'int',
- 'not null' => TRUE,
- ),
- 'notes' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'text',
- 'size' => 'medium',
- 'not null' => TRUE,
- ),
- ),
- 'primary key' => array('id'),
- );
-
- $schema['textbook_companion_feedback'] = array(
- 'description' => t('TODO: please describe this table!'),
- 'fields' => array(
- 'id' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'serial',
- 'not null' => TRUE,
- ),
- 'example_id' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'int',
- 'not null' => TRUE,
- ),
- 'uid' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'int',
- 'not null' => TRUE,
- ),
- 'feedback' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'text',
- 'size' => 'medium',
- 'not null' => TRUE,
- ),
- 'ip_address' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'varchar',
- 'length' => '16',
- 'not null' => TRUE,
- ),
- 'timestamp' => array(
- 'description' => t('TODO: please describe this field!'),
- 'type' => 'int',
- 'not null' => TRUE,
- ),
- ),
- 'primary key' => array('id'),
- );
-
- return $schema;
+ 'not null' => TRUE
+ ),
+ 'approval_status' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE
+ )
+ ),
+ 'primary key' => array(
+ 'id'
+ ),
+ 'unique keys' => array(
+ 'id' => array(
+ 'id'
+ )
+ )
+ );
+ /* chapter */
+ $schema['textbook_companion_chapter'] = array(
+ 'description' => t('TODO: please describe this table!'),
+ 'fields' => array(
+ 'id' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'serial',
+ 'not null' => TRUE
+ ),
+ 'preference_id' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE
+ ),
+ 'number' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE
+ ),
+ 'name' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '255',
+ 'not null' => TRUE
+ )
+ ),
+ 'primary key' => array(
+ 'id'
+ )
+ );
+ /* examples */
+ $schema['textbook_companion_example'] = array(
+ 'description' => t('TODO: please describe this table!'),
+ 'fields' => array(
+ 'id' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'serial',
+ 'not null' => TRUE
+ ),
+ 'chapter_id' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE
+ ),
+ 'approver_uid' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE
+ ),
+ 'number' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '10',
+ 'not null' => TRUE
+ ),
+ 'caption' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '255',
+ 'not null' => TRUE
+ ),
+ 'approval_date' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE
+ ),
+ 'approval_status' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE
+ ),
+ 'timestamp' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE
+ )
+ ),
+ 'primary key' => array(
+ 'id'
+ )
+ );
+ /* example files */
+ $schema['textbook_companion_example_files'] = array(
+ 'description' => t('TODO: please describe this table!'),
+ 'fields' => array(
+ 'id' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'serial',
+ 'not null' => TRUE
+ ),
+ 'example_id' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE
+ ),
+ 'filename' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '255',
+ 'not null' => TRUE
+ ),
+ 'filepath' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '500',
+ 'not null' => TRUE
+ ),
+ 'filemime' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '255',
+ 'not null' => TRUE
+ ),
+ 'filesize' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE
+ ),
+ 'filetype' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '1',
+ 'not null' => TRUE
+ ),
+ 'caption' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '100',
+ 'not null' => TRUE
+ ),
+ 'timestamp' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE
+ )
+ ),
+ 'primary key' => array(
+ 'id'
+ )
+ );
+ /* dependency files */
+ $schema['textbook_companion_dependency_files'] = array(
+ 'description' => t('TODO: please describe this table!'),
+ 'fields' => array(
+ 'id' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'serial',
+ 'not null' => TRUE
+ ),
+ 'preference_id' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE
+ ),
+ 'filename' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '255',
+ 'not null' => TRUE
+ ),
+ 'filepath' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '500',
+ 'not null' => TRUE
+ ),
+ 'filemime' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '255',
+ 'not null' => TRUE
+ ),
+ 'filesize' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE
+ ),
+ 'caption' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '100',
+ 'not null' => TRUE
+ ),
+ 'description' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'text',
+ 'size' => 'medium',
+ 'not null' => TRUE
+ ),
+ 'timestamp' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE
+ )
+ ),
+ 'primary key' => array(
+ 'id'
+ )
+ );
+ /* example - dependency files links */
+ $schema['textbook_companion_example_dependency'] = array(
+ 'description' => t('TODO: please describe this table!'),
+ 'fields' => array(
+ 'id' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'serial',
+ 'not null' => TRUE
+ ),
+ 'example_id' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE
+ ),
+ 'dependency_id' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE
+ ),
+ 'approval_status' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE
+ ),
+ 'timestamp' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE
+ )
+ ),
+ 'primary key' => array(
+ 'id'
+ )
+ );
+ $schema['textbook_companion_notes'] = array(
+ 'description' => t('TODO: please describe this table!'),
+ 'fields' => array(
+ 'id' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'serial',
+ 'not null' => TRUE
+ ),
+ 'preference_id' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE
+ ),
+ 'notes' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'text',
+ 'size' => 'medium',
+ 'not null' => TRUE
+ )
+ ),
+ 'primary key' => array(
+ 'id'
+ )
+ );
+ $schema['textbook_companion_feedback'] = array(
+ 'description' => t('TODO: please describe this table!'),
+ 'fields' => array(
+ 'id' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'serial',
+ 'not null' => TRUE
+ ),
+ 'example_id' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE
+ ),
+ 'uid' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE
+ ),
+ 'feedback' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'text',
+ 'size' => 'medium',
+ 'not null' => TRUE
+ ),
+ 'ip_address' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'varchar',
+ 'length' => '16',
+ 'not null' => TRUE
+ ),
+ 'timestamp' => array(
+ 'description' => t('TODO: please describe this field!'),
+ 'type' => 'int',
+ 'not null' => TRUE
+ )
+ ),
+ 'primary key' => array(
+ 'id'
+ )
+ );
+ return $schema;
}
-
diff --git a/textbook_companion.module b/textbook_companion.module
index 847d0bc..98263fb 100755
--- a/textbook_companion.module
+++ b/textbook_companion.module
@@ -1,3835 +1,1172 @@
<?php
// $Id$
-
+require_once('email.inc');
/*
-* Implementation of hook_menu().
-*/
-
+ * Implementation of hook_menu().
+ */
function textbook_companion_menu()
{
- $items = array();
-
- /* users */
- $items['proposal'] = array(
- 'title' => 'Book Proposal Form',
- 'description' => 'Book Proposal Form.',
- 'page callback' => 'textbook_companion_proposal_all',
- 'access callback' => 'user_access',
- 'access arguments' => array('create book proposal'),
- 'type' => MENU_CALLBACK,
- );
- $items["aicte_proposal"] = array(
- "title" => "AICTE Book Proposal",
- "description" => "AICTE Book Proposal Form",
- "page callback" => "textbook_companion_aicte_proposal_all",
- 'access arguments' => array('create book proposal'),
- 'type' => MENU_CALLBACK,
- );
- $items["all_proposal"] = array(
- "title" => "Book Proposal",
- "description" => "Book Proposal Form",
- "page callback" => "textbook_companion_aicte_proposal_all",
- 'access arguments' => array('create book proposal'),
- 'type' => MENU_CALLBACK,
- );
- /* for reviewers */
- $items['manage_proposal'] = array(
- 'title' => 'Manage Book Proposals',
- 'description' => 'Manage Book Proposals',
- 'page callback' => '_proposal_pending',
- 'access callback' => 'user_access',
- 'access arguments' => array('approve book proposal'),
- 'file' => 'manage_proposal.inc',
- );
- $items['manage_proposal/pending'] = array(
- 'title' => 'Pending Proposals',
- 'description' => 'Pending Proposals Queue',
- 'page callback' => '_proposal_pending',
- 'access callback' => 'user_access',
- 'access arguments' => array('approve book proposal'),
- 'type' => MENU_DEFAULT_LOCAL_TASK,
- 'weight' => 1,
- 'file' => 'manage_proposal.inc',
- );
- $items['manage_proposal/all'] = array(
- 'title' => 'All Proposals',
- 'description' => 'All Proposals',
- 'page callback' => '_proposal_all',
- 'access callback' => 'user_access',
- 'access arguments' => array('approve book proposal'),
- 'type' => MENU_LOCAL_TASK,
- 'weight' => 2,
- 'file' => 'manage_proposal.inc',
- );
- $items['manage_proposal/category'] = array(
- 'title' => 'Categorize',
- 'description' => 'Categorize Books',
- 'page callback' => '_category_all',
- 'access callback' => 'user_access',
- 'access arguments' => array('approve book proposal'),
- 'type' => MENU_LOCAL_TASK,
- 'weight' => 2,
- 'file' => 'manage_proposal.inc',
- );
- $items['manage_proposal/failed'] = array(
- 'title' => 'Failed Proposals',
- 'description' => 'Failed to submit code',
- 'page callback' => '_failed_all',
- 'access callback' => 'user_access',
- 'access arguments' => array('approve book proposal'),
- 'type' => MENU_LOCAL_TASK,
- 'weight' => 3,
- 'file' => 'manage_proposal.inc',
- );
- $items['manage_proposal/approve'] = array(
- 'title' => 'Proposal Approval',
- 'description' => 'Proposal Approval',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('proposal_approval_form'),
- 'access arguments' => array('approve book proposal'),
- 'type' => MENU_CALLBACK,
- 'file' => 'manage_proposal.inc',
- );
- $items['manage_proposal/status'] = array(
- 'title' => 'Proposal Status',
- 'description' => 'Proposal Status',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('proposal_status_form'),
- 'access arguments' => array('approve book proposal'),
- 'type' => MENU_CALLBACK,
- 'file' => 'manage_proposal.inc',
- );
- $items['manage_proposal/edit'] = array(
- 'title' => 'Edit Proposal',
- 'description' => 'Edit Proposal',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('proposal_edit_form'),
- 'access arguments' => array('edit book proposal'),
- 'type' => MENU_CALLBACK,
- 'file' => 'manage_proposal.inc',
- );
- $items['manage_proposal/category/edit'] = array(
- 'title' => 'Edit Category',
- 'description' => 'Edit category',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('category_edit_form'),
- 'access arguments' => array('edit book proposal'),
- 'type' => MENU_CALLBACK,
- 'file' => 'manage_proposal.inc',
- );
-
- $items['code_approval'] = array(
- 'title' => 'Manage Code Approval',
- 'description' => 'Manage Code Approval',
- 'page callback' => 'code_approval',
- 'access arguments' => array('approve code'),
- 'type' => MENU_NORMAL_ITEM,
- 'file' => 'code_approval.inc',
- );
- $items['code_approval/approve'] = array(
- 'title' => 'Code Approval',
- 'description' => 'Code Approval',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('code_approval_form'),
- 'access arguments' => array('approve code'),
- 'type' => MENU_DEFAULT_LOCAL_TASK,
- 'weight' => 1,
- 'file' => 'code_approval.inc',
- );
- $items['code_approval/bulk'] = array(
- 'title' => 'Bulk Manage',
- 'description' => 'Bulk Mangage',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('bulk_approval_form'),
- 'access arguments' => array('bulk manage code'),
- 'type' => MENU_LOCAL_TASK,
- 'weight' => 2,
- 'file' => 'code_approval.inc',
- );
- $items['code_approval/editcode'] = array(
- 'title' => 'Admin Edit Example',
- 'description' => 'Admin Edit Example',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('upload_examples_admin_edit_form'),
- 'access arguments' => array('approve code'),
- 'type' => MENU_CALLBACK,
- 'weight' => 3,
- 'file' => 'editcodeadmin.inc',
- );
- $items['code_approval/notes'] = array(
- 'title' => 'Notes for Reviewers',
- 'description' => 'Notes for Reviewers',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('book_notes_form'),
- 'access arguments' => array('bulk manage code'),
- 'type' => MENU_CALLBACK,
- 'weight' => 4,
- 'file' => 'notes.inc',
- );
- $items['code_approval/dependency'] = array(
- 'title' => 'Dependency',
- 'description' => 'Dependency',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('textbook_companion_dependency_approval_form'),
- 'access arguments' => array('bulk manage code'),
- 'type' => MENU_LOCAL_TASK,
- 'weight' => 3,
- 'file' => 'dependency_approval.inc',
- );
- $items['textbook_companion/code'] = array(
- 'title' => 'Code Submission',
- 'description' => 'Code Submission',
- 'page callback' => 'list_chapters',
- 'access callback' => 'user_access',
- 'access arguments' => array('upload code'),
- 'file' => 'general.inc',
- );
- $items['textbook_companion/code/list_chapters'] = array(
- 'title' => 'List Chapters',
- 'description' => 'List Chapters',
- 'page callback' => 'list_chapters',
- 'access arguments' => array('upload code'),
- 'type' => MENU_DEFAULT_LOCAL_TASK,
- 'file' => 'general.inc',
- 'weight' => 1,
- );
- $items['textbook_companion/code/upload'] = array(
- 'title' => 'Code Submission',
- 'description' => 'Code Submission',
- 'page callback' => 'upload_examples',
- 'access arguments' => array('upload code'),
- 'type' => MENU_LOCAL_TASK,
- 'file' => 'code.inc',
- 'weight' => 2,
- );
- $items['textbook_companion/code/upload_dep'] = array(
- 'title' => 'Upload Dependency',
- 'description' => 'Upload Dependency Files',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('upload_dependency_form'),
- 'access arguments' => array('upload code'),
- 'type' => MENU_LOCAL_TASK,
- 'file' => 'dependency.inc',
- 'weight' => 3,
- );
- $items['textbook_companion/code/edit_dep'] = array(
- 'title' => 'Edit Dependency',
- 'description' => 'Edit Dependency File',
- 'page callback' => 'edit_dependency',
- 'access arguments' => array('upload code'),
- 'type' => MENU_CALLBACK,
- 'file' => 'dependency.inc',
- );
- $items['textbook_companion/code/delete_dep'] = array(
- 'title' => 'Delete Dependency',
- 'description' => 'Delete Dependency File',
- 'page callback' => 'delete_dependency',
- 'access arguments' => array('upload code'),
- 'type' => MENU_CALLBACK,
- 'file' => 'dependency.inc',
- );
- $items['textbook_companion/code/edit'] = array(
- 'title' => 'Edit Example',
- 'description' => 'Edit Example',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('upload_examples_edit_form'),
- 'access arguments' => array('edit uploaded code'),
- 'type' => MENU_CALLBACK,
- 'file' => 'editcode.inc',
- );
- $items['textbook_companion/code/delete'] = array(
- 'title' => 'Delete Example',
- 'description' => 'Delete Example',
- 'page callback' => '_upload_examples_delete',
- 'access arguments' => array('upload code'),
- 'type' => MENU_CALLBACK,
- 'file' => 'code.inc',
- );
- $items['textbook_companion/code/chapter/edit'] = array(
- 'title' => 'Edit Chapter Title',
- 'description' => 'Edit Chapter Title',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('edit_chapter_title_form'),
- 'access arguments' => array('upload code'),
- 'type' => MENU_CALLBACK,
- 'file' => 'editcode.inc',
- );
- $items['textbook_companion/code/list_examples'] = array(
- 'title' => 'List Examples',
- 'description' => 'List Examples',
- 'page callback' => 'list_examples',
- 'access arguments' => array('upload code'),
- 'type' => MENU_CALLBACK,
- 'file' => 'general.inc',
- 'weight' => 3,
- );
-
- $items['textbook_search'] = array(
- 'title' => 'Book Search',
- 'description' => '',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('textbook_companion_search_form'),
- 'access arguments' => array('access content'),
- 'type' => MENU_NORMAL_ITEM,
- 'file' => 'search.inc',
- );
- $items['textbook_search/search'] = array(
- 'title' => 'Book Search',
- 'description' => '',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('textbook_companion_search_form'),
- 'access arguments' => array('access content'),
- 'type' => MENU_DEFAULT_LOCAL_TASK,
- 'file' => 'search.inc',
- 'weight' => 1,
- );
-
- $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['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(
- 'title' => 'Code Download',
- 'description' => 'Code Download',
- 'page callback' => 'textbook_companion_download_example_file',
- 'access arguments' => array('download code'),
- 'type' => MENU_CALLBACK,
- 'file' => 'download.inc',
- );
- $items['download/samplecode'] = array(
- 'title' => 'Sample Code Download',
- 'description' => 'Sample Code Download',
- 'page callback' => 'textbook_companion_download_sample_code',
- 'access arguments' => array('download code'),
- 'type' => MENU_CALLBACK,
- 'file' => 'download.inc',
- );
- $items['download/dependency'] = array(
- 'title' => 'Code Download',
- 'description' => 'Code Download',
- 'page callback' => 'textbook_companion_download_dependency_file',
- 'access arguments' => array('download code'),
- 'type' => MENU_CALLBACK,
- 'file' => 'download.inc',
- );
- $items['download/example'] = array(
- 'title' => 'Code Download',
- 'description' => 'Code Download',
- 'page callback' => 'textbook_companion_download_example',
- 'access arguments' => array('download code'),
- 'type' => MENU_CALLBACK,
- 'file' => 'download.inc',
- );
- $items['download/chapter'] = array(
- 'title' => 'Code Download',
- 'description' => 'Code Download',
- 'page callback' => 'textbook_companion_download_chapter',
- 'access arguments' => array('download code'),
- 'type' => MENU_CALLBACK,
- 'file' => 'download.inc',
- );
- $items['download/book'] = array(
- 'title' => 'Code Download',
- 'description' => 'Code Download',
- 'page callback' => 'textbook_companion_download_book',
- 'access arguments' => array('download code'),
- 'type' => MENU_CALLBACK,
- 'file' => 'download.inc',
- );
-
- /* reviewer download */
- $items['full_download/chapter'] = array(
- 'title' => 'Code Download',
- 'description' => 'Code Download',
- 'page callback' => 'textbook_companion_download_full_chapter',
- 'access arguments' => array('approve code'),
- 'type' => MENU_CALLBACK,
- 'file' => 'full_download.inc',
- );
- $items['full_download/book'] = array(
- 'title' => 'Code Download',
- 'description' => 'Code Download',
- 'page callback' => 'textbook_companion_download_full_book',
- 'access arguments' => array('approve code'),
- 'type' => MENU_CALLBACK,
- 'file' => 'full_download.inc',
- );
-
- /* external reviewer download */
- $items['full_download_external/chapter'] = array(
- 'title' => 'Code Download',
- 'description' => 'Code Download',
- 'page callback' => 'textbook_companion_download_full_chapter',
- 'access arguments' => array('download books to review'),
- 'type' => MENU_CALLBACK,
- 'file' => 'full_download.inc',
- );
- $items['full_download_external/book'] = array(
- 'title' => 'Code Download',
- 'description' => 'Code Download',
- 'page callback' => 'textbook_companion_download_full_book',
- 'access arguments' => array('download books to review'),
- 'type' => MENU_CALLBACK,
- 'file' => 'full_download.inc',
- );
-
- /* latex script for book generation */
- $items['textbook_companion/generate_book'] = array(
- 'title' => 'Generate Book',
- 'description' => 'Generate Book From Latex Script',
- 'page callback' => 'textbook_companion_download_book',
- 'access arguments' => array('generate book'),
- 'type' => MENU_CALLBACK,
- 'file' => 'latex.inc',
- );
- $items['textbook_companion/delete_book'] = array(
- 'title' => 'Delete Book PDF',
- 'description' => 'Delete Book PDF',
- 'page callback' => 'textbook_companion_delete_book',
- 'access arguments' => array('approve code'),
- 'type' => MENU_CALLBACK,
- 'file' => 'latex.inc',
- );
-
- /* general purpose callbacks */
- $items['textbook_companion/ajax'] = array(
- 'title' => 'Ajax',
- 'description' => 'Ajax',
- 'page callback' => 'textbook_companion_ajax',
- 'access arguments' => array('access content'),
- 'type' => MENU_CALLBACK,
- );
-
- /* for admin */
- $items['admin/settings/book_companion'] = array(
- 'title' => 'Book Companion Settings',
- 'description' => 'Book Companion Settings',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('textbook_companion_settings_form'),
- 'access arguments' => array('administer book companion'),
- 'type' => MENU_NORMAL_ITEM,
- 'file' => 'settings.inc',
- );
- /* for data entry */
- $items['dataentry_book'] = array(
- 'title' => 'Approved books list',
- 'page callback' => '_data_entry_proposal_all',
- 'access callback' => 'user_access',
- 'access arguments' => array('dataentry book proposal'),
- 'file' => 'manage_proposal.inc',
- );
- $items['dataentry_edit'] = array(
- 'title' => 'Edit book details',
- 'page callback' => 'dataentry_edit',
- 'access callback' => 'user_access',
- 'access arguments' => array('dataentry book proposal'),
- 'type' => MENU_NORMAL_ITEM,
- 'file' => 'manage_proposal.inc',
- );
- /*Cheque Details and Contact Form */
- $items['cheque_manage/all'] = array(
- 'title' => 'Cheque Proposals',
- 'description' => 'Cheque Proposals',
- 'page callback' => 'cheque_proposal_all',
- 'access arguments' => array('cheque proposal'),
- 'file' => 'cheque_manage.inc',
- );
- $items['mycontact'] = array(
- 'title' => 'Update Contact Details',
- 'description' => 'Update Contact Details',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('contact_details'),
- 'access arguments' => array('contact_details'),
- 'file' => 'cheque_contact.inc',
- );
-
- $items['cheque_contct'] = array(
- 'title' => 'Report',
- 'description' => 'Cheque Contact Form',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('cheque_contct_form'),
- 'access arguments' => array('cheque contct form'),
- 'file' => 'cheque_contact.inc',
- );
- $items['cheque_contact/status'] = array(
- 'title' => 'Cheque Status',
- 'description' => 'Cheque Status',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('cheque_status_form'),
- 'access' => 'user_is_logged_in',
- 'access arguments' => array('cheque status form'),
- 'file' => 'cheque_contact.inc',
- );
- $items['cheque_contct/report'] = array(
- 'title' => 'Report',
- 'description' => 'Report',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('cheque_report_form'),
- 'access' => 'user_is_logged_in',
- 'access arguments' => array('cheque report form'),
- 'file' => 'cheque_contact.inc',
- );
- $items['certificate'] = array(
- 'title' => 'List Of All Certificates',
- 'description' => 'List Of All Certificates',
- 'page callback' => '_list_all_certificates',
- 'access arguments' => array('list all certificates'),
- 'file' => 'pdf/list_all_certificates.inc',
- );
- $items['certificate/generate_pdf'] = array(
- 'title' => 'Download Certificate',
- 'description' => 'Download Certificate',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('generate_pdf'),
- 'access arguments' => array('generate pdf'),
- 'file' => 'pdf/generate_pdf.inc',
- );
- $items['manage_proposal/paper_submission'] = array(
- 'title' => 'Application Submission',
- 'description' => 'Application Submission',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('paper_submission_form'),
- 'access arguments' => array('paper submission form'),
- 'type' => MENU_CALLBACK,
- 'file' => 'cheque_contact.inc',
- );
- $items["nonaicte_proposal"] = array(
- "title" => "Book Suggestion Form ",
- "description" => "NON-AICTE Book Proposal Form",
- 'page callback' => 'textbook_companion_nonaicte_proposal_all',
- 'access arguments' => array('create book proposal'),
- 'type' => MENU_CALLBACK,
- );
- return $items;
+ $items = array();
+ /* users */
+ $items['proposal'] = array(
+ 'title' => 'Book Proposal Form',
+ 'description' => 'Book Proposal Form.',
+ 'page callback' => 'textbook_companion_proposal_all',
+ 'access callback' => 'user_access',
+ 'access arguments' => array(
+ 'create book proposal'
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'proposal.inc'
+ );
+ $items["aicte_proposal"] = array(
+ "title" => "AICTE Book Proposal",
+ "description" => "AICTE Book Proposal Form",
+ "page callback" => "textbook_companion_aicte_proposal_all",
+ 'access arguments' => array(
+ 'create book proposal'
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'proposal.inc'
+ );
+ $items["nonaicte_proposal"] = array(
+ "title" => "Book Suggestion Form ",
+ "description" => "NON-AICTE Book Proposal Form",
+ 'page callback' => 'textbook_companion_nonaicte_proposal_all',
+ 'access arguments' => array(
+ 'create book proposal'
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'proposal.inc'
+ );
+ $items["all_proposal"] = array(
+ "title" => "Book Proposal",
+ "description" => "Book Proposal Form",
+ "page callback" => "textbook_companion_aicte_proposal_all",
+ 'access arguments' => array(
+ 'create book proposal'
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'proposal.inc'
+ );
+ /* for reviewers */
+ $items['manage_proposal'] = array(
+ 'title' => 'Manage Book Proposals',
+ 'description' => 'Manage Book Proposals',
+ 'page callback' => '_proposal_pending',
+ 'access callback' => 'user_access',
+ 'access arguments' => array(
+ 'approve book proposal'
+ ),
+ 'file' => 'manage_proposal.inc'
+ );
+ $items['manage_proposal/pending'] = array(
+ 'title' => 'Pending Proposals',
+ 'description' => 'Pending Proposals Queue',
+ 'page callback' => '_proposal_pending',
+ 'access callback' => 'user_access',
+ 'access arguments' => array(
+ 'approve book proposal'
+ ),
+ 'type' => MENU_DEFAULT_LOCAL_TASK,
+ 'weight' => 1,
+ 'file' => 'manage_proposal.inc'
+ );
+ $items['manage_proposal/all'] = array(
+ 'title' => 'All Proposals',
+ 'description' => 'All Proposals',
+ 'page callback' => '_proposal_all',
+ 'access callback' => 'user_access',
+ 'access arguments' => array(
+ 'approve book proposal'
+ ),
+ 'type' => MENU_LOCAL_TASK,
+ 'weight' => 2,
+ 'file' => 'manage_proposal.inc'
+ );
+ $items['manage_proposal/category'] = array(
+ 'title' => 'Categorize',
+ 'description' => 'Categorize Books',
+ 'page callback' => '_category_all',
+ 'access callback' => 'user_access',
+ 'access arguments' => array(
+ 'approve book proposal'
+ ),
+ 'type' => MENU_LOCAL_TASK,
+ 'weight' => 2,
+ 'file' => 'manage_proposal.inc'
+ );
+ $items['manage_proposal/failed'] = array(
+ 'title' => 'Failed Proposals',
+ 'description' => 'Failed to submit code',
+ 'page callback' => '_failed_all',
+ 'access callback' => 'user_access',
+ 'access arguments' => array(
+ 'approve book proposal'
+ ),
+ 'type' => MENU_LOCAL_TASK,
+ 'weight' => 3,
+ 'file' => 'manage_proposal.inc'
+ );
+ $items['manage_proposal/approve'] = array(
+ 'title' => 'Proposal Approval',
+ 'description' => 'Proposal Approval',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array(
+ 'proposal_approval_form'
+ ),
+ 'access arguments' => array(
+ 'approve book proposal'
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'manage_proposal.inc'
+ );
+ $items['manage_proposal/status'] = array(
+ 'title' => 'Proposal Status',
+ 'description' => 'Proposal Status',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array(
+ 'proposal_status_form'
+ ),
+ 'access arguments' => array(
+ 'approve book proposal'
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'manage_proposal.inc'
+ );
+ $items['manage_proposal/edit'] = array(
+ 'title' => 'Edit Proposal',
+ 'description' => 'Edit Proposal',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array(
+ 'proposal_edit_form'
+ ),
+ 'access arguments' => array(
+ 'edit book proposal'
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'manage_proposal.inc'
+ );
+ $items['manage_proposal/category/edit'] = array(
+ 'title' => 'Edit Category',
+ 'description' => 'Edit category',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array(
+ 'category_edit_form'
+ ),
+ 'access arguments' => array(
+ 'edit book proposal'
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'manage_proposal.inc'
+ );
+ $items['code_approval'] = array(
+ 'title' => 'Manage Code Approval',
+ 'description' => 'Manage Code Approval',
+ 'page callback' => 'code_approval',
+ 'access arguments' => array(
+ 'approve code'
+ ),
+ 'type' => MENU_NORMAL_ITEM,
+ 'file' => 'code_approval.inc'
+ );
+ $items['code_approval/approve'] = array(
+ 'title' => 'Code Approval',
+ 'description' => 'Code Approval',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array(
+ 'code_approval_form'
+ ),
+ 'access arguments' => array(
+ 'approve code'
+ ),
+ 'type' => MENU_DEFAULT_LOCAL_TASK,
+ 'weight' => 1,
+ 'file' => 'code_approval.inc'
+ );
+ $items['code_approval/bulk'] = array(
+ 'title' => 'Bulk Manage',
+ 'description' => 'Bulk Mangage',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array(
+ 'bulk_approval_form'
+ ),
+ 'access arguments' => array(
+ 'bulk manage code'
+ ),
+ 'type' => MENU_LOCAL_TASK,
+ 'weight' => 2,
+ 'file' => 'code_approval.inc'
+ );
+ $items['code_approval/editcode'] = array(
+ 'title' => 'Admin Edit Example',
+ 'description' => 'Admin Edit Example',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array(
+ 'upload_examples_admin_edit_form'
+ ),
+ 'access arguments' => array(
+ 'approve code'
+ ),
+ 'type' => MENU_CALLBACK,
+ 'weight' => 3,
+ 'file' => 'editcodeadmin.inc'
+ );
+ $items['code_approval/notes'] = array(
+ 'title' => 'Notes for Reviewers',
+ 'description' => 'Notes for Reviewers',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array(
+ 'book_notes_form'
+ ),
+ 'access arguments' => array(
+ 'bulk manage code'
+ ),
+ 'type' => MENU_CALLBACK,
+ 'weight' => 4,
+ 'file' => 'notes.inc'
+ );
+ $items['code_approval/dependency'] = array(
+ 'title' => 'Dependency',
+ 'description' => 'Dependency',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array(
+ 'textbook_companion_dependency_approval_form'
+ ),
+ 'access arguments' => array(
+ 'bulk manage code'
+ ),
+ 'type' => MENU_LOCAL_TASK,
+ 'weight' => 3,
+ 'file' => 'dependency_approval.inc'
+ );
+ $items['textbook_companion/code'] = array(
+ 'title' => 'Code Submission',
+ 'description' => 'Code Submission',
+ 'page callback' => 'list_chapters',
+ 'access callback' => 'user_access',
+ 'access arguments' => array(
+ 'upload code'
+ ),
+ 'file' => 'general.inc'
+ );
+ $items['textbook_companion/code/list_chapters'] = array(
+ 'title' => 'List Chapters',
+ 'description' => 'List Chapters',
+ 'page callback' => 'list_chapters',
+ 'access arguments' => array(
+ 'upload code'
+ ),
+ 'type' => MENU_DEFAULT_LOCAL_TASK,
+ 'file' => 'general.inc',
+ 'weight' => 1
+ );
+ $items['textbook_companion/code/upload'] = array(
+ 'title' => 'Code Submission',
+ 'description' => 'Code Submission',
+ 'page callback' => 'upload_examples',
+ 'access arguments' => array(
+ 'upload code'
+ ),
+ 'type' => MENU_LOCAL_TASK,
+ 'file' => 'code.inc',
+ 'weight' => 2
+ );
+ $items['textbook_companion/code/upload_dep'] = array(
+ 'title' => 'Upload Dependency',
+ 'description' => 'Upload Dependency Files',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array(
+ 'upload_dependency_form'
+ ),
+ 'access arguments' => array(
+ 'upload code'
+ ),
+ 'type' => MENU_LOCAL_TASK,
+ 'file' => 'dependency.inc',
+ 'weight' => 3
+ );
+ $items['textbook_companion/code/edit_dep'] = array(
+ 'title' => 'Edit Dependency',
+ 'description' => 'Edit Dependency File',
+ 'page callback' => 'edit_dependency',
+ 'access arguments' => array(
+ 'upload code'
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'dependency.inc'
+ );
+ $items['textbook_companion/code/delete_dep'] = array(
+ 'title' => 'Delete Dependency',
+ 'description' => 'Delete Dependency File',
+ 'page callback' => 'delete_dependency',
+ 'access arguments' => array(
+ 'upload code'
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'dependency.inc'
+ );
+ $items['textbook_companion/code/edit'] = array(
+ 'title' => 'Edit Example',
+ 'description' => 'Edit Example',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array(
+ 'upload_examples_edit_form'
+ ),
+ 'access arguments' => array(
+ 'edit uploaded code'
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'editcode.inc'
+ );
+ $items['textbook_companion/code/delete'] = array(
+ 'title' => 'Delete Example',
+ 'description' => 'Delete Example',
+ 'page callback' => '_upload_examples_delete',
+ 'access arguments' => array(
+ 'upload code'
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'code.inc'
+ );
+ $items['textbook_companion/code/chapter/edit'] = array(
+ 'title' => 'Edit Chapter Title',
+ 'description' => 'Edit Chapter Title',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array(
+ 'edit_chapter_title_form'
+ ),
+ 'access arguments' => array(
+ 'upload code'
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'editcode.inc'
+ );
+ $items['textbook_companion/code/list_examples'] = array(
+ 'title' => 'List Examples',
+ 'description' => 'List Examples',
+ 'page callback' => 'list_examples',
+ 'access arguments' => array(
+ 'upload code'
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'general.inc',
+ 'weight' => 3
+ );
+ $items['textbook_search'] = array(
+ 'title' => 'Book Search',
+ 'description' => '',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array(
+ 'textbook_companion_search_form'
+ ),
+ 'access arguments' => array(
+ 'access content'
+ ),
+ 'type' => MENU_NORMAL_ITEM,
+ 'file' => 'search.inc'
+ );
+ $items['textbook_search/search'] = array(
+ 'title' => 'Book Search',
+ 'description' => '',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array(
+ 'textbook_companion_search_form'
+ ),
+ 'access arguments' => array(
+ 'access content'
+ ),
+ 'type' => MENU_DEFAULT_LOCAL_TASK,
+ 'file' => 'search.inc',
+ 'weight' => 1
+ );
+ $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['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(
+ 'title' => 'Code Download',
+ 'description' => 'Code Download',
+ 'page callback' => 'textbook_companion_download_example_file',
+ 'access arguments' => array(
+ 'download code'
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'download.inc'
+ );
+ $items['download/samplecode'] = array(
+ 'title' => 'Sample Code Download',
+ 'description' => 'Sample Code Download',
+ 'page callback' => 'textbook_companion_download_sample_code',
+ 'access arguments' => array(
+ 'download code'
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'download.inc'
+ );
+ $items['download/dependency'] = array(
+ 'title' => 'Code Download',
+ 'description' => 'Code Download',
+ 'page callback' => 'textbook_companion_download_dependency_file',
+ 'access arguments' => array(
+ 'download code'
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'download.inc'
+ );
+ $items['download/example'] = array(
+ 'title' => 'Code Download',
+ 'description' => 'Code Download',
+ 'page callback' => 'textbook_companion_download_example',
+ 'access arguments' => array(
+ 'download code'
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'download.inc'
+ );
+ $items['download/chapter'] = array(
+ 'title' => 'Code Download',
+ 'description' => 'Code Download',
+ 'page callback' => 'textbook_companion_download_chapter',
+ 'access arguments' => array(
+ 'download code'
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'download.inc'
+ );
+ $items['download/book'] = array(
+ 'title' => 'Code Download',
+ 'description' => 'Code Download',
+ 'page callback' => 'textbook_companion_download_book',
+ 'access arguments' => array(
+ 'download code'
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'download.inc'
+ );
+ /* reviewer download */
+ $items['full_download/chapter'] = array(
+ 'title' => 'Code Download',
+ 'description' => 'Code Download',
+ 'page callback' => 'textbook_companion_download_full_chapter',
+ 'access arguments' => array(
+ 'approve code'
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'full_download.inc'
+ );
+ $items['full_download/book'] = array(
+ 'title' => 'Code Download',
+ 'description' => 'Code Download',
+ 'page callback' => 'textbook_companion_download_full_book',
+ 'access arguments' => array(
+ 'approve code'
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'full_download.inc'
+ );
+ /* external reviewer download */
+ $items['full_download_external/chapter'] = array(
+ 'title' => 'Code Download',
+ 'description' => 'Code Download',
+ 'page callback' => 'textbook_companion_download_full_chapter',
+ 'access arguments' => array(
+ 'download books to review'
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'full_download.inc'
+ );
+ $items['full_download_external/book'] = array(
+ 'title' => 'Code Download',
+ 'description' => 'Code Download',
+ 'page callback' => 'textbook_companion_download_full_book',
+ 'access arguments' => array(
+ 'download books to review'
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'full_download.inc'
+ );
+ /* latex script for book generation */
+ $items['textbook_companion/generate_book'] = array(
+ 'title' => 'Generate Book',
+ 'description' => 'Generate Book From Latex Script',
+ 'page callback' => 'textbook_companion_download_book',
+ 'access arguments' => array(
+ 'generate book'
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'latex.inc'
+ );
+ $items['textbook_companion/delete_book'] = array(
+ 'title' => 'Delete Book PDF',
+ 'description' => 'Delete Book PDF',
+ 'page callback' => 'textbook_companion_delete_book',
+ 'access arguments' => array(
+ 'approve code'
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'latex.inc'
+ );
+ /* general purpose callbacks */
+ $items['textbook_companion/ajax'] = array(
+ 'title' => 'Ajax',
+ 'description' => 'Ajax',
+ 'page callback' => 'textbook_companion_ajax',
+ 'access arguments' => array(
+ 'access content'
+ ),
+ 'type' => MENU_CALLBACK
+ );
+ /* for admin */
+ $items['admin/settings/book_companion'] = array(
+ 'title' => 'Book Companion Settings',
+ 'description' => 'Book Companion Settings',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array(
+ 'textbook_companion_settings_form'
+ ),
+ 'access arguments' => array(
+ 'administer book companion'
+ ),
+ 'type' => MENU_NORMAL_ITEM,
+ 'file' => 'settings.inc'
+ );
+ /* for data entry */
+ $items['dataentry_book'] = array(
+ 'title' => 'Approved books list',
+ 'page callback' => '_data_entry_proposal_all',
+ 'access callback' => 'user_access',
+ 'access arguments' => array(
+ 'dataentry book proposal'
+ ),
+ 'file' => 'manage_proposal.inc'
+ );
+ $items['dataentry_edit'] = array(
+ 'title' => 'Edit book details',
+ 'page callback' => 'dataentry_edit',
+ 'access callback' => 'user_access',
+ 'access arguments' => array(
+ 'dataentry book proposal'
+ ),
+ 'type' => MENU_NORMAL_ITEM,
+ 'file' => 'manage_proposal.inc'
+ );
+ /*Cheque Details and Contact Form */
+ $items['cheque_manage/all'] = array(
+ 'title' => 'Cheque Proposals',
+ 'description' => 'Cheque Proposals',
+ 'page callback' => 'cheque_proposal_all',
+ 'access arguments' => array(
+ 'cheque proposal'
+ ),
+ 'file' => 'cheque_manage.inc'
+ );
+ $items['mycontact'] = array(
+ 'title' => 'Update Contact Details',
+ 'description' => 'Update Contact Details',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array(
+ 'contact_details'
+ ),
+ 'access arguments' => array(
+ 'contact_details'
+ ),
+ 'file' => 'cheque_contact.inc'
+ );
+ $items['cheque_contct'] = array(
+ 'title' => 'Report',
+ 'description' => 'Cheque Contact Form',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array(
+ 'cheque_contct_form'
+ ),
+ 'access arguments' => array(
+ 'cheque contct form'
+ ),
+ 'file' => 'cheque_contact.inc'
+ );
+ $items['cheque_contact/status'] = array(
+ 'title' => 'Cheque Status',
+ 'description' => 'Cheque Status',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array(
+ 'cheque_status_form'
+ ),
+ 'access' => 'user_is_logged_in',
+ 'access arguments' => array(
+ 'cheque status form'
+ ),
+ 'file' => 'cheque_contact.inc'
+ );
+ $items['cheque_contct/report'] = array(
+ 'title' => 'Report',
+ 'description' => 'Report',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array(
+ 'cheque_report_form'
+ ),
+ 'access' => 'user_is_logged_in',
+ 'access arguments' => array(
+ 'cheque report form'
+ ),
+ 'file' => 'cheque_contact.inc'
+ );
+ $items['certificate'] = array(
+ 'title' => 'List Of All Certificates',
+ 'description' => 'List Of All Certificates',
+ 'page callback' => '_list_all_certificates',
+ 'access arguments' => array(
+ 'list all certificates'
+ ),
+ 'file' => 'pdf/list_all_certificates.inc'
+ );
+ $items['certificate/generate_pdf'] = array(
+ 'title' => 'Download Certificate',
+ 'description' => 'Download Certificate',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array(
+ 'generate_pdf'
+ ),
+ 'access arguments' => array(
+ 'generate pdf'
+ ),
+ 'file' => 'pdf/generate_pdf.inc'
+ );
+ /*******************/
+ $items['Summer_Internship_Forms/copyright-form'] = array(
+ 'title' => 'List Of All Copyright Forms for Completed books',
+ 'description' => 'List Of All Copyright Forms for Completed books',
+ 'page callback' => '_list_all_copyright_forms',
+ 'access arguments' => array(
+ 'list all certificates'
+ ),
+ 'file' => 'pdf/list_all_form_pdf.inc'
+ );
+ $items['Summer_Internship_Forms/copyright-form/generate_pdf'] = array(
+ 'title' => 'Download Copyright Forms for Completed books',
+ 'description' => 'Download Copyright Forms for Completed books',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array(
+ 'generate_form_pdf'
+ ),
+ 'access arguments' => array(
+ 'generate pdf'
+ ),
+ 'file' => 'pdf/generate_pdf.inc'
+ );
+ /*******************/
+ $items['manage_proposal/paper_submission'] = array(
+ 'title' => 'Application Submission',
+ 'description' => 'Application Submission',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array(
+ 'paper_submission_form'
+ ),
+ 'access arguments' => array(
+ 'paper submission form'
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'cheque_contact.inc'
+ );
+ return $items;
}
-
/**
* Implementation of hook_permission().
*/
-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,&$form_state) {
- /*********** fetch aicte book data ********************/
- $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(
- "#type" => "fieldset",
- "#prefix" => "<div id='aicte-form-wrapper'>",
- "#suffix" => "</div>",
- );
-
- $num_rows = $result->rowCount();
- if ($num_rows > 0) {
- while($row = $result->fetchObject()) {
- /* fixing title string */
- $title = "";
- $edition = "";
- $year = "";
- $title = "{$row->book} by {$row->author}";
- if($row->edition) {
- $edition = "<i>ed</i>: {$row->edition}";
- }
- if($row->year) {
- if($row->edition) {
- $year = ", <i>pub</i>: {$row->year}";
- } else {
- $year = "<i>pub</i>: {$row->year}";
- }
- }
- if($edition or $year) {
- $title .= "({$edition} {$year})";
- }
- $form["wrapper"][$row->id] = array(
- "#type" => "checkbox",
- "#title" => $title,
- "#prefix" => "<div class='title'>",
- "#suffix" => "</div>",
- );
- }
- }
- $form["submit"] = array(
- "#type" => "submit",
- "#value" => "Submit Book Selections"
- );
- return $form;
-}
-
-function textbook_companion_aicte_proposal_form_validate($form, &$form_state) {
-
-
- $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 = $result->fetchObject()) {
- if($form_state["values"][$row->id] == 1) {
- $count++;
- array_push($selections, $row->id);
- }
- }
- /* user can choose only 3 books to propose */
- if($count != 3) {
- form_set_error("", "Please select exactly <strong>3</strong> books. You currently selected <strong>{$count}</strong>");
- } else {
- $form_state["values"]["selections"] = $selections;
- }
-}
-
-/* AICTE Book list proposal form submit */
-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");
-}
-
-/************* AICTE book report form **************/
-function textbook_companion_aicte_report_form($from, $form_state) {
-
- $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 = $result->fetchObject()) {
- $books[$row->id] = "{$row->book} ({$row->author})";
- }
- $form = array();
- $form["name"] = array(
- "#type" => "textfield",
- "#title" => "Name",
- "#description" => t("Please enter your name."),
- );
- $form["email"] = array(
- "#type" => "textfield",
- "#title" => "Email",
- "#description" => t("Please enter your valid email id."),
- );
- $form["number"] = array(
- "#type" => "textfield",
- "#title" => "Number",
- "#description" => t("Please enter your valid phone number."),
- );
- $form["book"] = array(
- "#type" => "select",
- "#title" => "AICTE Book",
- "#description" => t("Please select a book."),
- "#options" => $books
- );
- $form["comment"] = array(
- "#type" => "textarea",
- "#title" => "Any other comment?",
- "#description" => t("Please enter your query (if any)")
- );
- $form["submit"] = array(
- "#type" => "submit",
- "#value" => "Submit"
- );
- return $form;
-}
-/************* AICTE book report form submit **************/
-function textbook_companion_aicte_report_form_submit($form, &$form_state) {
- $v = $form_state["values"];
-
- $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");
-}
-/************* AICTE book list selection **************/
-function textbook_companion_aicte_proposal_all() {
- global $user;
-$page_content = "";
-
-
- if (!$user->uid) {
-
- $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>";
- $page_content .= "<li>Please <a href='/user'><b><u>Login</u></b></a> to create a proposal.</li>";
- //$page_content .= "<li>Unable to propose particular book: <a id='aicte-report' href='#'>Click here</a></li>";
- //$page_content .= "<li>Do not wish to propose any of the below books: <a id='aicte-report' href='http://fossee.in/feedback/scilab-aicte' target = _blank>Click here</a></li>";
- $page_content .= "</ul>";
- $page_content .= "Search : <input type='text' id='searchtext' onkeyup='searchbookFunction()' style='width:82%'/>";
- $page_content .= "<input type='button' value ='clear' id='search_clear'/>";
- $page_content .= "<div id='aicte-list-wrapper'>";
- $num_rows = $result->rowCount();
- if ($num_rows > 0) {
- $i = 1;
- while($row = $result->fetchObject()) {
- /* fixing title string */
- $title = "";
- $edition = "";
- $year = "";
- $title = "{$row->book} by {$row->author}";
- if($row->edition) {
- $edition = "<i>ed</i>: {$row->edition}";
- }
- if($row->year) {
- if($row->edition) {
- $year = ", <i>pub</i>: {$row->year}";
- } else {
- $year = "<i>pub</i>: {$row->year}";
- }
- }
- if($edition or $year) {
- $title .= "({$edition} {$year})";
- }
- $page_content .= "<div class='title'>{$i}) {$title}</div>";
- $i++;
- }
- }
- $page_content .= "</div>";
- /* adding aicte report form */
- //$page_content .= drupal_get_form("textbook_companion_aicte_report_form");
- return $page_content;
- }
-
- /* check if user has already submitted a proposal */
-
- $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 = $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');
- drupal_goto('');
- return;
- break;
- case 1:
- drupal_set_message(t('Your proposal has been approved. Please go to ' . l('Code Submission', 'textbook_companion/code') . ' to upload your code'), 'status');
- drupal_goto('');
- return;
- break;
- case 2:
- drupal_set_message(t('Your proposal has been dis-approved. Please create another proposal below.'), 'error');
- break;
- case 3:
- drupal_set_message(t('Congratulations! You have completed your last book proposal. You can create another proposal below.'), 'status');
- break;
- default:
- drupal_set_message(t('Invalid proposal state. Please contact site administrator for further information.'), 'error');
- drupal_goto('');
- return;
- break;
- }
- }
- }
-
- variable_del("aicte_".$user->uid);
- $page_content .= "<h5><b>* Please select any 3 books from the below list.</b></h5></br>";
- //$page_content .= "Unable to propose particular book: <a id='aicte-report' href='#'>Click here</a></br></br>";
- //$page_content .= "Do not wish to propose any of the below books: <a id='aicte-report' href='http://fossee.in/feedback/scilab-aicte' target = _blank>Click here</a></br></br>";
- $page_content .= "Search : <input type='text' id='searchtext' style='width:82%'/>";
- $page_content .= "<input type='button' value ='clear' id='search_clear'/>";
- $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 *******************/
-function textbook_companion_nonaicte_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;
- }
-
- /* 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);*/
-
- $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 = $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');
- drupal_goto('');
- return;
- break;
- case 1:
- drupal_set_message(t('Your proposal has been approved. Please go to ' . l('Code Submission', 'textbook_companion/code') . ' to upload your code'), 'status');
- drupal_goto('');
- return;
- break;
- case 2:
- drupal_set_message(t('Your proposal has been dis-approved. Please create another proposal below.'), 'error');
- break;
- case 3:
- drupal_set_message(t('Congratulations! You have completed your last book proposal. You can create another proposal below.'), 'status');
- break;
- default:
- drupal_set_message(t('Invalid proposal state. Please contact site administrator for further information.'), 'error');
- drupal_goto('');
- return;
- break;
- }
- }
- }
-
- //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;
-}
-
-/* Textbook Companion Proposal */
-function textbook_companion_proposal_all() {
- global $user;
- $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 **************/
-
-
-
- $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 =$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');
- drupal_goto('');
- return;
- break;
- case 1:
- drupal_set_message(t('Your proposal has been approved. Please go to ' . l('Code Submission', 'textbook_companion/code') . ' to upload your code'), 'status');
- drupal_goto('');
- return;
- break;
- case 2:
- drupal_set_message(t('Your proposal has been dis-approved. Please create another proposal below.'), 'error');
- break;
- case 3:
- drupal_set_message(t('Congratulations! You have completed your last book proposal. You can create another proposal below.'), 'status');
- break;
- default:
- drupal_set_message(t('Invalid proposal state. Please contact site administrator for further information.'), 'error');
- drupal_goto('');
- return;
- break;
- }
- }
- }
-
- $selections = variable_get("aicte_".$user->uid, "");
- if($selections) {
-
- $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 {
- // $book_proposal_form = drupal_get_form("book_proposal_form");
- // $page_content .= drupal_render($book_proposal_form);
- drupal_goto("aicte_proposal");
- }
-
- return $page_content;
+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.")
+ )
+ );
}
-function book_proposal_form($form,&$form_state, $row1=NULL, $row2=NULL, $row3=NULL)
+function del_book_pdf($book_id)
{
- global $user;
- $form = array();
- $form['imp_notice'] = array(
- '#type' => 'item',
- '#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(
- '#type' => 'textfield',
- '#title' => t('Full Name'),
- '#size' => 30,
- '#maxlength' => 50,
- '#required' => TRUE,
- );
- $form['email_id'] = array(
- '#type' => 'textfield',
- '#title' => t('Email'),
- '#size' => 30,
- '#value' => $user->mail,
- '#disabled' => TRUE,
- );
- $form['mobile'] = array(
- '#type' => 'textfield',
- '#title' => t('Mobile No.'),
- '#size' => 30,
- '#maxlength' => 15,
- '#required' => TRUE,
- );
- $form['gender'] = array(
- '#type' => 'radios',
- '#title' => t('Gender'),
- '#options' => array('M' => 'Male', 'F' => 'Female'),
- '#required' => TRUE,
- );
-
- /*$form['how_project'] = array(
- '#type' => 'select',
- '#title' => t('How did you come to know about this project'),
- '#options' => array('Scilab Website' => 'Scilab Website',
- 'Friend' => 'Friend',
- 'Professor/Teacher' => 'Professor/Teacher',
- 'Mailing List' => 'Mailing List',
- 'Poster in my/other college' => 'Poster in my/other college',
- 'Others' => 'Others'),
- '#required' => TRUE,
- );*/
- $form['course'] = array(
- '#type' => 'textfield',
- '#title' => t('Course'),
- '#size' => 30,
- '#maxlength' => 50,
- '#required' => TRUE,
- );
- $form['branch'] = array(
- '#type' => 'select',
- '#title' => t('Department/Branch'),
- '#options' => _tbc_list_of_departments(),
- '#required' => TRUE,
- );
- $form['university'] = array(
- '#type' => 'textfield',
- '#title' => t('University/Institute'),
- '#size' => 30,
- '#maxlength' => 50,
- '#required' => TRUE,
- );
- $form['country'] = array(
- '#type' => 'select',
- '#title' => t('Country'),
- '#options' => array(
- 'India' => 'India',
- 'Others' => 'Others',
- ),
- '#required' => TRUE,
- '#tree' => TRUE,
- '#validated' => TRUE,
- );
- $form['other_country'] = array(
- '#type' => 'textfield',
- '#title' => t('Other than India'),
- '#size' => 100,
- '#attributes' =>array('placeholder' => t('Enter your country name')),
- '#states' => array(
- 'visible' => array(
- ':input[name="country"]' => array('value' => 'Others'),
- ),
- ),
- );
- $form['other_state'] = array(
- '#type' => 'textfield',
- '#title' => t('State other than India'),
- '#size' => 100,
- '#attributes' =>array('placeholder' => t('Enter your state/region name')),
- '#states' => array(
- 'visible' => array(
- ':input[name="country"]' => array('value' => 'Others'),
- ),
- ),
- );
- $form['other_city'] = array(
- '#type' => 'textfield',
- '#title' => t('City other than India'),
- '#size' => 100,
- '#attributes' =>array('placeholder' => t('Enter your city name')),
- '#states' => array(
- 'visible' => array(
- ':input[name="country"]' => array('value' => 'Others'),
- ),
- ),
- );
- $form['all_state'] = array(
- '#type' => 'select',
- '#title' => t('State'),
- '#options' => _tbc_list_of_states(),
- '#validated' => TRUE,
- '#states' => array(
- 'visible' => array(
- ':input[name="country"]' => array('value' => 'India'),
- ),
- ),
- );
- $form['city'] = array(
- '#type' => 'select',
- '#title' => t('City'),
- '#options' => _tbc_list_of_cities(),
- '#states' => array(
- 'visible' => array(
- ':input[name="country"]' => array('value' => 'India'),
- ),
- ),
- );
- $form['pincode'] = array(
- '#type' => 'textfield',
- '#title' => t('Pincode'),
- '#size' => 30,
- '#maxlength' => 6,
- '#required' => False,
- '#attributes' =>array('placeholder' =>'Enter pincode....'),
- );
- $form['faculty'] = array(
- '#type' => 'hidden',
- '#value' => 'None',
- '#title' => t('College Teacher/Professor'),
- '#size' => 30,
- '#maxlength' => 50,
- '#required' => TRUE,
- );
- $form['faculty_email'] = array(
- '#type' => 'hidden',
- '#value' => 'None',
- '#title' => t('Teacher/Professor Email Id'),
- '#default_value' => '@email.com',
- '#size' => 30,
- '#maxlength' => 50,
- );
- $form['reviewer'] = array(
- '#type' => 'hidden',
- '#value' => 'None',
- '#title' => t('Reviewer'),
- '#size' => 30,
- '#maxlength' => 50,
- );
-
- $form['completion_date'] = array(
- '#type' => 'textfield',
- '#title' => t('Expected Date of Completion'),
- '#description' => t('Input date format should be DD-MM-YYYY. Eg: 23-03-2011'),
- '#size' => 10,
- '#maxlength' => 10,
- );
- $form['operating_system'] = array(
- '#type' => 'textfield',
- '#title' => t('Operating System'),
- '#required' => TRUE,
- '#size' => 30,
- '#maxlength' => 50,
- );
- $form['version'] = array(
- '#type' => 'textfield',
- '#title' => t('Scilab Version'),
- '#description' => t('Input version format should be like 5.4 or 5.4.1'),
- '#size' => 10,
- '#required' => TRUE,
- '#maxlength' => 20,
- );
- $form['preference1'] = array(
- '#type' => 'fieldset',
- '#title' => t('Book Preference 1'),
- '#collapsible' => TRUE,
- '#collapsed' => FALSE,
- );
- $form['preference1']['book1'] = array(
- '#type' => 'textfield',
- '#title' => t('Title of the book'),
- '#size' => 30,
- '#maxlength' => 100,
- '#required' => TRUE,
- '#default_value' => $row1->book,
- '#disabled' => ($row1->book?TRUE:FALSE),
- );
- $form['preference1']['author1'] = array(
- '#type' => 'textfield',
- '#title' => t('Author Name'),
- '#size' => 30,
- '#maxlength' => 100,
- '#required' => TRUE,
- '#default_value' => $row1->author,
- '#disabled' => ($row1->author?TRUE:FALSE),
- );
- $form['preference1']['isbn1'] = array(
- '#type' => 'textfield',
- '#title' => t('ISBN No'),
- '#size' => 30,
- '#maxlength' => 25,
- '#required' => TRUE,
- '#default_value' => $row1->isbn,
- '#disabled' => ($row1->isbn?TRUE:FALSE),
- );
- $form['preference1']['publisher1'] = array(
- '#type' => 'textfield',
- '#title' => t('Publisher & Place'),
- '#size' => 30,
- '#maxlength' => 50,
- '#required' => TRUE,
- '#default_value' => $row1->publisher,
- );
- $form['preference1']['edition1'] = array(
- '#type' => 'textfield',
- '#title' => t('Edition'),
- '#size' => 4,
- '#maxlength' => 2,
- '#required' => TRUE,
- '#default_value' => $row1->edition,
- );
- $form['preference1']['year1'] = array(
- '#type' => 'textfield',
- '#title' => t('Year of pulication'),
- '#size' => 4,
- '#maxlength' => 4,
- '#required' => TRUE,
- '#default_value' => $row1->year,
- );
- $form['preference1']['book_category_1'] = array(
- '#type' => 'select',
- '#title' => t('Category'),
- '#options' => _tbc_list_of_category(),
- '#required' => TRUE,
- );
- $form['preference2'] = array(
- '#type' => 'fieldset',
- '#title' => t('Book Preference 2'),
- '#collapsible' => TRUE,
- '#collapsed' => FALSE,
- );
- $form['preference2']['book2'] = array(
- '#type' => 'textfield',
- '#title' => t('Title of the book'),
- '#size' => 30,
- '#maxlength' => 100,
- '#required' => TRUE,
- '#default_value' => $row2->book,
- '#disabled' => ($row2->book?TRUE:FALSE),
- );
- $form['preference2']['author2'] = array(
- '#type' => 'textfield',
- '#title' => t('Author Name'),
- '#size' => 30,
- '#maxlength' => 100,
- '#required' => TRUE,
- '#default_value' => $row2->author,
- '#disabled' => ($row2->author?TRUE:FALSE),
- );
- $form['preference2']['isbn2'] = array(
- '#type' => 'textfield',
- '#title' => t('ISBN No'),
- '#size' => 30,
- '#maxlength' => 25,
- '#required' => TRUE,
- '#default_value' => $row2->isbn,
- '#disabled' => ($row2->isbn?TRUE:FALSE),
- );
- $form['preference2']['publisher2'] = array(
- '#type' => 'textfield',
- '#title' => t('Publisher & Place'),
- '#size' => 30,
- '#maxlength' => 50,
- '#required' => TRUE,
- '#default_value' => $row2->publisher,
- );
- $form['preference2']['edition2'] = array(
- '#type' => 'textfield',
- '#title' => t('Edition'),
- '#size' => 4,
- '#maxlength' => 2,
- '#required' => TRUE,
- '#default_value' => $row2->edition,
- );
- $form['preference2']['year2'] = array(
- '#type' => 'textfield',
- '#title' => t('Year of pulication'),
- '#size' => 4,
- '#maxlength' => 4,
- '#required' => TRUE,
- '#default_value' => $row2->year,
- );
- $form['preference2']['book_category_2'] = array(
- '#type' => 'select',
- '#title' => t('Category'),
- '#options' => _tbc_list_of_category(),
- '#required' => TRUE,
- );
- $form['preference3'] = array(
- '#type' => 'fieldset',
- '#title' => t('Book Preference 3'),
- '#collapsible' => TRUE,
- '#collapsed' => FALSE,
- );
- $form['preference3']['book3'] = array(
- '#type' => 'textfield',
- '#title' => t('Title of the book'),
- '#size' => 30,
- '#maxlength' => 100,
- '#required' => TRUE,
- '#default_value' => $row3->book,
- '#disabled' => ($row3->book?TRUE:FALSE),
- );
- $form['preference3']['author3'] = array(
- '#type' => 'textfield',
- '#title' => t('Author Name'),
- '#size' => 30,
- '#maxlength' => 100,
- '#required' => TRUE,
- '#default_value' => $row3->author,
- '#disabled' => ($row3->author?TRUE:FALSE),
- );
- $form['preference3']['isbn3'] = array(
- '#type' => 'textfield',
- '#title' => t('ISBN No'),
- '#size' => 30,
- '#maxlength' => 25,
- '#required' => TRUE,
- '#default_value' => $row3->isbn,
- '#disabled' => ($row3->isbn?TRUE:FALSE),
- );
- $form['preference3']['publisher3'] = array(
- '#type' => 'textfield',
- '#title' => t('Publisher & Place'),
- '#size' => 30,
- '#maxlength' => 50,
- '#required' => TRUE,
- '#default_value' => $row3->publisher,
- );
- $form['preference3']['edition3'] = array(
- '#type' => 'textfield',
- '#title' => t('Edition'),
- '#size' => 4,
- '#maxlength' => 2,
- '#required' => TRUE,
- '#default_value' => $row3->edition,
- );
- $form['preference3']['year3'] = array(
- '#type' => 'textfield',
- '#title' => t('Year of pulication'),
- '#size' => 4,
- '#maxlength' => 4,
- '#required' => TRUE,
- '#default_value' => $row3->year,
- );
- $form['preference3']['book_category_3'] = array(
- '#type' => 'select',
- '#title' => t('Category'),
- '#options' => _tbc_list_of_category(),
- '#required' => TRUE,
- );
- $form['samplefile'] = array(
- '#type' => 'fieldset',
- '#title' => t('<span class="form-required form-item" title="This field is required.">Sample Source Files *</span>'),
- '#collapsible' => FALSE,
- '#collapsed' => FALSE,
- );
- $form['samplefile']['samplefile1'] = array(
- '#type' => 'file',
- '#title' => t('Upload sample source file'),
- '#size' => 48,
- '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' .
- t('<span style="color:red;">Allowed file extensions : ') . variable_get('textbook_companion_sample_source_file_extensions', '').'</span>',
-
- );
- $form['termconditions'] = array(
- '#type' => 'checkboxes',
- '#title' => t('Terms And Conditions'),
- '#options' => array(
- 'status' => t('<a href="/term-and-conditions" target="_blank">I agree to the Terms and Conditions</a>'),),
- '#required' => TRUE,
- );
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Submit')
- );
-
- return $form;
+ $root_path = textbook_companion_path();
+ $dir_path = $root_path . "latex/";
+ $pdf_filename = "book_" . $book_id . ".pdf";
+ if (file_exists($dir_path . $pdf_filename))
+ unlink($dir_path . $pdf_filename);
}
-/******************** AICTE book proposal from validate *****************************/
-function book_proposal_form_validate($form,&$form_state)
+function _tbc_list_of_states()
{
-
- /* mobile */
- if (!preg_match('/^[0-9\ \+]{0,15}$/', $form_state['values']['mobile']))
- form_set_error('mobile', t('Invalid mobile number'));
-
- /* date of completion */
- if (!preg_match('/^[0-9]{1,2}-[0-9]{1,2}-[0-9]{4}$/', $form_state['values']['completion_date']))
- form_set_error('completion_date', t('Invalid expected date of completion'));
-
- list($d, $m, $y) = explode('-', $form_state['values']['completion_date']);
- $d = (int)$d; $m = (int)$m; $y = (int)$y;
- if (!checkdate($m, $d, $y))
- form_set_error('completion_date', t('Invalid expected date of completion'));
- if (mktime(0, 0, 0, $m, $d, $y) <= time())
- form_set_error('completion_date', t('Expected date of completion should be in future'));
-
- /* edition */
- if (!preg_match('/^[1-9][0-9]{0,1}$/', $form_state['values']['edition1']))
- form_set_error('edition1', t('Invalid edition for Book Preference 1'));
- if (!preg_match('/^[1-9][0-9]{0,1}$/', $form_state['values']['edition2']))
- form_set_error('edition2', t('Invalid edition for Book Preference 2'));
- if (!preg_match('/^[1-9][0-9]{0,1}$/', $form_state['values']['edition3']))
- form_set_error('edition3', t('Invalid edition for Book Preference 3'));
-
- /* year of publication */
- if (!preg_match('/^[1-3][0-9][0-9][0-9]$/', $form_state['values']['year1']))
- form_set_error('year1', t('Invalid year of pulication for Book Preference 1'));
- if (!preg_match('/^[1-3][0-9][0-9][0-9]$/', $form_state['values']['year2']))
- form_set_error('year2', t('Invalid year of pulication for Book Preference 2'));
- if (!preg_match('/^[1-3][0-9][0-9][0-9]$/', $form_state['values']['year3']))
- form_set_error('year3', t('Invalid year of pulication for Book Preference 3'));
-
- /* year of publication */
- $cur_year = date('Y');
- if ((int)$form_state['values']['year1'] > $cur_year)
- form_set_error('year1', t('Year of pulication should be not in the future for Book Preference 1'));
- if ((int)$form_state['values']['year2'] > $cur_year)
- form_set_error('year2', t('Year of pulication should be not in the future for Book Preference 2'));
- if ((int)$form_state['values']['year3'] > $cur_year)
- form_set_error('year3', t('Year of pulication should be not in the future for Book Preference 3'));
-
- /* isbn */
- if (!preg_match('/^[0-9\-xX]+$/', $form_state['values']['isbn1']))
- form_set_error('isbn1', t('Invalid ISBN for Book Preference 1'));
- if (!preg_match('/^[0-9\-xX]+$/', $form_state['values']['isbn2']))
- form_set_error('isbn2', t('Invalid ISBN for Book Preference 2'));
- if (!preg_match('/^[0-9\-xX]+$/', $form_state['values']['isbn3']))
- form_set_error('isbn3', t('Invalid ISBN for Book Preference 3'));
-/* version */
- if (!preg_match('/^\d+(?:\.\d+)+/', $form_state['values']['version']))
- form_set_error('version', t('Please enter correct version in given format'));
- /* country */
- if($form_state['values']['country']=='Others'){
- if($form_state['values']['other_country']== ''){
- form_set_error('other_country', t('Enter country name'));
- }else{
- $form_state['values']['country'] = $form_state['values']['other_country'];
- }
- if($form_state['values']['other_state']== ''){
- form_set_error('other_state', t('Enter state name'));
- }else{
- $form_state['values']['all_state'] = $form_state['values']['other_state'];
- }
- if($form_state['values']['other_city']== ''){
- form_set_error('other_city', t('Enter city name'));
- }else{
- $form_state['values']['city'] = $form_state['values']['other_city'];
- }
- }else{
- if($form_state['values']['country']== ''){
- form_set_error('country', t('Select country name'));
- }
- if($form_state['values']['all_state']== ''){
- form_set_error('all_state', t('Select state name'));
- }
- if($form_state['values']['city']== ''){
- form_set_error('city', t('Select city name'));
- }
-
-
- }
-
-
- if (isset($_FILES['files']))
- {
- /* check if atleast one source or result file is uploaded */
- if ( ! ($_FILES['files']['name']['samplefile1']))
- form_set_error('samplefile1', t('Please upload sample code main or source file.'));
-
- /* check for valid filename extensions */
- foreach ($_FILES['files']['name'] as $file_form_name => $file_name)
- {
- if ($file_name)
- {
- /* checking file type */
- if (strstr($file_form_name, 'sample'))
- $file_type = 'S';
-
- else
- $file_type = 'U';
-
- $allowed_extensions_str = '';
- switch ($file_type)
- {
- case 'S':
- $allowed_extensions_str = variable_get('textbook_companion_sample_source_file_extensions', '');
- break;
-
- }
- $allowed_extensions = explode(',' , $allowed_extensions_str);
- $allowd_file = strtolower($_FILES['files']['name'][$file_form_name]);
- $allowd_files = explode('.', $allowd_file);
- $temp_extension = end($allowd_files);
- if (!in_array($temp_extension, $allowed_extensions))
- form_set_error($file_form_name, t('Only file with ' . $allowed_extensions_str . ' extensions can be uploaded.'));
- if ($_FILES['files']['size'][$file_form_name] <= 0)
- form_set_error($file_form_name, t('File size cannot be zero.'));
-
- /* check if valid file name */
- if (!textbook_companion_check_valid_filename($_FILES['files']['name'][$file_form_name]))
- form_set_error($file_form_name, t('Invalid file name specified. Only alphabets and numbers are allowed as a valid filename.'));
-
-
- }
- }
- }
-
- return;
+ $states = array(
+ 0 => '-Select-'
+ );
+ $query = db_select('list_states_of_india');
+ $query->fields('list_states_of_india');
+ //$query->orderBy('', '');
+ $states_list = $query->execute();
+ while ($states_list_data = $states_list->fetchObject())
+ {
+ $states[$states_list_data->state] = $states_list_data->state;
+ } //$states_list_data = $states_list->fetchObject()
+ return $states;
}
-
-function book_proposal_form_submit($form, &$form_state)
+function _tbc_list_of_cities()
{
-
- global $user;
- $selections = variable_get("aicte_".$user->uid, "");
- $root_path =textbook_companion_samplecode_path();
-
- if (!$user->uid) {
- drupal_set_message('It is mandatory to login on this website to access the proposal form', 'error');
- return;
- }
-
- /* completion date to timestamp */
- list($d, $m, $y) = explode('-', $form_state['values']['completion_date']);
- $completion_date_timestamp = mktime(0, 0, 0, $m, $d, $y);
- $scilab_version = 'scilab ' . $form_state['values']['version'];
-
-$query = "INSERT INTO {textbook_companion_proposal}
- (uid, approver_uid, full_name, mobile, gender, how_project, course, branch, university, country, city, pincode, state, faculty, reviewer, completion_date, creation_date, approval_date, proposal_status, scilab_version, operating_system, teacher_email, message, samplefilepath) VALUES (:uid, :approver_uid, :full_name, :mobile, :gender, :how_project, :course, :branch, :university, :country, :city, :pincode, :state, :faculty, :reviewer, :completion_date,
- :creation_date, :approval_date, :proposal_status, :scilab_version, :operating_system,
-:teacher_email, :message, :samplefilepath)";
-$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" => 'Not available',
- ":course" => $form_state['values']['course'],
- ":branch" => $form_state['values']['branch'],
- ":university" => $form_state['values']['university'],
- ":country" => $form_state['values']['country'],
- ":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'])),
- ":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',
- ":samplefilepath"=>""
+ $city = array(
+ 0 => '-Select-'
);
-
- $result = db_query($query, $args, array('return' => Database::RETURN_INSERT_ID));
- $dest_path = $result . '/';
- if (!is_dir($root_path . $dest_path))
- mkdir($root_path . $dest_path);
- /* uploading files */
- foreach ($_FILES['files']['name'] as $file_form_name => $file_name)
- {
- if ($file_name)
- {
- /* checking file type */
- $file_type = 'S';
-
- if (file_exists($root_path . $dest_path . $_FILES['files']['name'][$file_form_name]))
- {
- drupal_set_message(t("Error uploading file. File !filename already exists.", array('!filename' => $_FILES['files']['name'][$file_form_name])), 'error');
- return;
- }
-
- /* uploading file */
- if (move_uploaded_file($_FILES['files']['tmp_name'][$file_form_name], $root_path . $dest_path . $_FILES['files']['name'][$file_form_name]))
- {
- $query = "UPDATE {textbook_companion_proposal} SET samplefilepath = :samplefilepath WHERE id = :id";
- $args = array(
- ":samplefilepath" => $dest_path . $_FILES['files']['name'][$file_form_name],
- ":id" =>$result,
- );
- $updateresult = db_query($query, $args);
-
- drupal_set_message($file_name . ' uploaded successfully.', 'status');
- } else {
- drupal_set_message('Error uploading file : ' . $dest_path . '/' . $file_name, 'error');
- }
- }
- }
-
- 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 = $result;
-
- /* inserting first book preference */
- if ($form_state['values']['book1'])
- {
-
- $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"=> $form_state['values']['book_category_1'],
- ":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");
-
- $preference_id = $result;
-
- /*$query = "
- UPDATE textbook_companion_aicte
- SET preference_id = {$preference_id}
- WHERE id = {$selections[0]}
- ";
- 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}
- (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,
- 2,
- ucwords(strtolower($form_state['values']['book2'])),
- ucwords(strtolower($form_state['values']['author2'])),
- $form_state['values']['isbn2'],
- ucwords(strtolower($form_state['values']['publisher2'])),
- $form_state['values']['edition2'],
- $form_state['values']['year2'],
- 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"=> $form_state['values']['book_category_2'],
- ":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");
- $preference_id = $result;
-
- /*$query = "
- UPDATE textbook_companion_aicte
- SET preference_id = {$preference_id}
- WHERE id = {$selections[1]}
- ";
- 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'])
- {
-
- $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"=> $form_state['values']['book_category_3'],
- ":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 = $result;
-
- /*$query = "
- UPDATE textbook_companion_aicte
- SET preference_id = {$preference_id}
- WHERE id = {$selections[2]}
- ";
- 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 = "
- UPDATE textbook_companion_aicte
- SET status = 1, uid = {$user->uid}, proposal_id = {$proposal_id}
- WHERE id = {$selection} AND status = 0
- ";
- 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)
- {
- drupal_set_message(t('Error receiving your third book preference.'), 'error');
- }
- }
-
- /* sending email */
- $email_to = $user->mail;
- $from = variable_get('textbook_companion_from_email', '');
- $bcc = variable_get('textbook_companion_emails', '');
- $cc = variable_get('textbook_companion_cc_emails', '');
-
- $params['proposal_received']['proposal_id'] = $proposal_id;
- $params['proposal_received']['user_id'] = $user->uid;
- $params['proposal_received']['headers']=array('From'=>$from,'MIME-Version'=> '1.0',
- 'Content-Type'=> 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
- 'Content-Transfer-Encoding' => '8Bit',
- 'X-Mailer'=> 'Drupal','Cc' => $cc, 'Bcc' => $bcc);
-
- if (!drupal_mail('textbook_companion', 'proposal_received', $email_to , language_default(), $params, $from, TRUE))
- drupal_set_message('Error sending email message.', 'error');
-
- drupal_set_message(t('We have received you book proposal. We will get back to you soon.'), 'status');
- drupal_goto('');
+ $query = db_select('list_cities_of_india');
+ $query->fields('list_cities_of_india');
+ $query->orderBy('city', 'ASC');
+ $city_list = $query->execute();
+ while ($city_list_data = $city_list->fetchObject())
+ {
+ $city[$city_list_data->city] = $city_list_data->city;
+ } //$city_list_data = $city_list->fetchObject()
+ return $city;
}
-
-/**
- * Implementation of hook_mail().
- */
-function textbook_companion_mail($key, &$message, $params)
+function _tbc_list_of_departments()
{
- global $user;
- $language = $message['language'];
- /*$tbc_bcc_emails = array(
- 'Bcc' => variable_get('textbook_companion_emails', ''),
- );*/
-
- switch ($key)
- {
- case 'proposal_received':
- // 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);*/
-
- $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();
-
- $samplecodefilename="";
- if(strlen($proposal_data->samplefilepath)>=5){
- $samplecodefilename=substr($proposal_data->samplefilepath, strrpos($proposal_data->samplefilepath, '/') + 1);
- }else{
- $samplecodefilename="Not provided";
- }
- /*$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 = "
- SELECT * FROM list_of_category loc
- JOIN textbook_companion_preference tcp ON loc.category_id = tcp.category
- WHERE proposal_id = :proposal_id AND pref_number = :pref_number LIMIT 1
- ";
- $args = array(
- ':proposal_id' => $params['proposal_received']['proposal_id'],
- ':pref_number' => 1,
- );
- $preference1_q = db_query($query,$args);
- $preference1_data = $preference1_q->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 = "
- SELECT * FROM list_of_category loc
- JOIN textbook_companion_preference tcp ON loc.category_id = tcp.category
- WHERE proposal_id = :proposal_id AND pref_number = :pref_number LIMIT 1
- ";
- $args = array(
- ':proposal_id' => $params['proposal_received']['proposal_id'],
- ':pref_number' => 2,
- );
- $preference2_q = db_query($query,$args);
- $preference2_data = $preference2_q->fetchObject();
-
-
- $query = "
- SELECT * FROM list_of_category loc
- JOIN textbook_companion_preference tcp ON loc.category_id = tcp.category
- WHERE proposal_id = :proposal_id AND pref_number = :pref_number LIMIT 1
- ";
- $args = array(
- ':proposal_id' => $params['proposal_received']['proposal_id'],
- ':pref_number' => 3,
- );
- $preference3_q = db_query($query,$args);
- $preference3_data = $preference3_q->fetchObject();
-
- /*$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['headers'] = $params['proposal_received']['headers'];
- $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:
-
-Full Name : ' . $proposal_data->full_name . '
-Email : ' . $user_data->mail . '
-Mobile : ' . $proposal_data->mobile . '
-Course : ' . $proposal_data->course . '
-Department/Branch : ' . $proposal_data->branch . '
-University/Institute : ' . $proposal_data->university . '
-College Teacher / Professor : ' . $proposal_data->faculty . '
-Reviewer : ' . $proposal_data->reviewer . '
-Expected date of completion : ' . date('d-m-Y', $proposal_data->completion_date) . '
-
-Your Book Preferences :
-
-Book Preference 1 :-
-Title of the book : ' . $preference1_data->book . '
-Author name : ' . $preference1_data->author . '
-ISBN No. : ' . $preference1_data->isbn . '
-Publisher and Place : ' . $preference1_data->publisher . '
-Edition : ' . $preference1_data->edition . '
-Year of publication : ' . $preference1_data->year . '
-Category : ' . $preference1_data->category_name . '
-
-Book Preference 2 :-
-Title of the book : ' . $preference2_data->book . '
-Author name : ' . $preference2_data->author . '
-ISBN No. : ' . $preference2_data->isbn . '
-Publisher and Place : ' . $preference2_data->publisher . '
-Edition : ' . $preference2_data->edition . '
-Year of publication : ' . $preference2_data->year . '
-Category : ' . $preference2_data->category_name . '
-
-Book Preference 3 :-
-Title of the book : ' . $preference3_data->book . '
-Author name : ' . $preference3_data->author . '
-ISBN No. : ' . $preference3_data->isbn . '
-Publisher and Place : ' . $preference3_data->publisher . '
-Edition : ' . $preference3_data->edition . '
-Year of publication : ' . $preference3_data->year . '
-Category : ' . $preference3_data->category_name . '
-
-
-Uploaded Sample Code :'.$samplecodefilename.'
-
-
-Your proposal is under review and you will soon receive an email from us regarding the same.
-
-
-Best Wishes,
-
-!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);*/
-
- $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['headers'] = $params['proposal_disapproved']['headers'];
- $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'] =array('body' => t('
-Dear !user_name,
-
-Your following book proposal has been disapproved:
-
-Reason for disapproval: ' . $proposal_data->message . '
-
-Full Name : ' . $proposal_data->full_name . '
-Email : ' . $user_data->mail . '
-Mobile : ' . $proposal_data->mobile . '
-Course : ' . $proposal_data->course . '
-Department/Branch : ' . $proposal_data->branch . '
-University/Institute : ' . $proposal_data->university . '
-College Teacher / Professor : ' . $proposal_data->faculty . '
-Reviewer : ' . $proposal_data->reviewer . '
-Expected date of completion : ' . date('d-m-Y', $proposal_data->completion_date) . '
-
-Your Book Preferences :
-
-Book Preference 1 :-
-Title of the book : ' . $preference1_data->book . '
-Author name : ' . $preference1_data->author . '
-ISBN No. : ' . $preference1_data->isbn . '
-Publisher and Place : ' . $preference1_data->publisher . '
-Edition : ' . $preference1_data->edition . '
-Year of publication : ' . $preference1_data->year . '
-
-Book Preference 2 :-
-Title of the book : ' . $preference2_data->book . '
-Author name : ' . $preference2_data->author . '
-ISBN No. : ' . $preference2_data->isbn . '
-Publisher and Place : ' . $preference2_data->publisher . '
-Edition : ' . $preference2_data->edition . '
-Year of publication : ' . $preference2_data->year . '
-
-Book Preference 3 :-
-Title of the book : ' . $preference3_data->book . '
-Author name : ' . $preference3_data->author . '
-ISBN No. : ' . $preference3_data->isbn . '
-Publisher and Place : ' . $preference3_data->publisher . '
-Edition : ' . $preference3_data->edition . '
-Year of publication : ' . $preference3_data->year . '
-
-Best Wishes,
-
-!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'] = array('body' => t('
-Dear !user_name,
-
-Your following book proposal has been disapproved:
-
-Reason for disapproval: ' . $proposal_data->message . '
-
-Full Name : ' . $proposal_data->full_name . '
-Email : ' . $user_data->mail . '
-Mobile : ' . $proposal_data->mobile . '
-Course : ' . $proposal_data->course . '
-Department/Branch : ' . $proposal_data->branch . '
-University/Institute : ' . $proposal_data->university . '
-College Teacher / Professor : ' . $proposal_data->faculty . '
-Reviewer : ' . $proposal_data->reviewer . '
-Expected date of completion : ' . date('d-m-Y', $proposal_data->completion_date) . '
-
-Your Book Preferences :
-
-Book Preference :-
-Title of the book : ' . $preference1_data->book . '
-Author name : ' . $preference1_data->author . '
-ISBN No. : ' . $preference1_data->isbn . '
-Publisher and Place : ' . $preference1_data->publisher . '
-Edition : ' . $preference1_data->edition . '
-Year of publication : ' . $preference1_data->year . '
-
-
-
-Best Wishes,
-
-!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), array('language' => $language->language)));
+ $query = db_select('list_of_departments');
+ $query->fields('list_of_departments');
+ $query->orderBy('id', 'DESC');
+ $department_list = $query->execute();
+ while ($department_list_data = $department_list->fetchObject())
+ {
+ $department[$department_list_data->department] = $department_list_data->department;
+ } //$department_list_data = $department_list->fetchObject()
+ return $department;
}
- break;
-
- /* Non AICTE Book Proposal */
- case 'nonaicte_proposal_received':
- // 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);*/
-
- $query = db_select('textbook_companion_proposal');
- $query->fields('textbook_companion_proposal');
- $query->condition('id', $params['nonaicte_proposal_received']['proposal_id']);
- $query->range(0, 1);
- $result = $query->execute();
- $proposal_data =$result->fetchObject();
-
- $samplecodefilename="";
- if(strlen($proposal_data->samplefilepath)>=5){
- $samplecodefilename=substr($proposal_data->samplefilepath, strrpos($proposal_data->samplefilepath, '/') + 1);
- }else{
- $samplecodefilename="Not provided";
+function _tbc_list_of_category($category_id = NULL)
+{
+ if ($category_id == NULL)
+ {
+ $query = db_select('list_of_category');
+ $query->fields('list_of_category');
+ $query->orderBy('id', 'ASC');
+ $category_list = $query->execute();
+ } //$category_id == NULL
+ else
+ {
+ $query = db_select('list_of_category');
+ $query->fields('list_of_category');
+ $query->condition('category_id', $category_id);
+ $query->orderBy('id', 'ASC');
+ $category_list = $query->execute();
}
- $query = "
- SELECT * FROM list_of_category loc
- JOIN textbook_companion_preference tcp ON loc.category_id = tcp.category
- WHERE proposal_id = :proposal_id AND pref_number = :pref_number LIMIT 1
- ";
- $args = array(
- ':proposal_id' => $params['nonaicte_proposal_received']['proposal_id'],
- ':pref_number' => 1,
- );
- $preference1_q = db_query($query,$args);
- $preference1_data = $preference1_q->fetchObject();
- $user_data = user_load($params['nonaicte_proposal_received']['user_id']);
- $message['headers'] = $params['nonaicte_proposal_received']['headers'];
- $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:
-
-Full Name : ' . $proposal_data->full_name . '
-Email : ' . $user_data->mail . '
-Mobile : ' . $proposal_data->mobile . '
-Course : ' . $proposal_data->course . '
-Department/Branch : ' . $proposal_data->branch . '
-University/Institute : ' . $proposal_data->university . '
-College Teacher / Professor : ' . $proposal_data->faculty . '
-Reviewer : ' . $proposal_data->reviewer . '
-Expected date of completion : ' . date('d-m-Y', $proposal_data->completion_date) . '
-
-Your Non AICTE Book Preferences:
-
-Book Preference :-
-Title of the book : ' . $preference1_data->book . '
-Author name : ' . $preference1_data->author . '
-ISBN No. : ' . $preference1_data->isbn . '
-Publisher and Place : ' . $preference1_data->publisher . '
-Edition : ' . $preference1_data->edition . '
-Year of publication : ' . $preference1_data->year . '
-Category : ' . $preference1_data->category_name . '
-
-
-Uploaded Sample Code : '.$samplecodefilename.'
-
-Your proposal is under review and you will soon receive an email from us regarding the same.
-
-Best Wishes,
-
-!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), array('language' => $language->language)));
- break;
-case 'nonaicte_proposal_to_pi':
- /************ fetch proposal data ****************/
-
- $query = db_select('textbook_companion_proposal');
- $query->fields('textbook_companion_proposal');
- $query->condition('id', $params['nonaicte_proposal_received']['proposal_id']);
- $query->range(0, 1);
- $result = $query->execute();
- $proposal_data=$result->fetchObject();
-
- /************ fetch book preference data ****************/
-
- $query = db_select('textbook_companion_preference');
- $query->fields('textbook_companion_preference');
- $query->condition('proposal_id', $params['nonaicte_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['nonaicte_proposal_received']['user_id']);
- $message['headers'] = $params['nonaicte_proposal_received']['headers'];
- $message['subject'] = t('[!site_name] New Non AICTE book suggestion has been received', array('!site_name' => variable_get('site_name', '')), array('language' => $language->language));
- /******************* Email Template for not aicte book suggestion **************************/
- $message['body'] = array('body' => t('
-Dear all,
-
-We have received following Non AICTE book suggestion:
-
-Full Name : ' . $proposal_data->full_name . '
-University/Institute :' . $proposal_data->university . '
-
-
-Reason(s): '. $proposal_data->reason . '
-
-
-Your Non AICTE Book Preference :
-
-Title of the book : ' . $preference1_data->book . '
-Author name : ' . $preference1_data->author . '
-ISBN No. : ' . $preference1_data->isbn . '
-Publisher and Place : ' . $preference1_data->publisher . '
-Edition : ' . $preference1_data->edition . '
-Year of publication : ' . $preference1_data->year . '
-
-Reference :- '.$proposal_data->reference
-
-//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), array('language' => $language->language)));
- break;
-
- case 'proposal_approved':
-
- $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();
-
-
- $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['headers'] = $params['proposal_approved']['headers'];
- $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:
-
-Full Name : ' . $proposal_data->full_name . '
-Email : ' . $user_data->mail . '
-Mobile : ' . $proposal_data->mobile . '
-Course : ' . $proposal_data->course . '
-Department/Branch : ' . $proposal_data->branch . '
-University/Institute : ' . $proposal_data->university . '
-College Teacher / Professor : ' . $proposal_data->faculty . '
-Reviewer : ' . $proposal_data->reviewer . '
-Expected date of completion : ' . date('d-m-Y', $proposal_data->completion_date) . '
-
-Title of the book : ' . $approved_preference_data->book . '
-Author name : ' . $approved_preference_data->author . '
-ISBN No. : ' . $approved_preference_data->isbn . '
-Publisher and Place : ' . $approved_preference_data->publisher . '
-Edition : ' . $approved_preference_data->edition . '
-Year of publication : ' . $approved_preference_data->year . '
-
-According the new Textbook Companion procedure, a student doing a textbook companion is not required to have a mentor. For more details check the links given below.
-http://scilab.in/tbc_honorarium
-http://scilab.in/Textbook_Companion_Internship
-
-Please contact us by sending an e-mail to textbook@scilab.in in case you wish to cancel this book proposal.
-
-Best Wishes,
-
-!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);*/
-
- $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['headers'] = $params['proposal_completed']['headers'];
- $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:
-
-Full Name : ' . $proposal_data->full_name . '
-Email : ' . $user_data->mail . '
-Mobile : ' . $proposal_data->mobile . '
-Course : ' . $proposal_data->course . '
-Department/Branch : ' . $proposal_data->branch . '
-University/Institute : ' . $proposal_data->university . '
-College Teacher / Professor : ' . $proposal_data->faculty . '
-Reviewer : ' . $proposal_data->reviewer . '
-Expected date of completion : ' . date('d-m-Y', $proposal_data->completion_date) . '
-
-Title of the book : ' . $approved_preference_data->book . '
-Author name : ' . $approved_preference_data->author . '
-ISBN No. : ' . $approved_preference_data->isbn . '
-Publisher and Place : ' . $approved_preference_data->publisher . '
-Edition : ' . $approved_preference_data->edition . '
-Year of publication : ' . $approved_preference_data->year . '
-
-Your book is now available at following link to download.
-
-http://scilab.in/textbook_run/' . $approved_preference_data->id . '
-
-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),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);*/
-
- $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();
-
- $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();
-
- $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();
-
- $user_data = user_load($params['example_uploaded']['user_id']);
- $message['headers'] = $params['example_uploaded']['headers'];
- $message['subject'] = t('[!site_name] You have uploaded example for Textbook Companion', array('!site_name' => variable_get('site_name', '')), array('language' => $language->language));
- $message['body'] =array('body' => t('
-Dear !user_name,
-
-You have uploaded the following solution :
-
-Title of the book : ' . $preference_data->book . '
-Title of the chapter : '. $chapter_data->name . '
-Example number : ' . $example_data->number . '
-Caption : ' . $example_data->caption . '
-
-You shall be notified after the solution is reviewed
-
-Best Wishes,
-
-!site_name Team,
-FOSSEE,IIT Bombay', 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);*/
-
- $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();
-
- $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();
-
- $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();
-
- $user_data = user_load($params['example_updated']['user_id']);
- $message['headers'] = $params['example_updated']['headers'];
- $message['subject'] = t('[!site_name] You have updated example for Textbook Companion', 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:
-
-Title of the book : ' . $preference_data->book . '
-Title of the chapter : '. $chapter_data->name . '
-Example number : ' . $example_data->number . '
-Caption : ' . $example_data->caption . '
-
-The example is still under review. You will be notified when it has been approved.
-
-Best Wishes,
-
-!site_name Team,
-FOSSEE,IIT Bombay', 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);*/
-
- $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', '')), array('language' => $language->language));
- $message['body'] = array('body' =>t('
-Dear !user_name,
-
-Reviewer have updated the following example:
-
-Example number : ' . $example_data->number . '
-Caption : ' . $example_data->caption . '
-
-Best Wishes,
-
-!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);*/
-
- $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['headers'] = $params['example_approved']['headers'];
- $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:
-
-Example number : ' . $example_data->number . '
-Caption : ' . $example_data->caption . '
-
-Best Wishes,
-
-!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), array('language' => $language->language)));
- break;
-
- case 'example_disapproved':
- // bcc to textbook_companion_emails
- $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', '')), array('language' => $language->language));
- $message['body'] = array('body' =>t('
-Dear !user_name,
-
-Your following example has been disapproved:
-
-Example number : ' . $params['example_disapproved']['example_number'] . '
-Caption : ' . $params['example_disapproved']['example_caption'] . '
-
-Reason for dis-approval : ' . $params['example_disapproved']['message'] . '
-
-Best Wishes,
-
-!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name),array('language' => $language->language)));
- break;
-
- case 'example_deleted_user':
- // bcc to textbook_companion_emails
- // $message['headers'] += $tbc_bcc_emails;
- $user_data = user_load($params['example_deleted_user']['user_id']);
- $message['headers'] = $params['example_deleted_user']['headers'];
- $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 :
-
-Title of the Book : ' . $params['example_deleted_user']['book_title'] . '
-Title of the Chapter : ' . $params['example_deleted_user']['chapter_title'] . '
-Example number : ' . $params['example_deleted_user']['example_number'] . '
-Caption : ' . $params['example_deleted_user']['example_caption'] . '
-
-Best Wishes,
-
-!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), array('language' => $language->language)));
- break;
-
- case 'dependency_uploaded':
- // bcc to textbook_companion_emails
- //$message['headers'] += $tbc_bcc_emails;
- $user_data = user_load($params['dependency_uploaded']['user_id']);
- $message['headers'] = $params['example_deleted_user']['headers'];
- $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', '')), array('language' => $language->language));
- $message['body'] = array('body' =>t('
-Dear !user_name,
-
-You have uploaded following dependency files :
- ' . $dependency_files . '
-
-Best Wishes,
-
-!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name),
-array('language' => $language->language)));
- break;
-
- case 'feedback_received':
- // bcc to textbook_companion_emails
- // $message['headers'] += $tbc_bcc_emails;
- $message['headers'] = $params['feedback_received']['headers'];
- $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', '')), array('language' => $language->language));
- $message['body'] = array('body' =>t('
-Dear !user_name,
-
-We have received your following feedback
-
-Title of the Book: ' . $params['feedback_received']['book_title'] . '
-Title of the Chapter: ' . $params['feedback_received']['chapter_number'] . ' ' . $params['feedback_received']['chapter_title'] . '
-Example No.: ' . $params['feedback_received']['example_no'] . '
-
-Your feedback :
-' . $params['feedback_received']['feedback'] . '
-
-Best Wishes,
-
-!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), array('language' => $language->language)));
- break;
-
- case 'internshipform':
- // bcc to textbook_companion_emails
- //$message['headers'] += $tbc_bcc_emails;
- $message['headers'] = $params['internshipform']['headers'];
- $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', '')), array('language' => $language->language));
- $message['body'] = array('body' =>t('
-Dear !user_name,
-
-We have received your Internship Form Application for the book
-
-Title of the Book: ' . $params['internshipform']['book_title'] . '
-Title of the Chapter: ' . $params['internshipform']['chapter_number'] . ' ' . $params['internshipform']['chapter_title'] . '
-Example No.: ' . $params['internshipform']['example_no'] . '
-
-Best Wishes,
-
-!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name),array('language' => $language->language)));
- break;
-
-case 'copyrighttransferform':
- // bcc to textbook_companion_emails
- //$message['headers'] += $tbc_bcc_emails;
- $message['headers'] = $params['copyrighttransferform']['headers'];
-
- $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', '')), array('language' => $language->language));
- $message['body'] =array('body' => t('
-Dear !user_name,
-
-We have received your Copyright Form Application for the book
-
-Title of the Book: ' . $params['copyrighttransferform']['book_title'] . '
-Title of the Chapter: ' . $params['copyrighttransferform']['chapter_number'] . ' ' . $params['copyrighttransferform']['chapter_title'] . '
-Example No.: ' . $params['copyrighttransferform']['example_no'] . '
-
-Best Wishes,
-
-!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name),array('language' => $language->language)));
- break;
-
-case 'undertakingform':
- // bcc to textbook_companion_emails
- //$message['headers'] += $tbc_bcc_emails;
- $message['headers'] = $params['undertakingform']['headers'];
- $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', '')), array('language' => $language->language));
- $message['body'] =array('body' => t('
-Dear !user_name,
-
-We have received your Undertaking Form Application for the book
-
-Title of the Book: ' . $params['undertakingform']['book_title'] . '
-Title of the Chapter: ' . $params['undertakingform']['chapter_number'] . ' ' . $params['undertakingform']['chapter_title'] . '
-Example No.: ' . $params['undertakingform']['example_no'] . '
-
-Best Wishes,
-
-!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), array('language' => $language->language)));
- break;
-
-
-case 'remark':
- // bcc to textbook_companion_emails
- //$message['headers'] += $tbc_bcc_emails;
-
- $user_data = user_load($params['remark']['user_id']);
- $message['headers'] = $params['remark']['headers'];
- $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
-
-Title of the Book: ' . $params['internshipform']['book_title'] . '
-Title of the Chapter: ' . $params['internshipform']['chapter_number'] . ' ' . $params['internshipform']['chapter_title'] . '
-Example No.: ' . $params['internshipform']['example_no'] . '
-
-Best Wishes,
-
-!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), array('language' => $language->language)));
- break;
-
- case 'cheque_sent':
- // bcc to textbook_companion_emails
- // $message['headers'] += $tbc_bcc_emails;
-
- $user_data = user_load($params['cheque_sent']['user_id']);
- $message['headers'] = $params['cheque_sent']['headers'];
-
- $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
-
-Title of the Book: ' . $params['cheque_sent']['book_title'] . '
-Title of the Chapter: ' . $params['cheque_sent']['chapter_number'] . ' ' . $params['cheque_sent']['chapter_title'] . '
-Example No.: ' . $params['cheque_sent']['example_no'] . '
-
-Best Wishes,
-
-!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), array('language' => $language->language)));
- break;
-
-
- case 'standard':
- // bcc to textbook_companion_emails
- //$message['headers'] += $tbc_bcc_emails;
- $message['headers'] = $params['standard']['headers'];
- $message['subject'] = $params['standard']['subject'];
- $message['body'] = $params['standard']['body'];
- break;
- }
+ while ($category_list_data = $category_list->fetchObject())
+ {
+ $category[$category_list_data->category_id] = $category_list_data->category_name;
+ } //$category_list_data = $category_list->fetchObject()
+ return $category;
}
-
-/* AJAX CALLS */
-function textbook_companion_ajax()
+function _tbc_sentence_case($string)
{
- $query_type = arg(2);
- if ($query_type == 'chapter_title')
- {
- $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);*/
-
- $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;
- }
- } else if ($query_type == 'example_exists') {
- $chapter_number = arg(3);
- $preference_id = arg(4);
- $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);*/
-
- $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;
- } else {
- $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);*/
-
- $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.';
- else
- echo 'Warning! Example already uploaded. Delete the example and reupload it.';
- return;
- }
- }
- echo '';
+ $string =ucwords(strtolower($string));
+ foreach (array('-', '\'') as $delimiter) {
+ if (strpos($string, $delimiter)!==false) {
+ $string =implode($delimiter, array_map('ucfirst', explode($delimiter, $string)));
+ }
+ }
+ return $string;
}
-
/*************************** VALIDATION FUNCTIONS *****************************/
-function textbook_companion_check_valid_filename($file_name) {
- if (!preg_match('/^[0-9a-zA-Z\_\.]+$/', $file_name))
- return FALSE;
- else
- if (substr_count($file_name, ".") > 1)
- return FALSE;
- else
- return TRUE;
+function textbook_companion_check_valid_filename($file_name)
+{
+ if (!preg_match('/^[0-9a-zA-Z\_\.]+$/', $file_name))
+ return FALSE;
+ else if (substr_count($file_name, ".") > 1)
+ return FALSE;
+ else
+ return TRUE;
}
-
-function check_name($name = '') {
- if (!preg_match('/^[0-9a-zA-Z\ ]+$/', $name))
- return FALSE;
- else
- return TRUE;
+function check_name($name = '')
+{
+ if (!preg_match('/^[0-9a-zA-Z\ ]+$/', $name))
+ return FALSE;
+ else
+ return TRUE;
}
-
-function check_chapter_number($name = '') {
- if (!preg_match('/^([0-9])+(\.([0-9a-zA-Z])+)+$/', $name))
- return FALSE;
- else
- return TRUE;
+function check_chapter_number($name = '')
+{
+ if (!preg_match('/^([0-9])+(\.([0-9a-zA-Z])+)+$/', $name))
+ return FALSE;
+ else
+ return TRUE;
}
-
-function textbook_companion_path() {
- return $_SERVER['DOCUMENT_ROOT'] . base_path() . 'uploads/';
+function textbook_companion_path()
+{
+ return $_SERVER['DOCUMENT_ROOT'] . base_path() . 'uploads/';
}
-
-function textbook_companion_samplecode_path() {
- return $_SERVER['DOCUMENT_ROOT'] . base_path() . 'tbc_sample_code/';
+function textbook_companion_samplecode_path()
+{
+ return $_SERVER['DOCUMENT_ROOT'] . base_path() . 'tbc_sample_code/';
}
/****************************** DELETION FUNCTIONS ****************************/
-
function delete_example($example_id)
{
- global $user;
- $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);*/
-
+ global $user;
+ $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);*/
$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);*/
-
+ $example_data = $example_q->fetchObject();
+ if (!$example_data)
+ {
+ drupal_set_message(t('Invalid example.'), 'error');
+ return FALSE;
+ } //!$example_data
+ /*$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');
- return FALSE;
- }
-
- /* deleting example files */
-
- /*$examples_files_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE example_id = %d", $example_id);*/
-
+ $chapter_data = $chapter_q->fetchObject();
+ if (!$chapter_data)
+ {
+ drupal_set_message(t('Invalid example chapter.'), 'error');
+ return FALSE;
+ } //!$chapter_data
+ /* deleting example files */
+ /*$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))
- {
- $status = FALSE;
- drupal_set_message(t('Error deleting !file. File does not exists.', array('!file' => $examples_files_data->filepath)), 'error');
- continue;
- }
-
- /* removing example file */
- 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');
-
- /* sending email to admins */
- $email_to = variable_get('textbook_companion_emails', '');
- $params['standard']['subject'] = "[ERROR] Error deleting example file";
- $params['standard']['body'] = array(0 =>"Error deleting example files by " . $user->uid . " at " . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . " :
+ while ($examples_files_data = $examples_files_q->fetchObject())
+ {
+ if (!file_exists($root_path . $examples_files_data->filepath))
+ {
+ $status = FALSE;
+ drupal_set_message(t('Error deleting !file. File does not exists.', array(
+ '!file' => $examples_files_data->filepath
+ )), 'error');
+ continue;
+ } //!file_exists($root_path . $examples_files_data->filepath)
+ /* removing example file */
+ 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');
+ /* sending email to admins */
+ $email_to = variable_get('textbook_companion_emails', '');
+ $params['standard']['subject'] = "[ERROR] Error deleting example file";
+ $params['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);
- if (!drupal_mail('textbook_companion', 'standard', $email_to, language_default(), $params, 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);*/
- $query = db_delete('textbook_companion_example_files');
- $query->condition('id', $examples_files_data->id);
- $num_deleted = $query->execute();
-
-
- }
- }
-
- if (!$status)
- return FALSE;
-
- /* 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 (!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', '');
- $params['standard']['subject'] = "[ERROR] Error deleting folder";
- $params['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(), $params, 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);*/
+ file id : " . $examples_files_data->id . "
+ file path : " . $examples_files_data->filepath
+ );
+ if (!drupal_mail('textbook_companion', 'standard', $email_to, language_default(), $params, variable_get('textbook_companion_from_email', NULL), TRUE))
+ drupal_set_message('Error sending email message.', 'error');
+ } //!drupal_unlink($root_path . $examples_files_data->filepath)
+ else
+ {
+ /* deleting example files database entries */
+ /*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();
+ }
+ } //$examples_files_data = $examples_files_q->fetchObject()
+ if (!$status)
+ return FALSE;
+ /* 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 (!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', '');
+ $params['standard']['subject'] = "[ERROR] Error deleting folder";
+ $params['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(), $params, variable_get('textbook_companion_from_email', NULL), TRUE))
+ drupal_set_message('Error sending email message.', 'error');
+ return FALSE;
+ } //!drupal_rmdir($dir_path)
+ } //is_dir($dir_path)
+ 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);*/
$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);*/
+ /*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;
+ return $status;
}
-
-function delete_chapter($chapter_id)
+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);*/
-
+ $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);*/
$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');
- return FALSE;
- }
-
- /* deleting examples */
-
- /*$example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d", $chapter_id);*/
-
+ $chapter_data = $chapter_q->fetchObject();
+ if (!$chapter_data)
+ {
+ drupal_set_message('Invalid chapter.', 'error');
+ return FALSE;
+ } //!$chapter_data
+ /* deleting examples */
+ /*$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;
- }
-
- if ($status)
- {
- $dir_path = $root_path . $chapter_data->preference_id . '/CH' . $chapter_data->number;
-
- if (is_dir($dir_path))
- {
- $res = rmdir($dir_path);
- if (!$res)
- {
- drupal_set_message(t('Error deleting chapter folder !folder', array('!folder' => $dir_path)), 'error');
-
- /* sending email to admins */
- $email_to = variable_get('textbook_companion_emails', '');
- $params['standard']['subject'] = "[ERROR] Error deleting folder";
- $params['standard']['body'] = "Error deleting folder " . $dir_path;
- if (!drupal_mail('textbook_companion', 'standard', $email_to, language_default(), $params, variable_get('textbook_companion_from_email', NULL), TRUE))
- drupal_set_message('Error sending email message.', 'error');
- return FALSE;
- } else {
- /* deleting chapter details from database */
-
- /*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 {
- drupal_set_message(t('Cannot delete chapter folder. !folder does not exists.', array('!folder' => $dir_path)), 'error');
- return FALSE;
- }
- }
- return FALSE;
+ while ($example_data = $example_q->fetchObject())
+ {
+ if (!delete_example($example_data->id))
+ $status = FALSE;
+ } //$example_data = $example_q->fetchObject()
+ if ($status)
+ {
+ $dir_path = $root_path . $chapter_data->preference_id . '/CH' . $chapter_data->number;
+ if (is_dir($dir_path))
+ {
+ $res = rmdir($dir_path);
+ if (!$res)
+ {
+ drupal_set_message(t('Error deleting chapter folder !folder', array(
+ '!folder' => $dir_path
+ )), 'error');
+ /* sending email to admins */
+ $email_to = variable_get('textbook_companion_emails', '');
+ $params['standard']['subject'] = "[ERROR] Error deleting folder";
+ $params['standard']['body'] = "Error deleting folder " . $dir_path;
+ if (!drupal_mail('textbook_companion', 'standard', $email_to, language_default(), $params, variable_get('textbook_companion_from_email', NULL), TRUE))
+ drupal_set_message('Error sending email message.', 'error');
+ return FALSE;
+ } //!$res
+ else
+ {
+ /* deleting chapter details from database */
+ /*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;
+ }
+ } //is_dir($dir_path)
+ else
+ {
+ drupal_set_message(t('Cannot delete chapter folder. !folder does not exists.', array(
+ '!folder' => $dir_path
+ )), 'error');
+ return FALSE;
+ }
+ } //$status
+ return FALSE;
}
-
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);*/
+ $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);*/
$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');
- return FALSE;
- }
-
- /* delete chapters */
-
- /*$chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE preference_id = %d", $preference_data->id);*/
+ $preference_data = $preference_q->fetchObject();
+ if (!$preference_data)
+ {
+ drupal_set_message('Invalid book.', 'error');
+ return FALSE;
+ } //!$preference_data
+ /* delete chapters */
+ /*$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))
- {
- $status = FALSE;
- }
- }
- return $status;
+ while ($chapter_data = $chapter_q->fetchObject())
+ {
+ if (!delete_chapter($chapter_data->id))
+ {
+ $status = FALSE;
+ } //!delete_chapter($chapter_data->id)
+ } //$chapter_data = $chapter_q->fetchObject()
+ return $status;
}
-
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);*/
-
+ $root_path = textbook_companion_path();
+ /*$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');
- return FALSE;
- }
-
- if (!file_exists($root_path . $file_data->filepath))
- {
- drupal_set_message(t('Error deleting !file. File does not exists.', array('!file' => $file_data->filepath)), 'error');
- return FALSE;
- }
-
- /* removing example file */
- if (!unlink($root_path . $file_data->filepath))
- {
- drupal_set_message(t('Error deleting !file', array('!file' => $file_data->filepath)), 'error');
-
- /* sending email to admins */
- $email_to = variable_get('textbook_companion_emails', '');
- $params['standard']['subject'] = "[ERROR] Error deleting file";
- $params['standard']['body'] = "Error deleting file by " . $user->uid . " at " . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . " :
- file id : " . $file_id . "
+ $file_data = $file_q->fetchObject();
+ if (!$file_data)
+ {
+ drupal_set_message('Invalid file specified.', 'error');
+ return FALSE;
+ } //!$file_data
+ if (!file_exists($root_path . $file_data->filepath))
+ {
+ drupal_set_message(t('Error deleting !file. File does not exists.', array(
+ '!file' => $file_data->filepath
+ )), 'error');
+ return FALSE;
+ } //!file_exists($root_path . $file_data->filepath)
+ /* removing example file */
+ if (!unlink($root_path . $file_data->filepath))
+ {
+ drupal_set_message(t('Error deleting !file', array(
+ '!file' => $file_data->filepath
+ )), 'error');
+ /* sending email to admins */
+ $email_to = variable_get('textbook_companion_emails', '');
+ $params['standard']['subject'] = "[ERROR] Error deleting file";
+ $params['standard']['body'] = "Error deleting file by " . $user->uid . " at " . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . " :
+ file id : " . $file_id . "
file path : " . $file_data->filepath;
- if (!drupal_mail('textbook_companion', 'standard', $email_to, language_default(), $params, variable_get('textbook_companion_from_email', NULL), TRUE))
- drupal_set_message('Error sending email message.', 'error');
- return FALSE;
- } else {
- /* deleting example files database entries */
-
- /*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;
- }
-}
-
-//Non aicte book proposal form
-
-function book_proposal_nonaicte_form($form,&$form_state)
-{
-
- global $user;
-
- $form = array();
- $form['imp_notice'] = array(
- '#type' => 'item',
- '#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',
- '#title' => t('Guidelines'),
- '#attributes' => array('style'=>'font-weight: bold'),
- '#collapsible' => TRUE,
- '#collapsed' => FALSE,
- );
- $form['guidelines']['book'] = array(
- '#type' => 'item',
- '#required' => TRUE,
- '#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>
- <li>If the book has less than 80 examples the <a href="tbc_honorarium" target="_blank">honorarium</a> will be provided on a pro-rata basis </li>
- <li>Make sure the book you propose is not already an <a href="aicte_proposal" target="_blank">AICTE recommended book</a>, <a href="Completed_Books" target="_blank">completed book</a>
- or a <a href="Books_Progress" target="_blank">book in progress</a> </li>
- <li>You will be intimated about the approval or rejection of your suggestion via e-mail</li>
-
-</ul> ',
-
- );
-
-
- $form['full_name'] = array(
- '#type' => 'textfield',
- '#title' => t('Full Name'),
- '#size' => 30,
- '#maxlength' => 50,
- '#required' => TRUE,
- );
- $form['email_id'] = array(
- '#type' => 'textfield',
- '#title' => t('Email'),
- '#size' => 30,
- '#value' => $user->mail,
- '#disabled' => TRUE,
- );
- $form['mobile'] = array(
- '#type' => 'textfield',
- '#title' => t('Mobile No.'),
- '#size' => 30,
- '#maxlength' => 15,
- '#required' => TRUE,
- );
- $form['gender'] = array(
- '#type' => 'radios',
- '#title' => t('Gender'),
- '#options' => array('M' => 'Male', 'F' => 'Female'),
- '#required' => TRUE,
- );
-
- /*$form['how_project'] = array(
- '#type' => 'select',
- '#title' => t('How did you come to know about this project'),
- '#options' => array('Scilab Website' => 'Scilab Website',
- 'Friend' => 'Friend',
- 'Professor/Teacher' => 'Professor/Teacher',
- 'Mailing List' => 'Mailing List',
- 'Poster in my/other college' => 'Poster in my/other college',
- 'Others' => 'Others'),
- '#required' => TRUE,
- );*/
-
- $form['course'] = array(
- '#type' => 'textfield',
- '#title' => t('Course'),
- '#size' => 30,
- '#maxlength' => 50,
- '#required' => TRUE,
- );
- $form['branch'] = array(
- '#type' => 'select',
- '#title' => t('Department/Branch'),
- '#options' => _tbc_list_of_departments(),
- '#required' => TRUE,
- );
- $form['university'] = array(
- '#type' => 'textfield',
- '#title' => t('University/Institute'),
- '#size' => 30,
- '#maxlength' => 50,
- '#required' => TRUE,
- );
- $form['country'] = array(
- '#type' => 'select',
- '#title' => t('Country'),
- '#options' => array(
- 'India' => 'India',
- 'Others' => 'Others',
- ),
- '#required' => TRUE,
- '#tree' => TRUE,
- '#validated' => TRUE,
- );
- $form['other_country'] = array(
- '#type' => 'textfield',
- '#title' => t('Other than India'),
- '#size' => 100,
- '#attributes' =>array('placeholder' => t('Enter your country name')),
- '#states' => array(
- 'visible' => array(
- ':input[name="country"]' => array('value' => 'Others'),
- ),
- ),
- );
- $form['other_state'] = array(
- '#type' => 'textfield',
- '#title' => t('State other than India'),
- '#size' => 100,
- '#attributes' =>array('placeholder' => t('Enter your state/region name')),
- '#states' => array(
- 'visible' => array(
- ':input[name="country"]' => array('value' => 'Others'),
- ),
- ),
- );
- $form['other_city'] = array(
- '#type' => 'textfield',
- '#title' => t('City other than India'),
- '#size' => 100,
- '#attributes' =>array('placeholder' => t('Enter your city name')),
- '#states' => array(
- 'visible' => array(
- ':input[name="country"]' => array('value' => 'Others'),
- ),
- ),
- );
- $form['all_state'] = array(
- '#type' => 'select',
- '#title' => t('State'),
- '#options' => _tbc_list_of_states(),
- '#validated' => TRUE,
- '#states' => array(
- 'visible' => array(
- ':input[name="country"]' => array('value' => 'India'),
- ),
- ),
- );
- $form['city'] = array(
- '#type' => 'select',
- '#title' => t('City'),
- '#options' => _tbc_list_of_cities(),
- '#states' => array(
- 'visible' => array(
- ':input[name="country"]' => array('value' => 'India'),
- ),
- ),
- );
- $form['pincode'] = array(
- '#type' => 'textfield',
- '#title' => t('Pincode'),
- '#size' => 30,
- '#maxlength' => 6,
- '#required' => False,
- '#attributes' =>array('placeholder' =>'Enter pincode....'),
- );
- $form['faculty'] = array(
- '#type' => 'hidden',
- '#value' => 'None',
- '#title' => t('College Teacher/Professor'),
- '#size' => 30,
- '#maxlength' => 50,
- '#required' => TRUE,
- );
- $form['faculty_email'] = array(
- '#type' => 'hidden',
- '#value' => 'None',
- '#title' => t('Teacher/Professor Email Id'),
- '#default_value' => '@email.com',
- '#size' => 30,
- '#maxlength' => 50,
- );
- $form['reviewer'] = array(
- '#type' => 'hidden',
- '#value' => 'None',
- '#title' => t('Reviewer'),
- '#size' => 30,
- '#maxlength' => 50,
- );
-
- $form['version'] = array(
- '#type' => 'textfield',
- '#title' => t('Scilab Version'),
- '#description' => t('Input version format should be like 5.4 or 5.4.1'),
- '#size' => 10,
- '#required' => TRUE,
- '#maxlength' => 20,
- );
- $form['completion_date'] = array(
- '#type' => 'textfield',
- '#title' => t('Expected Date of Completion'),
- '#description' => t('Input date format should be DD-MM-YYYY. Eg: 23-03-2011'),
- '#size' => 10,
- '#maxlength' => 10,
- '#required' => TRUE,
- );
- $form['operating_system'] = array(
- '#type' => 'textfield',
- '#title' => t('Operating System'),
- '#required' => TRUE,
- '#size' => 30,
- '#maxlength' => 50,
- );
-
- $reason=array(
- 'Used in more than one University' =>t('Used in more than one University'),
- 'The book has multiple editions' => t('The book has multiple editions'),
- 'Extremely useful' => t('Extremely useful'),
- 'Other reason' => t('Any other reason state below')
- );
- $form['reason'] = array(
- '#type' => 'checkboxes',
- '#title' => t('Reasons'),
- '#options' => $reason,
- '#required' => TRUE,
- );
- $form['other_reason'] = array(
- '#type' => 'textarea',
- '#size' => 300,
- '#maxlength' => 300,
- '#states' => array('visible' => array(':input[name="reason[Other reason]"]' => array('checked' => TRUE),),),
- //'#required' => FALSE,
- );
- $form['proposal_type'] = array(
- '#type' => 'hidden',
- '#default_value' => '1',
- '#required' => FALSE,
- );
- $form['reference'] = array(
- '#type' => 'textarea',
- '#title' => t('Reference'),
- '#required' => TRUE,
- '#size' => 1000,
- '#attributes' =>array('placeholder' =>'Links of the syllabus must be provided....'),
- );
- $form['preference1'] = array(
- '#type' => 'fieldset',
- '#title' => t('Book Preference'),
- '#collapsible' => TRUE,
- '#collapsed' => FALSE,
- );
- $form['preference1']['book1'] = array(
- '#type' => 'textfield',
- '#title' => t('Title of the book'),
- '#size' => 30,
- '#maxlength' => 100,
- '#required' => TRUE,
- '#default_value' => $row1->book,
- '#disabled' => ($row1->book?TRUE:FALSE),
- );
- $form['preference1']['author1'] = array(
- '#type' => 'textfield',
- '#title' => t('Author Name'),
- '#size' => 30,
- '#maxlength' => 100,
- '#required' => TRUE,
- '#default_value' => $row1->author,
- '#disabled' => ($row1->author?TRUE:FALSE),
- );
- $form['preference1']['isbn1'] = array(
- '#type' => 'textfield',
- '#title' => t('ISBN No'),
- '#size' => 30,
- '#maxlength' => 25,
- '#required' => TRUE,
- '#default_value' => $row1->isbn,
- '#disabled' => ($row1->isbn?TRUE:FALSE),
- );
- $form['preference1']['publisher1'] = array(
- '#type' => 'textfield',
- '#title' => t('Publisher & Place'),
- '#size' => 30,
- '#maxlength' => 50,
- '#required' => TRUE,
- '#default_value' => $row1->publisher,
- );
- $form['preference1']['edition1'] = array(
- '#type' => 'textfield',
- '#title' => t('Edition'),
- '#size' => 4,
- '#maxlength' => 2,
- '#required' => TRUE,
- '#default_value' => $row1->edition,
- );
- $form['preference1']['year1'] = array(
- '#type' => 'textfield',
- '#title' => t('Year of pulication'),
- '#size' => 4,
- '#maxlength' => 4,
- '#required' => TRUE,
- '#default_value' => $row1->year,
- );
- $form['preference1']['book_category_1'] = array(
- '#type' => 'select',
- '#title' => t('Category'),
- '#options' => _tbc_list_of_category(),
- '#required' => TRUE,
- );
- $form['samplefile'] = array(
- '#type' => 'fieldset',
- '#title' => t('<span class="form-required form-item" title="This field is required.">Sample Source Files *</span>'),
- '#collapsible' => FALSE,
- '#collapsed' => FALSE,
- );
- $form['samplefile']['samplefile1'] = array(
- '#type' => 'file',
- '#title' => t('Upload sample source file'),
- '#size' => 48,
- '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' .
- t('<span style="color:red;">Allowed file extensions : ') . variable_get('textbook_companion_sample_source_file_extensions', '').'</span>',
-
- );
-
- $form['termconditions'] = array(
- '#type' => 'checkboxes',
- '#title' => t('Terms And Conditions'),
- '#options' => array(
- 'status' => t('<a href="term-and-conditions" target="_blank">I agree to the Terms and Conditions</a>'),),
- '#required' => TRUE,
- );
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Submit')
- );
-
- return $form;
-}
-function book_proposal_nonaicte_form_validate($form, &$form_state)
-{
- /* mobile */
- if (!preg_match('/^[0-9\ \+]{0,15}$/', $form_state['values']['mobile']))
- form_set_error('mobile', t('Invalid mobile number'));
-
- /* date of completion */
- if (!preg_match('/^[0-9]{1,2}-[0-9]{1,2}-[0-9]{4}$/', $form_state['values']['completion_date']))
- form_set_error('completion_date', t('Invalid expected date of completion'));
-
- list($d, $m, $y) = explode('-', $form_state['values']['completion_date']);
- $d = (int)$d; $m = (int)$m; $y = (int)$y;
- if (!checkdate($m, $d, $y))
- form_set_error('completion_date', t('Invalid expected date of completion'));
- if (mktime(0, 0, 0, $m, $d, $y) <= time())
- form_set_error('completion_date', t('Expected date of completion should be in future'));
-
- /* edition */
- if (!preg_match('/^[1-9][0-9]{0,1}$/', $form_state['values']['edition1']))
- form_set_error('edition1', t('Invalid edition for Book Preference 1'));
-
-
- /* year of publication */
- if (!preg_match('/^[1-3][0-9][0-9][0-9]$/', $form_state['values']['year1']))
- form_set_error('year1', t('Invalid year of pulication for Book Preference 1'));
-
- /* year of publication */
- $cur_year = date('Y');
- if ((int)$form_state['values']['year1'] > $cur_year)
- form_set_error('year1', t('Year of pulication should be not in the future for Book Preference 1'));
-
-
- /* isbn */
- if (!preg_match('/^[0-9\-xX]+$/', $form_state['values']['isbn1']))
- form_set_error('isbn1', t('Invalid ISBN for Book Preference 1'));
-
- if (!preg_match('/^\d+(?:\.\d+)+/', $form_state['values']['version']))
- form_set_error('version', t('Please enter correct version in speacifed format'));
-
- if($form_state['values']['country']=='Others'){
- if($form_state['values']['other_country']== ''){
- form_set_error('other_country', t('Enter country name'));
- // $form_state['values']['country'] = $form_state['values']['other_country'];
- }else{
- $form_state['values']['country'] = $form_state['values']['other_country'];
- }
- if($form_state['values']['other_state']== ''){
- form_set_error('other_state', t('Enter state name'));
- // $form_state['values']['country'] = $form_state['values']['other_country'];
- }else{
- $form_state['values']['all_state'] = $form_state['values']['other_state'];
- }
- if($form_state['values']['other_city']== ''){
- form_set_error('other_city', t('Enter city name'));
- // $form_state['values']['country'] = $form_state['values']['other_country'];
- }else{
- $form_state['values']['city'] = $form_state['values']['other_city'];
- }
- }else{
- if($form_state['values']['country']== ''){
- form_set_error('country', t('Select country name'));
- // $form_state['values']['country'] = $form_state['values']['other_country'];
- }
- if($form_state['values']['all_state']== ''){
- form_set_error('all_state', t('Select state name'));
- // $form_state['values']['country'] = $form_state['values']['other_country'];
- }
- if($form_state['values']['city']== ''){
- form_set_error('city', t('Select city name'));
- // $form_state['values']['country'] = $form_state['values']['other_country'];
- }
-
-
- }
-
-
- if (isset($_FILES['files']))
- {
- /* check if atleast one source or result file is uploaded */
- if ( ! ($_FILES['files']['name']['samplefile1']))
- form_set_error('samplefile1', t('Please upload sample code main or source file.'));
-
- /* check for valid filename extensions */
- foreach ($_FILES['files']['name'] as $file_form_name => $file_name)
- {
- if ($file_name)
- {
- /* checking file type */
- if (strstr($file_form_name, 'sample'))
- $file_type = 'S';
-
- else
- $file_type = 'U';
-
- $allowed_extensions_str = '';
- switch ($file_type)
- {
- case 'S':
- $allowed_extensions_str = variable_get('textbook_companion_sample_source_file_extensions', '');
- break;
-
- }
- $allowed_extensions = explode(',' , $allowed_extensions_str);
- $allowd_file = strtolower($_FILES['files']['name'][$file_form_name]);
- $temp_extension = end(explode('.', $allowd_file));
- if (!in_array($temp_extension, $allowed_extensions))
- form_set_error($file_form_name, t('Only file with ' . $allowed_extensions_str . ' extensions can be uploaded.'));
- if ($_FILES['files']['size'][$file_form_name] <= 0)
- form_set_error($file_form_name, t('File size cannot be zero.'));
-
- /* check if valid file name */
- if (!textbook_companion_check_valid_filename($_FILES['files']['name'][$file_form_name]))
- form_set_error($file_form_name, t('Invalid file name specified. Only alphabets and numbers are allowed as a valid filename.'));
-
-
- }
- }
- }
-
- return;
-
-}
-
-function book_proposal_nonaicte_form_submit($form, &$form_state)
-{
- global $user;
- $root_path = textbook_companion_samplecode_path();
- $selections = variable_get("aicte_".$user->uid, "");
- $tbc_to_emails = variable_get("textbook_companion_emails_all");
-
-
- if (!$user->uid) {
- drupal_set_message('It is mandatory to login on this website to access the proposal form', 'error');
- return;
- }
-
- /* completion date to timestamp */
- list($d, $m, $y) = explode('-', $form_state['values']['completion_date']);
- $completion_date_timestamp = mktime(0, 0, 0, $m, $d, $y);
-
- /* Reasons for suggesting a book*/
-
-
- if (isset($_POST['reason'])) {
-
- if(!($form_state['values']['other_reason'])){
-
- $my_reason = implode(", ", $_POST['reason']);
-
- }
-
- else{
- $my_reason = implode(", ", $_POST['reason']);
- $my_reason = $my_reason."-"." ".$form_state['values']['other_reason'];
- }
- }
-
- /************************************/
-
- $scilab_version = 'scilab ' . $form_state['values']['version'];
-
- $query = "
-INSERT INTO {textbook_companion_proposal}
- (uid, approver_uid, full_name, mobile, gender, how_project, course, branch, university, country, city, pincode, state, faculty, reviewer, reference, completion_date, creation_date, approval_date, proposal_status, message, scilab_version, operating_system, teacher_email, proposal_type, reason, samplefilepath) VALUES (:uid, :approver_uid, :full_name, :mobile, :gender, :how_project, :course, :branch, :university, :country, :city, :pincode, :state,
-:faculty, :reviewer, :reference, :completion_date, :creation_date, :approval_date, :proposal_status, :message, :scilab_version,
- :operating_system, :teacher_email, :proposal_type, :reason, :samplefilepath)
-";
-
- // $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"=> 'Not available',
- ":course"=> $form_state['values']['course'],
- ":branch"=> $form_state['values']['branch'],
- ":university"=> $form_state['values']['university'],
- ":country" => $form_state['values']['country'],
- ":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,
- ":samplefilepath"=>""
- );
-//var_dump($args);
- $result = db_query($query, $args, array('return' => Database::RETURN_INSERT_ID));
-
- $dest_path = $result . '/';
-
- if (!is_dir($root_path . $dest_path)){
- mkdir($root_path . $dest_path);
-}
-
-/* uploading files */
- foreach ($_FILES['files']['name'] as $file_form_name => $file_name)
- {
- if ($file_name)
- {
- /* checking file type */
- $file_type = 'S';
-
- if (file_exists($root_path . $dest_path . $_FILES['files']['name'][$file_form_name]))
- {
- drupal_set_message(t("Error uploading file. File !filename already exists.", array('!filename' => $_FILES['files']['name'][$file_form_name])), 'error');
- return;
- }
-
- /* uploading file */
- if (move_uploaded_file($_FILES['files']['tmp_name'][$file_form_name], $root_path . $dest_path . $_FILES['files']['name'][$file_form_name]))
- {
- $query = "UPDATE {textbook_companion_proposal} SET samplefilepath = :samplefilepath WHERE id = :id";
- $args = array(
- ":samplefilepath" => $dest_path . $_FILES['files']['name'][$file_form_name],
- ":id" =>$result,
- );
- $updateresult = db_query($query, $args);
-
- drupal_set_message($file_name . ' uploaded successfully.', 'status');
- } else {
- drupal_set_message('Error uploading file : ' . $dest_path . $file_name, 'error');
- }
- }
- }
-
-
- if (!$result)
- {
- drupal_set_message(t('Error receiving your proposal. Please try again.'), 'error');
- return;
- }
- /* proposal id */
-
- $proposal_id = $result;
-
- /* inserting first book preference */
- if ($form_state['values']['book1'])
- {
-
-$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"=> $form_state['values']['book_category_1'],
- ":approval_status"=> 0,
- ":nonaicte_book"=> 1,
- );
-
- $result = db_query($query, $args);
-
- if (!$result)
- {
- drupal_set_message(t('Error receiving your first book preference.'), 'error');
- }
- }
-
- /* sending email */
- $email_to = $user->mail;
- $from = variable_get('textbook_companion_from_email', '');
- $bcc = variable_get('textbook_companion_emails', '');
- $cc = variable_get('textbook_companion_cc_emails', '');
-
- $params['nonaicte_proposal_received']['proposal_id'] = $proposal_id;
- $params['nonaicte_proposal_received']['user_id'] = $user->uid;
- $params['nonaicte_proposal_received']['headers']=array('From'=>$from,'MIME-Version'=> '1.0',
- 'Content-Type'=> 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
- 'Content-Transfer-Encoding' => '8Bit',
- 'X-Mailer'=> 'Drupal','Cc' => $cc, 'Bcc' => $bcc);
-
- if (!drupal_mail('textbook_companion', 'nonaicte_proposal_received', $email_to , language_default(), $params, $from, TRUE))
- drupal_set_message('Error sending email message.', 'error');
-
- drupal_set_message(t('We have received your book proposal. We will get back to you soon.'), 'status');
- drupal_goto('');
+ if (!drupal_mail('textbook_companion', 'standard', $email_to, language_default(), $params, variable_get('textbook_companion_from_email', NULL), TRUE))
+ drupal_set_message('Error sending email message.', 'error');
+ return FALSE;
+ } //!unlink($root_path . $file_data->filepath)
+ else
+ {
+ /* deleting example files database entries */
+ /*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;
+ }
}
-
-function del_book_pdf($book_id)
+function textbook_companion_init()
{
- $root_path = textbook_companion_path();
- $dir_path = $root_path . "latex/";
- $pdf_filename = "book_" . $book_id . ".pdf";
- if (file_exists($dir_path . $pdf_filename))
- unlink($dir_path . $pdf_filename);
-}
-
-function _tbc_list_of_states(){
- $states = array(0 => '-Select-');
- $query = db_select('list_states_of_india');
- $query->fields('list_states_of_india');
-
- //$query->orderBy('', '');
- $states_list = $query->execute();
- while ($states_list_data = $states_list->fetchObject())
- {
- $states[$states_list_data->state] = $states_list_data->state;
- }
- return $states;
-}
-function _tbc_list_of_cities(){
- $city = array(0 => '-Select-');
- $query = db_select('list_cities_of_india');
- $query->fields('list_cities_of_india');
- $query->orderBy('city', 'ASC');
- $city_list = $query->execute();
- while ($city_list_data = $city_list->fetchObject())
- {
- $city[$city_list_data->city] = $city_list_data->city;
- }
- return $city;
+ $path = drupal_get_path('module', 'textbook_companion');
+ drupal_add_css($path . '/css/textbook_companion.css');
+ drupal_add_js($path . '/js/textbook_companion.js');
+ drupal_add_js($path . '/js/jquery-1.7.1.js');
}
-function _tbc_list_of_departments(){
-
- $query = db_select('list_of_departments');
- $query->fields('list_of_departments');
- $query->orderBy('id', 'DESC');
- $department_list = $query->execute();
- while ($department_list_data = $department_list->fetchObject())
- {
- $department[$department_list_data->department] = $department_list_data->department;
- }
- return $department;
-}
-function _tbc_list_of_category($category_id=NULL){
- if($category_id==NULL){
- $query = db_select('list_of_category');
- $query->fields('list_of_category');
- $query->orderBy('id', 'ASC');
- $category_list = $query->execute();
- }else{
- $query = db_select('list_of_category');
- $query->fields('list_of_category');
- $query->condition('category_id', $category_id);
- $query->orderBy('id', 'ASC');
- $category_list = $query->execute();
- }
- while ($category_list_data = $category_list->fetchObject())
- {
- $category[$category_list_data->category_id] = $category_list_data->category_name;
- }
- return $category;
-}
-
-function textbook_companion_init(){
-
- $path = drupal_get_path('module', 'textbook_companion');
- drupal_add_css($path . '/css/textbook_companion.css');
- drupal_add_js($path . '/js/textbook_companion.js');
- drupal_add_js($path . '/js/jquery-1.7.1.js');
-
-}
-