summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-x.gitignore2
-rwxr-xr-xcheque_contact.inc38
-rwxr-xr-xcode.inc1185
-rwxr-xr-xcode_approval.inc2769
-rwxr-xr-xdependency.inc8
-rwxr-xr-xdependency_approval.inc8
-rwxr-xr-xdownload.inc506
-rwxr-xr-xeditcode.inc1355
-rwxr-xr-xeditcodeadmin.inc881
-rwxr-xr-xfull_download.inc345
-rwxr-xr-xgeneral.inc728
-rwxr-xr-xmanage_proposal.inc3579
-rwxr-xr-xpdf/151
-rwxr-xr-xpdf/generate_pdf.inc511
-rwxr-xr-xpdf/images/bg.pngbin0 -> 17983 bytes
-rwxr-xr-xpdf/images/dwsim_logo.pngbin6200 -> 0 bytes
-rwxr-xr-xpdf/images/fossee.pngbin12198 -> 17983 bytes
-rwxr-xr-xpdf/images/garland_logo.pngbin7971 -> 0 bytes
-rwxr-xr-xpdf/images/garland_logo2.pngbin37271 -> 0 bytes
-rwxr-xr-xpdf/images/garland_logo4.pngbin4018 -> 0 bytes
-rwxr-xr-xpdf/images/iitb.pngbin0 -> 21635 bytes
-rwxr-xr-xpdf/images/sign.pngbin41739 -> 0 bytes
-rw-r--r--pdf/images/verify_content.pngbin0 -> 35885 bytes
-rwxr-xr-xpdf/list_all_certificates.inc170
-rwxr-xr-xpdf/list_all_form_pdf.inc67
-rwxr-xr-xpdf/phpqrcode/CHANGELOG38
-rwxr-xr-xpdf/phpqrcode/INSTALL67
-rwxr-xr-xpdf/phpqrcode/LICENSE165
-rwxr-xr-xpdf/phpqrcode/README45
-rwxr-xr-xpdf/phpqrcode/VERSION2
-rwxr-xr-xpdf/phpqrcode/bindings/tcpdf/qrcode.php2875
-rwxr-xr-xpdf/phpqrcode/phpqrcode.php3312
-rwxr-xr-xpdf/phpqrcode/qrbitstream.php180
-rwxr-xr-xpdf/phpqrcode/qrconfig.php17
-rwxr-xr-xpdf/phpqrcode/qrconst.php54
-rwxr-xr-xpdf/phpqrcode/qrencode.php502
-rwxr-xr-xpdf/phpqrcode/qrimage.php95
-rwxr-xr-xpdf/phpqrcode/qrinput.php729
-rwxr-xr-xpdf/phpqrcode/qrlib.php43
-rwxr-xr-xpdf/phpqrcode/qrmask.php328
-rwxr-xr-xpdf/phpqrcode/qrrscode.php210
-rwxr-xr-xpdf/phpqrcode/qrspec.php592
-rwxr-xr-xpdf/phpqrcode/qrsplit.php311
-rwxr-xr-xpdf/phpqrcode/qrtools.php172
-rwxr-xr-xpdf/phpqrcode/tools/merge.bat2
-rwxr-xr-xpdf/phpqrcode/tools/merge.php70
-rwxr-xr-xpdf/phpqrcode/tools/merge.sh2
-rwxr-xr-xpdf/phpqrcode/tools/merged_config.php17
-rwxr-xr-xpdf/phpqrcode/tools/merged_header.php36
-rwxr-xr-xpdf/temp.inc58
-rwxr-xr-xpdf/temp_prcode/generated_qrcode.pngbin0 -> 459 bytes
-rwxr-xr-xpdf/temp_prcode/qrcode_name.pngbin0 -> 380 bytes
-rwxr-xr-xpdf/verify_certificates.inc96
-rwxr-xr-xrun.inc1014
-rwxr-xr-xsettings.inc136
-rwxr-xr-xtextbook_companion.module7044
56 files changed, 20023 insertions, 10392 deletions
diff --git a/.gitignore b/.gitignore
index 8d25f50..e0a272a 100755
--- a/.gitignore
+++ b/.gitignore
@@ -40,3 +40,5 @@ xmlrpc.php
*.swo
*.swp
*~
+*.*~
+*.bkp
diff --git a/cheque_contact.inc b/cheque_contact.inc
index 65208fd..55c0af0 100755
--- a/cheque_contact.inc
+++ b/cheque_contact.inc
@@ -95,16 +95,16 @@ function paper_submission_form_submit($form, &$form_state)
{
/* sending email */
$book_user = user_load($proposal_data->uid);
- $param['proposal_completed']['proposal_id'] = $proposal_id;
- $param['proposal_completed']['user_id'] = $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', 'internship_form', $email_to , language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE))
+ if (!drupal_mail('textbook_companion', 'internship_form', $email_to , language_default(), $params, 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))
+ if (!drupal_mail('textbook_companion', 'internship_form_not', $email_to , language_default(), $params, 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');
}
@@ -117,16 +117,16 @@ function paper_submission_form_submit($form, &$form_state)
{
/* sending email */
$book_user = user_load($proposal_data->uid);
- $param['proposal_completed']['proposal_id'] = $proposal_id;
- $param['proposal_completed']['user_id'] = $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', 'copyrighttransfer_form', $email_to , language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE))
+ if (!drupal_mail('textbook_companion', 'copyrighttransfer_form', $email_to , language_default(), $params, 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))
+ if (!drupal_mail('textbook_companion', 'copyrighttransfer_form_not', $email_to , language_default(), $params, 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');
}
@@ -139,16 +139,16 @@ function paper_submission_form_submit($form, &$form_state)
{
/* sending email */
$book_user = user_load($proposal_data->uid);
- $param['proposal_completed']['proposal_id'] = $proposal_id;
- $param['proposal_completed']['user_id'] = $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', 'undertakingform_form', $email_to , language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE))
+ if (!drupal_mail('textbook_companion', 'undertakingform_form', $email_to , language_default(), $params, 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))
+ if (!drupal_mail('textbook_companion', 'undertakingform_form_not', $email_to , language_default(), $params, 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');
}
@@ -985,10 +985,10 @@ function cheque_status_form_submit($form, &$form_state)
$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;
+ $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', '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(), $params, 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');
}
@@ -1027,16 +1027,16 @@ function cheque_status_form_submit($form, &$form_state)
{
/* sending email */
$book_user = user_load($proposal_data->uid);
- $param['proposal_completed']['proposal_id'] = $proposal_id;
- $param['proposal_completed']['user_id'] = $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', 'remark', $email_to , language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE))
+ if (!drupal_mail('textbook_companion', 'remark', $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('Remark Updated. User has been notified'), 'status');
}
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(), $params, 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');
}
diff --git a/code.inc b/code.inc
index 069f2e6..dd1ebd5 100755
--- a/code.inc
+++ b/code.inc
@@ -1,626 +1,599 @@
<?php
// $Id$
function upload_examples()
- {
- return drupal_get_form('upload_examples_form');
- }
-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);*/
- $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', 'textbook-companion/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', 'textbook-companion/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;
-case 5:
- drupal_set_message(t('You have submitted your all codes.'), 'status');
- drupal_goto('');
- return;
- 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);*/
- $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;
- }
- $form['#attributes'] = array(
- 'enctype' => "multipart/form-data"
- );
-$form['book_details']['pref_id'] = array(
- '#type' => 'hidden',
- '#value' => $preference_data->id,
- );
- $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;
- }
- $form['number'] = array(
- '#type' => 'select',
- '#title' => t('Chapter No'),
- '#options' => $options,
- '#multiple' => FALSE,
- '#size' => 1,
- '#required' => TRUE,
- '#ajax' => array(
- 'callback' => 'ajax_chapter_name_callback',
- ),
- );
- $form['name'] = array(
- '#type' => 'textfield',
- '#title' => t('Title of the Chapter'),
- '#size' => 40,
- '#maxlength' => 255,
- '#required' => TRUE,
- '#prefix' => '<div id="ajax-chapter-name-replace">',
- '#suffix' => '</div>',
- );
- $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 as zip (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('<span style="color:red;">Allowed file extensions : ') . variable_get('textbook_companion_source_extensions', '') . '</span>'
- );
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Submit')
- );
- $form['cancel'] = array(
- '#type' => 'markup',
- '#value' => l(t('Cancel'), 'textbook-companion/code')
- );
- return $form;
- }
+{
+ return drupal_get_form('upload_examples_form');
+}
+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);*/
+ $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', 'textbook-companion/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', 'textbook-companion/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;
+ case 5:
+ drupal_set_message(t('You have submitted your all codes.'), 'status');
+ drupal_goto('');
+ return;
+ 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_data
+ $form['#attributes'] = array(
+ 'enctype' => "multipart/form-data"
+ );
+ $form['book_details']['pref_id'] = array(
+ '#type' => 'hidden',
+ '#value' => $preference_data->id
+ );
+ $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++
+ $form['number'] = array(
+ '#type' => 'select',
+ '#title' => t('Chapter No'),
+ '#options' => $options,
+ '#multiple' => FALSE,
+ '#size' => 1,
+ '#required' => TRUE,
+ '#ajax' => array(
+ 'callback' => 'ajax_chapter_name_callback'
+ )
+ );
+ $form['name'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Title of the Chapter'),
+ '#size' => 40,
+ '#maxlength' => 255,
+ '#required' => TRUE,
+ '#prefix' => '<div id="ajax-chapter-name-replace">',
+ '#suffix' => '</div>'
+ );
+ $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 as zip (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('<span style="color:red;">Allowed file extensions : ') . variable_get('textbook_companion_source_extensions', '') . '</span>'
+ );
+ $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']))
- form_set_error('sourcefile1', t('Please upload source file.'));
- /* check for valid filename extensions */
- foreach ($_FILES['files']['name'] as $file_form_name => $file_name)
- {
- if ($file_name)
- {
- $allowed_extensions_str = variable_get('textbook_companion_source_extensions', '');
- $allowed_extensions = explode(',', $allowed_extensions_str);
- $temp_ext = explode('.', strtolower($_FILES['files']['name'][$file_form_name]));
- $temp_extension = end($temp_ext);
- //$temp_extension = substr($_FILES['files']['name'][$file_form_name], strripos($_FILES['files']['name'][$file_form_name], '.')); // get file name
- //var_dump($temp_extension); die;
- 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.'));*/
- }
- }
- }
- }
+{
+ 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']))
+ form_set_error('sourcefile1', t('Please upload source file.'));
+ /* check for valid filename extensions */
+ foreach ($_FILES['files']['name'] as $file_form_name => $file_name) {
+ if ($file_name) {
+ $allowed_extensions_str = variable_get('textbook_companion_source_extensions', '');
+ $allowed_extensions = explode(',', $allowed_extensions_str);
+ $temp_ext = explode('.', strtolower($_FILES['files']['name'][$file_form_name]));
+ $temp_extension = end($temp_ext);
+ //$temp_extension = substr($_FILES['files']['name'][$file_form_name], strripos($_FILES['files']['name'][$file_form_name], '.')); // get file name
+ //var_dump($temp_extension); die;
+ 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'])
+}
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', 'textbook-companion/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', 'textbook-companion/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;
-case 5:
- drupal_set_message(t('You have submmited your all codes'), '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);*/
- $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 **************************/
- $query = db_select('textbook_companion_preference');
- $query->fields('textbook_companion_preference');
- $query->condition('proposal_id', $proposal_data->id);
- $query->condition('approval_status', 1);
- $result = $query->execute()->rowCount();
- if ($result > 1)
- {
- drupal_set_message(t('You cannot upload your code. This name of book directory alrady preasent in directory folder, please contact to administrator.'), 'error');
- return;
- }
- $proposal_directory = $preference_data->directory_name;
- $dest_path = $proposal_directory . '/';
- if (!is_dir($root_path . $dest_path)){
- if(!mkdir($root_path . $dest_path))
- {
- drupal_set_message(t('You cannot upload your code. Error in creating directory'), 'error');
- }
- }
- /* 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_id = $preference_data->id;
- $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'); */
- $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']);*/
- $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);
- $filepath = 'CH' . $form_state['values']['number'] . '/' . 'EX' . $form_state['values']['example_number'] . '/';
- /* 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} (chapter_id, number, caption, approval_date, approval_status, timestamp) VALUES (:chapter_id, :number, :caption, :approval_date,:approval_status, :timestamp)";
- $args = array(
- ":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 */
- $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]))
- {
- /* 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, filename, filepath,filemime, filesize, filetype, timestamp)
+{
+ 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', 'textbook-companion/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', 'textbook-companion/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;
+ case 5:
+ drupal_set_message(t('You have submmited your all codes'), '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_data
+ /************************ end approve book details **************************/
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('proposal_id', $proposal_data->id);
+ $query->condition('approval_status', 1);
+ $result = $query->execute()->rowCount();
+ if ($result > 1) {
+ drupal_set_message(t('You cannot upload your code. This name of book directory alrady preasent in directory folder, please contact to administrator.'), 'error');
+ return;
+ } //$result > 1
+ $proposal_directory = $preference_data->directory_name;
+ $dest_path = $proposal_directory . '/';
+ if (!is_dir($root_path . $dest_path)) {
+ if (!mkdir($root_path . $dest_path)) {
+ drupal_set_message(t('You cannot upload your code. Error in creating directory'), 'error');
+ } //!mkdir($root_path . $dest_path)
+ } //!is_dir($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_id = $preference_data->id;
+ $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'); */
+ $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;
+ } //!$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;
+ } //$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);
+ $filepath = 'CH' . $form_state['values']['number'] . '/' . 'EX' . $form_state['values']['example_number'] . '/';
+ /* 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} (chapter_id, number, caption, approval_date, approval_status, timestamp) VALUES (:chapter_id, :number, :caption, :approval_date,:approval_status, :timestamp)";
+ $args = array(
+ ":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 */
+ $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])) {
+ /* 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, filename, filepath,filemime, filesize, filetype, timestamp)
VALUES (:example_id, :filename ,:filepath,:filemime, :filesize, :filetype, :timestamp)";
- $args = array(
- ":example_id" => $example_id,
- ":filename" => $_FILES['files']['name'][$file_form_name],
- ":filepath" => $filepath . $_FILES['files']['name'][$file_form_name],
- ":filemime" => 'application/zip',
- ":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;
- $param['example_uploaded']['example_id'] = $example_id;
- $param['example_uploaded']['user_id'] = $user->uid;
- if (!drupal_mail('textbook_companion', 'example_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');
- }
+ $args = array(
+ ":example_id" => $example_id,
+ ":filename" => $_FILES['files']['name'][$file_form_name],
+ ":filepath" => $filepath . $_FILES['files']['name'][$file_form_name],
+ ":filemime" => 'application/zip',
+ ":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');
+ } //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;
+ $params['example_uploaded']['example_id'] = $example_id;
+ $params['example_uploaded']['user_id'] = $user->uid;
+ if (!drupal_mail('textbook_companion', 'example_uploaded', $email_to, language_default(), $params, variable_get('textbook_companion_from_email', NULL), 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);
- //var_dump($example_id);die;
- /* 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);*/
- $query = db_select('textbook_companion_chapter');
- $query->fields('textbook_companion_chapter');
- $query->condition('id', $example_data->chapter_id);
- $query->range(0, 1);
- $result = $query->execute();
- $chapter_data = $result->fetchObject();
- if (!$chapter_data)
- {
- drupal_set_message('You do not have permission to delete this example.', 'error');
- 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);*/
- $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);*/
- $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;
- $param['example_deleted_user']['book_title'] = $preference_data->book;
- $param['example_deleted_user']['chapter_title'] = $chapter_data->name;
- $param['example_deleted_user']['example_number'] = $example_data->number;
- $param['example_deleted_user']['example_caption'] = $example_data->caption;
- $param['example_deleted_user']['user_id'] = $user->uid;
- if (!drupal_mail('textbook_companion', 'example_deleted_user', $email_to, language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE))
- drupal_set_message('Error sending email message.', 'error');
- }
- else
- {
- drupal_set_message('Error deleting example.', 'status');
- }
- drupal_goto('textbook-companion/code');
- return;
- }
+{
+ global $user;
+ $root_path = textbook_companion_path();
+ $example_id = arg(3);
+ //var_dump($example_id);die;
+ /* 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;
+ } //!$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->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;
+ } //!$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;
+ } //!$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;
+ } //!$proposal_data
+ /* deleting example files */
+ if (delete_example($example_data->id)) {
+ drupal_set_message('Example deleted.', 'status');
+ /* sending email */
+ $email_to = $user->mail;
+ $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;
+ if (!drupal_mail('textbook_companion', 'example_deleted_user', $email_to, language_default(), $params, variable_get('textbook_companion_from_email', NULL), 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");*/
- $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;
- }
+{
+ $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 . ')';
+ } //$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");*/
- $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, array(
- 'attributes' => array(
- 'class' => $book_dependency_files_data->preference_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
- );
- }
+{
+ $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, array(
+ 'attributes' => array(
+ 'class' => $book_dependency_files_data->preference_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
+ );
+}
+
+function ajax_chapter_name_callback($form, &$form_state)
+{
+ $pref_id = $form_state['values']['pref_id'];
+ $chapter_number = $form_state['values']['number'];
+ $query = "SELECT * FROM `textbook_companion_chapter` WHERE `preference_id` = :pref_id AND `number` = :number";
+ $arg = array(
+ ':pref_id' => $pref_id,
+ ':number' => $chapter_number
+ );
+ $chapter_name_data = db_query($query, $arg);
+
+ if ($chapter_name_data->rowCount() > 0) {
-function ajax_chapter_name_callback($form, $form_state){
+ //$form['name']['#default_value'] = $chapter_name_data->fetchObject()->name;
+ $form['name']['#value'] = $chapter_name_data->fetchObject()->name;
+ $form['name']['#readonly'] = TRUE;
+ $form['name']['#attributes']['readonly'] = 'readonly';
+ $commands[] = ajax_command_replace("#ajax-chapter-name-replace", drupal_render($form['name']));
- $pref_id = $form_state['values']['pref_id'];
- $chapter_number = $form_state['values']['number'];
- $query = "SELECT * FROM `textbook_companion_chapter` WHERE `preference_id` = :pref_id AND `number` = :number";
- $arg = array(':pref_id'=> $pref_id,':number' => $chapter_number);
- $chapter_name_data = db_query($query, $arg);
-
- if ($chapter_name_data->rowCount() > 0) {
+ } //$chapter_name_data->rowCount() > 0
+ else {
+ $form['name']['#value'] = ' ';
+ $form['name']['#readonly'] = FALSE;
+ //$form['name']['#attributes']['readonly'] = 'readonly';
+ $commands[] = ajax_command_replace("#ajax-chapter-name-replace", drupal_render($form['name']));
- //$form['name']['#default_value'] = $chapter_name_data->fetchObject()->name;
- $form['name']['#value'] = $chapter_name_data->fetchObject()->name;
- $form['name']['#readonly'] = TRUE;
- $form['name']['#attributes']['readonly'] = 'readonly';
- $commands[] = ajax_command_replace("#ajax-chapter-name-replace", drupal_render($form['name']));
-
- }else{
- $form['name']['#value'] = ' ';
- $form['name']['#readonly'] = FALSE;
- //$form['name']['#attributes']['readonly'] = 'readonly';
- $commands[] = ajax_command_replace("#ajax-chapter-name-replace", drupal_render($form['name']));
-
- }
- return array('#type' => 'ajax', '#commands' => $commands);
+ }
+ return array(
+ '#type' => 'ajax',
+ '#commands' => $commands
+ );
}
diff --git a/code_approval.inc b/code_approval.inc
index 71c769e..ab96fa5 100755
--- a/code_approval.inc
+++ b/code_approval.inc
@@ -2,546 +2,549 @@
// $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");*/
- $query = db_select('textbook_companion_example', 'e');
- $query->fields('c', array(
- 'id',
- 'number',
- 'name',
- 'preference_id'
- ));
- $query->addField('c', 'id', 'c_id');
- $query->addField('c', 'number', 'c_number');
- $query->addField('c', 'name', 'c_name');
- $query->addField('c', 'preference_id', 'c_preference_id');
- $query->innerJoin('textbook_companion_chapter', 'c', 'c.id = e.chapter_id');
- $query->condition('e.approval_status', 0);
- $pending_chapter_q = $query->execute();
- if (!$pending_chapter_q) {
- drupal_set_message(t('There are no pending code approvals.'), 'status');
- return '';
- }
- $rows = array();
- while ($row = $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', 'textbook-companion/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;
+ /* 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->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 '';
+ } //!$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', 'textbook-companion/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, $form_state)
+function code_approval_form($form, &$form_state)
{
- /* get a list of unapproved chapters */
- $chapter_id = arg(3);
- /*$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('textbook-companion/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', 'textbook-companion/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', 'textbook-companion/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;
+ /* get a list of unapproved chapters */
+ $chapter_id = arg(3);
+ /*$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();
+ } //$pending_chapter_data = $pending_chapter_q->fetchObject()
+ else {
+ drupal_set_message(t('Invalid chapter selected.'), 'error');
+ drupal_goto('textbook-companion/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', 'textbook-companion/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', 'textbook-companion/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', '');
- $param['example_approved']['example_id'] = $ex_data['example_id'];
- $param['example_approved']['user_id'] = $user_data->uid;
- $param['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(), $param, $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', '');
- $param['example_disapproved']['preference_id'] = $chapter_data->preference_id;
- $param['example_disapproved']['chapter_id'] = $example_data->chapter_id;
- $param['example_disapproved']['example_number'] = $example_data->number;
- $param['example_disapproved']['example_caption'] = $example_data->caption;
- $param['example_disapproved']['user_id'] = $user_data->uid;
- $param['example_disapproved']['message'] = $ex_data['message'];
- $param['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(), $param, $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('textbook-companion/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('textbook-companion/code-approval');
}
/******************************************************************************/
/********************************* BULK APPROVAL ******************************/
/******************************************************************************/
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">',
- '#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(),
- // '#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(
- 'visible' => array(
- array(
- array(
- ':input[name="book_actions"]' => array(
- 'value' => 3
- )
- ),
- 'or',
- array(
- ':input[name="chapter_actions"]' => array(
- 'value' => 3
- )
- ),
- 'or',
- array(
- ':input[name="example_actions"]' => array(
- 'value' => 3
- )
- ),
- 'or',
- array(
- ':input[name="book_actions"]' => array(
- 'value' => 4
- )
- )
- )
- ),
- 'required' => array(
- array(
- array(
- ':input[name="book_actions"]' => array(
- 'value' => 3
- )
- ),
- 'or',
- array(
- ':input[name="chapter_actions"]' => array(
- 'value' => 3
- )
- ),
- 'or',
- array(
- ':input[name="example_actions"]' => array(
- 'value' => 3
- )
- ),
- 'or',
- array(
- ':input[name="book_actions"]' => array(
- 'value' => 4
- )
- )
- )
- )
- )
- );
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Submit'),
- '#states' => array(
- 'invisible' => array(
- ':input[name="book"]' => array(
- 'value' => 0
- )
- )
- )
- );
- return $form;
+ $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">',
+ '#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(),
+ // '#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(
+ 'visible' => array(
+ array(
+ array(
+ ':input[name="book_actions"]' => array(
+ 'value' => 3
+ )
+ ),
+ 'or',
+ array(
+ ':input[name="chapter_actions"]' => array(
+ 'value' => 3
+ )
+ ),
+ 'or',
+ array(
+ ':input[name="example_actions"]' => array(
+ 'value' => 3
+ )
+ ),
+ 'or',
+ array(
+ ':input[name="book_actions"]' => array(
+ 'value' => 4
+ )
+ )
+ )
+ ),
+ 'required' => array(
+ array(
+ array(
+ ':input[name="book_actions"]' => array(
+ 'value' => 3
+ )
+ ),
+ 'or',
+ array(
+ ':input[name="chapter_actions"]' => array(
+ 'value' => 3
+ )
+ ),
+ 'or',
+ array(
+ ':input[name="example_actions"]' => array(
+ 'value' => 3
+ )
+ ),
+ 'or',
+ array(
+ ':input[name="book_actions"]' => array(
+ 'value' => 4
+ )
+ )
+ )
+ )
+ )
+ );
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit'),
+ '#states' => array(
+ 'invisible' => array(
+ ':input[name="book"]' => array(
+ 'value' => 0
+ )
+ )
+ )
+ );
+ return $form;
}
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')) {
- $query = db_select('textbook_companion_preference');
- $query->fields('textbook_companion_preference');
- $query->condition('id', $form_state['values']['book']);
- $result = $query->execute();
- $pref_data = $result->fetchObject();
- $prop_id = $pref_data->proposal_id;
- $query = db_select('textbook_companion_proposal');
- $query->fields('textbook_companion_proposal');
- $query->condition('id', $prop_id);
- $user_query = $query->execute();
- $user_info = $user_query->fetchObject();
- $user_data = user_load($user_info->uid);
- 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_preference');
- $query->fields('textbook_companion_preference');
- $query->condition('id', $form_state['values']['book']);
- $query->condition('approval_status', 1);
- $result = $query->execute();
- $preference_data = $result->fetchObject();
- $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();
- }
- $query = db_update('textbook_companion_preference');
- $query->fields(array(
- 'submited_all_examples_code' => 1
- ));
- $query->condition('id', $form_state['values']['book']);
- $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.'));
- $email_subject = t('[!site_name] Your uploaded Textbook Companion examples have been approved', array(
- '!site_name' => variable_get('site_name', '')
- ));
- $email_body = array(
- 0 => t('
+ 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')) {
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('id', $form_state['values']['book']);
+ $result = $query->execute();
+ $pref_data = $result->fetchObject();
+ $prop_id = $pref_data->proposal_id;
+ $query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal');
+ $query->condition('id', $prop_id);
+ $user_query = $query->execute();
+ $user_info = $user_query->fetchObject();
+ $user_data = user_load($user_info->uid);
+ 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_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('id', $form_state['values']['book']);
+ $query->condition('approval_status', 1);
+ $result = $query->execute();
+ $preference_data = $result->fetchObject();
+ $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();
+ } //$chapter_data = $chapter_q->fetchObject()
+ $query = db_update('textbook_companion_preference');
+ $query->fields(array(
+ 'submited_all_examples_code' => 1
+ ));
+ $query->condition('id', $form_state['values']['book']);
+ $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.'));
+ $email_subject = t('[!site_name] Your uploaded Textbook Companion examples have been approved', array(
+ '!site_name' => variable_get('site_name', '')
+ ));
+ $email_body = array(
+ 0 => t('
Dear !user_name,
@@ -558,41 +561,42 @@ Best Wishes,
!site_name Team,
FOSSEE,IIT Bombay', array(
- '!site_name' => variable_get('site_name', ''),
- '!user_name' => $user_data->name
- ))
- );
- } elseif (($form_state['values']['book_actions'] == 2) && ($form_state['values']['chapter_actions'] == 0) && ($form_state['values']['example_actions'] == 0)) {
- /* pending entire book */
- $query = db_select('textbook_companion_preference');
- $query->fields('textbook_companion_preference');
- $query->condition('id', $form_state['values']['book']);
- $query->condition('approval_status', 1);
- $result = $query->execute();
- $preference_data = $result->fetchObject();
- /*$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 = 0 WHERE chapter_id = %d", $chapter_data->id);*/
- $query = db_update('textbook_companion_example');
- $query->fields(array(
- 'approval_status' => 0
- ));
- $query->condition('chapter_id', $chapter_data->id);
- $num_updated = $query->execute();
- }
- drupal_set_message(t('Pending Review Entire Book.'), 'status');
- /* email */
- /*$email_subject = t('Your uploaded examples have been marked as pending');
- $email_body =array( t('Your all the uploaded examples for the book have been marked as pending to be review. You will be able to see the exmaples after they have been approved by one of our reviewers.'));*/
- $email_subject = t('[!site_name] Your uploaded Textbook Companion examples have been marked as pending', array(
- '!site_name' => variable_get('site_name', '')
- ));
- $email_body = array(
- 0 => t('
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name
+ ))
+ );
+ } //($form_state['values']['book_actions'] == 1) && ($form_state['values']['chapter_actions'] == 0) && ($form_state['values']['example_actions'] == 0)
+ elseif (($form_state['values']['book_actions'] == 2) && ($form_state['values']['chapter_actions'] == 0) && ($form_state['values']['example_actions'] == 0)) {
+ /* pending entire book */
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('id', $form_state['values']['book']);
+ $query->condition('approval_status', 1);
+ $result = $query->execute();
+ $preference_data = $result->fetchObject();
+ /*$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 = 0 WHERE chapter_id = %d", $chapter_data->id);*/
+ $query = db_update('textbook_companion_example');
+ $query->fields(array(
+ 'approval_status' => 0
+ ));
+ $query->condition('chapter_id', $chapter_data->id);
+ $num_updated = $query->execute();
+ } //$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( t('Your all the uploaded examples for the book have been marked as pending to be review. You will be able to see the exmaples after they have been approved by one of our reviewers.'));*/
+ $email_subject = t('[!site_name] Your uploaded Textbook Companion examples have been marked as pending', array(
+ '!site_name' => variable_get('site_name', '')
+ ));
+ $email_body = array(
+ 0 => t('
Dear !user_name,
@@ -610,44 +614,46 @@ Best Wishes,
!site_name Team,
FOSSEE,IIT Bombay', array(
- '!site_name' => variable_get('site_name', ''),
- '!user_name' => $user_data->name
- ))
- );
- } elseif (($form_state['values']['book_actions'] == 3) && ($form_state['values']['chapter_actions'] == 0) && ($form_state['values']['example_actions'] == 0)) {
- if (strlen(trim($form_state['values']['message'])) <= 30) {
- form_set_error('message', t(''));
- drupal_set_message("Please mention the reason for disapproval. Minimum 30 character required", 'error');
- return;
- }
- $query = db_select('textbook_companion_preference');
- $query->fields('textbook_companion_preference');
- $query->condition('id', $form_state['values']['book']);
- $query->condition('approval_status', 1);
- $result = $query->execute();
- $preference_data = $result->fetchObject();
- 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( t('Your all the uploaded examples for the whole book have been marked as dis-approved.
-
- Reason for dis-approval:
-
- ' . $form_state['values']['message']));*/
- $email_subject = t('[!site_name] Your uploaded Textbook Companion examples have been marked as
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name
+ ))
+ );
+ } //($form_state['values']['book_actions'] == 2) && ($form_state['values']['chapter_actions'] == 0) && ($form_state['values']['example_actions'] == 0)
+ elseif (($form_state['values']['book_actions'] == 3) && ($form_state['values']['chapter_actions'] == 0) && ($form_state['values']['example_actions'] == 0)) {
+ if (strlen(trim($form_state['values']['message'])) <= 30) {
+ form_set_error('message', t(''));
+ drupal_set_message("Please mention the reason for disapproval. Minimum 30 character required", 'error');
+ return;
+ } //strlen(trim($form_state['values']['message'])) <= 30
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('id', $form_state['values']['book']);
+ $query->condition('approval_status', 1);
+ $result = $query->execute();
+ $preference_data = $result->fetchObject();
+ 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;
+ } //!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( t('Your all the uploaded examples for the whole book have been marked as dis-approved.
+
+ Reason for dis-approval:
+
+ ' . $form_state['values']['message']));*/
+ $email_subject = t('[!site_name] Your uploaded Textbook Companion examples have been marked as
dis-approved', array(
- '!site_name' => variable_get('site_name', '')
- ));
- $email_body = array(
- 0 => t('
+ '!site_name' => variable_get('site_name', '')
+ ));
+ $email_body = array(
+ 0 => t('
Dear !user_name,
@@ -667,79 +673,81 @@ Best Wishes,
!site_name Team,
FOSSEE,IIT Bombay', array(
- '!site_name' => variable_get('site_name', ''),
- '!user_name' => $user_data->name
- ))
- );
- } elseif (($form_state['values']['book_actions'] == 4) && ($form_state['values']['chapter_actions'] == 0) && ($form_state['values']['example_actions'] == 0)) {
- if (strlen(trim($form_state['values']['message'])) <= 30) {
- form_set_error('message', t(''));
- drupal_set_message("Please mention the reason for disapproval/deletion. Minimum 30 character required", 'error');
- return;
- }
- $query = db_select('textbook_companion_preference');
- $query->fields('textbook_companion_preference');
- $query->condition('id', $form_state['values']['book']);
- $query->condition('approval_status', 1);
- $result = $query->execute();
- $pref_data = $result->fetchObject();
- 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');
- $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);
- */
- $query = db_select('textbook_companion_preference');
- $query->fields('textbook_companion_preference');
- $query->condition('id', $form_state['values']['book']);
- $result = $query->execute();
- $preference_data = $result->fetchObject();
- $proposal_id = $preference_data->proposal_id;
- /*db_query("DELETE FROM {textbook_companion_preference} WHERE proposal_id = %d", $proposal_id);*/
- $query = db_delete('textbook_companion_preference');
- $query->condition('proposal_id', $proposal_id);
- $num_deleted = $query->execute();
- /*db_query("DELETE FROM {textbook_companion_proposal} WHERE id = %d", $proposal_id);*/
- $query = db_delete('textbook_companion_proposal');
- $query->condition('id', $proposal_id);
- $num_deleted = $query->execute();
- drupal_set_message(t('Deleted Book Proposal.'), 'status');
- /* 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']));*/
- $email_subject = t('[!site_name] Your uploaded Textbook Companion examples including the book proposal have been deleted', array(
- '!site_name' => variable_get('site_name', '')
- ));
- $email_body = array(
- 0 => t('
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name
+ ))
+ );
+ } //($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 (strlen(trim($form_state['values']['message'])) <= 30) {
+ form_set_error('message', t(''));
+ drupal_set_message("Please mention the reason for disapproval/deletion. Minimum 30 character required", 'error');
+ return;
+ } //strlen(trim($form_state['values']['message'])) <= 30
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('id', $form_state['values']['book']);
+ $query->condition('approval_status', 1);
+ $result = $query->execute();
+ $pref_data = $result->fetchObject();
+ 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;
+ } //!$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);*/
+ $query = db_delete('textbook_companion_preference');
+ $query->condition('proposal_id', $proposal_id);
+ $num_deleted = $query->execute();
+ /*db_query("DELETE FROM {textbook_companion_proposal} WHERE id = %d", $proposal_id);*/
+ $query = db_delete('textbook_companion_proposal');
+ $query->condition('id', $proposal_id);
+ $num_deleted = $query->execute();
+ drupal_set_message(t('Deleted Book Proposal.'), 'status');
+ /* 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']));*/
+ $email_subject = t('[!site_name] Your uploaded Textbook Companion examples including the book proposal have been deleted', array(
+ '!site_name' => variable_get('site_name', '')
+ ));
+ $email_body = array(
+ 0 => t('
Dear !user_name,
@@ -760,44 +768,46 @@ Best Wishes,
!site_name Team,
FOSSEE,IIT Bombay', array(
- '!site_name' => variable_get('site_name', ''),
- '!user_name' => $user_data->name
- ))
- );
- } 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']);*/
- $query = db_select('textbook_companion_preference');
- $query->fields('textbook_companion_preference');
- $query->condition('id', $form_state['values']['book']);
- $query->condition('approval_status', 1);
- $result = $query->execute();
- $pref_data = $result->fetchObject();
- $query = db_select('textbook_companion_chapter');
- $query->fields('textbook_companion_chapter');
- $query->condition('preference_id', $form_state['values']['book']);
- $query->condition('id', $form_state['values']['chapter']);
- $result = $query->execute();
- $chap_data = $result->fetchObject();
- $query = db_update('textbook_companion_example');
- $query->fields(array(
- 'approval_status' => 1,
- 'approver_uid' => $user->uid
- ));
- $query->condition('chapter_id', $form_state['values']['chapter']);
- $query->condition('approval_status', 0);
- $num_updated = $query->execute();
- 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.'));*/
- $email_subject = t('[!site_name] Your uploaded Textbook Companion examples have been approved', array(
- '!site_name' => variable_get('site_name', '')
- ));
- $email_body = array(
- 0 => t('
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name
+ ))
+ );
+ } //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_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('id', $form_state['values']['book']);
+ $query->condition('approval_status', 1);
+ $result = $query->execute();
+ $pref_data = $result->fetchObject();
+ $query = db_select('textbook_companion_chapter');
+ $query->fields('textbook_companion_chapter');
+ $query->condition('preference_id', $form_state['values']['book']);
+ $query->condition('id', $form_state['values']['chapter']);
+ $result = $query->execute();
+ $chap_data = $result->fetchObject();
+ $query = db_update('textbook_companion_example');
+ $query->fields(array(
+ 'approval_status' => 1,
+ 'approver_uid' => $user->uid
+ ));
+ $query->condition('chapter_id', $form_state['values']['chapter']);
+ $query->condition('approval_status', 0);
+ $num_updated = $query->execute();
+ 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.'));*/
+ $email_subject = t('[!site_name] Your uploaded Textbook Companion examples have been approved', array(
+ '!site_name' => variable_get('site_name', '')
+ ));
+ $email_body = array(
+ 0 => t('
Dear !user_name,
@@ -810,40 +820,41 @@ Best Wishes,
!site_name Team,
FOSSEE,IIT Bombay', array(
- '!site_name' => variable_get('site_name', ''),
- '!user_name' => $user_data->name
- ))
- );
- } elseif (($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_select('textbook_companion_preference');
- $query->fields('textbook_companion_preference');
- $query->condition('id', $form_state['values']['book']);
- $query->condition('approval_status', 1);
- $result = $query->execute();
- $pref_data = $result->fetchObject();
- $query = db_select('textbook_companion_chapter');
- $query->fields('textbook_companion_chapter');
- $query->condition('preference_id', $form_state['values']['book']);
- $query->condition('id', $form_state['values']['chapter']);
- $result = $query->execute();
- $chap_data = $result->fetchObject();
- $query = db_update('textbook_companion_example');
- $query->fields(array(
- '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.'));*/
- $email_subject = t('[!site_name] Your uploaded Textbook Companion examples have been marked as pending', array(
- '!site_name' => variable_get('site_name', '')
- ));
- $email_body = array(
- 0 => t('
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name
+ ))
+ );
+ } //($form_state['values']['book_actions'] == 0) && ($form_state['values']['chapter_actions'] == 1) && ($form_state['values']['example_actions'] == 0)
+ elseif (($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_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('id', $form_state['values']['book']);
+ $query->condition('approval_status', 1);
+ $result = $query->execute();
+ $pref_data = $result->fetchObject();
+ $query = db_select('textbook_companion_chapter');
+ $query->fields('textbook_companion_chapter');
+ $query->condition('preference_id', $form_state['values']['book']);
+ $query->condition('id', $form_state['values']['chapter']);
+ $result = $query->execute();
+ $chap_data = $result->fetchObject();
+ $query = db_update('textbook_companion_example');
+ $query->fields(array(
+ '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.'));*/
+ $email_subject = t('[!site_name] Your uploaded Textbook Companion examples have been marked as pending', array(
+ '!site_name' => variable_get('site_name', '')
+ ));
+ $email_body = array(
+ 0 => t('
Dear !user_name,
@@ -856,46 +867,48 @@ Best Wishes,
!site_name Team,
FOSSEE,IIT Bombay', array(
- '!site_name' => variable_get('site_name', ''),
- '!user_name' => $user_data->name
- ))
- );
- } elseif (($form_state['values']['book_actions'] == 0) && ($form_state['values']['chapter_actions'] == 3) && ($form_state['values']['example_actions'] == 0)) {
- $query = db_select('textbook_companion_preference');
- $query->fields('textbook_companion_preference');
- $query->condition('id', $form_state['values']['book']);
- $query->condition('approval_status', 1);
- $result = $query->execute();
- $pref_data = $result->fetchObject();
- $query = db_select('textbook_companion_chapter');
- $query->fields('textbook_companion_chapter');
- $query->condition('preference_id', $form_state['values']['book']);
- $query->condition('id', $form_state['values']['chapter']);
- $result = $query->execute();
- $chap_data = $result->fetchObject();
- if (strlen(trim($form_state['values']['message'])) <= 30) {
- form_set_error('message', t(''));
- drupal_set_message("Please mention the reason for disapproval. Minimum 30 character required", 'error');
- return;
- }
- 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.
- Reason for dis-approval:' . $form_state['values']['message']));*/
- $email_subject = t('[!site_name] Your uploaded Textbook Companion example have been marked as dis-approved', array(
- '!site_name' => variable_get('site_name', '')
- ));
- $email_body = array(
- 0 => t('
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name
+ ))
+ );
+ } //($form_state['values']['book_actions'] == 0) && ($form_state['values']['chapter_actions'] == 2) && ($form_state['values']['example_actions'] == 0)
+ elseif (($form_state['values']['book_actions'] == 0) && ($form_state['values']['chapter_actions'] == 3) && ($form_state['values']['example_actions'] == 0)) {
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('id', $form_state['values']['book']);
+ $query->condition('approval_status', 1);
+ $result = $query->execute();
+ $pref_data = $result->fetchObject();
+ $query = db_select('textbook_companion_chapter');
+ $query->fields('textbook_companion_chapter');
+ $query->condition('preference_id', $form_state['values']['book']);
+ $query->condition('id', $form_state['values']['chapter']);
+ $result = $query->execute();
+ $chap_data = $result->fetchObject();
+ if (strlen(trim($form_state['values']['message'])) <= 30) {
+ form_set_error('message', t(''));
+ drupal_set_message("Please mention the reason for disapproval. Minimum 30 character required", 'error');
+ return;
+ } //strlen(trim($form_state['values']['message'])) <= 30
+ 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']));*/
+ $email_subject = t('[!site_name] Your uploaded Textbook Companion example have been marked as dis-approved', array(
+ '!site_name' => variable_get('site_name', '')
+ ));
+ $email_body = array(
+ 0 => t('
Dear !user_name,
@@ -911,45 +924,46 @@ Best Wishes,
!site_name Team,
FOSSEE,IIT Bombay', array(
- '!site_name' => variable_get('site_name', ''),
- '!user_name' => $user_data->name
- ))
- );
- } elseif (($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_select('textbook_companion_preference');
- $query->fields('textbook_companion_preference');
- $query->condition('id', $form_state['values']['book']);
- $query->condition('approval_status', 1);
- $result = $query->execute();
- $pref_data = $result->fetchObject();
- $query = db_select('textbook_companion_chapter');
- $query->fields('textbook_companion_chapter');
- $query->condition('preference_id', $form_state['values']['book']);
- $query->condition('id', $form_state['values']['chapter']);
- $result = $query->execute();
- $chap_data = $result->fetchObject();
- $query = db_select('textbook_companion_example');
- $query->fields('textbook_companion_example');
- $query->condition('id', $form_state['values']['example']);
- $result = $query->execute();
- $examp_data = $result->fetchObject();
- $query = db_update('textbook_companion_example');
- $query->fields(array(
- 'approval_status' => 1,
- 'approver_uid' => $user->uid
- ));
- $query->condition('id', $form_state['values']['example']);
- $num_updated = $query->execute();
- 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.'));*/
- $email_subject = t('[!site_name] Your uploaded Textbook Companion example have been approved', array(
- '!site_name' => variable_get('site_name', '')
- ));
- $email_body = array(
- 0 => t('
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name
+ ))
+ );
+ } //($form_state['values']['book_actions'] == 0) && ($form_state['values']['chapter_actions'] == 3) && ($form_state['values']['example_actions'] == 0)
+ elseif (($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_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('id', $form_state['values']['book']);
+ $query->condition('approval_status', 1);
+ $result = $query->execute();
+ $pref_data = $result->fetchObject();
+ $query = db_select('textbook_companion_chapter');
+ $query->fields('textbook_companion_chapter');
+ $query->condition('preference_id', $form_state['values']['book']);
+ $query->condition('id', $form_state['values']['chapter']);
+ $result = $query->execute();
+ $chap_data = $result->fetchObject();
+ $query = db_select('textbook_companion_example');
+ $query->fields('textbook_companion_example');
+ $query->condition('id', $form_state['values']['example']);
+ $result = $query->execute();
+ $examp_data = $result->fetchObject();
+ $query = db_update('textbook_companion_example');
+ $query->fields(array(
+ 'approval_status' => 1,
+ 'approver_uid' => $user->uid
+ ));
+ $query->condition('id', $form_state['values']['example']);
+ $num_updated = $query->execute();
+ 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.'));*/
+ $email_subject = t('[!site_name] Your uploaded Textbook Companion example have been approved', array(
+ '!site_name' => variable_get('site_name', '')
+ ));
+ $email_body = array(
+ 0 => t('
Dear !user_name,
@@ -964,44 +978,45 @@ Best Wishes,
!site_name Team,
FOSSEE,IIT Bombay', array(
- '!site_name' => variable_get('site_name', ''),
- '!user_name' => $user_data->name
- ))
- );
- } elseif (($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_select('textbook_companion_preference');
- $query->fields('textbook_companion_preference');
- $query->condition('id', $form_state['values']['book']);
- $query->condition('approval_status', 1);
- $result = $query->execute();
- $pref_data = $result->fetchObject();
- $query = db_select('textbook_companion_chapter');
- $query->fields('textbook_companion_chapter');
- $query->condition('preference_id', $form_state['values']['book']);
- $query->condition('id', $form_state['values']['chapter']);
- $result = $query->execute();
- $chap_data = $result->fetchObject();
- $query = db_select('textbook_companion_example');
- $query->fields('textbook_companion_example');
- $query->condition('id', $form_state['values']['example']);
- $result = $query->execute();
- $examp_data = $result->fetchObject();
- $query = db_update('textbook_companion_example');
- $query->fields(array(
- '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.'));*/
- $email_subject = t('[!site_name] Your uploaded Textbook Companion example has been marked as pending', array(
- '!site_name' => variable_get('site_name', '')
- ));
- $email_body = array(
- 0 => t('
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name
+ ))
+ );
+ } //($form_state['values']['book_actions'] == 0) && ($form_state['values']['chapter_actions'] == 0) && ($form_state['values']['example_actions'] == 1)
+ elseif (($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_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('id', $form_state['values']['book']);
+ $query->condition('approval_status', 1);
+ $result = $query->execute();
+ $pref_data = $result->fetchObject();
+ $query = db_select('textbook_companion_chapter');
+ $query->fields('textbook_companion_chapter');
+ $query->condition('preference_id', $form_state['values']['book']);
+ $query->condition('id', $form_state['values']['chapter']);
+ $result = $query->execute();
+ $chap_data = $result->fetchObject();
+ $query = db_select('textbook_companion_example');
+ $query->fields('textbook_companion_example');
+ $query->condition('id', $form_state['values']['example']);
+ $result = $query->execute();
+ $examp_data = $result->fetchObject();
+ $query = db_update('textbook_companion_example');
+ $query->fields(array(
+ '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.'));*/
+ $email_subject = t('[!site_name] Your uploaded Textbook Companion example has been marked as pending', array(
+ '!site_name' => variable_get('site_name', '')
+ ));
+ $email_body = array(
+ 0 => t('
Dear !user_name,
@@ -1016,48 +1031,50 @@ Best Wishes,
!site_name Team,
FOSSEE,IIT Bombay', array(
- '!site_name' => variable_get('site_name', ''),
- '!user_name' => $user_data->name
- ))
- );
- } elseif (($form_state['values']['book_actions'] == 0) && ($form_state['values']['chapter_actions'] == 0) && ($form_state['values']['example_actions'] == 3)) {
- if (strlen(trim($form_state['values']['message'])) <= 30) {
- form_set_error('message', t(''));
- drupal_set_message("Please mention the reason for disapproval. Minimum 30 character required", 'error');
- return;
- }
- $query = db_select('textbook_companion_preference');
- $query->fields('textbook_companion_preference');
- $query->condition('id', $form_state['values']['book']);
- $query->condition('approval_status', 1);
- $result = $query->execute();
- $pref_data = $result->fetchObject();
- $query = db_select('textbook_companion_chapter');
- $query->fields('textbook_companion_chapter');
- $query->condition('preference_id', $form_state['values']['book']);
- $query->condition('id', $form_state['values']['chapter']);
- $result = $query->execute();
- $chap_data = $result->fetchObject();
- $query = db_select('textbook_companion_example');
- $query->fields('textbook_companion_example');
- $query->condition('id', $form_state['values']['example']);
- $result = $query->execute();
- $examp_data = $result->fetchObject();
- 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.
- Reason for dis-approval:' . $form_state['values']['message']));*/
- $email_subject = t('[!site_name] Your uploaded Textbook Companion example has been marked as
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name
+ ))
+ );
+ } //($form_state['values']['book_actions'] == 0) && ($form_state['values']['chapter_actions'] == 0) && ($form_state['values']['example_actions'] == 2)
+ elseif (($form_state['values']['book_actions'] == 0) && ($form_state['values']['chapter_actions'] == 0) && ($form_state['values']['example_actions'] == 3)) {
+ if (strlen(trim($form_state['values']['message'])) <= 30) {
+ form_set_error('message', t(''));
+ drupal_set_message("Please mention the reason for disapproval. Minimum 30 character required", 'error');
+ return;
+ } //strlen(trim($form_state['values']['message'])) <= 30
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('id', $form_state['values']['book']);
+ $query->condition('approval_status', 1);
+ $result = $query->execute();
+ $pref_data = $result->fetchObject();
+ $query = db_select('textbook_companion_chapter');
+ $query->fields('textbook_companion_chapter');
+ $query->condition('preference_id', $form_state['values']['book']);
+ $query->condition('id', $form_state['values']['chapter']);
+ $result = $query->execute();
+ $chap_data = $result->fetchObject();
+ $query = db_select('textbook_companion_example');
+ $query->fields('textbook_companion_example');
+ $query->condition('id', $form_state['values']['example']);
+ $result = $query->execute();
+ $examp_data = $result->fetchObject();
+ 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']));*/
+ $email_subject = t('[!site_name] Your uploaded Textbook Companion example has been marked as
dis-approved', array(
- '!site_name' => variable_get('site_name', '')
- ));
- $email_body = array(
- 0 => t('
+ '!site_name' => variable_get('site_name', '')
+ ));
+ $email_body = array(
+ 0 => t('
Dear !user_name,
@@ -1074,523 +1091,529 @@ Best Wishes,
!site_name Team,
FOSSEE,IIT Bombay', array(
- '!site_name' => variable_get('site_name', ''),
- '!user_name' => $user_data->name
- ))
- );
- } else {
- drupal_set_message(t('Please select only one action at a time'), 'error');
- return;
- }
- /****** sending email when everything done ******/
- if ($email_subject) {
- $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', '');
- $param['standard']['subject'] = $email_subject;
- $param['standard']['body'] = $email_body;
- $param['standard']['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', 'standard', $email_to, language_default(), $param, $from, TRUE))
- drupal_set_message('Error sending email message.', 'error');
- }
- } else {
- drupal_set_message(t('You do not have permission to bulk manage code.'), 'error');
- }
- }
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name
+ ))
+ );
+ } //($form_state['values']['book_actions'] == 0) && ($form_state['values']['chapter_actions'] == 0) && ($form_state['values']['example_actions'] == 3)
+ else {
+ drupal_set_message(t('Please select only one action at a time'), 'error');
+ return;
+ }
+ /****** sending email when everything done ******/
+ if ($email_subject) {
+ $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['standard']['subject'] = $email_subject;
+ $params['standard']['body'] = $email_body;
+ $params['standard']['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', 'standard', $email_to, language_default(), $params, $from, 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");*/
- $query = db_select('textbook_companion_preference', 'pp');
- $query->join('textbook_companion_proposal', 'p', 'pp.proposal_id=p.id');
- $query->join('users', 'u', 'p.uid=u.uid');
- $query->fields('u', array(
- 'name'
- ));
- $query->fields('pp', array(
- 'id',
- 'book',
- 'author'
- ));
- $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 . ')' . ' (Proposed by ' . $book_titles_data->name . ')';
- }
- return $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");*/
+ $query = db_select('textbook_companion_preference', 'pp');
+ $query->join('textbook_companion_proposal', 'p', 'pp.proposal_id=p.id');
+ $query->join('users', 'u', 'p.uid=u.uid');
+ $query->fields('u', array(
+ 'name'
+ ));
+ $query->fields('pp', array(
+ 'id',
+ 'book',
+ 'author'
+ ));
+ $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 . ')' . ' (Proposed by ' . $book_titles_data->name . ')';
+ } //$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);*/
- $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;
+ $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 _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;
+ $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;
+ $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;
+ $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', 'textbook-companion/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
- );
+ $commands = array();
+ $book_default_value = $form_state['values']['book'];
+ if ($book_default_value > 0) {
+ $commands[] = ajax_command_html('#ajax_selected_book', l('Download', 'textbook-companion/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']));
+ }
+ 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', 'textbook-companion/full-download/chapter/' . $chapter_default_value) . ' ' . t('(Download all the approved and unapproved examples of the entire chapter)'));
- $form['chapter_actions']['#options'] = _bulk_list_chapter_actions();
- $commands[] = ajax_command_replace('#ajax_selected_chapter_action', drupal_render($form['chapter_actions']));
- $form['example']['#options'] = _ajax_bulk_get_examples($chapter_default_value);
- $commands[] = ajax_command_replace('#ajax_selected_example', drupal_render($form['example']));
- $commands[] = ajax_command_html('#ajax_download_selected_example', '');
- $commands[] = ajax_command_html('#ajax_edit_selected_example', '');
- $form['example_actions']['#options'] = _bulk_list_example_actions();
- $commands[] = ajax_command_replace('#ajax_selected_example_action', drupal_render($form['example_actions']));
- $commands[] = ajax_command_html('#ajax_selected_example_action', '');
- $form['example_files']['#title'] = '';
- $form['example_files']['#markup'] = '';
- $commands[] = ajax_command_replace('#ajax_example_files_list', drupal_render($form['example_files']));
- } else {
- $commands[] = ajax_command_html('#ajax_download_chapter', '');
- $form['chapter_actions']['#options'] = _bulk_list_chapter_actions();
- $commands[] = ajax_command_replace('#ajax_selected_chapter_action', drupal_render($form['chapter_actions']));
- $commands[] = ajax_command_html('#ajax_selected_chapter_action', '');
- $form['example']['#options'] = _ajax_bulk_get_examples();
- $commands[] = ajax_command_replace('#ajax_selected_example', drupal_render($form['example']));
- $commands[] = ajax_command_html('#ajax_selected_example', '');
- $commands[] = ajax_command_html('#ajax_download_selected_example', '');
- $commands[] = ajax_command_html('#ajax_edit_selected_example', '');
- $form['example_files']['#title'] = '';
- $form['example_files']['#markup'] = '';
- $commands[] = ajax_command_replace('#ajax_example_files_list', drupal_render($form['example_files']));
- $form['example_actions']['#options'] = _bulk_list_example_actions();
- $commands[] = ajax_command_replace('#ajax_selected_example_action', drupal_render($form['example_actions']));
- $commands[] = ajax_command_html('#ajax_selected_example_action', '');
- }
- return array(
- '#type' => 'ajax',
- '#commands' => $commands
- );
+ $commands = array();
+ $chapter_default_value = $form_state['values']['chapter'];
+ if ($chapter_default_value > 0) {
+ $commands[] = ajax_command_html('#ajax_download_chapter', l('Download', 'textbook-companion/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', '');
+ }
+ 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, 'textbook-companion/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', 'textbook-companion/download/example/' . $example_list_default_value));
- $commands[] = ajax_command_html('#ajax_edit_selected_example', l('Edit Example', 'code_approval/editcode/' . $example_list_default_value));
- $form['example_actions']['#options'] = _bulk_list_example_actions();
- $commands[] = ajax_command_replace('#ajax_selected_example_action', drupal_render($form['example_actions']));
- //$commands[] = ajax_command_html('#ajax_selected_example_action', '' );
- }
- } else {
- $commands[] = ajax_command_html('#ajax_download_selected_example', '');
- $commands[] = ajax_command_html('#ajax_edit_selected_example', '');
- $form['example_files']['#title'] = '';
- $form['example_files']['#markup'] = '';
- $commands[] = ajax_command_replace('#ajax_example_files_list', drupal_render($form['example_files']));
- $form['example_actions']['#options'] = _bulk_list_example_actions();
- $commands[] = ajax_command_replace('#ajax_selected_example_action', drupal_render($form['example_actions']));
- $commands[] = ajax_command_html('#ajax_selected_example_action', '');
- }
- return array(
- '#type' => 'ajax',
- '#commands' => $commands
- );
+ $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, 'textbook-companion/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);
+ }
+ */
+ /* 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', 'textbook-companion/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', '' );
+ } //$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', '');
+ }
+ 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
- );
+ //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
+ );
}
function edit_code_submission()
{
- /* 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->condition('proposal_status', 1);
- $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->condition('submited_all_examples_code', 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->condition('approval_status', 0);
- $query->range(0, 1);
- $preference_q = $query->execute();
- $preference_data = $preference_q->fetchObject();
- }
- $proposal_status = '';
- switch ($preference_data->submited_all_examples_code) {
- case 0:
- $proposal_status = 'Code Submission Pending';
- break;
- case 1:
- $proposal_status = 'Submitted code for all exmample for book';
- break;
- }
- $proposal_rows[] = array(
- "{$preference_data->book} <br>
+ /* 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->condition('proposal_status', 1);
+ $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->condition('submited_all_examples_code', 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->condition('approval_status', 0);
+ $query->range(0, 1);
+ $preference_q = $query->execute();
+ $preference_data = $preference_q->fetchObject();
+ } //!$preference_data
+ $proposal_status = '';
+ switch ($preference_data->submited_all_examples_code) {
+ case 0:
+ $proposal_status = 'Code Submission Pending';
+ break;
+ case 1:
+ $proposal_status = 'Submitted code for all exmample for book';
+ break;
+ } //$preference_data->submited_all_examples_code
+ $proposal_rows[] = array(
+ "{$preference_data->book} <br>
<em>by {$preference_data->author}</em>",
- l($proposal_data->full_name, 'user/' . $proposal_data->uid),
- $proposal_status,
- l('Edit', 'textbook-companion/code-approval/edit-code-submission/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(
- 'Title of the Book',
- 'Contributor Name',
- 'Status',
- 'Action'
- );
- $output = theme('table', array(
- 'header' => $proposal_header,
- 'rows' => $proposal_rows
- ));
- return $output;
+ l($proposal_data->full_name, 'user/' . $proposal_data->uid),
+ $proposal_status,
+ l('Edit', 'textbook-companion/code-approval/edit-code-submission/edit/' . $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(
+ 'Title of the Book',
+ 'Contributor Name',
+ 'Status',
+ 'Action'
+ );
+ $output = theme('table', array(
+ 'header' => $proposal_header,
+ 'rows' => $proposal_rows
+ ));
+ return $output;
}
function get_edit_code_submission($id = NULL)
{
- if ($id) {
- return drupal_get_form('edit_code_submission_form', $id);
- } else {
- return 'Access denied';
- }
+ if ($id) {
+ return drupal_get_form('edit_code_submission_form', $id);
+ } //$id
+ else {
+ return 'Access denied';
+ }
}
function edit_code_submission_form($form, $form_state, $preference_id)
{
- /* get current proposal */
- $preference_id = arg(4);
- /*$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_data = $query->execute()->fetchObject();
- if (!$preference_data) {
- drupal_set_message(t('Invalid book selected. Please try again.'), 'error');
- drupal_goto('textbook-companion/code-approval/edit-code-submission');
- return;
- }
- $form = array();
- $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['all_example_submitted'] = array(
- '#type' => 'checkbox',
- '#title' => t('Enable code submission interface for user'),
- '#description' => 'Once you have submited this option user can upload more examples.',
- '#required' => TRUE
- );
- $form['hidden_preference_id'] = array(
- '#type' => 'hidden',
- '#value' => $preference_id
- );
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Submit')
- );
- $form['cancle'] = array(
- '#type' => 'item',
- '#markup' => l('Cancle', 'textbook-companion/code-approval/edit-code-submission')
- );
- return $form;
+ /* get current proposal */
+ $preference_id = arg(4);
+ /*$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_data = $query->execute()->fetchObject();
+ if (!$preference_data) {
+ drupal_set_message(t('Invalid book selected. Please try again.'), 'error');
+ drupal_goto('textbook-companion/code-approval/edit-code-submission');
+ return;
+ } //!$preference_data
+ $form = array();
+ $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['all_example_submitted'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Enable code submission interface for user'),
+ '#description' => 'Once you have submited this option user can upload more examples.',
+ '#required' => TRUE
+ );
+ $form['hidden_preference_id'] = array(
+ '#type' => 'hidden',
+ '#value' => $preference_id
+ );
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit')
+ );
+ $form['cancle'] = array(
+ '#type' => 'item',
+ '#markup' => l('Cancle', 'textbook-companion/code-approval/edit-code-submission')
+ );
+ return $form;
}
function edit_code_submission_form_validate($form, $form_state)
{
- if ($form_state['values']['all_example_submitted'] != 1) {
- form_set_error('all_example_submitted', t('Please check the field if you are intrested to submit the all uploaded examples for review!'));
- }
- return;
+ if ($form_state['values']['all_example_submitted'] != 1) {
+ form_set_error('all_example_submitted', t('Please check the field if you are intrested to submit the all uploaded examples for review!'));
+ } //$form_state['values']['all_example_submitted'] != 1
+ return;
}
function edit_code_submission_form_submit($form, $form_state)
{
- global $user;
- if ($form_state['values']['all_example_submitted'] == 1) {
- if (db_query('UPDATE textbook_companion_preference SET submited_all_examples_code = 0 WHERE id = :preference_id', array(
- ':preference_id' => $form_state['values']['hidden_preference_id']
- ))) {
- $query = ("SELECT proposal_id FROM textbook_companion_preference WHERE id= :preference_id");
- $args = array(
- ":preference_id" => $form_state['values']['hidden_preference_id']
- );
- $proposal_data = db_query($query, $args);
- $proposal_data_result = $proposal_data->fetchObject();
- $proposal_query = db_select('textbook_companion_proposal');
- $proposal_query->fields('textbook_companion_proposal');
- $proposal_query->condition('proposal_status', 1);
- $proposal_query->condition('id', $proposal_data_result->proposal_id);
- $proposal_data_query = $proposal_query->execute()->fetchObject();
- /* sending email */
- $book_user = user_load($proposal_data_query->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', '');
- $param['all_code_submitted_status_changed']['proposal_id'] = $proposal_data_result->proposal_id;
- $param['all_code_submitted_status_changed']['user_id'] = $user->uid;
- $param['all_code_submitted_status_changed']['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', 'all_code_submitted_status_changed', $email_to, language_default(), $param, $from, TRUE))
- drupal_set_message('Error sending email message.', 'error');
- drupal_set_message('Enabled code submission interface for user');
- drupal_goto('textbook-companion/code-approval/edit-code-submission');
- }
- }
+ global $user;
+ if ($form_state['values']['all_example_submitted'] == 1) {
+ if (db_query('UPDATE textbook_companion_preference SET submited_all_examples_code = 0 WHERE id = :preference_id', array(
+ ':preference_id' => $form_state['values']['hidden_preference_id']
+ ))) {
+ $query = ("SELECT proposal_id FROM textbook_companion_preference WHERE id= :preference_id");
+ $args = array(
+ ":preference_id" => $form_state['values']['hidden_preference_id']
+ );
+ $proposal_data = db_query($query, $args);
+ $proposal_data_result = $proposal_data->fetchObject();
+ $proposal_query = db_select('textbook_companion_proposal');
+ $proposal_query->fields('textbook_companion_proposal');
+ $proposal_query->condition('proposal_status', 1);
+ $proposal_query->condition('id', $proposal_data_result->proposal_id);
+ $proposal_data_query = $proposal_query->execute()->fetchObject();
+ /* sending email */
+ $book_user = user_load($proposal_data_query->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['all_code_submitted_status_changed']['proposal_id'] = $proposal_data_result->proposal_id;
+ $params['all_code_submitted_status_changed']['user_id'] = $user->uid;
+ $params['all_code_submitted_status_changed']['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', 'all_code_submitted_status_changed', $email_to, language_default(), $params, $from, TRUE))
+ drupal_set_message('Error sending email message.', 'error');
+ drupal_set_message('Enabled code submission interface for user');
+ drupal_goto('textbook-companion/code-approval/edit-code-submission');
+ } //db_query('UPDATE textbook_companion_preference SET submited_all_examples_code = 0 WHERE id = :preference_id', array( ':preference_id' => $form_state['values']['hidden_preference_id'] ))
+ } //$form_state['values']['all_example_submitted'] == 1
}
diff --git a/dependency.inc b/dependency.inc
index c99da1d..89805ce 100755
--- a/dependency.inc
+++ b/dependency.inc
@@ -281,8 +281,8 @@ function upload_dependency_form_submit($form, &$form_state)
{
drupal_set_message('Dependencies uploaded successfully.', 'status');
/* sending email */
- $param['dependency_uploaded']['user_id'] = $user->uid;
- $param['dependency_uploaded']['dependency_names'] = $dependency_names;
+ $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');
@@ -623,8 +623,8 @@ function edit_dependency_form_submit($form, &$form_state)
{
drupal_set_message('Dependencies uploaded successfully.', 'status');
/* sending email */
- $param['dependency_uploaded']['user_id'] = $user->uid;
- $param['dependency_uploaded']['dependency_names'] = $dependency_names;
+ $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');
diff --git a/dependency_approval.inc b/dependency_approval.inc
index 81cf6f8..c0e939c 100755
--- a/dependency_approval.inc
+++ b/dependency_approval.inc
@@ -161,8 +161,8 @@ function textbook_companion_dependency_approval_form_submit($form, &$form_state)
$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;
+ $params['standard']['subject'] = $email_subject;
+ $params['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');
}
@@ -220,8 +220,8 @@ function textbook_companion_delete_dependency($dependency_id)
)), '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'] . " :
+ $params['standard']['subject'] = "[ERROR] Error deleting dependency file";
+ $params['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 path : " . $dependency_files_data->filepath;
diff --git a/download.inc b/download.inc
index 3ba603e..ff900f0 100755
--- a/download.inc
+++ b/download.inc
@@ -1,268 +1,254 @@
<?php
// $Id$
function textbook_companion_download_example_file()
- {
- $example_file_id = arg(3);
- $root_path = textbook_companion_path();
- $root_temp_path = textbook_companion_temp_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_files_q = db_query("select * from textbook_companion_preference tcp join textbook_companion_chapter tcc on tcp.id=tcc.preference_id join textbook_companion_example tce ON tcc.id=tce.chapter_id join textbook_companion_example_files tcef on tce.id=tcef.example_id where tcef.id= :example_id LIMIT 1", array(
- ':example_id' => $example_file_id
- ));
- $example_file_data = $example_files_q->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->directory_name . '/' . $example_file_data->filepath));
- ob_clean();
- readfile($root_path . $example_file_data->directory_name . '/' . $example_file_data->filepath);
- }
+{
+ $example_file_id = arg(3);
+ $root_path = textbook_companion_path();
+ $root_temp_path = textbook_companion_temp_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_files_q = db_query("select * from textbook_companion_preference tcp join textbook_companion_chapter tcc on tcp.id=tcc.preference_id join textbook_companion_example tce ON tcc.id=tce.chapter_id join textbook_companion_example_files tcef on tce.id=tcef.example_id where tcef.id= :example_id LIMIT 1", array(
+ ':example_id' => $example_file_id
+ ));
+ $example_file_data = $example_files_q->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->directory_name . '/' . $example_file_data->filepath));
+ ob_clean();
+ readfile($root_path . $example_file_data->directory_name . '/' . $example_file_data->filepath);
+}
function textbook_companion_download_sample_code()
- {
- $proposal_id = arg(3);
- $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);
- }
+{
+ $proposal_id = arg(3);
+ $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);
+}
function textbook_companion_download_dependency_file()
- {
- $dependency_file_id = arg(3);
- $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_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: ' . $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_id = arg(3);
+ $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_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: ' . $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(3);
- $root_path = textbook_companion_path();
- $root_temp_path = textbook_companion_temp_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);*/
- $query = db_select('textbook_companion_chapter');
- $query->fields('textbook_companion_chapter');
- $query->condition('id', $example_data->chapter_id);
- $result = $query->execute();
- $chapter_data = $result->fetchObject();
- /*$example_files_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE example_id = %d", $example_id);*/
- /* $query = db_select('textbook_companion_example_files');
- $query->fields('textbook_companion_example_files');
- $query->condition('example_id', $example_id);
- $example_files_q = $query->execute();*/
- $example_files_q = db_query("select * from textbook_companion_preference tcp join textbook_companion_chapter tcc on tcp.id=tcc.preference_id join textbook_companion_example tce ON tcc.id=tce.chapter_id join textbook_companion_example_files tcef on tce.id=tcef.example_id where tcef.example_id= :example_id", array(
- ':example_id' => $example_id
- ));
- $EX_PATH = 'EX' . $example_data->number . '/';
- /* zip filename */
- if (!is_dir($root_temp_path . 'tbc_download_temp'))
- mkdir($root_temp_path . 'tbc_download_temp');
- $zip_filename = $root_temp_path .'tbc_download_temp/' . '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->directory_name . '/' . $example_files_row->filepath, $EX_PATH . $example_files_row->filename);
- }
- $zip_file_count = $zip->numFiles;
- $zip->close();
- if ($zip_file_count > 0)
- {
- /* download zip file */
- header('Content-Type: application/octet-stream');
- header('Content-disposition: attachment; filename="EX' . $example_data->number . '.zip"');
- header('Content-Length: ' . filesize($zip_filename));
- ob_clean();
- readfile($zip_filename);
- unlink($zip_filename);
- }
- else
- {
- drupal_set_message("There are no files in this examples to download", 'error');
- drupal_goto('textbook-companion/textbook-run');
- }
- }
+{
+ $example_id = arg(3);
+ $root_path = textbook_companion_path();
+ $root_temp_path = textbook_companion_temp_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);*/
+ $query = db_select('textbook_companion_chapter');
+ $query->fields('textbook_companion_chapter');
+ $query->condition('id', $example_data->chapter_id);
+ $result = $query->execute();
+ $chapter_data = $result->fetchObject();
+ /*$example_files_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE example_id = %d", $example_id);*/
+ /* $query = db_select('textbook_companion_example_files');
+ $query->fields('textbook_companion_example_files');
+ $query->condition('example_id', $example_id);
+ $example_files_q = $query->execute();*/
+ $example_files_q = db_query("select * from textbook_companion_preference tcp join textbook_companion_chapter tcc on tcp.id=tcc.preference_id join textbook_companion_example tce ON tcc.id=tce.chapter_id join textbook_companion_example_files tcef on tce.id=tcef.example_id where tcef.example_id= :example_id", array(
+ ':example_id' => $example_id
+ ));
+ $EX_PATH = 'EX' . $example_data->number . '/';
+ /* zip filename */
+ if (!is_dir($root_temp_path . 'tbc_download_temp'))
+ mkdir($root_temp_path . 'tbc_download_temp');
+ $zip_filename = $root_temp_path . 'tbc_download_temp/' . '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->directory_name . '/' . $example_files_row->filepath, $EX_PATH . $example_files_row->filename);
+ } //$example_files_row = $example_files_q->fetchObject()
+ $zip_file_count = $zip->numFiles;
+ $zip->close();
+ if ($zip_file_count > 0) {
+ /* download zip file */
+ header('Content-Type: application/octet-stream');
+ header('Content-disposition: attachment; filename="EX' . $example_data->number . '.zip"');
+ header('Content-Length: ' . filesize($zip_filename));
+ ob_clean();
+ 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-companion/textbook-run');
+ }
+}
function textbook_companion_download_chapter()
- {
- $chapter_id = arg(3);
- //var_dump($chapter_id);die;
- global $root_path;
- $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 */
-if (!is_dir($root_path . 'tbc_download_temp'))
- mkdir($root_path . 'tbc_download_temp');
- $zip_filename = $root_path .'tbc_download_temp/' . '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_files_q = db_query("select * from textbook_companion_preference tcp join textbook_companion_chapter tcc on tcp.id=tcc.preference_id join textbook_companion_example tce ON tcc.id=tce.chapter_id join textbook_companion_example_files tcef on tce.id=tcef.example_id where tcef.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->directory_name . '/' . $example_files_row->filepath, $CH_PATH . $EX_PATH . $example_files_row->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));
- ob_clean();
- readfile($zip_filename);
- unlink($zip_filename);
- }
- else
- {
- drupal_set_message("There are no examples in this chapter to download", 'error');
- drupal_goto('textbook-companion/textbook-run');
- }
- }
+{
+ $chapter_id = arg(3);
+ //var_dump($chapter_id);die;
+ global $root_path;
+ $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 */
+ if (!is_dir($root_path . 'tbc_download_temp'))
+ mkdir($root_path . 'tbc_download_temp');
+ $zip_filename = $root_path . 'tbc_download_temp/' . '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_files_q = db_query("select * from textbook_companion_preference tcp join textbook_companion_chapter tcc on tcp.id=tcc.preference_id join textbook_companion_example tce ON tcc.id=tce.chapter_id join textbook_companion_example_files tcef on tce.id=tcef.example_id where tcef.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->directory_name . '/' . $example_files_row->filepath, $CH_PATH . $EX_PATH . $example_files_row->filename);
+ } //$example_files_row = $example_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));
+ ob_clean();
+ 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-companion/textbook-run');
+ }
+}
function textbook_companion_download_book()
- {
- $book_id = arg(3);
- $root_path = textbook_companion_path();
- $root_temp_path = textbook_companion_temp_path();
- /* get example data */
- /*$book_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d", $book_id);
- $book_data = db_fetch_object($book_q);*/
- $query = db_select('textbook_companion_preference');
- $query->fields('textbook_companion_preference');
- $query->condition('id', $book_id);
- $result = $query->execute();
- $book_data = $result->fetchObject();
- $zipname = str_replace(' ', '_', ($book_data->book));
- $directory_name = $book_data->directory_name;
- $BK_PATH = $zipname . '/';
- /* zip filename */
- if (!is_dir($root_temp_path . 'tbc_download_temp'))
- mkdir($root_temp_path . 'tbc_download_temp');
- $zip_filename = $root_temp_path .'tbc_download_temp/' . 'zip-' . time() . '-' . rand(0, 999999) . '.zip';
- /* creating zip archive on the server */
- $zip = new ZipArchive();
- $zip->open($zip_filename, ZipArchive::CREATE);
- /*$chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE preference_id = %d", $book_id);*/
- $query = db_select('textbook_companion_chapter');
- $query->fields('textbook_companion_chapter');
- $query->condition('preference_id', $book_id);
- $chapter_q = $query->execute();
- while ($chapter_row = $chapter_q->fetchObject())
- {
- $CH_PATH = 'CH' . $chapter_row->number . '/';
- /*$example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d AND approval_status = 1", $chapter_row->id);*/
- $query = db_select('textbook_companion_example');
- $query->fields('textbook_companion_example');
- $query->condition('chapter_id', $chapter_row->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();
- while ($example_files_row = $example_files_q->fetchObject())
- {
- $zip->addFile($root_path . $directory_name . '/' . $example_files_row->filepath, $BK_PATH . $CH_PATH . $EX_PATH . $example_files_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-companion/textbook-run');
- }
- }
+{
+ $book_id = arg(3);
+ $root_path = textbook_companion_path();
+ $root_temp_path = textbook_companion_temp_path();
+ /* get example data */
+ /*$book_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d", $book_id);
+ $book_data = db_fetch_object($book_q);*/
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('id', $book_id);
+ $result = $query->execute();
+ $book_data = $result->fetchObject();
+ $zipname = str_replace(' ', '_', ($book_data->book));
+ $directory_name = $book_data->directory_name;
+ $BK_PATH = $zipname . '/';
+ /* zip filename */
+ if (!is_dir($root_temp_path . 'tbc_download_temp'))
+ mkdir($root_temp_path . 'tbc_download_temp');
+ $zip_filename = $root_temp_path . 'tbc_download_temp/' . 'zip-' . time() . '-' . rand(0, 999999) . '.zip';
+ /* creating zip archive on the server */
+ $zip = new ZipArchive();
+ $zip->open($zip_filename, ZipArchive::CREATE);
+ /*$chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE preference_id = %d", $book_id);*/
+ $query = db_select('textbook_companion_chapter');
+ $query->fields('textbook_companion_chapter');
+ $query->condition('preference_id', $book_id);
+ $chapter_q = $query->execute();
+ while ($chapter_row = $chapter_q->fetchObject()) {
+ $CH_PATH = 'CH' . $chapter_row->number . '/';
+ /*$example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d AND approval_status = 1", $chapter_row->id);*/
+ $query = db_select('textbook_companion_example');
+ $query->fields('textbook_companion_example');
+ $query->condition('chapter_id', $chapter_row->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();
+ while ($example_files_row = $example_files_q->fetchObject()) {
+ $zip->addFile($root_path . $directory_name . '/' . $example_files_row->filepath, $BK_PATH . $CH_PATH . $EX_PATH . $example_files_row->filename);
+ } //$example_files_row = $example_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 */
+ 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-companion/textbook-run');
+ }
+}
diff --git a/editcode.inc b/editcode.inc
index 972f487..4f00e48 100755
--- a/editcode.inc
+++ b/editcode.inc
@@ -3,714 +3,669 @@
/******************************************************************************/
/***************************** EDIT EXAMPLE ***********************************/
/******************************************************************************/
-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);*/
- $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);*/
- $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, 'textbook-companion/download/file/' . $example_files_data->id);
- $source_file_id = $example_files_data->id;
- //var_dump($source_file);die;
- }
- }
- /* 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);*/
- $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);*/
- $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);
- $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['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Submit')
- );
- $form['cancel'] = array(
- '#type' => 'item',
- '#markup' => l(t('Cancel'), 'textbook-companion/code')
- );
- return $form;
- }
+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);*/
+ $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;
+ } //!$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, 'textbook-companion/download/file/' . $example_files_data->id);
+ $source_file_id = $example_files_data->id;
+ //var_dump($source_file);die;
+ } //$example_files_data->filetype == "S"
+ } //$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;
+ } //!$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;
+ } //!$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;
+ } //!$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);
+ $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
+ );
+ } //$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['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit')
+ );
+ $form['cancel'] = array(
+ '#type' => 'item',
+ '#markup' => 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_ext = explode('.', strtolower($_FILES['files']['name'][$file_form_name]));
- $temp_extension = end($temp_ext);
- 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() {
- $('#edit-number').change(function() {
- $.get('" . base_path() . "textbook-companion/ajax/chapter-title/' + $('#edit-number').val() + '/' + " . $row->pre_id . ", function(data) {
- $('#edit-name').val(data);
- });
- });
- $('#edit-example-number').change(function() {
- $.get('" . base_path() . "textbook-companion/ajax/example-exists/' + $('#edit-number').val() + '/' + $('#edit-example-number').val(), function(data) {
- if (data) {
- alert(data);
- }
- });
- });
- $('#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');*/
- }
+{
+ 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_ext = explode('.', strtolower($_FILES['files']['name'][$file_form_name]));
+ $temp_extension = end($temp_ext);
+ 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);
+ });
+ });
+ $('#edit-example-number').change(function() {
+ $.get('" . base_path() . "textbook-companion/ajax/example-exists/' + $('#edit-number').val() + '/' + $('#edit-example-number').val(), function(data) {
+ if (data) {
+ alert(data);
+ }
+ });
+ });
+ $('#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');*/
+}
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);*/
- $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);*/
- $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);*/
- $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);*/
- $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->directory_name . '/';
- 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);
- $filepath = 'CH' . $chapter_data->number . '/' . 'EX' . $example_data->number . '/';
- /* 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']
- ));
- $query->condition('id', $example_id);
- $num_updated = $query->execute();
- /* handle source file */
- if (isset($form_state['values']['cur_source_file_id']))
- {
- $cur_file_id = $form_state['values']['cur_source_file_id'];
- }
- else
- {
- $cur_file_id = isset($form_state['values']['cur_source_file_id']);
- }
- //var_dump($cur_file_id);die;
- 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);*/
- //var_dump($cur_file_id. $example_data->id);die;
- $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) VALUES (:example_id, :filename, :filepath, :filemime, :filesize, :filetype,:timestamp)";
- $args = array(
- ":example_id" => $example_data->id,
- ":filename" => $_FILES['files']['name']['sourcefile1'],
- ":filepath" => $filepath . $_FILES['files']['name']['sourcefile1'],
- ":filemime" => 'application/dwxml',
- ":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');
- }
- }
- /* 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', '');
- $param['example_updated']['example_id'] = $example_id;
- $param['example_updated']['user_id'] = $user->uid;
- $param['example_updated']['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_updated', $email_to, language_default(), $param, $from, TRUE))
- drupal_set_message('Error sending email message.', 'error');
- drupal_set_message(t("Example successfully udpated."), 'status');
- }
+{
+ 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;
+ } //!$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;
+ } //!$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;
+ } //!$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;
+ } //!$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->directory_name . '/';
+ 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);
+ $filepath = 'CH' . $chapter_data->number . '/' . 'EX' . $example_data->number . '/';
+ /* 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']
+ ));
+ $query->condition('id', $example_id);
+ $num_updated = $query->execute();
+ /* handle source file */
+ if (isset($form_state['values']['cur_source_file_id'])) {
+ $cur_file_id = $form_state['values']['cur_source_file_id'];
+ } //isset($form_state['values']['cur_source_file_id'])
+ else {
+ $cur_file_id = isset($form_state['values']['cur_source_file_id']);
+ }
+ //var_dump($cur_file_id);die;
+ 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);*/
+ //var_dump($cur_file_id. $example_data->id);die;
+ $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" => $filepath . $_FILES['files']['name']['sourcefile1'],
+ ":filemime" => 'application/dwxml',
+ ":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']
+ /* 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_updated']['example_id'] = $example_id;
+ $params['example_updated']['user_id'] = $user->uid;
+ $params['example_updated']['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_updated', $email_to, language_default(), $params, $from, 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, $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);*/
- $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', 'textbook-companion/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', 'textbook-companion/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);*/
- $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);*/
- $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;
- }
+function edit_chapter_title_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);*/
+ $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', 'textbook-companion/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', 'textbook-companion/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;
+ } //!$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;
+ } //!$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);*/
- $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', 'textbook-companion/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', 'textbook-companion/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);*/
- $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);*/
- $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('textbookcompanion/code');
- return;
- }
- /*db_query("UPDATE {textbook_companion_chapter} SET name = '%s' WHERE id = %d", $form_state['values']['chapter_title'], $chapter_id);*/
- $query = db_update('textbook_companion_chapter');
- $query->fields(array(
- 'name' => $form_state['values']['chapter_title']
- ));
- $query->condition('id', $chapter_id);
- $num_updated = $query->execute();
- drupal_set_message(t('Title of the Chapter updated.'), 'status');
- }
+{
+ 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', 'textbook-companion/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', 'textbook-companion/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;
+ } //!$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('textbookcompanion/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']
+ ));
+ $query->condition('id', $chapter_id);
+ $num_updated = $query->execute();
+ drupal_set_message(t('Title of the Chapter updated.'), '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");*/
- $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;
- }
+{
+ $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 . ')';
+ } //$book_titles_data = $book_titles_q->fetchObject()
+ return $book_titles;
+}
diff --git a/editcodeadmin.inc b/editcodeadmin.inc
index 32e3481..e12f5ed 100755
--- a/editcodeadmin.inc
+++ b/editcodeadmin.inc
@@ -4,469 +4,434 @@
/***************************** EDIT EXAMPLE ***********************************/
/******************************************************************************/
function upload_examples_admin_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);*/
- $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);*/
- $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, 'textbook-companion/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, 'textbook-companion/download/file/' . $example_files_data->id);
- $result1_file_id = $example_files_data->id;
- }
- else
- {
- $result2_file = l($example_files_data->filename, 'textbook-companion/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, 'textbook-companion/download/file/' . $example_files_data->id);
- $xcos1_file_id = $example_files_data->id;
- }
- else
- {
- $xcos2_file = l($example_files_data->filename, 'textbook-companion/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);*/
- $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);*/
- $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);*/
- $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);
- $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',
- '#default_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['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Submit')
- );
- $form['cancel'] = array(
- '#type' => 'markup',
- '#value' => l(t('Cancel'), 'textbook-companion/code')
- );
- return $form;
- }
+{
+ 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;
+ } //!$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, 'textbook-companion/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, 'textbook-companion/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, 'textbook-companion/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, 'textbook-companion/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, 'textbook-companion/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;
+ } //!$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;
+ } //!$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;
+ } //!$proposal_data
+ $user_data = user_load($proposal_data->uid);
+ $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',
+ '#default_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['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_ext = explode('.', strtolower($_FILES['files']['name'][$file_form_name]));
- $temp_extension = end($temp_ext);
- 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.'));
- }
- }
- }
- }
+{
+ 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_ext = explode('.', strtolower($_FILES['files']['name'][$file_form_name]));
+ $temp_extension = end($temp_ext);
+ 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'])
+}
function upload_examples_admin_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);*/
- $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);*/
- $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);*/
- $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);*/
- $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);
- /* creating directories */
- $root_path = textbook_companion_path();
- $dest_path = $preference_data->directory_name . '/';
- 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);
- $filepath = 'CH' . $chapter_data->number . '/' . 'EX' . $example_data->number . '/';
- /* 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']
- ));
- $query->condition('id', $example_id);
- $num_updated = $query->execute();
- /* handle source file */
- if (empty($form_state['values']['cur_source_file_id']))
- {
- $form_state['values']['cur_source_file_id'] = 0;
- }
- $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)
+{
+ 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;
+ } //!$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;
+ } //!$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;
+ } //!$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;
+ } //!$proposal_data
+ $user_data = user_load($proposal_data->uid);
+ /* creating directories */
+ $root_path = textbook_companion_path();
+ $dest_path = $preference_data->directory_name . '/';
+ 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);
+ $filepath = 'CH' . $chapter_data->number . '/' . 'EX' . $example_data->number . '/';
+ /* 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']
+ ));
+ $query->condition('id', $example_id);
+ $num_updated = $query->execute();
+ /* handle source file */
+ if (empty($form_state['values']['cur_source_file_id'])) {
+ $form_state['values']['cur_source_file_id'] = 0;
+ } //empty($form_state['values']['cur_source_file_id'])
+ $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" => $filepath . $_FILES['files']['name']['sourcefile1'],
- ":filemime" => 'application/dwxml',
- ":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');
- }
- }
- /* 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(), $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');
- }
+ $args = array(
+ ":example_id" => $example_data->id,
+ ":filename" => $_FILES['files']['name']['sourcefile1'],
+ ":filepath" => $filepath . $_FILES['files']['name']['sourcefile1'],
+ ":filemime" => 'application/dwxml',
+ ":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']
+ /* sending email */
+ $email_to = $user_data->mail;
+ $params['example_updated_admin']['example_id'] = $example_id;
+ $params['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");*/
- $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;
- }
+{
+ $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 . ')';
+ } //$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");*/
- $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, '/textbook-companion/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
- );
- }
+{
+ $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, '/textbook-companion/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/full_download.inc b/full_download.inc
index e688ec4..bc5b5ca 100755
--- a/full_download.inc
+++ b/full_download.inc
@@ -1,183 +1,170 @@
<?php
// $Id$
function textbook_companion_download_full_chapter()
- {
- $chapter_id = arg(3);
- $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);*/
- $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();
- 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);
- }
- }
- /* 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);*/
- $example_files_q = db_query("select * from textbook_companion_preference tcp join textbook_companion_chapter tcc on tcp.id=tcc.preference_id join textbook_companion_example tce ON tcc.id=tce.chapter_id join textbook_companion_example_files tcef on tce.id=tcef.example_id where tcef.example_id= :example_id", array(
- ':example_id' => $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();*/
- while ($example_files_row = $example_files_q->fetchObject())
- {
- $zip->addFile($root_path . $example_files_row->directory_name . '/' . $example_files_row->filepath, $PENDING_PATH . $CH_PATH . $EX_PATH . $example_files_row->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('textbook-companion/code-approval/bulk');
- }
- }
+{
+ $chapter_id = arg(3);
+ $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);*/
+ $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();
+ 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()
+ } //$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);*/
+ $example_files_q = db_query("select * from textbook_companion_preference tcp join textbook_companion_chapter tcc on tcp.id=tcc.preference_id join textbook_companion_example tce ON tcc.id=tce.chapter_id join textbook_companion_example_files tcef on tce.id=tcef.example_id where tcef.example_id= :example_id", array(
+ ':example_id' => $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();*/
+ while ($example_files_row = $example_files_q->fetchObject()) {
+ $zip->addFile($root_path . $example_files_row->directory_name . '/' . $example_files_row->filepath, $PENDING_PATH . $CH_PATH . $EX_PATH . $example_files_row->filename);
+ } //$example_files_row = $example_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('textbook-companion/code-approval/bulk');
+ }
+}
function textbook_companion_download_full_book()
- {
- $book_id = arg(3);
- $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 = %d", $book_id);
- $book_data = db_fetch_object($book_q);*/
- $query = db_select('textbook_companion_preference');
- $query->fields('textbook_companion_preference');
- $query->condition('id', $book_id);
- $book_q = $query->execute();
- $book_data = $book_q->fetchObject();
- //$zipname = str_replace(' ','_',($book_data->book));
- //$BK_PATH = $zipname . '/';
- $BK_PATH = $book_data->book . '/';
- /* zip filename */
- $zip_filename = $root_path . 'zip-' . time() . '-' . rand(0, 999999) . '.zip';
- /* creating zip archive on the server */
- $zip = new ZipArchive;
- $zip->open($zip_filename, ZipArchive::CREATE);
- /* approved examples */
- /*$chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE preference_id = %d", $book_id);*/
- $query = db_select('textbook_companion_chapter');
- $query->fields('textbook_companion_chapter');
- $query->condition('preference_id', $book_id);
- $chapter_q = $query->execute();
- while ($chapter_row = $chapter_q->fetchObject())
- {
- $CH_PATH = 'CH' . $chapter_row->number . '/';
- /*$example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d AND approval_status = 1", $chapter_row->id);*/
- $query = db_select('textbook_companion_example');
- $query->fields('textbook_companion_example');
- $query->condition('chapter_id', $chapter_row->id);
- $query->condition('approval_status', 1);
- $example_q = $query->execute();
- while ($example_row = $example_q->fetchObject())
- {
- $EX_PATH = 'EX' . $example_row->number . '/';
- /*$example_files_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE example_id = %d", $example_row->id);*/
- $example_files_q = db_query("select * from textbook_companion_preference tcp join textbook_companion_chapter tcc on tcp.id=tcc.preference_id join textbook_companion_example tce ON tcc.id=tce.chapter_id join textbook_companion_example_files tcef on tce.id=tcef.example_id where tcef.example_id= :example_id", array(
- ':example_id' => $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();*/
- while ($example_files_row = $example_files_q->fetchObject())
- {
- $zip->addFile($root_path . $example_files_row->directory_name . '/' . $example_files_row->filepath, $BK_PATH . $APPROVE_PATH . $CH_PATH . $EX_PATH . $example_files_row->filename);
- }
- }
- /* unapproved examples */
- /* $example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d AND approval_status = 0", $chapter_row->id);*/
- $query = db_select('textbook_companion_example');
- $query->fields('textbook_companion_example');
- $query->condition('chapter_id', $chapter_row->id);
- $query->condition('approval_status', 0);
- $example_q = $query->execute();
- while ($example_row = $example_q->fetchObject())
- {
- $EX_PATH = 'EX' . $example_row->number . '/';
- /*$example_files_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE example_id = %d", $example_row->id);*/
- $example_files_q = db_query("select * from textbook_companion_preference tcp join textbook_companion_chapter tcc on tcp.id=tcc.preference_id join textbook_companion_example tce ON tcc.id=tce.chapter_id join textbook_companion_example_files tcef on tce.id=tcef.example_id where tcef.example_id= :example_id", array(
- ':example_id' => $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();*/
- while ($example_files_row = $example_files_q->fetchObject())
- {
- $zip->addFile($root_path . $example_files_row->directory_name . '/' . $example_files_row->filepath, $BK_PATH . $PENDING_PATH . $CH_PATH . $EX_PATH . $example_files_row->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="' . str_replace(' ', '_', ($book_data->book)) . '.zip"');
- header('Content-Length: ' . filesize($zip_filename));
- ob_clean();
- readfile($zip_filename);
- unlink($zip_filename);
- }
- else
- {
- drupal_set_message("There are no examples in this book to download", 'error');
- drupal_goto('textbook-companion/code-approval/bulk');
- }
- }
+{
+ $book_id = arg(3);
+ $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 = %d", $book_id);
+ $book_data = db_fetch_object($book_q);*/
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('id', $book_id);
+ $book_q = $query->execute();
+ $book_data = $book_q->fetchObject();
+ //$zipname = str_replace(' ','_',($book_data->book));
+ //$BK_PATH = $zipname . '/';
+ $BK_PATH = $book_data->book . '/';
+ /* zip filename */
+ $zip_filename = $root_path . 'zip-' . time() . '-' . rand(0, 999999) . '.zip';
+ /* creating zip archive on the server */
+ $zip = new ZipArchive;
+ $zip->open($zip_filename, ZipArchive::CREATE);
+ /* approved examples */
+ /*$chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE preference_id = %d", $book_id);*/
+ $query = db_select('textbook_companion_chapter');
+ $query->fields('textbook_companion_chapter');
+ $query->condition('preference_id', $book_id);
+ $chapter_q = $query->execute();
+ while ($chapter_row = $chapter_q->fetchObject()) {
+ $CH_PATH = 'CH' . $chapter_row->number . '/';
+ /*$example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d AND approval_status = 1", $chapter_row->id);*/
+ $query = db_select('textbook_companion_example');
+ $query->fields('textbook_companion_example');
+ $query->condition('chapter_id', $chapter_row->id);
+ $query->condition('approval_status', 1);
+ $example_q = $query->execute();
+ while ($example_row = $example_q->fetchObject()) {
+ $EX_PATH = 'EX' . $example_row->number . '/';
+ /*$example_files_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE example_id = %d", $example_row->id);*/
+ $example_files_q = db_query("select * from textbook_companion_preference tcp join textbook_companion_chapter tcc on tcp.id=tcc.preference_id join textbook_companion_example tce ON tcc.id=tce.chapter_id join textbook_companion_example_files tcef on tce.id=tcef.example_id where tcef.example_id= :example_id", array(
+ ':example_id' => $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();*/
+ while ($example_files_row = $example_files_q->fetchObject()) {
+ $zip->addFile($root_path . $example_files_row->directory_name . '/' . $example_files_row->filepath, $BK_PATH . $APPROVE_PATH . $CH_PATH . $EX_PATH . $example_files_row->filename);
+ } //$example_files_row = $example_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_row->id);*/
+ $query = db_select('textbook_companion_example');
+ $query->fields('textbook_companion_example');
+ $query->condition('chapter_id', $chapter_row->id);
+ $query->condition('approval_status', 0);
+ $example_q = $query->execute();
+ while ($example_row = $example_q->fetchObject()) {
+ $EX_PATH = 'EX' . $example_row->number . '/';
+ /*$example_files_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE example_id = %d", $example_row->id);*/
+ $example_files_q = db_query("select * from textbook_companion_preference tcp join textbook_companion_chapter tcc on tcp.id=tcc.preference_id join textbook_companion_example tce ON tcc.id=tce.chapter_id join textbook_companion_example_files tcef on tce.id=tcef.example_id where tcef.example_id= :example_id", array(
+ ':example_id' => $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();*/
+ while ($example_files_row = $example_files_q->fetchObject()) {
+ $zip->addFile($root_path . $example_files_row->directory_name . '/' . $example_files_row->filepath, $BK_PATH . $PENDING_PATH . $CH_PATH . $EX_PATH . $example_files_row->filename);
+ } //$example_files_row = $example_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="' . str_replace(' ', '_', ($book_data->book)) . '.zip"');
+ header('Content-Length: ' . filesize($zip_filename));
+ ob_clean();
+ 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-companion/code-approval/bulk');
+ }
+}
diff --git a/general.inc b/general.inc
index 5c79e92..41bb7c1 100755
--- a/general.inc
+++ b/general.inc
@@ -1,408 +1,338 @@
<?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);*/
- $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', 'textbook-companion/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', 'textbook-companion/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;
-case 5:
- drupal_set_message(t('You have submitted your all examples.'), 'status');
- drupal_goto('');
- return;
- 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);*/
- $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);*/
- $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
- ));
- $submit_all_code_form = drupal_get_form('submit_all_code_form',$proposal_data->id, $preference_data->id);
- $return_html .= drupal_render($submit_all_code_form);
- 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);*/
- $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', 'textbook-companion/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', 'textbook-companion/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;
-case 5:
- drupal_set_message(t('You have submitted your all codes.'), 'status');
- drupal_goto('');
- return;
-
- 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);*/
- $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);*/
- $query = db_select('textbook_companion_chapter');
- $query->fields('textbook_companion_chapter');
- $query->condition('id', $chapter_id);
- $query->condition('preference_id', $preference_data->id);
- $query->range(0, 1);
- $chapter_q = $query->execute();
- if ($chapter_data = $chapter_q->fetchObject())
- {
- $return_html = '<br />';
- $return_html .= '<strong>Title of the Book:</strong><br />' . $preference_data->book . '<br /><br />';
- $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();
- $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, 'textbook-companion/download/file/' . $example_files_data->id) . ' (' . $file_type . ')<br />';
- }
- 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', 'textbook-companion/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;
- }
-/*function all_example_submitted_check_form($form,$form_state,$preference_id){
- $form = array();
- $form['all_example_submitted'] = array(
- '#type' => 'checkbox',
- '#title' => t('I have submitted codes for all the examples'),
- '#description' => 'Once you have submited this option you are not able to upload more examples.',
- '#required' => TRUE,
- );
- $form['hidden_preference_id'] = array(
- '#type' => 'hidden',
- '#value' => $preference_id
- );
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Submit')
- );
- return $form;
+{
+ 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', 'textbook-companion/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', 'textbook-companion/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->submited_all_examples_code == 1) {
+ drupal_set_message(t('You have already submited your all codes for this book to review, hence you can not upload more code, for any query please write us.'), 'status');
+ drupal_goto('');
+ return;
+ } //$preference_data->submited_all_examples_code == 1
+ 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)
+ );
+ } //$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
+ ));
+ $submited_all_example = drupal_get_form("all_example_submitted_check_form", $preference_data->id);
+ $return_html .= drupal_render($submited_all_example);
+ return $return_html;
}
-*/
-
-function all_example_submitted_check_form_submit($form,$form_state){
-global $user;
-if ($form_state['values']['all_example_submitted'] == 1) {
-db_query('UPDATE textbook_companion_preference SET submited_all_examples_code = 1 WHERE id = :preference_id',array(':preference_id' => $form_state['values']['hidden_preference_id']));
- /* sending email */
- $query = ("SELECT proposal_id FROM textbook_companion_preference WHERE id= :preference_id");
- $args = array(":preference_id" => $form_state['values']['hidden_preference_id']);
- $proposal_data = db_query($query,$args);
- $proposal_data_result = $proposal_data->fetchObject();
-
- $email_to = $user->mail;
- $from = variable_get('textbook_companion_from_email', '');
- $bcc = variable_get('textbook_companion_emails', '');
- $cc = variable_get('textbook_companion_cc_emails', '');
- $param['all_code_submitted']['proposal_id'] = $proposal_data_result->proposal_id;
- $param['all_code_submitted']['user_id'] = $user->uid;
- $param['all_code_submitted']['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', 'all_code_submitted', $email_to, language_default(), $param, $from, TRUE))
- drupal_set_message('Error sending email message.', 'error');
+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);*/
+ $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', 'textbook-companion/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', 'textbook-companion/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;
+ } //!$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->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 />';
+ } //$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();
+ $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_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, 'textbook-companion/download/file/' . $example_files_data->id) . ' (' . $file_type . ')<br />';
+ } //$example_files_data = $example_files_q->fetchObject()
+ 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'
+ );
+ } //$example_data->approval_status == 0
+ else {
+ $example_rows[] = array(
+ 'data' => array(
+ $example_data->number,
+ $example_data->caption,
+ $approval_status,
+ $example_files,
+ l('Download', 'textbook-companion/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;
}
+function all_example_submitted_check_form($form, &$form_state, $preference_id)
+{
+ $form = array();
+ $form['all_example_submitted'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('I have submitted codes for all the examples'),
+ '#description' => 'Once you have submited this option you are not able to upload more examples.',
+ '#required' => TRUE
+ );
+ $form['hidden_preference_id'] = array(
+ '#type' => 'hidden',
+ '#value' => $preference_id
+ );
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit')
+ );
+ return $form;
}
-
-function submit_all_code_form($form,&$form_state,$proposal_id,$preference_id){
-$form = array();
-$form['submit_all_code'] = array(
- '#type' => 'checkbox',
- '#title' => t('I have uploaded all the codes'),
- '#description' => 'Once you have submited this option you are not able to upload more examples.',
- '#required' => TRUE,
-);
-$form['prop_id'] = array(
- '#type' => 'hidden',
- '#value' => $proposal_id
-);
-$form['pref_id'] = array(
- '#type' => 'hidden',
- '#value' => $preference_id
-);
-
-$form['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Submit')
- );
-
- $form['cancel'] = array(
- '#type' => 'markup',
- '#value' => l(t('Cancel'), 'textbook-companion/code'),
- );
- return $form;
+function all_example_submitted_check_form_validate($form, &$form_state)
+{
+ if ($form_state['values']['all_example_submitted'] != 1) {
+ form_set_error('all_example_submitted', t('Please check the field if you are intrested to submit the all uploaded examples for review!'));
+ } //$form_state['values']['all_example_submitted'] != 1
+ return;
}
-function submit_all_code_form_submit($form,&$form_state){
-global $user;
-if($form_state['values']['submit_all_code']== 1){
-db_query('UPDATE textbook_companion_proposal SET proposal_status = 5 WHERE id = :id', array(":id" =>$form_state['values']['prop_id']));
-/* sending email */
- $query = ("SELECT proposal_id FROM textbook_companion_preference WHERE id= :preference_id");
- $args = array(":preference_id" => $form_state['values']['pref_id']);
- $proposal_data = db_query($query,$args);
- $proposal_data_result = $proposal_data->fetchObject();
-
- $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['all_code_submitted']['proposal_id'] = $proposal_data_result->proposal_id;
- $params['all_code_submitted']['user_id'] = $user->uid;
- $params['all_code_submitted']['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', 'all_code_submitted', $email_to, language_default(), $params, $from, TRUE))
- drupal_set_message('Error sending email message.', 'error');
+function all_example_submitted_check_form_submit($form, &$form_state)
+{
+ global $user;
+ if ($form_state['values']['all_example_submitted'] == 1) {
+ db_query('UPDATE textbook_companion_preference SET submited_all_examples_code = 1 WHERE id = :preference_id', array(
+ ':preference_id' => $form_state['values']['hidden_preference_id']
+ ));
+ /* sending email */
+ $query = ("SELECT proposal_id FROM textbook_companion_preference WHERE id= :preference_id");
+ $args = array(
+ ":preference_id" => $form_state['values']['hidden_preference_id']
+ );
+ $proposal_data = db_query($query, $args);
+ $proposal_data_result = $proposal_data->fetchObject();
+
+ $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['all_code_submitted']['proposal_id'] = $proposal_data_result->proposal_id;
+ $params['all_code_submitted']['user_id'] = $user->uid;
+ $params['all_code_submitted']['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', 'all_code_submitted', $email_to, language_default(), $params, $from, TRUE))
+ drupal_set_message('Error sending email message.', 'error');
+ } //$form_state['values']['all_example_submitted'] == 1
}
-
-}
diff --git a/manage_proposal.inc b/manage_proposal.inc
index b99bf8c..487f848 100755
--- a/manage_proposal.inc
+++ b/manage_proposal.inc
@@ -1,1726 +1,1736 @@
<?php
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");*/
- $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', 'textbook-companion/manage-proposal/approve/' . $pending_data->id) . ' | ' . l('Edit', 'textbook-companion/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;
+ /* 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', 'textbook-companion/manage-proposal/approve/' . $pending_data->id) . ' | ' . l('Edit', 'textbook-companion/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',
+ '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);
- return "";
- } 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->condition('approval_status', 0);
- $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;
- case 5:
- $proposal_status = 'Submitted all codes';
- break;
- default:
- $proposal_status = 'Unknown';
- break;
- }
- $proposal_rows[] = array(
- date('d-m-Y', $proposal_data->creation_date),
- "{$preference_data->book} <br>
+ function _tbc_ext($status, $preference_id)
+ {
+ if ($status == "Approved") {
+ //return " | " . l("ER", "tbc_external_review/add_book/" . $preference_id);
+ return "";
+ } //$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->condition('approval_status', 0);
+ $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;
+ case 5:
+ $proposal_status = 'Submitted all codes';
+ 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->completion_date),
- $proposal_status,
- l('Status', 'textbook-companion/manage-proposal/status/' . $proposal_data->id) . ' | ' . l('Edit', 'textbook-companion/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;
+ l($proposal_data->full_name, 'user/' . $proposal_data->uid),
+ date('d-m-Y', $proposal_data->completion_date),
+ $proposal_status,
+ l('Status', 'textbook-companion/manage-proposal/status/' . $proposal_data->id) . ' | ' . l('Edit', 'textbook-companion/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',
+ 'Expected 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");*/
- $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', 'textbook-companion/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;
+ /* 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_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', 'textbook-companion/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)
{
- global $user;
- /* get current proposal */
- $proposal_id = arg(3);
- /*$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('textbook-companion/manage-proposal');
- return;
- }
- } else {
- drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
- drupal_goto('textbook-companion/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/Village')
- );
- $form['pincode'] = array(
- '#type' => 'item',
- '#markup' => $row->pincode,
- '#title' => t('Pincode')
- );
- $form['state'] = array(
- '#type' => 'item',
- '#markup' => $row->state,
- '#title' => t('State')
- );
- $form['faculty'] = array(
- '#type' => 'hidden',
- '#markup' => $row->faculty,
- '#title' => t('College Teacher/Professor')
- );
- $form['reviewer'] = array(
- '#type' => 'hidden',
- '#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['version'] = array(
- '#type' => 'item',
- '#markup' => $row->dwsim_version,
- '#title' => t('DWSIM Version')
- );
- $form['reference'] = array(
- '#type' => 'item',
- '#markup' => $row->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 = %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()) {
- $preference_rows[$preference_data->id] = $preference_data->book . ' (Written by ' . $preference_data->author . ')';
- }
- 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 != "Not available") {
- $form['samplecode'] = array(
- '#type' => 'markup',
- '#markup' => l('Download Sample Code', 'textbook-companion/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'),
- '#states' => array(
- 'visible' => array(
- ':input[name="disapprove"]' => array(
- 'checked' => TRUE
- )
- ),
- 'required' => array(
- ':input[name="disapprove"]' => array(
- 'checked' => TRUE
- )
- )
- )
- );
- $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'), 'textbook-companion/manage-proposal')
- );
- return $form;
+ global $user;
+ /* get current proposal */
+ $proposal_id = arg(3);
+ /*$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 */
+ } //$row = $result->fetchObject()
+ else {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('textbook-companion/manage-proposal');
+ return;
+ }
+ } //$result
+ else {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('textbook-companion/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/Village')
+ );
+ $form['pincode'] = array(
+ '#type' => 'item',
+ '#markup' => $row->pincode,
+ '#title' => t('Pincode')
+ );
+ $form['state'] = array(
+ '#type' => 'item',
+ '#markup' => $row->state,
+ '#title' => t('State')
+ );
+ $form['faculty'] = array(
+ '#type' => 'hidden',
+ '#markup' => $row->faculty,
+ '#title' => t('College Teacher/Professor')
+ );
+ $form['reviewer'] = array(
+ '#type' => 'hidden',
+ '#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['version'] = array(
+ '#type' => 'item',
+ '#markup' => $row->dwsim_version,
+ '#title' => t('DWSIM Version')
+ );
+ $form['reference'] = array(
+ '#type' => 'item',
+ '#markup' => $row->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 = %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()) {
+ $preference_rows[$preference_data->id] = $preference_data->book . ' (Written by ' . $preference_data->author . ')';
+ } //$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 != "Not available") {
+ $form['samplecode'] = array(
+ '#type' => 'markup',
+ '#markup' => l('Download Sample Code', 'textbook-companion/download/samplecode/' . $proposal_id) . "<br><br>"
+ );
+ } //$row->samplefilepath != "Not available"
+ $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_id'] = array(
+ '#type' => 'hidden',
+ '#value' => $proposal_id
+ );
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit')
+ );
+ $form['cancel'] = array(
+ '#type' => 'markup',
+ '#value' => l(t('Cancel'), 'textbook-companion/manage-proposal')
+ );
+ return $form;
}
function proposal_approval_form_validate($form, &$form_state)
{
- if ($form_state['values']['disapprove']) {
- if (strlen(trim($form_state['values']['message'])) <= 30) {
- form_set_error('message', t('Please mention the reason for disapproval in minimum 30 characters.'));
- }
- }
- return;
+ if ($form_state['values']['disapprove']) {
+ if (strlen(trim($form_state['values']['message'])) <= 30) {
+ form_set_error('message', t('Please mention the reason for disapproval in minimum 30 characters.'));
+ } //strlen(trim($form_state['values']['message'])) <= 30
+ } //$form_state['values']['disapprove']
+ return;
}
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 = %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('textbook-companion/manage-proposal');
- return;
- }
- } else {
- drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
- drupal_goto('textbook-companion/manage-proposal');
- return;
- }
- /* disapprove */
- if ($form_state['values']['disapprove']) {
- /*db_query("UPDATE {textbook_companion_proposal} SET approver_uid = %d, approval_date = %d, proposal_status = 2, message = '%s' WHERE id = %d", $user->uid, time(), $form_state['values']['message'], $proposal_id);*/
- $query = db_update('textbook_companion_proposal');
- $query->fields(array(
- 'approver_uid' => $user->uid,
- 'approval_date' => time(),
- 'proposal_status' => 2,
- 'message' => $form_state['values']['message']
- ));
- $query->condition('id', $proposal_id);
- $num_updated = $query->execute();
- /*db_query("UPDATE {textbook_companion_preference} SET approval_status = 2 WHERE proposal_id = %d", $proposal_id);*/
- $query = db_update('textbook_companion_preference');
- $query->fields(array(
- 'approval_status' => 2
- ));
- $query->condition('proposal_id', $proposal_id);
- $num_updated = $query->execute();
- /* unlock all the aicte books */
- /*$query = "
- UPDATE textbook_companion_aicte
- SET status = 0, uid = 0, proposal_id = 0, preference_id = 0
- WHERE proposal_id = {$proposal_id}
- ";
- db_query($query);*/
- /*$query = db_update('textbook_companion_aicte');
- $query->fields(array(
- 'status' => 0,
- 'uid' => 0,
- 'proposal_id' => 0,
- 'preference_id' => 0,
- ));
- $query->condition('proposal_id', $proposal_id);
- $num_updated = $query->execute();*/
- /* sending email */
- $book_user = user_load($row->uid);
- $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', '');
- $param['proposal_disapproved']['proposal_id'] = $proposal_id;
- $param['proposal_disapproved']['user_id'] = $row->uid;
- $param['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(), $param, $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('textbook-companion/manage-proposal');
- return;
- }
- /* get book preference and set the status */
- $preference_id = $form_state['values']['book_preference'];
- /*db_query("UPDATE {textbook_companion_proposal} SET approver_uid = %d, approval_date = %d, proposal_status = 1 WHERE id = %d", $user->uid, time(), $proposal_id);*/
- $query = db_update('textbook_companion_proposal');
- $query->fields(array(
- 'approver_uid' => $user->uid,
- 'approval_date' => time(),
- 'proposal_status' => 1
- ));
- $query->condition('id', $proposal_id);
- $num_updated = $query->execute();
- /*db_query("UPDATE {textbook_companion_preference} SET approval_status = 1 WHERE id = %d", $preference_id);*/
- $query = db_update('textbook_companion_preference');
- $query->fields(array(
- 'approval_status' => 1
- ));
- $query->condition('id', $preference_id);
- $num_updated = $query->execute();
- /* unlock aicte books except the one which was approved out of 3 nos */
- /* $query = "
- 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);*/
- /*$query = db_update('textbook_companion_aicte');
- $query->fields(array(
- 'status' => 0,
- 'uid' => 0,
- 'proposal_id' => 0,
- 'preference_id' => 0,
- ));
- $query->condition('proposal_id', '$proposal_id');
- $query->condition('preference_id', '$preference_id', '<>');
- $num_updated = $query->execute();*/
- /* sending email */
- $book_user = user_load($row->uid);
- $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', '');
- $param['proposal_approved']['proposal_id'] = $proposal_id;
- $param['proposal_approved']['user_id'] = $row->uid;
- $param['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(), $param, $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('textbook-companion/manage-proposal');
- return;
+ 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 = %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 */
+ } //$row = $result->fetchObject()
+ else {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('textbook-companion/manage-proposal');
+ return;
+ }
+ } //$result
+ else {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('textbook-companion/manage-proposal');
+ return;
+ }
+ /* disapprove */
+ if ($form_state['values']['disapprove']) {
+ /*db_query("UPDATE {textbook_companion_proposal} SET approver_uid = %d, approval_date = %d, proposal_status = 2, message = '%s' WHERE id = %d", $user->uid, time(), $form_state['values']['message'], $proposal_id);*/
+ $query = db_update('textbook_companion_proposal');
+ $query->fields(array(
+ 'approver_uid' => $user->uid,
+ 'approval_date' => time(),
+ 'proposal_status' => 2,
+ 'message' => $form_state['values']['message']
+ ));
+ $query->condition('id', $proposal_id);
+ $num_updated = $query->execute();
+ /*db_query("UPDATE {textbook_companion_preference} SET approval_status = 2 WHERE proposal_id = %d", $proposal_id);*/
+ $query = db_update('textbook_companion_preference');
+ $query->fields(array(
+ 'approval_status' => 2
+ ));
+ $query->condition('proposal_id', $proposal_id);
+ $num_updated = $query->execute();
+ /* unlock all the aicte books */
+ /*$query = "
+ UPDATE textbook_companion_aicte
+ SET status = 0, uid = 0, proposal_id = 0, preference_id = 0
+ WHERE proposal_id = {$proposal_id}
+ ";
+ db_query($query);*/
+ /*$query = db_update('textbook_companion_aicte');
+ $query->fields(array(
+ 'status' => 0,
+ 'uid' => 0,
+ 'proposal_id' => 0,
+ 'preference_id' => 0,
+ ));
+ $query->condition('proposal_id', $proposal_id);
+ $num_updated = $query->execute();*/
+ /* sending email */
+ $book_user = user_load($row->uid);
+ $email_to = $book_user->mail;
+ $from = variable_get('textbook_companion_from_email', '');
+ $bcc = variable_get('textbook_companion_bcc_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('textbook-companion/manage-proposal');
+ return;
+ } //$form_state['values']['disapprove']
+ /* get book preference and set the status */
+ $preference_id = $form_state['values']['book_preference'];
+ /*db_query("UPDATE {textbook_companion_proposal} SET approver_uid = %d, approval_date = %d, proposal_status = 1 WHERE id = %d", $user->uid, time(), $proposal_id);*/
+ $query = db_update('textbook_companion_proposal');
+ $query->fields(array(
+ 'approver_uid' => $user->uid,
+ 'approval_date' => time(),
+ 'proposal_status' => 1
+ ));
+ $query->condition('id', $proposal_id);
+ $num_updated = $query->execute();
+ /*db_query("UPDATE {textbook_companion_preference} SET approval_status = 1 WHERE id = %d", $preference_id);*/
+ $query = db_update('textbook_companion_preference');
+ $query->fields(array(
+ 'approval_status' => 1
+ ));
+ $query->condition('id', $preference_id);
+ $num_updated = $query->execute();
+ /* unlock aicte books except the one which was approved out of 3 nos */
+ /* $query = "
+ 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);*/
+ /*$query = db_update('textbook_companion_aicte');
+ $query->fields(array(
+ 'status' => 0,
+ 'uid' => 0,
+ 'proposal_id' => 0,
+ 'preference_id' => 0,
+ ));
+ $query->condition('proposal_id', '$proposal_id');
+ $query->condition('preference_id', '$preference_id', '<>');
+ $num_updated = $query->execute();*/
+ /* sending email */
+ $book_user = user_load($row->uid);
+ $email_to = $book_user->mail;
+ $from = variable_get('textbook_companion_from_email', '');
+ $bcc = variable_get('textbook_companion_bcc_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('textbook-companion/manage-proposal');
+ return;
}
/******************************************************************************/
/*************************** PROPOSAL STATUS FORM *****************************/
/******************************************************************************/
function proposal_status_form($from, $form_state)
{
- global $user;
- /* get current proposal */
- $proposal_id = arg(3);
- /*$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('textbook-companion/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/Village')
- );
- $form['pincode'] = array(
- '#type' => 'item',
- '#markup' => $proposal_data->pincode,
- '#title' => t('Pincode')
- );
- $form['state'] = array(
- '#type' => 'item',
- '#markup' => $proposal_data->state,
- '#title' => t('State')
- );
- $form['faculty'] = array(
- '#type' => 'hidden',
- '#markup' => $proposal_data->faculty,
- '#title' => t('College Teacher/Professor')
- );
- $form['reviewer'] = array(
- '#type' => 'hidden',
- '#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['version'] = array(
- '#type' => 'item',
- '#markup' => $proposal_data->dwsim_version,
- '#title' => t('DWSIM Version')
- );
- if ($proposal_data->proposal_type == 1) {
- $form['reason'] = array(
- '#type' => 'hidden',
- '#markup' => $proposal_data->reason,
- '#title' => t('Reason')
- );
- $form['reference'] = array(
- '#type' => 'hidden',
- '#markup' => $proposal_data->reference,
- '#title' => t('References')
- );
- }
- /* 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_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;
- case 5:
- $proposal_status = t('Submitted all codes');
- 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')
- );
- }
- $query = db_select('textbook_companion_preference');
- $query->fields('textbook_companion_preference');
- $query->condition('proposal_id', $proposal_id);
- $query->orderBy('pref_number', 'ASC');
- $preference_q_status = $query->execute()->fetchObject();
- if ($preference_q_status->submited_all_examples_code < 1 && $proposal_data->proposal_status == 5) {
- $form['submit_all_code'] = array(
- '#type' => 'checkbox',
- '#title' => t('<strong>Enable Code Submission for user</strong>'),
- '#description' => t('Check if user has not submitted all the book examples.')
- );
- $form['completed'] = array(
- '#type' => 'hidden',
- '#value' => 0
- );
- }
- if ($proposal_data->proposal_status == 1 || $proposal_data->proposal_status == 4 || $preference_q_status->submited_all_examples_code == 1 && $proposal_data->proposal_status == 5) {
- $form['completed'] = array(
- '#type' => 'checkbox',
- '#title' => t('<strong>Completed</strong>'),
- '#description' => t('Check if user has completed all the book examples.')
- );
- $form['submit_all_code'] = array(
- '#type' => 'hidden',
- '#value' => 0
- );
- }
- if ($proposal_data->proposal_status == 0) {
- $form['approve'] = array(
- '#type' => 'item',
- '#markup' => l('Click here', 'textbook-companion/manage-proposal/approve/' . $proposal_id),
- '#title' => t('Approve')
- );
- $form['completed'] = array(
- '#type' => 'hidden',
- '#value' => 0
- );
- $form['submit_all_code'] = array(
- '#type' => 'hidden',
- '#value' => 0
- );
- }
- $form['proposal_id'] = array(
- '#type' => 'hidden',
- '#value' => $proposal_id
- );
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Submit')
- );
- $form['cancel'] = array(
- '#type' => 'item',
- '#markup' => l(t('Cancel'), 'textbook-companion/manage-proposal/all')
- );
- return $form;
+ global $user;
+ /* get current proposal */
+ $proposal_id = arg(3);
+ /*$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('textbook-companion/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/Village')
+ );
+ $form['pincode'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->pincode,
+ '#title' => t('Pincode')
+ );
+ $form['state'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->state,
+ '#title' => t('State')
+ );
+ $form['faculty'] = array(
+ '#type' => 'hidden',
+ '#markup' => $proposal_data->faculty,
+ '#title' => t('College Teacher/Professor')
+ );
+ $form['reviewer'] = array(
+ '#type' => 'hidden',
+ '#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['version'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->dwsim_version,
+ '#title' => t('DWSIM Version')
+ );
+ if ($proposal_data->proposal_type == 1) {
+ $form['reason'] = array(
+ '#type' => 'hidden',
+ '#markup' => $proposal_data->reason,
+ '#title' => t('Reason')
+ );
+ $form['reference'] = array(
+ '#type' => 'hidden',
+ '#markup' => $proposal_data->reference,
+ '#title' => t('References')
+ );
+ } //$proposal_data->proposal_type == 1
+ /* 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'] = 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;
+ case 5:
+ $proposal_status = t('Submitted all codes');
+ 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
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('proposal_id', $proposal_id);
+ $query->orderBy('pref_number', 'ASC');
+ $preference_q_status = $query->execute()->fetchObject();
+ if ($preference_q_status->submited_all_examples_code < 1 && $proposal_data->proposal_status == 5) {
+ $form['submit_all_code'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('<strong>Enable Code Submission for user</strong>'),
+ '#description' => t('Check if user has not submitted all the book examples.')
+ );
+ $form['completed'] = array(
+ '#type' => 'hidden',
+ '#value' => 0
+ );
+ } //$preference_q_status->submited_all_examples_code < 1 && $proposal_data->proposal_status == 5
+ if ($proposal_data->proposal_status == 1 || $proposal_data->proposal_status == 4 || $preference_q_status->submited_all_examples_code == 1 && $proposal_data->proposal_status == 5) {
+ $form['completed'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('<strong>Completed</strong>'),
+ '#description' => t('Check if user has completed all the book examples.')
+ );
+ $form['submit_all_code'] = array(
+ '#type' => 'hidden',
+ '#value' => 0
+ );
+ } //$proposal_data->proposal_status == 1 || $proposal_data->proposal_status == 4 || $preference_q_status->submited_all_examples_code == 1 && $proposal_data->proposal_status == 5
+ if ($proposal_data->proposal_status == 0) {
+ $form['approve'] = array(
+ '#type' => 'item',
+ '#markup' => l('Click here', 'textbook-companion/manage-proposal/approve/' . $proposal_id),
+ '#title' => t('Approve')
+ );
+ $form['completed'] = array(
+ '#type' => 'hidden',
+ '#value' => 0
+ );
+ $form['submit_all_code'] = array(
+ '#type' => 'hidden',
+ '#value' => 0
+ );
+ } //$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' => 'item',
+ '#markup' => l(t('Cancel'), 'textbook-companion/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);*/
- $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('textbook-companion/manage-proposal');
- return;
- }
- if ($form_state['values']['submit_all_code'] == 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' => 1
- ));
- $query->condition('id', $proposal_id);
- $num_updated = $query->execute();
- /* sending email */
- $book_user = user_load($proposal_data->uid);
- $params['all_code_submitted_status_changed']['proposal_id'] = $proposal_id;
- $params['all_code_submitted_status_changed']['user_id'] = $proposal_data->uid;
- $email_to = $book_user->mail;
- if (!drupal_mail('textbook_companion', 'all_code_submitted_status_changed', $email_to, language_default(), $params, variable_get('textbook_companion_from_email', NULL), TRUE))
- drupal_set_message('Error sending email message.', 'error');
- drupal_set_message('User has been notified of that code submission interface is now available .', 'status');
- drupal_goto('textbook-companion/manage-proposal');
- return;
- } else /* 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();
- CreateReadmeFileTextbookCompanion($proposal_id);
- /* sending email */
- $book_user = user_load($proposal_data->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', '');
- $param['proposal_completed']['proposal_id'] = $proposal_id;
- $param['proposal_completed']['user_id'] = $proposal_data->uid;
- $param['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(), $param, $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');
- } else {
- drupal_set_message('Please select any one action.', 'error');
- drupal_goto('textbook-companion/manage-proposal/status/' . $proposal_id);
- return;
- }
- drupal_goto('textbook-companion/manage-proposal');
- return;
+ 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('textbook-companion/manage-proposal');
+ return;
+ } //!$proposal_data = $proposal_q->fetchObject()
+ if ($form_state['values']['submit_all_code'] == 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' => 1
+ ));
+ $query->condition('id', $proposal_id);
+ $num_updated = $query->execute();
+ /* sending email */
+ $book_user = user_load($proposal_data->uid);
+ $params['all_code_submitted_status_changed']['proposal_id'] = $proposal_id;
+ $params['all_code_submitted_status_changed']['user_id'] = $proposal_data->uid;
+ $email_to = $book_user->mail;
+ if (!drupal_mail('textbook_companion', 'all_code_submitted_status_changed', $email_to, language_default(), $params, variable_get('textbook_companion_from_email', NULL), TRUE))
+ drupal_set_message('Error sending email message.', 'error');
+ drupal_set_message('User has been notified of that code submission interface is now available .', 'status');
+ drupal_goto('textbook-companion/manage-proposal');
+ return;
+ } //$form_state['values']['submit_all_code'] == 1
+ else /* 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();
+ CreateReadmeFileTextbookCompanion($proposal_id);
+ /* sending email */
+ $book_user = user_load($proposal_data->uid);
+ $email_to = $book_user->mail;
+ $from = variable_get('textbook_companion_from_email', '');
+ $bcc = variable_get('textbook_companion_bcc_emails', '');
+ $cc = variable_get('textbook_companion_cc_emails', '');
+ $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
+ else {
+ drupal_set_message('Please select any one action.', 'error');
+ drupal_goto('textbook-companion/manage-proposal/status/' . $proposal_id);
+ return;
+ }
+ drupal_goto('textbook-companion/manage-proposal');
+ return;
}
/******************************************************************************/
/**************************** PROPOSAL EDIT FORM ******************************/
/******************************************************************************/
function proposal_edit_form($fom, $form_state, $nonaicte_book)
{
- global $user;
- /* get current proposal */
- $proposal_id = arg(3);
- /*$proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d", $proposal_id);*/
- $query = db_select('textbook_companion_proposal');
- $query->fields('textbook_companion_proposal');
- $query->condition('id', $proposal_id);
- $proposal_q = $query->execute();
- if ($proposal_q) {
- $proposal_data = $proposal_q->fetchObject();
- if (!$proposal_data) {
- drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
- drupal_goto('textbook-companion/manage-proposal');
- return;
- }
- } else {
- drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
- drupal_goto('textbook-companion/manage-proposal');
- return;
- }
- $user_data = user_load($proposal_data->uid);
- /* $preference1_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $proposal_id, 1);
- $preference1_data = db_fetch_object($preference1_q);*/
- $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();
- /********************************************************************/
- $query = db_select('textbook_companion_preference');
- $query->fields('textbook_companion_preference');
- $query->condition('proposal_id', $proposal_id);
- $query->condition('pref_number', 2);
- $query->range(0, 1);
- $preference2_q = $query->execute();
- $preference2_data = $preference2_q->fetchObject();
- /**************************************************************************/
- $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(
- 'DWSIM Website' => 'DWSIM 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' => _list_of_departments(),
- '#required' => TRUE,
- '#default_value' => $proposal_data->branch
- );
- $form['university'] = array(
- '#type' => 'textfield',
- '#title' => t('University/ Institute'),
- '#size' => 80,
- '#maxlength' => 200,
- '#required' => TRUE,
- '#attributes' => array(
- 'placeholder' => 'Insert full name of your institute/ university.... '
- ),
- '#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,
- '#default_value' => $proposal_data->state,
- '#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,
- '#default_value' => $proposal_data->city,
- '#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'),
- '#selected' => array(
- '' => '-select-'
- ),
- '#options' => _list_of_states(),
- '#default_value' => $proposal_data->state,
- '#validated' => TRUE,
- '#states' => array(
- 'visible' => array(
- ':input[name="country"]' => array(
- 'value' => 'India'
- )
- )
- )
- );
- $form['city'] = array(
- '#type' => 'select',
- '#title' => t('City'),
- '#default_value' => $proposal_data->city,
- '#options' => _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,
- '#default_value' => $proposal_data->pincode,
- '#attributes' => array(
- 'placeholder' => 'Enter pincode....'
- )
- );
- /***************************************************************************/
- $form['hr'] = array(
- '#type' => 'item',
- '#markup' => '<hr>'
- );
- $form['faculty'] = array(
- '#type' => 'hidden',
- '#title' => t('College Teacher/Professor'),
- '#size' => 30,
- '#maxlength' => 100,
- '#required' => TRUE,
- '#default_value' => $proposal_data->faculty
- );
- $form['reviewer'] = array(
- '#type' => 'hidden',
- '#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['version'] = array(
- '#type' => 'textfield',
- '#title' => t('DWSIM Version'),
- '#size' => 10,
- '#maxlength' => 20,
- '#default_value' => $proposal_data->dwsim_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
- );
- 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
- );
- }
- 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
- );
- }
- /* hidden fields */
- $form['hidden_preference_id1'] = array(
- '#type' => 'hidden',
- '#value' => $preference1_data->id
- );
- /* $form['hidden_preference_id2'] = array(
- '#type' => 'hidden',
- '#value' => $preference2_data->id
- );
- $form['hidden_preference_id3'] = array(
- '#type' => 'hidden',
- '#value' => $preference3_data->id
- );*/
- $form['hidden_proposal_id'] = array(
- '#type' => 'hidden',
- '#value' => $proposal_id
- );
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Submit')
- );
- $form['cancel'] = array(
- '#type' => 'item',
- '#markup' => l(t('Cancel'), 'textbook-companion/manage-proposal')
- );
- return $form;
+ global $user;
+ /* get current proposal */
+ $proposal_id = arg(3);
+ /*$proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d", $proposal_id);*/
+ $query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal');
+ $query->condition('id', $proposal_id);
+ $proposal_q = $query->execute();
+ if ($proposal_q) {
+ $proposal_data = $proposal_q->fetchObject();
+ if (!$proposal_data) {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('textbook-companion/manage-proposal');
+ return;
+ } //!$proposal_data
+ } //$proposal_q
+ else {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('textbook-companion/manage-proposal');
+ return;
+ }
+ $user_data = user_load($proposal_data->uid);
+ /* $preference1_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $proposal_id, 1);
+ $preference1_data = db_fetch_object($preference1_q);*/
+ $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();
+ /********************************************************************/
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('proposal_id', $proposal_id);
+ $query->condition('pref_number', 2);
+ $query->range(0, 1);
+ $preference2_q = $query->execute();
+ $preference2_data = $preference2_q->fetchObject();
+ /**************************************************************************/
+ $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(
+ 'DWSIM Website' => 'DWSIM 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' => _list_of_departments(),
+ '#required' => TRUE,
+ '#default_value' => $proposal_data->branch
+ );
+ $form['university'] = array(
+ '#type' => 'textfield',
+ '#title' => t('University/ Institute'),
+ '#size' => 80,
+ '#maxlength' => 200,
+ '#required' => TRUE,
+ '#attributes' => array(
+ 'placeholder' => 'Insert full name of your institute/ university.... '
+ ),
+ '#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,
+ '#default_value' => $proposal_data->state,
+ '#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,
+ '#default_value' => $proposal_data->city,
+ '#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'),
+ '#selected' => array(
+ '' => '-select-'
+ ),
+ '#options' => _list_of_states(),
+ '#default_value' => $proposal_data->state,
+ '#validated' => TRUE,
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="country"]' => array(
+ 'value' => 'India'
+ )
+ )
+ )
+ );
+ $form['city'] = array(
+ '#type' => 'select',
+ '#title' => t('City'),
+ '#default_value' => $proposal_data->city,
+ '#options' => _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,
+ '#default_value' => $proposal_data->pincode,
+ '#attributes' => array(
+ 'placeholder' => 'Enter pincode....'
+ )
+ );
+ /***************************************************************************/
+ $form['hr'] = array(
+ '#type' => 'item',
+ '#markup' => '<hr>'
+ );
+ $form['faculty'] = array(
+ '#type' => 'hidden',
+ '#title' => t('College Teacher/Professor'),
+ '#size' => 30,
+ '#maxlength' => 100,
+ '#required' => TRUE,
+ '#default_value' => $proposal_data->faculty
+ );
+ $form['reviewer'] = array(
+ '#type' => 'hidden',
+ '#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['version'] = array(
+ '#type' => 'textfield',
+ '#title' => t('DWSIM Version'),
+ '#size' => 10,
+ '#maxlength' => 20,
+ '#default_value' => $proposal_data->dwsim_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
+ );
+ 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
+ );
+ } //$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
+ );
+ } //$preference3_data
+ /* hidden fields */
+ $form['hidden_preference_id1'] = array(
+ '#type' => 'hidden',
+ '#value' => $preference1_data->id
+ );
+ /* $form['hidden_preference_id2'] = array(
+ '#type' => 'hidden',
+ '#value' => $preference2_data->id
+ );
+ $form['hidden_preference_id3'] = array(
+ '#type' => 'hidden',
+ '#value' => $preference3_data->id
+ );*/
+ $form['hidden_proposal_id'] = array(
+ '#type' => 'hidden',
+ '#value' => $proposal_id
+ );
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit')
+ );
+ $form['cancel'] = array(
+ '#type' => 'item',
+ '#markup' => l(t('Cancel'), 'textbook-companion/manage-proposal')
+ );
+ return $form;
}
function proposal_edit_form_validate($form, &$form_state)
{
- if ($form_state['values']['book1'] && $form_state['values']['author1']) {
- $bk1 = trim($form_state['values']['book1']);
- $auth1 = trim($form_state['values']['author1']);
- if (_dir_name($bk1, $auth1, $form_state['values']['hidden_preference_id1']) != NULL) {
- $form_state['values']['dir_name1'] = _dir_name($bk1, $auth1, $form_state['values']['hidden_preference_id1']);
- }
- }
- /*if ($form_state['values']['book2'] && $form_state['values']['author2'])
- {
- $bk2 = trim($form_state['values']['book2']);
- $auth2 = trim($form_state['values']['author2']);
-
- if (_dir_name($bk2, $auth2, $form_state['values']['hidden_preference_id2']) != NULL)
- {
- $form_state['values']['dir_name2'] = _dir_name($bk2, $auth2, $form_state['values']['hidden_preference_id2']);
- }
- }
- if ($form_state['values']['book3'] && $form_state['values']['author3'])
- {
- $bk3 = trim($form_state['values']['book3']);
- $auth3 = trim($form_state['values']['author3']);
-
- if (_dir_name($bk3, $auth3, $form_state['values']['hidden_preference_id3']) != NULL)
- {
- $form_state['values']['dir_name3'] = _dir_name($bk3, $auth3, $form_state['values']['hidden_preference_id3']);
- }
- }
- /* 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 ($form_state['values']['version'] == 'olderversion') {
- if ($form_state['values']['older'] == '') {
- form_set_error('older', t('Please provide valid version'));
- }
- }
- return;
+ if ($form_state['values']['book1'] && $form_state['values']['author1']) {
+ $bk1 = trim($form_state['values']['book1']);
+ $auth1 = trim($form_state['values']['author1']);
+ if (_dir_name($bk1, $auth1, $form_state['values']['hidden_preference_id1']) != NULL) {
+ $form_state['values']['dir_name1'] = _dir_name($bk1, $auth1, $form_state['values']['hidden_preference_id1']);
+ } //_dir_name($bk1, $auth1, $form_state['values']['hidden_preference_id1']) != NULL
+ } //$form_state['values']['book1'] && $form_state['values']['author1']
+ /*if ($form_state['values']['book2'] && $form_state['values']['author2'])
+ {
+ $bk2 = trim($form_state['values']['book2']);
+ $auth2 = trim($form_state['values']['author2']);
+
+ if (_dir_name($bk2, $auth2, $form_state['values']['hidden_preference_id2']) != NULL)
+ {
+ $form_state['values']['dir_name2'] = _dir_name($bk2, $auth2, $form_state['values']['hidden_preference_id2']);
+ }
+ }
+ if ($form_state['values']['book3'] && $form_state['values']['author3'])
+ {
+ $bk3 = trim($form_state['values']['book3']);
+ $auth3 = trim($form_state['values']['author3']);
+
+ if (_dir_name($bk3, $auth3, $form_state['values']['hidden_preference_id3']) != NULL)
+ {
+ $form_state['values']['dir_name3'] = _dir_name($bk3, $auth3, $form_state['values']['hidden_preference_id3']);
+ }
+ }
+ /* 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 ($form_state['values']['version'] == 'olderversion') {
+ if ($form_state['values']['older'] == '') {
+ form_set_error('older', t('Please provide valid version'));
+ } //$form_state['values']['older'] == ''
+ } //$form_state['values']['version'] == 'olderversion'
+ return;
}
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);
- $proposal_id = $form_state['values']['hidden_proposal_id'];
- if ($form_state['values']['version'] == 'olderversion') {
- $form_state['values']['version'] = $form_state['values']['older'];
- }
- if ($form_state['values']['country'] == 'other') {
- $form_state['values']['country'] = $form_state['values']['other_country'];
- $form_state['values']['all_state'] = $form_state['values']['other_state'];
- }
- $query = db_update('textbook_companion_proposal');
- $query->fields(array(
- 'full_name' => $form_state['values']['full_name'],
- 'mobile' => $form_state['values']['mobile'],
- 'how_project' => $form_state['values']['how_project'],
- 'course' => $form_state['values']['course'],
- 'branch' => $form_state['values']['branch'],
- 'university' => $form_state['values']['university'],
- 'city' => $form_state['values']['city'],
- 'pincode' => $form_state['values']['pincode'],
- 'state' => $form_state['values']['all_state'],
- 'country' => $form_state['values']['country'],
- 'faculty' => $form_state['values']['faculty'],
- 'reviewer' => $form_state['values']['reviewer'],
- 'completion_date' => $completion_date_timestamp,
- 'operating_system' => $form_state['values']['operating_system'],
- 'dwsim_version' => $form_state['values']['version']
- ));
- $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();
- $preference1_id = $preference1_data->id;
- if ($preference1_data) {
- del_book_pdf($preference1_data->id);
- RenameDir($preference1_id, $form_state['values']['dir_name1']);
- $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'],
- 'directory_name' => $form_state['values']['dir_name1']
- ));
- $query->condition('id', $preference1_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', 2);
- $query->range(0, 1);
- $preference2_q = $query->execute();
- $preference2_data = $preference2_q->fetchObject();
- $preference2_id = $preference2_data->id;
- if ($preference2_data)
- {
- del_book_pdf($preference2_data->id);
- RenameDir($preference2_id, $form_state['values']['dir_name2']);
- $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'],
- 'directory_name' => $form_state['values']['dir_name2']
- ));
- $query->condition('id', $preference2_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', 3);
- $query->range(0, 1);
- $preference3_q = $query->execute();
- $preference3_data = $preference3_q->fetchObject();
- $preference3_id = $preference3_data->id;
- if ($preference3_data)
- {
- del_book_pdf($preference3_data->id);
- RenameDir($preference3_id, $form_state['values']['dir_name3']);
- $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'],
- 'directory_name' => $form_state['values']['dir_name3']
- ));
- $query->condition('id', $preference3_id);
- $num_updated = $query->execute();
- }**/
- drupal_set_message(t('Proposal Updated'), 'status');
+ /* completion date to timestamp */
+ list($d, $m, $y) = explode('-', $form_state['values']['completion_date']);
+ $completion_date_timestamp = mktime(0, 0, 0, $m, $d, $y);
+ $proposal_id = $form_state['values']['hidden_proposal_id'];
+ if ($form_state['values']['version'] == 'olderversion') {
+ $form_state['values']['version'] = $form_state['values']['older'];
+ } //$form_state['values']['version'] == 'olderversion'
+ if ($form_state['values']['country'] == 'other') {
+ $form_state['values']['country'] = $form_state['values']['other_country'];
+ $form_state['values']['all_state'] = $form_state['values']['other_state'];
+ } //$form_state['values']['country'] == 'other'
+ $query = db_update('textbook_companion_proposal');
+ $query->fields(array(
+ 'full_name' => $form_state['values']['full_name'],
+ 'mobile' => $form_state['values']['mobile'],
+ 'how_project' => $form_state['values']['how_project'],
+ 'course' => $form_state['values']['course'],
+ 'branch' => $form_state['values']['branch'],
+ 'university' => $form_state['values']['university'],
+ 'city' => $form_state['values']['city'],
+ 'pincode' => $form_state['values']['pincode'],
+ 'state' => $form_state['values']['all_state'],
+ 'country' => $form_state['values']['country'],
+ 'faculty' => $form_state['values']['faculty'],
+ 'reviewer' => $form_state['values']['reviewer'],
+ 'completion_date' => $completion_date_timestamp,
+ 'operating_system' => $form_state['values']['operating_system'],
+ 'dwsim_version' => $form_state['values']['version']
+ ));
+ $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();
+ $preference1_id = $preference1_data->id;
+ if ($preference1_data) {
+ del_book_pdf($preference1_data->id);
+ RenameDir($preference1_id, $form_state['values']['dir_name1']);
+ $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'],
+ 'directory_name' => $form_state['values']['dir_name1']
+ ));
+ $query->condition('id', $preference1_id);
+ $num_updated = $query->execute();
+ } //$preference1_data
+ /**************************************************************/
+ /**$query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('proposal_id', $proposal_id);
+ $query->condition('pref_number', 2);
+ $query->range(0, 1);
+ $preference2_q = $query->execute();
+ $preference2_data = $preference2_q->fetchObject();
+ $preference2_id = $preference2_data->id;
+ if ($preference2_data)
+ {
+ del_book_pdf($preference2_data->id);
+ RenameDir($preference2_id, $form_state['values']['dir_name2']);
+ $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'],
+ 'directory_name' => $form_state['values']['dir_name2']
+ ));
+ $query->condition('id', $preference2_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', 3);
+ $query->range(0, 1);
+ $preference3_q = $query->execute();
+ $preference3_data = $preference3_q->fetchObject();
+ $preference3_id = $preference3_data->id;
+ if ($preference3_data)
+ {
+ del_book_pdf($preference3_data->id);
+ RenameDir($preference3_id, $form_state['values']['dir_name3']);
+ $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'],
+ 'directory_name' => $form_state['values']['dir_name3']
+ ));
+ $query->condition('id', $preference3_id);
+ $num_updated = $query->execute();
+ }**/
+ drupal_set_message(t('Proposal Updated'), 'status');
}
/******************************************************************************/
/**************************** CATEGORY EDIT FORM ******************************/
/******************************************************************************/
function category_edit_form($from, $form_state)
{
- /* get current proposal */
- $preference_id = arg(3);
- /*$preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d", $preference_id);
- $preference_data = db_fetch_object($preference_q);*/
- $query = db_select('textbook_companion_preference');
- $query->fields('textbook_companion_preference');
- $query->condition('id', $preference_id);
- $result = $query->execute();
- if (!$preference_data) {
- drupal_set_message(t('Invalid book selected. Please try again.'), 'error');
- drupal_goto('textbook-companion/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_categories(),
- '#required' => TRUE,
- '#default_value' => $preference_data->category
- );
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Submit')
- );
- $form['cancel'] = array(
- '#type' => 'markup',
- '#value' => l(t('Cancel'), 'textbook-companion/manage-proposal/category')
- );
- return $form;
+ /* get current proposal */
+ $preference_id = arg(3);
+ /*$preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d", $preference_id);
+ $preference_data = db_fetch_object($preference_q);*/
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('id', $preference_id);
+ $result = $query->execute();
+ if (!$preference_data) {
+ drupal_set_message(t('Invalid book selected. Please try again.'), 'error');
+ drupal_goto('textbook-companion/manage-proposal/category');
+ return;
+ } //!$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_categories(),
+ '#required' => TRUE,
+ '#default_value' => $preference_data->category
+ );
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit')
+ );
+ $form['cancel'] = array(
+ '#type' => 'markup',
+ '#value' => l(t('Cancel'), 'textbook-companion/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);*/
- $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('textbook-companion/manage-proposal/category');
- return;
- }
- /*db_query("UPDATE {textbook_companion_preference} SET category = %d WHERE id = %d", $form_state['values']['category'], $preference_data->id);*/
- $query = db_update('textbook_companion_preference');
- $query->fields(array(
- 'category' => $form_state['values']['category']
- ));
- $query->condition('id', $preference_data->id);
- $num_updated = $query->execute();
- drupal_set_message(t('Book Category Updated'), 'status');
- drupal_goto('textbook-companion/manage-proposal/category');
+ /* 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();
+ if (!$preference_data) {
+ drupal_set_message(t('Invalid book selected. Please try again.'), 'error');
+ drupal_goto('textbook-companion/manage-proposal/category');
+ return;
+ } //!$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']
+ ));
+ $query->condition('id', $preference_data->id);
+ $num_updated = $query->execute();
+ drupal_set_message(t('Book Category Updated'), 'status');
+ drupal_goto('textbook-companion/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");*/
- $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', 'textbook-companion/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(
- 'headers' => $proposal_header,
- 'rows' => $proposal_rows
- ));
- return $output;
+ /* 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', 'textbook-companion/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(
+ 'headers' => $proposal_header,
+ 'rows' => $proposal_rows
+ ));
+ return $output;
}
function dataentry_edit($id = NULL)
{
- if ($id) {
- return drupal_get_form('dataentry_edit_form', $id);
- } else {
- return 'Access denied';
- }
+ if ($id) {
+ return drupal_get_form('dataentry_edit_form', $id);
+ } //$id
+ else {
+ return 'Access denied';
+ }
}
function dataentry_edit_form($form_state, $id)
{
- global $user;
- /*$preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d", $id);
- $preference_data = db_fetch_object($preference_q);*/
- $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;
+ global $user;
+ /*$preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d", $id);
+ $preference_data = db_fetch_object($preference_q);*/
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('id', $id);
+ $preference_q = $query->execute();
+ $preference_data = $preference_q->fetchObject();
+ $form['id'] = array(
+ '#type' => 'hidden',
+ '#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)
{
- /*db_query("UPDATE {textbook_companion_preference} SET book = '%s', author = '%s', isbn = '%s', publisher = '%s', edition = '%s', year = %d WHERE id = %d", $_POST['book'], $_POST['author'], $_POST['isbn'], $_POST['publisher'], $_POST['edition'], $_POST['year'], $_POST['id']);*/
- $query = db_update('textbook_companion_preference');
- $query->fields(array(
- 'book' => $_POST['book'],
- 'author' => $_POST['author'],
- 'isbn' => $_POST['isbn'],
- 'publisher' => $_POST['publisher'],
- 'edition' => $_POST['edition'],
- 'year' => $_POST['year']
- ));
- $query->condition('id', $_POST['id']);
- $num_updated = $query->execute();
- drupal_set_message('Book details updated successfully');
- drupal_goto('dataentry_book');
+ /*db_query("UPDATE {textbook_companion_preference} SET book = '%s', author = '%s', isbn = '%s', publisher = '%s', edition = '%s', year = %d WHERE id = %d", $_POST['book'], $_POST['author'], $_POST['isbn'], $_POST['publisher'], $_POST['edition'], $_POST['year'], $_POST['id']);*/
+ $query = db_update('textbook_companion_preference');
+ $query->fields(array(
+ 'book' => $_POST['book'],
+ 'author' => $_POST['author'],
+ 'isbn' => $_POST['isbn'],
+ 'publisher' => $_POST['publisher'],
+ 'edition' => $_POST['edition'],
+ 'year' => $_POST['year']
+ ));
+ $query->condition('id', $_POST['id']);
+ $num_updated = $query->execute();
+ drupal_set_message('Book details updated successfully');
+ drupal_goto('dataentry_book');
}
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);
- $row = db_fetch_object($result);*/
- $query = db_select('textbook_companion_proposal', 'pro');
- $query->fields('*', array(
- ''
- ));
- $query->fields('pro', array(
- 'id'
- ));
- $query->leftJoin('textbook_companion_preference', 'pre', 'pre.proposal_id = pro.id');
- $query->leftJoin('users', 'usr', 'usr.uid = pro.uid');
- $query->condition('pre.id', '$preference_id');
- $result = $query->execute();
- $row = $result->fetchObject();
- /* increment failed_reminder */
- /*$query = "
- UPDATE textbook_companion_proposal
- SET failed_reminder = failed_reminder + 1
- WHERE id = {$row->proposal_id}
- ";
- db_query($query);*/
- $query = db_update('textbook_companion_proposal');
- $query->fields(array(
- 'failed_reminder' => 'failed_reminder + 1'
- ));
- $query->condition('id', '$row->proposal_id');
- $num_updated = $query->execute();
- /* sending mail */
- $to = $row->mail;
- $subject = "Failed to upload the TBC codes on time";
- $body = "
+ $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);
+ $row = db_fetch_object($result);*/
+ $query = db_select('textbook_companion_proposal', 'pro');
+ $query->fields('*', array(
+ ''
+ ));
+ $query->fields('pro', array(
+ 'id'
+ ));
+ $query->leftJoin('textbook_companion_preference', 'pre', 'pre.proposal_id = pro.id');
+ $query->leftJoin('users', 'usr', 'usr.uid = pro.uid');
+ $query->condition('pre.id', '$preference_id');
+ $result = $query->execute();
+ $row = $result->fetchObject();
+ /* increment failed_reminder */
+ /*$query = "
+ UPDATE textbook_companion_proposal
+ SET failed_reminder = failed_reminder + 1
+ WHERE id = {$row->proposal_id}
+ ";
+ db_query($query);*/
+ $query = db_update('textbook_companion_proposal');
+ $query->fields(array(
+ 'failed_reminder' => 'failed_reminder + 1'
+ ));
+ $query->condition('id', '$row->proposal_id');
+ $num_updated = $query->execute();
+ /* sending mail */
+ $to = $row->mail;
+ $subject = "Failed to upload the TBC codes on time";
+ $body = "
<p>
Dear {$row->name},<br><br>
This is to inform you that you have failed to upload the TBC codes on time.<br>
@@ -1731,144 +1741,149 @@ function _failed_all($preference_id = 0, $confirm = "")
DWSIM TBC Team
</p>
";
- $message = array(
- "to" => $to,
- "subject" => $subject,
- "body" => $body,
- "headers" => array(
- "From" => "contact-dwsim@fossee.in",
- "Bcc" => "contact-dwsim@fossee.in",
- "Content-Type" => "text/html; charset=UTF-8; format=flowed"
- )
- );
- drupal_mail_send($message);
- drupal_set_message("Reminder sent successfully.");
- drupal_goto("textbook-companion/manage-proposal/failed");
- } else if ($preference_id) {
- /*$query = "
- SELECT * FROM textbook_companion_preference pre
- LEFT JOIN textbook_companion_proposal pro ON pro.id = pre.proposal_id
- WHERE pre.id = {$preference_id}
- ";
- $result = db_query($query);
- $row = db_fetch_object($result);*/
- $query = db_select('textbook_companion_preference', 'pre');
- $query->fields('pre');
- $query->leftJoin('textbook_companion_proposal', 'pro', 'pro.id = pre.proposal_id');
- $query->condition('pre.id', $preference_id);
- $result = $query->execute();
- $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", "textbook-companion/manage-proposal/failed/{$preference_id}/yes") . " | ";
- $page_content .= l("Cancel", "textbook-companion/manage-proposal/failed");
- } 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 < %d
- ORDER BY failed_reminder
- ";
- $result = db_query($query, time());*/
- $query = db_select('textbook_companion_proposal', 'pro');
- $query->fields('pro');
- $query->leftJoin('textbook_companion_preference', 'pre', 'pre.proposal_id = pro.id');
- $query->leftJoin('users', 'usr', 'usr.uid = pro.uid');
- $query->condition('pro.proposal_status', 1);
- $query->condition('pre.approval_status', 1);
- $query->condition('pro.completion_date', '%time()', '<');
- $query->orderBy('failed_reminder', 'ASC');
- $result = $query->execute();
- $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->name,
- date("d-m-Y", $row->completion_date),
- $row->failed_reminder,
- l("Remind", "textbook-companion/manage-proposal/failed/{$row->id}")
- );
- array_push($rows, $item);
- }
- $page_content .= theme('table', array(
- 'header' => $headers,
- 'rows' => $rows
- ));
- }
- return $page_content;
+ $message = array(
+ "to" => $to,
+ "subject" => $subject,
+ "body" => $body,
+ "headers" => array(
+ "From" => "contact-dwsim@fossee.in",
+ "Bcc" => "contact-dwsim@fossee.in",
+ "Content-Type" => "text/html; charset=UTF-8; format=flowed"
+ )
+ );
+ drupal_mail_send($message);
+ drupal_set_message("Reminder sent successfully.");
+ drupal_goto("textbook-companion/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);
+ $row = db_fetch_object($result);*/
+ $query = db_select('textbook_companion_preference', 'pre');
+ $query->fields('pre');
+ $query->leftJoin('textbook_companion_proposal', 'pro', 'pro.id = pre.proposal_id');
+ $query->condition('pre.id', $preference_id);
+ $result = $query->execute();
+ $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", "textbook-companion/manage-proposal/failed/{$preference_id}/yes") . " | ";
+ $page_content .= l("Cancel", "textbook-companion/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 < %d
+ ORDER BY failed_reminder
+ ";
+ $result = db_query($query, time());*/
+ $query = db_select('textbook_companion_proposal', 'pro');
+ $query->fields('pro');
+ $query->leftJoin('textbook_companion_preference', 'pre', 'pre.proposal_id = pro.id');
+ $query->leftJoin('users', 'usr', 'usr.uid = pro.uid');
+ $query->condition('pro.proposal_status', 1);
+ $query->condition('pre.approval_status', 1);
+ $query->condition('pro.completion_date', '%time()', '<');
+ $query->orderBy('failed_reminder', 'ASC');
+ $result = $query->execute();
+ $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->name,
+ date("d-m-Y", $row->completion_date),
+ $row->failed_reminder,
+ l("Remind", "textbook-companion/manage-proposal/failed/{$row->id}")
+ );
+ array_push($rows, $item);
+ } //$row = $result->fetchObject()
+ $page_content .= theme('table', array(
+ 'header' => $headers,
+ 'rows' => $rows
+ ));
+ }
+ return $page_content;
}
/***************************************************************************/
/*******Function to create readme file after book marked as completed*******/
/***************************************************************************/
function CreateReadmeFileTextbookCompanion($proposal_id)
{
- $result = db_query("
+ $result = db_query("
SELECT tcc.id AS proposal_id,tcc.full_name, tcc.course, tcc.branch, tcc.university, tcp.id as pref_id, tcp.directory_name, tcp.* FROM textbook_companion_preference tcp JOIN textbook_companion_proposal tcc ON tcp.proposal_id= tcc.id WHERE tcc.proposal_status = 3 AND tcp.approval_status = 1 AND tcc.id = :proposal_id
", array(
- ":proposal_id" => $proposal_id
- ));
- $proposal_data = $result->fetchObject();
- $root_path = textbook_companion_path();
- $readme_file = fopen($root_path . $proposal_data->directory_name . "/README.txt", "w") or die('unable to open file');
- $txt = "";
- $txt .= "About The Contributor" . "\n\n";
- $txt .= "Contributed By: " . ucwords(strtolower($proposal_data->full_name)) . "\n";
- $txt .= "Course: " . ucwords(strtolower($proposal_data->course)) . "\n";
- $txt .= "Branch: " . ucwords(strtolower($proposal_data->branch)) . "\n";
- $txt .= "College/Institute/Organization: " . ucwords(strtolower($proposal_data->university)) . "\n\n";
- $txt .= "About The Book" . "\n\n";
- $txt .= "Book: " . ucwords(strtolower($proposal_data->book)) . "\n";
- $txt .= "Author: " . ucwords(strtolower($proposal_data->author)) . "\n";
- $txt .= "Publisher: " . ucwords(strtolower($proposal_data->publisher)) . "\n";
- $txt .= "Year Of Publication: " . $proposal_data->year . "\n";
- $txt .= "ISBN: " . $proposal_data->isbn . "\n";
- $txt .= "Edition: " . ucwords(strtolower($proposal_data->edition)) . "\n";
- $txt .= "\n" . "\n";
- $txt .= "Textbook Companion Project By FOSSEE, IIT Bombay" . "\n";
- fwrite($readme_file, $txt);
- fclose($readme_file);
- return;
+ ":proposal_id" => $proposal_id
+ ));
+ $proposal_data = $result->fetchObject();
+ $root_path = textbook_companion_path();
+ $readme_file = fopen($root_path . $proposal_data->directory_name . "/README.txt", "w") or die('unable to open file');
+ $txt = "";
+ $txt .= "About The Contributor" . "\n\n";
+ $txt .= "Contributed By: " . ucwords(strtolower($proposal_data->full_name)) . "\n";
+ $txt .= "Course: " . ucwords(strtolower($proposal_data->course)) . "\n";
+ $txt .= "Branch: " . ucwords(strtolower($proposal_data->branch)) . "\n";
+ $txt .= "College/Institute/Organization: " . ucwords(strtolower($proposal_data->university)) . "\n\n";
+ $txt .= "About The Book" . "\n\n";
+ $txt .= "Book: " . ucwords(strtolower($proposal_data->book)) . "\n";
+ $txt .= "Author: " . ucwords(strtolower($proposal_data->author)) . "\n";
+ $txt .= "Publisher: " . ucwords(strtolower($proposal_data->publisher)) . "\n";
+ $txt .= "Year Of Publication: " . $proposal_data->year . "\n";
+ $txt .= "ISBN: " . $proposal_data->isbn . "\n";
+ $txt .= "Edition: " . ucwords(strtolower($proposal_data->edition)) . "\n";
+ $txt .= "\n" . "\n";
+ $txt .= "Textbook Companion Project By FOSSEE, IIT Bombay" . "\n";
+ fwrite($readme_file, $txt);
+ fclose($readme_file);
+ return;
}
function RenameDir($preference_id, $dir_name)
{
- $preference_id = $preference_id;
- $dir_name = $dir_name;
- $query = db_query("SELECT directory_name, proposal_id, id FROM textbook_companion_preference WHERE id = :preference_id", array(
- ':preference_id' => $preference_id
- ));
- $result = $query->fetchObject();
- if ($result != NULL) {
- $files = scandir(textbook_companion_path());
- $files_id_dir = textbook_companion_path() . $result->id;
- $file_dir = textbook_companion_path() . $result->directory_name;
- if (is_dir($file_dir)) {
- $new_directory_name = rename(textbook_companion_path() . $result->directory_name, textbook_companion_path() . $dir_name);
- CreateReadmeFileTextbookCompanion($result->proposal_id);
- return $new_directory_name;
- } else if (is_dir($files_id_dir)) {
- $new_directory_name = rename(textbook_companion_path() . $result->id, textbook_companion_path() . $dir_name);
- CreateReadmeFileTextbookCompanion($result->proposal_id);
- return $new_directory_name;
- } else {
- drupal_set_message('Can not rename the directory. If you are editing proposal before approving the proposal directory is not present because the code has been not uploaded yet. For more information please contact to administrator');
- return;
- }
- } else {
- drupal_set_message('Book names directory not present in databse');
- return;
- }
- return;
+ $preference_id = $preference_id;
+ $dir_name = $dir_name;
+ $query = db_query("SELECT directory_name, proposal_id, id FROM textbook_companion_preference WHERE id = :preference_id", array(
+ ':preference_id' => $preference_id
+ ));
+ $result = $query->fetchObject();
+ if ($result != NULL) {
+ $files = scandir(textbook_companion_path());
+ $files_id_dir = textbook_companion_path() . $result->id;
+ $file_dir = textbook_companion_path() . $result->directory_name;
+ if (is_dir($file_dir)) {
+ $new_directory_name = rename(textbook_companion_path() . $result->directory_name, textbook_companion_path() . $dir_name);
+ CreateReadmeFileTextbookCompanion($result->proposal_id);
+ return $new_directory_name;
+ } //is_dir($file_dir)
+ else if (is_dir($files_id_dir)) {
+ $new_directory_name = rename(textbook_companion_path() . $result->id, textbook_companion_path() . $dir_name);
+ CreateReadmeFileTextbookCompanion($result->proposal_id);
+ return $new_directory_name;
+ } //is_dir($files_id_dir)
+ else {
+ drupal_set_message('Can not rename the directory. If you are editing proposal before approving the proposal directory is not present because the code has been not uploaded yet. For more information please contact to administrator');
+ return;
+ }
+ } //$result != NULL
+ else {
+ drupal_set_message('Book names directory not present in databse');
+ return;
+ }
+ return;
}
diff --git a/pdf/1 b/pdf/1
deleted file mode 100755
index c795012..0000000
--- a/pdf/1
+++ /dev/null
@@ -1,51 +0,0 @@
-<?php
- function _list_all_certificates()
- {
- global $user;
- $uid1 = $user->uid;
-
- $query2 = db_query("SELECT * FROM {textbook_companion_proposal} WHERE proposal_status=3 AND uid=".$user->uid);
- $data2 = db_fetch_object($query2);
- if($data2->id)
- {
- $search_rows = array();
- global $output;
- $output = '';
- $query3 = db_query("SELECT * FROM textbook_companion_preference WHERE approval_status=1 AND proposal_id=".$data2->id);
-
- while ($search_data3 = db_fetch_object($query3))
- {
- $search_rows[] = array($search_data3->isbn,$search_data3->book,$search_data3->author,l('Download Certificate', 'certificate/generate_pdf/'.$search_data3->id));
- }
- if ($search_rows)
- {
- $search_header = array('ISBN', 'Book Name', 'Author', 'Download Certificates');
- $output = theme_table($search_header, $search_rows);
- return $output;
- }
- else
- {
- echo("Error");
- return '';
- }
- }
- else
- {
- $query3 = db_query("SELECT * FROM {textbook_companion_proposal} WHERE uid=".$user->uid);
- $data3 = db_fetch_object($query2);
- var_dump($query3);
- die;
- if($data3)
- {
- drupal_set_message('<strong>Your book is still under Review!</strong>', 'status');
- return '';
- }
- else
- {
- drupal_set_message('<strong>You need to propose a book <a href="/proposal">Book Proposal</a></strong>', 'status');
- return '';
- }
- }
-
-}
-?>
diff --git a/pdf/generate_pdf.inc b/pdf/generate_pdf.inc
index db76a88..f01c2e0 100755
--- a/pdf/generate_pdf.inc
+++ b/pdf/generate_pdf.inc
@@ -1,127 +1,388 @@
<?php
function generate_pdf()
- {
- require('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=". $proposal_id);
- $data2 = db_fetch_object($query2);*/
- $query = db_select('textbook_companion_preference');
- $query->fields('textbook_companion_preference');
- $query->condition('approval_status', 1);
- $query->condition('proposal_id', $proposal_id);
- $result = $query->execute();
- $data2 = $result->fetchObject();
- /*$query3 = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id=".$proposal_id);
- $data3 = db_fetch_object($query3);*/
- $query = db_select('textbook_companion_proposal');
- $query->fields('textbook_companion_proposal');
- $query->condition('id', $proposal_id);
- $result = $query->execute();
- $data3 = $result->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);
- $path = drupal_get_path('module', 'textbook_companion');
- $pdf->Image($path . "/pdf/images/dwsim_logo.png", 10, 9, 0, 15);
- $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 DWSIM, all the solved examples of the allotted textbook: '.$data2->book.' by '.$data2->author.'.', 0);
- }
- else
- {*/
- $pdf->MultiCell(240, 8, 'This is to certify that ' . $gender['salutation'] . " " . $data3->full_name . ' from ' . $data3->university . ' has successfully completed training under DWSIM Textbook Companion for a duration equivalent to six weeks. ' . $gender['gender'] . ' has coded, in DWSIM, 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://dwsim.fossee.in', 'http://dwsim.fossee.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. Kannan M Moudgalya', 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 Chemical 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: contact-dwsim@sfossee.in', 0, 1, 'L');
- $name = $data3->full_name;
- $certificate_name = str_replace(' ', '_', $name);
- $pdf->Output($certificate_name . '_DWSIM_TBC_Certificate.pdf', 'D');
- /*}
- else
- {
- drupal_set_message('Your Book Is Still Under Review.', 'status');
- }*/
- }
-?>
+{
+ $mpath = drupal_get_path('module', 'textbook_companion');
+ require($mpath . '/pdf/fpdf/fpdf.php');
+ require($mpath . '/pdf/phpqrcode/qrlib.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();
+ $query4 = db_query("SELECT COUNT( tce.id ) AS example_count FROM textbook_companion_example tce
+ LEFT JOIN textbook_companion_chapter tcc ON tce.chapter_id = tcc.id
+ LEFT JOIN textbook_companion_preference tcpe ON tcc.preference_id = tcpe.id
+ LEFT JOIN textbook_companion_proposal tcpo ON tcpe.proposal_id = tcpo.id
+ WHERE tcpo.proposal_status =3 AND tce.approval_status =1 AND tce.approval_status=1 AND tcpo.id = :prop_id", array(
+ ':prop_id' => $proposal_id
+ ));
+ $data4 = $query4->fetchObject();
+ $number_of_example = $data4->example_count;
+ $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 {
+ $gender = array(
+ 'salutation' => 'Ms.',
+ 'gender' => 'She'
+ );
+ }
+ } //$data3->gender
+ $pdf = new FPDF('L', 'mm', 'Letter');
+ if (!$pdf) {
+ echo "Error!";
+ } //!$pdf
+ $pdf->AddPage();
+ $image_bg = $mpath . "/pdf/images/bg.png";
+ $pdf->Image($image_bg, 0, 0, $pdf->w, $pdf->h);
+ //$pdf->Rect(5, 5, 267, 207, 'D');
+ $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);
+ $path = drupal_get_path('module', 'textbook_companion');
+ $image1 = $mpath . "/pdf/images/dwsim_logo.png";
+ $pdf->Ln(15);
+ //$pdf->Cell(200, 8, $pdf->Image($image1, 105, 15, 0, 28), 0, 1, 'C');
+ $pdf->Ln(20);
+ $pdf->SetFont('Arial', 'BI', 25);
+ $pdf->SetTextColor(139, 69, 19);
+ $pdf->Cell(240, 8, 'Certificate of Participation', '0', 1, 'C');
+ $pdf->Ln(4);
+ $pdf->SetFont('Arial', 'BI', 12);
+ $pdf->SetTextColor(0, 0, 0);
+ $pdf->Cell(240, 8, 'This is to certify that', '0', '1', 'C');
+ $pdf->Ln(4);
+ $pdf->SetFont('Arial', 'BI', 25);
+ $pdf->SetTextColor(139, 69, 19);
+ $pdf->Cell(240, 8, $data3->full_name, '0', '1', 'C');
+ $pdf->Ln(5);
+ $pdf->SetFont('Arial', 'I', 12);
+ if (strtolower($data3->branch) != "others") {
+ $pdf->SetTextColor(0, 0, 0);
+ $pdf->Cell(240, 8, 'from ' . $data3->university . ' has successfully', '0', '1', 'C');
+ $pdf->Ln(0);
+ $pdf->Cell(240, 8, 'completed Internship under DWSIM Textbook Companion', '0', '1', 'C');
+ $pdf->Ln(0);
+ $pdf->Cell(240, 8, 'He/she has coded ' . $number_of_example . ' solved examples using DWSIM from the', '0', '1', 'C');
+ $pdf->Ln(0);
+ $pdf->Cell(240, 8, 'Book: ' . $data2->book . ', Author: ' . $data2->author . '.', '0', '1', 'C');
+ $pdf->Ln(0);
+ } //strtolower($data3->branch) != "others"
+ else {
+ $pdf->SetTextColor(0, 0, 0);
+ $pdf->Cell(240, 8, 'from ' . $data3->university . ' has successfully', '0', '1', 'C');
+ $pdf->Ln(0);
+ $pdf->Cell(240, 8, 'completed Internship under DWSIM Textbook Companion', '0', '1', 'C');
+ $pdf->Ln(0);
+ $pdf->Cell(240, 8, 'He/she has coded ' . $number_of_example . ' solved examples using DWSIM from the', '0', '1', 'C');
+ $pdf->Ln(0);
+ $pdf->Cell(240, 8, 'Book: ' . $data2->book . ', Author: ' . $data2->author . '.', '0', '1', 'C');
+ $pdf->Ln(0);
+ }
+ $proposal_get_id = 0;
+ $UniqueString = "";
+ $tempDir = $path . "/pdf/temp_prcode/";
+ $query = db_select('textbook_companion_qr_code');
+ $query->fields('textbook_companion_qr_code', array(
+ 'qr_code',
+ 'proposal_id'
+ ));
+ $query->condition('proposal_id', $proposal_id);
+ $result = $query->execute();
+ $data = $result->fetchObject();
+ $DBString = $data->qr_code;
+ $proposal_get_id = $data->proposal_id;
+ if ($DBString == "" || $DBString == "null") {
+ $UniqueString = generateRandomString();
+ $query = "
+ INSERT INTO textbook_companion_qr_code
+ (proposal_id,qr_code)
+ VALUES
+ (:proposal_id,:qr_code)
+ ";
+ $args = array(
+ ":proposal_id" => $proposal_id,
+ ":qr_code" => $UniqueString
+ );
+ $result = db_query($query, $args, array(
+ 'return' => Database::RETURN_INSERT_ID
+ ));
+ } //$DBString == "" || $DBString == "null"
+ else {
+ $UniqueString = $DBString;
+ }
+ $codeContents = "http://dwsim.fossee.in/textbook-companion/certificates/verify/" . $UniqueString;
+ $fileName = 'generated_qrcode.png';
+ $pngAbsoluteFilePath = $tempDir . $fileName;
+ $urlRelativeFilePath = $path . "/pdf/temp_prcode/" . $fileName;
+ QRcode::png($codeContents, $pngAbsoluteFilePath);
+ $pdf->Cell(240, 4, '', '0', '1', 'C');
+ $pdf->SetX(95);
+ $pdf->write(0, 'The work done is available at ');
+ $pdf->SetFont('', 'U');
+ $pdf->SetTextColor(139, 69, 19);
+ $pdf->write(0, 'http://dwsim.fossee.in/', 'http://dwsim.fossee.in/');
+ $pdf->SetFont('', '');
+ $pdf->SetTextColor(0, 0, 0);
+ $pdf->write(0, '.', '.');
+ $pdf->Ln(5);
+ $pdf->SetX(198);
+ $pdf->SetFont('', '');
+ $pdf->SetTextColor(0, 0, 0);
+ $pdf->SetY(-85);
+ $pdf->SetX(200);
+ $pdf->SetTextColor(0, 0, 0);
+ $pdf->SetFont('', '');
+ //$sign = $path . "/pdf/images/sign.png";
+ //$pdf->Image($sign, $pdf->GetX(), $pdf->GetY() - 20, 50, 0);
+ $pdf->Cell(0, 8, 'Prof. Kannan M. Moudgalya', 0, 1, 'L');
+ $pdf->SetX(199);
+ $pdf->SetFont('Arial', '', 10);
+ $pdf->Cell(0, 7, 'Co - Principal Investigator - FOSSEE', 0, 1, 'L');
+ $pdf->SetX(190);
+ $pdf->Cell(0, 7, ' Dept. of Chemical Engineering, IIT Bombay.', 0, 1, 'L');
+ $pdf->SetX(29);
+ $pdf->SetFont('Arial', 'B', 10);
+ $pdf->SetY(-57);
+ $pdf->SetX(28);
+ $pdf->Cell(0, 2, $UniqueString, 0, 0, 'C');
+ $pdf->SetX(29);
+ $pdf->SetY(-50);
+ $image4 = $path . "/pdf/images/verify_content.png";
+ //$pdf->Image($image4, $pdf->GetX(), $pdf->GetY(), 20, 0);
+ $pdf->SetY(-50);
+ $pdf->SetX(80);
+ $image3 = $path . "/pdf/images/iitb.png";
+ $image2 = $path . "/pdf/images/fossee.png";
+ $pdf->Image($image2, $pdf->GetX() - 15, $pdf->GetY() + 7, 40, 0);
+ $pdf->Image($pngAbsoluteFilePath, $pdf->GetX() + 50, $pdf->GetY() - 5, 30, 0);
+ $pdf->Image($image3, $pdf->GetX() + 110, $pdf->GetY() + 3, 15, 0);
+ $pdf->Image($image4, $pdf->GetX() - 15, $pdf->GetY() + 28, 150, 0);
+ $pdf->SetFont('Arial', 'I', 8);
+ $pdf->SetTextColor(0, 0, 0);
+ $filename = str_replace(' ', '-', $data3->full_name) . '-DWSIM-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();
+ $fp = fopen($file, "r");
+ while (!feof($fp)) {
+ echo fread($fp, 65536);
+ flush();
+ } //!feof($fp)
+ fclose($fp);
+ unlink($file);
+ drupal_goto('certificate');
+ return;
+}
+function generateRandomString($length = 5)
+{
+ $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
+ $charactersLength = strlen($characters);
+ $randomString = '';
+ for ($i = 0; $i < $length; $i++) {
+ $randomString .= $characters[rand(0, $charactersLength - 1)];
+ } //$i = 0; $i < $length; $i++
+ return $randomString;
+}
+function generate_copyright_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();
+ $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 {
+ $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 DWSIM 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) . '-DWSIM-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();
+ $fp = fopen($file, "r");
+ while (!feof($fp)) {
+ echo fread($fp, 65536);
+ flush();
+ } //!feof($fp)
+ fclose($fp);
+ unlink($file);
+ drupal_goto('Summer_Internship_Forms/forms');
+ return;
+}
+function generate_undertaking_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();
+ $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 {
+ $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, 'Undertaking Form', 0, 1, 'C');
+ $pdf->Ln(0);
+ $pdf->SetFont('Arial', 'B', 10);
+ $pdf->Cell(200, 8, '(To be signed by college teacher)', 0, 1, 'C');
+ $pdf->Ln(20);
+ $pdf->SetFont('Arial', '', 12);
+ $pdf->MultiCell(200, 8, 'I hereby certify that all the codes written by ' . $gender['salutation'] . ' ' . $data3->full_name . ' under the DWSIM Textbook Companion Project for the book ' . $data2->book . ' ( Author: ' . $data2->author . ', Edition: ' . $data2->edition . ', Publisher: ' . $data2->publisher . ', Year: ' . $data2->year . ') are correctly reproducing the results given in the aforementioned book.', 0);
+ $pdf->Ln(10);
+ $pdf->MultiCell(200, 8, 'I understand that the DWSIM Textbook Companion created is a part of FOSSEE project, IIT Bombay, and is sponsored by the National Mission on Education through Information and Communication Technology (NMEICT), under MHRD, Govt. of India. The project requires that the textbook companion is made available for public access as an open source document. Hence I undertake that this DWSIM Textbook Companion can be made public along with the information that I have certified all the codes as giving the correct answer.');
+ $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(180);
+ $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(180);
+ $pdf->SetX(120);
+ $pdf->Cell(140, 0, 'Signature: _________________', 0, 1, 'L');
+ $pdf->SetX(120);
+ $pdf->multicell(140, 14, 'Name: ' . '____________________', 0, '');
+ $pdf->SetX(120);
+ $pdf->multicell(140, 14, 'Designation: ' . '______________', 0, '');
+ $filename = str_replace(' ', '-', $data3->full_name) . '-DWSIM-Textbook-Companion-undertaking-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();
+ $fp = fopen($file, "r");
+ while (!feof($fp)) {
+ echo fread($fp, 65536);
+ flush();
+ } //!feof($fp)
+ fclose($fp);
+ unlink($file);
+ drupal_goto('Summer_Internship_Forms/forms');
+ return;
+}
diff --git a/pdf/images/bg.png b/pdf/images/bg.png
new file mode 100755
index 0000000..478dc8e
--- /dev/null
+++ b/pdf/images/bg.png
Binary files differ
diff --git a/pdf/images/dwsim_logo.png b/pdf/images/dwsim_logo.png
deleted file mode 100755
index 48647f7..0000000
--- a/pdf/images/dwsim_logo.png
+++ /dev/null
Binary files differ
diff --git a/pdf/images/fossee.png b/pdf/images/fossee.png
index 9e255a4..478dc8e 100755
--- a/pdf/images/fossee.png
+++ b/pdf/images/fossee.png
Binary files differ
diff --git a/pdf/images/garland_logo.png b/pdf/images/garland_logo.png
deleted file mode 100755
index acdf54c..0000000
--- a/pdf/images/garland_logo.png
+++ /dev/null
Binary files differ
diff --git a/pdf/images/garland_logo2.png b/pdf/images/garland_logo2.png
deleted file mode 100755
index 0ea0ac3..0000000
--- a/pdf/images/garland_logo2.png
+++ /dev/null
Binary files differ
diff --git a/pdf/images/garland_logo4.png b/pdf/images/garland_logo4.png
deleted file mode 100755
index fdbc1b6..0000000
--- a/pdf/images/garland_logo4.png
+++ /dev/null
Binary files differ
diff --git a/pdf/images/iitb.png b/pdf/images/iitb.png
new file mode 100755
index 0000000..f115dd6
--- /dev/null
+++ b/pdf/images/iitb.png
Binary files differ
diff --git a/pdf/images/sign.png b/pdf/images/sign.png
deleted file mode 100755
index 974f493..0000000
--- a/pdf/images/sign.png
+++ /dev/null
Binary files differ
diff --git a/pdf/images/verify_content.png b/pdf/images/verify_content.png
new file mode 100644
index 0000000..8bd87b8
--- /dev/null
+++ b/pdf/images/verify_content.png
Binary files differ
diff --git a/pdf/list_all_certificates.inc b/pdf/list_all_certificates.inc
index 19dede5..43e47ab 100755
--- a/pdf/list_all_certificates.inc
+++ b/pdf/list_all_certificates.inc
@@ -1,119 +1,57 @@
<?php
-/* function _list_all_certificates()
-{
-global $user;
-$uid1 = $user->uid;
-
-$query2 = db_query("SELECT * FROM {textbook_companion_proposal} WHERE proposal_status=3 AND uid=".$user->uid);
-$data2 = db_fetch_object($query2);
-if($data2->id)
-/*while($data2 = db_fetch_object($query2))
-{*/
-/* if($data2->id)
-{
-$search_rows = array();
-global $output;
-$output = '';
-$query3 = db_query("SELECT * FROM textbook_companion_preference WHERE approval_status=1 AND proposal_id=".$data2->id);
-
-while ($search_data3 = db_fetch_object($query3))
-{
-$search_rows[] = array($search_data3->isbn,$search_data3->book,$search_data3->author,l('Download Certificate', 'certificate/generate_pdf/'.$search_data3->id));
-}
-if ($search_rows)
-{
-$search_header = array('ISBN', 'Book Name', 'Author', 'Download Certificates');
-$output = theme_table($search_header, $search_rows);
-return $output;
-}
-else
-{
-echo("Error");
-return '';
-}
-}
-else
-{
-$query3 = db_query("SELECT * FROM {textbook_companion_proposal} WHERE uid=".$user->uid);
-$data3 = db_fetch_object($query3);
-if($data3)
-{
-drupal_set_message('<strong>Your book is still under Review!</strong>', 'status');
-return '';
-}
-else
+function _list_all_certificates()
{
-drupal_set_message('<strong>You need to propose a book <a href="/proposal">Book Proposal</a></strong>', 'status');
-return '';
-}
+ 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){
+ if ($exist_id->id) {
+ if ($exist_id->id < 3) {
+ drupal_set_message('<strong>You need to propose a book <a href="http://dwsim.fossee.in/textbook-companion/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 Certificate', 'textbook-companion/certificates/generate-pdf/' . $search_data3->id)
+ );
+ } //$search_data3->id
+ } //$search_data3 = $query3->fetchObject()
+ if ($search_rows) {
+ $search_header = array(
+ 'ISBN',
+ 'Book Name',
+ 'Author',
+ 'Download Certificates'
+ );
+ $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://dwsim.fossee.in/textbook-companion/proposal">Book Proposal</a></strong> or if you have already proposed then your book is under reviewing process', 'status');
+ $page_content = "<span style='color:red;'>No book has been completed by you</span>";
+ return $page_content;
+ }
}
-//}
-} */
-function _list_all_certificates()
- {
- global $user;
- /*$query_id =db_query("SELECT id FROM textbook_companion_proposal WHERE proposal_status=3 AND uid=".$user->uid);
- $exist_id = db_fetch_object($query_id);*/
- $query = db_select('textbook_companion_proposal');
- $query->fields('textbook_companion_proposal', array(
- 'id'
- ));
- $query->condition('proposal_status', 3);
- $query->condition('uid', $user->uid);
- $result = $query->execute();
- $exist_id = $result->fetchObject();
- if ($exist_id->id)
- {
- if ($exist_id->id < 3)
- {
- drupal_set_message('<strong>You need to propose a book <a href="/proposal">Book Proposal</a></strong>', 'status');
- return '';
- }
- 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', 'textbook-companion/certificate/generate-pdf/' . $search_data3->id)
- );
- }
- }
- 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 '';
- }
- }
- }
- else
- {
- drupal_set_message('<strong>You need to propose a book <a href="/proposal">Book Proposal</a></strong>', 'status');
- return '';
- }
- }
-?>
diff --git a/pdf/list_all_form_pdf.inc b/pdf/list_all_form_pdf.inc
new file mode 100755
index 0000000..e05924f
--- /dev/null
+++ b/pdf/list_all_form_pdf.inc
@@ -0,0 +1,67 @@
+<?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 <a href="http://dwsim.fossee.in/textbook-companion/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),
+ l('Download Undertaking Form', 'Summer_Internship_Forms/undertaking-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',
+ 'Download Undertaking 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://dwsim.fossee.in/textbook-companion/proposal">Book Proposal</a></strong> or if you have already proposed then your book is under reviewing process', 'status');
+ return '';
+ }
+}
+
+
diff --git a/pdf/phpqrcode/CHANGELOG b/pdf/phpqrcode/CHANGELOG
new file mode 100755
index 0000000..1088530
--- /dev/null
+++ b/pdf/phpqrcode/CHANGELOG
@@ -0,0 +1,38 @@
+* 1.0.0 build 2010031920
+
+ - first public release
+ - help in readme, install
+ - cleanup ans separation of QRtools and QRspec
+ - now TCPDF binding requires minimal changes in TCPDF, having most of job
+ done in QRtools tcpdfBarcodeArray
+ - nicer QRtools::timeBenchmark output
+ - license and copyright notices in files
+ - indent cleanup - from tab to 4spc, keep it that way please :)
+ - sf project, repository, wiki
+ - simple code generator in index.php
+
+* 1.1.0 build 2010032113
+
+ - added merge tool wich generate merged version of code
+ located in phpqrcode.php
+ - splited qrconst.php from qrlib.php
+
+* 1.1.1 build 2010032405
+
+ - patch by Rick Seymour allowing saving PNG and displaying it at the same time
+ - added version info in VERSION file
+ - modified merge tool to include version info into generated file
+ - fixed e-mail in almost all head comments
+
+* 1.1.2 build 2010032722
+
+ - full integration with TCPDF thanks to Nicola Asuni, it's author
+ - fixed bug with alphanumeric encoding detection
+
+* 1.1.3 build 2010081807
+
+ - short opening tags replaced with standard ones
+
+* 1.1.4 build 2010100721
+
+ - added missing static keyword QRinput::check (found by Luke Brookhart, Onjax LLC)
diff --git a/pdf/phpqrcode/INSTALL b/pdf/phpqrcode/INSTALL
new file mode 100755
index 0000000..eac6b07
--- /dev/null
+++ b/pdf/phpqrcode/INSTALL
@@ -0,0 +1,67 @@
+== REQUIREMENTS ==
+
+ * PHP5
+ * PHP GD2 extension with JPEG and PNG support
+
+== INSTALLATION ==
+
+If you want to recreate cache by yourself make sure cache directory is
+writable and you have permisions to write into it. Also make sure you are
+able to read files in it if you have cache option enabled
+
+== CONFIGURATION ==
+
+Feel free to modify config constants in qrconfig.php file. Read about it in
+provided comments and project wiki page (links in README file)
+
+== QUICK START ==
+
+Notice: probably you should'nt use all of this in same script :)
+
+<?phpb
+
+//include only that one, rest required files will be included from it
+include "qrlib.php"
+
+//write code into file, Error corection lecer is lowest, L (one form: L,M,Q,H)
+//each code square will be 4x4 pixels (4x zoom)
+//code will have 2 code squares white boundary around
+
+QRcode::png('PHP QR Code :)', 'test.png', 'L', 4, 2);
+
+//same as above but outputs file directly into browser (with appr. header etc.)
+//all other settings are default
+//WARNING! it should be FIRST and ONLY output generated by script, otherwise
+//rest of output will land inside PNG binary, breaking it for sure
+QRcode::png('PHP QR Code :)');
+
+//show benchmark
+QRtools::timeBenchmark();
+
+//rebuild cache
+QRtools::buildCache();
+
+//code generated in text mode - as a binary table
+//then displayed out as HTML using Unicode block building chars :)
+$tab = $qr->encode('PHP QR Code :)');
+QRspec::debug($tab, true);
+
+== TCPDF INTEGRATION ==
+
+Inside bindings/tcpdf you will find slightly modified 2dbarcodes.php.
+Instal phpqrcode liblaty inside tcpdf folder, then overwrite (or merge)
+2dbarcodes.php
+
+Then use similar as example #50 from TCPDF examples:
+
+<?php
+
+$style = array(
+ 'border' => true,
+ 'padding' => 4,
+ 'fgcolor' => array(0,0,0),
+ 'bgcolor' => false, //array(255,255,255)
+);
+
+//code name: QR, specify error correction level after semicolon (L,M,Q,H)
+$pdf->write2DBarcode('PHP QR Code :)', 'QR,L', '', '', 30, 30, $style, 'N');
diff --git a/pdf/phpqrcode/LICENSE b/pdf/phpqrcode/LICENSE
new file mode 100755
index 0000000..1883303
--- /dev/null
+++ b/pdf/phpqrcode/LICENSE
@@ -0,0 +1,165 @@
+ GNU LESSER GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+
+ This version of the GNU Lesser General Public License incorporates
+the terms and conditions of version 3 of the GNU General Public
+License, supplemented by the additional permissions listed below.
+
+ 0. Additional Definitions.
+
+ As used herein, "this License" refers to version 3 of the GNU Lesser
+General Public License, and the "GNU GPL" refers to version 3 of the GNU
+General Public License.
+
+ "The Library" refers to a covered work governed by this License,
+other than an Application or a Combined Work as defined below.
+
+ An "Application" is any work that makes use of an interface provided
+by the Library, but which is not otherwise based on the Library.
+Defining a subclass of a class defined by the Library is deemed a mode
+of using an interface provided by the Library.
+
+ A "Combined Work" is a work produced by combining or linking an
+Application with the Library. The particular version of the Library
+with which the Combined Work was made is also called the "Linked
+Version".
+
+ The "Minimal Corresponding Source" for a Combined Work means the
+Corresponding Source for the Combined Work, excluding any source code
+for portions of the Combined Work that, considered in isolation, are
+based on the Application, and not on the Linked Version.
+
+ The "Corresponding Application Code" for a Combined Work means the
+object code and/or source code for the Application, including any data
+and utility programs needed for reproducing the Combined Work from the
+Application, but excluding the System Libraries of the Combined Work.
+
+ 1. Exception to Section 3 of the GNU GPL.
+
+ You may convey a covered work under sections 3 and 4 of this License
+without being bound by section 3 of the GNU GPL.
+
+ 2. Conveying Modified Versions.
+
+ If you modify a copy of the Library, and, in your modifications, a
+facility refers to a function or data to be supplied by an Application
+that uses the facility (other than as an argument passed when the
+facility is invoked), then you may convey a copy of the modified
+version:
+
+ a) under this License, provided that you make a good faith effort to
+ ensure that, in the event an Application does not supply the
+ function or data, the facility still operates, and performs
+ whatever part of its purpose remains meaningful, or
+
+ b) under the GNU GPL, with none of the additional permissions of
+ this License applicable to that copy.
+
+ 3. Object Code Incorporating Material from Library Header Files.
+
+ The object code form of an Application may incorporate material from
+a header file that is part of the Library. You may convey such object
+code under terms of your choice, provided that, if the incorporated
+material is not limited to numerical parameters, data structure
+layouts and accessors, or small macros, inline functions and templates
+(ten or fewer lines in length), you do both of the following:
+
+ a) Give prominent notice with each copy of the object code that the
+ Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the object code with a copy of the GNU GPL and this license
+ document.
+
+ 4. Combined Works.
+
+ You may convey a Combined Work under terms of your choice that,
+taken together, effectively do not restrict modification of the
+portions of the Library contained in the Combined Work and reverse
+engineering for debugging such modifications, if you also do each of
+the following:
+
+ a) Give prominent notice with each copy of the Combined Work that
+ the Library is used in it and that the Library and its use are
+ covered by this License.
+
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
+ document.
+
+ c) For a Combined Work that displays copyright notices during
+ execution, include the copyright notice for the Library among
+ these notices, as well as a reference directing the user to the
+ copies of the GNU GPL and this license document.
+
+ d) Do one of the following:
+
+ 0) Convey the Minimal Corresponding Source under the terms of this
+ License, and the Corresponding Application Code in a form
+ suitable for, and under terms that permit, the user to
+ recombine or relink the Application with a modified version of
+ the Linked Version to produce a modified Combined Work, in the
+ manner specified by section 6 of the GNU GPL for conveying
+ Corresponding Source.
+
+ 1) Use a suitable shared library mechanism for linking with the
+ Library. A suitable mechanism is one that (a) uses at run time
+ a copy of the Library already present on the user's computer
+ system, and (b) will operate properly with a modified version
+ of the Library that is interface-compatible with the Linked
+ Version.
+
+ e) Provide Installation Information, but only if you would otherwise
+ be required to provide such information under section 6 of the
+ GNU GPL, and only to the extent that such information is
+ necessary to install and execute a modified version of the
+ Combined Work produced by recombining or relinking the
+ Application with a modified version of the Linked Version. (If
+ you use option 4d0, the Installation Information must accompany
+ the Minimal Corresponding Source and Corresponding Application
+ Code. If you use option 4d1, you must provide the Installation
+ Information in the manner specified by section 6 of the GNU GPL
+ for conveying Corresponding Source.)
+
+ 5. Combined Libraries.
+
+ You may place library facilities that are a work based on the
+Library side by side in a single library together with other library
+facilities that are not Applications and are not covered by this
+License, and convey such a combined library under terms of your
+choice, if you do both of the following:
+
+ a) Accompany the combined library with a copy of the same work based
+ on the Library, uncombined with any other library facilities,
+ conveyed under the terms of this License.
+
+ b) Give prominent notice with the combined library that part of it
+ is a work based on the Library, and explaining where to find the
+ accompanying uncombined form of the same work.
+
+ 6. Revised Versions of the GNU Lesser General Public License.
+
+ The Free Software Foundation may publish revised and/or new versions
+of the GNU Lesser General Public License from time to time. Such new
+versions will be similar in spirit to the present version, but may
+differ in detail to address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Library as you received it specifies that a certain numbered version
+of the GNU Lesser General Public License "or any later version"
+applies to it, you have the option of following the terms and
+conditions either of that published version or of any later version
+published by the Free Software Foundation. If the Library as you
+received it does not specify a version number of the GNU Lesser
+General Public License, you may choose any version of the GNU Lesser
+General Public License ever published by the Free Software Foundation.
+
+ If the Library as you received it specifies that a proxy can decide
+whether future versions of the GNU Lesser General Public License shall
+apply, that proxy's public statement of acceptance of any version is
+permanent authorization for you to choose that version for the
+Library.
diff --git a/pdf/phpqrcode/README b/pdf/phpqrcode/README
new file mode 100755
index 0000000..a022fb5
--- /dev/null
+++ b/pdf/phpqrcode/README
@@ -0,0 +1,45 @@
+This is PHP implementation of QR Code 2-D barcode generator. It is pure-php
+LGPL-licensed implementation based on C libqrencode by Kentaro Fukuchi.
+
+== LICENSING ==
+
+Copyright (C) 2010 by Dominik Dzienia
+
+This library is free software; you can redistribute it and/or modify it under
+the terms of the GNU Lesser General Public License as published by the Free
+Software Foundation; either version 3 of the License, or any later version.
+
+This library is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+PARTICULAR PURPOSE. See the GNU Lesser General Public License (LICENSE file)
+for more details.
+
+You should have received a copy of the GNU Lesser General Public License along
+with this library; if not, write to the Free Software Foundation, Inc., 51
+Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+== INSTALATION AND USAGE ==
+
+ * INSTALL file
+ * http://sourceforge.net/apps/mediawiki/phpqrcode/index.php?title=Main_Page
+
+== CONTACT ==
+
+Fell free to contact me via e-mail (deltalab at poczta dot fm) or using
+folowing project pages:
+
+ * http://sourceforge.net/projects/phpqrcode/
+ * http://phpqrcode.sourceforge.net/
+
+== ACKNOWLEDGMENTS ==
+
+Based on C libqrencode library (ver. 3.1.1)
+Copyright (C) 2006-2010 by Kentaro Fukuchi
+http://megaui.net/fukuchi/works/qrencode/index.en.html
+
+QR Code is registered trademarks of DENSO WAVE INCORPORATED in JAPAN and other
+countries.
+
+Reed-Solomon code encoder is written by Phil Karn, KA9Q.
+Copyright (C) 2002, 2003, 2004, 2006 Phil Karn, KA9Q
+ \ No newline at end of file
diff --git a/pdf/phpqrcode/VERSION b/pdf/phpqrcode/VERSION
new file mode 100755
index 0000000..9f99279
--- /dev/null
+++ b/pdf/phpqrcode/VERSION
@@ -0,0 +1,2 @@
+1.1.4
+2010100721 \ No newline at end of file
diff --git a/pdf/phpqrcode/bindings/tcpdf/qrcode.php b/pdf/phpqrcode/bindings/tcpdf/qrcode.php
new file mode 100755
index 0000000..7995460
--- /dev/null
+++ b/pdf/phpqrcode/bindings/tcpdf/qrcode.php
@@ -0,0 +1,2875 @@
+<?php
+//============================================================+
+// File name : qrcode.php
+// Begin : 2010-03-22
+// Last Update : 2010-03-29
+// Version : 1.0.002
+// License : GNU LGPL v.3 (http://www.gnu.org/copyleft/lesser.html)
+// ----------------------------------------------------------------------------
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 3 of the License, or any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+// or browse http://www.gnu.org/copyleft/lesser.html
+//
+// ----------------------------------------------------------------------------
+//
+// DESCRIPTION :
+//
+// Class to create QR-code arrays for TCPDF class.
+// QR Code symbol is a 2D barcode that can be scanned by
+// handy terminals such as a mobile phone with CCD.
+// The capacity of QR Code is up to 7000 digits or 4000
+// characters, and has high robustness.
+// This class supports QR Code model 2, described in
+// JIS (Japanese Industrial Standards) X0510:2004
+// or ISO/IEC 18004.
+// Currently the following features are not supported:
+// ECI and FNC1 mode, Micro QR Code, QR Code model 1,
+// Structured mode.
+//
+// This class is derived from the following projects:
+// ---------------------------------------------------------
+// "PHP QR Code encoder"
+// License: GNU-LGPLv3
+// Copyright (C) 2010 by Dominik Dzienia <deltalab at poczta dot fm>
+// http://phpqrcode.sourceforge.net/
+// https://sourceforge.net/projects/phpqrcode/
+//
+// The "PHP QR Code encoder" is based on
+// "C libqrencode library" (ver. 3.1.1)
+// License: GNU-LGPL 2.1
+// Copyright (C) 2006-2010 by Kentaro Fukuchi
+// http://megaui.net/fukuchi/works/qrencode/index.en.html
+//
+// Reed-Solomon code encoder is written by Phil Karn, KA9Q.
+// Copyright (C) 2002-2006 Phil Karn, KA9Q
+//
+// QR Code is registered trademark of DENSO WAVE INCORPORATED
+// http://www.denso-wave.com/qrcode/index-e.html
+// ---------------------------------------------------------
+//
+// Author: Nicola Asuni
+//
+// (c) Copyright 2010:
+// Nicola Asuni
+// Tecnick.com S.r.l.
+// Via della Pace, 11
+// 09044 Quartucciu (CA)
+// ITALY
+// www.tecnick.com
+// info@tecnick.com
+//============================================================+
+
+/**
+ * Class to create QR-code arrays for TCPDF class.
+ * QR Code symbol is a 2D barcode that can be scanned by handy terminals such as a mobile phone with CCD.
+ * The capacity of QR Code is up to 7000 digits or 4000 characters, and has high robustness.
+ * This class supports QR Code model 2, described in JIS (Japanese Industrial Standards) X0510:2004 or ISO/IEC 18004.
+ * Currently the following features are not supported: ECI and FNC1 mode, Micro QR Code, QR Code model 1, Structured mode.
+ *
+ * This class is derived from "PHP QR Code encoder" by Dominik Dzienia (http://phpqrcode.sourceforge.net/) based on "libqrencode C library 3.1.1." by Kentaro Fukuchi (http://megaui.net/fukuchi/works/qrencode/index.en.html), contains Reed-Solomon code written by Phil Karn, KA9Q. QR Code is registered trademark of DENSO WAVE INCORPORATED (http://www.denso-wave.com/qrcode/index-e.html).
+ * Please read comments on this class source file for full copyright and license information.
+ *
+ * @package com.tecnick.tcpdf
+ * @abstract Class for generating QR-code array for TCPDF.
+ * @author Nicola Asuni
+ * @copyright 2010 Nicola Asuni - Tecnick.com S.r.l (www.tecnick.com) Via Della Pace, 11 - 09044 - Quartucciu (CA) - ITALY - www.tecnick.com - info@tecnick.com
+ * @link http://www.tcpdf.org
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL
+ * @version 1.0.002
+ */
+
+// definitions
+if (!defined('QRCODEDEFS')) {
+
+ /**
+ * Indicate that definitions for this class are set
+ */
+ define('QRCODEDEFS', true);
+
+ // -----------------------------------------------------
+
+ // Encoding modes (characters which can be encoded in QRcode)
+
+ /**
+ * Encoding mode
+ */
+ define('QR_MODE_NL', -1);
+
+ /**
+ * Encoding mode numeric (0-9). 3 characters are encoded to 10bit length. In theory, 7089 characters or less can be stored in a QRcode.
+ */
+ define('QR_MODE_NM', 0);
+
+ /**
+ * Encoding mode alphanumeric (0-9A-Z $%*+-./:) 45characters. 2 characters are encoded to 11bit length. In theory, 4296 characters or less can be stored in a QRcode.
+ */
+ define('QR_MODE_AN', 1);
+
+ /**
+ * Encoding mode 8bit byte data. In theory, 2953 characters or less can be stored in a QRcode.
+ */
+ define('QR_MODE_8B', 2);
+
+ /**
+ * Encoding mode KANJI. A KANJI character (multibyte character) is encoded to 13bit length. In theory, 1817 characters or less can be stored in a QRcode.
+ */
+ define('QR_MODE_KJ', 3);
+
+ /**
+ * Encoding mode STRUCTURED (currently unsupported)
+ */
+ define('QR_MODE_ST', 4);
+
+ // -----------------------------------------------------
+
+ // Levels of error correction.
+ // QRcode has a function of an error correcting for miss reading that white is black.
+ // Error correcting is defined in 4 level as below.
+
+ /**
+ * Error correction level L : About 7% or less errors can be corrected.
+ */
+ define('QR_ECLEVEL_L', 0);
+
+ /**
+ * Error correction level M : About 15% or less errors can be corrected.
+ */
+ define('QR_ECLEVEL_M', 1);
+
+ /**
+ * Error correction level Q : About 25% or less errors can be corrected.
+ */
+ define('QR_ECLEVEL_Q', 2);
+
+ /**
+ * Error correction level H : About 30% or less errors can be corrected.
+ */
+ define('QR_ECLEVEL_H', 3);
+
+ // -----------------------------------------------------
+
+ // Version. Size of QRcode is defined as version.
+ // Version is from 1 to 40.
+ // Version 1 is 21*21 matrix. And 4 modules increases whenever 1 version increases.
+ // So version 40 is 177*177 matrix.
+
+ /**
+ * Maximum QR Code version.
+ */
+ define('QRSPEC_VERSION_MAX', 40);
+
+ /**
+ * Maximum matrix size for maximum version (version 40 is 177*177 matrix).
+ */
+ define('QRSPEC_WIDTH_MAX', 177);
+
+ // -----------------------------------------------------
+
+ /**
+ * Matrix index to get width from $capacity array.
+ */
+ define('QRCAP_WIDTH', 0);
+
+ /**
+ * Matrix index to get number of words from $capacity array.
+ */
+ define('QRCAP_WORDS', 1);
+
+ /**
+ * Matrix index to get remainder from $capacity array.
+ */
+ define('QRCAP_REMINDER', 2);
+
+ /**
+ * Matrix index to get error correction level from $capacity array.
+ */
+ define('QRCAP_EC', 3);
+
+ // -----------------------------------------------------
+
+ // Structure (currently usupported)
+
+ /**
+ * Number of header bits for structured mode
+ */
+ define('STRUCTURE_HEADER_BITS', 20);
+
+ /**
+ * Max number of symbols for structured mode
+ */
+ define('MAX_STRUCTURED_SYMBOLS', 16);
+
+ // -----------------------------------------------------
+
+ // Masks
+
+ /**
+ * Down point base value for case 1 mask pattern (concatenation of same color in a line or a column)
+ */
+ define('N1', 3);
+
+ /**
+ * Down point base value for case 2 mask pattern (module block of same color)
+ */
+ define('N2', 3);
+
+ /**
+ * Down point base value for case 3 mask pattern (1:1:3:1:1(dark:bright:dark:bright:dark)pattern in a line or a column)
+ */
+ define('N3', 40);
+
+ /**
+ * Down point base value for case 4 mask pattern (ration of dark modules in whole)
+ */
+ define('N4', 10);
+
+ // -----------------------------------------------------
+
+ // Optimization settings
+
+ /**
+ * if true, estimates best mask (spec. default, but extremally slow; set to false to significant performance boost but (propably) worst quality code
+ */
+ define('QR_FIND_BEST_MASK', true);
+
+ /**
+ * if false, checks all masks available, otherwise value tells count of masks need to be checked, mask id are got randomly
+ */
+ define('QR_FIND_FROM_RANDOM', 2);
+
+ /**
+ * when QR_FIND_BEST_MASK === false
+ */
+ define('QR_DEFAULT_MASK', 2);
+
+ // -----------------------------------------------------
+
+} // end of definitions
+
+// #*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#
+
+if (!class_exists('QRcode', false)) {
+
+ // for compaibility with PHP4
+ if (!function_exists('str_split')) {
+ /**
+ * Convert a string to an array (needed for PHP4 compatibility)
+ * @param string $string The input string.
+ * @param int $split_length Maximum length of the chunk.
+ * @return If the optional split_length parameter is specified, the returned array will be broken down into chunks with each being split_length in length, otherwise each chunk will be one character in length. FALSE is returned if split_length is less than 1. If the split_length length exceeds the length of string , the entire string is returned as the first (and only) array element.
+ */
+ function str_split($string, $split_length=1) {
+ if ((strlen($string) > $split_length) OR (!$split_length)) {
+ do {
+ $c = strlen($string);
+ $parts[] = substr($string, 0, $split_length);
+ $string = substr($string, $split_length);
+ } while ($string !== false);
+ } else {
+ $parts = array($string);
+ }
+ return $parts;
+ }
+ }
+
+ // #####################################################
+
+ /**
+ * Class to create QR-code arrays for TCPDF class.
+ * QR Code symbol is a 2D barcode that can be scanned by handy terminals such as a mobile phone with CCD.
+ * The capacity of QR Code is up to 7000 digits or 4000 characters, and has high robustness.
+ * This class supports QR Code model 2, described in JIS (Japanese Industrial Standards) X0510:2004 or ISO/IEC 18004.
+ * Currently the following features are not supported: ECI and FNC1 mode, Micro QR Code, QR Code model 1, Structured mode.
+ *
+ * This class is derived from "PHP QR Code encoder" by Dominik Dzienia (http://phpqrcode.sourceforge.net/) based on "libqrencode C library 3.1.1." by Kentaro Fukuchi (http://megaui.net/fukuchi/works/qrencode/index.en.html), contains Reed-Solomon code written by Phil Karn, KA9Q. QR Code is registered trademark of DENSO WAVE INCORPORATED (http://www.denso-wave.com/qrcode/index-e.html).
+ * Please read comments on this class source file for full copyright and license information.
+ *
+ * @name QRcode
+ * @package com.tecnick.tcpdf
+ * @abstract Class for generating QR-code array for TCPDF.
+ * @author Nicola Asuni
+ * @copyright 2010 Nicola Asuni - Tecnick.com S.r.l (www.tecnick.com) Via Della Pace, 11 - 09044 - Quartucciu (CA) - ITALY - www.tecnick.com - info@tecnick.com
+ * @link http://www.tcpdf.org
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL
+ * @version 1.0.002
+ */
+ class QRcode {
+
+ /**
+ * @var barcode array to be returned which is readable by TCPDF
+ * @access protected
+ */
+ protected $barcode_array = array();
+
+ /**
+ * @var QR code version. Size of QRcode is defined as version. Version is from 1 to 40. Version 1 is 21*21 matrix. And 4 modules increases whenever 1 version increases. So version 40 is 177*177 matrix.
+ * @access protected
+ */
+ protected $version = 0;
+
+ /**
+ * @var Levels of error correction. See definitions for possible values.
+ * @access protected
+ */
+ protected $level = QR_ECLEVEL_L;
+
+ /**
+ * @var Encoding mode
+ * @access protected
+ */
+ protected $hint = QR_MODE_8B;
+
+ /**
+ * @var if true the input string will be converted to uppercase
+ * @access protected
+ */
+ protected $casesensitive = true;
+
+ /**
+ * @var structured QR code (not supported yet)
+ * @access protected
+ */
+ protected $structured = 0;
+
+ /**
+ * @var mask data
+ * @access protected
+ */
+ protected $data;
+
+ // FrameFiller
+
+ /**
+ * @var width
+ * @access protected
+ */
+ protected $width;
+
+ /**
+ * @var frame
+ * @access protected
+ */
+ protected $frame;
+
+ /**
+ * @var X position of bit
+ * @access protected
+ */
+ protected $x;
+
+ /**
+ * @var Y position of bit
+ * @access protected
+ */
+ protected $y;
+
+ /**
+ * @var direction
+ * @access protected
+ */
+ protected $dir;
+
+ /**
+ * @var single bit
+ * @access protected
+ */
+ protected $bit;
+
+ // ---- QRrawcode ----
+
+ /**
+ * @var data code
+ * @access protected
+ */
+ protected $datacode = array();
+
+ /**
+ * @var error correction code
+ * @access protected
+ */
+ protected $ecccode = array();
+
+ /**
+ * @var blocks
+ * @access protected
+ */
+ protected $blocks;
+
+ /**
+ * @var Reed-Solomon blocks
+ * @access protected
+ */
+ protected $rsblocks = array(); //of RSblock
+
+ /**
+ * @var counter
+ * @access protected
+ */
+ protected $count;
+
+ /**
+ * @var data length
+ * @access protected
+ */
+ protected $dataLength;
+
+ /**
+ * @var error correction length
+ * @access protected
+ */
+ protected $eccLength;
+
+ /**
+ * @var b1
+ * @access protected
+ */
+ protected $b1;
+
+ // ---- QRmask ----
+
+ /**
+ * @var run length
+ * @access protected
+ */
+ protected $runLength = array();
+
+ // ---- QRsplit ----
+
+ /**
+ * @var input data string
+ * @access protected
+ */
+ protected $dataStr = '';
+
+ /**
+ * @var input items
+ * @access protected
+ */
+ protected $items;
+
+ // Reed-Solomon items
+
+ /**
+ * @var Reed-Solomon items
+ * @access protected
+ */
+ protected $rsitems = array();
+
+ /**
+ * @var array of frames
+ * @access protected
+ */
+ protected $frames = array();
+
+ /**
+ * @var alphabet-numeric convesion table
+ * @access protected
+ */
+ protected $anTable = array(
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, //
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, //
+ 36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43, //
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1, //
+ -1, 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, -1, -1, -1, -1, -1, //
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, //
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 //
+ );
+
+ /**
+ * @var array Table of the capacity of symbols
+ * See Table 1 (pp.13) and Table 12-16 (pp.30-36), JIS X0510:2004.
+ * @access protected
+ */
+ protected $capacity = array(
+ array( 0, 0, 0, array( 0, 0, 0, 0)), //
+ array( 21, 26, 0, array( 7, 10, 13, 17)), // 1
+ array( 25, 44, 7, array( 10, 16, 22, 28)), //
+ array( 29, 70, 7, array( 15, 26, 36, 44)), //
+ array( 33, 100, 7, array( 20, 36, 52, 64)), //
+ array( 37, 134, 7, array( 26, 48, 72, 88)), // 5
+ array( 41, 172, 7, array( 36, 64, 96, 112)), //
+ array( 45, 196, 0, array( 40, 72, 108, 130)), //
+ array( 49, 242, 0, array( 48, 88, 132, 156)), //
+ array( 53, 292, 0, array( 60, 110, 160, 192)), //
+ array( 57, 346, 0, array( 72, 130, 192, 224)), // 10
+ array( 61, 404, 0, array( 80, 150, 224, 264)), //
+ array( 65, 466, 0, array( 96, 176, 260, 308)), //
+ array( 69, 532, 0, array( 104, 198, 288, 352)), //
+ array( 73, 581, 3, array( 120, 216, 320, 384)), //
+ array( 77, 655, 3, array( 132, 240, 360, 432)), // 15
+ array( 81, 733, 3, array( 144, 280, 408, 480)), //
+ array( 85, 815, 3, array( 168, 308, 448, 532)), //
+ array( 89, 901, 3, array( 180, 338, 504, 588)), //
+ array( 93, 991, 3, array( 196, 364, 546, 650)), //
+ array( 97, 1085, 3, array( 224, 416, 600, 700)), // 20
+ array(101, 1156, 4, array( 224, 442, 644, 750)), //
+ array(105, 1258, 4, array( 252, 476, 690, 816)), //
+ array(109, 1364, 4, array( 270, 504, 750, 900)), //
+ array(113, 1474, 4, array( 300, 560, 810, 960)), //
+ array(117, 1588, 4, array( 312, 588, 870, 1050)), // 25
+ array(121, 1706, 4, array( 336, 644, 952, 1110)), //
+ array(125, 1828, 4, array( 360, 700, 1020, 1200)), //
+ array(129, 1921, 3, array( 390, 728, 1050, 1260)), //
+ array(133, 2051, 3, array( 420, 784, 1140, 1350)), //
+ array(137, 2185, 3, array( 450, 812, 1200, 1440)), // 30
+ array(141, 2323, 3, array( 480, 868, 1290, 1530)), //
+ array(145, 2465, 3, array( 510, 924, 1350, 1620)), //
+ array(149, 2611, 3, array( 540, 980, 1440, 1710)), //
+ array(153, 2761, 3, array( 570, 1036, 1530, 1800)), //
+ array(157, 2876, 0, array( 570, 1064, 1590, 1890)), // 35
+ array(161, 3034, 0, array( 600, 1120, 1680, 1980)), //
+ array(165, 3196, 0, array( 630, 1204, 1770, 2100)), //
+ array(169, 3362, 0, array( 660, 1260, 1860, 2220)), //
+ array(173, 3532, 0, array( 720, 1316, 1950, 2310)), //
+ array(177, 3706, 0, array( 750, 1372, 2040, 2430)) // 40
+ );
+
+ /**
+ * @var array Length indicator
+ * @access protected
+ */
+ protected $lengthTableBits = array(
+ array(10, 12, 14),
+ array( 9, 11, 13),
+ array( 8, 16, 16),
+ array( 8, 10, 12)
+ );
+
+ /**
+ * @var array Table of the error correction code (Reed-Solomon block)
+ * See Table 12-16 (pp.30-36), JIS X0510:2004.
+ * @access protected
+ */
+ protected $eccTable = array(
+ array(array( 0, 0), array( 0, 0), array( 0, 0), array( 0, 0)), //
+ array(array( 1, 0), array( 1, 0), array( 1, 0), array( 1, 0)), // 1
+ array(array( 1, 0), array( 1, 0), array( 1, 0), array( 1, 0)), //
+ array(array( 1, 0), array( 1, 0), array( 2, 0), array( 2, 0)), //
+ array(array( 1, 0), array( 2, 0), array( 2, 0), array( 4, 0)), //
+ array(array( 1, 0), array( 2, 0), array( 2, 2), array( 2, 2)), // 5
+ array(array( 2, 0), array( 4, 0), array( 4, 0), array( 4, 0)), //
+ array(array( 2, 0), array( 4, 0), array( 2, 4), array( 4, 1)), //
+ array(array( 2, 0), array( 2, 2), array( 4, 2), array( 4, 2)), //
+ array(array( 2, 0), array( 3, 2), array( 4, 4), array( 4, 4)), //
+ array(array( 2, 2), array( 4, 1), array( 6, 2), array( 6, 2)), // 10
+ array(array( 4, 0), array( 1, 4), array( 4, 4), array( 3, 8)), //
+ array(array( 2, 2), array( 6, 2), array( 4, 6), array( 7, 4)), //
+ array(array( 4, 0), array( 8, 1), array( 8, 4), array(12, 4)), //
+ array(array( 3, 1), array( 4, 5), array(11, 5), array(11, 5)), //
+ array(array( 5, 1), array( 5, 5), array( 5, 7), array(11, 7)), // 15
+ array(array( 5, 1), array( 7, 3), array(15, 2), array( 3, 13)), //
+ array(array( 1, 5), array(10, 1), array( 1, 15), array( 2, 17)), //
+ array(array( 5, 1), array( 9, 4), array(17, 1), array( 2, 19)), //
+ array(array( 3, 4), array( 3, 11), array(17, 4), array( 9, 16)), //
+ array(array( 3, 5), array( 3, 13), array(15, 5), array(15, 10)), // 20
+ array(array( 4, 4), array(17, 0), array(17, 6), array(19, 6)), //
+ array(array( 2, 7), array(17, 0), array( 7, 16), array(34, 0)), //
+ array(array( 4, 5), array( 4, 14), array(11, 14), array(16, 14)), //
+ array(array( 6, 4), array( 6, 14), array(11, 16), array(30, 2)), //
+ array(array( 8, 4), array( 8, 13), array( 7, 22), array(22, 13)), // 25
+ array(array(10, 2), array(19, 4), array(28, 6), array(33, 4)), //
+ array(array( 8, 4), array(22, 3), array( 8, 26), array(12, 28)), //
+ array(array( 3, 10), array( 3, 23), array( 4, 31), array(11, 31)), //
+ array(array( 7, 7), array(21, 7), array( 1, 37), array(19, 26)), //
+ array(array( 5, 10), array(19, 10), array(15, 25), array(23, 25)), // 30
+ array(array(13, 3), array( 2, 29), array(42, 1), array(23, 28)), //
+ array(array(17, 0), array(10, 23), array(10, 35), array(19, 35)), //
+ array(array(17, 1), array(14, 21), array(29, 19), array(11, 46)), //
+ array(array(13, 6), array(14, 23), array(44, 7), array(59, 1)), //
+ array(array(12, 7), array(12, 26), array(39, 14), array(22, 41)), // 35
+ array(array( 6, 14), array( 6, 34), array(46, 10), array( 2, 64)), //
+ array(array(17, 4), array(29, 14), array(49, 10), array(24, 46)), //
+ array(array( 4, 18), array(13, 32), array(48, 14), array(42, 32)), //
+ array(array(20, 4), array(40, 7), array(43, 22), array(10, 67)), //
+ array(array(19, 6), array(18, 31), array(34, 34), array(20, 61)) // 40
+ );
+
+ /**
+ * @var array Positions of alignment patterns.
+ * This array includes only the second and the third position of the alignment patterns. Rest of them can be calculated from the distance between them.
+ * See Table 1 in Appendix E (pp.71) of JIS X0510:2004.
+ * @access protected
+ */
+ protected $alignmentPattern = array(
+ array( 0, 0),
+ array( 0, 0), array(18, 0), array(22, 0), array(26, 0), array(30, 0), // 1- 5
+ array(34, 0), array(22, 38), array(24, 42), array(26, 46), array(28, 50), // 6-10
+ array(30, 54), array(32, 58), array(34, 62), array(26, 46), array(26, 48), // 11-15
+ array(26, 50), array(30, 54), array(30, 56), array(30, 58), array(34, 62), // 16-20
+ array(28, 50), array(26, 50), array(30, 54), array(28, 54), array(32, 58), // 21-25
+ array(30, 58), array(34, 62), array(26, 50), array(30, 54), array(26, 52), // 26-30
+ array(30, 56), array(34, 60), array(30, 58), array(34, 62), array(30, 54), // 31-35
+ array(24, 50), array(28, 54), array(32, 58), array(26, 54), array(30, 58) // 35-40
+ );
+
+ /**
+ * @var array Version information pattern (BCH coded).
+ * See Table 1 in Appendix D (pp.68) of JIS X0510:2004.
+ * size: [QRSPEC_VERSION_MAX - 6]
+ * @access protected
+ */
+ protected $versionPattern = array(
+ 0x07c94, 0x085bc, 0x09a99, 0x0a4d3, 0x0bbf6, 0x0c762, 0x0d847, 0x0e60d, //
+ 0x0f928, 0x10b78, 0x1145d, 0x12a17, 0x13532, 0x149a6, 0x15683, 0x168c9, //
+ 0x177ec, 0x18ec4, 0x191e1, 0x1afab, 0x1b08e, 0x1cc1a, 0x1d33f, 0x1ed75, //
+ 0x1f250, 0x209d5, 0x216f0, 0x228ba, 0x2379f, 0x24b0b, 0x2542e, 0x26a64, //
+ 0x27541, 0x28c69
+ );
+
+ /**
+ * @var array Format information
+ * @access protected
+ */
+ protected $formatInfo = array(
+ array(0x77c4, 0x72f3, 0x7daa, 0x789d, 0x662f, 0x6318, 0x6c41, 0x6976), //
+ array(0x5412, 0x5125, 0x5e7c, 0x5b4b, 0x45f9, 0x40ce, 0x4f97, 0x4aa0), //
+ array(0x355f, 0x3068, 0x3f31, 0x3a06, 0x24b4, 0x2183, 0x2eda, 0x2bed), //
+ array(0x1689, 0x13be, 0x1ce7, 0x19d0, 0x0762, 0x0255, 0x0d0c, 0x083b) //
+ );
+
+
+ // -------------------------------------------------
+ // -------------------------------------------------
+
+
+ /**
+ * This is the class constructor.
+ * Creates a QRcode object
+ * @param string $code code to represent using QRcode
+ * @param string $eclevel error level: <ul><li>L : About 7% or less errors can be corrected.</li><li>M : About 15% or less errors can be corrected.</li><li>Q : About 25% or less errors can be corrected.</li><li>H : About 30% or less errors can be corrected.</li></ul>
+ * @access public
+ * @since 1.0.000
+ */
+ public function __construct($code, $eclevel = 'L') {
+ $barcode_array = array();
+ if ((is_null($code)) OR ($code == '\0') OR ($code == '')) {
+ return false;
+ }
+ // set error correction level
+ $this->level = array_search($eclevel, array('L', 'M', 'Q', 'H'));
+ if ($this->level === false) {
+ $this->level = QR_ECLEVEL_L;
+ }
+ if (($this->hint != QR_MODE_8B) AND ($this->hint != QR_MODE_KJ)) {
+ return false;
+ }
+ if (($this->version < 0) OR ($this->version > QRSPEC_VERSION_MAX)) {
+ return false;
+ }
+ $this->items = array();
+ $this->encodeString($code);
+ $qrTab = $this->binarize($this->data);
+ $size = count($qrTab);
+ $barcode_array['num_rows'] = $size;
+ $barcode_array['num_cols'] = $size;
+ $barcode_array['bcode'] = array();
+ foreach ($qrTab as $line) {
+ $arrAdd = array();
+ foreach (str_split($line) as $char) {
+ $arrAdd[] = ($char=='1')?1:0;
+ }
+ $barcode_array['bcode'][] = $arrAdd;
+ }
+ $this->barcode_array = $barcode_array;
+ }
+
+ /**
+ * Returns a barcode array which is readable by TCPDF
+ * @return array barcode array readable by TCPDF;
+ * @access public
+ */
+ public function getBarcodeArray() {
+ return $this->barcode_array;
+ }
+
+ /**
+ * Convert the frame in binary form
+ * @param array $frame array to binarize
+ * @return array frame in binary form
+ */
+ protected function binarize($frame) {
+ $len = count($frame);
+ // the frame is square (width = height)
+ foreach ($frame as &$frameLine) {
+ for ($i=0; $i<$len; $i++) {
+ $frameLine[$i] = (ord($frameLine[$i])&1)?'1':'0';
+ }
+ }
+ return $frame;
+ }
+
+ /**
+ * Encode the input string to QR code
+ * @param string $string input string to encode
+ */
+ protected function encodeString($string) {
+ $this->dataStr = $string;
+ if (!$this->casesensitive) {
+ $this->toUpper();
+ }
+ $ret = $this->splitString();
+ if ($ret < 0) {
+ return NULL;
+ }
+ $this->encodeMask(-1);
+ }
+
+ /**
+ * Encode mask
+ * @param int $mask masking mode
+ */
+ protected function encodeMask($mask) {
+ $spec = array(0, 0, 0, 0, 0);
+ $this->datacode = $this->getByteStream($this->items);
+ if (is_null($this->datacode)) {
+ return NULL;
+ }
+ $spec = $this->getEccSpec($this->version, $this->level, $spec);
+ $this->b1 = $this->rsBlockNum1($spec);
+ $this->dataLength = $this->rsDataLength($spec);
+ $this->eccLength = $this->rsEccLength($spec);
+ $this->ecccode = array_fill(0, $this->eccLength, 0);
+ $this->blocks = $this->rsBlockNum($spec);
+ $ret = $this->init($spec);
+ if ($ret < 0) {
+ return NULL;
+ }
+ $this->count = 0;
+ $this->width = $this->getWidth($this->version);
+ $this->frame = $this->newFrame($this->version);
+ $this->x = $this->width - 1;
+ $this->y = $this->width - 1;
+ $this->dir = -1;
+ $this->bit = -1;
+ // inteleaved data and ecc codes
+ for ($i=0; $i < ($this->dataLength + $this->eccLength); $i++) {
+ $code = $this->getCode();
+ $bit = 0x80;
+ for ($j=0; $j<8; $j++) {
+ $addr = $this->getNextPosition();
+ $this->setFrameAt($addr, 0x02 | (($bit & $code) != 0));
+ $bit = $bit >> 1;
+ }
+ }
+ // remainder bits
+ $j = $this->getRemainder($this->version);
+ for ($i=0; $i<$j; $i++) {
+ $addr = $this->getNextPosition();
+ $this->setFrameAt($addr, 0x02);
+ }
+ // masking
+ $this->runLength = array_fill(0, QRSPEC_WIDTH_MAX + 1, 0);
+ if ($mask < 0) {
+ if (QR_FIND_BEST_MASK) {
+ $masked = $this->mask($this->width, $this->frame, $this->level);
+ } else {
+ $masked = $this->makeMask($this->width, $this->frame, (intval(QR_DEFAULT_MASK) % 8), $this->level);
+ }
+ } else {
+ $masked = $this->makeMask($this->width, $this->frame, $mask, $this->level);
+ }
+ if ($masked == NULL) {
+ return NULL;
+ }
+ $this->data = $masked;
+ }
+
+ // - - - - - - - - - - - - - - - - - - - - - - - - -
+
+ // FrameFiller
+
+ /**
+ * Set frame value at specified position
+ * @param array $at x,y position
+ * @param int $val value of the character to set
+ */
+ protected function setFrameAt($at, $val) {
+ $this->frame[$at['y']][$at['x']] = chr($val);
+ }
+
+ /**
+ * Get frame value at specified position
+ * @param array $at x,y position
+ * @return value at specified position
+ */
+ protected function getFrameAt($at) {
+ return ord($this->frame[$at['y']][$at['x']]);
+ }
+
+ /**
+ * Return the next frame position
+ * @return array of x,y coordinates
+ */
+ protected function getNextPosition() {
+ do {
+ if ($this->bit == -1) {
+ $this->bit = 0;
+ return array('x'=>$this->x, 'y'=>$this->y);
+ }
+ $x = $this->x;
+ $y = $this->y;
+ $w = $this->width;
+ if ($this->bit == 0) {
+ $x--;
+ $this->bit++;
+ } else {
+ $x++;
+ $y += $this->dir;
+ $this->bit--;
+ }
+ if ($this->dir < 0) {
+ if ($y < 0) {
+ $y = 0;
+ $x -= 2;
+ $this->dir = 1;
+ if ($x == 6) {
+ $x--;
+ $y = 9;
+ }
+ }
+ } else {
+ if ($y == $w) {
+ $y = $w - 1;
+ $x -= 2;
+ $this->dir = -1;
+ if ($x == 6) {
+ $x--;
+ $y -= 8;
+ }
+ }
+ }
+ if (($x < 0) OR ($y < 0)) {
+ return NULL;
+ }
+ $this->x = $x;
+ $this->y = $y;
+ } while(ord($this->frame[$y][$x]) & 0x80);
+ return array('x'=>$x, 'y'=>$y);
+ }
+
+ // - - - - - - - - - - - - - - - - - - - - - - - - -
+
+ // QRrawcode
+
+ /**
+ * Initialize code.
+ * @param array $spec array of ECC specification
+ * @return 0 in case of success, -1 in case of error
+ */
+ protected function init($spec) {
+ $dl = $this->rsDataCodes1($spec);
+ $el = $this->rsEccCodes1($spec);
+ $rs = $this->init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el);
+ $blockNo = 0;
+ $dataPos = 0;
+ $eccPos = 0;
+ $endfor = $this->rsBlockNum1($spec);
+ for ($i=0; $i < $endfor; ++$i) {
+ $ecc = array_slice($this->ecccode, $eccPos);
+ $this->rsblocks[$blockNo] = array();
+ $this->rsblocks[$blockNo]['dataLength'] = $dl;
+ $this->rsblocks[$blockNo]['data'] = array_slice($this->datacode, $dataPos);
+ $this->rsblocks[$blockNo]['eccLength'] = $el;
+ $ecc = $this->encode_rs_char($rs, $this->rsblocks[$blockNo]['data'], $ecc);
+ $this->rsblocks[$blockNo]['ecc'] = $ecc;
+ $this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc);
+ $dataPos += $dl;
+ $eccPos += $el;
+ $blockNo++;
+ }
+ if ($this->rsBlockNum2($spec) == 0) {
+ return 0;
+ }
+ $dl = $this->rsDataCodes2($spec);
+ $el = $this->rsEccCodes2($spec);
+ $rs = $this->init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el);
+ if ($rs == NULL) {
+ return -1;
+ }
+ $endfor = $this->rsBlockNum2($spec);
+ for ($i=0; $i < $endfor; ++$i) {
+ $ecc = array_slice($this->ecccode, $eccPos);
+ $this->rsblocks[$blockNo] = array();
+ $this->rsblocks[$blockNo]['dataLength'] = $dl;
+ $this->rsblocks[$blockNo]['data'] = array_slice($this->datacode, $dataPos);
+ $this->rsblocks[$blockNo]['eccLength'] = $el;
+ $ecc = $this->encode_rs_char($rs, $this->rsblocks[$blockNo]['data'], $ecc);
+ $this->rsblocks[$blockNo]['ecc'] = $ecc;
+ $this->ecccode = array_merge(array_slice($this->ecccode, 0, $eccPos), $ecc);
+ $dataPos += $dl;
+ $eccPos += $el;
+ $blockNo++;
+ }
+ return 0;
+ }
+
+ /**
+ * Return Reed-Solomon block code.
+ * @return array rsblocks
+ */
+ protected function getCode() {
+ if ($this->count < $this->dataLength) {
+ $row = $this->count % $this->blocks;
+ $col = $this->count / $this->blocks;
+ if ($col >= $this->rsblocks[0]['dataLength']) {
+ $row += $this->b1;
+ }
+ $ret = $this->rsblocks[$row]['data'][$col];
+ } elseif ($this->count < $this->dataLength + $this->eccLength) {
+ $row = ($this->count - $this->dataLength) % $this->blocks;
+ $col = ($this->count - $this->dataLength) / $this->blocks;
+ $ret = $this->rsblocks[$row]['ecc'][$col];
+ } else {
+ return 0;
+ }
+ $this->count++;
+ return $ret;
+ }
+
+ // - - - - - - - - - - - - - - - - - - - - - - - - -
+
+ // QRmask
+
+ /**
+ * Write Format Information on frame and returns the number of black bits
+ * @param int $width frame width
+ * @param array $frame frame
+ * @param array $mask masking mode
+ * @param int $level error correction level
+ * @return int blacks
+ */
+ protected function writeFormatInformation($width, &$frame, $mask, $level) {
+ $blacks = 0;
+ $format = $this->getFormatInfo($mask, $level);
+ for ($i=0; $i<8; ++$i) {
+ if ($format & 1) {
+ $blacks += 2;
+ $v = 0x85;
+ } else {
+ $v = 0x84;
+ }
+ $frame[8][$width - 1 - $i] = chr($v);
+ if ($i < 6) {
+ $frame[$i][8] = chr($v);
+ } else {
+ $frame[$i + 1][8] = chr($v);
+ }
+ $format = $format >> 1;
+ }
+ for ($i=0; $i<7; ++$i) {
+ if ($format & 1) {
+ $blacks += 2;
+ $v = 0x85;
+ } else {
+ $v = 0x84;
+ }
+ $frame[$width - 7 + $i][8] = chr($v);
+ if ($i == 0) {
+ $frame[8][7] = chr($v);
+ } else {
+ $frame[8][6 - $i] = chr($v);
+ }
+ $format = $format >> 1;
+ }
+ return $blacks;
+ }
+
+ /**
+ * mask0
+ * @param int $x X position
+ * @param int $y Y position
+ * @return int mask
+ */
+ protected function mask0($x, $y) {
+ return ($x + $y) & 1;
+ }
+
+ /**
+ * mask1
+ * @param int $x X position
+ * @param int $y Y position
+ * @return int mask
+ */
+ protected function mask1($x, $y) {
+ return ($y & 1);
+ }
+
+ /**
+ * mask2
+ * @param int $x X position
+ * @param int $y Y position
+ * @return int mask
+ */
+ protected function mask2($x, $y) {
+ return ($x % 3);
+ }
+
+ /**
+ * mask3
+ * @param int $x X position
+ * @param int $y Y position
+ * @return int mask
+ */
+ protected function mask3($x, $y) {
+ return ($x + $y) % 3;
+ }
+
+ /**
+ * mask4
+ * @param int $x X position
+ * @param int $y Y position
+ * @return int mask
+ */
+ protected function mask4($x, $y) {
+ return (((int)($y / 2)) + ((int)($x / 3))) & 1;
+ }
+
+ /**
+ * mask5
+ * @param int $x X position
+ * @param int $y Y position
+ * @return int mask
+ */
+ protected function mask5($x, $y) {
+ return (($x * $y) & 1) + ($x * $y) % 3;
+ }
+
+ /**
+ * mask6
+ * @param int $x X position
+ * @param int $y Y position
+ * @return int mask
+ */
+ protected function mask6($x, $y) {
+ return ((($x * $y) & 1) + ($x * $y) % 3) & 1;
+ }
+
+ /**
+ * mask7
+ * @param int $x X position
+ * @param int $y Y position
+ * @return int mask
+ */
+ protected function mask7($x, $y) {
+ return ((($x * $y) % 3) + (($x + $y) & 1)) & 1;
+ }
+
+ /**
+ * Return bitmask
+ * @param int $maskNo mask number
+ * @param int $width width
+ * @param array $frame frame
+ * @return array bitmask
+ */
+ protected function generateMaskNo($maskNo, $width, $frame) {
+ $bitMask = array_fill(0, $width, array_fill(0, $width, 0));
+ for ($y=0; $y<$width; ++$y) {
+ for ($x=0; $x<$width; ++$x) {
+ if (ord($frame[$y][$x]) & 0x80) {
+ $bitMask[$y][$x] = 0;
+ } else {
+ $maskFunc = call_user_func(array($this, 'mask'.$maskNo), $x, $y);
+ $bitMask[$y][$x] = ($maskFunc == 0)?1:0;
+ }
+ }
+ }
+ return $bitMask;
+ }
+
+ /**
+ * makeMaskNo
+ * @param int $maskNo
+ * @param int $width
+ * @param int $s
+ * @param int $d
+ * @param boolean $maskGenOnly
+ * @return int b
+ */
+ protected function makeMaskNo($maskNo, $width, $s, &$d, $maskGenOnly=false) {
+ $b = 0;
+ $bitMask = array();
+ $bitMask = $this->generateMaskNo($maskNo, $width, $s, $d);
+ if ($maskGenOnly) {
+ return;
+ }
+ $d = $s;
+ for ($y=0; $y<$width; ++$y) {
+ for ($x=0; $x<$width; ++$x) {
+ if ($bitMask[$y][$x] == 1) {
+ $d[$y][$x] = chr(ord($s[$y][$x]) ^ (int)$bitMask[$y][$x]);
+ }
+ $b += (int)(ord($d[$y][$x]) & 1);
+ }
+ }
+ return $b;
+ }
+
+ /**
+ * makeMask
+ * @param int $width
+ * @param array $frame
+ * @param int $maskNo
+ * @param int $level
+ * @return array mask
+ */
+ protected function makeMask($width, $frame, $maskNo, $level) {
+ $masked = array_fill(0, $width, str_repeat("\0", $width));
+ $this->makeMaskNo($maskNo, $width, $frame, $masked);
+ $this->writeFormatInformation($width, $masked, $maskNo, $level);
+ return $masked;
+ }
+
+ /**
+ * calcN1N3
+ * @param int $length
+ * @return int demerit
+ */
+ protected function calcN1N3($length) {
+ $demerit = 0;
+ for ($i=0; $i<$length; ++$i) {
+ if ($this->runLength[$i] >= 5) {
+ $demerit += (N1 + ($this->runLength[$i] - 5));
+ }
+ if ($i & 1) {
+ if (($i >= 3) AND ($i < ($length-2)) AND ($this->runLength[$i] % 3 == 0)) {
+ $fact = (int)($this->runLength[$i] / 3);
+ if (($this->runLength[$i-2] == $fact)
+ AND ($this->runLength[$i-1] == $fact)
+ AND ($this->runLength[$i+1] == $fact)
+ AND ($this->runLength[$i+2] == $fact)) {
+ if (($this->runLength[$i-3] < 0) OR ($this->runLength[$i-3] >= (4 * $fact))) {
+ $demerit += N3;
+ } elseif ((($i+3) >= $length) OR ($this->runLength[$i+3] >= (4 * $fact))) {
+ $demerit += N3;
+ }
+ }
+ }
+ }
+ }
+ return $demerit;
+ }
+
+ /**
+ * evaluateSymbol
+ * @param int $width
+ * @param array $frame
+ * @return int demerit
+ */
+ protected function evaluateSymbol($width, $frame) {
+ $head = 0;
+ $demerit = 0;
+ for ($y=0; $y<$width; ++$y) {
+ $head = 0;
+ $this->runLength[0] = 1;
+ $frameY = $frame[$y];
+ if ($y > 0) {
+ $frameYM = $frame[$y-1];
+ }
+ for ($x=0; $x<$width; ++$x) {
+ if (($x > 0) AND ($y > 0)) {
+ $b22 = ord($frameY[$x]) & ord($frameY[$x-1]) & ord($frameYM[$x]) & ord($frameYM[$x-1]);
+ $w22 = ord($frameY[$x]) | ord($frameY[$x-1]) | ord($frameYM[$x]) | ord($frameYM[$x-1]);
+ if (($b22 | ($w22 ^ 1)) & 1) {
+ $demerit += N2;
+ }
+ }
+ if (($x == 0) AND (ord($frameY[$x]) & 1)) {
+ $this->runLength[0] = -1;
+ $head = 1;
+ $this->runLength[$head] = 1;
+ } elseif ($x > 0) {
+ if ((ord($frameY[$x]) ^ ord($frameY[$x-1])) & 1) {
+ $head++;
+ $this->runLength[$head] = 1;
+ } else {
+ $this->runLength[$head]++;
+ }
+ }
+ }
+ $demerit += $this->calcN1N3($head+1);
+ }
+ for ($x=0; $x<$width; ++$x) {
+ $head = 0;
+ $this->runLength[0] = 1;
+ for ($y=0; $y<$width; ++$y) {
+ if (($y == 0) AND (ord($frame[$y][$x]) & 1)) {
+ $this->runLength[0] = -1;
+ $head = 1;
+ $this->runLength[$head] = 1;
+ } elseif ($y > 0) {
+ if ((ord($frame[$y][$x]) ^ ord($frame[$y-1][$x])) & 1) {
+ $head++;
+ $this->runLength[$head] = 1;
+ } else {
+ $this->runLength[$head]++;
+ }
+ }
+ }
+ $demerit += $this->calcN1N3($head+1);
+ }
+ return $demerit;
+ }
+
+ /**
+ * mask
+ * @param int $width
+ * @param array $frame
+ * @param int $level
+ * @return array best mask
+ */
+ protected function mask($width, $frame, $level) {
+ $minDemerit = PHP_INT_MAX;
+ $bestMaskNum = 0;
+ $bestMask = array();
+ $checked_masks = array(0, 1, 2, 3, 4, 5, 6, 7);
+ if (QR_FIND_FROM_RANDOM !== false) {
+ $howManuOut = 8 - (QR_FIND_FROM_RANDOM % 9);
+ for ($i = 0; $i < $howManuOut; ++$i) {
+ $remPos = rand (0, count($checked_masks)-1);
+ unset($checked_masks[$remPos]);
+ $checked_masks = array_values($checked_masks);
+ }
+ }
+ $bestMask = $frame;
+ foreach ($checked_masks as $i) {
+ $mask = array_fill(0, $width, str_repeat("\0", $width));
+ $demerit = 0;
+ $blacks = 0;
+ $blacks = $this->makeMaskNo($i, $width, $frame, $mask);
+ $blacks += $this->writeFormatInformation($width, $mask, $i, $level);
+ $blacks = (int)(100 * $blacks / ($width * $width));
+ $demerit = (int)((int)(abs($blacks - 50) / 5) * N4);
+ $demerit += $this->evaluateSymbol($width, $mask);
+ if ($demerit < $minDemerit) {
+ $minDemerit = $demerit;
+ $bestMask = $mask;
+ $bestMaskNum = $i;
+ }
+ }
+ return $bestMask;
+ }
+
+ // - - - - - - - - - - - - - - - - - - - - - - - - -
+
+ // QRsplit
+
+ /**
+ * Return true if the character at specified position is a number
+ * @param string $str string
+ * @param int $pos characted position
+ * @return boolean true of false
+ */
+ protected function isdigitat($str, $pos) {
+ if ($pos >= strlen($str)) {
+ return false;
+ }
+ return ((ord($str[$pos]) >= ord('0'))&&(ord($str[$pos]) <= ord('9')));
+ }
+
+ /**
+ * Return true if the character at specified position is an alphanumeric character
+ * @param string $str string
+ * @param int $pos characted position
+ * @return boolean true of false
+ */
+ protected function isalnumat($str, $pos) {
+ if ($pos >= strlen($str)) {
+ return false;
+ }
+ return ($this->lookAnTable(ord($str[$pos])) >= 0);
+ }
+
+ /**
+ * identifyMode
+ * @param int $pos
+ * @return int mode
+ */
+ protected function identifyMode($pos) {
+ if ($pos >= strlen($this->dataStr)) {
+ return QR_MODE_NL;
+ }
+ $c = $this->dataStr[$pos];
+ if ($this->isdigitat($this->dataStr, $pos)) {
+ return QR_MODE_NM;
+ } elseif ($this->isalnumat($this->dataStr, $pos)) {
+ return QR_MODE_AN;
+ } elseif ($this->hint == QR_MODE_KJ) {
+ if ($pos+1 < strlen($this->dataStr)) {
+ $d = $this->dataStr[$pos+1];
+ $word = (ord($c) << 8) | ord($d);
+ if (($word >= 0x8140 && $word <= 0x9ffc) OR ($word >= 0xe040 && $word <= 0xebbf)) {
+ return QR_MODE_KJ;
+ }
+ }
+ }
+ return QR_MODE_8B;
+ }
+
+ /**
+ * eatNum
+ * @return int run
+ */
+ protected function eatNum() {
+ $ln = $this->lengthIndicator(QR_MODE_NM, $this->version);
+ $p = 0;
+ while($this->isdigitat($this->dataStr, $p)) {
+ $p++;
+ }
+ $run = $p;
+ $mode = $this->identifyMode($p);
+ if ($mode == QR_MODE_8B) {
+ $dif = $this->estimateBitsModeNum($run) + 4 + $ln
+ + $this->estimateBitsMode8(1) // + 4 + l8
+ - $this->estimateBitsMode8($run + 1); // - 4 - l8
+ if ($dif > 0) {
+ return $this->eat8();
+ }
+ }
+ if ($mode == QR_MODE_AN) {
+ $dif = $this->estimateBitsModeNum($run) + 4 + $ln
+ + $this->estimateBitsModeAn(1) // + 4 + la
+ - $this->estimateBitsModeAn($run + 1);// - 4 - la
+ if ($dif > 0) {
+ return $this->eatAn();
+ }
+ }
+ $this->items = $this->appendNewInputItem($this->items, QR_MODE_NM, $run, str_split($this->dataStr));
+ return $run;
+ }
+
+ /**
+ * eatAn
+ * @return int run
+ */
+ protected function eatAn() {
+ $la = $this->lengthIndicator(QR_MODE_AN, $this->version);
+ $ln = $this->lengthIndicator(QR_MODE_NM, $this->version);
+ $p = 0;
+ while($this->isalnumat($this->dataStr, $p)) {
+ if ($this->isdigitat($this->dataStr, $p)) {
+ $q = $p;
+ while($this->isdigitat($this->dataStr, $q)) {
+ $q++;
+ }
+ $dif = $this->estimateBitsModeAn($p) // + 4 + la
+ + $this->estimateBitsModeNum($q - $p) + 4 + $ln
+ - $this->estimateBitsModeAn($q); // - 4 - la
+ if ($dif < 0) {
+ break;
+ } else {
+ $p = $q;
+ }
+ } else {
+ $p++;
+ }
+ }
+ $run = $p;
+ if (!$this->isalnumat($this->dataStr, $p)) {
+ $dif = $this->estimateBitsModeAn($run) + 4 + $la
+ + $this->estimateBitsMode8(1) // + 4 + l8
+ - $this->estimateBitsMode8($run + 1); // - 4 - l8
+ if ($dif > 0) {
+ return $this->eat8();
+ }
+ }
+ $this->items = $this->appendNewInputItem($this->items, QR_MODE_AN, $run, str_split($this->dataStr));
+ return $run;
+ }
+
+ /**
+ * eatKanji
+ * @return int run
+ */
+ protected function eatKanji() {
+ $p = 0;
+ while($this->identifyMode($p) == QR_MODE_KJ) {
+ $p += 2;
+ }
+ $this->items = $this->appendNewInputItem($this->items, QR_MODE_KJ, $p, str_split($this->dataStr));
+ return $run;
+ }
+
+ /**
+ * eat8
+ * @return int run
+ */
+ protected function eat8() {
+ $la = $this->lengthIndicator(QR_MODE_AN, $this->version);
+ $ln = $this->lengthIndicator(QR_MODE_NM, $this->version);
+ $p = 1;
+ $dataStrLen = strlen($this->dataStr);
+ while($p < $dataStrLen) {
+ $mode = $this->identifyMode($p);
+ if ($mode == QR_MODE_KJ) {
+ break;
+ }
+ if ($mode == QR_MODE_NM) {
+ $q = $p;
+ while($this->isdigitat($this->dataStr, $q)) {
+ $q++;
+ }
+ $dif = $this->estimateBitsMode8($p) // + 4 + l8
+ + $this->estimateBitsModeNum($q - $p) + 4 + $ln
+ - $this->estimateBitsMode8($q); // - 4 - l8
+ if ($dif < 0) {
+ break;
+ } else {
+ $p = $q;
+ }
+ } elseif ($mode == QR_MODE_AN) {
+ $q = $p;
+ while($this->isalnumat($this->dataStr, $q)) {
+ $q++;
+ }
+ $dif = $this->estimateBitsMode8($p) // + 4 + l8
+ + $this->estimateBitsModeAn($q - $p) + 4 + $la
+ - $this->estimateBitsMode8($q); // - 4 - l8
+ if ($dif < 0) {
+ break;
+ } else {
+ $p = $q;
+ }
+ } else {
+ $p++;
+ }
+ }
+ $run = $p;
+ $this->items = $this->appendNewInputItem($this->items, QR_MODE_8B, $run, str_split($this->dataStr));
+ return $run;
+ }
+
+ /**
+ * splitString
+ */
+ protected function splitString() {
+ while (strlen($this->dataStr) > 0) {
+ if ($this->dataStr == '') {
+ return 0;
+ }
+ $mode = $this->identifyMode(0);
+ switch ($mode) {
+ case QR_MODE_NM: {
+ $length = $this->eatNum();
+ break;
+ }
+ case QR_MODE_AN: {
+ $length = $this->eatAn();
+ break;
+ }
+ case QR_MODE_KJ: {
+ if ($hint == QR_MODE_KJ) {
+ $length = $this->eatKanji();
+ } else {
+ $length = $this->eat8();
+ }
+ break;
+ }
+ default: {
+ $length = $this->eat8();
+ break;
+ }
+ }
+ if ($length == 0) {
+ return 0;
+ }
+ if ($length < 0) {
+ return -1;
+ }
+ $this->dataStr = substr($this->dataStr, $length);
+ }
+ }
+
+ /**
+ * toUpper
+ */
+ protected function toUpper() {
+ $stringLen = strlen($this->dataStr);
+ $p = 0;
+ while ($p < $stringLen) {
+ $mode = $this->identifyMode(substr($this->dataStr, $p), $this->hint);
+ if ($mode == QR_MODE_KJ) {
+ $p += 2;
+ } else {
+ if ((ord($this->dataStr[$p]) >= ord('a')) AND (ord($this->dataStr[$p]) <= ord('z'))) {
+ $this->dataStr[$p] = chr(ord($this->dataStr[$p]) - 32);
+ }
+ $p++;
+ }
+ }
+ return $this->dataStr;
+ }
+
+ // - - - - - - - - - - - - - - - - - - - - - - - - -
+
+ // QRinputItem
+
+ /**
+ * newInputItem
+ * @param int $mode
+ * @param int $size
+ * @param array $data
+ * @param array $bstream
+ * @return array input item
+ */
+ protected function newInputItem($mode, $size, $data, $bstream=null) {
+ $setData = array_slice($data, 0, $size);
+ if (count($setData) < $size) {
+ $setData = array_merge($setData, array_fill(0, ($size - count($setData)), 0));
+ }
+ if (!$this->check($mode, $size, $setData)) {
+ return NULL;
+ }
+ $inputitem = array();
+ $inputitem['mode'] = $mode;
+ $inputitem['size'] = $size;
+ $inputitem['data'] = $setData;
+ $inputitem['bstream'] = $bstream;
+ return $inputitem;
+ }
+
+ /**
+ * encodeModeNum
+ * @param array $inputitem
+ * @param int $version
+ * @return array input item
+ */
+ protected function encodeModeNum($inputitem, $version) {
+ $words = (int)($inputitem['size'] / 3);
+ $inputitem['bstream'] = array();
+ $val = 0x1;
+ $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, $val);
+ $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], $this->lengthIndicator(QR_MODE_NM, $version), $inputitem['size']);
+ for ($i=0; $i < $words; ++$i) {
+ $val = (ord($inputitem['data'][$i*3 ]) - ord('0')) * 100;
+ $val += (ord($inputitem['data'][$i*3+1]) - ord('0')) * 10;
+ $val += (ord($inputitem['data'][$i*3+2]) - ord('0'));
+ $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 10, $val);
+ }
+ if ($inputitem['size'] - $words * 3 == 1) {
+ $val = ord($inputitem['data'][$words*3]) - ord('0');
+ $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, $val);
+ } elseif (($inputitem['size'] - ($words * 3)) == 2) {
+ $val = (ord($inputitem['data'][$words*3 ]) - ord('0')) * 10;
+ $val += (ord($inputitem['data'][$words*3+1]) - ord('0'));
+ $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 7, $val);
+ }
+ return $inputitem;
+ }
+
+ /**
+ * encodeModeAn
+ * @param array $inputitem
+ * @param int $version
+ * @return array input item
+ */
+ protected function encodeModeAn($inputitem, $version) {
+ $words = (int)($inputitem['size'] / 2);
+ $inputitem['bstream'] = array();
+ $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, 0x02);
+ $inputitem['bstream'] = $this->appendNum(v, $this->lengthIndicator(QR_MODE_AN, $version), $inputitem['size']);
+ for ($i=0; $i < $words; ++$i) {
+ $val = (int)$this->lookAnTable(ord($inputitem['data'][$i*2 ])) * 45;
+ $val += (int)$this->lookAnTable(ord($inputitem['data'][$i*2+1]));
+ $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 11, $val);
+ }
+ if ($inputitem['size'] & 1) {
+ $val = $this->lookAnTable(ord($inputitem['data'][($words * 2)]));
+ $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 6, $val);
+ }
+ return $inputitem;
+ }
+
+ /**
+ * encodeMode8
+ * @param array $inputitem
+ * @param int $version
+ * @return array input item
+ */
+ protected function encodeMode8($inputitem, $version) {
+ $inputitem['bstream'] = array();
+ $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, 0x4);
+ $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], $this->lengthIndicator(QR_MODE_8B, $version), $inputitem['size']);
+ for ($i=0; $i < $inputitem['size']; ++$i) {
+ $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 8, ord($inputitem['data'][$i]));
+ }
+ return $inputitem;
+ }
+
+ /**
+ * encodeModeKanji
+ * @param array $inputitem
+ * @param int $version
+ * @return array input item
+ */
+ protected function encodeModeKanji($inputitem, $version) {
+ $inputitem['bstream'] = array();
+ $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, 0x8);
+ $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], $this->lengthIndicator(QR_MODE_KJ, $version), (int)($inputitem['size'] / 2));
+ for ($i=0; $i<$inputitem['size']; $i+=2) {
+ $val = (ord($inputitem['data'][$i]) << 8) | ord($inputitem['data'][$i+1]);
+ if ($val <= 0x9ffc) {
+ $val -= 0x8140;
+ } else {
+ $val -= 0xc140;
+ }
+ $h = ($val >> 8) * 0xc0;
+ $val = ($val & 0xff) + $h;
+ $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 13, $val);
+ }
+ return $inputitem;
+ }
+
+ /**
+ * encodeModeStructure
+ * @param array $inputitem
+ * @return array input item
+ */
+ protected function encodeModeStructure($inputitem) {
+ $inputitem['bstream'] = array();
+ $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, 0x03);
+ $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, ord($inputitem['data'][1]) - 1);
+ $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 4, ord($inputitem['data'][0]) - 1);
+ $inputitem['bstream'] = $this->appendNum($inputitem['bstream'], 8, ord($inputitem['data'][2]));
+ return $inputitem;
+ }
+
+ /**
+ * encodeBitStream
+ * @param array $inputitem
+ * @param int $version
+ * @return array input item
+ */
+ protected function encodeBitStream($inputitem, $version) {
+ $inputitem['bstream'] = array();
+ $words = $this->maximumWords($inputitem['mode'], $version);
+ if ($inputitem['size'] > $words) {
+ $st1 = $this->newInputItem($inputitem['mode'], $words, $inputitem['data']);
+ $st2 = $this->newInputItem($inputitem['mode'], $inputitem['size'] - $words, array_slice($inputitem['data'], $words));
+ $st1 = $this->encodeBitStream($st1, $version);
+ $st2 = $this->encodeBitStream($st2, $version);
+ $inputitem['bstream'] = array();
+ $inputitem['bstream'] = $this->appendBitstream($inputitem['bstream'], $st1['bstream']);
+ $inputitem['bstream'] = $this->appendBitstream($inputitem['bstream'], $st2['bstream']);
+ } else {
+ switch($inputitem['mode']) {
+ case QR_MODE_NM: {
+ $inputitem = $this->encodeModeNum($inputitem, $version);
+ break;
+ }
+ case QR_MODE_AN: {
+ $inputitem = $this->encodeModeAn($inputitem, $version);
+ break;
+ }
+ case QR_MODE_8B: {
+ $inputitem = $this->encodeMode8($inputitem, $version);
+ break;
+ }
+ case QR_MODE_KJ: {
+ $inputitem = $this->encodeModeKanji($inputitem, $version);
+ break;
+ }
+ case QR_MODE_ST: {
+ $inputitem = $this->encodeModeStructure($inputitem);
+ break;
+ }
+ default: {
+ break;
+ }
+ }
+ }
+ return $inputitem;
+ }
+
+ // - - - - - - - - - - - - - - - - - - - - - - - - -
+
+ // QRinput
+
+ /**
+ * Append data to an input object.
+ * The data is copied and appended to the input object.
+ * @param array items input items
+ * @param int $mode encoding mode.
+ * @param int $size size of data (byte).
+ * @param array $data array of input data.
+ * @return items
+ *
+ */
+ protected function appendNewInputItem($items, $mode, $size, $data) {
+ $items[] = $this->newInputItem($mode, $size, $data);
+ return $items;
+ }
+
+ /**
+ * insertStructuredAppendHeader
+ * @param array $items
+ * @param int $size
+ * @param int $index
+ * @param int $parity
+ * @return array items
+ */
+ protected function insertStructuredAppendHeader($items, $size, $index, $parity) {
+ if ($size > MAX_STRUCTURED_SYMBOLS) {
+ return -1;
+ }
+ if (($index <= 0) OR ($index > MAX_STRUCTURED_SYMBOLS)) {
+ return -1;
+ }
+ $buf = array($size, $index, $parity);
+ $entry = $this->newInputItem(QR_MODE_ST, 3, buf);
+ array_unshift($items, $entry);
+ return $items;
+ }
+
+ /**
+ * calcParity
+ * @param array $items
+ * @return int parity
+ */
+ protected function calcParity($items) {
+ $parity = 0;
+ foreach ($items as $item) {
+ if ($item['mode'] != QR_MODE_ST) {
+ for ($i=$item['size']-1; $i>=0; --$i) {
+ $parity ^= $item['data'][$i];
+ }
+ }
+ }
+ return $parity;
+ }
+
+ /**
+ * checkModeNum
+ * @param int $size
+ * @param array $data
+ * @return boolean true or false
+ */
+ protected function checkModeNum($size, $data) {
+ for ($i=0; $i<$size; ++$i) {
+ if ((ord($data[$i]) < ord('0')) OR (ord($data[$i]) > ord('9'))){
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * estimateBitsModeNum
+ * @param int $size
+ * @return int number of bits
+ */
+ protected function estimateBitsModeNum($size) {
+ $w = (int)$size / 3;
+ $bits = $w * 10;
+ switch($size - $w * 3) {
+ case 1: {
+ $bits += 4;
+ break;
+ }
+ case 2: {
+ $bits += 7;
+ break;
+ }
+ default: {
+ break;
+ }
+ }
+ return $bits;
+ }
+
+ /**
+ * Look up the alphabet-numeric convesion table (see JIS X0510:2004, pp.19).
+ * @param int $c character value
+ * @return value
+ */
+ protected function lookAnTable($c) {
+ return (($c > 127)?-1:$this->anTable[$c]);
+ }
+
+ /**
+ * checkModeAn
+ * @param int $size
+ * @param array $data
+ * @return boolean true or false
+ */
+ protected function checkModeAn($size, $data) {
+ for ($i=0; $i<$size; ++$i) {
+ if ($this->lookAnTable(ord($data[$i])) == -1) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * estimateBitsModeAn
+ * @param int $size
+ * @return int number of bits
+ */
+ protected function estimateBitsModeAn($size) {
+ $w = (int)($size / 2);
+ $bits = $w * 11;
+ if ($size & 1) {
+ $bits += 6;
+ }
+ return $bits;
+ }
+
+ /**
+ * estimateBitsMode8
+ * @param int $size
+ * @return int number of bits
+ */
+ protected function estimateBitsMode8($size) {
+ return $size * 8;
+ }
+
+ /**
+ * estimateBitsModeKanji
+ * @param int $size
+ * @return int number of bits
+ */
+ protected function estimateBitsModeKanji($size) {
+ return (int)(($size / 2) * 13);
+ }
+
+ /**
+ * checkModeKanji
+ * @param int $size
+ * @param array $data
+ * @return boolean true or false
+ */
+ protected function checkModeKanji($size, $data) {
+ if ($size & 1) {
+ return false;
+ }
+ for ($i=0; $i<$size; $i+=2) {
+ $val = (ord($data[$i]) << 8) | ord($data[$i+1]);
+ if (($val < 0x8140) OR (($val > 0x9ffc) AND ($val < 0xe040)) OR ($val > 0xebbf)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Validate the input data.
+ * @param int $mode encoding mode.
+ * @param int $size size of data (byte).
+ * @param array data data to validate
+ * @return boolean true in case of valid data, false otherwise
+ */
+ protected function check($mode, $size, $data) {
+ if ($size <= 0) {
+ return false;
+ }
+ switch($mode) {
+ case QR_MODE_NM: {
+ return $this->checkModeNum($size, $data);
+ }
+ case QR_MODE_AN: {
+ return $this->checkModeAn($size, $data);
+ }
+ case QR_MODE_KJ: {
+ return $this->checkModeKanji($size, $data);
+ }
+ case QR_MODE_8B: {
+ return true;
+ }
+ case QR_MODE_ST: {
+ return true;
+ }
+ default: {
+ break;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * estimateBitStreamSize
+ * @param array $items
+ * @param int $version
+ * @return int bits
+ */
+ protected function estimateBitStreamSize($items, $version) {
+ $bits = 0;
+ if ($version == 0) {
+ $version = 1;
+ }
+ foreach ($items as $item) {
+ switch($item['mode']) {
+ case QR_MODE_NM: {
+ $bits = $this->estimateBitsModeNum($item['size']);
+ break;
+ }
+ case QR_MODE_AN: {
+ $bits = $this->estimateBitsModeAn($item['size']);
+ break;
+ }
+ case QR_MODE_8B: {
+ $bits = $this->estimateBitsMode8($item['size']);
+ break;
+ }
+ case QR_MODE_KJ: {
+ $bits = $this->estimateBitsModeKanji($item['size']);
+ break;
+ }
+ case QR_MODE_ST: {
+ return STRUCTURE_HEADER_BITS;
+ }
+ default: {
+ return 0;
+ }
+ }
+ $l = $this->lengthIndicator($item['mode'], $version);
+ $m = 1 << $l;
+ $num = (int)(($item['size'] + $m - 1) / $m);
+ $bits += $num * (4 + $l);
+ }
+ return $bits;
+ }
+
+ /**
+ * estimateVersion
+ * @param array $items
+ * @return int version
+ */
+ protected function estimateVersion($items) {
+ $version = 0;
+ $prev = 0;
+ do {
+ $prev = $version;
+ $bits = $this->estimateBitStreamSize($items, $prev);
+ $version = $this->getMinimumVersion((int)(($bits + 7) / 8), $this->level);
+ if ($version < 0) {
+ return -1;
+ }
+ } while ($version > $prev);
+ return $version;
+ }
+
+ /**
+ * lengthOfCode
+ * @param int $mode
+ * @param int $version
+ * @param int $bits
+ * @return int size
+ */
+ protected function lengthOfCode($mode, $version, $bits) {
+ $payload = $bits - 4 - $this->lengthIndicator($mode, $version);
+ switch($mode) {
+ case QR_MODE_NM: {
+ $chunks = (int)($payload / 10);
+ $remain = $payload - $chunks * 10;
+ $size = $chunks * 3;
+ if ($remain >= 7) {
+ $size += 2;
+ } elseif ($remain >= 4) {
+ $size += 1;
+ }
+ break;
+ }
+ case QR_MODE_AN: {
+ $chunks = (int)($payload / 11);
+ $remain = $payload - $chunks * 11;
+ $size = $chunks * 2;
+ if ($remain >= 6) {
+ ++$size;
+ }
+ break;
+ }
+ case QR_MODE_8B: {
+ $size = (int)($payload / 8);
+ break;
+ }
+ case QR_MODE_KJ: {
+ $size = (int)(($payload / 13) * 2);
+ break;
+ }
+ case QR_MODE_ST: {
+ $size = (int)($payload / 8);
+ break;
+ }
+ default: {
+ $size = 0;
+ break;
+ }
+ }
+ $maxsize = $this->maximumWords($mode, $version);
+ if ($size < 0) {
+ $size = 0;
+ }
+ if ($size > $maxsize) {
+ $size = $maxsize;
+ }
+ return $size;
+ }
+
+ /**
+ * createBitStream
+ * @param array $items
+ * @return array of items and total bits
+ */
+ protected function createBitStream($items) {
+ $total = 0;
+ foreach ($items as $key => $item) {
+ $items[$key] = $this->encodeBitStream($item, $this->version);
+ $bits = count($items[$key]['bstream']);
+ $total += $bits;
+ }
+ return array($items, $total);
+ }
+
+ /**
+ * convertData
+ * @param array $items
+ * @return array items
+ */
+ protected function convertData($items) {
+ $ver = $this->estimateVersion($items);
+ if ($ver > $this->version) {
+ $this->version = $ver;
+ }
+ for (;;) {
+ $cbs = $this->createBitStream($items);
+ $items = $cbs[0];
+ $bits = $cbs[1];
+ if ($bits < 0) {
+ return -1;
+ }
+ $ver = $this->getMinimumVersion((int)(($bits + 7) / 8), $this->level);
+ if ($ver < 0) {
+ return -1;
+ } elseif ($ver > $this->version) {
+ $this->version = $ver;
+ } else {
+ break;
+ }
+ }
+ return $items;
+ }
+
+ /**
+ * Append Padding Bit to bitstream
+ * @param array $bstream
+ * @return array bitstream
+ */
+ protected function appendPaddingBit($bstream) {
+ $bits = count($bstream);
+ $maxwords = $this->getDataLength($this->version, $this->level);
+ $maxbits = $maxwords * 8;
+ if ($maxbits == $bits) {
+ return 0;
+ }
+ if ($maxbits - $bits < 5) {
+ return $this->appendNum($bstream, $maxbits - $bits, 0);
+ }
+ $bits += 4;
+ $words = (int)(($bits + 7) / 8);
+ $padding = array();
+ $padding = $this->appendNum($padding, $words * 8 - $bits + 4, 0);
+ $padlen = $maxwords - $words;
+ if ($padlen > 0) {
+ $padbuf = array();
+ for ($i=0; $i<$padlen; ++$i) {
+ $padbuf[$i] = ($i&1)?0x11:0xec;
+ }
+ $padding = $this->appendBytes($padding, $padlen, $padbuf);
+ }
+ return $this->appendBitstream($bstream, $padding);
+ }
+
+ /**
+ * mergeBitStream
+ * @param array $bstream
+ * @return array bitstream
+ */
+ protected function mergeBitStream($items) {
+ $items = $this->convertData($items);
+ $bstream = array();
+ foreach ($items as $item) {
+ $bstream = $this->appendBitstream($bstream, $item['bstream']);
+ }
+ return $bstream;
+ }
+
+ /**
+ * Returns a stream of bits.
+ * @param int $items
+ * @return array padded merged byte stream
+ */
+ protected function getBitStream($items) {
+ $bstream = $this->mergeBitStream($items);
+ return $this->appendPaddingBit($bstream);
+ }
+
+ /**
+ * Pack all bit streams padding bits into a byte array.
+ * @param int $items
+ * @return array padded merged byte stream
+ */
+ protected function getByteStream($items) {
+ $bstream = $this->getBitStream($items);
+ return $this->bitstreamToByte($bstream);
+ }
+
+ // - - - - - - - - - - - - - - - - - - - - - - - - -
+
+ // QRbitstream
+
+ /**
+ * Return an array with zeros
+ * @param int $setLength array size
+ * @return array
+ */
+ protected function allocate($setLength) {
+ return array_fill(0, $setLength, 0);
+ }
+
+ /**
+ * Return new bitstream from number
+ * @param int $bits number of bits
+ * @param int $num number
+ * @return array bitstream
+ */
+ protected function newFromNum($bits, $num) {
+ $bstream = $this->allocate($bits);
+ $mask = 1 << ($bits - 1);
+ for ($i=0; $i<$bits; ++$i) {
+ if ($num & $mask) {
+ $bstream[$i] = 1;
+ } else {
+ $bstream[$i] = 0;
+ }
+ $mask = $mask >> 1;
+ }
+ return $bstream;
+ }
+
+ /**
+ * Return new bitstream from bytes
+ * @param int $size size
+ * @param array $data bytes
+ * @return array bitstream
+ */
+ protected function newFromBytes($size, $data) {
+ $bstream = $this->allocate($size * 8);
+ $p=0;
+ for ($i=0; $i<$size; ++$i) {
+ $mask = 0x80;
+ for ($j=0; $j<8; ++$j) {
+ if ($data[$i] & $mask) {
+ $bstream[$p] = 1;
+ } else {
+ $bstream[$p] = 0;
+ }
+ $p++;
+ $mask = $mask >> 1;
+ }
+ }
+ return $bstream;
+ }
+
+ /**
+ * Append one bitstream to another
+ * @param array $bitstream original bitstream
+ * @param array $append bitstream to append
+ * @return array bitstream
+ */
+ protected function appendBitstream($bitstream, $append) {
+ if ((!is_array($append)) OR (count($append) == 0)) {
+ return $bitstream;
+ }
+ if (count($bitstream) == 0) {
+ return $append;
+ }
+ return array_values(array_merge($bitstream, $append));
+ }
+
+ /**
+ * Append one bitstream created from number to another
+ * @param array $bitstream original bitstream
+ * @param int $bits number of bits
+ * @param int $num number
+ * @return array bitstream
+ */
+ protected function appendNum($bitstream, $bits, $num) {
+ if ($bits == 0) {
+ return 0;
+ }
+ $b = $this->newFromNum($bits, $num);
+ return $this->appendBitstream($bitstream, $b);
+ }
+
+ /**
+ * Append one bitstream created from bytes to another
+ * @param array $bitstream original bitstream
+ * @param int $size size
+ * @param array $data bytes
+ * @return array bitstream
+ */
+ protected function appendBytes($bitstream, $size, $data) {
+ if ($size == 0) {
+ return 0;
+ }
+ $b = $this->newFromBytes($size, $data);
+ return $this->appendBitstream($bitstream, $b);
+ }
+
+ /**
+ * Convert bitstream to bytes
+ * @param array $bitstream original bitstream
+ * @return array of bytes
+ */
+ protected function bitstreamToByte($bstream) {
+ $size = count($bstream);
+ if ($size == 0) {
+ return array();
+ }
+ $data = array_fill(0, (int)(($size + 7) / 8), 0);
+ $bytes = (int)($size / 8);
+ $p = 0;
+ for ($i=0; $i<$bytes; $i++) {
+ $v = 0;
+ for ($j=0; $j<8; $j++) {
+ $v = $v << 1;
+ $v |= $bstream[$p];
+ $p++;
+ }
+ $data[$i] = $v;
+ }
+ if ($size & 7) {
+ $v = 0;
+ for ($j=0; $j<($size & 7); $j++) {
+ $v = $v << 1;
+ $v |= $bstream[$p];
+ $p++;
+ }
+ $data[$bytes] = $v;
+ }
+ return $data;
+ }
+
+ // - - - - - - - - - - - - - - - - - - - - - - - - -
+
+ // QRspec
+
+ /**
+ * Replace a value on the array at the specified position
+ * @param array $srctab
+ * @param int $x X position
+ * @param int $y Y position
+ * @param string $repl value to replace
+ * @param int $replLen length of the repl string
+ * @return array srctab
+ */
+ protected function qrstrset($srctab, $x, $y, $repl, $replLen=false) {
+ $srctab[$y] = substr_replace($srctab[$y], ($replLen !== false)?substr($repl,0,$replLen):$repl, $x, ($replLen !== false)?$replLen:strlen($repl));
+ return $srctab;
+ }
+
+ /**
+ * Return maximum data code length (bytes) for the version.
+ * @param int $version version
+ * @param int $level error correction level
+ * @return int maximum size (bytes)
+ */
+ protected function getDataLength($version, $level) {
+ return $this->capacity[$version][QRCAP_WORDS] - $this->capacity[$version][QRCAP_EC][$level];
+ }
+
+ /**
+ * Return maximum error correction code length (bytes) for the version.
+ * @param int $version version
+ * @param int $level error correction level
+ * @return int ECC size (bytes)
+ */
+ protected function getECCLength($version, $level){
+ return $this->capacity[$version][QRCAP_EC][$level];
+ }
+
+ /**
+ * Return the width of the symbol for the version.
+ * @param int $version version
+ * @return int width
+ */
+ protected function getWidth($version) {
+ return $this->capacity[$version][QRCAP_WIDTH];
+ }
+
+ /**
+ * Return the numer of remainder bits.
+ * @param int $version version
+ * @return int number of remainder bits
+ */
+ protected function getRemainder($version) {
+ return $this->capacity[$version][QRCAP_REMINDER];
+ }
+
+ /**
+ * Return a version number that satisfies the input code length.
+ * @param int $size input code length (byte)
+ * @param int $level error correction level
+ * @return int version number
+ */
+ protected function getMinimumVersion($size, $level) {
+ for ($i=1; $i <= QRSPEC_VERSION_MAX; ++$i) {
+ $words = $this->capacity[$i][QRCAP_WORDS] - $this->capacity[$i][QRCAP_EC][$level];
+ if ($words >= $size) {
+ return $i;
+ }
+ }
+ return -1;
+ }
+
+ /**
+ * Return the size of length indicator for the mode and version.
+ * @param int $mode encoding mode
+ * @param int $version version
+ * @return int the size of the appropriate length indicator (bits).
+ */
+ protected function lengthIndicator($mode, $version) {
+ if ($mode == QR_MODE_ST) {
+ return 0;
+ }
+ if ($version <= 9) {
+ $l = 0;
+ } elseif ($version <= 26) {
+ $l = 1;
+ } else {
+ $l = 2;
+ }
+ return $this->lengthTableBits[$mode][$l];
+ }
+
+ /**
+ * Return the maximum length for the mode and version.
+ * @param int $mode encoding mode
+ * @param int $version version
+ * @return int the maximum length (bytes)
+ */
+ protected function maximumWords($mode, $version) {
+ if ($mode == QR_MODE_ST) {
+ return 3;
+ }
+ if ($version <= 9) {
+ $l = 0;
+ } else if ($version <= 26) {
+ $l = 1;
+ } else {
+ $l = 2;
+ }
+ $bits = $this->lengthTableBits[$mode][$l];
+ $words = (1 << $bits) - 1;
+ if ($mode == QR_MODE_KJ) {
+ $words *= 2; // the number of bytes is required
+ }
+ return $words;
+ }
+
+ /**
+ * Return an array of ECC specification.
+ * @param int $version version
+ * @param int $level error correction level
+ * @param array $spec an array of ECC specification contains as following: {# of type1 blocks, # of data code, # of ecc code, # of type2 blocks, # of data code}
+ * @return array spec
+ */
+ protected function getEccSpec($version, $level, $spec) {
+ if (count($spec) < 5) {
+ $spec = array(0, 0, 0, 0, 0);
+ }
+ $b1 = $this->eccTable[$version][$level][0];
+ $b2 = $this->eccTable[$version][$level][1];
+ $data = $this->getDataLength($version, $level);
+ $ecc = $this->getECCLength($version, $level);
+ if ($b2 == 0) {
+ $spec[0] = $b1;
+ $spec[1] = (int)($data / $b1);
+ $spec[2] = (int)($ecc / $b1);
+ $spec[3] = 0;
+ $spec[4] = 0;
+ } else {
+ $spec[0] = $b1;
+ $spec[1] = (int)($data / ($b1 + $b2));
+ $spec[2] = (int)($ecc / ($b1 + $b2));
+ $spec[3] = $b2;
+ $spec[4] = $spec[1] + 1;
+ }
+ return $spec;
+ }
+
+ /**
+ * Put an alignment marker.
+ * @param array $frame frame
+ * @param int $width width
+ * @param int $ox X center coordinate of the pattern
+ * @param int $oy Y center coordinate of the pattern
+ * @return array frame
+ */
+ protected function putAlignmentMarker($frame, $ox, $oy) {
+ $finder = array(
+ "\xa1\xa1\xa1\xa1\xa1",
+ "\xa1\xa0\xa0\xa0\xa1",
+ "\xa1\xa0\xa1\xa0\xa1",
+ "\xa1\xa0\xa0\xa0\xa1",
+ "\xa1\xa1\xa1\xa1\xa1"
+ );
+ $yStart = $oy - 2;
+ $xStart = $ox - 2;
+ for ($y=0; $y < 5; $y++) {
+ $frame = $this->qrstrset($frame, $xStart, $yStart+$y, $finder[$y]);
+ }
+ return $frame;
+ }
+
+ /**
+ * Put an alignment pattern.
+ * @param int $version version
+ * @param array $fram frame
+ * @param int $width width
+ * @return array frame
+ */
+ protected function putAlignmentPattern($version, $frame, $width) {
+ if ($version < 2) {
+ return $frame;
+ }
+ $d = $this->alignmentPattern[$version][1] - $this->alignmentPattern[$version][0];
+ if ($d < 0) {
+ $w = 2;
+ } else {
+ $w = (int)(($width - $this->alignmentPattern[$version][0]) / $d + 2);
+ }
+ if ($w * $w - 3 == 1) {
+ $x = $this->alignmentPattern[$version][0];
+ $y = $this->alignmentPattern[$version][0];
+ $frame = $this->putAlignmentMarker($frame, $x, $y);
+ return $frame;
+ }
+ $cx = $this->alignmentPattern[$version][0];
+ $wo = $w - 1;
+ for ($x=1; $x < $wo; ++$x) {
+ $frame = $this->putAlignmentMarker($frame, 6, $cx);
+ $frame = $this->putAlignmentMarker($frame, $cx, 6);
+ $cx += $d;
+ }
+ $cy = $this->alignmentPattern[$version][0];
+ for ($y=0; $y < $wo; ++$y) {
+ $cx = $this->alignmentPattern[$version][0];
+ for ($x=0; $x < $wo; ++$x) {
+ $frame = $this->putAlignmentMarker($frame, $cx, $cy);
+ $cx += $d;
+ }
+ $cy += $d;
+ }
+ return $frame;
+ }
+
+ /**
+ * Return BCH encoded version information pattern that is used for the symbol of version 7 or greater. Use lower 18 bits.
+ * @param int $version version
+ * @return BCH encoded version information pattern
+ */
+ protected function getVersionPattern($version) {
+ if (($version < 7) OR ($version > QRSPEC_VERSION_MAX)) {
+ return 0;
+ }
+ return $this->versionPattern[($version - 7)];
+ }
+
+ /**
+ * Return BCH encoded format information pattern.
+ * @param array $mask
+ * @param int $level error correction level
+ * @return BCH encoded format information pattern
+ */
+ protected function getFormatInfo($mask, $level) {
+ if (($mask < 0) OR ($mask > 7)) {
+ return 0;
+ }
+ if (($level < 0) OR ($level > 3)) {
+ return 0;
+ }
+ return $this->formatInfo[$level][$mask];
+ }
+
+ /**
+ * Put a finder pattern.
+ * @param array $frame frame
+ * @param int $width width
+ * @param int $ox X center coordinate of the pattern
+ * @param int $oy Y center coordinate of the pattern
+ * @return array frame
+ */
+ protected function putFinderPattern($frame, $ox, $oy) {
+ $finder = array(
+ "\xc1\xc1\xc1\xc1\xc1\xc1\xc1",
+ "\xc1\xc0\xc0\xc0\xc0\xc0\xc1",
+ "\xc1\xc0\xc1\xc1\xc1\xc0\xc1",
+ "\xc1\xc0\xc1\xc1\xc1\xc0\xc1",
+ "\xc1\xc0\xc1\xc1\xc1\xc0\xc1",
+ "\xc1\xc0\xc0\xc0\xc0\xc0\xc1",
+ "\xc1\xc1\xc1\xc1\xc1\xc1\xc1"
+ );
+ for ($y=0; $y < 7; $y++) {
+ $frame = $this->qrstrset($frame, $ox, ($oy + $y), $finder[$y]);
+ }
+ return $frame;
+ }
+
+ /**
+ * Return a copy of initialized frame.
+ * @param int $version version
+ * @return Array of unsigned char.
+ */
+ protected function createFrame($version) {
+ $width = $this->capacity[$version][QRCAP_WIDTH];
+ $frameLine = str_repeat ("\0", $width);
+ $frame = array_fill(0, $width, $frameLine);
+ // Finder pattern
+ $frame = $this->putFinderPattern($frame, 0, 0);
+ $frame = $this->putFinderPattern($frame, $width - 7, 0);
+ $frame = $this->putFinderPattern($frame, 0, $width - 7);
+ // Separator
+ $yOffset = $width - 7;
+ for ($y=0; $y < 7; ++$y) {
+ $frame[$y][7] = "\xc0";
+ $frame[$y][$width - 8] = "\xc0";
+ $frame[$yOffset][7] = "\xc0";
+ ++$yOffset;
+ }
+ $setPattern = str_repeat("\xc0", 8);
+ $frame = $this->qrstrset($frame, 0, 7, $setPattern);
+ $frame = $this->qrstrset($frame, $width-8, 7, $setPattern);
+ $frame = $this->qrstrset($frame, 0, $width - 8, $setPattern);
+ // Format info
+ $setPattern = str_repeat("\x84", 9);
+ $frame = $this->qrstrset($frame, 0, 8, $setPattern);
+ $frame = $this->qrstrset($frame, $width - 8, 8, $setPattern, 8);
+ $yOffset = $width - 8;
+ for ($y=0; $y < 8; ++$y,++$yOffset) {
+ $frame[$y][8] = "\x84";
+ $frame[$yOffset][8] = "\x84";
+ }
+ // Timing pattern
+ $wo = $width - 15;
+ for ($i=1; $i < $wo; ++$i) {
+ $frame[6][7+$i] = chr(0x90 | ($i & 1));
+ $frame[7+$i][6] = chr(0x90 | ($i & 1));
+ }
+ // Alignment pattern
+ $frame = $this->putAlignmentPattern($version, $frame, $width);
+ // Version information
+ if ($version >= 7) {
+ $vinf = $this->getVersionPattern($version);
+ $v = $vinf;
+ for ($x=0; $x<6; ++$x) {
+ for ($y=0; $y<3; ++$y) {
+ $frame[($width - 11)+$y][$x] = chr(0x88 | ($v & 1));
+ $v = $v >> 1;
+ }
+ }
+ $v = $vinf;
+ for ($y=0; $y<6; ++$y) {
+ for ($x=0; $x<3; ++$x) {
+ $frame[$y][$x+($width - 11)] = chr(0x88 | ($v & 1));
+ $v = $v >> 1;
+ }
+ }
+ }
+ // and a little bit...
+ $frame[$width - 8][8] = "\x81";
+ return $frame;
+ }
+
+ /**
+ * Set new frame for the specified version.
+ * @param int $version version
+ * @return Array of unsigned char.
+ */
+ protected function newFrame($version) {
+ if (($version < 1) OR ($version > QRSPEC_VERSION_MAX)) {
+ return NULL;
+ }
+ if (!isset($this->frames[$version])) {
+ $this->frames[$version] = $this->createFrame($version);
+ }
+ if (is_null($this->frames[$version])) {
+ return NULL;
+ }
+ return $this->frames[$version];
+ }
+
+ /**
+ * Return block number 0
+ * @param array $spec
+ * @return int value
+ */
+ protected function rsBlockNum($spec) {
+ return ($spec[0] + $spec[3]);
+ }
+
+ /**
+ * Return block number 1
+ * @param array $spec
+ * @return int value
+ */
+ protected function rsBlockNum1($spec) {
+ return $spec[0];
+ }
+
+ /**
+ * Return data codes 1
+ * @param array $spec
+ * @return int value
+ */
+ protected function rsDataCodes1($spec) {
+ return $spec[1];
+ }
+
+ /**
+ * Return ecc codes 1
+ * @param array $spec
+ * @return int value
+ */
+ protected function rsEccCodes1($spec) {
+ return $spec[2];
+ }
+
+ /**
+ * Return block number 2
+ * @param array $spec
+ * @return int value
+ */
+ protected function rsBlockNum2($spec) {
+ return $spec[3];
+ }
+
+ /**
+ * Return data codes 2
+ * @param array $spec
+ * @return int value
+ */
+ protected function rsDataCodes2($spec) {
+ return $spec[4];
+ }
+
+ /**
+ * Return ecc codes 2
+ * @param array $spec
+ * @return int value
+ */
+ protected function rsEccCodes2($spec) {
+ return $spec[2];
+ }
+
+ /**
+ * Return data length
+ * @param array $spec
+ * @return int value
+ */
+ protected function rsDataLength($spec) {
+ return ($spec[0] * $spec[1]) + ($spec[3] * $spec[4]);
+ }
+
+ /**
+ * Return ecc length
+ * @param array $spec
+ * @return int value
+ */
+ protected function rsEccLength($spec) {
+ return ($spec[0] + $spec[3]) * $spec[2];
+ }
+
+ // - - - - - - - - - - - - - - - - - - - - - - - - -
+
+ // QRrs
+
+ /**
+ * Initialize a Reed-Solomon codec and add it to existing rsitems
+ * @param int $symsize symbol size, bits
+ * @param int $gfpoly Field generator polynomial coefficients
+ * @param int $fcr first root of RS code generator polynomial, index form
+ * @param int $prim primitive element to generate polynomial roots
+ * @param int $nroots RS code generator polynomial degree (number of roots)
+ * @param int $pad padding bytes at front of shortened block
+ * @return array Array of RS values:<ul><li>mm = Bits per symbol;</li><li>nn = Symbols per block;</li><li>alpha_to = log lookup table array;</li><li>index_of = Antilog lookup table array;</li><li>genpoly = Generator polynomial array;</li><li>nroots = Number of generator;</li><li>roots = number of parity symbols;</li><li>fcr = First consecutive root, index form;</li><li>prim = Primitive element, index form;</li><li>iprim = prim-th root of 1, index form;</li><li>pad = Padding bytes in shortened block;</li><li>gfpoly</ul>.
+ */
+ protected function init_rs($symsize, $gfpoly, $fcr, $prim, $nroots, $pad) {
+ foreach ($this->rsitems as $rs) {
+ if (($rs['pad'] != $pad) OR ($rs['nroots'] != $nroots) OR ($rs['mm'] != $symsize)
+ OR ($rs['gfpoly'] != $gfpoly) OR ($rs['fcr'] != $fcr) OR ($rs['prim'] != $prim)) {
+ continue;
+ }
+ return $rs;
+ }
+ $rs = $this->init_rs_char($symsize, $gfpoly, $fcr, $prim, $nroots, $pad);
+ array_unshift($this->rsitems, $rs);
+ return $rs;
+ }
+
+ // - - - - - - - - - - - - - - - - - - - - - - - - -
+
+ // QRrsItem
+
+ /**
+ * modnn
+ * @param array RS values
+ * @param int $x X position
+ * @return int X osition
+ */
+ protected function modnn($rs, $x) {
+ while ($x >= $rs['nn']) {
+ $x -= $rs['nn'];
+ $x = ($x >> $rs['mm']) + ($x & $rs['nn']);
+ }
+ return $x;
+ }
+
+ /**
+ * Initialize a Reed-Solomon codec and returns an array of values.
+ * @param int $symsize symbol size, bits
+ * @param int $gfpoly Field generator polynomial coefficients
+ * @param int $fcr first root of RS code generator polynomial, index form
+ * @param int $prim primitive element to generate polynomial roots
+ * @param int $nroots RS code generator polynomial degree (number of roots)
+ * @param int $pad padding bytes at front of shortened block
+ * @return array Array of RS values:<ul><li>mm = Bits per symbol;</li><li>nn = Symbols per block;</li><li>alpha_to = log lookup table array;</li><li>index_of = Antilog lookup table array;</li><li>genpoly = Generator polynomial array;</li><li>nroots = Number of generator;</li><li>roots = number of parity symbols;</li><li>fcr = First consecutive root, index form;</li><li>prim = Primitive element, index form;</li><li>iprim = prim-th root of 1, index form;</li><li>pad = Padding bytes in shortened block;</li><li>gfpoly</ul>.
+ */
+ protected function init_rs_char($symsize, $gfpoly, $fcr, $prim, $nroots, $pad) {
+ // Based on Reed solomon encoder by Phil Karn, KA9Q (GNU-LGPLv2)
+ $rs = null;
+ // Check parameter ranges
+ if (($symsize < 0) OR ($symsize > 8)) {
+ return $rs;
+ }
+ if (($fcr < 0) OR ($fcr >= (1<<$symsize))) {
+ return $rs;
+ }
+ if (($prim <= 0) OR ($prim >= (1<<$symsize))) {
+ return $rs;
+ }
+ if (($nroots < 0) OR ($nroots >= (1<<$symsize))) {
+ return $rs;
+ }
+ if (($pad < 0) OR ($pad >= ((1<<$symsize) -1 - $nroots))) {
+ return $rs;
+ }
+ $rs = array();
+ $rs['mm'] = $symsize;
+ $rs['nn'] = (1 << $symsize) - 1;
+ $rs['pad'] = $pad;
+ $rs['alpha_to'] = array_fill(0, ($rs['nn'] + 1), 0);
+ $rs['index_of'] = array_fill(0, ($rs['nn'] + 1), 0);
+ // PHP style macro replacement ;)
+ $NN =& $rs['nn'];
+ $A0 =& $NN;
+ // Generate Galois field lookup tables
+ $rs['index_of'][0] = $A0; // log(zero) = -inf
+ $rs['alpha_to'][$A0] = 0; // alpha**-inf = 0
+ $sr = 1;
+ for ($i=0; $i<$rs['nn']; ++$i) {
+ $rs['index_of'][$sr] = $i;
+ $rs['alpha_to'][$i] = $sr;
+ $sr <<= 1;
+ if ($sr & (1 << $symsize)) {
+ $sr ^= $gfpoly;
+ }
+ $sr &= $rs['nn'];
+ }
+ if ($sr != 1) {
+ // field generator polynomial is not primitive!
+ return NULL;
+ }
+ // Form RS code generator polynomial from its roots
+ $rs['genpoly'] = array_fill(0, ($nroots + 1), 0);
+ $rs['fcr'] = $fcr;
+ $rs['prim'] = $prim;
+ $rs['nroots'] = $nroots;
+ $rs['gfpoly'] = $gfpoly;
+ // Find prim-th root of 1, used in decoding
+ for ($iprim=1; ($iprim % $prim) != 0; $iprim += $rs['nn']) {
+ ; // intentional empty-body loop!
+ }
+ $rs['iprim'] = (int)($iprim / $prim);
+ $rs['genpoly'][0] = 1;
+
+
+ for ($i = 0,$root=$fcr*$prim; $i < $nroots; $i++, $root += $prim) {
+ $rs['genpoly'][$i+1] = 1;
+ // Multiply rs->genpoly[] by @**(root + x)
+ for ($j = $i; $j > 0; --$j) {
+ if ($rs['genpoly'][$j] != 0) {
+ $rs['genpoly'][$j] = $rs['genpoly'][$j-1] ^ $rs['alpha_to'][$this->modnn($rs, $rs['index_of'][$rs['genpoly'][$j]] + $root)];
+ } else {
+ $rs['genpoly'][$j] = $rs['genpoly'][$j-1];
+ }
+ }
+ // rs->genpoly[0] can never be zero
+ $rs['genpoly'][0] = $rs['alpha_to'][$this->modnn($rs, $rs['index_of'][$rs['genpoly'][0]] + $root)];
+ }
+ // convert rs->genpoly[] to index form for quicker encoding
+ for ($i = 0; $i <= $nroots; ++$i) {
+ $rs['genpoly'][$i] = $rs['index_of'][$rs['genpoly'][$i]];
+ }
+ return $rs;
+ }
+
+ /**
+ * Encode a Reed-Solomon codec and returns the parity array
+ * @param array $rs RS values
+ * @param array $data data
+ * @param array $parity parity
+ * @return parity array
+ */
+ protected function encode_rs_char($rs, $data, $parity) {
+ $MM =& $rs['mm']; // bits per symbol
+ $NN =& $rs['nn']; // the total number of symbols in a RS block
+ $ALPHA_TO =& $rs['alpha_to']; // the address of an array of NN elements to convert Galois field elements in index (log) form to polynomial form
+ $INDEX_OF =& $rs['index_of']; // the address of an array of NN elements to convert Galois field elements in polynomial form to index (log) form
+ $GENPOLY =& $rs['genpoly']; // an array of NROOTS+1 elements containing the generator polynomial in index form
+ $NROOTS =& $rs['nroots']; // the number of roots in the RS code generator polynomial, which is the same as the number of parity symbols in a block
+ $FCR =& $rs['fcr']; // first consecutive root, index form
+ $PRIM =& $rs['prim']; // primitive element, index form
+ $IPRIM =& $rs['iprim']; // prim-th root of 1, index form
+ $PAD =& $rs['pad']; // the number of pad symbols in a block
+ $A0 =& $NN;
+ $parity = array_fill(0, $NROOTS, 0);
+ for ($i=0; $i < ($NN - $NROOTS - $PAD); $i++) {
+ $feedback = $INDEX_OF[$data[$i] ^ $parity[0]];
+ if ($feedback != $A0) {
+ // feedback term is non-zero
+ // This line is unnecessary when GENPOLY[NROOTS] is unity, as it must
+ // always be for the polynomials constructed by init_rs()
+ $feedback = $this->modnn($rs, $NN - $GENPOLY[$NROOTS] + $feedback);
+ for ($j=1; $j < $NROOTS; ++$j) {
+ $parity[$j] ^= $ALPHA_TO[$this->modnn($rs, $feedback + $GENPOLY[($NROOTS - $j)])];
+ }
+ }
+ // Shift
+ array_shift($parity);
+ if ($feedback != $A0) {
+ array_push($parity, $ALPHA_TO[$this->modnn($rs, $feedback + $GENPOLY[0])]);
+ } else {
+ array_push($parity, 0);
+ }
+ }
+ return $parity;
+ }
+
+ } // end QRcode class
+
+} // END OF "class_exists QRcode"
+?>
diff --git a/pdf/phpqrcode/phpqrcode.php b/pdf/phpqrcode/phpqrcode.php
new file mode 100755
index 0000000..80adb9d
--- /dev/null
+++ b/pdf/phpqrcode/phpqrcode.php
@@ -0,0 +1,3312 @@
+<?php
+
+/*
+ * PHP QR Code encoder
+ *
+ * This file contains MERGED version of PHP QR Code library.
+ * It was auto-generated from full version for your convenience.
+ *
+ * This merged version was configured to not requre any external files,
+ * with disabled cache, error loging and weker but faster mask matching.
+ * If you need tune it up please use non-merged version.
+ *
+ * For full version, documentation, examples of use please visit:
+ *
+ * http://phpqrcode.sourceforge.net/
+ * https://sourceforge.net/projects/phpqrcode/
+ *
+ * PHP QR Code is distributed under LGPL 3
+ * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+
+
+/*
+ * Version: 1.1.4
+ * Build: 2010100721
+ */
+
+
+
+//---- qrconst.php -----------------------------
+
+
+
+
+
+/*
+ * PHP QR Code encoder
+ *
+ * Common constants
+ *
+ * Based on libqrencode C library distributed under LGPL 2.1
+ * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net>
+ *
+ * PHP QR Code is distributed under LGPL 3
+ * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+ // Encoding modes
+
+ define('QR_MODE_NUL', -1);
+ define('QR_MODE_NUM', 0);
+ define('QR_MODE_AN', 1);
+ define('QR_MODE_8', 2);
+ define('QR_MODE_KANJI', 3);
+ define('QR_MODE_STRUCTURE', 4);
+
+ // Levels of error correction.
+
+ define('QR_ECLEVEL_L', 0);
+ define('QR_ECLEVEL_M', 1);
+ define('QR_ECLEVEL_Q', 2);
+ define('QR_ECLEVEL_H', 3);
+
+ // Supported output formats
+
+ define('QR_FORMAT_TEXT', 0);
+ define('QR_FORMAT_PNG', 1);
+
+ class qrstr {
+ public static function set(&$srctab, $x, $y, $repl, $replLen = false) {
+ $srctab[$y] = substr_replace($srctab[$y], ($replLen !== false)?substr($repl,0,$replLen):$repl, $x, ($replLen !== false)?$replLen:strlen($repl));
+ }
+ }
+
+
+
+//---- merged_config.php -----------------------------
+
+
+
+
+/*
+ * PHP QR Code encoder
+ *
+ * Config file, tuned-up for merged verion
+ */
+
+ define('QR_CACHEABLE', false); // use cache - more disk reads but less CPU power, masks and format templates are stored there
+ define('QR_CACHE_DIR', false); // used when QR_CACHEABLE === true
+ define('QR_LOG_DIR', false); // default error logs dir
+
+ define('QR_FIND_BEST_MASK', true); // if true, estimates best mask (spec. default, but extremally slow; set to false to significant performance boost but (propably) worst quality code
+ define('QR_FIND_FROM_RANDOM', 2); // if false, checks all masks available, otherwise value tells count of masks need to be checked, mask id are got randomly
+ define('QR_DEFAULT_MASK', 2); // when QR_FIND_BEST_MASK === false
+
+ define('QR_PNG_MAXIMUM_SIZE', 1024); // maximum allowed png image width (in pixels), tune to make sure GD and PHP can handle such big images
+
+
+
+
+//---- qrtools.php -----------------------------
+
+
+
+
+/*
+ * PHP QR Code encoder
+ *
+ * Toolset, handy and debug utilites.
+ *
+ * PHP QR Code is distributed under LGPL 3
+ * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+ class QRtools {
+
+ //----------------------------------------------------------------------
+ public static function binarize($frame)
+ {
+ $len = count($frame);
+ foreach ($frame as &$frameLine) {
+
+ for($i=0; $i<$len; $i++) {
+ $frameLine[$i] = (ord($frameLine[$i])&1)?'1':'0';
+ }
+ }
+
+ return $frame;
+ }
+
+ //----------------------------------------------------------------------
+ public static function tcpdfBarcodeArray($code, $mode = 'QR,L', $tcPdfVersion = '4.5.037')
+ {
+ $barcode_array = array();
+
+ if (!is_array($mode))
+ $mode = explode(',', $mode);
+
+ $eccLevel = 'L';
+
+ if (count($mode) > 1) {
+ $eccLevel = $mode[1];
+ }
+
+ $qrTab = QRcode::text($code, false, $eccLevel);
+ $size = count($qrTab);
+
+ $barcode_array['num_rows'] = $size;
+ $barcode_array['num_cols'] = $size;
+ $barcode_array['bcode'] = array();
+
+ foreach ($qrTab as $line) {
+ $arrAdd = array();
+ foreach(str_split($line) as $char)
+ $arrAdd[] = ($char=='1')?1:0;
+ $barcode_array['bcode'][] = $arrAdd;
+ }
+
+ return $barcode_array;
+ }
+
+ //----------------------------------------------------------------------
+ public static function clearCache()
+ {
+ self::$frames = array();
+ }
+
+ //----------------------------------------------------------------------
+ public static function buildCache()
+ {
+ QRtools::markTime('before_build_cache');
+
+ $mask = new QRmask();
+ for ($a=1; $a <= QRSPEC_VERSION_MAX; $a++) {
+ $frame = QRspec::newFrame($a);
+ if (QR_IMAGE) {
+ $fileName = QR_CACHE_DIR.'frame_'.$a.'.png';
+ QRimage::png(self::binarize($frame), $fileName, 1, 0);
+ }
+
+ $width = count($frame);
+ $bitMask = array_fill(0, $width, array_fill(0, $width, 0));
+ for ($maskNo=0; $maskNo<8; $maskNo++)
+ $mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true);
+ }
+
+ QRtools::markTime('after_build_cache');
+ }
+
+ //----------------------------------------------------------------------
+ public static function log($outfile, $err)
+ {
+ if (QR_LOG_DIR !== false) {
+ if ($err != '') {
+ if ($outfile !== false) {
+ file_put_contents(QR_LOG_DIR.basename($outfile).'-errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND);
+ } else {
+ file_put_contents(QR_LOG_DIR.'errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND);
+ }
+ }
+ }
+ }
+
+ //----------------------------------------------------------------------
+ public static function dumpMask($frame)
+ {
+ $width = count($frame);
+ for($y=0;$y<$width;$y++) {
+ for($x=0;$x<$width;$x++) {
+ echo ord($frame[$y][$x]).',';
+ }
+ }
+ }
+
+ //----------------------------------------------------------------------
+ public static function markTime($markerId)
+ {
+ list($usec, $sec) = explode(" ", microtime());
+ $time = ((float)$usec + (float)$sec);
+
+ if (!isset($GLOBALS['qr_time_bench']))
+ $GLOBALS['qr_time_bench'] = array();
+
+ $GLOBALS['qr_time_bench'][$markerId] = $time;
+ }
+
+ //----------------------------------------------------------------------
+ public static function timeBenchmark()
+ {
+ self::markTime('finish');
+
+ $lastTime = 0;
+ $startTime = 0;
+ $p = 0;
+
+ echo '<table cellpadding="3" cellspacing="1">
+ <thead><tr style="border-bottom:1px solid silver"><td colspan="2" style="text-align:center">BENCHMARK</td></tr></thead>
+ <tbody>';
+
+ foreach($GLOBALS['qr_time_bench'] as $markerId=>$thisTime) {
+ if ($p > 0) {
+ echo '<tr><th style="text-align:right">till '.$markerId.': </th><td>'.number_format($thisTime-$lastTime, 6).'s</td></tr>';
+ } else {
+ $startTime = $thisTime;
+ }
+
+ $p++;
+ $lastTime = $thisTime;
+ }
+
+ echo '</tbody><tfoot>
+ <tr style="border-top:2px solid black"><th style="text-align:right">TOTAL: </th><td>'.number_format($lastTime-$startTime, 6).'s</td></tr>
+ </tfoot>
+ </table>';
+ }
+
+ }
+
+ //##########################################################################
+
+ QRtools::markTime('start');
+
+
+
+
+//---- qrspec.php -----------------------------
+
+
+
+
+/*
+ * PHP QR Code encoder
+ *
+ * QR Code specifications
+ *
+ * Based on libqrencode C library distributed under LGPL 2.1
+ * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net>
+ *
+ * PHP QR Code is distributed under LGPL 3
+ * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
+ *
+ * The following data / specifications are taken from
+ * "Two dimensional symbol -- QR-code -- Basic Specification" (JIS X0510:2004)
+ * or
+ * "Automatic identification and data capture techniques --
+ * QR Code 2005 bar code symbology specification" (ISO/IEC 18004:2006)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+ define('QRSPEC_VERSION_MAX', 40);
+ define('QRSPEC_WIDTH_MAX', 177);
+
+ define('QRCAP_WIDTH', 0);
+ define('QRCAP_WORDS', 1);
+ define('QRCAP_REMINDER', 2);
+ define('QRCAP_EC', 3);
+
+ class QRspec {
+
+ public static $capacity = array(
+ array( 0, 0, 0, array( 0, 0, 0, 0)),
+ array( 21, 26, 0, array( 7, 10, 13, 17)), // 1
+ array( 25, 44, 7, array( 10, 16, 22, 28)),
+ array( 29, 70, 7, array( 15, 26, 36, 44)),
+ array( 33, 100, 7, array( 20, 36, 52, 64)),
+ array( 37, 134, 7, array( 26, 48, 72, 88)), // 5
+ array( 41, 172, 7, array( 36, 64, 96, 112)),
+ array( 45, 196, 0, array( 40, 72, 108, 130)),
+ array( 49, 242, 0, array( 48, 88, 132, 156)),
+ array( 53, 292, 0, array( 60, 110, 160, 192)),
+ array( 57, 346, 0, array( 72, 130, 192, 224)), //10
+ array( 61, 404, 0, array( 80, 150, 224, 264)),
+ array( 65, 466, 0, array( 96, 176, 260, 308)),
+ array( 69, 532, 0, array( 104, 198, 288, 352)),
+ array( 73, 581, 3, array( 120, 216, 320, 384)),
+ array( 77, 655, 3, array( 132, 240, 360, 432)), //15
+ array( 81, 733, 3, array( 144, 280, 408, 480)),
+ array( 85, 815, 3, array( 168, 308, 448, 532)),
+ array( 89, 901, 3, array( 180, 338, 504, 588)),
+ array( 93, 991, 3, array( 196, 364, 546, 650)),
+ array( 97, 1085, 3, array( 224, 416, 600, 700)), //20
+ array(101, 1156, 4, array( 224, 442, 644, 750)),
+ array(105, 1258, 4, array( 252, 476, 690, 816)),
+ array(109, 1364, 4, array( 270, 504, 750, 900)),
+ array(113, 1474, 4, array( 300, 560, 810, 960)),
+ array(117, 1588, 4, array( 312, 588, 870, 1050)), //25
+ array(121, 1706, 4, array( 336, 644, 952, 1110)),
+ array(125, 1828, 4, array( 360, 700, 1020, 1200)),
+ array(129, 1921, 3, array( 390, 728, 1050, 1260)),
+ array(133, 2051, 3, array( 420, 784, 1140, 1350)),
+ array(137, 2185, 3, array( 450, 812, 1200, 1440)), //30
+ array(141, 2323, 3, array( 480, 868, 1290, 1530)),
+ array(145, 2465, 3, array( 510, 924, 1350, 1620)),
+ array(149, 2611, 3, array( 540, 980, 1440, 1710)),
+ array(153, 2761, 3, array( 570, 1036, 1530, 1800)),
+ array(157, 2876, 0, array( 570, 1064, 1590, 1890)), //35
+ array(161, 3034, 0, array( 600, 1120, 1680, 1980)),
+ array(165, 3196, 0, array( 630, 1204, 1770, 2100)),
+ array(169, 3362, 0, array( 660, 1260, 1860, 2220)),
+ array(173, 3532, 0, array( 720, 1316, 1950, 2310)),
+ array(177, 3706, 0, array( 750, 1372, 2040, 2430)) //40
+ );
+
+ //----------------------------------------------------------------------
+ public static function getDataLength($version, $level)
+ {
+ return self::$capacity[$version][QRCAP_WORDS] - self::$capacity[$version][QRCAP_EC][$level];
+ }
+
+ //----------------------------------------------------------------------
+ public static function getECCLength($version, $level)
+ {
+ return self::$capacity[$version][QRCAP_EC][$level];
+ }
+
+ //----------------------------------------------------------------------
+ public static function getWidth($version)
+ {
+ return self::$capacity[$version][QRCAP_WIDTH];
+ }
+
+ //----------------------------------------------------------------------
+ public static function getRemainder($version)
+ {
+ return self::$capacity[$version][QRCAP_REMINDER];
+ }
+
+ //----------------------------------------------------------------------
+ public static function getMinimumVersion($size, $level)
+ {
+
+ for($i=1; $i<= QRSPEC_VERSION_MAX; $i++) {
+ $words = self::$capacity[$i][QRCAP_WORDS] - self::$capacity[$i][QRCAP_EC][$level];
+ if($words >= $size)
+ return $i;
+ }
+
+ return -1;
+ }
+
+ //######################################################################
+
+ public static $lengthTableBits = array(
+ array(10, 12, 14),
+ array( 9, 11, 13),
+ array( 8, 16, 16),
+ array( 8, 10, 12)
+ );
+
+ //----------------------------------------------------------------------
+ public static function lengthIndicator($mode, $version)
+ {
+ if ($mode == QR_MODE_STRUCTURE)
+ return 0;
+
+ if ($version <= 9) {
+ $l = 0;
+ } else if ($version <= 26) {
+ $l = 1;
+ } else {
+ $l = 2;
+ }
+
+ return self::$lengthTableBits[$mode][$l];
+ }
+
+ //----------------------------------------------------------------------
+ public static function maximumWords($mode, $version)
+ {
+ if($mode == QR_MODE_STRUCTURE)
+ return 3;
+
+ if($version <= 9) {
+ $l = 0;
+ } else if($version <= 26) {
+ $l = 1;
+ } else {
+ $l = 2;
+ }
+
+ $bits = self::$lengthTableBits[$mode][$l];
+ $words = (1 << $bits) - 1;
+
+ if($mode == QR_MODE_KANJI) {
+ $words *= 2; // the number of bytes is required
+ }
+
+ return $words;
+ }
+
+ // Error correction code -----------------------------------------------
+ // Table of the error correction code (Reed-Solomon block)
+ // See Table 12-16 (pp.30-36), JIS X0510:2004.
+
+ public static $eccTable = array(
+ array(array( 0, 0), array( 0, 0), array( 0, 0), array( 0, 0)),
+ array(array( 1, 0), array( 1, 0), array( 1, 0), array( 1, 0)), // 1
+ array(array( 1, 0), array( 1, 0), array( 1, 0), array( 1, 0)),
+ array(array( 1, 0), array( 1, 0), array( 2, 0), array( 2, 0)),
+ array(array( 1, 0), array( 2, 0), array( 2, 0), array( 4, 0)),
+ array(array( 1, 0), array( 2, 0), array( 2, 2), array( 2, 2)), // 5
+ array(array( 2, 0), array( 4, 0), array( 4, 0), array( 4, 0)),
+ array(array( 2, 0), array( 4, 0), array( 2, 4), array( 4, 1)),
+ array(array( 2, 0), array( 2, 2), array( 4, 2), array( 4, 2)),
+ array(array( 2, 0), array( 3, 2), array( 4, 4), array( 4, 4)),
+ array(array( 2, 2), array( 4, 1), array( 6, 2), array( 6, 2)), //10
+ array(array( 4, 0), array( 1, 4), array( 4, 4), array( 3, 8)),
+ array(array( 2, 2), array( 6, 2), array( 4, 6), array( 7, 4)),
+ array(array( 4, 0), array( 8, 1), array( 8, 4), array(12, 4)),
+ array(array( 3, 1), array( 4, 5), array(11, 5), array(11, 5)),
+ array(array( 5, 1), array( 5, 5), array( 5, 7), array(11, 7)), //15
+ array(array( 5, 1), array( 7, 3), array(15, 2), array( 3, 13)),
+ array(array( 1, 5), array(10, 1), array( 1, 15), array( 2, 17)),
+ array(array( 5, 1), array( 9, 4), array(17, 1), array( 2, 19)),
+ array(array( 3, 4), array( 3, 11), array(17, 4), array( 9, 16)),
+ array(array( 3, 5), array( 3, 13), array(15, 5), array(15, 10)), //20
+ array(array( 4, 4), array(17, 0), array(17, 6), array(19, 6)),
+ array(array( 2, 7), array(17, 0), array( 7, 16), array(34, 0)),
+ array(array( 4, 5), array( 4, 14), array(11, 14), array(16, 14)),
+ array(array( 6, 4), array( 6, 14), array(11, 16), array(30, 2)),
+ array(array( 8, 4), array( 8, 13), array( 7, 22), array(22, 13)), //25
+ array(array(10, 2), array(19, 4), array(28, 6), array(33, 4)),
+ array(array( 8, 4), array(22, 3), array( 8, 26), array(12, 28)),
+ array(array( 3, 10), array( 3, 23), array( 4, 31), array(11, 31)),
+ array(array( 7, 7), array(21, 7), array( 1, 37), array(19, 26)),
+ array(array( 5, 10), array(19, 10), array(15, 25), array(23, 25)), //30
+ array(array(13, 3), array( 2, 29), array(42, 1), array(23, 28)),
+ array(array(17, 0), array(10, 23), array(10, 35), array(19, 35)),
+ array(array(17, 1), array(14, 21), array(29, 19), array(11, 46)),
+ array(array(13, 6), array(14, 23), array(44, 7), array(59, 1)),
+ array(array(12, 7), array(12, 26), array(39, 14), array(22, 41)), //35
+ array(array( 6, 14), array( 6, 34), array(46, 10), array( 2, 64)),
+ array(array(17, 4), array(29, 14), array(49, 10), array(24, 46)),
+ array(array( 4, 18), array(13, 32), array(48, 14), array(42, 32)),
+ array(array(20, 4), array(40, 7), array(43, 22), array(10, 67)),
+ array(array(19, 6), array(18, 31), array(34, 34), array(20, 61)),//40
+ );
+
+ //----------------------------------------------------------------------
+ // CACHEABLE!!!
+
+ public static function getEccSpec($version, $level, array &$spec)
+ {
+ if (count($spec) < 5) {
+ $spec = array(0,0,0,0,0);
+ }
+
+ $b1 = self::$eccTable[$version][$level][0];
+ $b2 = self::$eccTable[$version][$level][1];
+ $data = self::getDataLength($version, $level);
+ $ecc = self::getECCLength($version, $level);
+
+ if($b2 == 0) {
+ $spec[0] = $b1;
+ $spec[1] = (int)($data / $b1);
+ $spec[2] = (int)($ecc / $b1);
+ $spec[3] = 0;
+ $spec[4] = 0;
+ } else {
+ $spec[0] = $b1;
+ $spec[1] = (int)($data / ($b1 + $b2));
+ $spec[2] = (int)($ecc / ($b1 + $b2));
+ $spec[3] = $b2;
+ $spec[4] = $spec[1] + 1;
+ }
+ }
+
+ // Alignment pattern ---------------------------------------------------
+
+ // Positions of alignment patterns.
+ // This array includes only the second and the third position of the
+ // alignment patterns. Rest of them can be calculated from the distance
+ // between them.
+
+ // See Table 1 in Appendix E (pp.71) of JIS X0510:2004.
+
+ public static $alignmentPattern = array(
+ array( 0, 0),
+ array( 0, 0), array(18, 0), array(22, 0), array(26, 0), array(30, 0), // 1- 5
+ array(34, 0), array(22, 38), array(24, 42), array(26, 46), array(28, 50), // 6-10
+ array(30, 54), array(32, 58), array(34, 62), array(26, 46), array(26, 48), //11-15
+ array(26, 50), array(30, 54), array(30, 56), array(30, 58), array(34, 62), //16-20
+ array(28, 50), array(26, 50), array(30, 54), array(28, 54), array(32, 58), //21-25
+ array(30, 58), array(34, 62), array(26, 50), array(30, 54), array(26, 52), //26-30
+ array(30, 56), array(34, 60), array(30, 58), array(34, 62), array(30, 54), //31-35
+ array(24, 50), array(28, 54), array(32, 58), array(26, 54), array(30, 58), //35-40
+ );
+
+
+ /** --------------------------------------------------------------------
+ * Put an alignment marker.
+ * @param frame
+ * @param width
+ * @param ox,oy center coordinate of the pattern
+ */
+ public static function putAlignmentMarker(array &$frame, $ox, $oy)
+ {
+ $finder = array(
+ "\xa1\xa1\xa1\xa1\xa1",
+ "\xa1\xa0\xa0\xa0\xa1",
+ "\xa1\xa0\xa1\xa0\xa1",
+ "\xa1\xa0\xa0\xa0\xa1",
+ "\xa1\xa1\xa1\xa1\xa1"
+ );
+
+ $yStart = $oy-2;
+ $xStart = $ox-2;
+
+ for($y=0; $y<5; $y++) {
+ QRstr::set($frame, $xStart, $yStart+$y, $finder[$y]);
+ }
+ }
+
+ //----------------------------------------------------------------------
+ public static function putAlignmentPattern($version, &$frame, $width)
+ {
+ if($version < 2)
+ return;
+
+ $d = self::$alignmentPattern[$version][1] - self::$alignmentPattern[$version][0];
+ if($d < 0) {
+ $w = 2;
+ } else {
+ $w = (int)(($width - self::$alignmentPattern[$version][0]) / $d + 2);
+ }
+
+ if($w * $w - 3 == 1) {
+ $x = self::$alignmentPattern[$version][0];
+ $y = self::$alignmentPattern[$version][0];
+ self::putAlignmentMarker($frame, $x, $y);
+ return;
+ }
+
+ $cx = self::$alignmentPattern[$version][0];
+ for($x=1; $x<$w - 1; $x++) {
+ self::putAlignmentMarker($frame, 6, $cx);
+ self::putAlignmentMarker($frame, $cx, 6);
+ $cx += $d;
+ }
+
+ $cy = self::$alignmentPattern[$version][0];
+ for($y=0; $y<$w-1; $y++) {
+ $cx = self::$alignmentPattern[$version][0];
+ for($x=0; $x<$w-1; $x++) {
+ self::putAlignmentMarker($frame, $cx, $cy);
+ $cx += $d;
+ }
+ $cy += $d;
+ }
+ }
+
+ // Version information pattern -----------------------------------------
+
+ // Version information pattern (BCH coded).
+ // See Table 1 in Appendix D (pp.68) of JIS X0510:2004.
+
+ // size: [QRSPEC_VERSION_MAX - 6]
+
+ public static $versionPattern = array(
+ 0x07c94, 0x085bc, 0x09a99, 0x0a4d3, 0x0bbf6, 0x0c762, 0x0d847, 0x0e60d,
+ 0x0f928, 0x10b78, 0x1145d, 0x12a17, 0x13532, 0x149a6, 0x15683, 0x168c9,
+ 0x177ec, 0x18ec4, 0x191e1, 0x1afab, 0x1b08e, 0x1cc1a, 0x1d33f, 0x1ed75,
+ 0x1f250, 0x209d5, 0x216f0, 0x228ba, 0x2379f, 0x24b0b, 0x2542e, 0x26a64,
+ 0x27541, 0x28c69
+ );
+
+ //----------------------------------------------------------------------
+ public static function getVersionPattern($version)
+ {
+ if($version < 7 || $version > QRSPEC_VERSION_MAX)
+ return 0;
+
+ return self::$versionPattern[$version -7];
+ }
+
+ // Format information --------------------------------------------------
+ // See calcFormatInfo in tests/test_qrspec.c (orginal qrencode c lib)
+
+ public static $formatInfo = array(
+ array(0x77c4, 0x72f3, 0x7daa, 0x789d, 0x662f, 0x6318, 0x6c41, 0x6976),
+ array(0x5412, 0x5125, 0x5e7c, 0x5b4b, 0x45f9, 0x40ce, 0x4f97, 0x4aa0),
+ array(0x355f, 0x3068, 0x3f31, 0x3a06, 0x24b4, 0x2183, 0x2eda, 0x2bed),
+ array(0x1689, 0x13be, 0x1ce7, 0x19d0, 0x0762, 0x0255, 0x0d0c, 0x083b)
+ );
+
+ public static function getFormatInfo($mask, $level)
+ {
+ if($mask < 0 || $mask > 7)
+ return 0;
+
+ if($level < 0 || $level > 3)
+ return 0;
+
+ return self::$formatInfo[$level][$mask];
+ }
+
+ // Frame ---------------------------------------------------------------
+ // Cache of initial frames.
+
+ public static $frames = array();
+
+ /** --------------------------------------------------------------------
+ * Put a finder pattern.
+ * @param frame
+ * @param width
+ * @param ox,oy upper-left coordinate of the pattern
+ */
+ public static function putFinderPattern(&$frame, $ox, $oy)
+ {
+ $finder = array(
+ "\xc1\xc1\xc1\xc1\xc1\xc1\xc1",
+ "\xc1\xc0\xc0\xc0\xc0\xc0\xc1",
+ "\xc1\xc0\xc1\xc1\xc1\xc0\xc1",
+ "\xc1\xc0\xc1\xc1\xc1\xc0\xc1",
+ "\xc1\xc0\xc1\xc1\xc1\xc0\xc1",
+ "\xc1\xc0\xc0\xc0\xc0\xc0\xc1",
+ "\xc1\xc1\xc1\xc1\xc1\xc1\xc1"
+ );
+
+ for($y=0; $y<7; $y++) {
+ QRstr::set($frame, $ox, $oy+$y, $finder[$y]);
+ }
+ }
+
+ //----------------------------------------------------------------------
+ public static function createFrame($version)
+ {
+ $width = self::$capacity[$version][QRCAP_WIDTH];
+ $frameLine = str_repeat ("\0", $width);
+ $frame = array_fill(0, $width, $frameLine);
+
+ // Finder pattern
+ self::putFinderPattern($frame, 0, 0);
+ self::putFinderPattern($frame, $width - 7, 0);
+ self::putFinderPattern($frame, 0, $width - 7);
+
+ // Separator
+ $yOffset = $width - 7;
+
+ for($y=0; $y<7; $y++) {
+ $frame[$y][7] = "\xc0";
+ $frame[$y][$width - 8] = "\xc0";
+ $frame[$yOffset][7] = "\xc0";
+ $yOffset++;
+ }
+
+ $setPattern = str_repeat("\xc0", 8);
+
+ QRstr::set($frame, 0, 7, $setPattern);
+ QRstr::set($frame, $width-8, 7, $setPattern);
+ QRstr::set($frame, 0, $width - 8, $setPattern);
+
+ // Format info
+ $setPattern = str_repeat("\x84", 9);
+ QRstr::set($frame, 0, 8, $setPattern);
+ QRstr::set($frame, $width - 8, 8, $setPattern, 8);
+
+ $yOffset = $width - 8;
+
+ for($y=0; $y<8; $y++,$yOffset++) {
+ $frame[$y][8] = "\x84";
+ $frame[$yOffset][8] = "\x84";
+ }
+
+ // Timing pattern
+
+ for($i=1; $i<$width-15; $i++) {
+ $frame[6][7+$i] = chr(0x90 | ($i & 1));
+ $frame[7+$i][6] = chr(0x90 | ($i & 1));
+ }
+
+ // Alignment pattern
+ self::putAlignmentPattern($version, $frame, $width);
+
+ // Version information
+ if($version >= 7) {
+ $vinf = self::getVersionPattern($version);
+
+ $v = $vinf;
+
+ for($x=0; $x<6; $x++) {
+ for($y=0; $y<3; $y++) {
+ $frame[($width - 11)+$y][$x] = chr(0x88 | ($v & 1));
+ $v = $v >> 1;
+ }
+ }
+
+ $v = $vinf;
+ for($y=0; $y<6; $y++) {
+ for($x=0; $x<3; $x++) {
+ $frame[$y][$x+($width - 11)] = chr(0x88 | ($v & 1));
+ $v = $v >> 1;
+ }
+ }
+ }
+
+ // and a little bit...
+ $frame[$width - 8][8] = "\x81";
+
+ return $frame;
+ }
+
+ //----------------------------------------------------------------------
+ public static function debug($frame, $binary_mode = false)
+ {
+ if ($binary_mode) {
+
+ foreach ($frame as &$frameLine) {
+ $frameLine = join('<span class="m">&nbsp;&nbsp;</span>', explode('0', $frameLine));
+ $frameLine = join('&#9608;&#9608;', explode('1', $frameLine));
+ }
+
+ ?>
+ <style>
+ .m { background-color: white; }
+ </style>
+ <?php
+ echo '<pre><tt><br/ ><br/ ><br/ >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
+ echo join("<br/ >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", $frame);
+ echo '</tt></pre><br/ ><br/ ><br/ ><br/ ><br/ ><br/ >';
+
+ } else {
+
+ foreach ($frame as &$frameLine) {
+ $frameLine = join('<span class="m">&nbsp;</span>', explode("\xc0", $frameLine));
+ $frameLine = join('<span class="m">&#9618;</span>', explode("\xc1", $frameLine));
+ $frameLine = join('<span class="p">&nbsp;</span>', explode("\xa0", $frameLine));
+ $frameLine = join('<span class="p">&#9618;</span>', explode("\xa1", $frameLine));
+ $frameLine = join('<span class="s">&#9671;</span>', explode("\x84", $frameLine)); //format 0
+ $frameLine = join('<span class="s">&#9670;</span>', explode("\x85", $frameLine)); //format 1
+ $frameLine = join('<span class="x">&#9762;</span>', explode("\x81", $frameLine)); //special bit
+ $frameLine = join('<span class="c">&nbsp;</span>', explode("\x90", $frameLine)); //clock 0
+ $frameLine = join('<span class="c">&#9719;</span>', explode("\x91", $frameLine)); //clock 1
+ $frameLine = join('<span class="f">&nbsp;</span>', explode("\x88", $frameLine)); //version
+ $frameLine = join('<span class="f">&#9618;</span>', explode("\x89", $frameLine)); //version
+ $frameLine = join('&#9830;', explode("\x01", $frameLine));
+ $frameLine = join('&#8901;', explode("\0", $frameLine));
+ }
+
+ ?>
+ <style>
+ .p { background-color: yellow; }
+ .m { background-color: #00FF00; }
+ .s { background-color: #FF0000; }
+ .c { background-color: aqua; }
+ .x { background-color: pink; }
+ .f { background-color: gold; }
+ </style>
+ <?php
+ echo "<pre><tt>";
+ echo join("<br/ >", $frame);
+ echo "</tt></pre>";
+
+ }
+ }
+
+ //----------------------------------------------------------------------
+ public static function serial($frame)
+ {
+ return gzcompress(join("\n", $frame), 9);
+ }
+
+ //----------------------------------------------------------------------
+ public static function unserial($code)
+ {
+ return explode("\n", gzuncompress($code));
+ }
+
+ //----------------------------------------------------------------------
+ public static function newFrame($version)
+ {
+ if($version < 1 || $version > QRSPEC_VERSION_MAX)
+ return null;
+
+ if(!isset(self::$frames[$version])) {
+
+ $fileName = QR_CACHE_DIR.'frame_'.$version.'.dat';
+
+ if (QR_CACHEABLE) {
+ if (file_exists($fileName)) {
+ self::$frames[$version] = self::unserial(file_get_contents($fileName));
+ } else {
+ self::$frames[$version] = self::createFrame($version);
+ file_put_contents($fileName, self::serial(self::$frames[$version]));
+ }
+ } else {
+ self::$frames[$version] = self::createFrame($version);
+ }
+ }
+
+ if(is_null(self::$frames[$version]))
+ return null;
+
+ return self::$frames[$version];
+ }
+
+ //----------------------------------------------------------------------
+ public static function rsBlockNum($spec) { return $spec[0] + $spec[3]; }
+ public static function rsBlockNum1($spec) { return $spec[0]; }
+ public static function rsDataCodes1($spec) { return $spec[1]; }
+ public static function rsEccCodes1($spec) { return $spec[2]; }
+ public static function rsBlockNum2($spec) { return $spec[3]; }
+ public static function rsDataCodes2($spec) { return $spec[4]; }
+ public static function rsEccCodes2($spec) { return $spec[2]; }
+ public static function rsDataLength($spec) { return ($spec[0] * $spec[1]) + ($spec[3] * $spec[4]); }
+ public static function rsEccLength($spec) { return ($spec[0] + $spec[3]) * $spec[2]; }
+
+ }
+
+
+
+//---- qrimage.php -----------------------------
+
+
+
+
+/*
+ * PHP QR Code encoder
+ *
+ * Image output of code using GD2
+ *
+ * PHP QR Code is distributed under LGPL 3
+ * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+ define('QR_IMAGE', true);
+
+ class QRimage {
+
+ //----------------------------------------------------------------------
+ public static function png($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4,$saveandprint=FALSE)
+ {
+ $image = self::image($frame, $pixelPerPoint, $outerFrame);
+
+ if ($filename === false) {
+ Header("Content-type: image/png");
+ ImagePng($image);
+ } else {
+ if($saveandprint===TRUE){
+ ImagePng($image, $filename);
+ header("Content-type: image/png");
+ ImagePng($image);
+ }else{
+ ImagePng($image, $filename);
+ }
+ }
+
+ ImageDestroy($image);
+ }
+
+ //----------------------------------------------------------------------
+ public static function jpg($frame, $filename = false, $pixelPerPoint = 8, $outerFrame = 4, $q = 85)
+ {
+ $image = self::image($frame, $pixelPerPoint, $outerFrame);
+
+ if ($filename === false) {
+ Header("Content-type: image/jpeg");
+ ImageJpeg($image, null, $q);
+ } else {
+ ImageJpeg($image, $filename, $q);
+ }
+
+ ImageDestroy($image);
+ }
+
+ //----------------------------------------------------------------------
+ private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4)
+ {
+ $h = count($frame);
+ $w = strlen($frame[0]);
+
+ $imgW = $w + 2*$outerFrame;
+ $imgH = $h + 2*$outerFrame;
+
+ $base_image =ImageCreate($imgW, $imgH);
+
+ $col[0] = ImageColorAllocate($base_image,255,255,255);
+ $col[1] = ImageColorAllocate($base_image,0,0,0);
+
+ imagefill($base_image, 0, 0, $col[0]);
+
+ for($y=0; $y<$h; $y++) {
+ for($x=0; $x<$w; $x++) {
+ if ($frame[$y][$x] == '1') {
+ ImageSetPixel($base_image,$x+$outerFrame,$y+$outerFrame,$col[1]);
+ }
+ }
+ }
+
+ $target_image =ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint);
+ ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH);
+ ImageDestroy($base_image);
+
+ return $target_image;
+ }
+ }
+
+
+
+//---- qrinput.php -----------------------------
+
+
+
+
+/*
+ * PHP QR Code encoder
+ *
+ * Input encoding class
+ *
+ * Based on libqrencode C library distributed under LGPL 2.1
+ * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net>
+ *
+ * PHP QR Code is distributed under LGPL 3
+ * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+ define('STRUCTURE_HEADER_BITS', 20);
+ define('MAX_STRUCTURED_SYMBOLS', 16);
+
+ class QRinputItem {
+
+ public $mode;
+ public $size;
+ public $data;
+ public $bstream;
+
+ public function __construct($mode, $size, $data, $bstream = null)
+ {
+ $setData = array_slice($data, 0, $size);
+
+ if (count($setData) < $size) {
+ $setData = array_merge($setData, array_fill(0,$size-count($setData),0));
+ }
+
+ if(!QRinput::check($mode, $size, $setData)) {
+ throw new Exception('Error m:'.$mode.',s:'.$size.',d:'.join(',',$setData));
+ return null;
+ }
+
+ $this->mode = $mode;
+ $this->size = $size;
+ $this->data = $setData;
+ $this->bstream = $bstream;
+ }
+
+ //----------------------------------------------------------------------
+ public function encodeModeNum($version)
+ {
+ try {
+
+ $words = (int)($this->size / 3);
+ $bs = new QRbitstream();
+
+ $val = 0x1;
+ $bs->appendNum(4, $val);
+ $bs->appendNum(QRspec::lengthIndicator(QR_MODE_NUM, $version), $this->size);
+
+ for($i=0; $i<$words; $i++) {
+ $val = (ord($this->data[$i*3 ]) - ord('0')) * 100;
+ $val += (ord($this->data[$i*3+1]) - ord('0')) * 10;
+ $val += (ord($this->data[$i*3+2]) - ord('0'));
+ $bs->appendNum(10, $val);
+ }
+
+ if($this->size - $words * 3 == 1) {
+ $val = ord($this->data[$words*3]) - ord('0');
+ $bs->appendNum(4, $val);
+ } else if($this->size - $words * 3 == 2) {
+ $val = (ord($this->data[$words*3 ]) - ord('0')) * 10;
+ $val += (ord($this->data[$words*3+1]) - ord('0'));
+ $bs->appendNum(7, $val);
+ }
+
+ $this->bstream = $bs;
+ return 0;
+
+ } catch (Exception $e) {
+ return -1;
+ }
+ }
+
+ //----------------------------------------------------------------------
+ public function encodeModeAn($version)
+ {
+ try {
+ $words = (int)($this->size / 2);
+ $bs = new QRbitstream();
+
+ $bs->appendNum(4, 0x02);
+ $bs->appendNum(QRspec::lengthIndicator(QR_MODE_AN, $version), $this->size);
+
+ for($i=0; $i<$words; $i++) {
+ $val = (int)QRinput::lookAnTable(ord($this->data[$i*2 ])) * 45;
+ $val += (int)QRinput::lookAnTable(ord($this->data[$i*2+1]));
+
+ $bs->appendNum(11, $val);
+ }
+
+ if($this->size & 1) {
+ $val = QRinput::lookAnTable(ord($this->data[$words * 2]));
+ $bs->appendNum(6, $val);
+ }
+
+ $this->bstream = $bs;
+ return 0;
+
+ } catch (Exception $e) {
+ return -1;
+ }
+ }
+
+ //----------------------------------------------------------------------
+ public function encodeMode8($version)
+ {
+ try {
+ $bs = new QRbitstream();
+
+ $bs->appendNum(4, 0x4);
+ $bs->appendNum(QRspec::lengthIndicator(QR_MODE_8, $version), $this->size);
+
+ for($i=0; $i<$this->size; $i++) {
+ $bs->appendNum(8, ord($this->data[$i]));
+ }
+
+ $this->bstream = $bs;
+ return 0;
+
+ } catch (Exception $e) {
+ return -1;
+ }
+ }
+
+ //----------------------------------------------------------------------
+ public function encodeModeKanji($version)
+ {
+ try {
+
+ $bs = new QRbitrtream();
+
+ $bs->appendNum(4, 0x8);
+ $bs->appendNum(QRspec::lengthIndicator(QR_MODE_KANJI, $version), (int)($this->size / 2));
+
+ for($i=0; $i<$this->size; $i+=2) {
+ $val = (ord($this->data[$i]) << 8) | ord($this->data[$i+1]);
+ if($val <= 0x9ffc) {
+ $val -= 0x8140;
+ } else {
+ $val -= 0xc140;
+ }
+
+ $h = ($val >> 8) * 0xc0;
+ $val = ($val & 0xff) + $h;
+
+ $bs->appendNum(13, $val);
+ }
+
+ $this->bstream = $bs;
+ return 0;
+
+ } catch (Exception $e) {
+ return -1;
+ }
+ }
+
+ //----------------------------------------------------------------------
+ public function encodeModeStructure()
+ {
+ try {
+ $bs = new QRbitstream();
+
+ $bs->appendNum(4, 0x03);
+ $bs->appendNum(4, ord($this->data[1]) - 1);
+ $bs->appendNum(4, ord($this->data[0]) - 1);
+ $bs->appendNum(8, ord($this->data[2]));
+
+ $this->bstream = $bs;
+ return 0;
+
+ } catch (Exception $e) {
+ return -1;
+ }
+ }
+
+ //----------------------------------------------------------------------
+ public function estimateBitStreamSizeOfEntry($version)
+ {
+ $bits = 0;
+
+ if($version == 0)
+ $version = 1;
+
+ switch($this->mode) {
+ case QR_MODE_NUM: $bits = QRinput::estimateBitsModeNum($this->size); break;
+ case QR_MODE_AN: $bits = QRinput::estimateBitsModeAn($this->size); break;
+ case QR_MODE_8: $bits = QRinput::estimateBitsMode8($this->size); break;
+ case QR_MODE_KANJI: $bits = QRinput::estimateBitsModeKanji($this->size);break;
+ case QR_MODE_STRUCTURE: return STRUCTURE_HEADER_BITS;
+ default:
+ return 0;
+ }
+
+ $l = QRspec::lengthIndicator($this->mode, $version);
+ $m = 1 << $l;
+ $num = (int)(($this->size + $m - 1) / $m);
+
+ $bits += $num * (4 + $l);
+
+ return $bits;
+ }
+
+ //----------------------------------------------------------------------
+ public function encodeBitStream($version)
+ {
+ try {
+
+ unset($this->bstream);
+ $words = QRspec::maximumWords($this->mode, $version);
+
+ if($this->size > $words) {
+
+ $st1 = new QRinputItem($this->mode, $words, $this->data);
+ $st2 = new QRinputItem($this->mode, $this->size - $words, array_slice($this->data, $words));
+
+ $st1->encodeBitStream($version);
+ $st2->encodeBitStream($version);
+
+ $this->bstream = new QRbitstream();
+ $this->bstream->append($st1->bstream);
+ $this->bstream->append($st2->bstream);
+
+ unset($st1);
+ unset($st2);
+
+ } else {
+
+ $ret = 0;
+
+ switch($this->mode) {
+ case QR_MODE_NUM: $ret = $this->encodeModeNum($version); break;
+ case QR_MODE_AN: $ret = $this->encodeModeAn($version); break;
+ case QR_MODE_8: $ret = $this->encodeMode8($version); break;
+ case QR_MODE_KANJI: $ret = $this->encodeModeKanji($version);break;
+ case QR_MODE_STRUCTURE: $ret = $this->encodeModeStructure(); break;
+
+ default:
+ break;
+ }
+
+ if($ret < 0)
+ return -1;
+ }
+
+ return $this->bstream->size();
+
+ } catch (Exception $e) {
+ return -1;
+ }
+ }
+ };
+
+ //##########################################################################
+
+ class QRinput {
+
+ public $items;
+
+ private $version;
+ private $level;
+
+ //----------------------------------------------------------------------
+ public function __construct($version = 0, $level = QR_ECLEVEL_L)
+ {
+ if ($version < 0 || $version > QRSPEC_VERSION_MAX || $level > QR_ECLEVEL_H) {
+ throw new Exception('Invalid version no');
+ return NULL;
+ }
+
+ $this->version = $version;
+ $this->level = $level;
+ }
+
+ //----------------------------------------------------------------------
+ public function getVersion()
+ {
+ return $this->version;
+ }
+
+ //----------------------------------------------------------------------
+ public function setVersion($version)
+ {
+ if($version < 0 || $version > QRSPEC_VERSION_MAX) {
+ throw new Exception('Invalid version no');
+ return -1;
+ }
+
+ $this->version = $version;
+
+ return 0;
+ }
+
+ //----------------------------------------------------------------------
+ public function getErrorCorrectionLevel()
+ {
+ return $this->level;
+ }
+
+ //----------------------------------------------------------------------
+ public function setErrorCorrectionLevel($level)
+ {
+ if($level > QR_ECLEVEL_H) {
+ throw new Exception('Invalid ECLEVEL');
+ return -1;
+ }
+
+ $this->level = $level;
+
+ return 0;
+ }
+
+ //----------------------------------------------------------------------
+ public function appendEntry(QRinputItem $entry)
+ {
+ $this->items[] = $entry;
+ }
+
+ //----------------------------------------------------------------------
+ public function append($mode, $size, $data)
+ {
+ try {
+ $entry = new QRinputItem($mode, $size, $data);
+ $this->items[] = $entry;
+ return 0;
+ } catch (Exception $e) {
+ return -1;
+ }
+ }
+
+ //----------------------------------------------------------------------
+
+ public function insertStructuredAppendHeader($size, $index, $parity)
+ {
+ if( $size > MAX_STRUCTURED_SYMBOLS ) {
+ throw new Exception('insertStructuredAppendHeader wrong size');
+ }
+
+ if( $index <= 0 || $index > MAX_STRUCTURED_SYMBOLS ) {
+ throw new Exception('insertStructuredAppendHeader wrong index');
+ }
+
+ $buf = array($size, $index, $parity);
+
+ try {
+ $entry = new QRinputItem(QR_MODE_STRUCTURE, 3, buf);
+ array_unshift($this->items, $entry);
+ return 0;
+ } catch (Exception $e) {
+ return -1;
+ }
+ }
+
+ //----------------------------------------------------------------------
+ public function calcParity()
+ {
+ $parity = 0;
+
+ foreach($this->items as $item) {
+ if($item->mode != QR_MODE_STRUCTURE) {
+ for($i=$item->size-1; $i>=0; $i--) {
+ $parity ^= $item->data[$i];
+ }
+ }
+ }
+
+ return $parity;
+ }
+
+ //----------------------------------------------------------------------
+ public static function checkModeNum($size, $data)
+ {
+ for($i=0; $i<$size; $i++) {
+ if((ord($data[$i]) < ord('0')) || (ord($data[$i]) > ord('9'))){
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ //----------------------------------------------------------------------
+ public static function estimateBitsModeNum($size)
+ {
+ $w = (int)$size / 3;
+ $bits = $w * 10;
+
+ switch($size - $w * 3) {
+ case 1:
+ $bits += 4;
+ break;
+ case 2:
+ $bits += 7;
+ break;
+ default:
+ break;
+ }
+
+ return $bits;
+ }
+
+ //----------------------------------------------------------------------
+ public static $anTable = array(
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43,
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1,
+ -1, 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, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
+ );
+
+ //----------------------------------------------------------------------
+ public static function lookAnTable($c)
+ {
+ return (($c > 127)?-1:self::$anTable[$c]);
+ }
+
+ //----------------------------------------------------------------------
+ public static function checkModeAn($size, $data)
+ {
+ for($i=0; $i<$size; $i++) {
+ if (self::lookAnTable(ord($data[$i])) == -1) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ //----------------------------------------------------------------------
+ public static function estimateBitsModeAn($size)
+ {
+ $w = (int)($size / 2);
+ $bits = $w * 11;
+
+ if($size & 1) {
+ $bits += 6;
+ }
+
+ return $bits;
+ }
+
+ //----------------------------------------------------------------------
+ public static function estimateBitsMode8($size)
+ {
+ return $size * 8;
+ }
+
+ //----------------------------------------------------------------------
+ public function estimateBitsModeKanji($size)
+ {
+ return (int)(($size / 2) * 13);
+ }
+
+ //----------------------------------------------------------------------
+ public static function checkModeKanji($size, $data)
+ {
+ if($size & 1)
+ return false;
+
+ for($i=0; $i<$size; $i+=2) {
+ $val = (ord($data[$i]) << 8) | ord($data[$i+1]);
+ if( $val < 0x8140
+ || ($val > 0x9ffc && $val < 0xe040)
+ || $val > 0xebbf) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ /***********************************************************************
+ * Validation
+ **********************************************************************/
+
+ public static function check($mode, $size, $data)
+ {
+ if($size <= 0)
+ return false;
+
+ switch($mode) {
+ case QR_MODE_NUM: return self::checkModeNum($size, $data); break;
+ case QR_MODE_AN: return self::checkModeAn($size, $data); break;
+ case QR_MODE_KANJI: return self::checkModeKanji($size, $data); break;
+ case QR_MODE_8: return true; break;
+ case QR_MODE_STRUCTURE: return true; break;
+
+ default:
+ break;
+ }
+
+ return false;
+ }
+
+
+ //----------------------------------------------------------------------
+ public function estimateBitStreamSize($version)
+ {
+ $bits = 0;
+
+ foreach($this->items as $item) {
+ $bits += $item->estimateBitStreamSizeOfEntry($version);
+ }
+
+ return $bits;
+ }
+
+ //----------------------------------------------------------------------
+ public function estimateVersion()
+ {
+ $version = 0;
+ $prev = 0;
+ do {
+ $prev = $version;
+ $bits = $this->estimateBitStreamSize($prev);
+ $version = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level);
+ if ($version < 0) {
+ return -1;
+ }
+ } while ($version > $prev);
+
+ return $version;
+ }
+
+ //----------------------------------------------------------------------
+ public static function lengthOfCode($mode, $version, $bits)
+ {
+ $payload = $bits - 4 - QRspec::lengthIndicator($mode, $version);
+ switch($mode) {
+ case QR_MODE_NUM:
+ $chunks = (int)($payload / 10);
+ $remain = $payload - $chunks * 10;
+ $size = $chunks * 3;
+ if($remain >= 7) {
+ $size += 2;
+ } else if($remain >= 4) {
+ $size += 1;
+ }
+ break;
+ case QR_MODE_AN:
+ $chunks = (int)($payload / 11);
+ $remain = $payload - $chunks * 11;
+ $size = $chunks * 2;
+ if($remain >= 6)
+ $size++;
+ break;
+ case QR_MODE_8:
+ $size = (int)($payload / 8);
+ break;
+ case QR_MODE_KANJI:
+ $size = (int)(($payload / 13) * 2);
+ break;
+ case QR_MODE_STRUCTURE:
+ $size = (int)($payload / 8);
+ break;
+ default:
+ $size = 0;
+ break;
+ }
+
+ $maxsize = QRspec::maximumWords($mode, $version);
+ if($size < 0) $size = 0;
+ if($size > $maxsize) $size = $maxsize;
+
+ return $size;
+ }
+
+ //----------------------------------------------------------------------
+ public function createBitStream()
+ {
+ $total = 0;
+
+ foreach($this->items as $item) {
+ $bits = $item->encodeBitStream($this->version);
+
+ if($bits < 0)
+ return -1;
+
+ $total += $bits;
+ }
+
+ return $total;
+ }
+
+ //----------------------------------------------------------------------
+ public function convertData()
+ {
+ $ver = $this->estimateVersion();
+ if($ver > $this->getVersion()) {
+ $this->setVersion($ver);
+ }
+
+ for(;;) {
+ $bits = $this->createBitStream();
+
+ if($bits < 0)
+ return -1;
+
+ $ver = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level);
+ if($ver < 0) {
+ throw new Exception('WRONG VERSION');
+ return -1;
+ } else if($ver > $this->getVersion()) {
+ $this->setVersion($ver);
+ } else {
+ break;
+ }
+ }
+
+ return 0;
+ }
+
+ //----------------------------------------------------------------------
+ public function appendPaddingBit(&$bstream)
+ {
+ $bits = $bstream->size();
+ $maxwords = QRspec::getDataLength($this->version, $this->level);
+ $maxbits = $maxwords * 8;
+
+ if ($maxbits == $bits) {
+ return 0;
+ }
+
+ if ($maxbits - $bits < 5) {
+ return $bstream->appendNum($maxbits - $bits, 0);
+ }
+
+ $bits += 4;
+ $words = (int)(($bits + 7) / 8);
+
+ $padding = new QRbitstream();
+ $ret = $padding->appendNum($words * 8 - $bits + 4, 0);
+
+ if($ret < 0)
+ return $ret;
+
+ $padlen = $maxwords - $words;
+
+ if($padlen > 0) {
+
+ $padbuf = array();
+ for($i=0; $i<$padlen; $i++) {
+ $padbuf[$i] = ($i&1)?0x11:0xec;
+ }
+
+ $ret = $padding->appendBytes($padlen, $padbuf);
+
+ if($ret < 0)
+ return $ret;
+
+ }
+
+ $ret = $bstream->append($padding);
+
+ return $ret;
+ }
+
+ //----------------------------------------------------------------------
+ public function mergeBitStream()
+ {
+ if($this->convertData() < 0) {
+ return null;
+ }
+
+ $bstream = new QRbitstream();
+
+ foreach($this->items as $item) {
+ $ret = $bstream->append($item->bstream);
+ if($ret < 0) {
+ return null;
+ }
+ }
+
+ return $bstream;
+ }
+
+ //----------------------------------------------------------------------
+ public function getBitStream()
+ {
+
+ $bstream = $this->mergeBitStream();
+
+ if($bstream == null) {
+ return null;
+ }
+
+ $ret = $this->appendPaddingBit($bstream);
+ if($ret < 0) {
+ return null;
+ }
+
+ return $bstream;
+ }
+
+ //----------------------------------------------------------------------
+ public function getByteStream()
+ {
+ $bstream = $this->getBitStream();
+ if($bstream == null) {
+ return null;
+ }
+
+ return $bstream->toByte();
+ }
+ }
+
+
+
+
+
+
+//---- qrbitstream.php -----------------------------
+
+
+
+
+/*
+ * PHP QR Code encoder
+ *
+ * Bitstream class
+ *
+ * Based on libqrencode C library distributed under LGPL 2.1
+ * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net>
+ *
+ * PHP QR Code is distributed under LGPL 3
+ * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+ class QRbitstream {
+
+ public $data = array();
+
+ //----------------------------------------------------------------------
+ public function size()
+ {
+ return count($this->data);
+ }
+
+ //----------------------------------------------------------------------
+ public function allocate($setLength)
+ {
+ $this->data = array_fill(0, $setLength, 0);
+ return 0;
+ }
+
+ //----------------------------------------------------------------------
+ public static function newFromNum($bits, $num)
+ {
+ $bstream = new QRbitstream();
+ $bstream->allocate($bits);
+
+ $mask = 1 << ($bits - 1);
+ for($i=0; $i<$bits; $i++) {
+ if($num & $mask) {
+ $bstream->data[$i] = 1;
+ } else {
+ $bstream->data[$i] = 0;
+ }
+ $mask = $mask >> 1;
+ }
+
+ return $bstream;
+ }
+
+ //----------------------------------------------------------------------
+ public static function newFromBytes($size, $data)
+ {
+ $bstream = new QRbitstream();
+ $bstream->allocate($size * 8);
+ $p=0;
+
+ for($i=0; $i<$size; $i++) {
+ $mask = 0x80;
+ for($j=0; $j<8; $j++) {
+ if($data[$i] & $mask) {
+ $bstream->data[$p] = 1;
+ } else {
+ $bstream->data[$p] = 0;
+ }
+ $p++;
+ $mask = $mask >> 1;
+ }
+ }
+
+ return $bstream;
+ }
+
+ //----------------------------------------------------------------------
+ public function append(QRbitstream $arg)
+ {
+ if (is_null($arg)) {
+ return -1;
+ }
+
+ if($arg->size() == 0) {
+ return 0;
+ }
+
+ if($this->size() == 0) {
+ $this->data = $arg->data;
+ return 0;
+ }
+
+ $this->data = array_values(array_merge($this->data, $arg->data));
+
+ return 0;
+ }
+
+ //----------------------------------------------------------------------
+ public function appendNum($bits, $num)
+ {
+ if ($bits == 0)
+ return 0;
+
+ $b = QRbitstream::newFromNum($bits, $num);
+
+ if(is_null($b))
+ return -1;
+
+ $ret = $this->append($b);
+ unset($b);
+
+ return $ret;
+ }
+
+ //----------------------------------------------------------------------
+ public function appendBytes($size, $data)
+ {
+ if ($size == 0)
+ return 0;
+
+ $b = QRbitstream::newFromBytes($size, $data);
+
+ if(is_null($b))
+ return -1;
+
+ $ret = $this->append($b);
+ unset($b);
+
+ return $ret;
+ }
+
+ //----------------------------------------------------------------------
+ public function toByte()
+ {
+
+ $size = $this->size();
+
+ if($size == 0) {
+ return array();
+ }
+
+ $data = array_fill(0, (int)(($size + 7) / 8), 0);
+ $bytes = (int)($size / 8);
+
+ $p = 0;
+
+ for($i=0; $i<$bytes; $i++) {
+ $v = 0;
+ for($j=0; $j<8; $j++) {
+ $v = $v << 1;
+ $v |= $this->data[$p];
+ $p++;
+ }
+ $data[$i] = $v;
+ }
+
+ if($size & 7) {
+ $v = 0;
+ for($j=0; $j<($size & 7); $j++) {
+ $v = $v << 1;
+ $v |= $this->data[$p];
+ $p++;
+ }
+ $data[$bytes] = $v;
+ }
+
+ return $data;
+ }
+
+ }
+
+
+
+
+//---- qrsplit.php -----------------------------
+
+
+
+
+/*
+ * PHP QR Code encoder
+ *
+ * Input splitting classes
+ *
+ * Based on libqrencode C library distributed under LGPL 2.1
+ * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net>
+ *
+ * PHP QR Code is distributed under LGPL 3
+ * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
+ *
+ * The following data / specifications are taken from
+ * "Two dimensional symbol -- QR-code -- Basic Specification" (JIS X0510:2004)
+ * or
+ * "Automatic identification and data capture techniques --
+ * QR Code 2005 bar code symbology specification" (ISO/IEC 18004:2006)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+ class QRsplit {
+
+ public $dataStr = '';
+ public $input;
+ public $modeHint;
+
+ //----------------------------------------------------------------------
+ public function __construct($dataStr, $input, $modeHint)
+ {
+ $this->dataStr = $dataStr;
+ $this->input = $input;
+ $this->modeHint = $modeHint;
+ }
+
+ //----------------------------------------------------------------------
+ public static function isdigitat($str, $pos)
+ {
+ if ($pos >= strlen($str))
+ return false;
+
+ return ((ord($str[$pos]) >= ord('0'))&&(ord($str[$pos]) <= ord('9')));
+ }
+
+ //----------------------------------------------------------------------
+ public static function isalnumat($str, $pos)
+ {
+ if ($pos >= strlen($str))
+ return false;
+
+ return (QRinput::lookAnTable(ord($str[$pos])) >= 0);
+ }
+
+ //----------------------------------------------------------------------
+ public function identifyMode($pos)
+ {
+ if ($pos >= strlen($this->dataStr))
+ return QR_MODE_NUL;
+
+ $c = $this->dataStr[$pos];
+
+ if(self::isdigitat($this->dataStr, $pos)) {
+ return QR_MODE_NUM;
+ } else if(self::isalnumat($this->dataStr, $pos)) {
+ return QR_MODE_AN;
+ } else if($this->modeHint == QR_MODE_KANJI) {
+
+ if ($pos+1 < strlen($this->dataStr))
+ {
+ $d = $this->dataStr[$pos+1];
+ $word = (ord($c) << 8) | ord($d);
+ if(($word >= 0x8140 && $word <= 0x9ffc) || ($word >= 0xe040 && $word <= 0xebbf)) {
+ return QR_MODE_KANJI;
+ }
+ }
+ }
+
+ return QR_MODE_8;
+ }
+
+ //----------------------------------------------------------------------
+ public function eatNum()
+ {
+ $ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion());
+
+ $p = 0;
+ while(self::isdigitat($this->dataStr, $p)) {
+ $p++;
+ }
+
+ $run = $p;
+ $mode = $this->identifyMode($p);
+
+ if($mode == QR_MODE_8) {
+ $dif = QRinput::estimateBitsModeNum($run) + 4 + $ln
+ + QRinput::estimateBitsMode8(1) // + 4 + l8
+ - QRinput::estimateBitsMode8($run + 1); // - 4 - l8
+ if($dif > 0) {
+ return $this->eat8();
+ }
+ }
+ if($mode == QR_MODE_AN) {
+ $dif = QRinput::estimateBitsModeNum($run) + 4 + $ln
+ + QRinput::estimateBitsModeAn(1) // + 4 + la
+ - QRinput::estimateBitsModeAn($run + 1);// - 4 - la
+ if($dif > 0) {
+ return $this->eatAn();
+ }
+ }
+
+ $ret = $this->input->append(QR_MODE_NUM, $run, str_split($this->dataStr));
+ if($ret < 0)
+ return -1;
+
+ return $run;
+ }
+
+ //----------------------------------------------------------------------
+ public function eatAn()
+ {
+ $la = QRspec::lengthIndicator(QR_MODE_AN, $this->input->getVersion());
+ $ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion());
+
+ $p = 0;
+
+ while(self::isalnumat($this->dataStr, $p)) {
+ if(self::isdigitat($this->dataStr, $p)) {
+ $q = $p;
+ while(self::isdigitat($this->dataStr, $q)) {
+ $q++;
+ }
+
+ $dif = QRinput::estimateBitsModeAn($p) // + 4 + la
+ + QRinput::estimateBitsModeNum($q - $p) + 4 + $ln
+ - QRinput::estimateBitsModeAn($q); // - 4 - la
+
+ if($dif < 0) {
+ break;
+ } else {
+ $p = $q;
+ }
+ } else {
+ $p++;
+ }
+ }
+
+ $run = $p;
+
+ if(!self::isalnumat($this->dataStr, $p)) {
+ $dif = QRinput::estimateBitsModeAn($run) + 4 + $la
+ + QRinput::estimateBitsMode8(1) // + 4 + l8
+ - QRinput::estimateBitsMode8($run + 1); // - 4 - l8
+ if($dif > 0) {
+ return $this->eat8();
+ }
+ }
+
+ $ret = $this->input->append(QR_MODE_AN, $run, str_split($this->dataStr));
+ if($ret < 0)
+ return -1;
+
+ return $run;
+ }
+
+ //----------------------------------------------------------------------
+ public function eatKanji()
+ {
+ $p = 0;
+
+ while($this->identifyMode($p) == QR_MODE_KANJI) {
+ $p += 2;
+ }
+
+ $ret = $this->input->append(QR_MODE_KANJI, $p, str_split($this->dataStr));
+ if($ret < 0)
+ return -1;
+
+ return $run;
+ }
+
+ //----------------------------------------------------------------------
+ public function eat8()
+ {
+ $la = QRspec::lengthIndicator(QR_MODE_AN, $this->input->getVersion());
+ $ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion());
+
+ $p = 1;
+ $dataStrLen = strlen($this->dataStr);
+
+ while($p < $dataStrLen) {
+
+ $mode = $this->identifyMode($p);
+ if($mode == QR_MODE_KANJI) {
+ break;
+ }
+ if($mode == QR_MODE_NUM) {
+ $q = $p;
+ while(self::isdigitat($this->dataStr, $q)) {
+ $q++;
+ }
+ $dif = QRinput::estimateBitsMode8($p) // + 4 + l8
+ + QRinput::estimateBitsModeNum($q - $p) + 4 + $ln
+ - QRinput::estimateBitsMode8($q); // - 4 - l8
+ if($dif < 0) {
+ break;
+ } else {
+ $p = $q;
+ }
+ } else if($mode == QR_MODE_AN) {
+ $q = $p;
+ while(self::isalnumat($this->dataStr, $q)) {
+ $q++;
+ }
+ $dif = QRinput::estimateBitsMode8($p) // + 4 + l8
+ + QRinput::estimateBitsModeAn($q - $p) + 4 + $la
+ - QRinput::estimateBitsMode8($q); // - 4 - l8
+ if($dif < 0) {
+ break;
+ } else {
+ $p = $q;
+ }
+ } else {
+ $p++;
+ }
+ }
+
+ $run = $p;
+ $ret = $this->input->append(QR_MODE_8, $run, str_split($this->dataStr));
+
+ if($ret < 0)
+ return -1;
+
+ return $run;
+ }
+
+ //----------------------------------------------------------------------
+ public function splitString()
+ {
+ while (strlen($this->dataStr) > 0)
+ {
+ if($this->dataStr == '')
+ return 0;
+
+ $mode = $this->identifyMode(0);
+
+ switch ($mode) {
+ case QR_MODE_NUM: $length = $this->eatNum(); break;
+ case QR_MODE_AN: $length = $this->eatAn(); break;
+ case QR_MODE_KANJI:
+ if ($hint == QR_MODE_KANJI)
+ $length = $this->eatKanji();
+ else $length = $this->eat8();
+ break;
+ default: $length = $this->eat8(); break;
+
+ }
+
+ if($length == 0) return 0;
+ if($length < 0) return -1;
+
+ $this->dataStr = substr($this->dataStr, $length);
+ }
+ }
+
+ //----------------------------------------------------------------------
+ public function toUpper()
+ {
+ $stringLen = strlen($this->dataStr);
+ $p = 0;
+
+ while ($p<$stringLen) {
+ $mode = self::identifyMode(substr($this->dataStr, $p), $this->modeHint);
+ if($mode == QR_MODE_KANJI) {
+ $p += 2;
+ } else {
+ if (ord($this->dataStr[$p]) >= ord('a') && ord($this->dataStr[$p]) <= ord('z')) {
+ $this->dataStr[$p] = chr(ord($this->dataStr[$p]) - 32);
+ }
+ $p++;
+ }
+ }
+
+ return $this->dataStr;
+ }
+
+ //----------------------------------------------------------------------
+ public static function splitStringToQRinput($string, QRinput $input, $modeHint, $casesensitive = true)
+ {
+ if(is_null($string) || $string == '\0' || $string == '') {
+ throw new Exception('empty string!!!');
+ }
+
+ $split = new QRsplit($string, $input, $modeHint);
+
+ if(!$casesensitive)
+ $split->toUpper();
+
+ return $split->splitString();
+ }
+ }
+
+
+
+//---- qrrscode.php -----------------------------
+
+
+
+
+/*
+ * PHP QR Code encoder
+ *
+ * Reed-Solomon error correction support
+ *
+ * Copyright (C) 2002, 2003, 2004, 2006 Phil Karn, KA9Q
+ * (libfec is released under the GNU Lesser General Public License.)
+ *
+ * Based on libqrencode C library distributed under LGPL 2.1
+ * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net>
+ *
+ * PHP QR Code is distributed under LGPL 3
+ * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+ class QRrsItem {
+
+ public $mm; // Bits per symbol
+ public $nn; // Symbols per block (= (1<<mm)-1)
+ public $alpha_to = array(); // log lookup table
+ public $index_of = array(); // Antilog lookup table
+ public $genpoly = array(); // Generator polynomial
+ public $nroots; // Number of generator roots = number of parity symbols
+ public $fcr; // First consecutive root, index form
+ public $prim; // Primitive element, index form
+ public $iprim; // prim-th root of 1, index form
+ public $pad; // Padding bytes in shortened block
+ public $gfpoly;
+
+ //----------------------------------------------------------------------
+ public function modnn($x)
+ {
+ while ($x >= $this->nn) {
+ $x -= $this->nn;
+ $x = ($x >> $this->mm) + ($x & $this->nn);
+ }
+
+ return $x;
+ }
+
+ //----------------------------------------------------------------------
+ public static function init_rs_char($symsize, $gfpoly, $fcr, $prim, $nroots, $pad)
+ {
+ // Common code for intializing a Reed-Solomon control block (char or int symbols)
+ // Copyright 2004 Phil Karn, KA9Q
+ // May be used under the terms of the GNU Lesser General Public License (LGPL)
+
+ $rs = null;
+
+ // Check parameter ranges
+ if($symsize < 0 || $symsize > 8) return $rs;
+ if($fcr < 0 || $fcr >= (1<<$symsize)) return $rs;
+ if($prim <= 0 || $prim >= (1<<$symsize)) return $rs;
+ if($nroots < 0 || $nroots >= (1<<$symsize)) return $rs; // Can't have more roots than symbol values!
+ if($pad < 0 || $pad >= ((1<<$symsize) -1 - $nroots)) return $rs; // Too much padding
+
+ $rs = new QRrsItem();
+ $rs->mm = $symsize;
+ $rs->nn = (1<<$symsize)-1;
+ $rs->pad = $pad;
+
+ $rs->alpha_to = array_fill(0, $rs->nn+1, 0);
+ $rs->index_of = array_fill(0, $rs->nn+1, 0);
+
+ // PHP style macro replacement ;)
+ $NN =& $rs->nn;
+ $A0 =& $NN;
+
+ // Generate Galois field lookup tables
+ $rs->index_of[0] = $A0; // log(zero) = -inf
+ $rs->alpha_to[$A0] = 0; // alpha**-inf = 0
+ $sr = 1;
+
+ for($i=0; $i<$rs->nn; $i++) {
+ $rs->index_of[$sr] = $i;
+ $rs->alpha_to[$i] = $sr;
+ $sr <<= 1;
+ if($sr & (1<<$symsize)) {
+ $sr ^= $gfpoly;
+ }
+ $sr &= $rs->nn;
+ }
+
+ if($sr != 1){
+ // field generator polynomial is not primitive!
+ $rs = NULL;
+ return $rs;
+ }
+
+ /* Form RS code generator polynomial from its roots */
+ $rs->genpoly = array_fill(0, $nroots+1, 0);
+
+ $rs->fcr = $fcr;
+ $rs->prim = $prim;
+ $rs->nroots = $nroots;
+ $rs->gfpoly = $gfpoly;
+
+ /* Find prim-th root of 1, used in decoding */
+ for($iprim=1;($iprim % $prim) != 0;$iprim += $rs->nn)
+ ; // intentional empty-body loop!
+
+ $rs->iprim = (int)($iprim / $prim);
+ $rs->genpoly[0] = 1;
+
+ for ($i = 0,$root=$fcr*$prim; $i < $nroots; $i++, $root += $prim) {
+ $rs->genpoly[$i+1] = 1;
+
+ // Multiply rs->genpoly[] by @**(root + x)
+ for ($j = $i; $j > 0; $j--) {
+ if ($rs->genpoly[$j] != 0) {
+ $rs->genpoly[$j] = $rs->genpoly[$j-1] ^ $rs->alpha_to[$rs->modnn($rs->index_of[$rs->genpoly[$j]] + $root)];
+ } else {
+ $rs->genpoly[$j] = $rs->genpoly[$j-1];
+ }
+ }
+ // rs->genpoly[0] can never be zero
+ $rs->genpoly[0] = $rs->alpha_to[$rs->modnn($rs->index_of[$rs->genpoly[0]] + $root)];
+ }
+
+ // convert rs->genpoly[] to index form for quicker encoding
+ for ($i = 0; $i <= $nroots; $i++)
+ $rs->genpoly[$i] = $rs->index_of[$rs->genpoly[$i]];
+
+ return $rs;
+ }
+
+ //----------------------------------------------------------------------
+ public function encode_rs_char($data, &$parity)
+ {
+ $MM =& $this->mm;
+ $NN =& $this->nn;
+ $ALPHA_TO =& $this->alpha_to;
+ $INDEX_OF =& $this->index_of;
+ $GENPOLY =& $this->genpoly;
+ $NROOTS =& $this->nroots;
+ $FCR =& $this->fcr;
+ $PRIM =& $this->prim;
+ $IPRIM =& $this->iprim;
+ $PAD =& $this->pad;
+ $A0 =& $NN;
+
+ $parity = array_fill(0, $NROOTS, 0);
+
+ for($i=0; $i< ($NN-$NROOTS-$PAD); $i++) {
+
+ $feedback = $INDEX_OF[$data[$i] ^ $parity[0]];
+ if($feedback != $A0) {
+ // feedback term is non-zero
+
+ // This line is unnecessary when GENPOLY[NROOTS] is unity, as it must
+ // always be for the polynomials constructed by init_rs()
+ $feedback = $this->modnn($NN - $GENPOLY[$NROOTS] + $feedback);
+
+ for($j=1;$j<$NROOTS;$j++) {
+ $parity[$j] ^= $ALPHA_TO[$this->modnn($feedback + $GENPOLY[$NROOTS-$j])];
+ }
+ }
+
+ // Shift
+ array_shift($parity);
+ if($feedback != $A0) {
+ array_push($parity, $ALPHA_TO[$this->modnn($feedback + $GENPOLY[0])]);
+ } else {
+ array_push($parity, 0);
+ }
+ }
+ }
+ }
+
+ //##########################################################################
+
+ class QRrs {
+
+ public static $items = array();
+
+ //----------------------------------------------------------------------
+ public static function init_rs($symsize, $gfpoly, $fcr, $prim, $nroots, $pad)
+ {
+ foreach(self::$items as $rs) {
+ if($rs->pad != $pad) continue;
+ if($rs->nroots != $nroots) continue;
+ if($rs->mm != $symsize) continue;
+ if($rs->gfpoly != $gfpoly) continue;
+ if($rs->fcr != $fcr) continue;
+ if($rs->prim != $prim) continue;
+
+ return $rs;
+ }
+
+ $rs = QRrsItem::init_rs_char($symsize, $gfpoly, $fcr, $prim, $nroots, $pad);
+ array_unshift(self::$items, $rs);
+
+ return $rs;
+ }
+ }
+
+
+
+//---- qrmask.php -----------------------------
+
+
+
+
+/*
+ * PHP QR Code encoder
+ *
+ * Masking
+ *
+ * Based on libqrencode C library distributed under LGPL 2.1
+ * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net>
+ *
+ * PHP QR Code is distributed under LGPL 3
+ * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+ define('N1', 3);
+ define('N2', 3);
+ define('N3', 40);
+ define('N4', 10);
+
+ class QRmask {
+
+ public $runLength = array();
+
+ //----------------------------------------------------------------------
+ public function __construct()
+ {
+ $this->runLength = array_fill(0, QRSPEC_WIDTH_MAX + 1, 0);
+ }
+
+ //----------------------------------------------------------------------
+ public function writeFormatInformation($width, &$frame, $mask, $level)
+ {
+ $blacks = 0;
+ $format = QRspec::getFormatInfo($mask, $level);
+
+ for($i=0; $i<8; $i++) {
+ if($format & 1) {
+ $blacks += 2;
+ $v = 0x85;
+ } else {
+ $v = 0x84;
+ }
+
+ $frame[8][$width - 1 - $i] = chr($v);
+ if($i < 6) {
+ $frame[$i][8] = chr($v);
+ } else {
+ $frame[$i + 1][8] = chr($v);
+ }
+ $format = $format >> 1;
+ }
+
+ for($i=0; $i<7; $i++) {
+ if($format & 1) {
+ $blacks += 2;
+ $v = 0x85;
+ } else {
+ $v = 0x84;
+ }
+
+ $frame[$width - 7 + $i][8] = chr($v);
+ if($i == 0) {
+ $frame[8][7] = chr($v);
+ } else {
+ $frame[8][6 - $i] = chr($v);
+ }
+
+ $format = $format >> 1;
+ }
+
+ return $blacks;
+ }
+
+ //----------------------------------------------------------------------
+ public function mask0($x, $y) { return ($x+$y)&1; }
+ public function mask1($x, $y) { return ($y&1); }
+ public function mask2($x, $y) { return ($x%3); }
+ public function mask3($x, $y) { return ($x+$y)%3; }
+ public function mask4($x, $y) { return (((int)($y/2))+((int)($x/3)))&1; }
+ public function mask5($x, $y) { return (($x*$y)&1)+($x*$y)%3; }
+ public function mask6($x, $y) { return ((($x*$y)&1)+($x*$y)%3)&1; }
+ public function mask7($x, $y) { return ((($x*$y)%3)+(($x+$y)&1))&1; }
+
+ //----------------------------------------------------------------------
+ private function generateMaskNo($maskNo, $width, $frame)
+ {
+ $bitMask = array_fill(0, $width, array_fill(0, $width, 0));
+
+ for($y=0; $y<$width; $y++) {
+ for($x=0; $x<$width; $x++) {
+ if(ord($frame[$y][$x]) & 0x80) {
+ $bitMask[$y][$x] = 0;
+ } else {
+ $maskFunc = call_user_func(array($this, 'mask'.$maskNo), $x, $y);
+ $bitMask[$y][$x] = ($maskFunc == 0)?1:0;
+ }
+
+ }
+ }
+
+ return $bitMask;
+ }
+
+ //----------------------------------------------------------------------
+ public static function serial($bitFrame)
+ {
+ $codeArr = array();
+
+ foreach ($bitFrame as $line)
+ $codeArr[] = join('', $line);
+
+ return gzcompress(join("\n", $codeArr), 9);
+ }
+
+ //----------------------------------------------------------------------
+ public static function unserial($code)
+ {
+ $codeArr = array();
+
+ $codeLines = explode("\n", gzuncompress($code));
+ foreach ($codeLines as $line)
+ $codeArr[] = str_split($line);
+
+ return $codeArr;
+ }
+
+ //----------------------------------------------------------------------
+ public function makeMaskNo($maskNo, $width, $s, &$d, $maskGenOnly = false)
+ {
+ $b = 0;
+ $bitMask = array();
+
+ $fileName = QR_CACHE_DIR.'mask_'.$maskNo.DIRECTORY_SEPARATOR.'mask_'.$width.'_'.$maskNo.'.dat';
+
+ if (QR_CACHEABLE) {
+ if (file_exists($fileName)) {
+ $bitMask = self::unserial(file_get_contents($fileName));
+ } else {
+ $bitMask = $this->generateMaskNo($maskNo, $width, $s, $d);
+ if (!file_exists(QR_CACHE_DIR.'mask_'.$maskNo))
+ mkdir(QR_CACHE_DIR.'mask_'.$maskNo);
+ file_put_contents($fileName, self::serial($bitMask));
+ }
+ } else {
+ $bitMask = $this->generateMaskNo($maskNo, $width, $s, $d);
+ }
+
+ if ($maskGenOnly)
+ return;
+
+ $d = $s;
+
+ for($y=0; $y<$width; $y++) {
+ for($x=0; $x<$width; $x++) {
+ if($bitMask[$y][$x] == 1) {
+ $d[$y][$x] = chr(ord($s[$y][$x]) ^ (int)$bitMask[$y][$x]);
+ }
+ $b += (int)(ord($d[$y][$x]) & 1);
+ }
+ }
+
+ return $b;
+ }
+
+ //----------------------------------------------------------------------
+ public function makeMask($width, $frame, $maskNo, $level)
+ {
+ $masked = array_fill(0, $width, str_repeat("\0", $width));
+ $this->makeMaskNo($maskNo, $width, $frame, $masked);
+ $this->writeFormatInformation($width, $masked, $maskNo, $level);
+
+ return $masked;
+ }
+
+ //----------------------------------------------------------------------
+ public function calcN1N3($length)
+ {
+ $demerit = 0;
+
+ for($i=0; $i<$length; $i++) {
+
+ if($this->runLength[$i] >= 5) {
+ $demerit += (N1 + ($this->runLength[$i] - 5));
+ }
+ if($i & 1) {
+ if(($i >= 3) && ($i < ($length-2)) && ($this->runLength[$i] % 3 == 0)) {
+ $fact = (int)($this->runLength[$i] / 3);
+ if(($this->runLength[$i-2] == $fact) &&
+ ($this->runLength[$i-1] == $fact) &&
+ ($this->runLength[$i+1] == $fact) &&
+ ($this->runLength[$i+2] == $fact)) {
+ if(($this->runLength[$i-3] < 0) || ($this->runLength[$i-3] >= (4 * $fact))) {
+ $demerit += N3;
+ } else if((($i+3) >= $length) || ($this->runLength[$i+3] >= (4 * $fact))) {
+ $demerit += N3;
+ }
+ }
+ }
+ }
+ }
+ return $demerit;
+ }
+
+ //----------------------------------------------------------------------
+ public function evaluateSymbol($width, $frame)
+ {
+ $head = 0;
+ $demerit = 0;
+
+ for($y=0; $y<$width; $y++) {
+ $head = 0;
+ $this->runLength[0] = 1;
+
+ $frameY = $frame[$y];
+
+ if ($y>0)
+ $frameYM = $frame[$y-1];
+
+ for($x=0; $x<$width; $x++) {
+ if(($x > 0) && ($y > 0)) {
+ $b22 = ord($frameY[$x]) & ord($frameY[$x-1]) & ord($frameYM[$x]) & ord($frameYM[$x-1]);
+ $w22 = ord($frameY[$x]) | ord($frameY[$x-1]) | ord($frameYM[$x]) | ord($frameYM[$x-1]);
+
+ if(($b22 | ($w22 ^ 1))&1) {
+ $demerit += N2;
+ }
+ }
+ if(($x == 0) && (ord($frameY[$x]) & 1)) {
+ $this->runLength[0] = -1;
+ $head = 1;
+ $this->runLength[$head] = 1;
+ } else if($x > 0) {
+ if((ord($frameY[$x]) ^ ord($frameY[$x-1])) & 1) {
+ $head++;
+ $this->runLength[$head] = 1;
+ } else {
+ $this->runLength[$head]++;
+ }
+ }
+ }
+
+ $demerit += $this->calcN1N3($head+1);
+ }
+
+ for($x=0; $x<$width; $x++) {
+ $head = 0;
+ $this->runLength[0] = 1;
+
+ for($y=0; $y<$width; $y++) {
+ if($y == 0 && (ord($frame[$y][$x]) & 1)) {
+ $this->runLength[0] = -1;
+ $head = 1;
+ $this->runLength[$head] = 1;
+ } else if($y > 0) {
+ if((ord($frame[$y][$x]) ^ ord($frame[$y-1][$x])) & 1) {
+ $head++;
+ $this->runLength[$head] = 1;
+ } else {
+ $this->runLength[$head]++;
+ }
+ }
+ }
+
+ $demerit += $this->calcN1N3($head+1);
+ }
+
+ return $demerit;
+ }
+
+
+ //----------------------------------------------------------------------
+ public function mask($width, $frame, $level)
+ {
+ $minDemerit = PHP_INT_MAX;
+ $bestMaskNum = 0;
+ $bestMask = array();
+
+ $checked_masks = array(0,1,2,3,4,5,6,7);
+
+ if (QR_FIND_FROM_RANDOM !== false) {
+
+ $howManuOut = 8-(QR_FIND_FROM_RANDOM % 9);
+ for ($i = 0; $i < $howManuOut; $i++) {
+ $remPos = rand (0, count($checked_masks)-1);
+ unset($checked_masks[$remPos]);
+ $checked_masks = array_values($checked_masks);
+ }
+
+ }
+
+ $bestMask = $frame;
+
+ foreach($checked_masks as $i) {
+ $mask = array_fill(0, $width, str_repeat("\0", $width));
+
+ $demerit = 0;
+ $blacks = 0;
+ $blacks = $this->makeMaskNo($i, $width, $frame, $mask);
+ $blacks += $this->writeFormatInformation($width, $mask, $i, $level);
+ $blacks = (int)(100 * $blacks / ($width * $width));
+ $demerit = (int)((int)(abs($blacks - 50) / 5) * N4);
+ $demerit += $this->evaluateSymbol($width, $mask);
+
+ if($demerit < $minDemerit) {
+ $minDemerit = $demerit;
+ $bestMask = $mask;
+ $bestMaskNum = $i;
+ }
+ }
+
+ return $bestMask;
+ }
+
+ //----------------------------------------------------------------------
+ }
+
+
+
+
+//---- qrencode.php -----------------------------
+
+
+
+
+/*
+ * PHP QR Code encoder
+ *
+ * Main encoder classes.
+ *
+ * Based on libqrencode C library distributed under LGPL 2.1
+ * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net>
+ *
+ * PHP QR Code is distributed under LGPL 3
+ * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+ class QRrsblock {
+ public $dataLength;
+ public $data = array();
+ public $eccLength;
+ public $ecc = array();
+
+ public function __construct($dl, $data, $el, &$ecc, QRrsItem $rs)
+ {
+ $rs->encode_rs_char($data, $ecc);
+
+ $this->dataLength = $dl;
+ $this->data = $data;
+ $this->eccLength = $el;
+ $this->ecc = $ecc;
+ }
+ };
+
+ //##########################################################################
+
+ class QRrawcode {
+ public $version;
+ public $datacode = array();
+ public $ecccode = array();
+ public $blocks;
+ public $rsblocks = array(); //of RSblock
+ public $count;
+ public $dataLength;
+ public $eccLength;
+ public $b1;
+
+ //----------------------------------------------------------------------
+ public function __construct(QRinput $input)
+ {
+ $spec = array(0,0,0,0,0);
+
+ $this->datacode = $input->getByteStream();
+ if(is_null($this->datacode)) {
+ throw new Exception('null imput string');
+ }
+
+ QRspec::getEccSpec($input->getVersion(), $input->getErrorCorrectionLevel(), $spec);
+
+ $this->version = $input->getVersion();
+ $this->b1 = QRspec::rsBlockNum1($spec);
+ $this->dataLength = QRspec::rsDataLength($spec);
+ $this->eccLength = QRspec::rsEccLength($spec);
+ $this->ecccode = array_fill(0, $this->eccLength, 0);
+ $this->blocks = QRspec::rsBlockNum($spec);
+
+ $ret = $this->init($spec);
+ if($ret < 0) {
+ throw new Exception('block alloc error');
+ return null;
+ }
+
+ $this->count = 0;
+ }
+
+ //----------------------------------------------------------------------
+ public function init(array $spec)
+ {
+ $dl = QRspec::rsDataCodes1($spec);
+ $el = QRspec::rsEccCodes1($spec);
+ $rs = QRrs::init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el);
+
+
+ $blockNo = 0;
+ $dataPos = 0;
+ $eccPos = 0;
+ for($i=0; $i<QRspec::rsBlockNum1($spec); $i++) {
+ $ecc = array_slice($this->ecccode,$eccPos);
+ $this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el, $ecc, $rs);
+ $this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc);
+
+ $dataPos += $dl;
+ $eccPos += $el;
+ $blockNo++;
+ }
+
+ if(QRspec::rsBlockNum2($spec) == 0)
+ return 0;
+
+ $dl = QRspec::rsDataCodes2($spec);
+ $el = QRspec::rsEccCodes2($spec);
+ $rs = QRrs::init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el);
+
+ if($rs == NULL) return -1;
+
+ for($i=0; $i<QRspec::rsBlockNum2($spec); $i++) {
+ $ecc = array_slice($this->ecccode,$eccPos);
+ $this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el, $ecc, $rs);
+ $this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc);
+
+ $dataPos += $dl;
+ $eccPos += $el;
+ $blockNo++;
+ }
+
+ return 0;
+ }
+
+ //----------------------------------------------------------------------
+ public function getCode()
+ {
+ $ret;
+
+ if($this->count < $this->dataLength) {
+ $row = $this->count % $this->blocks;
+ $col = $this->count / $this->blocks;
+ if($col >= $this->rsblocks[0]->dataLength) {
+ $row += $this->b1;
+ }
+ $ret = $this->rsblocks[$row]->data[$col];
+ } else if($this->count < $this->dataLength + $this->eccLength) {
+ $row = ($this->count - $this->dataLength) % $this->blocks;
+ $col = ($this->count - $this->dataLength) / $this->blocks;
+ $ret = $this->rsblocks[$row]->ecc[$col];
+ } else {
+ return 0;
+ }
+ $this->count++;
+
+ return $ret;
+ }
+ }
+
+ //##########################################################################
+
+ class QRcode {
+
+ public $version;
+ public $width;
+ public $data;
+
+ //----------------------------------------------------------------------
+ public function encodeMask(QRinput $input, $mask)
+ {
+ if($input->getVersion() < 0 || $input->getVersion() > QRSPEC_VERSION_MAX) {
+ throw new Exception('wrong version');
+ }
+ if($input->getErrorCorrectionLevel() > QR_ECLEVEL_H) {
+ throw new Exception('wrong level');
+ }
+
+ $raw = new QRrawcode($input);
+
+ QRtools::markTime('after_raw');
+
+ $version = $raw->version;
+ $width = QRspec::getWidth($version);
+ $frame = QRspec::newFrame($version);
+
+ $filler = new FrameFiller($width, $frame);
+ if(is_null($filler)) {
+ return NULL;
+ }
+
+ // inteleaved data and ecc codes
+ for($i=0; $i<$raw->dataLength + $raw->eccLength; $i++) {
+ $code = $raw->getCode();
+ $bit = 0x80;
+ for($j=0; $j<8; $j++) {
+ $addr = $filler->next();
+ $filler->setFrameAt($addr, 0x02 | (($bit & $code) != 0));
+ $bit = $bit >> 1;
+ }
+ }
+
+ QRtools::markTime('after_filler');
+
+ unset($raw);
+
+ // remainder bits
+ $j = QRspec::getRemainder($version);
+ for($i=0; $i<$j; $i++) {
+ $addr = $filler->next();
+ $filler->setFrameAt($addr, 0x02);
+ }
+
+ $frame = $filler->frame;
+ unset($filler);
+
+
+ // masking
+ $maskObj = new QRmask();
+ if($mask < 0) {
+
+ if (QR_FIND_BEST_MASK) {
+ $masked = $maskObj->mask($width, $frame, $input->getErrorCorrectionLevel());
+ } else {
+ $masked = $maskObj->makeMask($width, $frame, (intval(QR_DEFAULT_MASK) % 8), $input->getErrorCorrectionLevel());
+ }
+ } else {
+ $masked = $maskObj->makeMask($width, $frame, $mask, $input->getErrorCorrectionLevel());
+ }
+
+ if($masked == NULL) {
+ return NULL;
+ }
+
+ QRtools::markTime('after_mask');
+
+ $this->version = $version;
+ $this->width = $width;
+ $this->data = $masked;
+
+ return $this;
+ }
+
+ //----------------------------------------------------------------------
+ public function encodeInput(QRinput $input)
+ {
+ return $this->encodeMask($input, -1);
+ }
+
+ //----------------------------------------------------------------------
+ public function encodeString8bit($string, $version, $level)
+ {
+ if(string == NULL) {
+ throw new Exception('empty string!');
+ return NULL;
+ }
+
+ $input = new QRinput($version, $level);
+ if($input == NULL) return NULL;
+
+ $ret = $input->append($input, QR_MODE_8, strlen($string), str_split($string));
+ if($ret < 0) {
+ unset($input);
+ return NULL;
+ }
+ return $this->encodeInput($input);
+ }
+
+ //----------------------------------------------------------------------
+ public function encodeString($string, $version, $level, $hint, $casesensitive)
+ {
+
+ if($hint != QR_MODE_8 && $hint != QR_MODE_KANJI) {
+ throw new Exception('bad hint');
+ return NULL;
+ }
+
+ $input = new QRinput($version, $level);
+ if($input == NULL) return NULL;
+
+ $ret = QRsplit::splitStringToQRinput($string, $input, $hint, $casesensitive);
+ if($ret < 0) {
+ return NULL;
+ }
+
+ return $this->encodeInput($input);
+ }
+
+ //----------------------------------------------------------------------
+ public static function png($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4, $saveandprint=false)
+ {
+ $enc = QRencode::factory($level, $size, $margin);
+ return $enc->encodePNG($text, $outfile, $saveandprint=false);
+ }
+
+ //----------------------------------------------------------------------
+ public static function text($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4)
+ {
+ $enc = QRencode::factory($level, $size, $margin);
+ return $enc->encode($text, $outfile);
+ }
+
+ //----------------------------------------------------------------------
+ public static function raw($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4)
+ {
+ $enc = QRencode::factory($level, $size, $margin);
+ return $enc->encodeRAW($text, $outfile);
+ }
+ }
+
+ //##########################################################################
+
+ class FrameFiller {
+
+ public $width;
+ public $frame;
+ public $x;
+ public $y;
+ public $dir;
+ public $bit;
+
+ //----------------------------------------------------------------------
+ public function __construct($width, &$frame)
+ {
+ $this->width = $width;
+ $this->frame = $frame;
+ $this->x = $width - 1;
+ $this->y = $width - 1;
+ $this->dir = -1;
+ $this->bit = -1;
+ }
+
+ //----------------------------------------------------------------------
+ public function setFrameAt($at, $val)
+ {
+ $this->frame[$at['y']][$at['x']] = chr($val);
+ }
+
+ //----------------------------------------------------------------------
+ public function getFrameAt($at)
+ {
+ return ord($this->frame[$at['y']][$at['x']]);
+ }
+
+ //----------------------------------------------------------------------
+ public function next()
+ {
+ do {
+
+ if($this->bit == -1) {
+ $this->bit = 0;
+ return array('x'=>$this->x, 'y'=>$this->y);
+ }
+
+ $x = $this->x;
+ $y = $this->y;
+ $w = $this->width;
+
+ if($this->bit == 0) {
+ $x--;
+ $this->bit++;
+ } else {
+ $x++;
+ $y += $this->dir;
+ $this->bit--;
+ }
+
+ if($this->dir < 0) {
+ if($y < 0) {
+ $y = 0;
+ $x -= 2;
+ $this->dir = 1;
+ if($x == 6) {
+ $x--;
+ $y = 9;
+ }
+ }
+ } else {
+ if($y == $w) {
+ $y = $w - 1;
+ $x -= 2;
+ $this->dir = -1;
+ if($x == 6) {
+ $x--;
+ $y -= 8;
+ }
+ }
+ }
+ if($x < 0 || $y < 0) return null;
+
+ $this->x = $x;
+ $this->y = $y;
+
+ } while(ord($this->frame[$y][$x]) & 0x80);
+
+ return array('x'=>$x, 'y'=>$y);
+ }
+
+ } ;
+
+ //##########################################################################
+
+ class QRencode {
+
+ public $casesensitive = true;
+ public $eightbit = false;
+
+ public $version = 0;
+ public $size = 3;
+ public $margin = 4;
+
+ public $structured = 0; // not supported yet
+
+ public $level = QR_ECLEVEL_L;
+ public $hint = QR_MODE_8;
+
+ //----------------------------------------------------------------------
+ public static function factory($level = QR_ECLEVEL_L, $size = 3, $margin = 4)
+ {
+ $enc = new QRencode();
+ $enc->size = $size;
+ $enc->margin = $margin;
+
+ switch ($level.'') {
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ $enc->level = $level;
+ break;
+ case 'l':
+ case 'L':
+ $enc->level = QR_ECLEVEL_L;
+ break;
+ case 'm':
+ case 'M':
+ $enc->level = QR_ECLEVEL_M;
+ break;
+ case 'q':
+ case 'Q':
+ $enc->level = QR_ECLEVEL_Q;
+ break;
+ case 'h':
+ case 'H':
+ $enc->level = QR_ECLEVEL_H;
+ break;
+ }
+
+ return $enc;
+ }
+
+ //----------------------------------------------------------------------
+ public function encodeRAW($intext, $outfile = false)
+ {
+ $code = new QRcode();
+
+ if($this->eightbit) {
+ $code->encodeString8bit($intext, $this->version, $this->level);
+ } else {
+ $code->encodeString($intext, $this->version, $this->level, $this->hint, $this->casesensitive);
+ }
+
+ return $code->data;
+ }
+
+ //----------------------------------------------------------------------
+ public function encode($intext, $outfile = false)
+ {
+ $code = new QRcode();
+
+ if($this->eightbit) {
+ $code->encodeString8bit($intext, $this->version, $this->level);
+ } else {
+ $code->encodeString($intext, $this->version, $this->level, $this->hint, $this->casesensitive);
+ }
+
+ QRtools::markTime('after_encode');
+
+ if ($outfile!== false) {
+ file_put_contents($outfile, join("\n", QRtools::binarize($code->data)));
+ } else {
+ return QRtools::binarize($code->data);
+ }
+ }
+
+ //----------------------------------------------------------------------
+ public function encodePNG($intext, $outfile = false,$saveandprint=false)
+ {
+ try {
+
+ ob_start();
+ $tab = $this->encode($intext);
+ $err = ob_get_contents();
+ ob_end_clean();
+
+ if ($err != '')
+ QRtools::log($outfile, $err);
+
+ $maxSize = (int)(QR_PNG_MAXIMUM_SIZE / (count($tab)+2*$this->margin));
+
+ QRimage::png($tab, $outfile, min(max(1, $this->size), $maxSize), $this->margin,$saveandprint);
+
+ } catch (Exception $e) {
+
+ QRtools::log($outfile, $e->getMessage());
+
+ }
+ }
+ }
+
+
diff --git a/pdf/phpqrcode/qrbitstream.php b/pdf/phpqrcode/qrbitstream.php
new file mode 100755
index 0000000..7d4ec4a
--- /dev/null
+++ b/pdf/phpqrcode/qrbitstream.php
@@ -0,0 +1,180 @@
+<?php
+/*
+ * PHP QR Code encoder
+ *
+ * Bitstream class
+ *
+ * Based on libqrencode C library distributed under LGPL 2.1
+ * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net>
+ *
+ * PHP QR Code is distributed under LGPL 3
+ * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+ class QRbitstream {
+
+ public $data = array();
+
+ //----------------------------------------------------------------------
+ public function size()
+ {
+ return count($this->data);
+ }
+
+ //----------------------------------------------------------------------
+ public function allocate($setLength)
+ {
+ $this->data = array_fill(0, $setLength, 0);
+ return 0;
+ }
+
+ //----------------------------------------------------------------------
+ public static function newFromNum($bits, $num)
+ {
+ $bstream = new QRbitstream();
+ $bstream->allocate($bits);
+
+ $mask = 1 << ($bits - 1);
+ for($i=0; $i<$bits; $i++) {
+ if($num & $mask) {
+ $bstream->data[$i] = 1;
+ } else {
+ $bstream->data[$i] = 0;
+ }
+ $mask = $mask >> 1;
+ }
+
+ return $bstream;
+ }
+
+ //----------------------------------------------------------------------
+ public static function newFromBytes($size, $data)
+ {
+ $bstream = new QRbitstream();
+ $bstream->allocate($size * 8);
+ $p=0;
+
+ for($i=0; $i<$size; $i++) {
+ $mask = 0x80;
+ for($j=0; $j<8; $j++) {
+ if($data[$i] & $mask) {
+ $bstream->data[$p] = 1;
+ } else {
+ $bstream->data[$p] = 0;
+ }
+ $p++;
+ $mask = $mask >> 1;
+ }
+ }
+
+ return $bstream;
+ }
+
+ //----------------------------------------------------------------------
+ public function append(QRbitstream $arg)
+ {
+ if (is_null($arg)) {
+ return -1;
+ }
+
+ if($arg->size() == 0) {
+ return 0;
+ }
+
+ if($this->size() == 0) {
+ $this->data = $arg->data;
+ return 0;
+ }
+
+ $this->data = array_values(array_merge($this->data, $arg->data));
+
+ return 0;
+ }
+
+ //----------------------------------------------------------------------
+ public function appendNum($bits, $num)
+ {
+ if ($bits == 0)
+ return 0;
+
+ $b = QRbitstream::newFromNum($bits, $num);
+
+ if(is_null($b))
+ return -1;
+
+ $ret = $this->append($b);
+ unset($b);
+
+ return $ret;
+ }
+
+ //----------------------------------------------------------------------
+ public function appendBytes($size, $data)
+ {
+ if ($size == 0)
+ return 0;
+
+ $b = QRbitstream::newFromBytes($size, $data);
+
+ if(is_null($b))
+ return -1;
+
+ $ret = $this->append($b);
+ unset($b);
+
+ return $ret;
+ }
+
+ //----------------------------------------------------------------------
+ public function toByte()
+ {
+
+ $size = $this->size();
+
+ if($size == 0) {
+ return array();
+ }
+
+ $data = array_fill(0, (int)(($size + 7) / 8), 0);
+ $bytes = (int)($size / 8);
+
+ $p = 0;
+
+ for($i=0; $i<$bytes; $i++) {
+ $v = 0;
+ for($j=0; $j<8; $j++) {
+ $v = $v << 1;
+ $v |= $this->data[$p];
+ $p++;
+ }
+ $data[$i] = $v;
+ }
+
+ if($size & 7) {
+ $v = 0;
+ for($j=0; $j<($size & 7); $j++) {
+ $v = $v << 1;
+ $v |= $this->data[$p];
+ $p++;
+ }
+ $data[$bytes] = $v;
+ }
+
+ return $data;
+ }
+
+ }
diff --git a/pdf/phpqrcode/qrconfig.php b/pdf/phpqrcode/qrconfig.php
new file mode 100755
index 0000000..e53dff8
--- /dev/null
+++ b/pdf/phpqrcode/qrconfig.php
@@ -0,0 +1,17 @@
+<?php
+/*
+ * PHP QR Code encoder
+ *
+ * Config file, feel free to modify
+ */
+
+ define('QR_CACHEABLE', true); // use cache - more disk reads but less CPU power, masks and format templates are stored there
+ define('QR_CACHE_DIR', dirname(__FILE__).DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR); // used when QR_CACHEABLE === true
+ define('QR_LOG_DIR', dirname(__FILE__).DIRECTORY_SEPARATOR); // default error logs dir
+
+ define('QR_FIND_BEST_MASK', true); // if true, estimates best mask (spec. default, but extremally slow; set to false to significant performance boost but (propably) worst quality code
+ define('QR_FIND_FROM_RANDOM', false); // if false, checks all masks available, otherwise value tells count of masks need to be checked, mask id are got randomly
+ define('QR_DEFAULT_MASK', 2); // when QR_FIND_BEST_MASK === false
+
+ define('QR_PNG_MAXIMUM_SIZE', 1024); // maximum allowed png image width (in pixels), tune to make sure GD and PHP can handle such big images
+ \ No newline at end of file
diff --git a/pdf/phpqrcode/qrconst.php b/pdf/phpqrcode/qrconst.php
new file mode 100755
index 0000000..9fac9fd
--- /dev/null
+++ b/pdf/phpqrcode/qrconst.php
@@ -0,0 +1,54 @@
+<?php
+
+/*
+ * PHP QR Code encoder
+ *
+ * Common constants
+ *
+ * Based on libqrencode C library distributed under LGPL 2.1
+ * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net>
+ *
+ * PHP QR Code is distributed under LGPL 3
+ * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+ // Encoding modes
+
+ define('QR_MODE_NUL', -1);
+ define('QR_MODE_NUM', 0);
+ define('QR_MODE_AN', 1);
+ define('QR_MODE_8', 2);
+ define('QR_MODE_KANJI', 3);
+ define('QR_MODE_STRUCTURE', 4);
+
+ // Levels of error correction.
+
+ define('QR_ECLEVEL_L', 0);
+ define('QR_ECLEVEL_M', 1);
+ define('QR_ECLEVEL_Q', 2);
+ define('QR_ECLEVEL_H', 3);
+
+ // Supported output formats
+
+ define('QR_FORMAT_TEXT', 0);
+ define('QR_FORMAT_PNG', 1);
+
+ class qrstr {
+ public static function set(&$srctab, $x, $y, $repl, $replLen = false) {
+ $srctab[$y] = substr_replace($srctab[$y], ($replLen !== false)?substr($repl,0,$replLen):$repl, $x, ($replLen !== false)?$replLen:strlen($repl));
+ }
+ } \ No newline at end of file
diff --git a/pdf/phpqrcode/qrencode.php b/pdf/phpqrcode/qrencode.php
new file mode 100755
index 0000000..4b77a5b
--- /dev/null
+++ b/pdf/phpqrcode/qrencode.php
@@ -0,0 +1,502 @@
+<?php
+/*
+ * PHP QR Code encoder
+ *
+ * Main encoder classes.
+ *
+ * Based on libqrencode C library distributed under LGPL 2.1
+ * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net>
+ *
+ * PHP QR Code is distributed under LGPL 3
+ * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+ class QRrsblock {
+ public $dataLength;
+ public $data = array();
+ public $eccLength;
+ public $ecc = array();
+
+ public function __construct($dl, $data, $el, &$ecc, QRrsItem $rs)
+ {
+ $rs->encode_rs_char($data, $ecc);
+
+ $this->dataLength = $dl;
+ $this->data = $data;
+ $this->eccLength = $el;
+ $this->ecc = $ecc;
+ }
+ };
+
+ //##########################################################################
+
+ class QRrawcode {
+ public $version;
+ public $datacode = array();
+ public $ecccode = array();
+ public $blocks;
+ public $rsblocks = array(); //of RSblock
+ public $count;
+ public $dataLength;
+ public $eccLength;
+ public $b1;
+
+ //----------------------------------------------------------------------
+ public function __construct(QRinput $input)
+ {
+ $spec = array(0,0,0,0,0);
+
+ $this->datacode = $input->getByteStream();
+ if(is_null($this->datacode)) {
+ throw new Exception('null imput string');
+ }
+
+ QRspec::getEccSpec($input->getVersion(), $input->getErrorCorrectionLevel(), $spec);
+
+ $this->version = $input->getVersion();
+ $this->b1 = QRspec::rsBlockNum1($spec);
+ $this->dataLength = QRspec::rsDataLength($spec);
+ $this->eccLength = QRspec::rsEccLength($spec);
+ $this->ecccode = array_fill(0, $this->eccLength, 0);
+ $this->blocks = QRspec::rsBlockNum($spec);
+
+ $ret = $this->init($spec);
+ if($ret < 0) {
+ throw new Exception('block alloc error');
+ return null;
+ }
+
+ $this->count = 0;
+ }
+
+ //----------------------------------------------------------------------
+ public function init(array $spec)
+ {
+ $dl = QRspec::rsDataCodes1($spec);
+ $el = QRspec::rsEccCodes1($spec);
+ $rs = QRrs::init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el);
+
+
+ $blockNo = 0;
+ $dataPos = 0;
+ $eccPos = 0;
+ for($i=0; $i<QRspec::rsBlockNum1($spec); $i++) {
+ $ecc = array_slice($this->ecccode,$eccPos);
+ $this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el, $ecc, $rs);
+ $this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc);
+
+ $dataPos += $dl;
+ $eccPos += $el;
+ $blockNo++;
+ }
+
+ if(QRspec::rsBlockNum2($spec) == 0)
+ return 0;
+
+ $dl = QRspec::rsDataCodes2($spec);
+ $el = QRspec::rsEccCodes2($spec);
+ $rs = QRrs::init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el);
+
+ if($rs == NULL) return -1;
+
+ for($i=0; $i<QRspec::rsBlockNum2($spec); $i++) {
+ $ecc = array_slice($this->ecccode,$eccPos);
+ $this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el, $ecc, $rs);
+ $this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc);
+
+ $dataPos += $dl;
+ $eccPos += $el;
+ $blockNo++;
+ }
+
+ return 0;
+ }
+
+ //----------------------------------------------------------------------
+ public function getCode()
+ {
+ $ret;
+
+ if($this->count < $this->dataLength) {
+ $row = $this->count % $this->blocks;
+ $col = $this->count / $this->blocks;
+ if($col >= $this->rsblocks[0]->dataLength) {
+ $row += $this->b1;
+ }
+ $ret = $this->rsblocks[$row]->data[$col];
+ } else if($this->count < $this->dataLength + $this->eccLength) {
+ $row = ($this->count - $this->dataLength) % $this->blocks;
+ $col = ($this->count - $this->dataLength) / $this->blocks;
+ $ret = $this->rsblocks[$row]->ecc[$col];
+ } else {
+ return 0;
+ }
+ $this->count++;
+
+ return $ret;
+ }
+ }
+
+ //##########################################################################
+
+ class QRcode {
+
+ public $version;
+ public $width;
+ public $data;
+
+ //----------------------------------------------------------------------
+ public function encodeMask(QRinput $input, $mask)
+ {
+ if($input->getVersion() < 0 || $input->getVersion() > QRSPEC_VERSION_MAX) {
+ throw new Exception('wrong version');
+ }
+ if($input->getErrorCorrectionLevel() > QR_ECLEVEL_H) {
+ throw new Exception('wrong level');
+ }
+
+ $raw = new QRrawcode($input);
+
+ QRtools::markTime('after_raw');
+
+ $version = $raw->version;
+ $width = QRspec::getWidth($version);
+ $frame = QRspec::newFrame($version);
+
+ $filler = new FrameFiller($width, $frame);
+ if(is_null($filler)) {
+ return NULL;
+ }
+
+ // inteleaved data and ecc codes
+ for($i=0; $i<$raw->dataLength + $raw->eccLength; $i++) {
+ $code = $raw->getCode();
+ $bit = 0x80;
+ for($j=0; $j<8; $j++) {
+ $addr = $filler->next();
+ $filler->setFrameAt($addr, 0x02 | (($bit & $code) != 0));
+ $bit = $bit >> 1;
+ }
+ }
+
+ QRtools::markTime('after_filler');
+
+ unset($raw);
+
+ // remainder bits
+ $j = QRspec::getRemainder($version);
+ for($i=0; $i<$j; $i++) {
+ $addr = $filler->next();
+ $filler->setFrameAt($addr, 0x02);
+ }
+
+ $frame = $filler->frame;
+ unset($filler);
+
+
+ // masking
+ $maskObj = new QRmask();
+ if($mask < 0) {
+
+ if (QR_FIND_BEST_MASK) {
+ $masked = $maskObj->mask($width, $frame, $input->getErrorCorrectionLevel());
+ } else {
+ $masked = $maskObj->makeMask($width, $frame, (intval(QR_DEFAULT_MASK) % 8), $input->getErrorCorrectionLevel());
+ }
+ } else {
+ $masked = $maskObj->makeMask($width, $frame, $mask, $input->getErrorCorrectionLevel());
+ }
+
+ if($masked == NULL) {
+ return NULL;
+ }
+
+ QRtools::markTime('after_mask');
+
+ $this->version = $version;
+ $this->width = $width;
+ $this->data = $masked;
+
+ return $this;
+ }
+
+ //----------------------------------------------------------------------
+ public function encodeInput(QRinput $input)
+ {
+ return $this->encodeMask($input, -1);
+ }
+
+ //----------------------------------------------------------------------
+ public function encodeString8bit($string, $version, $level)
+ {
+ if(string == NULL) {
+ throw new Exception('empty string!');
+ return NULL;
+ }
+
+ $input = new QRinput($version, $level);
+ if($input == NULL) return NULL;
+
+ $ret = $input->append($input, QR_MODE_8, strlen($string), str_split($string));
+ if($ret < 0) {
+ unset($input);
+ return NULL;
+ }
+ return $this->encodeInput($input);
+ }
+
+ //----------------------------------------------------------------------
+ public function encodeString($string, $version, $level, $hint, $casesensitive)
+ {
+
+ if($hint != QR_MODE_8 && $hint != QR_MODE_KANJI) {
+ throw new Exception('bad hint');
+ return NULL;
+ }
+
+ $input = new QRinput($version, $level);
+ if($input == NULL) return NULL;
+
+ $ret = QRsplit::splitStringToQRinput($string, $input, $hint, $casesensitive);
+ if($ret < 0) {
+ return NULL;
+ }
+
+ return $this->encodeInput($input);
+ }
+
+ //----------------------------------------------------------------------
+ public static function png($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4, $saveandprint=false)
+ {
+ $enc = QRencode::factory($level, $size, $margin);
+ return $enc->encodePNG($text, $outfile, $saveandprint=false);
+ }
+
+ //----------------------------------------------------------------------
+ public static function text($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4)
+ {
+ $enc = QRencode::factory($level, $size, $margin);
+ return $enc->encode($text, $outfile);
+ }
+
+ //----------------------------------------------------------------------
+ public static function raw($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4)
+ {
+ $enc = QRencode::factory($level, $size, $margin);
+ return $enc->encodeRAW($text, $outfile);
+ }
+ }
+
+ //##########################################################################
+
+ class FrameFiller {
+
+ public $width;
+ public $frame;
+ public $x;
+ public $y;
+ public $dir;
+ public $bit;
+
+ //----------------------------------------------------------------------
+ public function __construct($width, &$frame)
+ {
+ $this->width = $width;
+ $this->frame = $frame;
+ $this->x = $width - 1;
+ $this->y = $width - 1;
+ $this->dir = -1;
+ $this->bit = -1;
+ }
+
+ //----------------------------------------------------------------------
+ public function setFrameAt($at, $val)
+ {
+ $this->frame[$at['y']][$at['x']] = chr($val);
+ }
+
+ //----------------------------------------------------------------------
+ public function getFrameAt($at)
+ {
+ return ord($this->frame[$at['y']][$at['x']]);
+ }
+
+ //----------------------------------------------------------------------
+ public function next()
+ {
+ do {
+
+ if($this->bit == -1) {
+ $this->bit = 0;
+ return array('x'=>$this->x, 'y'=>$this->y);
+ }
+
+ $x = $this->x;
+ $y = $this->y;
+ $w = $this->width;
+
+ if($this->bit == 0) {
+ $x--;
+ $this->bit++;
+ } else {
+ $x++;
+ $y += $this->dir;
+ $this->bit--;
+ }
+
+ if($this->dir < 0) {
+ if($y < 0) {
+ $y = 0;
+ $x -= 2;
+ $this->dir = 1;
+ if($x == 6) {
+ $x--;
+ $y = 9;
+ }
+ }
+ } else {
+ if($y == $w) {
+ $y = $w - 1;
+ $x -= 2;
+ $this->dir = -1;
+ if($x == 6) {
+ $x--;
+ $y -= 8;
+ }
+ }
+ }
+ if($x < 0 || $y < 0) return null;
+
+ $this->x = $x;
+ $this->y = $y;
+
+ } while(ord($this->frame[$y][$x]) & 0x80);
+
+ return array('x'=>$x, 'y'=>$y);
+ }
+
+ } ;
+
+ //##########################################################################
+
+ class QRencode {
+
+ public $casesensitive = true;
+ public $eightbit = false;
+
+ public $version = 0;
+ public $size = 3;
+ public $margin = 4;
+
+ public $structured = 0; // not supported yet
+
+ public $level = QR_ECLEVEL_L;
+ public $hint = QR_MODE_8;
+
+ //----------------------------------------------------------------------
+ public static function factory($level = QR_ECLEVEL_L, $size = 3, $margin = 4)
+ {
+ $enc = new QRencode();
+ $enc->size = $size;
+ $enc->margin = $margin;
+
+ switch ($level.'') {
+ case '0':
+ case '1':
+ case '2':
+ case '3':
+ $enc->level = $level;
+ break;
+ case 'l':
+ case 'L':
+ $enc->level = QR_ECLEVEL_L;
+ break;
+ case 'm':
+ case 'M':
+ $enc->level = QR_ECLEVEL_M;
+ break;
+ case 'q':
+ case 'Q':
+ $enc->level = QR_ECLEVEL_Q;
+ break;
+ case 'h':
+ case 'H':
+ $enc->level = QR_ECLEVEL_H;
+ break;
+ }
+
+ return $enc;
+ }
+
+ //----------------------------------------------------------------------
+ public function encodeRAW($intext, $outfile = false)
+ {
+ $code = new QRcode();
+
+ if($this->eightbit) {
+ $code->encodeString8bit($intext, $this->version, $this->level);
+ } else {
+ $code->encodeString($intext, $this->version, $this->level, $this->hint, $this->casesensitive);
+ }
+
+ return $code->data;
+ }
+
+ //----------------------------------------------------------------------
+ public function encode($intext, $outfile = false)
+ {
+ $code = new QRcode();
+
+ if($this->eightbit) {
+ $code->encodeString8bit($intext, $this->version, $this->level);
+ } else {
+ $code->encodeString($intext, $this->version, $this->level, $this->hint, $this->casesensitive);
+ }
+
+ QRtools::markTime('after_encode');
+
+ if ($outfile!== false) {
+ file_put_contents($outfile, join("\n", QRtools::binarize($code->data)));
+ } else {
+ return QRtools::binarize($code->data);
+ }
+ }
+
+ //----------------------------------------------------------------------
+ public function encodePNG($intext, $outfile = false,$saveandprint=false)
+ {
+ try {
+
+ ob_start();
+ $tab = $this->encode($intext);
+ $err = ob_get_contents();
+ ob_end_clean();
+
+ if ($err != '')
+ QRtools::log($outfile, $err);
+
+ $maxSize = (int)(QR_PNG_MAXIMUM_SIZE / (count($tab)+2*$this->margin));
+
+ QRimage::png($tab, $outfile, min(max(1, $this->size), $maxSize), $this->margin,$saveandprint);
+
+ } catch (Exception $e) {
+
+ QRtools::log($outfile, $e->getMessage());
+
+ }
+ }
+ }
diff --git a/pdf/phpqrcode/qrimage.php b/pdf/phpqrcode/qrimage.php
new file mode 100755
index 0000000..10b0a6e
--- /dev/null
+++ b/pdf/phpqrcode/qrimage.php
@@ -0,0 +1,95 @@
+<?php
+/*
+ * PHP QR Code encoder
+ *
+ * Image output of code using GD2
+ *
+ * PHP QR Code is distributed under LGPL 3
+ * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+ define('QR_IMAGE', true);
+
+ class QRimage {
+
+ //----------------------------------------------------------------------
+ public static function png($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4,$saveandprint=FALSE)
+ {
+ $image = self::image($frame, $pixelPerPoint, $outerFrame);
+
+ if ($filename === false) {
+ Header("Content-type: image/png");
+ ImagePng($image);
+ } else {
+ if($saveandprint===TRUE){
+ ImagePng($image, $filename);
+ header("Content-type: image/png");
+ ImagePng($image);
+ }else{
+ ImagePng($image, $filename);
+ }
+ }
+
+ ImageDestroy($image);
+ }
+
+ //----------------------------------------------------------------------
+ public static function jpg($frame, $filename = false, $pixelPerPoint = 8, $outerFrame = 4, $q = 85)
+ {
+ $image = self::image($frame, $pixelPerPoint, $outerFrame);
+
+ if ($filename === false) {
+ Header("Content-type: image/jpeg");
+ ImageJpeg($image, null, $q);
+ } else {
+ ImageJpeg($image, $filename, $q);
+ }
+
+ ImageDestroy($image);
+ }
+
+ //----------------------------------------------------------------------
+ private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4)
+ {
+ $h = count($frame);
+ $w = strlen($frame[0]);
+
+ $imgW = $w + 2*$outerFrame;
+ $imgH = $h + 2*$outerFrame;
+
+ $base_image =ImageCreate($imgW, $imgH);
+
+ $col[0] = ImageColorAllocate($base_image,255,255,255);
+ $col[1] = ImageColorAllocate($base_image,0,0,0);
+
+ imagefill($base_image, 0, 0, $col[0]);
+
+ for($y=0; $y<$h; $y++) {
+ for($x=0; $x<$w; $x++) {
+ if ($frame[$y][$x] == '1') {
+ ImageSetPixel($base_image,$x+$outerFrame,$y+$outerFrame,$col[1]);
+ }
+ }
+ }
+
+ $target_image =ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint);
+ ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH);
+ ImageDestroy($base_image);
+
+ return $target_image;
+ }
+ } \ No newline at end of file
diff --git a/pdf/phpqrcode/qrinput.php b/pdf/phpqrcode/qrinput.php
new file mode 100755
index 0000000..0f6d7f9
--- /dev/null
+++ b/pdf/phpqrcode/qrinput.php
@@ -0,0 +1,729 @@
+<?php
+/*
+ * PHP QR Code encoder
+ *
+ * Input encoding class
+ *
+ * Based on libqrencode C library distributed under LGPL 2.1
+ * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net>
+ *
+ * PHP QR Code is distributed under LGPL 3
+ * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+ define('STRUCTURE_HEADER_BITS', 20);
+ define('MAX_STRUCTURED_SYMBOLS', 16);
+
+ class QRinputItem {
+
+ public $mode;
+ public $size;
+ public $data;
+ public $bstream;
+
+ public function __construct($mode, $size, $data, $bstream = null)
+ {
+ $setData = array_slice($data, 0, $size);
+
+ if (count($setData) < $size) {
+ $setData = array_merge($setData, array_fill(0,$size-count($setData),0));
+ }
+
+ if(!QRinput::check($mode, $size, $setData)) {
+ throw new Exception('Error m:'.$mode.',s:'.$size.',d:'.join(',',$setData));
+ return null;
+ }
+
+ $this->mode = $mode;
+ $this->size = $size;
+ $this->data = $setData;
+ $this->bstream = $bstream;
+ }
+
+ //----------------------------------------------------------------------
+ public function encodeModeNum($version)
+ {
+ try {
+
+ $words = (int)($this->size / 3);
+ $bs = new QRbitstream();
+
+ $val = 0x1;
+ $bs->appendNum(4, $val);
+ $bs->appendNum(QRspec::lengthIndicator(QR_MODE_NUM, $version), $this->size);
+
+ for($i=0; $i<$words; $i++) {
+ $val = (ord($this->data[$i*3 ]) - ord('0')) * 100;
+ $val += (ord($this->data[$i*3+1]) - ord('0')) * 10;
+ $val += (ord($this->data[$i*3+2]) - ord('0'));
+ $bs->appendNum(10, $val);
+ }
+
+ if($this->size - $words * 3 == 1) {
+ $val = ord($this->data[$words*3]) - ord('0');
+ $bs->appendNum(4, $val);
+ } else if($this->size - $words * 3 == 2) {
+ $val = (ord($this->data[$words*3 ]) - ord('0')) * 10;
+ $val += (ord($this->data[$words*3+1]) - ord('0'));
+ $bs->appendNum(7, $val);
+ }
+
+ $this->bstream = $bs;
+ return 0;
+
+ } catch (Exception $e) {
+ return -1;
+ }
+ }
+
+ //----------------------------------------------------------------------
+ public function encodeModeAn($version)
+ {
+ try {
+ $words = (int)($this->size / 2);
+ $bs = new QRbitstream();
+
+ $bs->appendNum(4, 0x02);
+ $bs->appendNum(QRspec::lengthIndicator(QR_MODE_AN, $version), $this->size);
+
+ for($i=0; $i<$words; $i++) {
+ $val = (int)QRinput::lookAnTable(ord($this->data[$i*2 ])) * 45;
+ $val += (int)QRinput::lookAnTable(ord($this->data[$i*2+1]));
+
+ $bs->appendNum(11, $val);
+ }
+
+ if($this->size & 1) {
+ $val = QRinput::lookAnTable(ord($this->data[$words * 2]));
+ $bs->appendNum(6, $val);
+ }
+
+ $this->bstream = $bs;
+ return 0;
+
+ } catch (Exception $e) {
+ return -1;
+ }
+ }
+
+ //----------------------------------------------------------------------
+ public function encodeMode8($version)
+ {
+ try {
+ $bs = new QRbitstream();
+
+ $bs->appendNum(4, 0x4);
+ $bs->appendNum(QRspec::lengthIndicator(QR_MODE_8, $version), $this->size);
+
+ for($i=0; $i<$this->size; $i++) {
+ $bs->appendNum(8, ord($this->data[$i]));
+ }
+
+ $this->bstream = $bs;
+ return 0;
+
+ } catch (Exception $e) {
+ return -1;
+ }
+ }
+
+ //----------------------------------------------------------------------
+ public function encodeModeKanji($version)
+ {
+ try {
+
+ $bs = new QRbitrtream();
+
+ $bs->appendNum(4, 0x8);
+ $bs->appendNum(QRspec::lengthIndicator(QR_MODE_KANJI, $version), (int)($this->size / 2));
+
+ for($i=0; $i<$this->size; $i+=2) {
+ $val = (ord($this->data[$i]) << 8) | ord($this->data[$i+1]);
+ if($val <= 0x9ffc) {
+ $val -= 0x8140;
+ } else {
+ $val -= 0xc140;
+ }
+
+ $h = ($val >> 8) * 0xc0;
+ $val = ($val & 0xff) + $h;
+
+ $bs->appendNum(13, $val);
+ }
+
+ $this->bstream = $bs;
+ return 0;
+
+ } catch (Exception $e) {
+ return -1;
+ }
+ }
+
+ //----------------------------------------------------------------------
+ public function encodeModeStructure()
+ {
+ try {
+ $bs = new QRbitstream();
+
+ $bs->appendNum(4, 0x03);
+ $bs->appendNum(4, ord($this->data[1]) - 1);
+ $bs->appendNum(4, ord($this->data[0]) - 1);
+ $bs->appendNum(8, ord($this->data[2]));
+
+ $this->bstream = $bs;
+ return 0;
+
+ } catch (Exception $e) {
+ return -1;
+ }
+ }
+
+ //----------------------------------------------------------------------
+ public function estimateBitStreamSizeOfEntry($version)
+ {
+ $bits = 0;
+
+ if($version == 0)
+ $version = 1;
+
+ switch($this->mode) {
+ case QR_MODE_NUM: $bits = QRinput::estimateBitsModeNum($this->size); break;
+ case QR_MODE_AN: $bits = QRinput::estimateBitsModeAn($this->size); break;
+ case QR_MODE_8: $bits = QRinput::estimateBitsMode8($this->size); break;
+ case QR_MODE_KANJI: $bits = QRinput::estimateBitsModeKanji($this->size);break;
+ case QR_MODE_STRUCTURE: return STRUCTURE_HEADER_BITS;
+ default:
+ return 0;
+ }
+
+ $l = QRspec::lengthIndicator($this->mode, $version);
+ $m = 1 << $l;
+ $num = (int)(($this->size + $m - 1) / $m);
+
+ $bits += $num * (4 + $l);
+
+ return $bits;
+ }
+
+ //----------------------------------------------------------------------
+ public function encodeBitStream($version)
+ {
+ try {
+
+ unset($this->bstream);
+ $words = QRspec::maximumWords($this->mode, $version);
+
+ if($this->size > $words) {
+
+ $st1 = new QRinputItem($this->mode, $words, $this->data);
+ $st2 = new QRinputItem($this->mode, $this->size - $words, array_slice($this->data, $words));
+
+ $st1->encodeBitStream($version);
+ $st2->encodeBitStream($version);
+
+ $this->bstream = new QRbitstream();
+ $this->bstream->append($st1->bstream);
+ $this->bstream->append($st2->bstream);
+
+ unset($st1);
+ unset($st2);
+
+ } else {
+
+ $ret = 0;
+
+ switch($this->mode) {
+ case QR_MODE_NUM: $ret = $this->encodeModeNum($version); break;
+ case QR_MODE_AN: $ret = $this->encodeModeAn($version); break;
+ case QR_MODE_8: $ret = $this->encodeMode8($version); break;
+ case QR_MODE_KANJI: $ret = $this->encodeModeKanji($version);break;
+ case QR_MODE_STRUCTURE: $ret = $this->encodeModeStructure(); break;
+
+ default:
+ break;
+ }
+
+ if($ret < 0)
+ return -1;
+ }
+
+ return $this->bstream->size();
+
+ } catch (Exception $e) {
+ return -1;
+ }
+ }
+ };
+
+ //##########################################################################
+
+ class QRinput {
+
+ public $items;
+
+ private $version;
+ private $level;
+
+ //----------------------------------------------------------------------
+ public function __construct($version = 0, $level = QR_ECLEVEL_L)
+ {
+ if ($version < 0 || $version > QRSPEC_VERSION_MAX || $level > QR_ECLEVEL_H) {
+ throw new Exception('Invalid version no');
+ return NULL;
+ }
+
+ $this->version = $version;
+ $this->level = $level;
+ }
+
+ //----------------------------------------------------------------------
+ public function getVersion()
+ {
+ return $this->version;
+ }
+
+ //----------------------------------------------------------------------
+ public function setVersion($version)
+ {
+ if($version < 0 || $version > QRSPEC_VERSION_MAX) {
+ throw new Exception('Invalid version no');
+ return -1;
+ }
+
+ $this->version = $version;
+
+ return 0;
+ }
+
+ //----------------------------------------------------------------------
+ public function getErrorCorrectionLevel()
+ {
+ return $this->level;
+ }
+
+ //----------------------------------------------------------------------
+ public function setErrorCorrectionLevel($level)
+ {
+ if($level > QR_ECLEVEL_H) {
+ throw new Exception('Invalid ECLEVEL');
+ return -1;
+ }
+
+ $this->level = $level;
+
+ return 0;
+ }
+
+ //----------------------------------------------------------------------
+ public function appendEntry(QRinputItem $entry)
+ {
+ $this->items[] = $entry;
+ }
+
+ //----------------------------------------------------------------------
+ public function append($mode, $size, $data)
+ {
+ try {
+ $entry = new QRinputItem($mode, $size, $data);
+ $this->items[] = $entry;
+ return 0;
+ } catch (Exception $e) {
+ return -1;
+ }
+ }
+
+ //----------------------------------------------------------------------
+
+ public function insertStructuredAppendHeader($size, $index, $parity)
+ {
+ if( $size > MAX_STRUCTURED_SYMBOLS ) {
+ throw new Exception('insertStructuredAppendHeader wrong size');
+ }
+
+ if( $index <= 0 || $index > MAX_STRUCTURED_SYMBOLS ) {
+ throw new Exception('insertStructuredAppendHeader wrong index');
+ }
+
+ $buf = array($size, $index, $parity);
+
+ try {
+ $entry = new QRinputItem(QR_MODE_STRUCTURE, 3, buf);
+ array_unshift($this->items, $entry);
+ return 0;
+ } catch (Exception $e) {
+ return -1;
+ }
+ }
+
+ //----------------------------------------------------------------------
+ public function calcParity()
+ {
+ $parity = 0;
+
+ foreach($this->items as $item) {
+ if($item->mode != QR_MODE_STRUCTURE) {
+ for($i=$item->size-1; $i>=0; $i--) {
+ $parity ^= $item->data[$i];
+ }
+ }
+ }
+
+ return $parity;
+ }
+
+ //----------------------------------------------------------------------
+ public static function checkModeNum($size, $data)
+ {
+ for($i=0; $i<$size; $i++) {
+ if((ord($data[$i]) < ord('0')) || (ord($data[$i]) > ord('9'))){
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ //----------------------------------------------------------------------
+ public static function estimateBitsModeNum($size)
+ {
+ $w = (int)$size / 3;
+ $bits = $w * 10;
+
+ switch($size - $w * 3) {
+ case 1:
+ $bits += 4;
+ break;
+ case 2:
+ $bits += 7;
+ break;
+ default:
+ break;
+ }
+
+ return $bits;
+ }
+
+ //----------------------------------------------------------------------
+ public static $anTable = array(
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ 36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43,
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1,
+ -1, 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, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
+ );
+
+ //----------------------------------------------------------------------
+ public static function lookAnTable($c)
+ {
+ return (($c > 127)?-1:self::$anTable[$c]);
+ }
+
+ //----------------------------------------------------------------------
+ public static function checkModeAn($size, $data)
+ {
+ for($i=0; $i<$size; $i++) {
+ if (self::lookAnTable(ord($data[$i])) == -1) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ //----------------------------------------------------------------------
+ public static function estimateBitsModeAn($size)
+ {
+ $w = (int)($size / 2);
+ $bits = $w * 11;
+
+ if($size & 1) {
+ $bits += 6;
+ }
+
+ return $bits;
+ }
+
+ //----------------------------------------------------------------------
+ public static function estimateBitsMode8($size)
+ {
+ return $size * 8;
+ }
+
+ //----------------------------------------------------------------------
+ public function estimateBitsModeKanji($size)
+ {
+ return (int)(($size / 2) * 13);
+ }
+
+ //----------------------------------------------------------------------
+ public static function checkModeKanji($size, $data)
+ {
+ if($size & 1)
+ return false;
+
+ for($i=0; $i<$size; $i+=2) {
+ $val = (ord($data[$i]) << 8) | ord($data[$i+1]);
+ if( $val < 0x8140
+ || ($val > 0x9ffc && $val < 0xe040)
+ || $val > 0xebbf) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ /***********************************************************************
+ * Validation
+ **********************************************************************/
+
+ public static function check($mode, $size, $data)
+ {
+ if($size <= 0)
+ return false;
+
+ switch($mode) {
+ case QR_MODE_NUM: return self::checkModeNum($size, $data); break;
+ case QR_MODE_AN: return self::checkModeAn($size, $data); break;
+ case QR_MODE_KANJI: return self::checkModeKanji($size, $data); break;
+ case QR_MODE_8: return true; break;
+ case QR_MODE_STRUCTURE: return true; break;
+
+ default:
+ break;
+ }
+
+ return false;
+ }
+
+
+ //----------------------------------------------------------------------
+ public function estimateBitStreamSize($version)
+ {
+ $bits = 0;
+
+ foreach($this->items as $item) {
+ $bits += $item->estimateBitStreamSizeOfEntry($version);
+ }
+
+ return $bits;
+ }
+
+ //----------------------------------------------------------------------
+ public function estimateVersion()
+ {
+ $version = 0;
+ $prev = 0;
+ do {
+ $prev = $version;
+ $bits = $this->estimateBitStreamSize($prev);
+ $version = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level);
+ if ($version < 0) {
+ return -1;
+ }
+ } while ($version > $prev);
+
+ return $version;
+ }
+
+ //----------------------------------------------------------------------
+ public static function lengthOfCode($mode, $version, $bits)
+ {
+ $payload = $bits - 4 - QRspec::lengthIndicator($mode, $version);
+ switch($mode) {
+ case QR_MODE_NUM:
+ $chunks = (int)($payload / 10);
+ $remain = $payload - $chunks * 10;
+ $size = $chunks * 3;
+ if($remain >= 7) {
+ $size += 2;
+ } else if($remain >= 4) {
+ $size += 1;
+ }
+ break;
+ case QR_MODE_AN:
+ $chunks = (int)($payload / 11);
+ $remain = $payload - $chunks * 11;
+ $size = $chunks * 2;
+ if($remain >= 6)
+ $size++;
+ break;
+ case QR_MODE_8:
+ $size = (int)($payload / 8);
+ break;
+ case QR_MODE_KANJI:
+ $size = (int)(($payload / 13) * 2);
+ break;
+ case QR_MODE_STRUCTURE:
+ $size = (int)($payload / 8);
+ break;
+ default:
+ $size = 0;
+ break;
+ }
+
+ $maxsize = QRspec::maximumWords($mode, $version);
+ if($size < 0) $size = 0;
+ if($size > $maxsize) $size = $maxsize;
+
+ return $size;
+ }
+
+ //----------------------------------------------------------------------
+ public function createBitStream()
+ {
+ $total = 0;
+
+ foreach($this->items as $item) {
+ $bits = $item->encodeBitStream($this->version);
+
+ if($bits < 0)
+ return -1;
+
+ $total += $bits;
+ }
+
+ return $total;
+ }
+
+ //----------------------------------------------------------------------
+ public function convertData()
+ {
+ $ver = $this->estimateVersion();
+ if($ver > $this->getVersion()) {
+ $this->setVersion($ver);
+ }
+
+ for(;;) {
+ $bits = $this->createBitStream();
+
+ if($bits < 0)
+ return -1;
+
+ $ver = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level);
+ if($ver < 0) {
+ throw new Exception('WRONG VERSION');
+ return -1;
+ } else if($ver > $this->getVersion()) {
+ $this->setVersion($ver);
+ } else {
+ break;
+ }
+ }
+
+ return 0;
+ }
+
+ //----------------------------------------------------------------------
+ public function appendPaddingBit(&$bstream)
+ {
+ $bits = $bstream->size();
+ $maxwords = QRspec::getDataLength($this->version, $this->level);
+ $maxbits = $maxwords * 8;
+
+ if ($maxbits == $bits) {
+ return 0;
+ }
+
+ if ($maxbits - $bits < 5) {
+ return $bstream->appendNum($maxbits - $bits, 0);
+ }
+
+ $bits += 4;
+ $words = (int)(($bits + 7) / 8);
+
+ $padding = new QRbitstream();
+ $ret = $padding->appendNum($words * 8 - $bits + 4, 0);
+
+ if($ret < 0)
+ return $ret;
+
+ $padlen = $maxwords - $words;
+
+ if($padlen > 0) {
+
+ $padbuf = array();
+ for($i=0; $i<$padlen; $i++) {
+ $padbuf[$i] = ($i&1)?0x11:0xec;
+ }
+
+ $ret = $padding->appendBytes($padlen, $padbuf);
+
+ if($ret < 0)
+ return $ret;
+
+ }
+
+ $ret = $bstream->append($padding);
+
+ return $ret;
+ }
+
+ //----------------------------------------------------------------------
+ public function mergeBitStream()
+ {
+ if($this->convertData() < 0) {
+ return null;
+ }
+
+ $bstream = new QRbitstream();
+
+ foreach($this->items as $item) {
+ $ret = $bstream->append($item->bstream);
+ if($ret < 0) {
+ return null;
+ }
+ }
+
+ return $bstream;
+ }
+
+ //----------------------------------------------------------------------
+ public function getBitStream()
+ {
+
+ $bstream = $this->mergeBitStream();
+
+ if($bstream == null) {
+ return null;
+ }
+
+ $ret = $this->appendPaddingBit($bstream);
+ if($ret < 0) {
+ return null;
+ }
+
+ return $bstream;
+ }
+
+ //----------------------------------------------------------------------
+ public function getByteStream()
+ {
+ $bstream = $this->getBitStream();
+ if($bstream == null) {
+ return null;
+ }
+
+ return $bstream->toByte();
+ }
+ }
+
+
+ \ No newline at end of file
diff --git a/pdf/phpqrcode/qrlib.php b/pdf/phpqrcode/qrlib.php
new file mode 100755
index 0000000..d55c4af
--- /dev/null
+++ b/pdf/phpqrcode/qrlib.php
@@ -0,0 +1,43 @@
+<?php
+/*
+ * PHP QR Code encoder
+ *
+ * Root library file, prepares environment and includes dependencies
+ *
+ * Based on libqrencode C library distributed under LGPL 2.1
+ * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net>
+ *
+ * PHP QR Code is distributed under LGPL 3
+ * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+ $QR_BASEDIR = dirname(__FILE__).DIRECTORY_SEPARATOR;
+
+ // Required libs
+
+ include $QR_BASEDIR."qrconst.php";
+ include $QR_BASEDIR."qrconfig.php";
+ include $QR_BASEDIR."qrtools.php";
+ include $QR_BASEDIR."qrspec.php";
+ include $QR_BASEDIR."qrimage.php";
+ include $QR_BASEDIR."qrinput.php";
+ include $QR_BASEDIR."qrbitstream.php";
+ include $QR_BASEDIR."qrsplit.php";
+ include $QR_BASEDIR."qrrscode.php";
+ include $QR_BASEDIR."qrmask.php";
+ include $QR_BASEDIR."qrencode.php";
+
diff --git a/pdf/phpqrcode/qrmask.php b/pdf/phpqrcode/qrmask.php
new file mode 100755
index 0000000..b14d7ae
--- /dev/null
+++ b/pdf/phpqrcode/qrmask.php
@@ -0,0 +1,328 @@
+<?php
+/*
+ * PHP QR Code encoder
+ *
+ * Masking
+ *
+ * Based on libqrencode C library distributed under LGPL 2.1
+ * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net>
+ *
+ * PHP QR Code is distributed under LGPL 3
+ * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+ define('N1', 3);
+ define('N2', 3);
+ define('N3', 40);
+ define('N4', 10);
+
+ class QRmask {
+
+ public $runLength = array();
+
+ //----------------------------------------------------------------------
+ public function __construct()
+ {
+ $this->runLength = array_fill(0, QRSPEC_WIDTH_MAX + 1, 0);
+ }
+
+ //----------------------------------------------------------------------
+ public function writeFormatInformation($width, &$frame, $mask, $level)
+ {
+ $blacks = 0;
+ $format = QRspec::getFormatInfo($mask, $level);
+
+ for($i=0; $i<8; $i++) {
+ if($format & 1) {
+ $blacks += 2;
+ $v = 0x85;
+ } else {
+ $v = 0x84;
+ }
+
+ $frame[8][$width - 1 - $i] = chr($v);
+ if($i < 6) {
+ $frame[$i][8] = chr($v);
+ } else {
+ $frame[$i + 1][8] = chr($v);
+ }
+ $format = $format >> 1;
+ }
+
+ for($i=0; $i<7; $i++) {
+ if($format & 1) {
+ $blacks += 2;
+ $v = 0x85;
+ } else {
+ $v = 0x84;
+ }
+
+ $frame[$width - 7 + $i][8] = chr($v);
+ if($i == 0) {
+ $frame[8][7] = chr($v);
+ } else {
+ $frame[8][6 - $i] = chr($v);
+ }
+
+ $format = $format >> 1;
+ }
+
+ return $blacks;
+ }
+
+ //----------------------------------------------------------------------
+ public function mask0($x, $y) { return ($x+$y)&1; }
+ public function mask1($x, $y) { return ($y&1); }
+ public function mask2($x, $y) { return ($x%3); }
+ public function mask3($x, $y) { return ($x+$y)%3; }
+ public function mask4($x, $y) { return (((int)($y/2))+((int)($x/3)))&1; }
+ public function mask5($x, $y) { return (($x*$y)&1)+($x*$y)%3; }
+ public function mask6($x, $y) { return ((($x*$y)&1)+($x*$y)%3)&1; }
+ public function mask7($x, $y) { return ((($x*$y)%3)+(($x+$y)&1))&1; }
+
+ //----------------------------------------------------------------------
+ private function generateMaskNo($maskNo, $width, $frame)
+ {
+ $bitMask = array_fill(0, $width, array_fill(0, $width, 0));
+
+ for($y=0; $y<$width; $y++) {
+ for($x=0; $x<$width; $x++) {
+ if(ord($frame[$y][$x]) & 0x80) {
+ $bitMask[$y][$x] = 0;
+ } else {
+ $maskFunc = call_user_func(array($this, 'mask'.$maskNo), $x, $y);
+ $bitMask[$y][$x] = ($maskFunc == 0)?1:0;
+ }
+
+ }
+ }
+
+ return $bitMask;
+ }
+
+ //----------------------------------------------------------------------
+ public static function serial($bitFrame)
+ {
+ $codeArr = array();
+
+ foreach ($bitFrame as $line)
+ $codeArr[] = join('', $line);
+
+ return gzcompress(join("\n", $codeArr), 9);
+ }
+
+ //----------------------------------------------------------------------
+ public static function unserial($code)
+ {
+ $codeArr = array();
+
+ $codeLines = explode("\n", gzuncompress($code));
+ foreach ($codeLines as $line)
+ $codeArr[] = str_split($line);
+
+ return $codeArr;
+ }
+
+ //----------------------------------------------------------------------
+ public function makeMaskNo($maskNo, $width, $s, &$d, $maskGenOnly = false)
+ {
+ $b = 0;
+ $bitMask = array();
+
+ $fileName = QR_CACHE_DIR.'mask_'.$maskNo.DIRECTORY_SEPARATOR.'mask_'.$width.'_'.$maskNo.'.dat';
+
+ if (QR_CACHEABLE) {
+ if (file_exists($fileName)) {
+ $bitMask = self::unserial(file_get_contents($fileName));
+ } else {
+ $bitMask = $this->generateMaskNo($maskNo, $width, $s, $d);
+ if (!file_exists(QR_CACHE_DIR.'mask_'.$maskNo))
+ mkdir(QR_CACHE_DIR.'mask_'.$maskNo);
+ file_put_contents($fileName, self::serial($bitMask));
+ }
+ } else {
+ $bitMask = $this->generateMaskNo($maskNo, $width, $s, $d);
+ }
+
+ if ($maskGenOnly)
+ return;
+
+ $d = $s;
+
+ for($y=0; $y<$width; $y++) {
+ for($x=0; $x<$width; $x++) {
+ if($bitMask[$y][$x] == 1) {
+ $d[$y][$x] = chr(ord($s[$y][$x]) ^ (int)$bitMask[$y][$x]);
+ }
+ $b += (int)(ord($d[$y][$x]) & 1);
+ }
+ }
+
+ return $b;
+ }
+
+ //----------------------------------------------------------------------
+ public function makeMask($width, $frame, $maskNo, $level)
+ {
+ $masked = array_fill(0, $width, str_repeat("\0", $width));
+ $this->makeMaskNo($maskNo, $width, $frame, $masked);
+ $this->writeFormatInformation($width, $masked, $maskNo, $level);
+
+ return $masked;
+ }
+
+ //----------------------------------------------------------------------
+ public function calcN1N3($length)
+ {
+ $demerit = 0;
+
+ for($i=0; $i<$length; $i++) {
+
+ if($this->runLength[$i] >= 5) {
+ $demerit += (N1 + ($this->runLength[$i] - 5));
+ }
+ if($i & 1) {
+ if(($i >= 3) && ($i < ($length-2)) && ($this->runLength[$i] % 3 == 0)) {
+ $fact = (int)($this->runLength[$i] / 3);
+ if(($this->runLength[$i-2] == $fact) &&
+ ($this->runLength[$i-1] == $fact) &&
+ ($this->runLength[$i+1] == $fact) &&
+ ($this->runLength[$i+2] == $fact)) {
+ if(($this->runLength[$i-3] < 0) || ($this->runLength[$i-3] >= (4 * $fact))) {
+ $demerit += N3;
+ } else if((($i+3) >= $length) || ($this->runLength[$i+3] >= (4 * $fact))) {
+ $demerit += N3;
+ }
+ }
+ }
+ }
+ }
+ return $demerit;
+ }
+
+ //----------------------------------------------------------------------
+ public function evaluateSymbol($width, $frame)
+ {
+ $head = 0;
+ $demerit = 0;
+
+ for($y=0; $y<$width; $y++) {
+ $head = 0;
+ $this->runLength[0] = 1;
+
+ $frameY = $frame[$y];
+
+ if ($y>0)
+ $frameYM = $frame[$y-1];
+
+ for($x=0; $x<$width; $x++) {
+ if(($x > 0) && ($y > 0)) {
+ $b22 = ord($frameY[$x]) & ord($frameY[$x-1]) & ord($frameYM[$x]) & ord($frameYM[$x-1]);
+ $w22 = ord($frameY[$x]) | ord($frameY[$x-1]) | ord($frameYM[$x]) | ord($frameYM[$x-1]);
+
+ if(($b22 | ($w22 ^ 1))&1) {
+ $demerit += N2;
+ }
+ }
+ if(($x == 0) && (ord($frameY[$x]) & 1)) {
+ $this->runLength[0] = -1;
+ $head = 1;
+ $this->runLength[$head] = 1;
+ } else if($x > 0) {
+ if((ord($frameY[$x]) ^ ord($frameY[$x-1])) & 1) {
+ $head++;
+ $this->runLength[$head] = 1;
+ } else {
+ $this->runLength[$head]++;
+ }
+ }
+ }
+
+ $demerit += $this->calcN1N3($head+1);
+ }
+
+ for($x=0; $x<$width; $x++) {
+ $head = 0;
+ $this->runLength[0] = 1;
+
+ for($y=0; $y<$width; $y++) {
+ if($y == 0 && (ord($frame[$y][$x]) & 1)) {
+ $this->runLength[0] = -1;
+ $head = 1;
+ $this->runLength[$head] = 1;
+ } else if($y > 0) {
+ if((ord($frame[$y][$x]) ^ ord($frame[$y-1][$x])) & 1) {
+ $head++;
+ $this->runLength[$head] = 1;
+ } else {
+ $this->runLength[$head]++;
+ }
+ }
+ }
+
+ $demerit += $this->calcN1N3($head+1);
+ }
+
+ return $demerit;
+ }
+
+
+ //----------------------------------------------------------------------
+ public function mask($width, $frame, $level)
+ {
+ $minDemerit = PHP_INT_MAX;
+ $bestMaskNum = 0;
+ $bestMask = array();
+
+ $checked_masks = array(0,1,2,3,4,5,6,7);
+
+ if (QR_FIND_FROM_RANDOM !== false) {
+
+ $howManuOut = 8-(QR_FIND_FROM_RANDOM % 9);
+ for ($i = 0; $i < $howManuOut; $i++) {
+ $remPos = rand (0, count($checked_masks)-1);
+ unset($checked_masks[$remPos]);
+ $checked_masks = array_values($checked_masks);
+ }
+
+ }
+
+ $bestMask = $frame;
+
+ foreach($checked_masks as $i) {
+ $mask = array_fill(0, $width, str_repeat("\0", $width));
+
+ $demerit = 0;
+ $blacks = 0;
+ $blacks = $this->makeMaskNo($i, $width, $frame, $mask);
+ $blacks += $this->writeFormatInformation($width, $mask, $i, $level);
+ $blacks = (int)(100 * $blacks / ($width * $width));
+ $demerit = (int)((int)(abs($blacks - 50) / 5) * N4);
+ $demerit += $this->evaluateSymbol($width, $mask);
+
+ if($demerit < $minDemerit) {
+ $minDemerit = $demerit;
+ $bestMask = $mask;
+ $bestMaskNum = $i;
+ }
+ }
+
+ return $bestMask;
+ }
+
+ //----------------------------------------------------------------------
+ }
diff --git a/pdf/phpqrcode/qrrscode.php b/pdf/phpqrcode/qrrscode.php
new file mode 100755
index 0000000..591129a
--- /dev/null
+++ b/pdf/phpqrcode/qrrscode.php
@@ -0,0 +1,210 @@
+<?php
+/*
+ * PHP QR Code encoder
+ *
+ * Reed-Solomon error correction support
+ *
+ * Copyright (C) 2002, 2003, 2004, 2006 Phil Karn, KA9Q
+ * (libfec is released under the GNU Lesser General Public License.)
+ *
+ * Based on libqrencode C library distributed under LGPL 2.1
+ * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net>
+ *
+ * PHP QR Code is distributed under LGPL 3
+ * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+ class QRrsItem {
+
+ public $mm; // Bits per symbol
+ public $nn; // Symbols per block (= (1<<mm)-1)
+ public $alpha_to = array(); // log lookup table
+ public $index_of = array(); // Antilog lookup table
+ public $genpoly = array(); // Generator polynomial
+ public $nroots; // Number of generator roots = number of parity symbols
+ public $fcr; // First consecutive root, index form
+ public $prim; // Primitive element, index form
+ public $iprim; // prim-th root of 1, index form
+ public $pad; // Padding bytes in shortened block
+ public $gfpoly;
+
+ //----------------------------------------------------------------------
+ public function modnn($x)
+ {
+ while ($x >= $this->nn) {
+ $x -= $this->nn;
+ $x = ($x >> $this->mm) + ($x & $this->nn);
+ }
+
+ return $x;
+ }
+
+ //----------------------------------------------------------------------
+ public static function init_rs_char($symsize, $gfpoly, $fcr, $prim, $nroots, $pad)
+ {
+ // Common code for intializing a Reed-Solomon control block (char or int symbols)
+ // Copyright 2004 Phil Karn, KA9Q
+ // May be used under the terms of the GNU Lesser General Public License (LGPL)
+
+ $rs = null;
+
+ // Check parameter ranges
+ if($symsize < 0 || $symsize > 8) return $rs;
+ if($fcr < 0 || $fcr >= (1<<$symsize)) return $rs;
+ if($prim <= 0 || $prim >= (1<<$symsize)) return $rs;
+ if($nroots < 0 || $nroots >= (1<<$symsize)) return $rs; // Can't have more roots than symbol values!
+ if($pad < 0 || $pad >= ((1<<$symsize) -1 - $nroots)) return $rs; // Too much padding
+
+ $rs = new QRrsItem();
+ $rs->mm = $symsize;
+ $rs->nn = (1<<$symsize)-1;
+ $rs->pad = $pad;
+
+ $rs->alpha_to = array_fill(0, $rs->nn+1, 0);
+ $rs->index_of = array_fill(0, $rs->nn+1, 0);
+
+ // PHP style macro replacement ;)
+ $NN =& $rs->nn;
+ $A0 =& $NN;
+
+ // Generate Galois field lookup tables
+ $rs->index_of[0] = $A0; // log(zero) = -inf
+ $rs->alpha_to[$A0] = 0; // alpha**-inf = 0
+ $sr = 1;
+
+ for($i=0; $i<$rs->nn; $i++) {
+ $rs->index_of[$sr] = $i;
+ $rs->alpha_to[$i] = $sr;
+ $sr <<= 1;
+ if($sr & (1<<$symsize)) {
+ $sr ^= $gfpoly;
+ }
+ $sr &= $rs->nn;
+ }
+
+ if($sr != 1){
+ // field generator polynomial is not primitive!
+ $rs = NULL;
+ return $rs;
+ }
+
+ /* Form RS code generator polynomial from its roots */
+ $rs->genpoly = array_fill(0, $nroots+1, 0);
+
+ $rs->fcr = $fcr;
+ $rs->prim = $prim;
+ $rs->nroots = $nroots;
+ $rs->gfpoly = $gfpoly;
+
+ /* Find prim-th root of 1, used in decoding */
+ for($iprim=1;($iprim % $prim) != 0;$iprim += $rs->nn)
+ ; // intentional empty-body loop!
+
+ $rs->iprim = (int)($iprim / $prim);
+ $rs->genpoly[0] = 1;
+
+ for ($i = 0,$root=$fcr*$prim; $i < $nroots; $i++, $root += $prim) {
+ $rs->genpoly[$i+1] = 1;
+
+ // Multiply rs->genpoly[] by @**(root + x)
+ for ($j = $i; $j > 0; $j--) {
+ if ($rs->genpoly[$j] != 0) {
+ $rs->genpoly[$j] = $rs->genpoly[$j-1] ^ $rs->alpha_to[$rs->modnn($rs->index_of[$rs->genpoly[$j]] + $root)];
+ } else {
+ $rs->genpoly[$j] = $rs->genpoly[$j-1];
+ }
+ }
+ // rs->genpoly[0] can never be zero
+ $rs->genpoly[0] = $rs->alpha_to[$rs->modnn($rs->index_of[$rs->genpoly[0]] + $root)];
+ }
+
+ // convert rs->genpoly[] to index form for quicker encoding
+ for ($i = 0; $i <= $nroots; $i++)
+ $rs->genpoly[$i] = $rs->index_of[$rs->genpoly[$i]];
+
+ return $rs;
+ }
+
+ //----------------------------------------------------------------------
+ public function encode_rs_char($data, &$parity)
+ {
+ $MM =& $this->mm;
+ $NN =& $this->nn;
+ $ALPHA_TO =& $this->alpha_to;
+ $INDEX_OF =& $this->index_of;
+ $GENPOLY =& $this->genpoly;
+ $NROOTS =& $this->nroots;
+ $FCR =& $this->fcr;
+ $PRIM =& $this->prim;
+ $IPRIM =& $this->iprim;
+ $PAD =& $this->pad;
+ $A0 =& $NN;
+
+ $parity = array_fill(0, $NROOTS, 0);
+
+ for($i=0; $i< ($NN-$NROOTS-$PAD); $i++) {
+
+ $feedback = $INDEX_OF[$data[$i] ^ $parity[0]];
+ if($feedback != $A0) {
+ // feedback term is non-zero
+
+ // This line is unnecessary when GENPOLY[NROOTS] is unity, as it must
+ // always be for the polynomials constructed by init_rs()
+ $feedback = $this->modnn($NN - $GENPOLY[$NROOTS] + $feedback);
+
+ for($j=1;$j<$NROOTS;$j++) {
+ $parity[$j] ^= $ALPHA_TO[$this->modnn($feedback + $GENPOLY[$NROOTS-$j])];
+ }
+ }
+
+ // Shift
+ array_shift($parity);
+ if($feedback != $A0) {
+ array_push($parity, $ALPHA_TO[$this->modnn($feedback + $GENPOLY[0])]);
+ } else {
+ array_push($parity, 0);
+ }
+ }
+ }
+ }
+
+ //##########################################################################
+
+ class QRrs {
+
+ public static $items = array();
+
+ //----------------------------------------------------------------------
+ public static function init_rs($symsize, $gfpoly, $fcr, $prim, $nroots, $pad)
+ {
+ foreach(self::$items as $rs) {
+ if($rs->pad != $pad) continue;
+ if($rs->nroots != $nroots) continue;
+ if($rs->mm != $symsize) continue;
+ if($rs->gfpoly != $gfpoly) continue;
+ if($rs->fcr != $fcr) continue;
+ if($rs->prim != $prim) continue;
+
+ return $rs;
+ }
+
+ $rs = QRrsItem::init_rs_char($symsize, $gfpoly, $fcr, $prim, $nroots, $pad);
+ array_unshift(self::$items, $rs);
+
+ return $rs;
+ }
+ } \ No newline at end of file
diff --git a/pdf/phpqrcode/qrspec.php b/pdf/phpqrcode/qrspec.php
new file mode 100755
index 0000000..92aea0c
--- /dev/null
+++ b/pdf/phpqrcode/qrspec.php
@@ -0,0 +1,592 @@
+<?php
+/*
+ * PHP QR Code encoder
+ *
+ * QR Code specifications
+ *
+ * Based on libqrencode C library distributed under LGPL 2.1
+ * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net>
+ *
+ * PHP QR Code is distributed under LGPL 3
+ * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
+ *
+ * The following data / specifications are taken from
+ * "Two dimensional symbol -- QR-code -- Basic Specification" (JIS X0510:2004)
+ * or
+ * "Automatic identification and data capture techniques --
+ * QR Code 2005 bar code symbology specification" (ISO/IEC 18004:2006)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+ define('QRSPEC_VERSION_MAX', 40);
+ define('QRSPEC_WIDTH_MAX', 177);
+
+ define('QRCAP_WIDTH', 0);
+ define('QRCAP_WORDS', 1);
+ define('QRCAP_REMINDER', 2);
+ define('QRCAP_EC', 3);
+
+ class QRspec {
+
+ public static $capacity = array(
+ array( 0, 0, 0, array( 0, 0, 0, 0)),
+ array( 21, 26, 0, array( 7, 10, 13, 17)), // 1
+ array( 25, 44, 7, array( 10, 16, 22, 28)),
+ array( 29, 70, 7, array( 15, 26, 36, 44)),
+ array( 33, 100, 7, array( 20, 36, 52, 64)),
+ array( 37, 134, 7, array( 26, 48, 72, 88)), // 5
+ array( 41, 172, 7, array( 36, 64, 96, 112)),
+ array( 45, 196, 0, array( 40, 72, 108, 130)),
+ array( 49, 242, 0, array( 48, 88, 132, 156)),
+ array( 53, 292, 0, array( 60, 110, 160, 192)),
+ array( 57, 346, 0, array( 72, 130, 192, 224)), //10
+ array( 61, 404, 0, array( 80, 150, 224, 264)),
+ array( 65, 466, 0, array( 96, 176, 260, 308)),
+ array( 69, 532, 0, array( 104, 198, 288, 352)),
+ array( 73, 581, 3, array( 120, 216, 320, 384)),
+ array( 77, 655, 3, array( 132, 240, 360, 432)), //15
+ array( 81, 733, 3, array( 144, 280, 408, 480)),
+ array( 85, 815, 3, array( 168, 308, 448, 532)),
+ array( 89, 901, 3, array( 180, 338, 504, 588)),
+ array( 93, 991, 3, array( 196, 364, 546, 650)),
+ array( 97, 1085, 3, array( 224, 416, 600, 700)), //20
+ array(101, 1156, 4, array( 224, 442, 644, 750)),
+ array(105, 1258, 4, array( 252, 476, 690, 816)),
+ array(109, 1364, 4, array( 270, 504, 750, 900)),
+ array(113, 1474, 4, array( 300, 560, 810, 960)),
+ array(117, 1588, 4, array( 312, 588, 870, 1050)), //25
+ array(121, 1706, 4, array( 336, 644, 952, 1110)),
+ array(125, 1828, 4, array( 360, 700, 1020, 1200)),
+ array(129, 1921, 3, array( 390, 728, 1050, 1260)),
+ array(133, 2051, 3, array( 420, 784, 1140, 1350)),
+ array(137, 2185, 3, array( 450, 812, 1200, 1440)), //30
+ array(141, 2323, 3, array( 480, 868, 1290, 1530)),
+ array(145, 2465, 3, array( 510, 924, 1350, 1620)),
+ array(149, 2611, 3, array( 540, 980, 1440, 1710)),
+ array(153, 2761, 3, array( 570, 1036, 1530, 1800)),
+ array(157, 2876, 0, array( 570, 1064, 1590, 1890)), //35
+ array(161, 3034, 0, array( 600, 1120, 1680, 1980)),
+ array(165, 3196, 0, array( 630, 1204, 1770, 2100)),
+ array(169, 3362, 0, array( 660, 1260, 1860, 2220)),
+ array(173, 3532, 0, array( 720, 1316, 1950, 2310)),
+ array(177, 3706, 0, array( 750, 1372, 2040, 2430)) //40
+ );
+
+ //----------------------------------------------------------------------
+ public static function getDataLength($version, $level)
+ {
+ return self::$capacity[$version][QRCAP_WORDS] - self::$capacity[$version][QRCAP_EC][$level];
+ }
+
+ //----------------------------------------------------------------------
+ public static function getECCLength($version, $level)
+ {
+ return self::$capacity[$version][QRCAP_EC][$level];
+ }
+
+ //----------------------------------------------------------------------
+ public static function getWidth($version)
+ {
+ return self::$capacity[$version][QRCAP_WIDTH];
+ }
+
+ //----------------------------------------------------------------------
+ public static function getRemainder($version)
+ {
+ return self::$capacity[$version][QRCAP_REMINDER];
+ }
+
+ //----------------------------------------------------------------------
+ public static function getMinimumVersion($size, $level)
+ {
+
+ for($i=1; $i<= QRSPEC_VERSION_MAX; $i++) {
+ $words = self::$capacity[$i][QRCAP_WORDS] - self::$capacity[$i][QRCAP_EC][$level];
+ if($words >= $size)
+ return $i;
+ }
+
+ return -1;
+ }
+
+ //######################################################################
+
+ public static $lengthTableBits = array(
+ array(10, 12, 14),
+ array( 9, 11, 13),
+ array( 8, 16, 16),
+ array( 8, 10, 12)
+ );
+
+ //----------------------------------------------------------------------
+ public static function lengthIndicator($mode, $version)
+ {
+ if ($mode == QR_MODE_STRUCTURE)
+ return 0;
+
+ if ($version <= 9) {
+ $l = 0;
+ } else if ($version <= 26) {
+ $l = 1;
+ } else {
+ $l = 2;
+ }
+
+ return self::$lengthTableBits[$mode][$l];
+ }
+
+ //----------------------------------------------------------------------
+ public static function maximumWords($mode, $version)
+ {
+ if($mode == QR_MODE_STRUCTURE)
+ return 3;
+
+ if($version <= 9) {
+ $l = 0;
+ } else if($version <= 26) {
+ $l = 1;
+ } else {
+ $l = 2;
+ }
+
+ $bits = self::$lengthTableBits[$mode][$l];
+ $words = (1 << $bits) - 1;
+
+ if($mode == QR_MODE_KANJI) {
+ $words *= 2; // the number of bytes is required
+ }
+
+ return $words;
+ }
+
+ // Error correction code -----------------------------------------------
+ // Table of the error correction code (Reed-Solomon block)
+ // See Table 12-16 (pp.30-36), JIS X0510:2004.
+
+ public static $eccTable = array(
+ array(array( 0, 0), array( 0, 0), array( 0, 0), array( 0, 0)),
+ array(array( 1, 0), array( 1, 0), array( 1, 0), array( 1, 0)), // 1
+ array(array( 1, 0), array( 1, 0), array( 1, 0), array( 1, 0)),
+ array(array( 1, 0), array( 1, 0), array( 2, 0), array( 2, 0)),
+ array(array( 1, 0), array( 2, 0), array( 2, 0), array( 4, 0)),
+ array(array( 1, 0), array( 2, 0), array( 2, 2), array( 2, 2)), // 5
+ array(array( 2, 0), array( 4, 0), array( 4, 0), array( 4, 0)),
+ array(array( 2, 0), array( 4, 0), array( 2, 4), array( 4, 1)),
+ array(array( 2, 0), array( 2, 2), array( 4, 2), array( 4, 2)),
+ array(array( 2, 0), array( 3, 2), array( 4, 4), array( 4, 4)),
+ array(array( 2, 2), array( 4, 1), array( 6, 2), array( 6, 2)), //10
+ array(array( 4, 0), array( 1, 4), array( 4, 4), array( 3, 8)),
+ array(array( 2, 2), array( 6, 2), array( 4, 6), array( 7, 4)),
+ array(array( 4, 0), array( 8, 1), array( 8, 4), array(12, 4)),
+ array(array( 3, 1), array( 4, 5), array(11, 5), array(11, 5)),
+ array(array( 5, 1), array( 5, 5), array( 5, 7), array(11, 7)), //15
+ array(array( 5, 1), array( 7, 3), array(15, 2), array( 3, 13)),
+ array(array( 1, 5), array(10, 1), array( 1, 15), array( 2, 17)),
+ array(array( 5, 1), array( 9, 4), array(17, 1), array( 2, 19)),
+ array(array( 3, 4), array( 3, 11), array(17, 4), array( 9, 16)),
+ array(array( 3, 5), array( 3, 13), array(15, 5), array(15, 10)), //20
+ array(array( 4, 4), array(17, 0), array(17, 6), array(19, 6)),
+ array(array( 2, 7), array(17, 0), array( 7, 16), array(34, 0)),
+ array(array( 4, 5), array( 4, 14), array(11, 14), array(16, 14)),
+ array(array( 6, 4), array( 6, 14), array(11, 16), array(30, 2)),
+ array(array( 8, 4), array( 8, 13), array( 7, 22), array(22, 13)), //25
+ array(array(10, 2), array(19, 4), array(28, 6), array(33, 4)),
+ array(array( 8, 4), array(22, 3), array( 8, 26), array(12, 28)),
+ array(array( 3, 10), array( 3, 23), array( 4, 31), array(11, 31)),
+ array(array( 7, 7), array(21, 7), array( 1, 37), array(19, 26)),
+ array(array( 5, 10), array(19, 10), array(15, 25), array(23, 25)), //30
+ array(array(13, 3), array( 2, 29), array(42, 1), array(23, 28)),
+ array(array(17, 0), array(10, 23), array(10, 35), array(19, 35)),
+ array(array(17, 1), array(14, 21), array(29, 19), array(11, 46)),
+ array(array(13, 6), array(14, 23), array(44, 7), array(59, 1)),
+ array(array(12, 7), array(12, 26), array(39, 14), array(22, 41)), //35
+ array(array( 6, 14), array( 6, 34), array(46, 10), array( 2, 64)),
+ array(array(17, 4), array(29, 14), array(49, 10), array(24, 46)),
+ array(array( 4, 18), array(13, 32), array(48, 14), array(42, 32)),
+ array(array(20, 4), array(40, 7), array(43, 22), array(10, 67)),
+ array(array(19, 6), array(18, 31), array(34, 34), array(20, 61)),//40
+ );
+
+ //----------------------------------------------------------------------
+ // CACHEABLE!!!
+
+ public static function getEccSpec($version, $level, array &$spec)
+ {
+ if (count($spec) < 5) {
+ $spec = array(0,0,0,0,0);
+ }
+
+ $b1 = self::$eccTable[$version][$level][0];
+ $b2 = self::$eccTable[$version][$level][1];
+ $data = self::getDataLength($version, $level);
+ $ecc = self::getECCLength($version, $level);
+
+ if($b2 == 0) {
+ $spec[0] = $b1;
+ $spec[1] = (int)($data / $b1);
+ $spec[2] = (int)($ecc / $b1);
+ $spec[3] = 0;
+ $spec[4] = 0;
+ } else {
+ $spec[0] = $b1;
+ $spec[1] = (int)($data / ($b1 + $b2));
+ $spec[2] = (int)($ecc / ($b1 + $b2));
+ $spec[3] = $b2;
+ $spec[4] = $spec[1] + 1;
+ }
+ }
+
+ // Alignment pattern ---------------------------------------------------
+
+ // Positions of alignment patterns.
+ // This array includes only the second and the third position of the
+ // alignment patterns. Rest of them can be calculated from the distance
+ // between them.
+
+ // See Table 1 in Appendix E (pp.71) of JIS X0510:2004.
+
+ public static $alignmentPattern = array(
+ array( 0, 0),
+ array( 0, 0), array(18, 0), array(22, 0), array(26, 0), array(30, 0), // 1- 5
+ array(34, 0), array(22, 38), array(24, 42), array(26, 46), array(28, 50), // 6-10
+ array(30, 54), array(32, 58), array(34, 62), array(26, 46), array(26, 48), //11-15
+ array(26, 50), array(30, 54), array(30, 56), array(30, 58), array(34, 62), //16-20
+ array(28, 50), array(26, 50), array(30, 54), array(28, 54), array(32, 58), //21-25
+ array(30, 58), array(34, 62), array(26, 50), array(30, 54), array(26, 52), //26-30
+ array(30, 56), array(34, 60), array(30, 58), array(34, 62), array(30, 54), //31-35
+ array(24, 50), array(28, 54), array(32, 58), array(26, 54), array(30, 58), //35-40
+ );
+
+
+ /** --------------------------------------------------------------------
+ * Put an alignment marker.
+ * @param frame
+ * @param width
+ * @param ox,oy center coordinate of the pattern
+ */
+ public static function putAlignmentMarker(array &$frame, $ox, $oy)
+ {
+ $finder = array(
+ "\xa1\xa1\xa1\xa1\xa1",
+ "\xa1\xa0\xa0\xa0\xa1",
+ "\xa1\xa0\xa1\xa0\xa1",
+ "\xa1\xa0\xa0\xa0\xa1",
+ "\xa1\xa1\xa1\xa1\xa1"
+ );
+
+ $yStart = $oy-2;
+ $xStart = $ox-2;
+
+ for($y=0; $y<5; $y++) {
+ QRstr::set($frame, $xStart, $yStart+$y, $finder[$y]);
+ }
+ }
+
+ //----------------------------------------------------------------------
+ public static function putAlignmentPattern($version, &$frame, $width)
+ {
+ if($version < 2)
+ return;
+
+ $d = self::$alignmentPattern[$version][1] - self::$alignmentPattern[$version][0];
+ if($d < 0) {
+ $w = 2;
+ } else {
+ $w = (int)(($width - self::$alignmentPattern[$version][0]) / $d + 2);
+ }
+
+ if($w * $w - 3 == 1) {
+ $x = self::$alignmentPattern[$version][0];
+ $y = self::$alignmentPattern[$version][0];
+ self::putAlignmentMarker($frame, $x, $y);
+ return;
+ }
+
+ $cx = self::$alignmentPattern[$version][0];
+ for($x=1; $x<$w - 1; $x++) {
+ self::putAlignmentMarker($frame, 6, $cx);
+ self::putAlignmentMarker($frame, $cx, 6);
+ $cx += $d;
+ }
+
+ $cy = self::$alignmentPattern[$version][0];
+ for($y=0; $y<$w-1; $y++) {
+ $cx = self::$alignmentPattern[$version][0];
+ for($x=0; $x<$w-1; $x++) {
+ self::putAlignmentMarker($frame, $cx, $cy);
+ $cx += $d;
+ }
+ $cy += $d;
+ }
+ }
+
+ // Version information pattern -----------------------------------------
+
+ // Version information pattern (BCH coded).
+ // See Table 1 in Appendix D (pp.68) of JIS X0510:2004.
+
+ // size: [QRSPEC_VERSION_MAX - 6]
+
+ public static $versionPattern = array(
+ 0x07c94, 0x085bc, 0x09a99, 0x0a4d3, 0x0bbf6, 0x0c762, 0x0d847, 0x0e60d,
+ 0x0f928, 0x10b78, 0x1145d, 0x12a17, 0x13532, 0x149a6, 0x15683, 0x168c9,
+ 0x177ec, 0x18ec4, 0x191e1, 0x1afab, 0x1b08e, 0x1cc1a, 0x1d33f, 0x1ed75,
+ 0x1f250, 0x209d5, 0x216f0, 0x228ba, 0x2379f, 0x24b0b, 0x2542e, 0x26a64,
+ 0x27541, 0x28c69
+ );
+
+ //----------------------------------------------------------------------
+ public static function getVersionPattern($version)
+ {
+ if($version < 7 || $version > QRSPEC_VERSION_MAX)
+ return 0;
+
+ return self::$versionPattern[$version -7];
+ }
+
+ // Format information --------------------------------------------------
+ // See calcFormatInfo in tests/test_qrspec.c (orginal qrencode c lib)
+
+ public static $formatInfo = array(
+ array(0x77c4, 0x72f3, 0x7daa, 0x789d, 0x662f, 0x6318, 0x6c41, 0x6976),
+ array(0x5412, 0x5125, 0x5e7c, 0x5b4b, 0x45f9, 0x40ce, 0x4f97, 0x4aa0),
+ array(0x355f, 0x3068, 0x3f31, 0x3a06, 0x24b4, 0x2183, 0x2eda, 0x2bed),
+ array(0x1689, 0x13be, 0x1ce7, 0x19d0, 0x0762, 0x0255, 0x0d0c, 0x083b)
+ );
+
+ public static function getFormatInfo($mask, $level)
+ {
+ if($mask < 0 || $mask > 7)
+ return 0;
+
+ if($level < 0 || $level > 3)
+ return 0;
+
+ return self::$formatInfo[$level][$mask];
+ }
+
+ // Frame ---------------------------------------------------------------
+ // Cache of initial frames.
+
+ public static $frames = array();
+
+ /** --------------------------------------------------------------------
+ * Put a finder pattern.
+ * @param frame
+ * @param width
+ * @param ox,oy upper-left coordinate of the pattern
+ */
+ public static function putFinderPattern(&$frame, $ox, $oy)
+ {
+ $finder = array(
+ "\xc1\xc1\xc1\xc1\xc1\xc1\xc1",
+ "\xc1\xc0\xc0\xc0\xc0\xc0\xc1",
+ "\xc1\xc0\xc1\xc1\xc1\xc0\xc1",
+ "\xc1\xc0\xc1\xc1\xc1\xc0\xc1",
+ "\xc1\xc0\xc1\xc1\xc1\xc0\xc1",
+ "\xc1\xc0\xc0\xc0\xc0\xc0\xc1",
+ "\xc1\xc1\xc1\xc1\xc1\xc1\xc1"
+ );
+
+ for($y=0; $y<7; $y++) {
+ QRstr::set($frame, $ox, $oy+$y, $finder[$y]);
+ }
+ }
+
+ //----------------------------------------------------------------------
+ public static function createFrame($version)
+ {
+ $width = self::$capacity[$version][QRCAP_WIDTH];
+ $frameLine = str_repeat ("\0", $width);
+ $frame = array_fill(0, $width, $frameLine);
+
+ // Finder pattern
+ self::putFinderPattern($frame, 0, 0);
+ self::putFinderPattern($frame, $width - 7, 0);
+ self::putFinderPattern($frame, 0, $width - 7);
+
+ // Separator
+ $yOffset = $width - 7;
+
+ for($y=0; $y<7; $y++) {
+ $frame[$y][7] = "\xc0";
+ $frame[$y][$width - 8] = "\xc0";
+ $frame[$yOffset][7] = "\xc0";
+ $yOffset++;
+ }
+
+ $setPattern = str_repeat("\xc0", 8);
+
+ QRstr::set($frame, 0, 7, $setPattern);
+ QRstr::set($frame, $width-8, 7, $setPattern);
+ QRstr::set($frame, 0, $width - 8, $setPattern);
+
+ // Format info
+ $setPattern = str_repeat("\x84", 9);
+ QRstr::set($frame, 0, 8, $setPattern);
+ QRstr::set($frame, $width - 8, 8, $setPattern, 8);
+
+ $yOffset = $width - 8;
+
+ for($y=0; $y<8; $y++,$yOffset++) {
+ $frame[$y][8] = "\x84";
+ $frame[$yOffset][8] = "\x84";
+ }
+
+ // Timing pattern
+
+ for($i=1; $i<$width-15; $i++) {
+ $frame[6][7+$i] = chr(0x90 | ($i & 1));
+ $frame[7+$i][6] = chr(0x90 | ($i & 1));
+ }
+
+ // Alignment pattern
+ self::putAlignmentPattern($version, $frame, $width);
+
+ // Version information
+ if($version >= 7) {
+ $vinf = self::getVersionPattern($version);
+
+ $v = $vinf;
+
+ for($x=0; $x<6; $x++) {
+ for($y=0; $y<3; $y++) {
+ $frame[($width - 11)+$y][$x] = chr(0x88 | ($v & 1));
+ $v = $v >> 1;
+ }
+ }
+
+ $v = $vinf;
+ for($y=0; $y<6; $y++) {
+ for($x=0; $x<3; $x++) {
+ $frame[$y][$x+($width - 11)] = chr(0x88 | ($v & 1));
+ $v = $v >> 1;
+ }
+ }
+ }
+
+ // and a little bit...
+ $frame[$width - 8][8] = "\x81";
+
+ return $frame;
+ }
+
+ //----------------------------------------------------------------------
+ public static function debug($frame, $binary_mode = false)
+ {
+ if ($binary_mode) {
+
+ foreach ($frame as &$frameLine) {
+ $frameLine = join('<span class="m">&nbsp;&nbsp;</span>', explode('0', $frameLine));
+ $frameLine = join('&#9608;&#9608;', explode('1', $frameLine));
+ }
+
+ ?>
+ <style>
+ .m { background-color: white; }
+ </style>
+ <?php
+ echo '<pre><tt><br/ ><br/ ><br/ >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
+ echo join("<br/ >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", $frame);
+ echo '</tt></pre><br/ ><br/ ><br/ ><br/ ><br/ ><br/ >';
+
+ } else {
+
+ foreach ($frame as &$frameLine) {
+ $frameLine = join('<span class="m">&nbsp;</span>', explode("\xc0", $frameLine));
+ $frameLine = join('<span class="m">&#9618;</span>', explode("\xc1", $frameLine));
+ $frameLine = join('<span class="p">&nbsp;</span>', explode("\xa0", $frameLine));
+ $frameLine = join('<span class="p">&#9618;</span>', explode("\xa1", $frameLine));
+ $frameLine = join('<span class="s">&#9671;</span>', explode("\x84", $frameLine)); //format 0
+ $frameLine = join('<span class="s">&#9670;</span>', explode("\x85", $frameLine)); //format 1
+ $frameLine = join('<span class="x">&#9762;</span>', explode("\x81", $frameLine)); //special bit
+ $frameLine = join('<span class="c">&nbsp;</span>', explode("\x90", $frameLine)); //clock 0
+ $frameLine = join('<span class="c">&#9719;</span>', explode("\x91", $frameLine)); //clock 1
+ $frameLine = join('<span class="f">&nbsp;</span>', explode("\x88", $frameLine)); //version
+ $frameLine = join('<span class="f">&#9618;</span>', explode("\x89", $frameLine)); //version
+ $frameLine = join('&#9830;', explode("\x01", $frameLine));
+ $frameLine = join('&#8901;', explode("\0", $frameLine));
+ }
+
+ ?>
+ <style>
+ .p { background-color: yellow; }
+ .m { background-color: #00FF00; }
+ .s { background-color: #FF0000; }
+ .c { background-color: aqua; }
+ .x { background-color: pink; }
+ .f { background-color: gold; }
+ </style>
+ <?php
+ echo "<pre><tt>";
+ echo join("<br/ >", $frame);
+ echo "</tt></pre>";
+
+ }
+ }
+
+ //----------------------------------------------------------------------
+ public static function serial($frame)
+ {
+ return gzcompress(join("\n", $frame), 9);
+ }
+
+ //----------------------------------------------------------------------
+ public static function unserial($code)
+ {
+ return explode("\n", gzuncompress($code));
+ }
+
+ //----------------------------------------------------------------------
+ public static function newFrame($version)
+ {
+ if($version < 1 || $version > QRSPEC_VERSION_MAX)
+ return null;
+
+ if(!isset(self::$frames[$version])) {
+
+ $fileName = QR_CACHE_DIR.'frame_'.$version.'.dat';
+
+ if (QR_CACHEABLE) {
+ if (file_exists($fileName)) {
+ self::$frames[$version] = self::unserial(file_get_contents($fileName));
+ } else {
+ self::$frames[$version] = self::createFrame($version);
+ file_put_contents($fileName, self::serial(self::$frames[$version]));
+ }
+ } else {
+ self::$frames[$version] = self::createFrame($version);
+ }
+ }
+
+ if(is_null(self::$frames[$version]))
+ return null;
+
+ return self::$frames[$version];
+ }
+
+ //----------------------------------------------------------------------
+ public static function rsBlockNum($spec) { return $spec[0] + $spec[3]; }
+ public static function rsBlockNum1($spec) { return $spec[0]; }
+ public static function rsDataCodes1($spec) { return $spec[1]; }
+ public static function rsEccCodes1($spec) { return $spec[2]; }
+ public static function rsBlockNum2($spec) { return $spec[3]; }
+ public static function rsDataCodes2($spec) { return $spec[4]; }
+ public static function rsEccCodes2($spec) { return $spec[2]; }
+ public static function rsDataLength($spec) { return ($spec[0] * $spec[1]) + ($spec[3] * $spec[4]); }
+ public static function rsEccLength($spec) { return ($spec[0] + $spec[3]) * $spec[2]; }
+
+ } \ No newline at end of file
diff --git a/pdf/phpqrcode/qrsplit.php b/pdf/phpqrcode/qrsplit.php
new file mode 100755
index 0000000..d75b827
--- /dev/null
+++ b/pdf/phpqrcode/qrsplit.php
@@ -0,0 +1,311 @@
+<?php
+/*
+ * PHP QR Code encoder
+ *
+ * Input splitting classes
+ *
+ * Based on libqrencode C library distributed under LGPL 2.1
+ * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi <fukuchi@megaui.net>
+ *
+ * PHP QR Code is distributed under LGPL 3
+ * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
+ *
+ * The following data / specifications are taken from
+ * "Two dimensional symbol -- QR-code -- Basic Specification" (JIS X0510:2004)
+ * or
+ * "Automatic identification and data capture techniques --
+ * QR Code 2005 bar code symbology specification" (ISO/IEC 18004:2006)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+ class QRsplit {
+
+ public $dataStr = '';
+ public $input;
+ public $modeHint;
+
+ //----------------------------------------------------------------------
+ public function __construct($dataStr, $input, $modeHint)
+ {
+ $this->dataStr = $dataStr;
+ $this->input = $input;
+ $this->modeHint = $modeHint;
+ }
+
+ //----------------------------------------------------------------------
+ public static function isdigitat($str, $pos)
+ {
+ if ($pos >= strlen($str))
+ return false;
+
+ return ((ord($str[$pos]) >= ord('0'))&&(ord($str[$pos]) <= ord('9')));
+ }
+
+ //----------------------------------------------------------------------
+ public static function isalnumat($str, $pos)
+ {
+ if ($pos >= strlen($str))
+ return false;
+
+ return (QRinput::lookAnTable(ord($str[$pos])) >= 0);
+ }
+
+ //----------------------------------------------------------------------
+ public function identifyMode($pos)
+ {
+ if ($pos >= strlen($this->dataStr))
+ return QR_MODE_NUL;
+
+ $c = $this->dataStr[$pos];
+
+ if(self::isdigitat($this->dataStr, $pos)) {
+ return QR_MODE_NUM;
+ } else if(self::isalnumat($this->dataStr, $pos)) {
+ return QR_MODE_AN;
+ } else if($this->modeHint == QR_MODE_KANJI) {
+
+ if ($pos+1 < strlen($this->dataStr))
+ {
+ $d = $this->dataStr[$pos+1];
+ $word = (ord($c) << 8) | ord($d);
+ if(($word >= 0x8140 && $word <= 0x9ffc) || ($word >= 0xe040 && $word <= 0xebbf)) {
+ return QR_MODE_KANJI;
+ }
+ }
+ }
+
+ return QR_MODE_8;
+ }
+
+ //----------------------------------------------------------------------
+ public function eatNum()
+ {
+ $ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion());
+
+ $p = 0;
+ while(self::isdigitat($this->dataStr, $p)) {
+ $p++;
+ }
+
+ $run = $p;
+ $mode = $this->identifyMode($p);
+
+ if($mode == QR_MODE_8) {
+ $dif = QRinput::estimateBitsModeNum($run) + 4 + $ln
+ + QRinput::estimateBitsMode8(1) // + 4 + l8
+ - QRinput::estimateBitsMode8($run + 1); // - 4 - l8
+ if($dif > 0) {
+ return $this->eat8();
+ }
+ }
+ if($mode == QR_MODE_AN) {
+ $dif = QRinput::estimateBitsModeNum($run) + 4 + $ln
+ + QRinput::estimateBitsModeAn(1) // + 4 + la
+ - QRinput::estimateBitsModeAn($run + 1);// - 4 - la
+ if($dif > 0) {
+ return $this->eatAn();
+ }
+ }
+
+ $ret = $this->input->append(QR_MODE_NUM, $run, str_split($this->dataStr));
+ if($ret < 0)
+ return -1;
+
+ return $run;
+ }
+
+ //----------------------------------------------------------------------
+ public function eatAn()
+ {
+ $la = QRspec::lengthIndicator(QR_MODE_AN, $this->input->getVersion());
+ $ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion());
+
+ $p = 0;
+
+ while(self::isalnumat($this->dataStr, $p)) {
+ if(self::isdigitat($this->dataStr, $p)) {
+ $q = $p;
+ while(self::isdigitat($this->dataStr, $q)) {
+ $q++;
+ }
+
+ $dif = QRinput::estimateBitsModeAn($p) // + 4 + la
+ + QRinput::estimateBitsModeNum($q - $p) + 4 + $ln
+ - QRinput::estimateBitsModeAn($q); // - 4 - la
+
+ if($dif < 0) {
+ break;
+ } else {
+ $p = $q;
+ }
+ } else {
+ $p++;
+ }
+ }
+
+ $run = $p;
+
+ if(!self::isalnumat($this->dataStr, $p)) {
+ $dif = QRinput::estimateBitsModeAn($run) + 4 + $la
+ + QRinput::estimateBitsMode8(1) // + 4 + l8
+ - QRinput::estimateBitsMode8($run + 1); // - 4 - l8
+ if($dif > 0) {
+ return $this->eat8();
+ }
+ }
+
+ $ret = $this->input->append(QR_MODE_AN, $run, str_split($this->dataStr));
+ if($ret < 0)
+ return -1;
+
+ return $run;
+ }
+
+ //----------------------------------------------------------------------
+ public function eatKanji()
+ {
+ $p = 0;
+
+ while($this->identifyMode($p) == QR_MODE_KANJI) {
+ $p += 2;
+ }
+
+ $ret = $this->input->append(QR_MODE_KANJI, $p, str_split($this->dataStr));
+ if($ret < 0)
+ return -1;
+
+ return $run;
+ }
+
+ //----------------------------------------------------------------------
+ public function eat8()
+ {
+ $la = QRspec::lengthIndicator(QR_MODE_AN, $this->input->getVersion());
+ $ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion());
+
+ $p = 1;
+ $dataStrLen = strlen($this->dataStr);
+
+ while($p < $dataStrLen) {
+
+ $mode = $this->identifyMode($p);
+ if($mode == QR_MODE_KANJI) {
+ break;
+ }
+ if($mode == QR_MODE_NUM) {
+ $q = $p;
+ while(self::isdigitat($this->dataStr, $q)) {
+ $q++;
+ }
+ $dif = QRinput::estimateBitsMode8($p) // + 4 + l8
+ + QRinput::estimateBitsModeNum($q - $p) + 4 + $ln
+ - QRinput::estimateBitsMode8($q); // - 4 - l8
+ if($dif < 0) {
+ break;
+ } else {
+ $p = $q;
+ }
+ } else if($mode == QR_MODE_AN) {
+ $q = $p;
+ while(self::isalnumat($this->dataStr, $q)) {
+ $q++;
+ }
+ $dif = QRinput::estimateBitsMode8($p) // + 4 + l8
+ + QRinput::estimateBitsModeAn($q - $p) + 4 + $la
+ - QRinput::estimateBitsMode8($q); // - 4 - l8
+ if($dif < 0) {
+ break;
+ } else {
+ $p = $q;
+ }
+ } else {
+ $p++;
+ }
+ }
+
+ $run = $p;
+ $ret = $this->input->append(QR_MODE_8, $run, str_split($this->dataStr));
+
+ if($ret < 0)
+ return -1;
+
+ return $run;
+ }
+
+ //----------------------------------------------------------------------
+ public function splitString()
+ {
+ while (strlen($this->dataStr) > 0)
+ {
+ if($this->dataStr == '')
+ return 0;
+
+ $mode = $this->identifyMode(0);
+
+ switch ($mode) {
+ case QR_MODE_NUM: $length = $this->eatNum(); break;
+ case QR_MODE_AN: $length = $this->eatAn(); break;
+ case QR_MODE_KANJI:
+ if ($hint == QR_MODE_KANJI)
+ $length = $this->eatKanji();
+ else $length = $this->eat8();
+ break;
+ default: $length = $this->eat8(); break;
+
+ }
+
+ if($length == 0) return 0;
+ if($length < 0) return -1;
+
+ $this->dataStr = substr($this->dataStr, $length);
+ }
+ }
+
+ //----------------------------------------------------------------------
+ public function toUpper()
+ {
+ $stringLen = strlen($this->dataStr);
+ $p = 0;
+
+ while ($p<$stringLen) {
+ $mode = self::identifyMode(substr($this->dataStr, $p), $this->modeHint);
+ if($mode == QR_MODE_KANJI) {
+ $p += 2;
+ } else {
+ if (ord($this->dataStr[$p]) >= ord('a') && ord($this->dataStr[$p]) <= ord('z')) {
+ $this->dataStr[$p] = chr(ord($this->dataStr[$p]) - 32);
+ }
+ $p++;
+ }
+ }
+
+ return $this->dataStr;
+ }
+
+ //----------------------------------------------------------------------
+ public static function splitStringToQRinput($string, QRinput $input, $modeHint, $casesensitive = true)
+ {
+ if(is_null($string) || $string == '\0' || $string == '') {
+ throw new Exception('empty string!!!');
+ }
+
+ $split = new QRsplit($string, $input, $modeHint);
+
+ if(!$casesensitive)
+ $split->toUpper();
+
+ return $split->splitString();
+ }
+ } \ No newline at end of file
diff --git a/pdf/phpqrcode/qrtools.php b/pdf/phpqrcode/qrtools.php
new file mode 100755
index 0000000..3012db4
--- /dev/null
+++ b/pdf/phpqrcode/qrtools.php
@@ -0,0 +1,172 @@
+<?php
+/*
+ * PHP QR Code encoder
+ *
+ * Toolset, handy and debug utilites.
+ *
+ * PHP QR Code is distributed under LGPL 3
+ * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+ class QRtools {
+
+ //----------------------------------------------------------------------
+ public static function binarize($frame)
+ {
+ $len = count($frame);
+ foreach ($frame as &$frameLine) {
+
+ for($i=0; $i<$len; $i++) {
+ $frameLine[$i] = (ord($frameLine[$i])&1)?'1':'0';
+ }
+ }
+
+ return $frame;
+ }
+
+ //----------------------------------------------------------------------
+ public static function tcpdfBarcodeArray($code, $mode = 'QR,L', $tcPdfVersion = '4.5.037')
+ {
+ $barcode_array = array();
+
+ if (!is_array($mode))
+ $mode = explode(',', $mode);
+
+ $eccLevel = 'L';
+
+ if (count($mode) > 1) {
+ $eccLevel = $mode[1];
+ }
+
+ $qrTab = QRcode::text($code, false, $eccLevel);
+ $size = count($qrTab);
+
+ $barcode_array['num_rows'] = $size;
+ $barcode_array['num_cols'] = $size;
+ $barcode_array['bcode'] = array();
+
+ foreach ($qrTab as $line) {
+ $arrAdd = array();
+ foreach(str_split($line) as $char)
+ $arrAdd[] = ($char=='1')?1:0;
+ $barcode_array['bcode'][] = $arrAdd;
+ }
+
+ return $barcode_array;
+ }
+
+ //----------------------------------------------------------------------
+ public static function clearCache()
+ {
+ self::$frames = array();
+ }
+
+ //----------------------------------------------------------------------
+ public static function buildCache()
+ {
+ QRtools::markTime('before_build_cache');
+
+ $mask = new QRmask();
+ for ($a=1; $a <= QRSPEC_VERSION_MAX; $a++) {
+ $frame = QRspec::newFrame($a);
+ if (QR_IMAGE) {
+ $fileName = QR_CACHE_DIR.'frame_'.$a.'.png';
+ QRimage::png(self::binarize($frame), $fileName, 1, 0);
+ }
+
+ $width = count($frame);
+ $bitMask = array_fill(0, $width, array_fill(0, $width, 0));
+ for ($maskNo=0; $maskNo<8; $maskNo++)
+ $mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true);
+ }
+
+ QRtools::markTime('after_build_cache');
+ }
+
+ //----------------------------------------------------------------------
+ public static function log($outfile, $err)
+ {
+ if (QR_LOG_DIR !== false) {
+ if ($err != '') {
+ if ($outfile !== false) {
+ file_put_contents(QR_LOG_DIR.basename($outfile).'-errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND);
+ } else {
+ file_put_contents(QR_LOG_DIR.'errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND);
+ }
+ }
+ }
+ }
+
+ //----------------------------------------------------------------------
+ public static function dumpMask($frame)
+ {
+ $width = count($frame);
+ for($y=0;$y<$width;$y++) {
+ for($x=0;$x<$width;$x++) {
+ echo ord($frame[$y][$x]).',';
+ }
+ }
+ }
+
+ //----------------------------------------------------------------------
+ public static function markTime($markerId)
+ {
+ list($usec, $sec) = explode(" ", microtime());
+ $time = ((float)$usec + (float)$sec);
+
+ if (!isset($GLOBALS['qr_time_bench']))
+ $GLOBALS['qr_time_bench'] = array();
+
+ $GLOBALS['qr_time_bench'][$markerId] = $time;
+ }
+
+ //----------------------------------------------------------------------
+ public static function timeBenchmark()
+ {
+ self::markTime('finish');
+
+ $lastTime = 0;
+ $startTime = 0;
+ $p = 0;
+
+ echo '<table cellpadding="3" cellspacing="1">
+ <thead><tr style="border-bottom:1px solid silver"><td colspan="2" style="text-align:center">BENCHMARK</td></tr></thead>
+ <tbody>';
+
+ foreach($GLOBALS['qr_time_bench'] as $markerId=>$thisTime) {
+ if ($p > 0) {
+ echo '<tr><th style="text-align:right">till '.$markerId.': </th><td>'.number_format($thisTime-$lastTime, 6).'s</td></tr>';
+ } else {
+ $startTime = $thisTime;
+ }
+
+ $p++;
+ $lastTime = $thisTime;
+ }
+
+ echo '</tbody><tfoot>
+ <tr style="border-top:2px solid black"><th style="text-align:right">TOTAL: </th><td>'.number_format($lastTime-$startTime, 6).'s</td></tr>
+ </tfoot>
+ </table>';
+ }
+
+ }
+
+ //##########################################################################
+
+ QRtools::markTime('start');
+ \ No newline at end of file
diff --git a/pdf/phpqrcode/tools/merge.bat b/pdf/phpqrcode/tools/merge.bat
new file mode 100755
index 0000000..b60a485
--- /dev/null
+++ b/pdf/phpqrcode/tools/merge.bat
@@ -0,0 +1,2 @@
+php ./merge.php
+pause \ No newline at end of file
diff --git a/pdf/phpqrcode/tools/merge.php b/pdf/phpqrcode/tools/merge.php
new file mode 100755
index 0000000..19d338b
--- /dev/null
+++ b/pdf/phpqrcode/tools/merge.php
@@ -0,0 +1,70 @@
+<?php
+
+/*
+ * PHP QR Code encoder
+ *
+ * Tool for merging all library files into one, simpler to incorporate.
+ *
+ * MAKE SURE THAT RESULTING PHPQRCode.php (and its dir) ARE WRITABLE!
+ *
+ * PHP QR Code is distributed under LGPL 3
+ * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+ $QR_BASEDIR = dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR;
+ $QR_TOOLSDIR = dirname(__FILE__).DIRECTORY_SEPARATOR;
+
+ $outputFile = $QR_BASEDIR.'phpqrcode.php';
+
+ // Required libs
+
+ $fileList = array(
+ $QR_BASEDIR.'qrconst.php',
+ $QR_TOOLSDIR.'merged_config.php',
+ $QR_BASEDIR.'qrtools.php',
+ $QR_BASEDIR.'qrspec.php',
+ $QR_BASEDIR.'qrimage.php',
+ $QR_BASEDIR.'qrinput.php',
+ $QR_BASEDIR.'qrbitstream.php',
+ $QR_BASEDIR.'qrsplit.php',
+ $QR_BASEDIR.'qrrscode.php',
+ $QR_BASEDIR.'qrmask.php',
+ $QR_BASEDIR.'qrencode.php'
+ );
+
+ $headerFile = $QR_TOOLSDIR.'merged_header.php';
+ $versionFile = $QR_BASEDIR.'VERSION';
+
+ $outputCode = '';
+
+ foreach($fileList as $fileName) {
+ $outputCode .= "\n\n".'//---- '.basename($fileName).' -----------------------------'."\n\n";
+ $anotherCode = file_get_contents($fileName);
+ $anotherCode = preg_replace ('/^<\?php/', '', $anotherCode);
+ $anotherCode = preg_replace ('/\?>\*$/', '', $anotherCode);
+ $outputCode .= "\n\n".$anotherCode."\n\n";
+ }
+
+ $versionDataEx = explode("\n", file_get_contents($versionFile));
+
+ $outputContents = file_get_contents($headerFile);
+ $outputContents .= "\n\n/*\n * Version: ".trim($versionDataEx[0])."\n * Build: ".trim($versionDataEx[1])."\n */\n\n";
+ $outputContents .= $outputCode;
+
+ file_put_contents($outputFile, $outputContents);
+
+ \ No newline at end of file
diff --git a/pdf/phpqrcode/tools/merge.sh b/pdf/phpqrcode/tools/merge.sh
new file mode 100755
index 0000000..e4c2fbc
--- /dev/null
+++ b/pdf/phpqrcode/tools/merge.sh
@@ -0,0 +1,2 @@
+#!/bin/sh
+php ./merge.php \ No newline at end of file
diff --git a/pdf/phpqrcode/tools/merged_config.php b/pdf/phpqrcode/tools/merged_config.php
new file mode 100755
index 0000000..55ddb45
--- /dev/null
+++ b/pdf/phpqrcode/tools/merged_config.php
@@ -0,0 +1,17 @@
+<?php
+/*
+ * PHP QR Code encoder
+ *
+ * Config file, tuned-up for merged verion
+ */
+
+ define('QR_CACHEABLE', false); // use cache - more disk reads but less CPU power, masks and format templates are stored there
+ define('QR_CACHE_DIR', false); // used when QR_CACHEABLE === true
+ define('QR_LOG_DIR', false); // default error logs dir
+
+ define('QR_FIND_BEST_MASK', true); // if true, estimates best mask (spec. default, but extremally slow; set to false to significant performance boost but (propably) worst quality code
+ define('QR_FIND_FROM_RANDOM', 2); // if false, checks all masks available, otherwise value tells count of masks need to be checked, mask id are got randomly
+ define('QR_DEFAULT_MASK', 2); // when QR_FIND_BEST_MASK === false
+
+ define('QR_PNG_MAXIMUM_SIZE', 1024); // maximum allowed png image width (in pixels), tune to make sure GD and PHP can handle such big images
+ \ No newline at end of file
diff --git a/pdf/phpqrcode/tools/merged_header.php b/pdf/phpqrcode/tools/merged_header.php
new file mode 100755
index 0000000..25805e5
--- /dev/null
+++ b/pdf/phpqrcode/tools/merged_header.php
@@ -0,0 +1,36 @@
+<?php
+
+/*
+ * PHP QR Code encoder
+ *
+ * This file contains MERGED version of PHP QR Code library.
+ * It was auto-generated from full version for your convenience.
+ *
+ * This merged version was configured to not requre any external files,
+ * with disabled cache, error loging and weker but faster mask matching.
+ * If you need tune it up please use non-merged version.
+ *
+ * For full version, documentation, examples of use please visit:
+ *
+ * http://phpqrcode.sourceforge.net/
+ * https://sourceforge.net/projects/phpqrcode/
+ *
+ * PHP QR Code is distributed under LGPL 3
+ * Copyright (C) 2010 Dominik Dzienia <deltalab at poczta dot fm>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+ \ No newline at end of file
diff --git a/pdf/temp.inc b/pdf/temp.inc
deleted file mode 100755
index 4e46946..0000000
--- a/pdf/temp.inc
+++ /dev/null
@@ -1,58 +0,0 @@
-$pending_rows = array();
- $pending_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE proposal_status = 0 ORDER BY id DESC");
- while ($pending_data = db_fetch_object($pending_q))
- {
- $pending_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($pending_header, $pending_rows);
- return $output;
-
-
-
-
-
-
-
-global $user;
- $uid1 = $user->uid;
-
- $query2 = db_query("SELECT * FROM {textbook_companion_proposal} WHERE proposal_status=3 AND uid=".$user->uid);
- $data2 = db_fetch_object($query2);
- if($data2->id)
- {
- $search_rows = array();
- $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->id,$search_data3->proposal_id,$search_data3->book, l('Download Certificate', 'certificate/generate_pdf'.$search_data3->proposal_id));
- }
- if ($search_rows)
- {
- $search_header = array('Id', 'Proposal Id', 'Book Name', 'Download Certificates');
- $output .= theme_table($search_header, $search_rows);
- }
- else
- {
- echo("Error");
- }
- return $output;
- }
- else
- {
- echo("Book Still Under Review");
- };
-
diff --git a/pdf/temp_prcode/generated_qrcode.png b/pdf/temp_prcode/generated_qrcode.png
new file mode 100755
index 0000000..2009dff
--- /dev/null
+++ b/pdf/temp_prcode/generated_qrcode.png
Binary files differ
diff --git a/pdf/temp_prcode/qrcode_name.png b/pdf/temp_prcode/qrcode_name.png
new file mode 100755
index 0000000..0e88581
--- /dev/null
+++ b/pdf/temp_prcode/qrcode_name.png
Binary files differ
diff --git a/pdf/verify_certificates.inc b/pdf/verify_certificates.inc
new file mode 100755
index 0000000..e9731b8
--- /dev/null
+++ b/pdf/verify_certificates.inc
@@ -0,0 +1,96 @@
+<?php
+function verify_certificates($qr_code = 0)
+{
+ $qr_code = arg(3);
+ $page_content = "";
+ if ($qr_code)
+ {
+ $page_content = verify_qrcode_fromdb($qr_code);
+ } //$qr_code
+ else
+ {
+ $verify_certificates_form = drupal_get_form("verify_certificates_form");
+ $page_content = drupal_render($verify_certificates_form);
+ }
+ return $page_content;
+}
+function verify_certificates_form($form, &$form_state)
+{
+ $form = array();
+ $form['Title'] = array(
+ '#type' => 'markup',
+ '#markup' => ''
+ );
+ $form["QR_code"] = array(
+ "#type" => "textfield",
+ "#title" => "Enter QR Code",
+ "#default_value" => '',
+ "#required" => TRUE
+ );
+ $form["submit"] = array(
+ "#type" => "submit",
+ "#value" => "Verify",
+ '#ajax' => array(
+ 'callback' => 'verify_certificates_form_submit',
+ 'progress' => array(
+ 'message' => ''
+ )
+ )
+ );
+ $form['displaytable'] = array(
+ '#type' => 'markup',
+ '#prefix' => '<div><div id="displaytable" style="font-weight:bold;padding-top:10px">',
+ '#suffix' => '</div></div>',
+ '#markup' => ''
+ );
+ return $form;
+}
+function verify_certificates_form_submit($form, &$form_state)
+{
+ $page_content = "";
+ $v = $form_state["values"];
+ $qr_code = $v["QR_code"];
+ $page_content = verify_qrcode_fromdb($qr_code);
+ $form['displaytable']['#markup'] = $page_content;
+ $commands[] = ajax_command_html("#displaytable", drupal_render($form['displaytable']));
+ return array(
+ '#type' => 'ajax',
+ '#commands' => $commands
+ );
+}
+function verify_qrcode_fromdb($qr_code)
+{
+ $query = db_select('textbook_companion_qr_code');
+ $query->fields('textbook_companion_qr_code', array(
+ 'proposal_id'
+ ));
+ $query->condition('qr_code', $qr_code);
+ $result = $query->execute();
+ $proposal_id = $result->fetchObject()->proposal_id;
+ if ($proposal_id)
+ {
+ $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();
+ $page_content = "";
+ $page_content .= "<h4>Participation Details</h4><table><tr><td>Name</td>";
+ $page_content .= "<td>" . $data3->full_name . "</td></tr>";
+ $page_content .= "<tr><td>Project</td>";
+ $page_content .= "<td>DWSIM Textbook Companion</td></tr>";
+ $page_content .= "<tr><td>Books completed</td>";
+ $page_content .= "<td>" . $data2->book . "</td></tr>";
+ $page_content .= "<tr><td>Book Author</td>";
+ $page_content .= "<td>" . $data2->author . "</td></tr>";
+ $page_content .= "</table>";
+ } //$proposal_id
+ else
+ {
+ $page_content = "<b>Sorry ! The serial number you entered seems to be invalid. Please try again ! <b>";
+ }
+ return $page_content;
+}
diff --git a/run.inc b/run.inc
index 64aa9e6..c1b2524 100755
--- a/run.inc
+++ b/run.inc
@@ -1,550 +1,558 @@
<?php
function textbook_companion_run_form($form, &$form_state)
{
- $url_book_pref_id = (int) arg(2);
- // var_dump($url_book_pref_id);die;
- if ($url_book_pref_id) {
- $query = db_select('textbook_companion_preference');
- $query->fields('textbook_companion_preference', array(
- 'category'
- ));
- $query->condition('id', $url_book_pref_id);
- $result = $query->execute()->fetchObject();
- $category_default_value = $result->category;
- } else {
- $category_default_value = 0;
- }
- if ($url_book_pref_id) {
- $form['category'] = array(
- '#type' => 'hidden',
- '#title' => t('Category'),
- '#options' => _list_of_category(),
- '#default_value' => $category_default_value,
- '#ajax' => array(
- 'callback' => 'ajax_book_list_callback'
- ),
- '#validated' => TRUE
- );
- $book_default_value = $url_book_pref_id;
- $form['book'] = array(
- '#type' => 'select',
- '#title' => t('Title of the book'),
- '#options' => _list_of_books($book_default_value),
- '#default_value' => $book_default_value,
- '#prefix' => '<div id="ajax-book-list-replace">',
- '#suffix' => '</div>',
- '#ajax' => array(
- 'callback' => 'ajax_chapter_list_callback'
- ),
- '#validated' => TRUE
- );
- /*$form['book_details'] = array(
- '#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>'
- );
- $form['download_book'] = array(
- '#type' => 'item',
- '#markup' => '<div id="ajax-download-book-replace">' . l('Download', 'textbook-companion/download/book/' . $book_default_value) . ' ' . t('(Download the DWSIM codes for all the solved examples)') . '</div>'
- );
- /*$book_pref_id_array = array("19");
- if(in_array($book_default_value, $book_pref_id_array)){
- $form['freeeda_download_book'] = array(
- '#type' => 'item',
- '#markup' => '<div id="ajax-download-freeeda-book-replace">'.l('Download (FreeEDA Version)', 'textbook-companion/uploads/Microelectronic_Circuits___Theory_And_Applications_FreeEDA_Version.zip') . ' ' . t('(Download the FreeEDA 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 eSim codes for all the solved examples)').'</div>',
- );*/
- $form['chapter'] = array(
- '#type' => 'select',
- '#title' => t('Title of the chapter'),
- '#options' => _list_of_chapters($book_default_value),
- //'#default_value' => isset($form_state['values']['chapter']) ? $form_state['values']['chapter'] : '',
- '#prefix' => '<div id="ajax-chapter-list-replace">',
- '#suffix' => '</div>',
- '#ajax' => array(
- 'callback' => 'ajax_example_list_callback'
- ),
- '#validated' => TRUE,
- '#states' => array(
- 'invisible' => array(
- ':input[name="category"]' => array(
- 'value' => 0
- )
- )
- )
- );
- $form['download_chapter'] = array(
- '#type' => 'item',
- '#markup' => '<div id="ajax-download-chapter-replace"></div>'
- );
- $example_default_value = isset($form_state['values']['chapter']) ? $form_state['values']['chapter'] : '';
- $form['examples'] = array(
- '#type' => 'select',
- '#title' => t('Example No. (Caption): '),
- '#options' => _list_of_examples($example_default_value),
- '#default_value' => isset($form_state['values']['examples']) ? $form_state['values']['examples'] : '',
- '#prefix' => '<div id="ajax-example-list-replace">',
- '#suffix' => '</div>',
- '#ajax' => array(
- 'callback' => 'ajax_example_files_callback'
- ),
- '#states' => array(
- 'invisible' => array(
- ':input[name="chapter"]' => array(
- 'value' => 0
- )
- )
- )
- );
- $form['download_example_code'] = array(
- '#type' => 'item',
- '#markup' => '<div id="ajax-download-example-code-replace"></div>'
- );
- $form['example_files'] = array(
- '#type' => 'item',
- '#markup' => '<div id="ajax-download-example-files-replace"></div>'
- );
- } else {
- $form['category'] = array(
- '#type' => 'hidden',
- '#title' => t('Category'),
- '#options' => _list_of_category(),
- '#default_value' => $category_default_value,
- '#ajax' => array(
- 'callback' => 'ajax_book_list_callback'
- ),
- '#validated' => TRUE
- );
- $form['book'] = array(
- '#type' => 'select',
- '#title' => t('Title of the book'),
- '#options' => _list_of_books(),
- //'#default_value' => isset($form_state['values']['book']) ? $form_state['values']['book'] : 0,
- '#prefix' => '<div id="ajax-book-list-replace">',
- '#suffix' => '</div>',
- '#ajax' => array(
- 'callback' => 'ajax_chapter_list_callback'
- ),
- '#validated' => TRUE
- //'#states' => array('invisible' => array(':input[name="category"]' => array('value' => 0),),),
- );
- $form['book_details'] = array(
- '#type' => 'item',
- '#markup' => '<div id="ajax-book-details-replace"></div>'
- );
- $form['download_book'] = array(
- '#type' => 'item',
- '#markup' => '<div id="ajax-download-book-replace"></div>'
- );
- $form['freeeda_download_book'] = array(
- '#type' => 'item',
- '#markup' => '<div id="ajax-download-freeeda-book-replace"></div>'
- );
- /* $form['download_pdf'] = array(
- '#type' => 'item',
- '#markup' => '<div id="ajax-download-book-pdf-replace"></div>',
- );*/
- $book_default_value = isset($form_state['values']['book']) ? $form_state['values']['book'] : '';
- $form['chapter'] = array(
- '#type' => 'select',
- '#title' => t('Title of the chapter'),
- '#options' => _list_of_chapters($book_default_value),
- //'#default_value' => isset($form_state['values']['chapter']) ? $form_state['values']['chapter'] : '',
- '#prefix' => '<div id="ajax-chapter-list-replace">',
- '#suffix' => '</div>',
- '#ajax' => array(
- 'callback' => 'ajax_example_list_callback'
- ),
- '#validated' => TRUE,
- '#states' => array(
- 'invisible' => array(
- ':input[name="book"]' => array(
- 'value' => 0
- )
- )
- )
- );
- $form['download_chapter'] = array(
- '#type' => 'item',
- '#markup' => '<div id="ajax-download-chapter-replace"></div>'
- );
- $example_default_value = isset($form_state['values']['chapter']) ? $form_state['values']['chapter'] : '';
- $form['examples'] = array(
- '#type' => 'select',
- '#title' => t('Example No. (Caption): '),
- '#options' => _list_of_examples($example_default_value),
- '#default_value' => isset($form_state['values']['examples']) ? $form_state['values']['examples'] : '',
- '#prefix' => '<div id="ajax-example-list-replace">',
- '#suffix' => '</div>',
- '#ajax' => array(
- 'callback' => 'ajax_example_files_callback'
- ),
- '#states' => array(
- 'invisible' => array(
- ':input[name="book"]' => 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;
+ $url_book_pref_id = (int) arg(2);
+ // var_dump($url_book_pref_id);die;
+ 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' => 'hidden',
+ '#title' => t('Category'),
+ '#options' => _list_of_category(),
+ '#default_value' => $category_default_value,
+ '#ajax' => array(
+ 'callback' => 'ajax_book_list_callback'
+ ),
+ '#validated' => TRUE
+ );
+ $book_default_value = $url_book_pref_id;
+ $form['book'] = array(
+ '#type' => 'select',
+ '#title' => t('Title of the book'),
+ '#options' => _list_of_books($book_default_value),
+ '#default_value' => $book_default_value,
+ '#prefix' => '<div id="ajax-book-list-replace">',
+ '#suffix' => '</div>',
+ '#ajax' => array(
+ 'callback' => 'ajax_chapter_list_callback'
+ ),
+ '#validated' => TRUE
+ );
+ /*$form['book_details'] = array(
+ '#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>'
+ );
+ $form['download_book'] = array(
+ '#type' => 'item',
+ '#markup' => '<div id="ajax-download-book-replace">' . l('Download', 'textbook-companion/download/book/' . $book_default_value) . ' ' . t('(Download the DWSIM codes for all the solved examples)') . '</div>'
+ );
+ /*$book_pref_id_array = array("19");
+ if(in_array($book_default_value, $book_pref_id_array)){
+ $form['freeeda_download_book'] = array(
+ '#type' => 'item',
+ '#markup' => '<div id="ajax-download-freeeda-book-replace">'.l('Download (FreeEDA Version)', 'textbook-companion/uploads/Microelectronic_Circuits___Theory_And_Applications_FreeEDA_Version.zip') . ' ' . t('(Download the FreeEDA 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 eSim codes for all the solved examples)').'</div>',
+ );*/
+ $form['chapter'] = array(
+ '#type' => 'select',
+ '#title' => t('Title of the chapter'),
+ '#options' => _list_of_chapters($book_default_value),
+ //'#default_value' => isset($form_state['values']['chapter']) ? $form_state['values']['chapter'] : '',
+ '#prefix' => '<div id="ajax-chapter-list-replace">',
+ '#suffix' => '</div>',
+ '#ajax' => array(
+ 'callback' => 'ajax_example_list_callback'
+ ),
+ '#validated' => TRUE,
+ '#states' => array(
+ 'invisible' => array(
+ ':input[name="category"]' => array(
+ 'value' => 0
+ )
+ )
+ )
+ );
+ $form['download_chapter'] = array(
+ '#type' => 'item',
+ '#markup' => '<div id="ajax-download-chapter-replace"></div>'
+ );
+ $example_default_value = isset($form_state['values']['chapter']) ? $form_state['values']['chapter'] : '';
+ $form['examples'] = array(
+ '#type' => 'select',
+ '#title' => t('Example No. (Caption): '),
+ '#options' => _list_of_examples($example_default_value),
+ '#default_value' => isset($form_state['values']['examples']) ? $form_state['values']['examples'] : '',
+ '#prefix' => '<div id="ajax-example-list-replace">',
+ '#suffix' => '</div>',
+ '#ajax' => array(
+ 'callback' => 'ajax_example_files_callback'
+ ),
+ '#states' => array(
+ 'invisible' => array(
+ ':input[name="chapter"]' => array(
+ 'value' => 0
+ )
+ )
+ )
+ );
+ $form['download_example_code'] = array(
+ '#type' => 'item',
+ '#markup' => '<div id="ajax-download-example-code-replace"></div>'
+ );
+ $form['example_files'] = array(
+ '#type' => 'item',
+ '#markup' => '<div id="ajax-download-example-files-replace"></div>'
+ );
+ } //$url_book_pref_id
+ else {
+ $form['category'] = array(
+ '#type' => 'hidden',
+ '#title' => t('Category'),
+ '#options' => _list_of_category(),
+ '#default_value' => $category_default_value,
+ '#ajax' => array(
+ 'callback' => 'ajax_book_list_callback'
+ ),
+ '#validated' => TRUE
+ );
+ $form['book'] = array(
+ '#type' => 'select',
+ '#title' => t('Title of the book'),
+ '#options' => _list_of_books(),
+ //'#default_value' => isset($form_state['values']['book']) ? $form_state['values']['book'] : 0,
+ '#prefix' => '<div id="ajax-book-list-replace">',
+ '#suffix' => '</div>',
+ '#ajax' => array(
+ 'callback' => 'ajax_chapter_list_callback'
+ ),
+ '#validated' => TRUE
+ //'#states' => array('invisible' => array(':input[name="category"]' => array('value' => 0),),),
+ );
+ $form['book_details'] = array(
+ '#type' => 'item',
+ '#markup' => '<div id="ajax-book-details-replace"></div>'
+ );
+ $form['download_book'] = array(
+ '#type' => 'item',
+ '#markup' => '<div id="ajax-download-book-replace"></div>'
+ );
+ $form['freeeda_download_book'] = array(
+ '#type' => 'item',
+ '#markup' => '<div id="ajax-download-freeeda-book-replace"></div>'
+ );
+ /* $form['download_pdf'] = array(
+ '#type' => 'item',
+ '#markup' => '<div id="ajax-download-book-pdf-replace"></div>',
+ );*/
+ $book_default_value = isset($form_state['values']['book']) ? $form_state['values']['book'] : '';
+ $form['chapter'] = array(
+ '#type' => 'select',
+ '#title' => t('Title of the chapter'),
+ '#options' => _list_of_chapters($book_default_value),
+ //'#default_value' => isset($form_state['values']['chapter']) ? $form_state['values']['chapter'] : '',
+ '#prefix' => '<div id="ajax-chapter-list-replace">',
+ '#suffix' => '</div>',
+ '#ajax' => array(
+ 'callback' => 'ajax_example_list_callback'
+ ),
+ '#validated' => TRUE,
+ '#states' => array(
+ 'invisible' => array(
+ ':input[name="book"]' => array(
+ 'value' => 0
+ )
+ )
+ )
+ );
+ $form['download_chapter'] = array(
+ '#type' => 'item',
+ '#markup' => '<div id="ajax-download-chapter-replace"></div>'
+ );
+ $example_default_value = isset($form_state['values']['chapter']) ? $form_state['values']['chapter'] : '';
+ $form['examples'] = array(
+ '#type' => 'select',
+ '#title' => t('Example No. (Caption): '),
+ '#options' => _list_of_examples($example_default_value),
+ '#default_value' => isset($form_state['values']['examples']) ? $form_state['values']['examples'] : '',
+ '#prefix' => '<div id="ajax-example-list-replace">',
+ '#suffix' => '</div>',
+ '#ajax' => array(
+ 'callback' => 'ajax_example_files_callback'
+ ),
+ '#states' => array(
+ 'invisible' => array(
+ ':input[name="book"]' => array(
+ 'value' => 0
+ )
+ )
+ )
+ );
+ $form['download_example_code'] = array(
+ '#type' => 'item',
+ '#markup' => '<div id="ajax-download-example-code-replace"></div>'
+ );
+ $form['example_files'] = array(
+ '#type' => 'item',
+ '#markup' => '<div id="ajax-download-example-files-replace"></div>'
+ );
+ }
+ return $form;
}
/********************* Ajax callback ***************************/
function ajax_book_list_callback($form, $form_state)
{
- $category_default_value = $form_state['values']['category'];
- if ($category_default_value == 0) {
- $form['book']['#options'] = _list_of_books($category_default_value);
- $commands[] = ajax_command_replace("#ajax-book-list-replace", drupal_render($form['book']));
- $commands[] = ajax_command_html("#ajax-chapter-list-replace", '');
- $commands[] = ajax_command_html("#ajax-example-list-replace", '');
- } else {
- $form['book']['#options'] = _list_of_books();
- $commands[] = ajax_command_replace("#ajax-book-list-replace", drupal_render($form['book']));
- $commands[] = ajax_command_html("#ajax-book-list-replace", '');
- $commands[] = ajax_command_html("#ajax-chapter-list-replace", '');
- $commands[] = ajax_command_html("#ajax-example-list-replace", '');
- $commands[] = ajax_command_html("#ajax-book-details-replace", '');
- $commands[] = ajax_command_html("#ajax-download-book-replace", '');
- $commands[] = ajax_command_html("#ajax-download-freeeda-book-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
- );
+ $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-freeeda-book-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', 'textbook-companion/download/book/' . $book_list_default_value) . ' ' . t('(Download the DWSIM codes for all the solved examples)'));
- $book_pref_id_array = array(
- "19"
- );
- if (in_array($book_list_default_value, $book_pref_id_array)) {
- $commands[] = ajax_command_html("#ajax-download-freeeda-book-replace", l('Download FreeEDA Version', 'textbook-companion/uploads/Microelectronic_Circuits___Theory_And_Applications_FreeEDA_Version.zip') . ' ' . t('(Download the FreeEDA codes for all the solved examples)'));
- } else {
- $commands[] = ajax_command_html("#ajax-download-freeeda-book-replace", '');
- }
- $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-freeeda-book-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
- );
+ $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', 'textbook-companion/download/book/' . $book_list_default_value) . ' ' . t('(Download the DWSIM codes for all the solved examples)'));
+ $book_pref_id_array = array(
+ "19"
+ );
+ if (in_array($book_list_default_value, $book_pref_id_array)) {
+ $commands[] = ajax_command_html("#ajax-download-freeeda-book-replace", l('Download FreeEDA Version', 'textbook-companion/uploads/Microelectronic_Circuits___Theory_And_Applications_FreeEDA_Version.zip') . ' ' . t('(Download the FreeEDA codes for all the solved examples)'));
+ } //in_array($book_list_default_value, $book_pref_id_array)
+ else {
+ $commands[] = ajax_command_html("#ajax-download-freeeda-book-replace", '');
+ }
+ $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-freeeda-book-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', 'textbook-companion/download/chapter/' . $chapter_list_default_value) . ' ' . t('(Download the DWSIM 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
- );
+ $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', 'textbook-companion/download/chapter/' . $chapter_list_default_value) . ' ' . t('(Download the DWSIM 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_files_rows[] = array(
- l($example_list_data->filename, 'textbook-companion/download/file/' . $example_list_data->id),
- $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 DWSIM code for the example', 'textbook-companion/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
- );
+ $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, 'textbook-companion/download/file/' . $example_list_data->id),
+ $example_file_type
+ );
+ } //$example_list_data = $example_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 DWSIM code for the example', 'textbook-companion/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>";
- }
- foreach ($rows as $row) {
- $tbody .= "<tr>";
- foreach ($row as $data) {
- $tbody .= "<td>{$data}</td>";
- }
- $tbody .= "</tr>";
- }
- $table = "
+ $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;
+ 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;
+ $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($preference_id = NULL)
{
- if ($preference_id != NULL) {
- $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('id', $preference_id);
- $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 . ')';
- }
- } else {
- $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('id', $preference_id);
- $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;
+ if ($preference_id != NULL) {
+ $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('id', $preference_id);
+ $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()
+ } //$preference_id != NULL
+ else {
+ $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('id', $preference_id);
+ $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;
- }
- return $book_chapters;
+ $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 . ')';
- }
- return $book_examples;
+ $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;
+ /*$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 = 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>';
+ } //$book_details
+ return $html_data;
}
diff --git a/settings.inc b/settings.inc
index cdacb28..1aaafc2 100755
--- a/settings.inc
+++ b/settings.inc
@@ -1,72 +1,72 @@
<?php
// $Id$
-function textbook_companion_settings_form($form, $form_state)
- {
- $form['emails'] = array(
- '#type' => 'textfield',
- '#title' => t('(Bcc) Notification emails'),
- '#description' => t('Specify emails id for Bcc option of mail system with comma separated'),
- '#size' => 50,
- '#maxlength' => 255,
- '#required' => TRUE,
- '#default_value' => variable_get('textbook_companion_emails', '')
- );
- $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', '')
- );
- $options = array(
- '1' => t('1'),
- '2' => t('2'),
- '3' => t('3')
- );
- $form['book_preference_options'] = array(
- '#type' => 'radios',
- '#title' => t('Book Preferences'),
- '#options' => $options,
- '#required' => TRUE,
- '#description' => t('Set number book preference to be allowed'),
- '#default_value' => variable_get('textbook_companion_book_preferences', '')
- );
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Submit')
- );
- return $form;
- }
+function textbook_companion_settings_form($form, &$form_state)
+{
+ $form['bcc_emails'] = array(
+ '#type' => 'textfield',
+ '#title' => t('(Bcc) Notification emails'),
+ '#description' => t('Specify emails id for Bcc option of mail system with comma separated'),
+ '#size' => 50,
+ '#maxlength' => 255,
+ '#required' => TRUE,
+ '#default_value' => variable_get('textbook_companion_bcc_emails', '')
+ );
+ $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', '')
+ );
+ $options = array(
+ '1' => t('1'),
+ '2' => t('2'),
+ '3' => t('3')
+ );
+ $form['book_preference_options'] = array(
+ '#type' => 'radios',
+ '#title' => t('Book Preferences'),
+ '#options' => $options,
+ '#required' => TRUE,
+ '#description' => t('Set number book preference to be allowed'),
+ '#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_from_email', $form_state['values']['from_email']);
- variable_set('textbook_companion_source_extensions', $form_state['values']['source']);
- variable_set('textbook_companion_book_preferences', $form_state['values']['book_preference_options']);
- drupal_set_message(t('Settings updated'), 'status');
- }
+{
+ variable_set('textbook_companion_bcc_emails', $form_state['values']['bcc_emails']);
+ variable_set('textbook_companion_cc_emails', $form_state['values']['cc_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_book_preferences', $form_state['values']['book_preference_options']);
+ drupal_set_message(t('Settings updated'), 'status');
+}
diff --git a/textbook_companion.module b/textbook_companion.module
index 5a3685c..f795de6 100755
--- a/textbook_companion.module
+++ b/textbook_companion.module
@@ -4,834 +4,890 @@ implementation of hook_menu().
*/
function textbook_companion_menu()
{
- $items = array();
- /* users */
- $items['textbook-companion/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["textbook-companion/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['textbook-companion/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['textbook-companion/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['textbook-companion/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['textbook-companion/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['textbook-companion/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['textbook-companion/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['textbook-companion/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['textbook-companion/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['textbook-companion/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['textbook-companion/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['textbook-companion/code-approval/edit-code-submission'] = array(
- 'title' => 'Edit Code Submission',
- 'description' => 'Enable users code submission interface',
- // 'page callback' => 'drupal_get_form',
- 'page callback' => 'edit_code_submission',
- // 'page arguments' => array(
- // 'edit_code_submission_form'
- // ),
- 'access arguments' => array(
- 'bulk manage code'
- ),
- 'type' => MENU_LOCAL_TASK,
- 'weight' => 3,
- 'file' => 'code_approval.inc'
- );*/
- $items['textbook-companion/code-approval/edit-code-submission/edit'] = array(
- 'title' => 'Edit Code Submission',
- 'description' => 'Enable users code submission interface',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array(
- 'edit_code_submission_form'
- ),
- 'access arguments' => array(
- 'bulk manage code'
- ),
- 'file' => 'code_approval.inc'
- );
- $items['textbook-companion/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['textbook-companion/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-companion/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-companion/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-companion/textbook-search/book'] = array(
- 'title' => 'By Book Title',
- 'description' => '',
- 'page callback' => 'textbook_companion_browse_book',
- 'access arguments' => array(
- 'access content'
- ),
- 'type' => MENU_LOCAL_TASK,
- 'file' => 'search.inc',
- 'weight' => 2
- );
- $items['textbook-companion/textbook-search/author'] = array(
- 'title' => 'By Author',
- 'description' => '',
- 'page callback' => 'textbook_companion_browse_author',
- 'access arguments' => array(
- 'access content'
- ),
- 'type' => MENU_LOCAL_TASK,
- 'file' => 'search.inc',
- 'weight' => 3
- );
- $items['textbook-companion/textbook-search/college'] = array(
- 'title' => 'By College',
- 'description' => '',
- 'page callback' => 'textbook_companion_browse_college',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array(
- 'textbook_companion_browse_college_form'
- ),
- 'access arguments' => array(
- 'access content'
- ),
- 'type' => MENU_LOCAL_TASK,
- 'file' => 'search.inc',
- 'weight' => 4
- );
- $items['textbook-companion/textbook-search/student'] = array(
- 'title' => 'By Student',
- 'description' => '',
- 'page callback' => 'textbook_companion_browse_student',
- 'access arguments' => array(
- 'access content'
- ),
- 'type' => MENU_LOCAL_TASK,
- 'file' => 'search.inc',
- 'weight' => 5
- );
- /* $items['textbook_run'] = array(
- 'title' => 'Download Codes',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('textbook_companion_run_form_ajax'),
- 'access arguments' => array('access content'),
- 'type' => MENU_NORMAL_ITEM,
- 'file' => 'run.inc',
- );*/
- $items['textbook-companion/textbook-run'] = array(
- 'title' => 'Download Codes',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array(
- 'textbook_companion_run_form'
- ),
- 'access arguments' => array(
- 'access content'
- ),
- 'type' => MENU_NORMAL_ITEM,
- 'file' => 'run.inc'
- );
- /*$items['textbook_run_ajax'] = array(
- 'page callback' => 'textbook_run_ajax',
- 'access callback' => TRUE,
- 'file' => 'run.inc',
- );*/
- /*$items['download_codes'] = array(
- 'title' => 'Download Codes',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('textbook_companion_run_form_ajax'),
- 'access arguments' => array('access content'),
- 'type' => MENU_NORMAL_ITEM,
- 'file' => 'run.inc',
- );*/
- $items['textbook-companion/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['textbook-companion/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['textbook-companion/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['textbook-companion/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['textbook-companion/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['textbook-companion/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['textbook-companion/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['textbook-companion/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['textbook-companion/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['textbook-companion/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' => 'Textbook 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['textbook-companion/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['textbook-companion/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['textbook-companion/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['textbook-companion/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['textbook-companion/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['textbook-companion/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['textbook-companion/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['textbook-companion/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['textbook-companion/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['textbook-companion/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["textbook-companion/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['textbook-companion/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["textbook-companion/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['textbook-companion/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['textbook-companion/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['textbook-companion/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['textbook-companion/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['textbook-companion/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['textbook-companion/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['textbook-companion/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['textbook-companion/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['textbook-companion/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['textbook-companion/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['textbook-companion/code-approval/edit-code-submission'] = array(
+ 'title' => 'Edit Code Submission',
+ 'description' => 'Enable users code submission interface',
+ // 'page callback' => 'drupal_get_form',
+ 'page callback' => 'edit_code_submission',
+ // 'page arguments' => array(
+ // 'edit_code_submission_form'
+ // ),
+ 'access arguments' => array(
+ 'bulk manage code'
+ ),
+ 'type' => MENU_LOCAL_TASK,
+ 'weight' => 3,
+ 'file' => 'code_approval.inc'
+ );*/
+ $items['textbook-companion/code-approval/edit-code-submission/edit'] = array(
+ 'title' => 'Edit Code Submission',
+ 'description' => 'Enable users code submission interface',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array(
+ 'edit_code_submission_form'
+ ),
+ 'access arguments' => array(
+ 'bulk manage code'
+ ),
+ 'file' => 'code_approval.inc'
+ );
+ $items['textbook-companion/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['textbook-companion/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-companion/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-companion/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-companion/textbook-search/book'] = array(
+ 'title' => 'By Book Title',
+ 'description' => '',
+ 'page callback' => 'textbook_companion_browse_book',
+ 'access arguments' => array(
+ 'access content'
+ ),
+ 'type' => MENU_LOCAL_TASK,
+ 'file' => 'search.inc',
+ 'weight' => 2
+ );
+ $items['textbook-companion/textbook-search/author'] = array(
+ 'title' => 'By Author',
+ 'description' => '',
+ 'page callback' => 'textbook_companion_browse_author',
+ 'access arguments' => array(
+ 'access content'
+ ),
+ 'type' => MENU_LOCAL_TASK,
+ 'file' => 'search.inc',
+ 'weight' => 3
+ );
+ $items['textbook-companion/textbook-search/college'] = array(
+ 'title' => 'By College',
+ 'description' => '',
+ 'page callback' => 'textbook_companion_browse_college',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array(
+ 'textbook_companion_browse_college_form'
+ ),
+ 'access arguments' => array(
+ 'access content'
+ ),
+ 'type' => MENU_LOCAL_TASK,
+ 'file' => 'search.inc',
+ 'weight' => 4
+ );
+ $items['textbook-companion/textbook-search/student'] = array(
+ 'title' => 'By Student',
+ 'description' => '',
+ 'page callback' => 'textbook_companion_browse_student',
+ 'access arguments' => array(
+ 'access content'
+ ),
+ 'type' => MENU_LOCAL_TASK,
+ 'file' => 'search.inc',
+ 'weight' => 5
+ );
+ /* $items['textbook_run'] = array(
+ 'title' => 'Download Codes',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('textbook_companion_run_form_ajax'),
+ 'access arguments' => array('access content'),
+ 'type' => MENU_NORMAL_ITEM,
+ 'file' => 'run.inc',
+ );*/
+ $items['textbook-companion/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_CALLBACK,
+ 'file' => 'run.inc'
+ );
+ /*$items['textbook_run_ajax'] = array(
+ 'page callback' => 'textbook_run_ajax',
+ 'access callback' => TRUE,
+ 'file' => 'run.inc',
+ );*/
+ /*$items['download_codes'] = array(
+ 'title' => 'Download Codes',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('textbook_companion_run_form_ajax'),
+ 'access arguments' => array('access content'),
+ 'type' => MENU_NORMAL_ITEM,
+ 'file' => 'run.inc',
+ );*/
+ $items['textbook-companion/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_CALLBACK,
+ 'file' => 'run.inc'
+ );
+ /* download callbacks */
+ $items['textbook-companion/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['textbook-companion/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['textbook-companion/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['textbook-companion/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['textbook-companion/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['textbook-companion/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['textbook-companion/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['textbook-companion/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['textbook-companion/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' => 'Textbook 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['textbook-companion/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['textbook-companion/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['textbook-companion/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['textbook-companion/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['textbook-companion/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['textbook-companion/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['textbook-companion/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['textbook-companion/certificates'] = 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['textbook-companion/certificates/generate-pdf'] = array(
+ 'title' => 'Download Certificate',
+ 'description' => 'Download Certificate',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array(
+ 'generate_pdf'
+ ),
+ 'type' => MENU_CALLBACK,
+ 'access arguments' => array(
+ 'generate pdf'
+ ),
+ 'file' => 'pdf/generate_pdf.inc'
+ );
+ $items["textbook-companion/certificates/verify"] = array(
+ "title" => "Certificate Verification",
+ "page callback" => "verify_certificates",
+ "access arguments" => array(
+ "verify certificates"
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'pdf/verify_certificates.inc'
+ );
+ /*******************/
+ $items['Summer_Internship_Forms/forms'] = array(
+ 'title' => 'List of all Copyright Form and Undertaking Form for books',
+ 'description' => 'List of all Copyright Form for books',
+ 'page callback' => '_list_all_copyright_forms',
+ 'access arguments' => array(
+ 'list all certificates'
+ ),
+ 'type' => MENU_LOCAL_TASK,
+ 'file' => 'pdf/list_all_form_pdf.inc'
+ );
+ $items['Summer_Internship_Forms/copyright-form/generate_pdf'] = array(
+ 'title' => 'Download Copyright Form for books',
+ 'description' => 'Download Copyright Form for books',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array(
+ 'generate_copyright_form_pdf'
+ ),
+ 'access arguments' => array(
+ 'generate pdf'
+ ),
+ 'type' => MENU_LOCAL_TASK,
+ 'file' => 'pdf/generate_pdf.inc'
+ );
+ $items['Summer_Internship_Forms/undertaking-form/generate_pdf'] = array(
+ 'title' => 'Download Undertaking Form for books',
+ 'description' => 'Download Undertaking Form for books',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array(
+ 'generate_undertaking_form_pdf'
+ ),
+ 'access arguments' => array(
+ 'generate pdf'
+ ),
+ 'type' => MENU_LOCAL_TASK,
+ 'file' => 'pdf/generate_pdf.inc'
+ );
+ $items['textbook-companion/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["textbook-companion/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;
}
/**
* Implementation of hook_perm().
*/
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.")
- )
- );
+ 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.")
+ ),
+ "list all certificates" => array(
+ "title" => t("list the certificates"),
+ "description" => t("list the certificates")
+ ),
+ "verify certificates" => array(
+ "title" => t("verify the certificates"),
+ "description" => t("verify the certificates")
+ )
+ );
}
+
/* Aicte books pickup before the proposal form */
/*function textbook_companion_aicte_proposal_form($form_state) {
/* $query = "
@@ -1011,1626 +1067,1173 @@ drupal_set_message("Thank you for reporting.", "status");
*/
function textbook_companion_aicte_proposal_all()
{
- global $user;
- $page_content = "";
- if (!$user->uid) {
- /*$query = "
- SELECT * FROM textbook_companion_aicte
- WHERE status = 0
- ";
- $result = db_query($query);*/
- $query = db_select('textbook_companion_aicte');
- $query->fields('textbook_companion_aicte');
- $query->condition('status', 0);
- $result = $query->execute();
- $page_content .= "<ul>";
- $page_content .= "<li>These are the list of books available for <em>Textbook Companion</em> proposal.</li>";
- $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' 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 */
- /* $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);
- $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'/>";
- //$page_content .= drupal_get_form("textbook_companion_aicte_report_form");
- $textbook_companion_aicte_proposal_form = drupal_get_form("textbook_companion_aicte_proposal_form");
- $page_content .= drupal_render($textbook_companion_aicte_proposal_form);
- return $page_content;
+ global $user;
+ $page_content = "";
+ if (!$user->uid)
+ {
+ /*$query = "
+ SELECT * FROM textbook_companion_aicte
+ WHERE status = 0
+ ";
+ $result = db_query($query);*/
+ $query = db_select('textbook_companion_aicte');
+ $query->fields('textbook_companion_aicte');
+ $query->condition('status', 0);
+ $result = $query->execute();
+ $page_content .= "<ul>";
+ $page_content .= "<li>These are the list of books available for <em>Textbook Companion</em> proposal.</li>";
+ $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' 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 */
+ /* $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);
+ $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'/>";
+ //$page_content .= drupal_get_form("textbook_companion_aicte_report_form");
+ $textbook_companion_aicte_proposal_form = drupal_get_form("textbook_companion_aicte_proposal_form");
+ $page_content .= drupal_render($textbook_companion_aicte_proposal_form);
+ return $page_content;
}
/*non aicte book proposal */
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;
- case 5:
- drupal_set_message(t('You have submitted your all codes.'), '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;
- }
- }
- }
- //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;
+ 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;
+ case 5:
+ drupal_set_message(t('You have submitted your all codes.'), '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_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');
- drupal_goto('');
- return;
- }
- /* check if user has already submitted a proposal */
- /*$proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE uid = %d ORDER BY id DESC LIMIT 1", $user->uid);*/
- $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;
- }
- }
- }
- $book_proposal_form = drupal_get_form("book_proposal_form");
- $page_content .= drupal_render($book_proposal_form);
- // drupal_goto("aicte_proposal");
- return $page_content;
-}
-/*function book_proposal_form($form, $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</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(
-'DWSIM Website' => 'DWSIM 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' => _list_of_departments(),
-'#required' => TRUE
-);
-$form['university'] = array(
-'#type' => 'textfield',
-'#title' => t('University/ Institute'),
-'#size' => 80,
-'#maxlength' => 200,
-'#required' => TRUE,
-'#attributes' => array(
-'placeholder' => 'Insert full name of your institute/ university.... '
-)
-);
-$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'),
-'#selected' => array(
-'' => '-select-'
-),
-'#options' => _list_of_states(),
-'#validated' => TRUE,
-'#states' => array(
-'visible' => array(
-':input[name="country"]' => array(
-'value' => 'India'
-)
-)
-)
-);
-$form['city'] = array(
-'#type' => 'select',
-'#title' => t('City'),
-'#options' => _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['hr'] = array(
-'#type' => 'item',
-'#markup' => '<hr>'
-);
-$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'),
-'#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' => 'select',
-'#title' => t('Version'),
-'#options' => _list_of_software_version(),
-'#required' => TRUE
-);
-$form['older'] = array(
-'#type' => 'textfield',
-'#size' => 30,
-'#maxlength' => 50,
-//'#required' => TRUE,
-'#description' => t('Specify the Older version used'),
-'#states' => array(
-'visible' => array(
-':input[name="version"]' => array(
-'value' => 'olderversion'
-)
-)
-)
-);
-$form['completion_date'] = array(
-'#type' => 'textfield',
-'#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
-);
-$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' => 'hidden',
-'#default_value' => 'Not available'
-);
-/*$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' => '0',
-'#required' => FALSE
-);
-$form['reference'] = array(
-'#type' => 'hidden',
-'#default_value' => 'Not available',
-);
-/*$form['reference'] = array(
-'#type' => 'textarea',
-'#title' => t('Reference'),
-'#required' => TRUE,
-'#size' => 500,
-'#maxlength' => 500,
-'#attributes' => array(
-'placeholder' => 'Links of the syllabus must be provided....'
-)
-);*/
-/*$form['scilab_version'] = array(
-'#type' => 'textfield',
-'#title' => t('Scilab Version'),
-'#required' => TRUE,
-'#size' => 10,
-'#maxlength' => 10,
-);*/
-/*$form['form_type'] = array(
-'#type' => 'hidden',
-'#value' => 1
-);
-$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
-);
-$form['preference1']['author1'] = array(
-'#type' => 'textfield',
-'#title' => t('Author Name'),
-'#size' => 30,
-'#maxlength' => 100,
-'#required' => TRUE
-//'#value' => $row1->author,
-//'#disabled' => ($row1->author?TRUE:FALSE),
-);
-$form['preference1']['isbn1'] = array(
-'#type' => 'textfield',
-'#title' => t('ISBN No'),
-'#size' => 30,
-'#maxlength' => 25,
-'#required' => TRUE
-// '#value' => $row1->isbn,
-// '#disabled' => ($row1->isbn?TRUE:FALSE),
-);
-$form['preference1']['publisher1'] = array(
-'#type' => 'textfield',
-'#title' => t('Publisher & Place'),
-'#size' => 30,
-'#maxlength' => 50,
-'#required' => TRUE
-//'#value' => $row1->publisher,
-);
-$form['preference1']['edition1'] = array(
-'#type' => 'textfield',
-'#title' => t('Edition'),
-'#size' => 4,
-'#maxlength' => 2,
-'#required' => TRUE
-//'#value' => $row1->edition,
-);
-$form['preference1']['year1'] = array(
-'#type' => 'textfield',
-'#title' => t('Year of pulication'),
-'#size' => 4,
-'#maxlength' => 4,
-'#required' => TRUE
-//'#value' => $row1->year,
-);
-$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
-//'#value' => $row2->book,
-//'#disabled' => ($row2->book?TRUE:FALSE),
-);
-$form['preference2']['author2'] = array(
-'#type' => 'textfield',
-'#title' => t('Author Name'),
-'#size' => 30,
-'#maxlength' => 100,
-'#required' => TRUE
-//'#value' => $row2->author,
-//'#disabled' => ($row2->author?TRUE:FALSE),
-);
-$form['preference2']['isbn2'] = array(
-'#type' => 'textfield',
-'#title' => t('ISBN No'),
-'#size' => 30,
-'#maxlength' => 25,
-'#required' => TRUE
-// '#value' => $row2->isbn,
-// '#disabled' => ($row2->isbn?TRUE:FALSE),
-);
-$form['preference2']['publisher2'] = array(
-'#type' => 'textfield',
-'#title' => t('Publisher & Place'),
-'#size' => 30,
-'#maxlength' => 50,
-'#required' => TRUE
-//'#value' => $row2->publisher,
-);
-$form['preference2']['edition2'] = array(
-'#type' => 'textfield',
-'#title' => t('Edition'),
-'#size' => 4,
-'#maxlength' => 2,
-'#required' => TRUE
-//'#value' => $row2->edition,
-);
-$form['preference2']['year2'] = array(
-'#type' => 'textfield',
-'#title' => t('Year of pulication'),
-'#size' => 4,
-'#maxlength' => 4,
-'#required' => TRUE
-//'#value' => $row2->year,
-);
-$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
-//'#value' => $row3->book,
-//'#disabled' => ($row3->book?TRUE:FALSE),
-);
-$form['preference3']['author3'] = array(
-'#type' => 'textfield',
-'#title' => t('Author Name'),
-'#size' => 30,
-'#maxlength' => 100,
-'#required' => TRUE
-//'#value' => $row3->author,
-// '#disabled' => ($row3->author?TRUE:FALSE),
-);
-$form['preference3']['isbn3'] = array(
-'#type' => 'textfield',
-'#title' => t('ISBN No'),
-'#size' => 30,
-'#maxlength' => 25,
-'#required' => TRUE
-//'#value' => $row3->isbn,
-//'#disabled' => ($row3->isbn?TRUE:FALSE),
-);
-$form['preference3']['publisher3'] = array(
-'#type' => 'textfield',
-'#title' => t('Publisher & Place'),
-'#size' => 30,
-'#maxlength' => 50,
-'#required' => TRUE
-// '#value' => $row3->publisher,
-);
-$form['preference3']['edition3'] = array(
-'#type' => 'textfield',
-'#title' => t('Edition'),
-'#size' => 4,
-'#maxlength' => 2,
-'#required' => TRUE
-//'#value' => $row3->edition,
-);
-$form['preference3']['year3'] = array(
-'#type' => 'textfield',
-'#title' => t('Year of pulication'),
-'#size' => 4,
-'#maxlength' => 4,
-'#required' => TRUE
-//'#value' => $row3->year,
-);
-/*$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['samplefile'] = array(
-'#type' => 'fieldset',
-'#title' => t('Sample Source Files'),
-'#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_source_extensions', '') . '</span>'
-);*/
-/*$form['submit'] = array(
-'#type' => 'submit',
-'#value' => t('Submit')
-);
-$form['dir_name1'] = array(
-'#type' => 'hidden',
-'#value' => 'None'
-);
-$form['dir_name2'] = array(
-'#type' => 'hidden',
-'#value' => 'None'
-);
-$form['dir_name3'] = array(
-'#type' => 'hidden',
-'#value' => 'None'
-);
-/* #value fix for #default_value bug drupal6
-foreach(array("preference1", "preference2", "preference3") as $preference) {
-foreach($form[$preference] as $key => $value) {
-if(!$form[$preference][$key]["#value"]) {
-unset($form[$preference][$key]["#value"]);
-}
+ global $user;
+ $page_content = "";
+ if (!$user->uid)
+ {
+ drupal_set_message('It is mandatory to login on this website to access the proposal form', 'error');
+ drupal_goto('');
+ return;
+ } //!$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
+ $book_proposal_form = drupal_get_form("book_proposal_form");
+ $page_content .= drupal_render($book_proposal_form);
+ // drupal_goto("aicte_proposal");
+ return $page_content;
}
-}*/
-/* return $form;
-}*/
-function book_proposal_form($form, $form_state)
+function book_proposal_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</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(
- 'DWSIM Website' => 'DWSIM 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' => _list_of_departments(),
- '#required' => TRUE
- );
- $form['university'] = array(
- '#type' => 'textfield',
- '#title' => t('University/ Institute'),
- '#size' => 80,
- '#maxlength' => 200,
- '#required' => TRUE,
- '#attributes' => array(
- 'placeholder' => 'Insert full name of your institute/ university.... '
- )
- );
- $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'),
- '#selected' => array(
- '' => '-select-'
- ),
- '#options' => _list_of_states(),
- '#validated' => TRUE,
- '#states' => array(
- 'visible' => array(
- ':input[name="country"]' => array(
- 'value' => 'India'
- )
- )
- )
- );
- $form['city'] = array(
- '#type' => 'select',
- '#title' => t('City'),
- '#options' => _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['hr'] = array(
- '#type' => 'item',
- '#markup' => '<hr>'
- );
- $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'),
- '#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' => 'select',
- '#title' => t('Version'),
- '#options' => _list_of_software_version(),
- '#required' => TRUE
- );
- $form['older'] = array(
- '#type' => 'textfield',
- '#size' => 30,
- '#maxlength' => 50,
- //'#required' => TRUE,
- '#description' => t('Specify the Older version used'),
- '#states' => array(
- 'visible' => array(
- ':input[name="version"]' => array(
- 'value' => 'olderversion'
- )
- )
- )
- );
- $form['completion_date'] = array(
- '#type' => 'textfield',
- '#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
- );
- $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' => 500,
- '#maxlength' => 500,
- '#attributes' => array(
- 'placeholder' => 'Links of the syllabus must be provided....'
- )
- );
- $form['form_type'] = array(
- '#type' => 'hidden',
- '#value' => 1
- );
- $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
- );
- $form['preference1']['author1'] = array(
- '#type' => 'textfield',
- '#title' => t('Author Name'),
- '#size' => 30,
- '#maxlength' => 100,
- '#required' => TRUE
- //'#value' => $row1->author,
- //'#disabled' => ($row1->author?TRUE:FALSE),
- );
- $form['preference1']['isbn1'] = array(
- '#type' => 'textfield',
- '#title' => t('ISBN No'),
- '#size' => 30,
- '#maxlength' => 25,
- '#required' => TRUE
- // '#value' => $row1->isbn,
- // '#disabled' => ($row1->isbn?TRUE:FALSE),
- );
- $form['preference1']['publisher1'] = array(
- '#type' => 'textfield',
- '#title' => t('Publisher & Place'),
- '#size' => 30,
- '#maxlength' => 50,
- '#required' => TRUE
- //'#value' => $row1->publisher,
- );
- $form['preference1']['edition1'] = array(
- '#type' => 'textfield',
- '#title' => t('Edition'),
- '#size' => 4,
- '#maxlength' => 2,
- '#required' => TRUE
- //'#value' => $row1->edition,
- );
- $form['preference1']['year1'] = array(
- '#type' => 'textfield',
- '#title' => t('Year of publication'),
- '#size' => 4,
- '#maxlength' => 4,
- '#required' => TRUE
- //'#value' => $row1->year,
- );
- /*$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
- //'#value' => $row2->book,
- //'#disabled' => ($row2->book?TRUE:FALSE),
- );
- $form['preference2']['author2'] = array(
- '#type' => 'textfield',
- '#title' => t('Author Name'),
- '#size' => 30,
- '#maxlength' => 100,
- '#required' => TRUE
- //'#value' => $row2->author,
- //'#disabled' => ($row2->author?TRUE:FALSE),
- );
- $form['preference2']['isbn2'] = array(
- '#type' => 'textfield',
- '#title' => t('ISBN No'),
- '#size' => 30,
- '#maxlength' => 25,
- '#required' => TRUE
- // '#value' => $row2->isbn,
- // '#disabled' => ($row2->isbn?TRUE:FALSE),
- );
- $form['preference2']['publisher2'] = array(
- '#type' => 'textfield',
- '#title' => t('Publisher & Place'),
- '#size' => 30,
- '#maxlength' => 50,
- '#required' => TRUE
- //'#value' => $row2->publisher,
- );
- $form['preference2']['edition2'] = array(
- '#type' => 'textfield',
- '#title' => t('Edition'),
- '#size' => 4,
- '#maxlength' => 2,
- '#required' => TRUE
- //'#value' => $row2->edition,
- );
- $form['preference2']['year2'] = array(
- '#type' => 'textfield',
- '#title' => t('Year of pulication'),
- '#size' => 4,
- '#maxlength' => 4,
- '#required' => TRUE
- //'#value' => $row2->year,
- );
- $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
- //'#value' => $row3->book,
- //'#disabled' => ($row3->book?TRUE:FALSE),
- );
- $form['preference3']['author3'] = array(
- '#type' => 'textfield',
- '#title' => t('Author Name'),
- '#size' => 30,
- '#maxlength' => 100,
- '#required' => TRUE
- //'#value' => $row3->author,
- // '#disabled' => ($row3->author?TRUE:FALSE),
- );
- $form['preference3']['isbn3'] = array(
- '#type' => 'textfield',
- '#title' => t('ISBN No'),
- '#size' => 30,
- '#maxlength' => 25,
- '#required' => TRUE
- //'#value' => $row3->isbn,
- //'#disabled' => ($row3->isbn?TRUE:FALSE),
- );
- $form['preference3']['publisher3'] = array(
- '#type' => 'textfield',
- '#title' => t('Publisher & Place'),
- '#size' => 30,
- '#maxlength' => 50,
- '#required' => TRUE
- // '#value' => $row3->publisher,
- );
- $form['preference3']['edition3'] = array(
- '#type' => 'textfield',
- '#title' => t('Edition'),
- '#size' => 4,
- '#maxlength' => 2,
- '#required' => TRUE
- //'#value' => $row3->edition,
- );
- $form['preference3']['year3'] = array(
- '#type' => 'textfield',
- '#title' => t('Year of pulication'),
- '#size' => 4,
- '#maxlength' => 4,
- '#required' => TRUE
- //'#value' => $row3->year,
- );
- /*$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['samplefile'] = array(
- '#type' => 'fieldset',
- '#title' => t('Sample Source Files'),
- '#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_source_extensions', '') . '</span>'
- );
- $form['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Submit')
- );
- $form['dir_name'] = array(
- '#type' => 'hidden',
- '#value' => 'None'
- );
- /* #value fix for #default_value bug drupal6
- foreach(array("preference1", "preference2", "preference3") as $preference) {
- foreach($form[$preference] as $key => $value) {
- if(!$form[$preference][$key]["#value"]) {
- unset($form[$preference][$key]["#value"]);
- }
- }
- }*/
- return $form;
+ 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(
+ 'DWSIM Website' => 'DWSIM 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' => _list_of_departments(),
+ '#required' => TRUE
+ );
+ $form['university'] = array(
+ '#type' => 'textfield',
+ '#title' => t('University/ Institute'),
+ '#size' => 80,
+ '#maxlength' => 200,
+ '#required' => TRUE,
+ '#attributes' => array(
+ 'placeholder' => 'Insert full name of your institute/ university.... '
+ )
+ );
+ $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'),
+ '#selected' => array(
+ '' => '-select-'
+ ),
+ '#options' => _list_of_states(),
+ '#validated' => TRUE,
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="country"]' => array(
+ 'value' => 'India'
+ )
+ )
+ )
+ );
+ $form['city'] = array(
+ '#type' => 'select',
+ '#title' => t('City'),
+ '#options' => _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['hr'] = array(
+ '#type' => 'item',
+ '#markup' => '<hr>'
+ );
+ $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'),
+ '#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' => 'select',
+ '#title' => t('Version'),
+ '#options' => _list_of_software_version(),
+ '#required' => TRUE
+ );
+ $form['older'] = array(
+ '#type' => 'textfield',
+ '#size' => 30,
+ '#maxlength' => 50,
+ //'#required' => TRUE,
+ '#description' => t('Specify the Older version used'),
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="version"]' => array(
+ 'value' => 'olderversion'
+ )
+ )
+ )
+ );
+ $form['completion_date'] = array(
+ '#type' => 'textfield',
+ '#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
+ );
+ $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' => 500,
+ '#maxlength' => 500,
+ '#attributes' => array(
+ 'placeholder' => 'Links of the syllabus must be provided....'
+ )
+ );
+ $form['form_type'] = array(
+ '#type' => 'hidden',
+ '#value' => 1
+ );
+ $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
+ );
+ $form['preference1']['author1'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Author Name'),
+ '#size' => 30,
+ '#maxlength' => 100,
+ '#required' => TRUE
+ //'#value' => $row1->author,
+ //'#disabled' => ($row1->author?TRUE:FALSE),
+ );
+ $form['preference1']['isbn1'] = array(
+ '#type' => 'textfield',
+ '#title' => t('ISBN No'),
+ '#size' => 30,
+ '#maxlength' => 25,
+ '#required' => TRUE
+ // '#value' => $row1->isbn,
+ // '#disabled' => ($row1->isbn?TRUE:FALSE),
+ );
+ $form['preference1']['publisher1'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Publisher & Place'),
+ '#size' => 30,
+ '#maxlength' => 50,
+ '#required' => TRUE
+ //'#value' => $row1->publisher,
+ );
+ $form['preference1']['edition1'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Edition'),
+ '#size' => 4,
+ '#maxlength' => 2,
+ '#required' => TRUE
+ //'#value' => $row1->edition,
+ );
+ $form['preference1']['year1'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Year of publication'),
+ '#size' => 4,
+ '#maxlength' => 4,
+ '#required' => TRUE
+ //'#value' => $row1->year,
+ );
+ /*$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
+ //'#value' => $row2->book,
+ //'#disabled' => ($row2->book?TRUE:FALSE),
+ );
+ $form['preference2']['author2'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Author Name'),
+ '#size' => 30,
+ '#maxlength' => 100,
+ '#required' => TRUE
+ //'#value' => $row2->author,
+ //'#disabled' => ($row2->author?TRUE:FALSE),
+ );
+ $form['preference2']['isbn2'] = array(
+ '#type' => 'textfield',
+ '#title' => t('ISBN No'),
+ '#size' => 30,
+ '#maxlength' => 25,
+ '#required' => TRUE
+ // '#value' => $row2->isbn,
+ // '#disabled' => ($row2->isbn?TRUE:FALSE),
+ );
+ $form['preference2']['publisher2'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Publisher & Place'),
+ '#size' => 30,
+ '#maxlength' => 50,
+ '#required' => TRUE
+ //'#value' => $row2->publisher,
+ );
+ $form['preference2']['edition2'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Edition'),
+ '#size' => 4,
+ '#maxlength' => 2,
+ '#required' => TRUE
+ //'#value' => $row2->edition,
+ );
+ $form['preference2']['year2'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Year of pulication'),
+ '#size' => 4,
+ '#maxlength' => 4,
+ '#required' => TRUE
+ //'#value' => $row2->year,
+ );
+ $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
+ //'#value' => $row3->book,
+ //'#disabled' => ($row3->book?TRUE:FALSE),
+ );
+ $form['preference3']['author3'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Author Name'),
+ '#size' => 30,
+ '#maxlength' => 100,
+ '#required' => TRUE
+ //'#value' => $row3->author,
+ // '#disabled' => ($row3->author?TRUE:FALSE),
+ );
+ $form['preference3']['isbn3'] = array(
+ '#type' => 'textfield',
+ '#title' => t('ISBN No'),
+ '#size' => 30,
+ '#maxlength' => 25,
+ '#required' => TRUE
+ //'#value' => $row3->isbn,
+ //'#disabled' => ($row3->isbn?TRUE:FALSE),
+ );
+ $form['preference3']['publisher3'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Publisher & Place'),
+ '#size' => 30,
+ '#maxlength' => 50,
+ '#required' => TRUE
+ // '#value' => $row3->publisher,
+ );
+ $form['preference3']['edition3'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Edition'),
+ '#size' => 4,
+ '#maxlength' => 2,
+ '#required' => TRUE
+ //'#value' => $row3->edition,
+ );
+ $form['preference3']['year3'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Year of pulication'),
+ '#size' => 4,
+ '#maxlength' => 4,
+ '#required' => TRUE
+ //'#value' => $row3->year,
+ );
+ /*$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['samplefile'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Sample Source Files'),
+ '#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_source_extensions', '') . '</span>'
+ );
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit')
+ );
+ $form['dir_name'] = array(
+ '#type' => 'hidden',
+ '#value' => 'None'
+ );
+ /* #value fix for #default_value bug drupal6
+ foreach(array("preference1", "preference2", "preference3") as $preference) {
+ foreach($form[$preference] as $key => $value) {
+ if(!$form[$preference][$key]["#value"]) {
+ unset($form[$preference][$key]["#value"]);
+ }
+ }
+ }*/
+ return $form;
}
function book_proposal_form_validate($form, &$form_state)
{
- /* 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 */
- $cur_year = date('Y');
- if (!preg_match('/^[A-Za-z]/', $form_state['values']['book1']))
- form_set_error('book1', t('Invalid book name for Book Preference 1'));
- if (!preg_match('/^[A-Za-z]/', $form_state['values']['author1']))
- if (!preg_match('/^[0-9\-xX]+$/', $form_state['values']['isbn1']))
- form_set_error('isbn1', t('Invalid ISBN for Book Preference 1'));
- 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']['year1']))
- form_set_error('year1', t('Invalid year of pulication for Book Preference 1'));
- 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']['book1'] && $form_state['values']['author1']) {
- $bk1 = trim($form_state['values']['book1']);
- $auth1 = trim($form_state['values']['author1']);
- //var_dump(_dir_name($bk1, $auth1))
- $pref_id = NULL;
- if (_dir_name($bk1, $auth1, $pref_id) != NULL) {
- $form_state['values']['dir_name1'] = _dir_name($bk1, $auth1, $pref_id);
- }
- }
- /*****************************************************************************
- if (!preg_match('/^[0-9\-xX]+$/', $form_state['values']['isbn2']))
- form_set_error('isbn2', t('Invalid ISBN 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-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 ($form_state['values']['book2'] && $form_state['values']['author2']) {
- $bk2 = trim($form_state['values']['book2']);
- $auth2 = trim($form_state['values']['author2']);
- //var_dump(_dir_name($bk1, $auth1))
- $pref_id = NULL;
- if (_dir_name($bk2, $auth2, $pref_id) != NULL) {
- $form_state['values']['dir_name2'] = _dir_name($bk2, $auth2, $pref_id);
- }
- /*****************************************************************************
- }
- if (!preg_match('/^[0-9\-xX]+$/', $form_state['values']['isbn3']))
- form_set_error('isbn3', t('Invalid ISBN for Book Preference 3'));
- 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'));
- 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'));
- if ($form_state['values']['book3'] && $form_state['values']['author3']) {
- $bk3 = trim($form_state['values']['book3']);
- $auth3 = trim($form_state['values']['author3']);
- //var_dump(_dir_name($bk1, $auth1))
- $pref_id = NULL;
- if (_dir_name($bk1, $auth1, $pref_id) != NULL) {
- $form_state['values']['dir_name3'] = _dir_name($bk3, $auth3, $pref_id);
- }
- /*****************************************************************************
-
- }*/
- if ($form_state['values']['version'] == 'olderversion') {
- if ($form_state['values']['older'] == '') {
- form_set_error('older', t('Please provide valid version'));
- }
- }
- 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_source_extensions', '');
- break;
- }
- $allowed_extensions = explode(',', $allowed_extensions_str);
- $fnames = explode('.', strtolower($_FILES['files']['name'][$file_form_name]));
- $temp_extension = end($fnames);
- 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.'));
- }
- }
- }
- if ($form_state['values']['version'] == 'olderversion') {
- if ($form_state['values']['older'] == '') {
- form_set_error('older', t('Please provide valid version'));
- }
- }
- return;
+ /* 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 */
+ $cur_year = date('Y');
+ if (!preg_match('/^[A-Za-z]/', $form_state['values']['book1']))
+ form_set_error('book1', t('Invalid book name for Book Preference 1'));
+ if (!preg_match('/^[A-Za-z]/', $form_state['values']['author1']))
+ if (!preg_match('/^[0-9\-xX]+$/', $form_state['values']['isbn1']))
+ form_set_error('isbn1', t('Invalid ISBN for Book Preference 1'));
+ 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']['year1']))
+ form_set_error('year1', t('Invalid year of pulication for Book Preference 1'));
+ 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']['book1'] && $form_state['values']['author1'])
+ {
+ $bk1 = trim($form_state['values']['book1']);
+ $auth1 = trim($form_state['values']['author1']);
+ //var_dump(_dir_name($bk1, $auth1))
+ $pref_id = NULL;
+ if (_dir_name($bk1, $auth1, $pref_id) != NULL)
+ {
+ $form_state['values']['dir_name1'] = _dir_name($bk1, $auth1, $pref_id);
+ } //_dir_name($bk1, $auth1, $pref_id) != NULL
+ } //$form_state['values']['book1'] && $form_state['values']['author1']
+ /*****************************************************************************
+ if (!preg_match('/^[0-9\-xX]+$/', $form_state['values']['isbn2']))
+ form_set_error('isbn2', t('Invalid ISBN 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-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 ($form_state['values']['book2'] && $form_state['values']['author2']) {
+ $bk2 = trim($form_state['values']['book2']);
+ $auth2 = trim($form_state['values']['author2']);
+ //var_dump(_dir_name($bk1, $auth1))
+ $pref_id = NULL;
+ if (_dir_name($bk2, $auth2, $pref_id) != NULL) {
+ $form_state['values']['dir_name2'] = _dir_name($bk2, $auth2, $pref_id);
+ }
+ /*****************************************************************************
+ }
+ if (!preg_match('/^[0-9\-xX]+$/', $form_state['values']['isbn3']))
+ form_set_error('isbn3', t('Invalid ISBN for Book Preference 3'));
+ 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'));
+ 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'));
+ if ($form_state['values']['book3'] && $form_state['values']['author3']) {
+ $bk3 = trim($form_state['values']['book3']);
+ $auth3 = trim($form_state['values']['author3']);
+ //var_dump(_dir_name($bk1, $auth1))
+ $pref_id = NULL;
+ if (_dir_name($bk1, $auth1, $pref_id) != NULL) {
+ $form_state['values']['dir_name3'] = _dir_name($bk3, $auth3, $pref_id);
+ }
+ /*****************************************************************************
+
+ }*/
+ if ($form_state['values']['version'] == 'olderversion')
+ {
+ if ($form_state['values']['older'] == '')
+ {
+ form_set_error('older', t('Please provide valid version'));
+ } //$form_state['values']['older'] == ''
+ } //$form_state['values']['version'] == 'olderversion'
+ 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_source_extensions', '');
+ break;
+ } //$file_type
+ $allowed_extensions = explode(',', $allowed_extensions_str);
+ $fnames = explode('.', strtolower($_FILES['files']['name'][$file_form_name]));
+ $temp_extension = end($fnames);
+ 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'])
+ if ($form_state['values']['version'] == 'olderversion')
+ {
+ if ($form_state['values']['older'] == '')
+ {
+ form_set_error('older', t('Please provide valid version'));
+ } //$form_state['values']['older'] == ''
+ } //$form_state['values']['version'] == 'olderversion'
+ return;
}
function book_proposal_form_submit($form, &$form_state, $directory_name = NULL)
{
- global $user;
- $root_path = textbook_companion_samplecode_path();
- $selections = variable_get("aicte_" . $user->uid, "");
- 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);
- $dwsim_version = $form_state['values']['version'];
- if ($form_state['values']['version'] == 'olderversion') {
- $form_state['values']['version'] = $form_state['values']['older'];
- }
- if ($form_state['values']['country'] == 'other') {
- $form_state['values']['country'] = trim($form_state['values']['other_country']);
- $form_state['values']['all_state'] = trim($form_state['values']['other_state']);
- }
- 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'];
- }
- $form_state['values']['reason'] = $my_reason;
- }
- //var_dump($form_state['values']);
- /*$query = "INSERT INTO {textbook_companion_proposal}
- (uid, approver_uid, full_name, mobile, gender, how_project, course, branch, university, faculty, reviewer, completion_date, creation_date, approval_date, proposal_status, scilab_version, operating_system, teacher_email) VALUES (".$user->uid.", 0, '".ucwords(strtolower($form_state['values']['full_name']))."', '".$form_state['values']['mobile']."', '".$form_state['values']['gender']."', '".$form_state['values']['how_project']."', '".$form_state['values']['course']."', '".$form_state['values']['branch']."', '".$form_state['values']['university']."', '".ucwords(strtolower($form_state['values']['faculty']))."', '".ucwords(strtolower($form_state['values']['reviewer']))."', '".$completion_date_timestamp."', '".time()."', 0, 0, '".$scilab_version."', '".$form_state['values']['operating_system']."', '".$form_state['values']['faculty_email']."')";
-
- $result = db_query($query);*/
- $query = "INSERT INTO {textbook_companion_proposal}
+ global $user;
+ $root_path = textbook_companion_samplecode_path();
+ $selections = variable_get("aicte_" . $user->uid, "");
+ 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);
+ $dwsim_version = $form_state['values']['version'];
+ if ($form_state['values']['version'] == 'olderversion')
+ {
+ $form_state['values']['version'] = $form_state['values']['older'];
+ } //$form_state['values']['version'] == 'olderversion'
+ if ($form_state['values']['country'] == 'other')
+ {
+ $form_state['values']['country'] = trim($form_state['values']['other_country']);
+ $form_state['values']['all_state'] = trim($form_state['values']['other_state']);
+ } //$form_state['values']['country'] == 'other'
+ 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'];
+ }
+ $form_state['values']['reason'] = $my_reason;
+ } //isset($_POST['reason'])
+ //var_dump($form_state['values']);
+ /*$query = "INSERT INTO {textbook_companion_proposal}
+ (uid, approver_uid, full_name, mobile, gender, how_project, course, branch, university, faculty, reviewer, completion_date, creation_date, approval_date, proposal_status, scilab_version, operating_system, teacher_email) VALUES (".$user->uid.", 0, '".ucwords(strtolower($form_state['values']['full_name']))."', '".$form_state['values']['mobile']."', '".$form_state['values']['gender']."', '".$form_state['values']['how_project']."', '".$form_state['values']['course']."', '".$form_state['values']['branch']."', '".$form_state['values']['university']."', '".ucwords(strtolower($form_state['values']['faculty']))."', '".ucwords(strtolower($form_state['values']['reviewer']))."', '".$completion_date_timestamp."', '".time()."', 0, 0, '".$scilab_version."', '".$form_state['values']['operating_system']."', '".$form_state['values']['faculty_email']."')";
+
+ $result = db_query($query);*/
+ $query = "INSERT INTO {textbook_companion_proposal}
(uid, approver_uid, full_name, mobile, gender, how_project, course, branch, university,city,pincode,state,country, faculty, reviewer,reference, completion_date, creation_date, approval_date, proposal_status, dwsim_version, operating_system, teacher_email,reason,samplefilepath,proposal_type) VALUES (:uid, :approver_uid, :full_name, :mobile, :gender, :how_project, :course, :branch, :university, :city,:pincode,:state,:country, :faculty, :reviewer,:reference, :completion_date,
:creation_date, :approval_date, :proposal_status, :dwsim_version, :operating_system,
:teacher_email,:reason,:samplefilepath,:proposal_type)";
- $args = array(
- ":uid" => $user->uid,
- ":approver_uid" => 0,
- ":full_name" => trim(ucwords(strtolower($form_state['values']['full_name']))),
- ":mobile" => trim($form_state['values']['mobile']),
- ":gender" => $form_state['values']['gender'],
- ":how_project" => $form_state['values']['how_project'],
- ":course" => trim($form_state['values']['course']),
- ":branch" => $form_state['values']['branch'],
- ":university" => trim($form_state['values']['university']),
- ":city" => trim($form_state['values']['city']),
- ":pincode" => $form_state['values']['pincode'],
- ":state" => trim($form_state['values']['all_state']),
- ":country" => $form_state['values']['country'],
- ":faculty" => ucwords(strtolower($form_state['values']['faculty'])),
- ":reviewer" => ucwords(strtolower($form_state['values']['reviewer'])),
- ":reference" => trim($form_state['values']['reference']),
- ":completion_date" => $completion_date_timestamp,
- ":creation_date" => time(),
- ":approval_date" => 0,
- ":proposal_status" => 0,
- ":dwsim_version" => trim($form_state['values']['version']),
- ":operating_system" => trim($form_state['values']['operating_system']),
- ":teacher_email" => $form_state['values']['faculty_email'],
- ":reason" => $form_state['values']['reason'],
- ":samplefilepath" => "",
- ":proposal_type" => 0
- );
- $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');
- unlink($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');
- } 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']) {
- /*$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,
- 1,
- ucwords(strtolower($form_state['values']['book1'])),
- ucwords(strtolower($form_state['values']['author1'])),
- $form_state['values']['isbn1'],
- ucwords(strtolower($form_state['values']['publisher1'])),
- $form_state['values']['edition1'],
- $form_state['values']['year1'],
- 0,
- 0
- );*/
- $bk1 = trim($form_state['values']['book1']);
- $auth1 = trim($form_state['values']['author1']);
- $pref_id = NULL;
- $directory_name = _dir_name($bk1, $auth1, $pref_id);
- $query = "INSERT INTO {textbook_companion_preference}
+ $args = array(
+ ":uid" => $user->uid,
+ ":approver_uid" => 0,
+ ":full_name" => trim(ucwords(strtolower($form_state['values']['full_name']))),
+ ":mobile" => trim($form_state['values']['mobile']),
+ ":gender" => $form_state['values']['gender'],
+ ":how_project" => $form_state['values']['how_project'],
+ ":course" => trim($form_state['values']['course']),
+ ":branch" => $form_state['values']['branch'],
+ ":university" => trim($form_state['values']['university']),
+ ":city" => trim($form_state['values']['city']),
+ ":pincode" => $form_state['values']['pincode'],
+ ":state" => trim($form_state['values']['all_state']),
+ ":country" => $form_state['values']['country'],
+ ":faculty" => ucwords(strtolower($form_state['values']['faculty'])),
+ ":reviewer" => ucwords(strtolower($form_state['values']['reviewer'])),
+ ":reference" => trim($form_state['values']['reference']),
+ ":completion_date" => $completion_date_timestamp,
+ ":creation_date" => time(),
+ ":approval_date" => 0,
+ ":proposal_status" => 0,
+ ":dwsim_version" => trim($form_state['values']['version']),
+ ":operating_system" => trim($form_state['values']['operating_system']),
+ ":teacher_email" => $form_state['values']['faculty_email'],
+ ":reason" => $form_state['values']['reason'],
+ ":samplefilepath" => "",
+ ":proposal_type" => 0
+ );
+ $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');
+ unlink($root_path . $dest_path . $_FILES['files']['name'][$file_form_name]);
+ } //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'])
+ {
+ /*$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,
+ 1,
+ ucwords(strtolower($form_state['values']['book1'])),
+ ucwords(strtolower($form_state['values']['author1'])),
+ $form_state['values']['isbn1'],
+ ucwords(strtolower($form_state['values']['publisher1'])),
+ $form_state['values']['edition1'],
+ $form_state['values']['year1'],
+ 0,
+ 0
+ );*/
+ $bk1 = trim($form_state['values']['book1']);
+ $auth1 = trim($form_state['values']['author1']);
+ $pref_id = NULL;
+ $directory_name = _dir_name($bk1, $auth1, $pref_id);
+ $query = "INSERT INTO {textbook_companion_preference}
(proposal_id, pref_number, book, author, isbn, publisher, edition, year, category, approval_status, directory_name) VALUES (:proposal_id, :pref_number, :book, :author, :isbn, :publisher, :edition, :year, :category, :approval_status, :directory_name)
";
- $args = array(
- ":proposal_id" => $proposal_id,
- ":pref_number" => 1,
- ":book" => trim(ucwords(strtolower($form_state['values']['book1']))),
- ":author" => trim(ucwords(strtolower($form_state['values']['author1']))),
- ":isbn" => trim($form_state['values']['isbn1']),
- ":publisher" => trim(ucwords(strtolower($form_state['values']['publisher1']))),
- ":edition" => trim($form_state['values']['edition1']),
- ":year" => trim($form_state['values']['year1']),
- ":category" => 0,
- ":approval_status" => 0,
- ":directory_name" => $form_state['values']['dir_name1']
- );
- $result = db_query($query, $args, array(
- 'return' => Database::RETURN_INSERT_ID
- ));
- if (!$result) {
- drupal_set_message(t('Error receiving your first book preference.'), 'error');
- }
- }
- /*******************************************************/
- /* 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,
- 1,
- ucwords(strtolower($form_state['values']['book1'])),
- ucwords(strtolower($form_state['values']['author1'])),
- $form_state['values']['isbn1'],
- ucwords(strtolower($form_state['values']['publisher1'])),
- $form_state['values']['edition1'],
- $form_state['values']['year1'],
- 0,
- 0
- );*/
- /**$bk2 = trim($form_state['values']['book2']);
- $auth2 = trim($form_state['values']['author2']);
- $pref_id = NULL;
- $directory_name = _dir_name($bk2, $auth2, $pref_id);
- $query = "INSERT INTO {textbook_companion_preference}
- (proposal_id, pref_number, book, author, isbn, publisher, edition, year, category, approval_status, directory_name) VALUES (:proposal_id, :pref_number, :book, :author, :isbn, :publisher, :edition, :year, :category, :approval_status, :directory_name)
- ";
- $args = array(
- ":proposal_id" => $proposal_id,
-
-
- ":pref_number" => 2,
- ":book" => trim(ucwords(strtolower($form_state['values']['book2']))),
- ":author" => trim(ucwords(strtolower($form_state['values']['author2']))),
- ":isbn" => trim($form_state['values']['isbn2']),
- ":publisher" => trim(ucwords(strtolower($form_state['values']['publisher2']))),
- ":edition" => trim($form_state['values']['edition2']),
- ":year" => trim($form_state['values']['year2']),
- ":category" => 0,
- ":approval_status" => 0,
- ":directory_name" => $form_state['values']['dir_name2']
- );
- $result = db_query($query, $args, array(
- 'return' => Database::RETURN_INSERT_ID
- ));
- if (!$result) {
- drupal_set_message(t('Error receiving your second book preference.'), 'error');
- }
- }**/
- /*******************************************************/
- /**if ($form_state['values']['book3']) {
- /*$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,
- 1,
- ucwords(strtolower($form_state['values']['book1'])),
- ucwords(strtolower($form_state['values']['author1'])),
- $form_state['values']['isbn1'],
- ucwords(strtolower($form_state['values']['publisher1'])),
- $form_state['values']['edition1'],
- $form_state['values']['year1'],
- 0,
- 0
- );*/
- /** $bk3 = trim($form_state['values']['book3']);
- $auth3 = trim($form_state['values']['author3']);
- $pref_id = NULL;
- $directory_name = _dir_name($bk3, $auth3, $pref_id);
- $query = "INSERT INTO {textbook_companion_preference}
- (proposal_id, pref_number, book, author, isbn, publisher, edition, year, category, approval_status, directory_name) VALUES (:proposal_id, :pref_number, :book, :author, :isbn, :publisher, :edition, :year, :category, :approval_status, :directory_name)
- ";
- $args = array(
- ":proposal_id" => $proposal_id,
- ":pref_number" => 3,
- ":book" => trim(ucwords(strtolower($form_state['values']['book3']))),
- ":author" => trim(ucwords(strtolower($form_state['values']['author3']))),
- ":isbn" => trim($form_state['values']['isbn3']),
- ":publisher" => trim(ucwords(strtolower($form_state['values']['publisher3']))),
- ":edition" => trim($form_state['values']['edition3']),
- ":year" => trim($form_state['values']['year3']),
- ":category" => 0,
- ":approval_status" => 0,
- ":directory_name" => $form_state['values']['dir_name3']
- );
- $result = db_query($query, $args, array(
- 'return' => Database::RETURN_INSERT_ID
- ));
- 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', '');
- $param['proposal_received']['proposal_id'] = $proposal_id;
- $param['proposal_received']['user_id'] = $user->uid;
- $param['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(), $param, $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('');
+ $args = array(
+ ":proposal_id" => $proposal_id,
+ ":pref_number" => 1,
+ ":book" => trim(ucwords(strtolower($form_state['values']['book1']))),
+ ":author" => trim(ucwords(strtolower($form_state['values']['author1']))),
+ ":isbn" => trim($form_state['values']['isbn1']),
+ ":publisher" => trim(ucwords(strtolower($form_state['values']['publisher1']))),
+ ":edition" => trim($form_state['values']['edition1']),
+ ":year" => trim($form_state['values']['year1']),
+ ":category" => 0,
+ ":approval_status" => 0,
+ ":directory_name" => $form_state['values']['dir_name1']
+ );
+ $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
+ } //$form_state['values']['book1']
+ /*******************************************************/
+ /* 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,
+ 1,
+ ucwords(strtolower($form_state['values']['book1'])),
+ ucwords(strtolower($form_state['values']['author1'])),
+ $form_state['values']['isbn1'],
+ ucwords(strtolower($form_state['values']['publisher1'])),
+ $form_state['values']['edition1'],
+ $form_state['values']['year1'],
+ 0,
+ 0
+ );*/
+ /**$bk2 = trim($form_state['values']['book2']);
+ $auth2 = trim($form_state['values']['author2']);
+ $pref_id = NULL;
+ $directory_name = _dir_name($bk2, $auth2, $pref_id);
+ $query = "INSERT INTO {textbook_companion_preference}
+ (proposal_id, pref_number, book, author, isbn, publisher, edition, year, category, approval_status, directory_name) VALUES (:proposal_id, :pref_number, :book, :author, :isbn, :publisher, :edition, :year, :category, :approval_status, :directory_name)
+ ";
+ $args = array(
+ ":proposal_id" => $proposal_id,
+
+
+ ":pref_number" => 2,
+ ":book" => trim(ucwords(strtolower($form_state['values']['book2']))),
+ ":author" => trim(ucwords(strtolower($form_state['values']['author2']))),
+ ":isbn" => trim($form_state['values']['isbn2']),
+ ":publisher" => trim(ucwords(strtolower($form_state['values']['publisher2']))),
+ ":edition" => trim($form_state['values']['edition2']),
+ ":year" => trim($form_state['values']['year2']),
+ ":category" => 0,
+ ":approval_status" => 0,
+ ":directory_name" => $form_state['values']['dir_name2']
+ );
+ $result = db_query($query, $args, array(
+ 'return' => Database::RETURN_INSERT_ID
+ ));
+ if (!$result) {
+ drupal_set_message(t('Error receiving your second book preference.'), 'error');
+ }
+ }**/
+ /*******************************************************/
+ /**if ($form_state['values']['book3']) {
+ /*$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,
+ 1,
+ ucwords(strtolower($form_state['values']['book1'])),
+ ucwords(strtolower($form_state['values']['author1'])),
+ $form_state['values']['isbn1'],
+ ucwords(strtolower($form_state['values']['publisher1'])),
+ $form_state['values']['edition1'],
+ $form_state['values']['year1'],
+ 0,
+ 0
+ );*/
+ /** $bk3 = trim($form_state['values']['book3']);
+ $auth3 = trim($form_state['values']['author3']);
+ $pref_id = NULL;
+ $directory_name = _dir_name($bk3, $auth3, $pref_id);
+ $query = "INSERT INTO {textbook_companion_preference}
+ (proposal_id, pref_number, book, author, isbn, publisher, edition, year, category, approval_status, directory_name) VALUES (:proposal_id, :pref_number, :book, :author, :isbn, :publisher, :edition, :year, :category, :approval_status, :directory_name)
+ ";
+ $args = array(
+ ":proposal_id" => $proposal_id,
+ ":pref_number" => 3,
+ ":book" => trim(ucwords(strtolower($form_state['values']['book3']))),
+ ":author" => trim(ucwords(strtolower($form_state['values']['author3']))),
+ ":isbn" => trim($form_state['values']['isbn3']),
+ ":publisher" => trim(ucwords(strtolower($form_state['values']['publisher3']))),
+ ":edition" => trim($form_state['values']['edition3']),
+ ":year" => trim($form_state['values']['year3']),
+ ":category" => 0,
+ ":approval_status" => 0,
+ ":directory_name" => $form_state['values']['dir_name3']
+ );
+ $result = db_query($query, $args, array(
+ 'return' => Database::RETURN_INSERT_ID
+ ));
+ 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_bcc_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('');
}
/**
* Implementation of hook_mail().
*/
function textbook_companion_mail($key, &$message, $params)
{
- global $user;
- // $language = $message['lianguage'];
- $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 = db_select('textbook_companion_preference');
- $query->fields('textbook_companion_preference');
- $query->condition('proposal_id', $params['proposal_received']['proposal_id']);
- $query->condition('pref_number', 1);
- $query->range(0, 1);
- $result = $query->execute();
- $preference1_data = $result->fetchObject();
- $query = db_select('textbook_companion_preference');
- $query->fields('textbook_companion_preference');
- $query->condition('proposal_id', $params['proposal_received']['proposal_id']);
- $query->condition('pref_number', 2);
- $query->range(0, 1);
- $result = $query->execute();
- $preference2_data = $result->fetchObject();
- $query = db_select('textbook_companion_preference');
- $query->fields('textbook_companion_preference');
- $query->condition('proposal_id', $params['proposal_received']['proposal_id']);
- $query->condition('pref_number', 3);
- $query->range(0, 1);
- $result = $query->execute();
- $preference3_data = $result->fetchObject();
- $user_data = user_load($params['proposal_received']['user_id']);
- $message['subject'] = t('[!site_name] Your textbook companion book proposal has been received', array(
- '!site_name' => variable_get('site_name', '')
- ));
- $message['body'] = array(
- 'body' => t('
+ global $user;
+ // $language = $message['lianguage'];
+ /*$tbc_bcc_emails = array(
+ 'Bcc' => variable_get('textbook_companion_bcc_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 = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('proposal_id', $params['proposal_received']['proposal_id']);
+ $query->condition('pref_number', 1);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $preference1_data = $result->fetchObject();
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('proposal_id', $params['proposal_received']['proposal_id']);
+ $query->condition('pref_number', 2);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $preference2_data = $result->fetchObject();
+ $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][Textbook Companion] Your textbook companion book proposal has been received', array(
+ '!site_name' => variable_get('site_name', '')
+ ));
+ $message['body'] = array(
+ 'body' => t('
Dear !user_name,
We have received your proposal for DWSIM Textbook Companion with the following details:
@@ -2665,39 +2268,40 @@ Best Wishes,
!site_name Team,
FOSSEE,IIT Bombay', array(
- '!site_name' => variable_get('site_name', ''),
- '!user_name' => $user_data->name
- ))
- );
- break;
- 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();
- $user_data = user_load($params['proposal_disapproved']['user_id']);
- $message['subject'] = t('[!site_name] Your textbook companion book proposal has been disapproved', array(
- '!site_name' => variable_get('site_name', '')
- ));
- $message['body'] = array(
- 'body' => t('
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name
+ ))
+ );
+ break;
+ 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();
+ $user_data = user_load($params['proposal_disapproved']['user_id']);
+ $message['headers'] = $params['proposal_disapproved']['headers'];
+ $message['subject'] = t('[!site_name][Textbook Companion] Your textbook companion book proposal has been disapproved', array(
+ '!site_name' => variable_get('site_name', '')
+ ));
+ $message['body'] = array(
+ 'body' => t('
Dear !user_name,
We regret to inform you that all the uploaded examples including the book
@@ -2737,38 +2341,39 @@ Best Wishes,
!site_name Team,
FOSSEE,IIT Bombay', array(
- '!site_name' => variable_get('site_name', ''),
- '!user_name' => $user_data->name
- ))
- );
- break;
- case 'proposal_approved':
- // bcc to textbook_companion_emails
- //$message['headers'] += $tbc_bcc_emails;
- /*$proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d LIMIT 1", $params['proposal_approved']['proposal_id']);
- $proposal_data = db_fetch_object($proposal_q);*/
- $query = db_select('textbook_companion_proposal');
- $query->fields('textbook_companion_proposal');
- $query->condition('id', $params['proposal_approved']['proposal_id']);
- $query->range(0, 1);
- $result = $query->execute();
- $proposal_data = $result->fetchObject();
- /* $approved_preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND approval_status = 1 LIMIT 1", $params['proposal_approved']['proposal_id']);
- $approved_preference_data = db_fetch_object($approved_preference_q);*/
- $query = db_select('textbook_companion_preference');
- $query->fields('textbook_companion_preference');
- $query->condition('proposal_id', $params['proposal_approved']['proposal_id']);
- $query->condition('approval_status', 1);
- $query->range(0, 1);
- $result = $query->execute();
- $approved_preference_data = $result->fetchObject();
- $user_data = user_load($params['proposal_approved']['user_id']);
- $message['headers'] = $params['proposal_approved']['headers'];
- $message['subject'] = t('[!site_name] Your book proposal has been approved', array(
- '!site_name' => variable_get('site_name', '')
- ));
- $message['body'] = array(
- 'body' => t('
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name
+ ))
+ );
+ break;
+ case 'proposal_approved':
+ // bcc to textbook_companion_emails
+ //$message['headers'] += $tbc_bcc_emails;
+ /*$proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d LIMIT 1", $params['proposal_approved']['proposal_id']);
+ $proposal_data = db_fetch_object($proposal_q);*/
+ $query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal');
+ $query->condition('id', $params['proposal_approved']['proposal_id']);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $proposal_data = $result->fetchObject();
+ /* $approved_preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND approval_status = 1 LIMIT 1", $params['proposal_approved']['proposal_id']);
+ $approved_preference_data = db_fetch_object($approved_preference_q);*/
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('proposal_id', $params['proposal_approved']['proposal_id']);
+ $query->condition('approval_status', 1);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $approved_preference_data = $result->fetchObject();
+ $user_data = user_load($params['proposal_approved']['user_id']);
+ $message['headers'] = $params['proposal_approved']['headers'];
+ $message['headers'] = $params['proposal_approved']['headers'];
+ $message['subject'] = t('[!site_name][Textbook Companion] Your book proposal has been approved', array(
+ '!site_name' => variable_get('site_name', '')
+ ));
+ $message['body'] = array(
+ 'body' => t('
Dear !user_name,
Congratulations! Your proposal for DWSIM Textbook Companion with the following details is approved.
@@ -2803,37 +2408,38 @@ Best Wishes,
!site_name Team,
FOSSEE,IIT Bombay', array(
- '!site_name' => variable_get('site_name', ''),
- '!user_name' => $user_data->name
- ))
- );
- 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['subject'] = t('[!site_name] Congratulations on the completion of the Textbook Companion.', array(
- '!site_name' => variable_get('site_name', '')
- ));
- $message['body'] = array(
- 'body' => t('
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name
+ ))
+ );
+ 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_approved']['headers'];
+ $message['subject'] = t('[!site_name][Textbook Companion] Congratulations on the completion of the Textbook Companion.', array(
+ '!site_name' => variable_get('site_name', '')
+ ));
+ $message['body'] = array(
+ 'body' => t('
Dear !user_name,
The textbook companion on the following book has been completed successfully by you:
@@ -2866,38 +2472,39 @@ Best Wishes,
!site_name Team,
FOSSEE,IIT Bombay', array(
- '!site_name' => variable_get('site_name', ''),
- '!user_name' => $user_data->name
- ))
- );
- break;
- /***********************************************************************************************/
- case 'all_code_submitted':
- // 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['all_code_submitted']['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['all_code_submitted']['proposal_id']);
- $query->condition('approval_status', 1);
- $query->range(0, 1);
- $result = $query->execute();
- $approved_preference_data = $result->fetchObject();
- $user_data = user_load($params['all_code_submitted']['user_id']);
- $message['subject'] = t('[!site_name][Textbook Companion] You have marked to submited code for all examples.', array(
- '!site_name' => variable_get('site_name', '')
- ));
- $message['body'] = array(
- 'body' => t('
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name
+ ))
+ );
+ break;
+ /***********************************************************************************************/
+ case 'all_code_submitted':
+ // 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['all_code_submitted']['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['all_code_submitted']['proposal_id']);
+ $query->condition('approval_status', 1);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $approved_preference_data = $result->fetchObject();
+ $user_data = user_load($params['all_code_submitted']['user_id']);
+ $message['headers'] = $params['all_code_submitted']['headers'];
+ $message['subject'] = t('[!site_name][Textbook Companion] You have marked to submited code for all examples.', array(
+ '!site_name' => variable_get('site_name', '')
+ ));
+ $message['body'] = array(
+ 'body' => t('
Dear !user_name,
You have submitted codes for all examples:
@@ -2926,37 +2533,38 @@ Best Wishes,
!site_name Team,
FOSSEE,IIT Bombay', array(
- '!site_name' => variable_get('site_name', ''),
- '!user_name' => $user_data->name
- ))
- );
- break;
- case 'all_code_submitted_status_changed':
- // 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['all_code_submitted_status_changed']['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['all_code_submitted_status_changed']['proposal_id']);
- $query->condition('approval_status', 1);
- $query->range(0, 1);
- $result = $query->execute();
- $approved_preference_data = $result->fetchObject();
- $user_data = user_load($params['all_code_submitted_status_changed']['user_id']);
- $message['subject'] = t('[!site_name][Textbook Companion] Your interface for code submission has been enabled by the reviewer', array(
- '!site_name' => variable_get('site_name', '')
- ));
- $message['body'] = array(
- 'body' => t('
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name
+ ))
+ );
+ break;
+ case 'all_code_submitted_status_changed':
+ // 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['all_code_submitted_status_changed']['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['all_code_submitted_status_changed']['proposal_id']);
+ $query->condition('approval_status', 1);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $approved_preference_data = $result->fetchObject();
+ $user_data = user_load($params['all_code_submitted_status_changed']['user_id']);
+ $message['headers'] = $params['all_code_submitted_status_changed']['headers'];
+ $message['subject'] = t('[!site_name][Textbook Companion] Your interface for code submission has been enabled by the reviewer', array(
+ '!site_name' => variable_get('site_name', '')
+ ));
+ $message['body'] = array(
+ 'body' => t('
Dear !user_name,
Your interface for code submission has been enabled by the reviewer, you can now able to send more code for this book.
@@ -2983,41 +2591,42 @@ Best Wishes,
!site_name Team,
FOSSEE,IIT Bombay', array(
- '!site_name' => variable_get('site_name', ''),
- '!user_name' => $user_data->name
- ))
- );
- 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['subject'] = t('[!site_name] You have uploaded example for Textbook Companion', array(
- '!site_name' => variable_get('site_name', '')
- ));
- $message['body'] = array(
- 'body' => t('
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name
+ ))
+ );
+ 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][Textbook Companion] You have uploaded example for Textbook Companion', array(
+ '!site_name' => variable_get('site_name', '')
+ ));
+ $message['body'] = array(
+ 'body' => t('
Dear !user_name,
You have uploaded the following solution :
@@ -3033,40 +2642,41 @@ Best Wishes,
!site_name Team,
FOSSEE,IIT Bombay', array(
- '!site_name' => variable_get('site_name', ''),
- '!user_name' => $user_data->name
- ))
- );
- 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['subject'] = t('[!site_name] You have updated example for Textbook Companion', array(
- '!site_name' => variable_get('site_name', '')
- ));
- $message['body'] = array(
- 'body' => t('
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name
+ ))
+ );
+ 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][Textbook Companion] You have updated example for Textbook Companion', array(
+ '!site_name' => variable_get('site_name', '')
+ ));
+ $message['body'] = array(
+ 'body' => t('
Dear !user_name,
You have updated the following example:
@@ -3082,40 +2692,41 @@ Best Wishes,
!site_name Team,
FOSSEE,IIT Bombay', array(
- '!site_name' => variable_get('site_name', ''),
- '!user_name' => $user_data->name
- ))
- );
- 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();
- $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_admin']['user_id']);
- $message['subject'] = t('[!site_name] Reviewer have updated example for Textbook Companion ', array(
- '!site_name' => variable_get('site_name', '')
- ));
- $message['body'] = array(
- 'body' => t('
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name
+ ))
+ );
+ 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();
+ $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_admin']['user_id']);
+ $message['headers'] = $params['example_updated_admin']['headers'];
+ $message['subject'] = t('[!site_name] Reviewer have updated example for Textbook Companion ', array(
+ '!site_name' => variable_get('site_name', '')
+ ));
+ $message['body'] = array(
+ 'body' => t('
Dear !user_name,
Reviewer have updated the following example:
@@ -3129,40 +2740,41 @@ Best Wishes,
!site_name Team,
FOSSEE,IIT Bombay', array(
- '!site_name' => variable_get('site_name', ''),
- '!user_name' => $user_data->name
- ))
- );
- 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();
- $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_approved']['user_id']);
- $message['subject'] = t('[!site_name] Your uploaded example has been approved for Textbook Companion', array(
- '!site_name' => variable_get('site_name', '')
- ));
- $message['body'] = array(
- 'body' => t('
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name
+ ))
+ );
+ 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();
+ $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_approved']['user_id']);
+ $message['headers'] = $params['example_approved']['headers'];
+ $message['subject'] = t('[!site_name][Textbook Companion] Your uploaded example has been approved for Textbook Companion', array(
+ '!site_name' => variable_get('site_name', '')
+ ));
+ $message['body'] = array(
+ 'body' => t('
Dear !user_name,
Your example for DWSIM Textbook Companion with the following details is approved.
@@ -3176,34 +2788,35 @@ Best Wishes,
!site_name Team,
FOSSEE,IIT Bombay', array(
- '!site_name' => variable_get('site_name', ''),
- '!user_name' => $user_data->name
- ))
- );
- break;
- case 'example_disapproved':
- // bcc to textbook_companion_emails
- //$message['headers'] += $tbc_bcc_emails;
- $user_data = user_load($params['example_disapproved']['user_id']);
- $preference_id = $param['example_disapproved']['preference_id'];
- $chapter_id = $param['example_disapproved']['chapter_id'];
- $query = db_select('textbook_companion_chapter');
- $query->fields('textbook_companion_chapter');
- $query->condition('id', $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', $preference_id);
- $query->range(0, 1);
- $result = $query->execute();
- $preference_data = $result->fetchObject();
- $message['subject'] = t('[!site_name] Your uploaded example has been disapproved for Textbook Companion', array(
- '!site_name' => variable_get('site_name', '')
- ));
- $message['body'] = array(
- 'body' => t('
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name
+ ))
+ );
+ break;
+ case 'example_disapproved':
+ // bcc to textbook_companion_emails
+ //$message['headers'] += $tbc_bcc_emails;
+ $user_data = user_load($params['example_disapproved']['user_id']);
+ $preference_id = $params['example_disapproved']['preference_id'];
+ $chapter_id = $params['example_disapproved']['chapter_id'];
+ $query = db_select('textbook_companion_chapter');
+ $query->fields('textbook_companion_chapter');
+ $query->condition('id', $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', $preference_id);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $preference_data = $result->fetchObject();
+ $message['headers'] = $params['example_disapproved']['headers'];
+ $message['subject'] = t('[!site_name][Textbook Companion] Your uploaded example has been disapproved for Textbook Companion', array(
+ '!site_name' => variable_get('site_name', '')
+ ));
+ $message['body'] = array(
+ 'body' => t('
Dear !user_name,
Your following example has been disapproved:
@@ -3219,20 +2832,21 @@ Best Wishes,
!site_name Team,
FOSSEE,IIT Bombay', array(
- '!site_name' => variable_get('site_name', ''),
- '!user_name' => $user_data->name
- ))
- );
- 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['subject'] = t('[!site_name] User has deleted pending example for Textbook Companion', array(
- '!site_name' => variable_get('site_name', '')
- ));
- $message['body'] = array(
- 'body' => t('
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name
+ ))
+ );
+ 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][Textbook Companion] User has deleted pending example for Textbook Companion', array(
+ '!site_name' => variable_get('site_name', '')
+ ));
+ $message['body'] = array(
+ 'body' => t('
Dear !user_name,
Your following pending example has been deleted :
@@ -3246,21 +2860,22 @@ Best Wishes,
!site_name Team,
FOSSEE,IIT Bombay', array(
- '!site_name' => variable_get('site_name', ''),
- '!user_name' => $user_data->name
- ))
- );
- break;
- case 'dependency_uploaded':
- // bcc to textbook_companion_emails
- //$message['headers'] += $tbc_bcc_emails;
- $user_data = user_load($params['dependency_uploaded']['user_id']);
- $dependency_files = implode(',', $params['dependency_uploaded']['dependency_names']);
- $message['subject'] = t('[!site_name] You have uploaded dependency file', array(
- '!site_name' => variable_get('site_name', '')
- ));
- $message['body'] = array(
- 'body' => t('
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name
+ ))
+ );
+ break;
+ case 'dependency_uploaded':
+ // bcc to textbook_companion_emails
+ //$message['headers'] += $tbc_bcc_emails;
+ $user_data = user_load($params['dependency_uploaded']['user_id']);
+ $dependency_files = implode(',', $params['dependency_uploaded']['dependency_names']);
+ $message['headers'] = $params['dependency_uploaded']['headers'];
+ $message['subject'] = t('[!site_name][Textbook Companion] You have uploaded dependency file', array(
+ '!site_name' => variable_get('site_name', '')
+ ));
+ $message['body'] = array(
+ 'body' => t('
Dear !user_name,
You have uploaded following dependency files :
@@ -3270,20 +2885,20 @@ Best Wishes,
!site_name Team,
FOSSEE,IIT Bombay', array(
- '!site_name' => variable_get('site_name', ''),
- '!user_name' => $user_data->name
- ))
- );
- break;
- case 'feedback_received':
- // bcc to textbook_companion_emails
- //$message['headers'] += $tbc_bcc_emails;
- $user_data = user_load($params['feedback_received']['user_id']);
- $message['subject'] = t('[!site_name] We have received your feedback', array(
- '!site_name' => variable_get('site_name', '')
- ));
- $message['body'] = array(
- 'body' => t('
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name
+ ))
+ );
+ break;
+ case 'feedback_received':
+ // bcc to textbook_companion_emails
+ //$message['headers'] += $tbc_bcc_emails;
+ $user_data = user_load($params['feedback_received']['user_id']);
+ $message['subject'] = t('[!site_name][Textbook Companion] We have received your feedback', array(
+ '!site_name' => variable_get('site_name', '')
+ ));
+ $message['body'] = array(
+ 'body' => t('
Dear !user_name,
We have received your following feedback
@@ -3299,20 +2914,20 @@ Best Wishes,
!site_name Team,
FOSSEE,IIT Bombay', array(
- '!site_name' => variable_get('site_name', ''),
- '!user_name' => $user_data->name
- ))
- );
- break;
- case 'internshipform':
- // bcc to textbook_companion_emails
- //$message['headers'] += $tbc_bcc_emails;
- $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', '')
- ));
- $message['body'] = array(
- 'body' => t('
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name
+ ))
+ );
+ break;
+ case 'internshipform':
+ // bcc to textbook_companion_emails
+ //$message['headers'] += $tbc_bcc_emails;
+ $user_data = user_load($params['internshipform']['user_id']);
+ $message['subject'] = t('[!site_name][Textbook Companion] We have received your feedback', array(
+ '!site_name' => variable_get('site_name', '')
+ ));
+ $message['body'] = array(
+ 'body' => t('
Dear !user_name,
We have received your Internship Form Application for the book
@@ -3325,20 +2940,20 @@ Best Wishes,
!site_name Team,
FOSSEE,IIT Bombay', array(
- '!site_name' => variable_get('site_name', ''),
- '!user_name' => $user_data->name
- ))
- );
- break;
- case 'copyrighttransferform':
- // bcc to textbook_companion_emails
- //$message['headers'] += $tbc_bcc_emails;
- $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', '')
- ));
- $message['body'] = array(
- 'body' => t('
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name
+ ))
+ );
+ break;
+ case 'copyrighttransferform':
+ // bcc to textbook_companion_emails
+ //$message['headers'] += $tbc_bcc_emails;
+ $user_data = user_load($params['copyrighttransferform']['user_id']);
+ $message['subject'] = t('[!site_name][Textbook Companion] We have received your feedback', array(
+ '!site_name' => variable_get('site_name', '')
+ ));
+ $message['body'] = array(
+ 'body' => t('
Dear !user_name,
We have received your Copyright Form Application for the book
@@ -3351,20 +2966,20 @@ Best Wishes,
!site_name Team,
FOSSEE,IIT Bombay', array(
- '!site_name' => variable_get('site_name', ''),
- '!user_name' => $user_data->name
- ))
- );
- break;
- case 'undertakingform':
- // bcc to textbook_companion_emails
- //$message['headers'] += $tbc_bcc_emails;
- $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', '')
- ));
- $message['body'] = array(
- 'body' => t('
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name
+ ))
+ );
+ break;
+ case 'undertakingform':
+ // bcc to textbook_companion_emails
+ //$message['headers'] += $tbc_bcc_emails;
+ $user_data = user_load($params['undertakingform']['user_id']);
+ $message['subject'] = t('[!site_name][Textbook Companion] We have received your feedback', array(
+ '!site_name' => variable_get('site_name', '')
+ ));
+ $message['body'] = array(
+ 'body' => t('
Dear !user_name,
We have received your Undertaking Form Application for the book
@@ -3377,20 +2992,20 @@ Best Wishes,
!site_name Team,
FOSSEE,IIT Bombay', array(
- '!site_name' => variable_get('site_name', ''),
- '!user_name' => $user_data->name
- ))
- );
- break;
- case 'remark':
- // bcc to textbook_companion_emails
- //$message['headers'] += $tbc_bcc_emails;
- $user_data = user_load($params['remark']['user_id']);
- $message['subject'] = t('[!site_name] A remark has been given.Please check your contact detail form', array(
- '!site_name' => variable_get('site_name', '')
- ));
- $message['body'] = array(
- 'body' => t('
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name
+ ))
+ );
+ break;
+ case 'remark':
+ // bcc to textbook_companion_emails
+ //$message['headers'] += $tbc_bcc_emails;
+ $user_data = user_load($params['remark']['user_id']);
+ $message['subject'] = t('[!site_name][Textbook Companion] A remark has been given.Please check your contact detail form', array(
+ '!site_name' => variable_get('site_name', '')
+ ));
+ $message['body'] = array(
+ 'body' => t('
Dear !user_name,
A Remark has been given.Please check your Contact Detail Form
@@ -3403,20 +3018,20 @@ Best Wishes,
!site_name Team,
FOSSEE,IIT Bombay', array(
- '!site_name' => variable_get('site_name', ''),
- '!user_name' => $user_data->name
- ))
- );
- break;
- case 'cheque_sent':
- // bcc to textbook_companion_emails
- //$message['headers'] += $tbc_bcc_emails;
- $user_data = user_load($params['cheque_sent']['user_id']);
- $message['subject'] = t('[!site_name] We have received your feedback', array(
- '!site_name' => variable_get('site_name', '')
- ));
- $message['body'] = array(
- 'body' => t('
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name
+ ))
+ );
+ break;
+ case 'cheque_sent':
+ // bcc to textbook_companion_emails
+ //$message['headers'] += $tbc_bcc_emails;
+ $user_data = user_load($params['cheque_sent']['user_id']);
+ $message['subject'] = t('[!site_name][Textbook Companion] We have received your feedback', array(
+ '!site_name' => variable_get('site_name', '')
+ ));
+ $message['body'] = array(
+ 'body' => t('
Dear !user_name,
We have Sent Cheque for the following book proposed
@@ -3429,378 +3044,415 @@ Best Wishes,
!site_name Team,
FOSSEE,IIT Bombay', array(
- '!site_name' => variable_get('site_name', ''),
- '!user_name' => $user_data->name
- ))
- );
- break;
- case 'standard':
- // bcc to textbook_companion_emails
- //$message['headers'] += $tbc_bcc_emails;
- $message['subject'] = $params['standard']['subject'];
- $message['body'] = $params['standard']['body'];
- break;
- }
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name
+ ))
+ );
+ 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
}
/* 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;
- }
- } 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 '';
+ $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 '';
}
/*************************** 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;
+ 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;
+ 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;
+ 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() . 'dwsim_uploads/tbc_uploads/';
+ return $_SERVER['DOCUMENT_ROOT'] . base_path() . 'dwsim_uploads/tbc_uploads/';
}
function textbook_companion_temp_path()
{
- return $_SERVER['DOCUMENT_ROOT'] . base_path() . 'dwsim_uploads/';
+ return $_SERVER['DOCUMENT_ROOT'] . base_path() . 'dwsim_uploads/';
}
function textbook_companion_samplecode_path()
{
- return $_SERVER['DOCUMENT_ROOT'] . base_path() . 'dwsim_uploads/tbc_sample_code/';
+ return $_SERVER['DOCUMENT_ROOT'] . base_path() . 'dwsim_uploads/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);*/
- $query = db_select('textbook_companion_example');
- $query->fields('textbook_companion_example');
- $query->condition('id', $example_id);
- $example_q = $query->execute();
- $example_data = $example_q->fetchObject();
- if (!$example_data) {
- drupal_set_message(t('Invalid example.'), 'error');
- return FALSE;
- }
- /*$chapter_q = db_query("SELECT * FROM {textbook_companion_chapter} WHERE id = %d", $example_data->chapter_id);
- $chapter_data = db_fetch_object($chapter_q);*/
- $chapter_q = db_query("SELECT tcp.id as pref_id, tcp.directory_name, tcc.*
+ 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;
+ } //!$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);*/
+ $chapter_q = db_query("SELECT tcp.id as pref_id, tcp.directory_name, tcc.*
FROM textbook_companion_preference tcp
JOIN textbook_companion_chapter tcc
ON tcp.id= tcc.preference_id
WHERE tcc.id = :chapter_id", array(
- ":chapter_id" => $example_data->chapter_id
- ));
- /*$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);*/
- $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 . $chapter_data->directory_name . '/' . $examples_files_data->filepath)) {
- $status = FALSE;
- var_dump($root_path . $chapter_data->directory_name . '/' . $examples_files_data->filepath);
- die;
- drupal_set_message(t('Error deleting !file. File does not exists.', array(
- '!file' => $examples_files_data->filepath
- )), 'error');
- continue;
- }
- /* removing example file */
- if (!unlink($root_path . $chapter_data->directory_name . '/' . $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', '');
- $param['standard']['subject'] = "[ERROR] Error deleting example file";
- $param['standard']['body'] = "Error deleting example files by " . $user->uid . " at " . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . " :
+ ":chapter_id" => $example_data->chapter_id
+ ));
+ /*$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;
+ } //!$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 . $chapter_data->directory_name . '/' . $examples_files_data->filepath))
+ {
+ $status = FALSE;
+ //var_dump($root_path . $chapter_data->directory_name . '/' . $examples_files_data->filepath);
+ die;
+ drupal_set_message(t('Error deleting !file. File does not exists.', array(
+ '!file' => $examples_files_data->filepath
+ )), 'error');
+ continue;
+ } //!file_exists($root_path . $chapter_data->directory_name . '/' . $examples_files_data->filepath)
+ /* removing example file */
+ if (!unlink($root_path . $chapter_data->directory_name . '/' . $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_bcc_emails', '');
+ $params['standard']['subject'] = "[ERROR] Error deleting example file";
+ $params['standard']['body'] = "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(), $param, variable_get('textbook_companion_from_email', NULL), TRUE))
- drupal_set_message('Error sending email message.', 'error');
- } else {
- /* deleting example files database entries */
- /*db_query("DELETE FROM {textbook_companion_example_files} WHERE id = %d", $examples_files_data->id);*/
- $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->directory_name . '/' . 'CH' . $chapter_data->number . '/' . 'EX' . $example_data->number;
- $dir_path = $root_path . $ex_path;
- if (is_dir($dir_path)) {
- if (!rmdir($dir_path)) {
- drupal_set_message(t('Error deleting folder !folder', array(
- '!folder' => $dir_path
- )), 'error');
- /* sending email to admins */
- $email_to = variable_get('textbook_companion_emails', '');
- $param['standard']['subject'] = "[ERROR] Error deleting folder";
- $param['standard']['body'] = "Error deleting folder " . $dir_path . " by " . $user->uid . " at " . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
- if (!drupal_mail('textbook_companion', 'standard', $email_to, language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE))
- drupal_set_message('Error sending email message.', 'error');
- return FALSE;
- }
- } else {
- drupal_set_message(t('Cannot delete example folder. !folder does not exists.', array(
- '!folder' => $dir_path
- )), 'error');
- return FALSE;
- }
- /* deleting example dependency and exmaple database entries */
- /*db_query("DELETE FROM {textbook_companion_example_dependency} WHERE example_id = %d", $example_id);*/
- //$query = db_delete('textbook_companion_example_dependency');
- //$query->condition('example_id', $example_id);
- //$num_deleted = $query->execute();
- /*db_query("DELETE FROM {textbook_companion_example} WHERE id = %d", $example_id);*/
- $query = db_delete('textbook_companion_example');
- $query->condition('id', $example_id);
- $num_deleted = $query->execute();
- return $status;
+ 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');
+ } //!unlink($root_path . $chapter_data->directory_name . '/' . $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->directory_name . '/' . 'CH' . $chapter_data->number . '/' . 'EX' . $example_data->number;
+ $dir_path = $root_path . $ex_path;
+ if (is_dir($dir_path))
+ {
+ if (!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_bcc_emails', '');
+ $params['standard']['subject'] = "[ERROR] Error deleting folder";
+ $params['standard']['body'] = "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;
+ } //!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);*/
+ $query = db_delete('textbook_companion_example');
+ $query->condition('id', $example_id);
+ $num_deleted = $query->execute();
+ return $status;
}
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);*/
- /*$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();*/
- $chapter_q = db_query("SELECT tcp.id as pref_id, tcp.directory_name, tcc.*
+ $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();*/
+ $chapter_q = db_query("SELECT tcp.id as pref_id, tcp.directory_name, tcc.*
FROM textbook_companion_preference tcp
JOIN textbook_companion_chapter tcc
ON tcp.id= tcc.preference_id
WHERE tcc.id = :chapter_id", array(
- ":chapter_id" => $chapter_id
- ));
- $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);*/
- $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->directory_name . '/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', '');
- $param['standard']['subject'] = "[ERROR] Error deleting folder";
- $param['standard']['body'] = "Error deleting folder " . $dir_path;
- if (!drupal_mail('textbook_companion', 'standard', $email_to, language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE))
- drupal_set_message('Error sending email message.', 'error');
- return FALSE;
- } else {
- /* 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;
+ ":chapter_id" => $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;
+ } //$example_data = $example_q->fetchObject()
+ if ($status)
+ {
+ $dir_path = $root_path . $chapter_data->directory_name . '/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_bcc_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);*/
- $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);*/
- $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;
+ $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;
+ } //!$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;
+ } //!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);*/
- $file_q = db_query("SELECT * FROM textbook_companion_preference tcp JOIN textbook_companion_chapter tcc ON tcp.id = tcc.preference_id JOIN textbook_companion_example tce ON tcc.id=tce.chapter_id JOIN textbook_companion_example_files tcef on tce.id = tcef.example_id WHERE tcef.id = :example_id", array(
- ':example_id' => $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->directory_name . '/' . $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->directory_name . '/' . $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', '');
- $param['standard']['subject'] = "[ERROR] Error deleting file";
- $param['standard']['body'] = "Error deleting file by " . $user->uid . " at " . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . " :
+ $root_path = textbook_companion_path();
+ /*$file_q = db_query("SELECT * FROM {textbook_companion_example_files} WHERE id = %d LIMIT 1", $file_id);*/
+ $file_q = db_query("SELECT * FROM textbook_companion_preference tcp JOIN textbook_companion_chapter tcc ON tcp.id = tcc.preference_id JOIN textbook_companion_example tce ON tcc.id=tce.chapter_id JOIN textbook_companion_example_files tcef on tce.id = tcef.example_id WHERE tcef.id = :example_id", array(
+ ':example_id' => $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;
+ } //!$file_data
+ if (!file_exists($root_path . $file_data->directory_name . '/' . $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->directory_name . '/' . $file_data->filepath)
+ /* removing example file */
+ if (!unlink($root_path . $file_data->directory_name . '/' . $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_bcc_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->directory_name . '/' . $file_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');
- 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;
- }
+ 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->directory_name . '/' . $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;
+ }
}
//Non aicte book proposal form
function book_proposal_nonaicte_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">
+ 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 DWSIM</li>
@@ -3810,516 +3462,529 @@ function book_proposal_nonaicte_form($form_state)
<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(
- 'DWSIM Website' => 'DWSIM 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['department'] = array(
- '#type' => 'select',
- '#title' => t('Department/Branch'),
- '#options' => _list_of_departments(),
- '#required' => TRUE
- );
- $form['university'] = array(
- '#type' => 'textfield',
- '#title' => t('University/ Institute'),
- '#size' => 80,
- '#maxlength' => 200,
- '#required' => TRUE,
- '#attributes' => array(
- 'placeholder' => 'Insert full name of your institute/ university.... '
- )
- );
- $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' => _list_of_states(),
- '#validated' => TRUE,
- '#states' => array(
- 'visible' => array(
- ':input[name="country"]' => array(
- 'value' => 'India'
- )
- )
- )
- );
- $form['city'] = array(
- '#type' => 'select',
- '#title' => t('City'),
- '#options' => _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['hr'] = array(
- '#type' => 'item',
- '#markup' => '<hr>'
- );
- $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'),
- '#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' => 'hidden',
- '#default_value' => 'Not available'
- );
- $form['version'] = array(
- '#type' => 'select',
- '#title' => t('Version'),
- '#options' => _list_of_software_version(),
- '#required' => TRUE
- );
- $form['older'] = array(
- '#type' => 'textfield',
- '#size' => 30,
- '#maxlength' => 50,
- //'#required' => TRUE,
- '#description' => t('Specify the Older version used')
- );
- $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
- //'#required' => FALSE,
- );
- $form['proposal_type'] = array(
- '#type' => 'hidden',
- '#value' => '1',
- '#required' => FALSE
- );
- $form['reference'] = array(
- '#type' => 'textarea',
- '#title' => t('Reference'),
- '#required' => TRUE,
- '#size' => 500,
- '#maxlength' => 500,
- '#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,
- '#value' => $row1->book,
- '#disabled' => ($row1->book ? TRUE : FALSE)
- );
- $form['preference1']['author1'] = array(
- '#type' => 'textfield',
- '#title' => t('Author Name'),
- '#size' => 30,
- '#maxlength' => 100,
- '#required' => TRUE,
- '#value' => $row1->author,
- '#disabled' => ($row1->author ? TRUE : FALSE)
- );
- $form['preference1']['isbn1'] = array(
- '#type' => 'textfield',
- '#title' => t('ISBN No'),
- '#size' => 30,
- '#maxlength' => 25,
- '#required' => TRUE,
- '#value' => $row1->isbn,
- '#disabled' => ($row1->isbn ? TRUE : FALSE)
- );
- $form['preference1']['publisher1'] = array(
- '#type' => 'textfield',
- '#title' => t('Publisher & Place'),
- '#size' => 30,
- '#maxlength' => 50,
- '#required' => TRUE,
- '#value' => $row1->publisher
- );
- $form['preference1']['edition1'] = array(
- '#type' => 'textfield',
- '#title' => t('Edition'),
- '#size' => 4,
- '#maxlength' => 2,
- '#required' => TRUE,
- '#value' => $row1->edition
- );
- $form['preference1']['year1'] = array(
- '#type' => 'textfield',
- '#title' => t('Year of publication'),
- '#size' => 4,
- '#maxlength' => 4,
- '#required' => TRUE,
- '#value' => $row1->year
- );
- /*$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')
- );
- /* #value fix for #default_value bug drupal6
- foreach(array("preference1") as $preference) {
- foreach($form[$preference] as $key => $value) {
- if(!$form[$preference][$key]["#value"]) {
- unset($form[$preference][$key]["#value"]);
- }
- }
- }*/
- return $form;
+ );
+ $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(
+ 'DWSIM Website' => 'DWSIM 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['department'] = array(
+ '#type' => 'select',
+ '#title' => t('Department/Branch'),
+ '#options' => _list_of_departments(),
+ '#required' => TRUE
+ );
+ $form['university'] = array(
+ '#type' => 'textfield',
+ '#title' => t('University/ Institute'),
+ '#size' => 80,
+ '#maxlength' => 200,
+ '#required' => TRUE,
+ '#attributes' => array(
+ 'placeholder' => 'Insert full name of your institute/ university.... '
+ )
+ );
+ $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' => _list_of_states(),
+ '#validated' => TRUE,
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="country"]' => array(
+ 'value' => 'India'
+ )
+ )
+ )
+ );
+ $form['city'] = array(
+ '#type' => 'select',
+ '#title' => t('City'),
+ '#options' => _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['hr'] = array(
+ '#type' => 'item',
+ '#markup' => '<hr>'
+ );
+ $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'),
+ '#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' => 'hidden',
+ '#default_value' => 'Not available'
+ );
+ $form['version'] = array(
+ '#type' => 'select',
+ '#title' => t('Version'),
+ '#options' => _list_of_software_version(),
+ '#required' => TRUE
+ );
+ $form['older'] = array(
+ '#type' => 'textfield',
+ '#size' => 30,
+ '#maxlength' => 50,
+ //'#required' => TRUE,
+ '#description' => t('Specify the Older version used')
+ );
+ $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
+ //'#required' => FALSE,
+ );
+ $form['proposal_type'] = array(
+ '#type' => 'hidden',
+ '#value' => '1',
+ '#required' => FALSE
+ );
+ $form['reference'] = array(
+ '#type' => 'textarea',
+ '#title' => t('Reference'),
+ '#required' => TRUE,
+ '#size' => 500,
+ '#maxlength' => 500,
+ '#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,
+ '#value' => $row1->book,
+ '#disabled' => ($row1->book ? TRUE : FALSE)
+ );
+ $form['preference1']['author1'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Author Name'),
+ '#size' => 30,
+ '#maxlength' => 100,
+ '#required' => TRUE,
+ '#value' => $row1->author,
+ '#disabled' => ($row1->author ? TRUE : FALSE)
+ );
+ $form['preference1']['isbn1'] = array(
+ '#type' => 'textfield',
+ '#title' => t('ISBN No'),
+ '#size' => 30,
+ '#maxlength' => 25,
+ '#required' => TRUE,
+ '#value' => $row1->isbn,
+ '#disabled' => ($row1->isbn ? TRUE : FALSE)
+ );
+ $form['preference1']['publisher1'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Publisher & Place'),
+ '#size' => 30,
+ '#maxlength' => 50,
+ '#required' => TRUE,
+ '#value' => $row1->publisher
+ );
+ $form['preference1']['edition1'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Edition'),
+ '#size' => 4,
+ '#maxlength' => 2,
+ '#required' => TRUE,
+ '#value' => $row1->edition
+ );
+ $form['preference1']['year1'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Year of publication'),
+ '#size' => 4,
+ '#maxlength' => 4,
+ '#required' => TRUE,
+ '#value' => $row1->year
+ );
+ /*$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')
+ );
+ /* #value fix for #default_value bug drupal6
+ foreach(array("preference1") as $preference) {
+ foreach($form[$preference] as $key => $value) {
+ if(!$form[$preference][$key]["#value"]) {
+ unset($form[$preference][$key]["#value"]);
+ }
+ }
+ }*/
+ return $form;
}
function book_proposal_nonaicte_form_submit($form, &$form_state)
{
- global $user;
- $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'];
- }
- $form_state['values']['other_reason'] = $my_reason;
- }
- /************************************/
- $dwsim_version = $form_state['values']['version'];
- if ($form_state['values']['version'] == 'olderversion') {
- $dwsim_version = $form_state['values']['older'];
- }
- $form_state['values']['version'] = $dwsim_version;
- //var_dump($form_state['values']);
- /*$query = "INSERT INTO {textbook_companion_proposal}
- (uid, approver_uid, full_name, mobile, gender, how_project, course, branch, university, faculty, reviewer, reference, completion_date, creation_date, approval_date, proposal_status, scilab_version, operating_system, teacher_email, proposal_type, reason ) VALUES (".$user->uid.", 0, '".ucwords(strtolower($form_state['values']['full_name']))."', '".$form_state['values']['mobile']."', '".$form_state['values']['gender']."', '".$form_state['values']['how_project']."', '".$form_state['values']['course']."', '".$form_state['values']['branch']."', '".$form_state['values']['university']."', '".ucwords(strtolower($form_state['values']['faculty']))."', '".ucwords(strtolower($form_state['values']['reviewer']))."', '".strtolower($form_state['values']['reference'])."', '".$completion_date_timestamp."', '".time()."', 0, 0, '".$scilab_version."', '".$form_state['values']['operating_system']."', '".$form_state['values']['faculty_email']."','".$form_state['values']['proposal_type']."','".$my_reason."')";*/
- $query = "INSERT INTO {textbook_companion_proposal}
+ global $user;
+ $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'];
+ }
+ $form_state['values']['other_reason'] = $my_reason;
+ } //isset($_POST['reason'])
+ /************************************/
+ $dwsim_version = $form_state['values']['version'];
+ if ($form_state['values']['version'] == 'olderversion')
+ {
+ $dwsim_version = $form_state['values']['older'];
+ } //$form_state['values']['version'] == 'olderversion'
+ $form_state['values']['version'] = $dwsim_version;
+ //var_dump($form_state['values']);
+ /*$query = "INSERT INTO {textbook_companion_proposal}
+ (uid, approver_uid, full_name, mobile, gender, how_project, course, branch, university, faculty, reviewer, reference, completion_date, creation_date, approval_date, proposal_status, scilab_version, operating_system, teacher_email, proposal_type, reason ) VALUES (".$user->uid.", 0, '".ucwords(strtolower($form_state['values']['full_name']))."', '".$form_state['values']['mobile']."', '".$form_state['values']['gender']."', '".$form_state['values']['how_project']."', '".$form_state['values']['course']."', '".$form_state['values']['branch']."', '".$form_state['values']['university']."', '".ucwords(strtolower($form_state['values']['faculty']))."', '".ucwords(strtolower($form_state['values']['reviewer']))."', '".strtolower($form_state['values']['reference'])."', '".$completion_date_timestamp."', '".time()."', 0, 0, '".$scilab_version."', '".$form_state['values']['operating_system']."', '".$form_state['values']['faculty_email']."','".$form_state['values']['proposal_type']."','".$my_reason."')";*/
+ $query = "INSERT INTO {textbook_companion_proposal}
(uid, approver_uid, full_name, mobile, gender, how_project, course, branch, university,city,pincode,state,faculty, reviewer, reference, completion_date, creation_date,approval_date, proposal_status, version, operating_system, teacher_email, proposal_type, reason ) VALUES (:uid, :approver_uid, :full_name, :mobile, :gender, :how_project, :course, :branch, :university,:city,:pincode,:state, :faculty, :reviewer, :reference,
:expected_completion_date, :actual_completion_date,:creation_date,:message, :approval_date, :proposal_status, :dwsim_version, :operating_system, :teacher_email,
:proposal_type, :reason)";
- $args = array(
- "uid" => $user->uid,
- "approver_uid" => 0,
- "full_name" => ucwords(strtolower($form_state['values']['full_name'])),
- "mobile" => $form_state['values']['mobile'],
- "gender" => $form_state['values']['gender'],
- "how_project" => $form_state['values']['how_project'],
- "course" => $form_state['values']['course'],
- "branch" => $form_state['values']['branch'],
- "university" => $form_state['values']['university'],
- ":city" => $form_state['values']['city'],
- ":pincode" => $form_state['values']['pincode'],
- ":state" => $form_state['values']['all_state'],
- "faculty" => ucwords(strtolower($form_state['values']['faculty'])),
- "reviewer" => ucwords(strtolower($form_state['values']['reviewer'])),
- "reference" => strtolower($form_state['values']['reference']),
- "completion_date" => $completion_date_timestamp,
- "creation_date" => time(),
- "approval_date" => time(),
- "proposal_status" => 0,
- "dwsim_version" => $dwsim_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
- );
- $result = db_query($query, $args, array(
- 'return' => Database::RETURN_INSERT_ID
- ));
- 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');
- /* inserting first book preference */
- if ($form_state['values']['book1']) {
- /*$result = db_query("INSERT INTO {textbook_companion_preference}
- (proposal_id, pref_number, book, author, isbn, publisher, edition, year, category, approval_status, nonaicte_book) VALUES
- (%d, %d, '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d)",
- $proposal_id,
- 1,
- ucwords(strtolower($form_state['values']['book1'])),
- ucwords(strtolower($form_state['values']['author1'])),
- $form_state['values']['isbn1'],
- ucwords(strtolower($form_state['values']['publisher1'])),
- $form_state['values']['edition1'],
- $form_state['values']['year1'],
- 0,
- 0,
- 1
- );*/
- $query = "INSERT INTO {textbook_companion_preference}
+ $args = array(
+ "uid" => $user->uid,
+ "approver_uid" => 0,
+ "full_name" => ucwords(strtolower($form_state['values']['full_name'])),
+ "mobile" => $form_state['values']['mobile'],
+ "gender" => $form_state['values']['gender'],
+ "how_project" => $form_state['values']['how_project'],
+ "course" => $form_state['values']['course'],
+ "branch" => $form_state['values']['branch'],
+ "university" => $form_state['values']['university'],
+ ":city" => $form_state['values']['city'],
+ ":pincode" => $form_state['values']['pincode'],
+ ":state" => $form_state['values']['all_state'],
+ "faculty" => ucwords(strtolower($form_state['values']['faculty'])),
+ "reviewer" => ucwords(strtolower($form_state['values']['reviewer'])),
+ "reference" => strtolower($form_state['values']['reference']),
+ "completion_date" => $completion_date_timestamp,
+ "creation_date" => time(),
+ "approval_date" => time(),
+ "proposal_status" => 0,
+ "dwsim_version" => $dwsim_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
+ );
+ $result = db_query($query, $args, array(
+ 'return' => Database::RETURN_INSERT_ID
+ ));
+ 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');
+ /* inserting first book preference */
+ if ($form_state['values']['book1'])
+ {
+ /*$result = db_query("INSERT INTO {textbook_companion_preference}
+ (proposal_id, pref_number, book, author, isbn, publisher, edition, year, category, approval_status, nonaicte_book) VALUES
+ (%d, %d, '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, %d)",
+ $proposal_id,
+ 1,
+ ucwords(strtolower($form_state['values']['book1'])),
+ ucwords(strtolower($form_state['values']['author1'])),
+ $form_state['values']['isbn1'],
+ ucwords(strtolower($form_state['values']['publisher1'])),
+ $form_state['values']['edition1'],
+ $form_state['values']['year1'],
+ 0,
+ 0,
+ 1
+ );*/
+ $query = "INSERT INTO {textbook_companion_preference}
(proposal_id, pref_number, book, author, isbn, publisher, edition, year, category, approval_status, nonaicte_book) VALUES
(:proposal_id, :pref_number, :book, :author, :isbn, :publisher, :edition, :year, :category, :approval_status, :nonaicte_book)";
- $args = array(
- ":proposal_id" => $proposal_id,
- ":pref_number" => 1,
- ":book" => ucwords(strtolower($form_state['values']['book1'])),
- ":author" => ucwords(strtolower($form_state['values']['author1'])),
- ":isbn" => $form_state['values']['isbn1'],
- ":publisher" => ucwords(strtolower($form_state['values']['publisher1'])),
- ":edition" => $form_state['values']['edition1'],
- ":year" => $form_state['values']['year1'],
- ":category" => 0,
- ":approval_status" => 0,
- ":nonaicte_book" => 1
- );
- $result = db_query($query, $args, array(
- 'return' => Database::RETURN_INSERT_ID
- ));
- if (!$result) {
- drupal_set_message(t('Error receiving your first book preference.'), 'error');
- }
- }
- /* sending email */
- $email_to = $user->mail;
- $param['proposal_received']['proposal_id'] = $proposal_id;
- $param['proposal_received']['user_id'] = $user->uid;
- if (!drupal_mail('textbook_companion', 'nonaicte_proposal_received', $email_to, language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE))
- drupal_set_message('Error sending email message.', 'error');
- if (!drupal_mail('textbook_companion', 'nonaicte_proposal_to_pi', $tbc_to_emails, language_default(), $param, variable_get('textbook_companion_from_email', NULL), 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('');
+ $args = array(
+ ":proposal_id" => $proposal_id,
+ ":pref_number" => 1,
+ ":book" => ucwords(strtolower($form_state['values']['book1'])),
+ ":author" => ucwords(strtolower($form_state['values']['author1'])),
+ ":isbn" => $form_state['values']['isbn1'],
+ ":publisher" => ucwords(strtolower($form_state['values']['publisher1'])),
+ ":edition" => $form_state['values']['edition1'],
+ ":year" => $form_state['values']['year1'],
+ ":category" => 0,
+ ":approval_status" => 0,
+ ":nonaicte_book" => 1
+ );
+ $result = db_query($query, $args, array(
+ 'return' => Database::RETURN_INSERT_ID
+ ));
+ if (!$result)
+ {
+ drupal_set_message(t('Error receiving your first book preference.'), 'error');
+ } //!$result
+ } //$form_state['values']['book1']
+ /* sending email */
+ $email_to = $user->mail;
+ $params['proposal_received']['proposal_id'] = $proposal_id;
+ $params['proposal_received']['user_id'] = $user->uid;
+ if (!drupal_mail('textbook_companion', 'nonaicte_proposal_received', $email_to, language_default(), $params, variable_get('textbook_companion_from_email', NULL), TRUE))
+ drupal_set_message('Error sending email message.', 'error');
+ if (!drupal_mail('textbook_companion', 'nonaicte_proposal_to_pi', $tbc_to_emails, language_default(), $params, variable_get('textbook_companion_from_email', NULL), 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('');
}
//
function del_book_pdf($book_id)
{
- $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);
+ $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 _list_of_software_version()
{
- $software_version = array();
- $query = db_select('dwsim_software_version');
- $query->fields('dwsim_software_version');
- $query->orderBy('dwsim_version', 'ASC');
- $software_version_list = $query->execute();
- while ($software_version_list_data = $software_version_list->fetchObject()) {
- $software_version[$software_version_list_data->dwsim_version] = $software_version_list_data->dwsim_version;
- }
- return $software_version;
+ $software_version = array();
+ $query = db_select('dwsim_software_version');
+ $query->fields('dwsim_software_version');
+ $query->orderBy('dwsim_version', 'ASC');
+ $software_version_list = $query->execute();
+ while ($software_version_list_data = $software_version_list->fetchObject())
+ {
+ $software_version[$software_version_list_data->dwsim_version] = $software_version_list_data->dwsim_version;
+ } //$software_version_list_data = $software_version_list->fetchObject()
+ return $software_version;
}
function _list_of_departments()
{
- $department = array();
- $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;
+ $department = array();
+ $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;
}
function _list_of_states()
{
- $states = array(
- '' => '-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;
+ $states = array(
+ '' => '-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 _list_of_cities()
{
- $city = array(
- '' => '-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;
+ $city = array(
+ '' => '-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;
+ } //$city_list_data = $city_list->fetchObject()
+ return $city;
}
/*************************************************************************/
/***** Function To convert only first charater of string in uppercase ****/
@@ -4336,35 +4001,40 @@ return $string;
}*/
function _dir_name($book, $author, $pref_id)
{
- if (!$pref_id) {
- $book_title = ucname($book);
- $author = ucname($author);
- $dir_name = $book_title . " " . "by" . " " . $author;
- $directory_name = str_replace("__", "_", str_replace(" ", "_", $dir_name));
- $query = db_select('textbook_companion_preference');
- $query->fields('textbook_companion_preference');
- $query->condition('directory_name', $directory_name);
- $query->condition('approval_status', 1);
- $result = $query->execute()->rowCount();
- if ($result > 0) {
- //var_dump('this');die;
- form_set_error('', t('Book is already allotted. Please try another book or contact to administrator'));
- return;
- }
- } else {
- $book_title = ucname($book);
- $author = ucname($author);
- $dir_name = $book_title . " " . "by" . " " . $author;
- $directory_name = str_replace("__", "_", str_replace(" ", "_", $dir_name));
- $query = db_select('textbook_companion_preference');
- $query->fields('textbook_companion_preference');
- $query->condition('directory_name', $directory_name);
- $query->condition('id', $pref_id);
- $result = $query->execute()->rowCount();
- if ($result > 1) {
- form_set_error('', t('Book is already present. Please try another book or contact to administrator'));
- return;
- }
- }
- return $directory_name;
+ if (!$pref_id)
+ {
+ $book_title = ucname($book);
+ $author = ucname($author);
+ $dir_name = $book_title . " " . "by" . " " . $author;
+ $directory_name = str_replace("__", "_", str_replace(" ", "_", $dir_name));
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('directory_name', $directory_name);
+ $query->condition('approval_status', 1);
+ $result = $query->execute()->rowCount();
+ if ($result > 0)
+ {
+ //var_dump('this');die;
+ form_set_error('', t('Book is already allotted. Please try another book or contact to administrator'));
+ return;
+ } //$result > 0
+ } //!$pref_id
+ else
+ {
+ $book_title = ucname($book);
+ $author = ucname($author);
+ $dir_name = $book_title . " " . "by" . " " . $author;
+ $directory_name = str_replace("__", "_", str_replace(" ", "_", $dir_name));
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('directory_name', $directory_name);
+ $query->condition('id', $pref_id);
+ $result = $query->execute()->rowCount();
+ if ($result > 1)
+ {
+ form_set_error('', t('Book is already present. Please try another book or contact to administrator'));
+ return;
+ } //$result > 1
+ }
+ return $directory_name;
}