diff options
author | prashantsinalkar | 2016-04-07 16:18:04 +0530 |
---|---|---|
committer | prashantsinalkar | 2016-04-07 16:18:04 +0530 |
commit | f45d48b9da8764141edbf5dc10d0b17f01870ed3 (patch) | |
tree | 2607d2f958e60380327f655d85e517c90226e469 | |
parent | 64b7656aa8140441e07a96218085fe3b55595681 (diff) | |
download | scilab_textbook_companion-f45d48b9da8764141edbf5dc10d0b17f01870ed3.tar.gz scilab_textbook_companion-f45d48b9da8764141edbf5dc10d0b17f01870ed3.tar.bz2 scilab_textbook_companion-f45d48b9da8764141edbf5dc10d0b17f01870ed3.zip |
added category in book proposal and edited mail function
-rw-r--r--[-rwxr-xr-x] | .gitignore | 1 | ||||
-rw-r--r--[-rwxr-xr-x] | README | 2 | ||||
-rw-r--r--[-rwxr-xr-x] | README.txt | 0 | ||||
-rwxr-xr-x | code.inc | 36 | ||||
-rw-r--r--[-rwxr-xr-x] | css/jquery-ui.css | 0 | ||||
-rw-r--r--[-rwxr-xr-x] | css/textbook_companion.css | 0 | ||||
-rwxr-xr-x | dependency.inc | 50 | ||||
-rwxr-xr-x | download.inc | 21 | ||||
-rwxr-xr-x[-rw-r--r--] | js/jquery-1.7.1.js | 0 | ||||
-rwxr-xr-x[-rw-r--r--] | js/tbc-download.js | 0 | ||||
-rwxr-xr-x | js/textbook_companion.js | 7 | ||||
-rwxr-xr-x | manage_proposal.inc | 553 | ||||
-rwxr-xr-x | search.inc | 94 | ||||
-rwxr-xr-x | settings.inc | 21 | ||||
-rwxr-xr-x | textbook_companion.module | 1271 |
15 files changed, 1171 insertions, 885 deletions
diff --git a/.gitignore b/.gitignore index 8d25f50..6b05a7a 100755..100644 --- a/.gitignore +++ b/.gitignore @@ -37,6 +37,7 @@ xmlrpc.php /themes # Ignore vim temp. files +*.bak *.swo *.swp *~ @@ -1,2 +1,2 @@ -Textbook Companion project for FOSSEE, IIT Bombay written in Drupal 7 +Textbook Companion project for IIT Bombay written in Drupal 6 diff --git a/README.txt b/README.txt index 8f9f203..8f9f203 100755..100644 --- a/README.txt +++ b/README.txt @@ -671,9 +671,17 @@ function upload_examples_form_submit($form, &$form_state) { /* 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)) + $from = variable_get('textbook_companion_from_email', ''); + $bcc= variable_get('textbook_companion_emails', ''); + $cc=variable_get('textbook_companion_cc_emails', ''); + $params['example_uploaded']['example_id'] = $example_id; + $params['example_uploaded']['user_id'] = $user->uid; + $params['example_uploaded']['headers']=array('From'=>$from,'MIME-Version'=> '1.0', + 'Content-Type'=> 'text/plain; charset=UTF-8; format=flowed; delsp=yes', + 'Content-Transfer-Encoding' => '8Bit', + 'X-Mailer'=> 'Drupal','Cc' => $cc, 'Bcc' => $bcc); + + if (!drupal_mail('textbook_companion', 'example_uploaded', $email_to, language_default(), $param, $from, TRUE)) drupal_set_message('Error sending email message.', 'error'); drupal_goto('textbook_companion/code'); @@ -771,14 +779,20 @@ function _upload_examples_delete() /* 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)) + $from = variable_get('textbook_companion_from_email', ''); + $bcc= variable_get('textbook_companion_emails', ''); + $cc=variable_get('textbook_companion_cc_emails', ''); + $params['example_deleted_user']['book_title'] = $preference_data->book; + $params['example_deleted_user']['chapter_title'] = $chapter_data->name; + $params['example_deleted_user']['example_number'] = $example_data->number; + $params['example_deleted_user']['example_caption'] = $example_data->caption; + $params['example_deleted_user']['user_id'] = $user->uid; + $params['example_deleted_user']['headers']=array('From'=>$from,'MIME-Version'=> '1.0', + 'Content-Type'=> 'text/plain; charset=UTF-8; format=flowed; delsp=yes', + 'Content-Transfer-Encoding' => '8Bit', + 'X-Mailer'=> 'Drupal','Cc' => $cc, 'Bcc' => $bcc); + + if (!drupal_mail('textbook_companion', 'example_deleted_user', $email_to, language_default(), $param, $from, TRUE)) drupal_set_message('Error sending email message.', 'error'); } else { drupal_set_message('Error deleting example.', 'status'); diff --git a/css/jquery-ui.css b/css/jquery-ui.css index 1e400aa..1e400aa 100755..100644 --- a/css/jquery-ui.css +++ b/css/jquery-ui.css diff --git a/css/textbook_companion.css b/css/textbook_companion.css index ae35e79..ae35e79 100755..100644 --- a/css/textbook_companion.css +++ b/css/textbook_companion.css diff --git a/dependency.inc b/dependency.inc index fc5bc0d..5d6b3cc 100755 --- a/dependency.inc +++ b/dependency.inc @@ -1,7 +1,7 @@ <?php // $Id$ -function upload_dependency_form($form_state) +function upload_dependency_form($form,&$form_state) { global $user; @@ -20,7 +20,7 @@ function upload_dependency_form($form_state) if (!$proposal_data) { - drupal_set_message("Please submit a " . l('proposal', 'proposal') . ".", 'error'); + drupal_set_message("Please submit a " . l('proposal', 'book_proposal') . ".", 'error'); drupal_goto(''); } if ($proposal_data->proposal_status != 1 && $proposal_data->proposal_status != 4) @@ -33,12 +33,12 @@ function upload_dependency_form($form_state) return; break; case 2: - drupal_set_message(t('Your proposal has been dis-approved. Please create another proposal ' . l('here', 'proposal') . '.'), 'error'); + drupal_set_message(t('Your proposal has been dis-approved. Please create another proposal ' . l('here', 'book_proposal') . '.'), 'error'); drupal_goto(''); return; break; case 3: - drupal_set_message(t('Congratulations! You have completed your last book proposal. You have to create another proposal ' . l('here', 'proposal') . '.'), 'status'); + drupal_set_message(t('Congratulations! You have completed your last book proposal. You have to create another proposal ' . l('here', 'book_proposal') . '.'), 'status'); drupal_goto(''); return; break; @@ -195,7 +195,7 @@ function upload_dependency_form_submit($form, &$form_state) { if (!$proposal_data) { - drupal_set_message("Please submit a " . l('proposal', 'proposal') . ".", 'error'); + drupal_set_message("Please submit a " . l('proposal', 'book_proposal') . ".", 'error'); drupal_goto(''); } if ($proposal_data->proposal_status != 1 && $proposal_data->proposal_status != 4) @@ -208,12 +208,12 @@ function upload_dependency_form_submit($form, &$form_state) { return; break; case 2: - drupal_set_message(t('Your proposal has been dis-approved. Please create another proposal ' . l('here', 'proposal') . '.'), 'error'); + drupal_set_message(t('Your proposal has been dis-approved. Please create another proposal ' . l('here', 'book_proposal') . '.'), 'error'); drupal_goto(''); return; break; case 3: - drupal_set_message(t('Congratulations! You have completed your last book proposal. You have to create another proposal ' . l('here', 'proposal') . '.'), 'status'); + drupal_set_message(t('Congratulations! You have completed your last book proposal. You have to create another proposal ' . l('here', 'book_proposal') . '.'), 'status'); drupal_goto(''); return; break; @@ -310,8 +310,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)) @@ -334,19 +334,6 @@ function _list_existing_dependency($book_id) $query->orderBy('filename', 'ASC'); $result = $query->execute(); - // $counter = 0; - // while ($row = db_fetch_object($query)) - // { - // $temp_caption = ''; - // if ($row->caption) - // $temp_caption = ' (' . $row->caption . ')'; - // $return_html .= '<li>' . l($row->filename . $temp_caption, 'download/dependency/' . $row->id) . '</li>'; - // $counter++; - // } - // if ($counter == 0) - // $return_html .= '<li>(None)</li>'; - // $return_html .= '</ul>'; - $headers = array( "File", "Action", ); @@ -694,11 +681,18 @@ 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; + $from = variable_get('textbook_companion_from_email', ''); + $bcc= variable_get('textbook_companion_emails', ''); + $cc=variable_get('textbook_companion_cc_emails', ''); + $params['dependency_uploaded']['user_id'] = $user->uid; + $params['dependency_uploaded']['dependency_names'] = $dependency_names; + $params['dependency_uploaded']['headers']=array('From'=>$from,'MIME-Version'=> '1.0', + 'Content-Type'=> 'text/plain; charset=UTF-8; format=flowed; delsp=yes', + 'Content-Transfer-Encoding' => '8Bit', + 'X-Mailer'=> 'Drupal','Cc' => $cc, 'Bcc' => $bcc); $email_to = $user->mail; - if (!drupal_mail('textbook_companion', 'dependency_uploaded', $email_to, language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE)) + if (!drupal_mail('textbook_companion', 'dependency_uploaded', $email_to, language_default(), $params, $from, TRUE)) drupal_set_message('Error sending email message.', 'error'); } @@ -735,7 +729,7 @@ function delete_dependency($dependency_id = 0, $confirm = "") { if (!$proposal_data) { - drupal_set_message("Please submit a " . l('proposal', 'proposal') . ".", 'error'); + drupal_set_message("Please submit a " . l('proposal', 'book_proposal') . ".", 'error'); drupal_goto(''); } if ($proposal_data->proposal_status != 1 && $proposal_data->proposal_status != 4) @@ -748,12 +742,12 @@ function delete_dependency($dependency_id = 0, $confirm = "") { return; break; case 2: - drupal_set_message(t('Your proposal has been dis-approved. Please create another proposal ' . l('here', 'proposal') . '.'), 'error'); + drupal_set_message(t('Your proposal has been dis-approved. Please create another proposal ' . l('here', 'book_proposal') . '.'), 'error'); drupal_goto(''); return; break; case 3: - drupal_set_message(t('Congratulations! You have completed your last book proposal. You have to create another proposal ' . l('here', 'proposal') . '.'), 'status'); + drupal_set_message(t('Congratulations! You have completed your last book proposal. You have to create another proposal ' . l('here', 'book_proposal') . '.'), 'status'); drupal_goto(''); return; break; diff --git a/download.inc b/download.inc index f851273..e4d2a5d 100755 --- a/download.inc +++ b/download.inc @@ -135,6 +135,7 @@ function textbook_companion_download_example() function textbook_companion_download_chapter() { $chapter_id = arg(2); + // var_dump($chapter_id);die; $root_path = textbook_companion_path(); /* get example data */ @@ -297,4 +298,24 @@ $zip->addFile($root_path . $dependency_file_data->filepath, $BK_PATH . $CH_PATH drupal_goto('textbook_run'); } } + +function textbook_companion_download_sample_code() +{ + $proposal_id = arg(2); + $root_path = textbook_companion_samplecode_path(); + + $query = db_select('textbook_companion_proposal'); + $query->fields('textbook_companion_proposal'); + $query->condition('id', $proposal_id); + $query->range(0, 1); + $result = $query->execute(); + + $example_file_data =$result->fetchObject(); + $samplecodename=substr($example_file_data->samplefilepath, strrpos($example_file_data->samplefilepath, '/') + 1); + header('Content-Type: application/zip'); + header('Content-disposition: attachment; filename="'.$samplecodename.'"'); + header('Content-Length: ' . filesize($root_path . $example_file_data->samplefilepath)); + ob_clean(); + readfile($root_path . $example_file_data->samplefilepath); +} diff --git a/js/jquery-1.7.1.js b/js/jquery-1.7.1.js index 16ad06c..16ad06c 100644..100755 --- a/js/jquery-1.7.1.js +++ b/js/jquery-1.7.1.js diff --git a/js/tbc-download.js b/js/tbc-download.js index 04b7633..04b7633 100644..100755 --- a/js/tbc-download.js +++ b/js/tbc-download.js diff --git a/js/textbook_companion.js b/js/textbook_companion.js index bbbb851..10bb3d2 100755 --- a/js/textbook_companion.js +++ b/js/textbook_companion.js @@ -1,6 +1,7 @@ -$( document ).ready(function() { +(function ($) { //to search - $('#searchtext').keyup(function(event) { +$(document).ready(function(){ +$('#searchtext').keyup(function(event) { var search_text = $('#searchtext').val(); var rg = new RegExp(search_text,'i'); $('#aicte-list-wrapper .title , .form-item' ).each(function(){ @@ -206,5 +207,5 @@ $report_form.submit(function(e) { } e.preventDefault(); }); - }); +})(jQuery); diff --git a/manage_proposal.inc b/manage_proposal.inc index 68f3590..4527146 100755 --- a/manage_proposal.inc +++ b/manage_proposal.inc @@ -159,7 +159,7 @@ function _category_all() /************************** PROPOSAL APPROVAL FORM ****************************/ /******************************************************************************/ -function proposal_approval_form($form,$form_state) +function proposal_approval_form($form,&$form_state) { global $user; @@ -229,17 +229,22 @@ function proposal_approval_form($form,$form_state) '#type' => 'item', '#markup' => $row->city, '#title' => t('City'), + ); + $form['all_state'] = array( + '#type' => 'item', + '#markup' => $row->state, + '#title' => t('State'), + ); + $form['country'] = array( + '#type' => 'item', + '#markup' => $row->country, + '#title' => t('Country'), ); $form['pincode'] = array( '#type' => 'item', '#markup' => $row->pincode, '#title' => t('Pincode'), ); - $form['all_state'] = array( - '#type' => 'item', - '#markup' => $row->state, - '#title' => t('State'), - ); $form['faculty'] = array( '#type' => 'item', '#markup' => $row->faculty, @@ -279,8 +284,11 @@ function proposal_approval_form($form,$form_state) /* get book preference */ $preference_rows = array(); - $preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = :proposal_id ORDER BY pref_number ASC", array(':proposal_id' => $proposal_id)); - + // $preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = :proposal_id ORDER BY pref_number ASC", array(':proposal_id' => $proposal_id)); + $preference_q = db_query(" SELECT * FROM list_of_category loc + JOIN textbook_companion_preference tcp ON loc.category_id = tcp.category + WHERE proposal_id = :proposal_id ORDER BY pref_number ASC +",array(':proposal_id' => $proposal_id)); /*$query = db_select('textbook_companion_preference'); $query->fields('textbook_companion_preference'); $query->condition('proposal_id', $proposal_id); @@ -290,7 +298,11 @@ function proposal_approval_form($form,$form_state) while ($preference_data = $preference_q->fetchObject()) { - $preference_rows[$preference_data->id] = $preference_data->book . ' (Written by ' . $preference_data->author . ')'; + + $category_data = _tbc_list_of_category($preference_data->category); + foreach ($category_data as $cat){ + $preference_rows[$preference_data->id] = $preference_data->book . ' (Written by ' . $preference_data->author . ')</br>[Category: '.$cat.']</br>'; + } } if($row->proposal_type == 1){ $form['book_preference'] = array( @@ -308,6 +320,12 @@ function proposal_approval_form($form,$form_state) '#options' => $preference_rows, '#required' => TRUE, );} + if($row->samplefilepath !="None"){ + $form['samplecode'] = array( + '#type' => 'markup', + '#markup' => l('Click here to download sample code', 'download/samplecode/' . $proposal_id)."<br><br>" , + ); + } $form['disapprove'] = array( '#type' => 'checkbox', @@ -351,12 +369,6 @@ function proposal_approval_form_submit($form, &$form_state) $result = db_query("SELECT * FROM {textbook_companion_proposal} WHERE proposal_status = 0 and id = :proposal_id",array(':proposal_id' => $proposal_id)); - /*$query = db_select('textbook_companion_proposal'); - $query->fields('textbook_companion_proposal'); - $query->condition('proposal_status', 0); - $query->condition('id',$proposal_id); - $result = $query->execute();*/ - if ($result) { if ($row = $result->fetchObject()) @@ -379,26 +391,8 @@ function proposal_approval_form_submit($form, &$form_state) //var_dump(array(':approver_uid' => $user->uid,':approver_date'=> time(), ':message' => $form_state['values']['message'], ':id' =>$proposal_id));die; db_query("UPDATE {textbook_companion_proposal} SET approver_uid = :approver_uid, approval_date = :approval_date, proposal_status = 2, message = :message WHERE id = :id", array(':approver_uid' => $user->uid,':approval_date'=> time(), ':message' => $form_state['values']['message'], ':id' =>$proposal_id)); - /*$query = db_update('textbook_companion_proposal'); - $query->fields(array( - 'approver_uid' => $user->uid, - 'approval_date' => $current_date, - 'proposal_status' => 2, - 'message' => $form_state['values']['message'], - )); - $query->condition('id', $proposal_id); - $num_updated = $query->execute(); -var_dump($num_updated);die;*/ db_query("UPDATE {textbook_companion_preference} SET approval_status = 2 WHERE proposal_id = :id",array(':id' => $proposal_id)); - /*$query = db_update('textbook_companion_preference'); - $query->fields(array( - 'approval_status' => 2, - )); - $query->condition('proposal_id',$proposal_id); - $num_updated = $query->execute(); -*/ - /* unlock all the aicte books */ if($form_state['values']['proposal_type']==0){ $query = " @@ -408,22 +402,23 @@ if($form_state['values']['proposal_type']==0){ "; db_query($query, array(':proposal_id' => $proposal_id)); - /*$query = db_update('textbook_companion_aicte'); - $query->fields(array( - 'status' => 0, - 'uid' => 0, - 'proposal_id' => 0, - 'preference_id' => 0, - )); - $query->condition('proposal_id', $proposal_id); - $num_updated = $query->execute();*/ -} + + } /* sending email */ $book_user = user_load($row->uid); - $param['proposal_disapproved']['proposal_id'] = $proposal_id; - $param['proposal_disapproved']['user_id'] = $row->uid; $email_to = $book_user->mail; - if (!drupal_mail('textbook_companion', 'proposal_disapproved', $email_to , language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE)) + $from = variable_get('textbook_companion_from_email', ''); + $bcc= variable_get('textbook_companion_emails', ''); + $cc=variable_get('textbook_companion_cc_emails', ''); + $params['proposal_disapproved']['proposal_id'] = $proposal_id; + $params['proposal_disapproved']['user_id'] = $row->uid; + $params['proposal_disapproved']['headers']=array('From'=>$from,'MIME-Version'=> '1.0', + 'Content-Type'=> 'text/plain; charset=UTF-8; format=flowed; delsp=yes', + 'Content-Transfer-Encoding' => '8Bit', + 'X-Mailer'=> 'Drupal','Cc' => $cc, 'Bcc' => $bcc); + + + if (!drupal_mail('textbook_companion', 'proposal_disapproved', $email_to , language_default(), $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'); @@ -433,8 +428,7 @@ if($form_state['values']['proposal_type']==0){ /* 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( @@ -453,15 +447,6 @@ if($form_state['values']['proposal_type']==0){ )); $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 = " UPDATE textbook_companion_aicte @@ -469,23 +454,21 @@ if($form_state['values']['proposal_type']==0){ WHERE proposal_id = {:proposal_id} AND preference_id != {:preference_id} "; db_query($query,array(':proposal_id' => $proposal_id, ':preference_id'=> $preference_id)); - /*$query = db_update('textbook_companion_aicte'); - $query->fields(array( - 'status' => 0, - 'uid' => 0, - 'proposal_id' => 0, - 'preference_id' => 0, - )); - $query->condition('proposal_id', $proposal_id); - $query->condition('preference_id', $preference_id, '<>'); - $num_updated = $query->execute(); - - /* sending email */ + + /* sending email */ $book_user = user_load($row->uid); - $param['proposal_approved']['proposal_id'] = $proposal_id; - $param['proposal_approved']['user_id'] = $row->uid; $email_to = $book_user->mail; - if (!drupal_mail('textbook_companion', 'proposal_approved', $email_to , language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE)) + $from = variable_get('textbook_companion_from_email', ''); + $bcc = variable_get('textbook_companion_emails', ''); + $cc=variable_get('textbook_companion_cc_emails', ''); + $params['proposal_approved']['proposal_id'] = $proposal_id; + $params['proposal_approved']['user_id'] = $row->uid; + $params['proposal_approved']['headers']=array('From'=>$from,'MIME-Version'=> '1.0', + 'Content-Type'=> 'text/plain; charset=UTF-8; format=flowed; delsp=yes', + 'Content-Transfer-Encoding' => '8Bit', + 'X-Mailer'=> 'Drupal','Cc' => $cc, 'Bcc' => $bcc); + + if (!drupal_mail('textbook_companion', 'proposal_approved', $email_to , language_default(), $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'); @@ -498,7 +481,7 @@ if($form_state['values']['proposal_type']==0){ /*************************** PROPOSAL STATUS FORM *****************************/ /******************************************************************************/ -function proposal_status_form($form_state) +function proposal_status_form($form,&$form_state) { global $user; @@ -558,18 +541,22 @@ function proposal_status_form($form_state) '#type' => 'item', '#markup' => $proposal_data->city, '#title' => t('City'), - ); - $form['pincode'] = array( - '#type' => 'item', - '#markup' => $proposal_data->pincode, - '#title' => t('Pincode'), - ); + ); $form['all_state'] = array( '#type' => 'item', '#markup' => $proposal_data->state, '#title' => t('State'), ); - + $form['country'] = array( + '#type' => 'item', + '#markup' => $proposal_data->country, + '#title' => t('Country'), + ); + $form['pincode'] = array( + '#type' => 'item', + '#markup' => $proposal_data->pincode, + '#title' => t('Pincode'), + ); $form['faculty'] = array( '#type' => 'item', '#markup' => $proposal_data->faculty, @@ -609,12 +596,9 @@ function proposal_status_form($form_state) ); } - /* get book preference */ $preference_html = '<ul>'; - /*$preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d ORDER BY pref_number ASC", $proposal_id);*/ - $query = db_select('textbook_companion_preference'); $query->fields('textbook_companion_preference'); $query->condition('proposal_id', $proposal_id); @@ -731,10 +715,10 @@ function proposal_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', 'proposal_completed', $email_to , language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE)) + if (!drupal_mail('textbook_companion', 'proposal_completed', $email_to , language_default(), $params, variable_get('textbook_companion_from_email', NULL), TRUE)) drupal_set_message('Error sending email message.', 'error'); drupal_set_message('Congratulations! Book proposal has been marked as completed. User has been notified of the completion.', 'status'); @@ -748,14 +732,13 @@ function proposal_status_form_submit($form, &$form_state) /**************************** PROPOSAL EDIT FORM ******************************/ /******************************************************************************/ -function proposal_edit_form($form_state,$nonaicte_book) +function proposal_edit_form($form, $form_state,$nonaicte_book) { global $user; /* get current proposal */ $proposal_id = arg(2); - /*$proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d", $proposal_id);*/ $query = db_select('textbook_companion_proposal'); $query->fields('textbook_companion_proposal'); $query->condition('id', $proposal_id); @@ -778,9 +761,6 @@ function proposal_edit_form($form_state,$nonaicte_book) $user_data = user_load($proposal_data->uid); - /* $preference1_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $proposal_id, 1); - $preference1_data = db_fetch_object($preference1_q);*/ - $query = db_select('textbook_companion_preference'); $query->fields('textbook_companion_preference'); $query->condition('proposal_id', $proposal_id); @@ -789,9 +769,6 @@ function proposal_edit_form($form_state,$nonaicte_book) $preference1_q = $query->execute(); $preference1_data =$preference1_q->fetchObject(); - /*$preference2_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $proposal_id, 2); - $preference2_data = db_fetch_object($preference2_q);*/ - $query = db_select('textbook_companion_preference'); $query->fields('textbook_companion_preference'); $query->condition('proposal_id', $proposal_id); @@ -800,9 +777,6 @@ function proposal_edit_form($form_state,$nonaicte_book) $preference2_q = $query->execute(); $preference2_data =$preference2_q->fetchObject(); - /*$preference3_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $proposal_id, 3); - $preference3_data = db_fetch_object($preference3_q);*/ - $query = db_select('textbook_companion_preference'); $query->fields('textbook_companion_preference'); $query->condition('proposal_id', $proposal_id); @@ -834,7 +808,7 @@ function proposal_edit_form($form_state,$nonaicte_book) '#required' => TRUE, '#default_value' => $proposal_data->mobile, ); - $form['how_project'] = array( + /*$form['how_project'] = array( '#type' => 'select', '#title' => t('How did you come to know about this project'), '#options' => array('Scilab Website' => 'Scilab Website', @@ -845,7 +819,7 @@ function proposal_edit_form($form_state,$nonaicte_book) 'Others' => 'Others'), '#required' => TRUE, '#default_value' => $proposal_data->how_project, - ); + );*/ $form['course'] = array( '#type' => 'textfield', '#title' => t('Course'), @@ -857,18 +831,7 @@ function proposal_edit_form($form_state,$nonaicte_book) $form['branch'] = array( '#type' => 'select', '#title' => t('Department/Branch'), - '#options' => array('Electrical Engineering' => 'Electrical Engineering', - 'Electronics Engineering' => 'Electronics Engineering', - 'Computer Engineering' => 'Computer Engineering', - 'Chemical Engineering' => 'Chemical Engineering', - 'Instrumentation Engineering' => 'Instrumentation Engineering', - 'Mechanical Engineering' => 'Mechanical Engineering', - 'Civil Engineering' => 'Civil Engineering', - 'Physics' => 'Physics', - 'Applied Physics' =>'Applied Physics', - 'Nuclear Technology and Biotechnology' => ' Nuclear Technology and Biotechnology', - 'Mathematics' => 'Mathematics', - 'Others' => 'Others'), + '#options' => _tbc_list_of_departments(), '#required' => TRUE, '#default_value' => $proposal_data->branch, ); @@ -880,73 +843,86 @@ function proposal_edit_form($form_state,$nonaicte_book) '#required' => TRUE, '#default_value' => $proposal_data->university, ); - $form['city'] = array( - '#type' => 'textfield', - '#title' => t('City/ Village'), - '#size' => 80, - '#maxlength' => 150, - '#required' => TRUE, - '#attributes' =>array('placeholder' =>'Insert location of your institute/ university....'), - '#default_value' => $proposal_data->city, - - ); -$form['pincode'] = array( - '#type' => 'textfield', - '#title' => t('Pincode'), - '#size' => 30, - '#maxlength' => 6, - '#required' => TRUE, - '#attributes' =>array('placeholder' =>'Insert pincode of your city/ village....'), - '#default_value' => $proposal_data->pincode, -); -$form['all_state'] = array( +$form['country'] = array( '#type' => 'select', - '#title' => t('State'), + '#title' => t('Country'), '#options' => array( - '0' => 'Please select...', - 'Andhra Pradesh' => t('Andhra Pradesh'), - 'Arunachal Pradesh' => 'Arunachal Pradesh', - 'Assam' => 'Assam', - 'Bihar' => 'Bihar', - 'Chhattisgarh' => 'Chhattisgarh', - 'Goa' => 'Goa', - 'Gujarat' => 'Gujarat', - 'Haryana' => 'Haryana', - 'Himachal Pradesh' => 'Himachal Pradesh', - 'Jammu & Kashmir' => 'Jammu & Kashmir', - 'Jharkhand' => 'Jharkhand', - 'Karnataka' => 'Karnataka', - 'Kerala' => 'Kerala', - 'Madhya Pradesh' => 'Madhya Pradesh', - 'Maharashtra' => 'Maharashtra', - 'Manipur' => 'Manipur', - 'Meghalaya' => 'Meghalaya', - 'Mizoram' => 'Mizoram', - 'Nagaland' => 'Nagaland', - 'Odisha' => 'Odisha', - 'Punjab' => 'Punjab', - 'Rajasthan' => 'Rajasthan', - 'Sikkim' => 'Sikkim', - 'Tamil Nadu' => 'Tamil Nadu', - 'Telangana' => 'Telangana', - 'Tripura' => 'Tripura', - 'Uttarakhand' => 'Uttarakhand', - 'Uttar Pradesh'=> 'Uttar Pradesh', - 'West Bengal' => 'West Bengal', - 'Andaman & Nicobar' => 'Andaman & Nicobar', - 'Chandigarh' => 'Chandigarh', - 'Dadra and Nagar Haveli' => 'Dadra and Nagar Haveli', - 'Daman & Diu' => 'Daman & Diu', - 'Delhi' => 'Delhi', - 'Lakshadweep' => 'Lakshadweep', - 'Puducherry' => 'Puducherry', - 'Others' => 'Others', + 'India' => 'India', + 'Others' => 'Others', ), '#required' => TRUE, '#tree' => TRUE, '#validated' => TRUE, + '#default_value' => $proposal_data->country, + ); + $form['other_country'] = array( + '#type' => 'textfield', + '#title' => t('Other than India'), + '#size' => 100, + '#attributes' =>array('placeholder' => t('Enter your country name')), + '#default_value' => $proposal_data->country, + '#states' => array( + 'visible' => array( + ':input[name="country"]' => array('value' => 'Others'), + ), + ), + ); + $form['other_state'] = array( + '#type' => 'textfield', + '#title' => t('State other than India'), + '#size' => 100, + '#attributes' =>array('placeholder' => t('Enter your state/region name')), + '#default_value' => $proposal_data->state, + '#states' => array( + 'visible' => array( + ':input[name="country"]' => array('value' => 'Others'), + ), + ), + ); + $form['other_city'] = array( + '#type' => 'textfield', + '#title' => t('City other than India'), + '#size' => 100, + '#attributes' =>array('placeholder' => t('Enter your city name')), + '#default_value' => $proposal_data->city, + '#states' => array( + 'visible' => array( + ':input[name="country"]' => array('value' => 'Others'), + ), + ), + ); + $form['all_state'] = array( + '#type' => 'select', + '#title' => t('State'), + '#options' => _tbc_list_of_states(), + '#validated' => TRUE, '#default_value' => $proposal_data->state, -); + '#states' => array( + 'visible' => array( + ':input[name="country"]' => array('value' => 'India'), + ), + ), + ); + $form['city'] = array( + '#type' => 'select', + '#title' => t('City'), + '#options' => _tbc_list_of_cities(), + '#default_value' => $proposal_data->city, + '#states' => array( + 'visible' => array( + ':input[name="country"]' => array('value' => 'India'), + ), + ), + ); + $form['pincode'] = array( + '#type' => 'textfield', + '#title' => t('Pincode'), + '#size' => 30, + '#maxlength' => 6, + '#default_value' => $proposal_data->pincode, + '#required' => False, + '#attributes' =>array('placeholder' =>'Enter pincode....'), + ); $form['faculty'] = array( '#type' => 'textfield', '#title' => t('College Teacher/Professor'), @@ -970,12 +946,14 @@ $form['all_state'] = array( '#maxlength' => 10, '#default_value' => date('d-m-Y', $proposal_data->completion_date), ); - $form['scilab_version'] = array( + list($scilab, $version) = explode(' ', $proposal_data->scilab_version); + $scilab_version = $version; + $form['version'] = array( '#type' => 'textfield', '#title' => t('Scilab Version'), '#size' => 10, '#maxlength' => 20, - '#default_value' => $proposal_data->scilab_version, + '#default_value' => $scilab_version, ); $form['operating_system'] = array( '#type' => 'textfield', @@ -1038,6 +1016,13 @@ $form['all_state'] = array( '#required' => TRUE, '#default_value' => $preference1_data->year, ); + $form['preference1']['book_category_1'] = array( + '#type' => 'select', + '#title' => t('Category'), + '#options' => _tbc_list_of_category(), + '#required' => TRUE, + '#default_value' => $preference1_data->category, + ); if($preference2_data){ $form['preference2'] = array( '#type' => 'fieldset', @@ -1093,6 +1078,13 @@ $form['all_state'] = array( '#required' => TRUE, '#default_value' => $preference2_data->year, ); + $form['preference2']['book_category_2'] = array( + '#type' => 'select', + '#title' => t('Category'), + '#options' => _tbc_list_of_category(), + '#required' => TRUE, + '#default_value' => $preference2_data->category, + ); } if($preference3_data){ $form['preference3'] = array( @@ -1149,6 +1141,13 @@ if($preference3_data){ '#required' => TRUE, '#default_value' => $preference3_data->year, ); + $form['preference3']['book_category_3'] = array( + '#type' => 'select', + '#title' => t('Category'), + '#options' => _tbc_list_of_category(), + '#required' => TRUE, + '#default_value' => $preference3_data->category, + ); } /* hidden fields */ @@ -1170,7 +1169,9 @@ if($preference3_data){ function proposal_edit_form_validate($form, &$form_state) { - + /* version */ + if (!preg_match('/^\d+(?:\.\d+)+/', $form_state['values']['version'])) + form_set_error('version', t('Please enter correct version in speacifed format')); /* mobile */ if (!preg_match('/^[0-9\ \+]{0,15}$/', $form_state['values']['mobile'])) form_set_error('mobile', t('Invalid mobile number')); @@ -1225,61 +1226,77 @@ function proposal_edit_form_validate($form, &$form_state) if (!preg_match('/^[0-9\-xX]+$/', $form_state['values']['isbn3'])) form_set_error('isbn3', t('Invalid ISBN for Book Preference 3')); } + +if($form_state['values']['country']=='Others'){ + if($form_state['values']['other_country']== ''){ + form_set_error('other_country', t('Enter country name')); + // $form_state['values']['country'] = $form_state['values']['other_country']; + }else{ + $form_state['values']['country'] = $form_state['values']['other_country']; + } + if($form_state['values']['other_state']== ''){ + form_set_error('other_state', t('Enter state name')); + // $form_state['values']['country'] = $form_state['values']['other_country']; + }else{ + $form_state['values']['all_state'] = $form_state['values']['other_state']; + } + if($form_state['values']['other_city']== ''){ + form_set_error('other_city', t('Enter city name')); + // $form_state['values']['country'] = $form_state['values']['other_country']; + }else{ + $form_state['values']['city'] = $form_state['values']['other_city']; + } + }else{ + if($form_state['values']['country']== ''){ + form_set_error('country', t('Select country name')); + // $form_state['values']['country'] = $form_state['values']['other_country']; + } + if($form_state['values']['all_state']== ''){ + form_set_error('all_state', t('Select state name')); + // $form_state['values']['country'] = $form_state['values']['other_country']; + } + if($form_state['values']['city']== ''){ + form_set_error('city', t('Select city name')); + // $form_state['values']['country'] = $form_state['values']['other_country']; + } + + + } + + + return; } - +/***************** proposal edit from ********************/ function proposal_edit_form_submit($form, &$form_state) { /* completion date to timestamp */ list($d, $m, $y) = explode('-', $form_state['values']['completion_date']); $completion_date_timestamp = mktime(0, 0, 0, $m, $d, $y); - + $scilab_version = 'scilab ' . $form_state['values']['version']; $proposal_id = $form_state['values']['hidden_proposal_id']; - - - /*$query = "UPDATE {textbook_companion_proposal} SET full_name = '".$form_state['values']['full_name']."', mobile = '".$form_state['values']['mobile']."', how_project = '".$form_state['values']['how_project']."', course = '".$form_state['values']['course']."', branch = '".$form_state['values']['branch']."', university = '".$form_state['values']['university']."', faculty = '".$form_state['values']['faculty']."', reviewer = '".$form_state['values']['reviewer']."', completion_date = $completion_date_timestamp, operating_system= '".$form_state['values']['operating_system']."', scilab_version= '".$form_state['values']['scilab_version']."' WHERE id =".$proposal_id; - db_query($query);*/ - + $scilab_version = 'scilab ' . $form_state['values']['version']; + $query = db_update('textbook_companion_proposal'); $query->fields(array( 'full_name' => $form_state['values']['full_name'], 'mobile' => $form_state['values'][ 'mobile'], - 'how_project' => $form_state['values']['how_project'], 'course' => $form_state['values']['course'], 'branch' => $form_state['values']['branch'], 'university' => $form_state['values']['university'], + 'country' => $form_state['values']['country'], 'city' => $form_state['values']['city'], - 'pincode' => $form_state['values']['pincode'], - 'state' => $form_state['values']['all_state'], + 'pincode' => $form_state['values']['pincode'], + 'state' => $form_state['values']['all_state'], 'faculty' => $form_state['values']['faculty'], 'reviewer' => $form_state['values']['reviewer'], 'completion_date' => $completion_date_timestamp, 'operating_system' => $form_state['values']['operating_system'], - 'scilab_version' => $form_state['values']['scilab_version'], + 'scilab_version' => $scilab_version, )); $query->condition('id', $proposal_id); $num_updated = $query->execute(); - -/*db_query("UPDATE {textbook_companion_proposal} SET full_name = '%s', mobile = '%s', how_project = '%s', course = '%s', branch = '%s', university = '%s', faculty = '%s', reviewer = '%s', completion_date = %d, operating_system= '%s', scilab_version= '%s' WHERE id = %d", - $form_state['values']['full_name'], - $form_state['values']['mobile'], - $form_state['values']['how_project'], - $form_state['values']['course'], - $form_state['values']['branch'], - $form_state['values']['university'], - $form_state['values']['faculty'], - $form_state['values']['reviewer'], - $completion_date_timestamp, - $form_state['values']['operating_system'], - $form_state['values']['scilab_version'], - $proposal_id); */ - - - - /*$preference1_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $proposal_id, 1); - $preference1_data = db_fetch_object($preference1_q);*/ - $query = db_select('textbook_companion_preference'); $query->fields('textbook_companion_preference'); $query->condition('proposal_id', $proposal_id); @@ -1291,9 +1308,6 @@ $query = db_update('textbook_companion_proposal'); if ($preference1_data) $preference1_id = $preference1_data->id; - /*$preference2_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $proposal_id, 2); - $preference2_data = db_fetch_object($preference2_q);*/ - $query = db_select('textbook_companion_preference'); $query->fields('textbook_companion_preference'); $query->condition('proposal_id', $proposal_id); @@ -1305,9 +1319,6 @@ $query = db_update('textbook_companion_proposal'); if ($preference2_data) $preference2_id = $preference2_data->id; - /*$preference3_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $proposal_id, 3); - $preference3_data = db_fetch_object($preference3_q);*/ - $query = db_select('textbook_companion_preference'); $query->fields('textbook_companion_preference'); $query->condition('proposal_id', $proposal_id); @@ -1323,15 +1334,6 @@ $query = db_update('textbook_companion_proposal'); { del_book_pdf($preference1_data->id); - /*db_query("UPDATE {textbook_companion_preference} SET book = '%s', author = '%s', isbn = '%s', publisher = '%s', edition = %d, year = %d WHERE id = %d", - $form_state['values']['book1'], - $form_state['values']['author1'], - $form_state['values']['isbn1'], - $form_state['values']['publisher1'], - $form_state['values']['edition1'], - $form_state['values']['year1'], - $preference1_id);*/ - $query = db_update('textbook_companion_preference'); $query->fields(array( 'book' => $form_state['values']['book1'], @@ -1340,6 +1342,7 @@ $query = db_update('textbook_companion_proposal'); 'publisher' => $form_state['values']['publisher1'], 'edition' => $form_state['values']['edition1'], 'year' => $form_state['values']['year1'], + 'category' => $form_state['values']['book_category_1'], )); $query->condition('id', $preference1_id); $num_updated = $query->execute(); @@ -1349,15 +1352,6 @@ $query = db_update('textbook_companion_proposal'); { del_book_pdf($preference2_data->id); - /*db_query("UPDATE {textbook_companion_preference} SET book = '%s', author = '%s', isbn = '%s', publisher = '%s', edition = %d, year = %d WHERE id = %d", - $form_state['values']['book2'], - $form_state['values']['author2'], - $form_state['values']['isbn2'], - $form_state['values']['publisher2'], - $form_state['values']['edition2'], - $form_state['values']['year2'], - $preference2_id);*/ - $query = db_update('textbook_companion_preference'); $query->fields(array( 'book' => $form_state['values']['book2'], @@ -1366,6 +1360,7 @@ $query = db_update('textbook_companion_proposal'); 'publisher' => $form_state['values']['publisher2'], 'edition' => $form_state['values']['edition2'], 'year' => $form_state['values']['year2'], + 'category' => $form_state['values']['book_category_2'], )); $query->condition('id', $preference2_id); $num_updated = $query->execute(); @@ -1375,15 +1370,6 @@ $query = db_update('textbook_companion_proposal'); { del_book_pdf($preference3_data->id); - /*db_query("UPDATE {textbook_companion_preference} SET book = '%s', author = '%s', isbn = '%s', publisher = '%s', edition = %d, year = %d WHERE id = %d", - $form_state['values']['book3'], - $form_state['values']['author3'], - $form_state['values']['isbn3'], - $form_state['values']['publisher3'], - $form_state['values']['edition3'], - $form_state['values']['year3'], - $preference3_id);*/ - $query = db_update('textbook_companion_preference'); $query->fields(array( 'book' => $form_state['values']['book3'], @@ -1392,30 +1378,25 @@ $query = db_update('textbook_companion_proposal'); 'publisher' => $form_state['values']['publisher3'], 'edition' => $form_state['values']['edition3'], 'year' => $form_state['values']['year3'], + 'category' => $form_state['values']['book_category_3'], )); $query->condition('id',$preference3_id); $num_updated = $query->execute(); - - + } drupal_set_message(t('Proposal Updated'), 'status'); drupal_goto('manage_proposal/'); } - - /******************************************************************************/ /**************************** CATEGORY EDIT FORM ******************************/ /******************************************************************************/ -function category_edit_form($form_state) +function category_edit_form($form, &$form_state) { /* get current proposal */ $preference_id = arg(3); - /*$preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d", $preference_id); - $preference_data = db_fetch_object($preference_q);*/ - $query = db_select('textbook_companion_preference'); $query->fields('textbook_companion_preference'); $query->condition('id', $preference_id); @@ -1463,20 +1444,7 @@ function category_edit_form($form_state) $form['category'] = array( '#type' => 'select', '#title' => t('Category'), - '#options' => array(0 => 'Please select', - 1 => 'Fluid Mechanics', - 2 => 'Control Theory & Control Systems', - 3 => 'Chemical Engineering', - 4 => 'Thermodynamics', - 5 => 'Mechanical Engineering', - 6 => 'Signal Processing', - 7 => 'Digital Communications', - 8 => 'Electrical Technology', - 9 => 'Mathematics & Pure Science', - 10 => 'Analog Electronics', - 11 => 'Digital Electronics', - 12 => 'Computer Programming', - 13 => 'Others'), + '#options' => _tbc_list_of_category(), '#required' => TRUE, '#default_value' => $preference_data->category, ); @@ -1570,13 +1538,10 @@ function dataentry_edit($id = NULL) { } } -function dataentry_edit_form($form,$form_state, $id) +function dataentry_edit_form($form,&$form_state, $id) { global $user; - /*$preference_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE id = %d", $id); - $preference_data = db_fetch_object($preference_q);*/ - $query = db_select('textbook_companion_preference'); $query->fields('textbook_companion_preference'); $query->condition('id', $id); @@ -1647,9 +1612,7 @@ function dataentry_edit_form($form,$form_state, $id) function dataentry_edit_form_submit($form, &$form_state) { - /*db_query("UPDATE {textbook_companion_preference} SET book = '%s', author = '%s', isbn = '%s', publisher = '%s', edition = '%s', year = %d WHERE id = %d", $_POST['book'], $_POST['author'], $_POST['isbn'], $_POST['publisher'], $_POST['edition'], $_POST['year'], $_POST['id']);*/ - - $query = db_update('textbook_companion_preference'); + $query = db_update('textbook_companion_preference'); $query->fields(array( 'book' => $_POST['book'], 'author' => $_POST['author'], @@ -1669,25 +1632,6 @@ function dataentry_edit_form_submit($form, &$form_state) 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('pro'); - $query->fields('pro', array('id')); - $query->addField('pro','id','proposal_id'); - $query->leftJoin('textbook_companion_preference', 'pre', 'pre.proposal_id = pro.id'); - $query->leftJoin('users', 'usr', 'usr.uid = pro.uid'); - $query->condition('pre.id', $preference_id); - $result = $query->execute(); - $row =$result->fetchObject(); -*/ $query = " SELECT *, pro.id as proposal_id FROM textbook_companion_proposal pro @@ -1699,22 +1643,7 @@ function _failed_all($preference_id=0, $confirm="") { $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(); -*/ - + $query = " UPDATE textbook_companion_proposal SET failed_reminder = failed_reminder + 1 @@ -1764,25 +1693,7 @@ function _failed_all($preference_id=0, $confirm="") { $page_content .= l("Cancel", "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(); -*/ + $query = " SELECT * FROM textbook_companion_proposal pro LEFT JOIN textbook_companion_preference pre ON pre.proposal_id = pro.id @@ -9,17 +9,12 @@ function textbook_companion_search_form($form,&$form_state) '#title' => t('Search'), '#size' => 48, ); - - $form['search_by_title'] = array( - '#type' => 'checkbox', - '#default_value' => TRUE, - '#title' => t('Search by Title of the Book'), - ); - - $form['search_by_author'] = array( - '#type' => 'checkbox', + + $form['search_by'] = array( + '#type' => 'radios', '#default_value' => TRUE, - '#title' => t('Search by Author of the Book'), + '#title' => t('Search by'), + '#options' => array('title'=>t('Title'),'author'=>t('Author'),'contributor'=>t('Contributor')), ); $form['submit'] = array( @@ -29,7 +24,6 @@ function textbook_companion_search_form($form,&$form_state) 'callback' => 'textbook_companion_search_ajax_callback', ), ); - $form['cancel'] = array( '#type' => 'item', '#markup' => l(t('Cancel'), ''), @@ -45,17 +39,19 @@ function textbook_companion_search_form($form,&$form_state) return $form; } function textbook_companion_search_ajax_callback($form,$form_state){ - if ($form_state['values']['search_by_title'] && $form_state['values']['search_by_author']){ + if ($form_state['values']['search_by'] == 'title' ){ - $search_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE approval_status = 1 AND (book LIKE :book OR author LIKE :author)", array(':book' => '%%'.$form_state['values']['search'].'%%',':author' =>'%%'.$form_state['values']['search'].'%%')); + $search_q = db_query("SELECT pe.id AS pref_id, po.full_name, pe.book as book, pe.author as author, pe.publisher as publisher, pe.year as year, pe.id as pe_id, po.approval_date as approval_date + FROM textbook_companion_preference pe LEFT JOIN textbook_companion_proposal po ON pe.proposal_id = po.id + WHERE po.proposal_status = 3 AND pe.approval_status = 1 AND book LIKE :book ORDER BY pe.book ASC", array(":book" => '%%'.trim($form_state['values']['search']).'%%')); while ($search_data = $search_q->fetchObject()) { - $search_rows[] = array(l($search_data->book, 'textbook_run/' . $search_data->id), $search_data->author); + $search_rows[] = array(l($search_data->book, 'textbook_run/' . $search_data->pref_id), $search_data->author, $search_data->full_name); } if ($search_rows) { - $search_header = array('Title of the Book', 'Author Name'); + $search_header = array('Title of the Book', 'Author Name', 'Contributor'); $output .= theme('table',array('header'=>$search_header, 'rows'=>$search_rows)); $form['search_results']['#markup'] = $output; $form['search_results']['#title'] = t('Search results for "') . $_POST['search'] . '"'; @@ -66,35 +62,57 @@ while ($search_data = $search_q->fetchObject()) } - }elseif ($form_state['values']['search_by_title']){ - - $search_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE approval_status = 1 AND book LIKE :search",array(':search' => '%%'.$form_state['values']['search'].'%%')); - - }else if ($form_state['values']['search_by_author']){ - - $search_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE approval_status = 1 AND author LIKE :search",array(':search' => '%%'.$form_state['values']['search'].'%%')); - -} -/*while ($search_data = $search_q->fetchObject()) + }elseif ($form_state['values']['search_by'] =='author'){ + + $search_q = db_query("SELECT pe.id AS pref_id, po.full_name, pe.book as book, pe.author as author, pe.publisher as publisher, pe.year as year, pe.id as pe_id, po.approval_date as approval_date + FROM textbook_companion_preference pe LEFT JOIN textbook_companion_proposal po ON pe.proposal_id = po.id + WHERE po.proposal_status = 3 AND pe.approval_status = 1 AND author LIKE :author ORDER BY pe.author ASC", array(":author" => '%%'.trim($form_state['values']['search']).'%%')); +while ($search_data = $search_q->fetchObject()) { - $search_rows[] = array(l($search_data->book, 'textbook_run/' . $search_data->id), $search_data->author); + $search_rows[] = array($search_data->author,l($search_data->book, 'textbook_run/' . $search_data->pref_id), $search_data->full_name); } if ($search_rows) { - $search_header = array('Title of the Book', 'Author Name'); + $search_header = array('Author Name', 'Title of the Book', 'Contributor'); $output .= theme('table',array('header'=>$search_header, 'rows'=>$search_rows)); - $form_state['search_result'] = $output; + $form['search_results']['#markup'] = $output; + $form['search_results']['#title'] = t('Search results for "') . $_POST['search'] . '"'; + } else{ - $form_state['search_result'] = 'not available'; + $form['search_results']['#title'] = t('Search results for "') . $_POST['search'] . '" is not available'; + + } + + }else if ($form_state['values']['search_by']== 'contributor'){ + + $search_q = db_query("SELECT pe.id AS pref_id, po.full_name, pe.book as book, pe.author as author, pe.publisher as publisher, pe.year as year, pe.id as pe_id, po.approval_date as approval_date + FROM textbook_companion_preference pe LEFT JOIN textbook_companion_proposal po ON pe.proposal_id = po.id + WHERE po.proposal_status = 3 AND pe.approval_status = 1 AND po.full_name LIKE :contributor ORDER BY po.full_name ASC", array(":contributor" => '%%'.trim($form_state['values']['search']).'%%')); +while ($search_data = $search_q->fetchObject()) + { + $search_rows[] = array($search_data->full_name, l($search_data->book, 'textbook_run/' . $search_data->pref_id), $search_data->author); + } - }*/ + if ($search_rows) + { + $search_header = array('Contributor', 'Title of the Book', 'Author Name'); + $output .= theme('table',array('header'=>$search_header, 'rows'=>$search_rows)); + $form['search_results']['#markup'] = $output; + $form['search_results']['#title'] = t('Search results for "') . $_POST['search'] . '"'; + } + else{ + $form['search_results']['#title'] = t('Search results for "') . $_POST['search'] . '" is not available'; + + } +} $commands[] = ajax_command_replace("#search-result", drupal_render($form['search_results'])); return array('#type' => 'ajax', '#commands' => $commands); } + function textbook_search_display($search_q){ while ($search_data = $search_q->fetchObject()) { @@ -268,17 +286,17 @@ function _list_of_colleges() { $college_names = array('0' => '--- select ---'); - /*$college_names_q = db_query("SELECT DISTINCT university FROM {textbook_companion_proposal} WHERE proposal_status=1 OR proposal_status=3 ORDER BY university ASC");*/ + $college_names_q = db_query("SELECT DISTINCT university FROM {textbook_companion_proposal} WHERE proposal_status=1 OR proposal_status=3 ORDER BY university ASC"); - $query = db_select('textbook_companion_proposal'); + /*$query = db_select('textbook_companion_proposal'); $query =distinct(); $query->fields('university', array('')); $or = db_or(); $or->condition('proposal_status', 1); $or->condition('proposal_status', 3); $query->condition($or); - $query->orderBy('university', 'ASC'); - $college_names_q = $query->execute(); + $query->orderBy('university', 'ASC');*/ + $college_names_q = $college_names_q->execute(); while ($college_names_data = $college_names_q->fetchObject()) { @@ -320,10 +338,10 @@ function _list_books_by_college($college) { return $output; } -function textbook_companion_browse_college_form($form_state) { +function textbook_companion_browse_college_form($form, $form_state) { $form = array(); - ahah_helper_register($form, $form_state); + //ahah_helper_register($form, $form_state); if (!isset($form_state['storage']['college_info']['college'])) { @@ -344,11 +362,11 @@ function textbook_companion_browse_college_form($form_state) { '#title' => t('College Name'), '#options' => _list_of_colleges(), '#default_value' => $usage_default_value, - '#ahah' => array( + /* '#ahah' => array( 'event' => 'change', 'path' => ahah_helper_path(array('college_info')), 'wrapper' => 'college-info-wrapper', - ), + ),*/ ); diff --git a/settings.inc b/settings.inc index 16d1126..865a549 100755 --- a/settings.inc +++ b/settings.inc @@ -30,7 +30,15 @@ function textbook_companion_settings_form($form_state) '#required' => TRUE, '#default_value' => variable_get('textbook_companion_emails_all', ''), ); - +$form['cc_emails'] = array( + '#type' => 'textfield', + '#title' => t('(Cc) Notification emails'), + '#description' => t('Specify emails id for Cc option of mail system with comma separated'), + '#size' => 50, + '#maxlength' => 255, + '#required' => TRUE, + '#default_value' => variable_get('textbook_companion_cc_emails', ''), + ); $form['from_email'] = array( '#type' => 'textfield', '#title' => t('Outgoing from email address'), @@ -50,6 +58,15 @@ function textbook_companion_settings_form($form_state) '#required' => TRUE, '#default_value' => variable_get('textbook_companion_source_extensions', ''), ); + $form['extensions']['sample_source_file'] = array( + '#type' => 'textfield', + '#title' => t('Allowed sample source file extensions'), + '#description' => t('A comma separated list WITHOUT SPACE of source file extensions that are permitted to be uploaded on the server'), + '#size' => 50, + '#maxlength' => 255, + '#required' => TRUE, + '#default_value' => variable_get('textbook_companion_sample_source_file_extensions', ''), + ); $form['extensions']['dependency'] = array( '#type' => 'textfield', '#title' => t('Allowed dependency file extensions'), @@ -93,10 +110,12 @@ function textbook_companion_settings_form_validate($form, &$form_state) function textbook_companion_settings_form_submit($form, &$form_state) { variable_set('textbook_companion_emails', $form_state['values']['emails']); + variable_set('textbook_companion_cc_emails', $form_state['values']['cc_emails']); variable_set('textbook_companion_emails_fail_rem_bcc', $form_state['values']['bcc_emails_rem']); variable_set('textbook_companion_emails_all', $form_state['values']['to_emails']); variable_set('textbook_companion_from_email', $form_state['values']['from_email']); variable_set('textbook_companion_source_extensions', $form_state['values']['source']); + variable_set('textbook_companion_sample_source_file_extensions', $form_state['values']['sample_source_file']); variable_set('textbook_companion_dependency_extensions', $form_state['values']['dependency']); variable_set('textbook_companion_result_extensions', $form_state['values']['result']); variable_set('textbook_companion_xcos_extensions', $form_state['values']['xcos']); diff --git a/textbook_companion.module b/textbook_companion.module index fb93f01..bdeb5d8 100755 --- a/textbook_companion.module +++ b/textbook_companion.module @@ -283,53 +283,6 @@ function textbook_companion_menu() 'file' => 'search.inc', 'weight' => 1, ); - $items['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_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_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_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_run'] = array( 'title' => 'Download Codes', @@ -340,19 +293,6 @@ function textbook_companion_menu() '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['download_codes'] = array( 'title' => 'Download Codes', 'page callback' => 'drupal_get_form', @@ -371,6 +311,14 @@ function textbook_companion_menu() 'type' => MENU_CALLBACK, 'file' => 'download.inc', ); + $items['download/samplecode'] = array( + 'title' => 'Sample Code Download', + 'description' => 'Sample Code Download', + 'page callback' => 'textbook_companion_download_sample_code', + 'access arguments' => array('download code'), + 'type' => MENU_CALLBACK, + 'file' => 'download.inc', + ); $items['download/dependency'] = array( 'title' => 'Code Download', 'description' => 'Code Download', @@ -571,7 +519,7 @@ function textbook_companion_menu() } /** - * Implementation of hook_perm(). + * Implementation of hook_permission(). */ function textbook_companion_permission() { @@ -670,23 +618,8 @@ return array( } /* Aicte books pickup before the proposal form */ -function textbook_companion_aicte_proposal_form($form_state) { - /* $query = " - SELECT * FROM textbook_companion_aicte - WHERE status = 0 AND selected = 0 - "; - $result = db_query($query);*/ - - /* $query = " - SELECT * FROM textbook_companion_aicte - WHERE status = :status AND selected = :selected - "; - $args = array( - ':status' => 0, - ':selected' => 0, - ); - $result = db_query($query,$args); */ - +function textbook_companion_aicte_proposal_form($form,&$form_state) { + /*********** fetch aicte book data ********************/ $query = db_select('textbook_companion_aicte'); $query->fields('textbook_companion_aicte'); $query->condition('status', 0); @@ -699,8 +632,8 @@ function textbook_companion_aicte_proposal_form($form_state) { "#prefix" => "<div id='aicte-form-wrapper'>", "#suffix" => "</div>", ); - // $num_rows = mysql_num_rows($result); - $num_rows = $query->countQuery(); + + $num_rows = $result->rowCount(); if ($num_rows > 0) { while($row = $result->fetchObject()) { /* fixing title string */ @@ -737,11 +670,7 @@ function textbook_companion_aicte_proposal_form($form_state) { } function textbook_companion_aicte_proposal_form_validate($form, &$form_state) { - /*$query = " - SELECT * FROM textbook_companion_aicte - WHERE status = 0 AND selected = 0 - "; - $result = db_query($query);*/ + $query = db_select('textbook_companion_aicte'); $query->fields('textbook_companion_aicte'); @@ -765,22 +694,18 @@ function textbook_companion_aicte_proposal_form_validate($form, &$form_state) { } } +/* AICTE Book list proposal form submit */ function textbook_companion_aicte_proposal_form_submit($form, &$form_state) { global $user; $selections = $form_state["values"]["selections"]; - var_dump($selections); + //var_dump($selections); variable_set("aicte_".$user->uid, $selections); drupal_goto("proposal"); } -function textbook_companion_aicte_report_form($form_state) { - /*$query = " - SELECT * FROM textbook_companion_aicte - WHERE status = 0 - ORDER BY book - "; - $result = db_query($query);*/ - +/************* AICTE book report form **************/ +function textbook_companion_aicte_report_form($from, $form_state) { + $query = db_select('textbook_companion_aicte'); $query->fields('textbook_companion_aicte'); $query->condition('status', 0); @@ -825,19 +750,9 @@ function textbook_companion_aicte_report_form($form_state) { ); return $form; } - +/************* AICTE book report form submit **************/ function textbook_companion_aicte_report_form_submit($form, &$form_state) { $v = $form_state["values"]; - - /*$query = " - INSERT INTO textbook_companion_aicte_report - (aicte_id, name, number, email, comment) - VALUES - (%d, '%s', '%s', '%s', '%s') - "; - $result = db_query($query, - $v["book"], $v["name"], $v["number"], $v["email"], $v["comment"] - );*/ $query = "INSERT INTO textbook_companion_aicte_report (aicte_id, name, number, email, comment) @@ -853,19 +768,15 @@ function textbook_companion_aicte_report_form_submit($form, &$form_state) { drupal_set_message("Thank you for reporting.", "status"); } - +/************* AICTE book list selection **************/ function textbook_companion_aicte_proposal_all() { global $user; - $page_content = ""; +$page_content = ""; + - if (!$user->uid) { - /*$query = " - SELECT * FROM textbook_companion_aicte - WHERE status = 0 - "; - $result = db_query($query);*/ + if (!$user->uid) { - $query = db_select('textbook_companion_aicte'); + $query = db_select('textbook_companion_aicte'); $query->fields('textbook_companion_aicte'); $query->condition('status', 0); $result = $query->execute(); @@ -876,7 +787,7 @@ function textbook_companion_aicte_proposal_all() { //$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 .= "Search : <input type='text' id='searchtext' onkeyup='searchbookFunction()' style='width:82%'/>"; $page_content .= "<input type='button' value ='clear' id='search_clear'/>"; $page_content .= "<div id='aicte-list-wrapper'>"; $num_rows = $result->rowCount(); @@ -913,8 +824,6 @@ function textbook_companion_aicte_proposal_all() { /* check if user has already submitted a proposal */ - /* $proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE uid = %d ORDER BY id DESC LIMIT 1", $user->uid);*/ - $query = db_select('textbook_companion_proposal'); $query->fields('textbook_companion_proposal'); $query->condition('uid', $user->uid); @@ -956,12 +865,11 @@ function textbook_companion_aicte_proposal_all() { //$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 */ +/*************** non aicte book proposal *******************/ function textbook_companion_nonaicte_proposal_all() { global $user; $page_content = ""; @@ -1029,9 +937,9 @@ function textbook_companion_proposal_all() { // return; // } - /* check if user has already submitted a proposal */ + /************* 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'); @@ -1070,12 +978,6 @@ function textbook_companion_proposal_all() { $selections = variable_get("aicte_".$user->uid, ""); if($selections) { - - /*$query = " - SELECT * FROM textbook_companion_aicte - WHERE id IN ({$selections}) - "; - $result = db_query($query);*/ $query = db_select('textbook_companion_aicte'); $query->fields('textbook_companion_aicte'); @@ -1143,7 +1045,7 @@ function book_proposal_form($form,&$form_state, $row1=NULL, $row2=NULL, $row3=NU '#required' => TRUE, ); - $form['how_project'] = array( + /*$form['how_project'] = array( '#type' => 'select', '#title' => t('How did you come to know about this project'), '#options' => array('Scilab Website' => 'Scilab Website', @@ -1153,7 +1055,7 @@ function book_proposal_form($form,&$form_state, $row1=NULL, $row2=NULL, $row3=NU 'Poster in my/other college' => 'Poster in my/other college', 'Others' => 'Others'), '#required' => TRUE, - ); + );*/ $form['course'] = array( '#type' => 'textfield', '#title' => t('Course'), @@ -1164,18 +1066,7 @@ function book_proposal_form($form,&$form_state, $row1=NULL, $row2=NULL, $row3=NU $form['branch'] = array( '#type' => 'select', '#title' => t('Department/Branch'), - '#options' => array('Electrical Engineering' => 'Electrical Engineering', - 'Electronics Engineering' => 'Electronics Engineering', - 'Computer Engineering' => 'Computer Engineering', - 'Chemical Engineering' => 'Chemical Engineering', - 'Instrumentation Engineering' => 'Instrumentation Engineering', - 'Mechanical Engineering' => 'Mechanical Engineering', - 'Civil Engineering' => 'Civil Engineering', - 'Physics' => 'Physics', - 'Applied Physics' =>'Applied Physics', - ' Nuclear Technology and Biotechnology' => ' Nuclear Technology and Biotechnology', - 'Mathematics' => 'Mathematics', - 'Others' => 'Others'), + '#options' => _tbc_list_of_departments(), '#required' => TRUE, ); $form['university'] = array( @@ -1185,6 +1076,79 @@ function book_proposal_form($form,&$form_state, $row1=NULL, $row2=NULL, $row3=NU '#maxlength' => 50, '#required' => TRUE, ); + $form['country'] = array( + '#type' => 'select', + '#title' => t('Country'), + '#options' => array( + 'India' => 'India', + 'Others' => 'Others', + ), + '#required' => TRUE, + '#tree' => TRUE, + '#validated' => TRUE, + ); + $form['other_country'] = array( + '#type' => 'textfield', + '#title' => t('Other than India'), + '#size' => 100, + '#attributes' =>array('placeholder' => t('Enter your country name')), + '#states' => array( + 'visible' => array( + ':input[name="country"]' => array('value' => 'Others'), + ), + ), + ); + $form['other_state'] = array( + '#type' => 'textfield', + '#title' => t('State other than India'), + '#size' => 100, + '#attributes' =>array('placeholder' => t('Enter your state/region name')), + '#states' => array( + 'visible' => array( + ':input[name="country"]' => array('value' => 'Others'), + ), + ), + ); + $form['other_city'] = array( + '#type' => 'textfield', + '#title' => t('City other than India'), + '#size' => 100, + '#attributes' =>array('placeholder' => t('Enter your city name')), + '#states' => array( + 'visible' => array( + ':input[name="country"]' => array('value' => 'Others'), + ), + ), + ); + $form['all_state'] = array( + '#type' => 'select', + '#title' => t('State'), + '#options' => _tbc_list_of_states(), + '#validated' => TRUE, + '#states' => array( + 'visible' => array( + ':input[name="country"]' => array('value' => 'India'), + ), + ), + ); + $form['city'] = array( + '#type' => 'select', + '#title' => t('City'), + '#options' => _tbc_list_of_cities(), + '#states' => array( + 'visible' => array( + ':input[name="country"]' => array('value' => 'India'), + ), + ), + ); + $form['pincode'] = array( + '#type' => 'textfield', + '#title' => t('Pincode'), + '#size' => 30, + '#maxlength' => 6, + '#required' => False, + '#attributes' =>array('placeholder' =>'Enter pincode....'), + ); $form['faculty'] = array( '#type' => 'hidden', '#value' => 'None', @@ -1208,21 +1172,7 @@ function book_proposal_form($form,&$form_state, $row1=NULL, $row2=NULL, $row3=NU '#size' => 30, '#maxlength' => 50, ); - $form['version'] = array( - '#type' => 'select', - '#title' => t('Version'), - '#options' => array('scilab 5.4.1' => 'Scilab 5.4.1', - 'scilab 5.3.3' => 'Scilab 5.3.3', - 'olderversion' => 'Older 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'), @@ -1237,13 +1187,14 @@ function book_proposal_form($form,&$form_state, $row1=NULL, $row2=NULL, $row3=NU '#size' => 30, '#maxlength' => 50, ); - /*$form['scilab_version'] = array( + $form['version'] = array( '#type' => 'textfield', '#title' => t('Scilab Version'), - '#required' => TRUE, + '#description' => t('Input version format should be like 5.4 or 5.4.1'), '#size' => 10, - '#maxlength' => 10, - );*/ + '#required' => TRUE, + '#maxlength' => 20, + ); $form['preference1'] = array( '#type' => 'fieldset', '#title' => t('Book Preference 1'), @@ -1301,6 +1252,12 @@ function book_proposal_form($form,&$form_state, $row1=NULL, $row2=NULL, $row3=NU '#required' => TRUE, '#default_value' => $row1->year, ); + $form['preference1']['book_category_1'] = array( + '#type' => 'select', + '#title' => t('Category'), + '#options' => _tbc_list_of_category(), + '#required' => TRUE, + ); $form['preference2'] = array( '#type' => 'fieldset', '#title' => t('Book Preference 2'), @@ -1358,6 +1315,12 @@ function book_proposal_form($form,&$form_state, $row1=NULL, $row2=NULL, $row3=NU '#required' => TRUE, '#default_value' => $row2->year, ); + $form['preference2']['book_category_2'] = array( + '#type' => 'select', + '#title' => t('Category'), + '#options' => _tbc_list_of_category(), + '#required' => TRUE, + ); $form['preference3'] = array( '#type' => 'fieldset', '#title' => t('Book Preference 3'), @@ -1415,11 +1378,31 @@ function book_proposal_form($form,&$form_state, $row1=NULL, $row2=NULL, $row3=NU '#required' => TRUE, '#default_value' => $row3->year, ); + $form['preference3']['book_category_3'] = array( + '#type' => 'select', + '#title' => t('Category'), + '#options' => _tbc_list_of_category(), + '#required' => TRUE, + ); + $form['samplefile'] = array( + '#type' => 'fieldset', + '#title' => t('<span class="form-required form-item" title="This field is required.">Sample Source Files *</span>'), + '#collapsible' => FALSE, + '#collapsed' => FALSE, + ); + $form['samplefile']['samplefile1'] = array( + '#type' => 'file', + '#title' => t('Upload sample source file'), + '#size' => 48, + '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' . + t('<span style="color:red;">Allowed file extensions : ') . variable_get('textbook_companion_sample_source_file_extensions', '').'</span>', + + ); $form['termconditions'] = array( '#type' => 'checkboxes', '#title' => t('Terms And Conditions'), '#options' => array( - 'status' => t('<a href="term-and-conditions" target="_blank">I agree to the Terms and Conditions</a>'),), + 'status' => t('<a href="/term-and-conditions" target="_blank">I agree to the Terms and Conditions</a>'),), '#required' => TRUE, ); $form['submit'] = array( @@ -1427,17 +1410,9 @@ function book_proposal_form($form,&$form_state, $row1=NULL, $row2=NULL, $row3=NU '#value' => t('Submit') ); - /* #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; } - +/******************** AICTE book proposal from validate *****************************/ function book_proposal_form_validate($form,&$form_state) { @@ -1488,12 +1463,85 @@ function book_proposal_form_validate($form,&$form_state) form_set_error('isbn2', t('Invalid ISBN for Book Preference 2')); if (!preg_match('/^[0-9\-xX]+$/', $form_state['values']['isbn3'])) form_set_error('isbn3', t('Invalid ISBN for Book Preference 3')); +/* version */ + if (!preg_match('/^\d+(?:\.\d+)+/', $form_state['values']['version'])) + form_set_error('version', t('Please enter correct version in given format')); + /* country */ + if($form_state['values']['country']=='Others'){ + if($form_state['values']['other_country']== ''){ + form_set_error('other_country', t('Enter country name')); + }else{ + $form_state['values']['country'] = $form_state['values']['other_country']; + } + if($form_state['values']['other_state']== ''){ + form_set_error('other_state', t('Enter state name')); + }else{ + $form_state['values']['all_state'] = $form_state['values']['other_state']; + } + if($form_state['values']['other_city']== ''){ + form_set_error('other_city', t('Enter city name')); + }else{ + $form_state['values']['city'] = $form_state['values']['other_city']; + } + }else{ + if($form_state['values']['country']== ''){ + form_set_error('country', t('Select country name')); + } + if($form_state['values']['all_state']== ''){ + form_set_error('all_state', t('Select state name')); + } + if($form_state['values']['city']== ''){ + form_set_error('city', t('Select city name')); + } + + + } + + + if (isset($_FILES['files'])) + { + /* check if atleast one source or result file is uploaded */ + if ( ! ($_FILES['files']['name']['samplefile1'])) + form_set_error('samplefile1', t('Please upload sample code main or source file.')); - if($form_state['values']['version'] == 'olderversion'){ - if($form_state['values']['older'] == ''){ - form_set_error('older', t('Please provide valid version')); - } - } + /* check for valid filename extensions */ + foreach ($_FILES['files']['name'] as $file_form_name => $file_name) + { + if ($file_name) + { + /* checking file type */ + if (strstr($file_form_name, 'sample')) + $file_type = 'S'; + + else + $file_type = 'U'; + + $allowed_extensions_str = ''; + switch ($file_type) + { + case 'S': + $allowed_extensions_str = variable_get('textbook_companion_sample_source_file_extensions', ''); + break; + + } + $allowed_extensions = explode(',' , $allowed_extensions_str); + $allowd_file = strtolower($_FILES['files']['name'][$file_form_name]); + $allowd_files = explode('.', $allowd_file); + $temp_extension = end($allowd_files); + if (!in_array($temp_extension, $allowed_extensions)) + form_set_error($file_form_name, t('Only file with ' . $allowed_extensions_str . ' extensions can be uploaded.')); + if ($_FILES['files']['size'][$file_form_name] <= 0) + form_set_error($file_form_name, t('File size cannot be zero.')); + + /* check if valid file name */ + if (!textbook_companion_check_valid_filename($_FILES['files']['name'][$file_form_name])) + form_set_error($file_form_name, t('Invalid file name specified. Only alphabets and numbers are allowed as a valid filename.')); + + + } + } + } + return; } @@ -1502,6 +1550,7 @@ function book_proposal_form_submit($form, &$form_state) global $user; $selections = variable_get("aicte_".$user->uid, ""); + $root_path =textbook_companion_samplecode_path(); if (!$user->uid) { drupal_set_message('It is mandatory to login on this website to access the proposal form', 'error'); @@ -1510,37 +1559,27 @@ function book_proposal_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); - + $completion_date_timestamp = mktime(0, 0, 0, $m, $d, $y); + $scilab_version = 'scilab ' . $form_state['values']['version']; - $scilab_version = $form_state['values']['version']; - - if($form_state['values']['version'] == 'olderversion'){ - $scilab_version = $form_state['values']['older']; - } - - //var_dump($form_state['values']); -var_dump('okk'); - /*$query = "INSERT INTO {textbook_companion_proposal} - (uid, approver_uid, full_name, mobile, gender, how_project, course, branch, university, faculty, reviewer, completion_date, creation_date, approval_date, proposal_status, scilab_version, operating_system, teacher_email) VALUES (".$user->uid.", 0, '".ucwords(strtolower($form_state['values']['full_name']))."', '".$form_state['values']['mobile']."', '".$form_state['values']['gender']."', '".$form_state['values']['how_project']."', '".$form_state['values']['course']."', '".$form_state['values']['branch']."', '".$form_state['values']['university']."', '".ucwords(strtolower($form_state['values']['faculty']))."', '".ucwords(strtolower($form_state['values']['reviewer']))."', '".$completion_date_timestamp."', '".time()."', 0, 0, '".$scilab_version."', '".$form_state['values']['operating_system']."', '".$form_state['values']['faculty_email']."')"; - - $result = db_query($query);*/ - - $query = "INSERT INTO {textbook_companion_proposal} - (uid, approver_uid, full_name, mobile, gender, how_project, course, branch, university, faculty, reviewer, completion_date, creation_date, approval_date, proposal_status, scilab_version, operating_system, teacher_email, message) VALUES (:uid, :approver_uid, :full_name, :mobile, :gender, :how_project, :course, :branch, :university, :faculty, :reviewer, :completion_date, + (uid, approver_uid, full_name, mobile, gender, how_project, course, branch, university, country, city, pincode, state, faculty, reviewer, completion_date, creation_date, approval_date, proposal_status, scilab_version, operating_system, teacher_email, message, samplefilepath) VALUES (:uid, :approver_uid, :full_name, :mobile, :gender, :how_project, :course, :branch, :university, :country, :city, :pincode, :state, :faculty, :reviewer, :completion_date, :creation_date, :approval_date, :proposal_status, :scilab_version, :operating_system, -:teacher_email, :message)"; +:teacher_email, :message, :samplefilepath)"; $args = array( ":uid" => $user->uid, ":approver_uid" => 0, ":full_name" => ucwords(strtolower($form_state['values']['full_name'])), ":mobile" =>$form_state['values']['mobile'], ":gender" => $form_state['values']['gender'], - ":how_project" => $form_state['values']['how_project'], + ":how_project" => 'Not available', ":course" => $form_state['values']['course'], ":branch" => $form_state['values']['branch'], ":university" => $form_state['values']['university'], + ":country" => $form_state['values']['country'], + ":city"=> $form_state['values']['city'], + ":pincode"=> $form_state['values']['pincode'], + ":state"=> $form_state['values']['all_state'], ":faculty" => ucwords(strtolower($form_state['values']['faculty'])), ":reviewer" => ucwords(strtolower($form_state['values']['reviewer'])), ":completion_date" => $completion_date_timestamp, @@ -1551,10 +1590,43 @@ $args = array( ":operating_system" => $form_state['values']['operating_system'], ":teacher_email" => $form_state['values']['faculty_email'], ":message" => 'None', + ":samplefilepath"=>"" ); $result = db_query($query, $args, array('return' => Database::RETURN_INSERT_ID)); + $dest_path = $result . '/'; + if (!is_dir($root_path . $dest_path)) + mkdir($root_path . $dest_path); + /* uploading files */ + foreach ($_FILES['files']['name'] as $file_form_name => $file_name) + { + if ($file_name) + { + /* checking file type */ + $file_type = 'S'; + if (file_exists($root_path . $dest_path . $_FILES['files']['name'][$file_form_name])) + { + drupal_set_message(t("Error uploading file. File !filename already exists.", array('!filename' => $_FILES['files']['name'][$file_form_name])), 'error'); + return; + } + + /* uploading file */ + if (move_uploaded_file($_FILES['files']['tmp_name'][$file_form_name], $root_path . $dest_path . $_FILES['files']['name'][$file_form_name])) + { + $query = "UPDATE {textbook_companion_proposal} SET samplefilepath = :samplefilepath WHERE id = :id"; + $args = array( + ":samplefilepath" => $dest_path . $_FILES['files']['name'][$file_form_name], + ":id" =>$result, + ); + $updateresult = db_query($query, $args); + + drupal_set_message($file_name . ' uploaded successfully.', 'status'); + } else { + drupal_set_message('Error uploading file : ' . $dest_path . '/' . $file_name, 'error'); + } + } + } if (!$result) { @@ -1568,21 +1640,7 @@ $args = array( /* 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 - );*/ - + $query = "INSERT INTO {textbook_companion_preference} (proposal_id, pref_number, book, author, isbn, publisher, edition, year, category, approval_status) VALUES (:proposal_id, :pref_number, :book, :author, :isbn, :publisher, :edition, :year, :category, :approval_status) "; @@ -1596,7 +1654,7 @@ $args = array( ":publisher" => ucwords(strtolower($form_state['values']['publisher1'])), ":edition" => $form_state['values']['edition1'], ":year" => $form_state['values']['year1'], - ":category" => 0, + ":category"=> $form_state['values']['book_category_1'], ":approval_status" => 0, ); $result = db_query($query, $args, array('return' => Database::RETURN_INSERT_ID)); @@ -1659,7 +1717,7 @@ $args = array( ":publisher" => ucwords(strtolower($form_state['values']['publisher2'])), ":edition" => $form_state['values']['edition2'], ":year" => $form_state['values']['year2'], - ":category" => 0, + ":category"=> $form_state['values']['book_category_2'], ":approval_status" => 0 ); $result = db_query($query, $args, array('return' => Database::RETURN_INSERT_ID)); @@ -1690,21 +1748,7 @@ $args = array( /* inserting third book preference */ 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, - 3, - ucwords(strtolower($form_state['values']['book3'])), - ucwords(strtolower($form_state['values']['author3'])), - $form_state['values']['isbn3'], - ucwords(strtolower($form_state['values']['publisher3'])), - $form_state['values']['edition3'], - $form_state['values']['year3'], - 0, - 0 - );*/ - + $query = "INSERT INTO {textbook_companion_preference} (proposal_id, pref_number, book, author, isbn, publisher, edition, year, category, approval_status) VALUES (:proposal_id, :pref_number, :book, :author, :isbn, :publisher, :edition, :year, :category, :approval_status) "; @@ -1718,7 +1762,7 @@ $args = array( ":publisher" => ucwords(strtolower($form_state['values']['publisher3'])), ":edition" => $form_state['values']['edition3'], ":year" => $form_state['values']['year3'], - ":category" => 0, + ":category"=> $form_state['values']['book_category_3'], ":approval_status" => 0 ); $result = db_query($query, $args, array('return' => Database::RETURN_INSERT_ID)); @@ -1771,11 +1815,20 @@ $args = array( } } - /* sending email */ + /* 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', 'proposal_received', $email_to , language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE)) + $from = variable_get('textbook_companion_from_email', ''); + $bcc = variable_get('textbook_companion_emails', ''); + $cc = variable_get('textbook_companion_cc_emails', ''); + + $params['proposal_received']['proposal_id'] = $proposal_id; + $params['proposal_received']['user_id'] = $user->uid; + $params['proposal_received']['headers']=array('From'=>$from,'MIME-Version'=> '1.0', + 'Content-Type'=> 'text/plain; charset=UTF-8; format=flowed; delsp=yes', + 'Content-Transfer-Encoding' => '8Bit', + 'X-Mailer'=> 'Drupal','Cc' => $cc, 'Bcc' => $bcc); + + if (!drupal_mail('textbook_companion', 'proposal_received', $email_to , language_default(), $params, $from, TRUE)) drupal_set_message('Error sending email message.', 'error'); drupal_set_message(t('We have received you book proposal. We will get back to you soon.'), 'status'); @@ -1788,16 +1841,16 @@ $args = array( function textbook_companion_mail($key, &$message, $params) { global $user; - $language = $message['lianguage']; - $tbc_bcc_emails = array( + $language = $message['language']; + /*$tbc_bcc_emails = array( 'Bcc' => variable_get('textbook_companion_emails', ''), - ); + );*/ switch ($key) { case 'proposal_received': // bcc to textbook_companion_emails - $message['headers'] += $tbc_bcc_emails; + //$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']); @@ -1809,41 +1862,63 @@ function textbook_companion_mail($key, &$message, $params) $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 = " + SELECT * FROM list_of_category loc + JOIN textbook_companion_preference tcp ON loc.category_id = tcp.category + WHERE proposal_id = :proposal_id AND pref_number = :pref_number LIMIT 1 + "; + $args = array( + ':proposal_id' => $params['proposal_received']['proposal_id'], + ':pref_number' => 1, + ); + $preference1_q = db_query($query,$args); + $preference1_data = $preference1_q->fetchObject(); /*$preference2_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $params['proposal_received']['proposal_id'], 2); $preference2_data = db_fetch_object($preference2_q);*/ - $query = db_select('textbook_companion_preference'); - $query->fields('textbook_companion_preference'); - $query->condition('proposal_id', $params['proposal_received']['proposal_id']); - $query->condition('pref_number',2); - $query->range(0, 1); - $result = $query->execute(); - $preference2_data =$result->fetchObject(); - - - /*$preference3_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $params['proposal_received']['proposal_id'], 3); - $preference3_data = db_fetch_object($preference3_q);*/ - - $query = db_select('textbook_companion_preference'); +$query = " + SELECT * FROM list_of_category loc + JOIN textbook_companion_preference tcp ON loc.category_id = tcp.category + WHERE proposal_id = :proposal_id AND pref_number = :pref_number LIMIT 1 + "; + $args = array( + ':proposal_id' => $params['proposal_received']['proposal_id'], + ':pref_number' => 2, + ); + $preference2_q = db_query($query,$args); + $preference2_data = $preference2_q->fetchObject(); + + + $query = " + SELECT * FROM list_of_category loc + JOIN textbook_companion_preference tcp ON loc.category_id = tcp.category + WHERE proposal_id = :proposal_id AND pref_number = :pref_number LIMIT 1 + "; + $args = array( + ':proposal_id' => $params['proposal_received']['proposal_id'], + ':pref_number' => 3, + ); + $preference3_q = db_query($query,$args); + $preference3_data = $preference3_q->fetchObject(); + + /*$query = db_select('textbook_companion_preference'); $query->fields('textbook_companion_preference'); $query->condition('proposal_id', $params['proposal_received']['proposal_id']); $query->condition('pref_number', 3); $query->range(0, 1); $result = $query->execute(); - $preference3_data =$result->fetchObject(); + $preference3_data =$result->fetchObject();*/ $user_data = user_load($params['proposal_received']['user_id']); @@ -1873,6 +1948,7 @@ ISBN No. : ' . $preference1_data->isbn . ' Publisher and Place : ' . $preference1_data->publisher . ' Edition : ' . $preference1_data->edition . ' Year of publication : ' . $preference1_data->year . ' +Category : ' . $preference1_data->category_name . ' Book Preference 2 :- Title of the book : ' . $preference2_data->book . ' @@ -1881,6 +1957,7 @@ ISBN No. : ' . $preference2_data->isbn . ' Publisher and Place : ' . $preference2_data->publisher . ' Edition : ' . $preference2_data->edition . ' Year of publication : ' . $preference2_data->year . ' +Category : ' . $preference2_data->category_name . ' Book Preference 3 :- Title of the book : ' . $preference3_data->book . ' @@ -1889,11 +1966,14 @@ ISBN No. : ' . $preference3_data->isbn . ' Publisher and Place : ' . $preference3_data->publisher . ' Edition : ' . $preference3_data->edition . ' Year of publication : ' . $preference3_data->year . ' +Category : ' . $preference3_data->category_name . ' + + +Uploaded Sample Code :'.$samplecodefilename.' + Your proposal is under review and you will soon receive an email from us regarding the same. -Note: -Send sample codes to textbook@scilab.in in a .zip or .tgz file. The sample codes should be sent utmost by the 3rd day of the proposal. The subject of the email containing sample code should be "New Book Proposal-Sample Codes-(Student Name)". -The book will not be alloted to you until we receive the sample codes. + Best Wishes, @@ -1902,7 +1982,7 @@ Best Wishes, case 'proposal_disapproved': // bcc to textbook_companion_emails - $message['headers'] += $tbc_bcc_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']); @@ -2041,7 +2121,7 @@ Best Wishes, /* Non AICTE Book Proposal */ case 'nonaicte_proposal_received': // bcc to textbook_companion_emails - $message['headers'] += $tbc_bcc_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']); @@ -2054,21 +2134,30 @@ Best Wishes, $result = $query->execute(); $proposal_data =$result->fetchObject(); - - /*$preference1_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $params['proposal_received']['proposal_id'], 1); - $preference1_data = db_fetch_object($preference1_q);*/ - - $query = db_select('textbook_companion_preference'); - $query->fields('textbook_companion_preference'); - $query->condition('proposal_id',$params['proposal_received']['proposal_id']); - $query->condition('pref_number', 1); - $query->range(0, 1); - $result = $query->execute(); - $preference1_data=$result->fetchObject(); + $samplecodefilename=""; + if(strlen($proposal_data->samplefilepath)>=5){ + $samplecodefilename=substr($proposal_data->samplefilepath, strrpos($proposal_data->samplefilepath, '/') + 1); + }else{ + $samplecodefilename="Not provided"; + } + $query = " + SELECT * FROM list_of_category loc + JOIN textbook_companion_preference tcp ON loc.category_id = tcp.category + WHERE proposal_id = :proposal_id AND pref_number = :pref_number LIMIT 1 + "; + $args = array( + ':proposal_id' => $params['proposal_received']['proposal_id'], + ':pref_number' => 1, + ); + $preference1_q = db_query($query,$args); + $preference1_data = $preference1_q->fetchObject(); + + + $user_data = user_load($params['proposal_received']['user_id']); - - $message['subject'] = t('[!site_name] Your book proposal has been received', array('!site_name' => variable_get('site_name', '')),array('language' => $language->language)); + $message['headers'] = $params['proposal_received']['headers']; + $message['subject'] = t('[!site_name] Your book proposal has been received', array('!site_name' => variable_get('site_name', '')),array('language' => $language->language)); $message['body'] =array('body' => t(' Dear !user_name, @@ -2093,24 +2182,19 @@ ISBN No. : ' . $preference1_data->isbn . ' Publisher and Place : ' . $preference1_data->publisher . ' Edition : ' . $preference1_data->edition . ' Year of publication : ' . $preference1_data->year . ' +Category : ' . $preference1_data->category_name . ' +Uploaded Sample Code :'.$samplecodefilename.' + Your proposal is under review and you will soon receive an email from us regarding the same. -Note: -Send sample codes to textbook@scilab.in in a .zip or .tgz file. The sample codes should be sent utmost by the 3rd day of the proposal. The subject of the email containing sample code should be "New Book Proposal-Sample Codes-(Student Name)". -The book will not be alloted to you until we receive the sample codes. Best Wishes, !site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), array('language' => $language->language))); break; case 'nonaicte_proposal_to_pi': - // bcc to textbook_companion_emails - $message['headers'] += $tbc_bcc_emails; - /* initializing data */ - - /*$proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d LIMIT 1", $params['proposal_received']['proposal_id']); - $proposal_data = db_fetch_object($proposal_q);*/ + /************ fetch proposal data ****************/ $query = db_select('textbook_companion_proposal'); $query->fields('textbook_companion_proposal'); @@ -2119,8 +2203,7 @@ case 'nonaicte_proposal_to_pi': $result = $query->execute(); $proposal_data=$result->fetchObject(); - /* $preference1_q = db_query("SELECT * FROM {textbook_companion_preference} WHERE proposal_id = %d AND pref_number = %d LIMIT 1", $params['proposal_received']['proposal_id'], 1); - $preference1_data = db_fetch_object($preference1_q);*/ + /************ fetch book preference data ****************/ $query = db_select('textbook_companion_preference'); $query->fields('textbook_companion_preference'); @@ -2130,9 +2213,10 @@ case 'nonaicte_proposal_to_pi': $result = $query->execute(); $preference1_data=$result->fetchObject(); - $user_data = user_load($params['proposal_received']['user_id']); - + $user_data = user_load($params['nonaicte_proposal_received']['user_id']); + $message['headers'] = $params['nonaicte_proposal_received']['headers']; $message['subject'] = t('[!site_name] New Non AICTE book suggestion has been received', array('!site_name' => variable_get('site_name', '')), array('language' => $language->language)); + /******************* Email Template for not aicte book suggestion **************************/ $message['body'] = array('body' => t(' Dear all, @@ -2154,10 +2238,10 @@ Publisher and Place : ' . $preference1_data->publisher . ' Edition : ' . $preference1_data->edition . ' Year of publication : ' . $preference1_data->year . ' -Reference :- '.$proposal_data->reference.' - -Please click here to provide your feedback: http://scilab.in/comments +Reference :- '.$proposal_data->reference +//Please click here to provide your feedback: http://scilab.in/comments +.' Best Wishes, @@ -2166,12 +2250,7 @@ Best Wishes, - case 'proposal_approved': - // bcc to textbook_companion_emails - $message['headers'] += $tbc_bcc_emails; - - /*$proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d LIMIT 1", $params['proposal_approved']['proposal_id']); - $proposal_data = db_fetch_object($proposal_q);*/ + case 'proposal_approved': $query = db_select('textbook_companion_proposal'); $query->fields('textbook_companion_proposal'); @@ -2181,9 +2260,6 @@ Best Wishes, $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']); @@ -2193,7 +2269,7 @@ Best Wishes, $approved_preference_data=$result->fetchObject(); $user_data = user_load($params['proposal_approved']['user_id']); - + $message['headers'] = $params['proposal_approved']['headers']; $message['subject'] = t('[!site_name] Your book proposal has been approved', array('!site_name' => variable_get('site_name', '')), array('language' => $language->language)); $message['body'] =array('body' => t(' Dear !user_name, @@ -2230,7 +2306,7 @@ Best Wishes, case 'proposal_completed': // bcc to textbook_companion_emails - $message['headers'] += $tbc_bcc_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);*/ @@ -2255,6 +2331,7 @@ Best Wishes, $user_data = user_load($params['proposal_completed']['user_id']); + $message['headers'] = $params['proposal_completed']['headers']; $message['subject'] = t('[!site_name] Congratulations for completion of the book.', array('!site_name' => variable_get('site_name', '')), array('language' => $language->language)); $message['body'] =array('body' => t(' @@ -2292,7 +2369,7 @@ Best Wishes, case 'example_uploaded': // bcc to textbook_companion_emails - $message['headers'] += $tbc_bcc_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);*/ @@ -2304,30 +2381,45 @@ Best Wishes, $result = $query->execute(); $example_data=$result->fetchObject(); - $user_data = user_load($params['example_uploaded']['user_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(); - $message['subject'] = t('[!site_name] You have uploaded example', array('!site_name' => variable_get('site_name', '')), array('language' => $language->language)); + $query = db_select('textbook_companion_preference'); + $query->fields('textbook_companion_preference'); + $query->condition('id', $chapter_data->preference_id); + $query->range(0, 1); + $result = $query->execute(); + $preference_data=$result->fetchObject(); + + $user_data = user_load($params['example_uploaded']['user_id']); + $message['headers'] = $params['example_uploaded']['headers']; + $message['subject'] = t('[!site_name] You have uploaded example for Textbook Companion', array('!site_name' => variable_get('site_name', '')), array('language' => $language->language)); $message['body'] =array('body' => t(' Dear !user_name, -You have uploaded the following example: +You have uploaded the following solution : +Title of the book : ' . $preference_data->book . ' +Title of the chapter : '. $chapter_data->name . ' Example number : ' . $example_data->number . ' Caption : ' . $example_data->caption . ' -The example is under review. You will be notified when it has been approved. - -Please ensure that ALL the codes have followed the naming convention and contain captions as described here. -The codes cannot be approved unless the convention is followed. +You shall be notified after the solution is reviewed Best Wishes, -!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), array('language' => $language->language))); +!site_name Team, +FOSSEE,IIT Bombay', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), array('language' => $language->language))); + break; case 'example_updated': // bcc to textbook_companion_emails - $message['headers'] += $tbc_bcc_emails; + //$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);*/ @@ -2339,14 +2431,30 @@ Best Wishes, $result = $query->execute(); $example_data=$result->fetchObject(); - $user_data = user_load($params['example_updated']['user_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(); + + $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(); - $message['subject'] = t('[!site_name] You have updated example', array('!site_name' => variable_get('site_name', '')), array('language' => $language->language)); + $user_data = user_load($params['example_updated']['user_id']); + $message['headers'] = $params['example_updated']['headers']; + $message['subject'] = t('[!site_name] You have updated example for Textbook Companion', array('!site_name' => variable_get('site_name', '')), array('language' => $language->language)); $message['body'] =array('body' => t(' Dear !user_name, You have updated the following example: +Title of the book : ' . $preference_data->book . ' +Title of the chapter : '. $chapter_data->name . ' Example number : ' . $example_data->number . ' Caption : ' . $example_data->caption . ' @@ -2354,7 +2462,9 @@ The example is still under review. You will be notified when it has been approve Best Wishes, -!site_name', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), array('language' => $language->language))); +!site_name Team, +FOSSEE,IIT Bombay', array('!site_name' => variable_get('site_name', ''), '!user_name' => $user_data->name), array('language' => $language->language))); + break; case 'example_updated_admin': @@ -2441,9 +2551,9 @@ Best Wishes, case 'example_deleted_user': // bcc to textbook_companion_emails - $message['headers'] += $tbc_bcc_emails; + // $message['headers'] += $tbc_bcc_emails; $user_data = user_load($params['example_deleted_user']['user_id']); - + $message['headers'] = $params['example_deleted_user']['headers']; $message['subject'] = t('[!site_name] User has deleted pending example', array('!site_name' => variable_get('site_name', '')), array('language' => $language->language)); $message['body'] =array('body' => t(' Dear !user_name, @@ -2462,8 +2572,9 @@ Best Wishes, case 'dependency_uploaded': // bcc to textbook_companion_emails - $message['headers'] += $tbc_bcc_emails; + //$message['headers'] += $tbc_bcc_emails; $user_data = user_load($params['dependency_uploaded']['user_id']); + $message['headers'] = $params['example_deleted_user']['headers']; $dependency_files = implode(',', $params['dependency_uploaded']['dependency_names']); $message['subject'] = t('[!site_name] You have uploaded dependency file', array('!site_name' => variable_get('site_name', '')), array('language' => $language->language)); @@ -2715,6 +2826,9 @@ function textbook_companion_path() { return $_SERVER['DOCUMENT_ROOT'] . base_path() . 'uploads/'; } +function textbook_companion_samplecode_path() { + return $_SERVER['DOCUMENT_ROOT'] . base_path() . 'tbc_sample_code/'; +} /****************************** DELETION FUNCTIONS ****************************/ function delete_example($example_id) @@ -2780,12 +2894,12 @@ function delete_example($example_id) /* sending email to admins */ $email_to = variable_get('textbook_companion_emails', ''); - $param['standard']['subject'] = "[ERROR] Error deleting example file"; - $param['standard']['body'] = array(0 =>"Error deleting example files by " . $user->uid . " at " . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . " : + $params['standard']['subject'] = "[ERROR] Error deleting example file"; + $params['standard']['body'] = array(0 =>"Error deleting example files by " . $user->uid . " at " . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . " : example id : " . $example_id . " file id : " . $examples_files_data->id . " file path : " . $examples_files_data->filepath); - if (!drupal_mail('textbook_companion', 'standard', $email_to, language_default(), $param, variable_get('textbook_companion_from_email', NULL), 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'); } else { /* deleting example files database entries */ @@ -2817,9 +2931,9 @@ function delete_example($example_id) /* sending email to admins */ $email_to = variable_get('textbook_companion_emails', ''); - $param['standard']['subject'] = "[ERROR] Error deleting folder"; - $param['standard']['body'] = array(0 => "Error deleting folder " . $dir_path . " by " . $user->uid . " at " . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); - if (!drupal_mail('textbook_companion', 'standard', $email_to, language_default(), $param, variable_get('textbook_companion_from_email', NULL), TRUE)) + $params['standard']['subject'] = "[ERROR] Error deleting folder"; + $params['standard']['body'] = array(0 => "Error deleting folder " . $dir_path . " by " . $user->uid . " at " . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); + if (!drupal_mail('textbook_companion', 'standard', $email_to, language_default(), $params, variable_get('textbook_companion_from_email', NULL), TRUE)) drupal_set_message('Error sending email message.', 'error'); return FALSE; @@ -2896,9 +3010,9 @@ function delete_chapter($chapter_id) /* 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)) + $params['standard']['subject'] = "[ERROR] Error deleting folder"; + $params['standard']['body'] = "Error deleting folder " . $dir_path; + if (!drupal_mail('textbook_companion', 'standard', $email_to, language_default(), $params, variable_get('textbook_companion_from_email', NULL), TRUE)) drupal_set_message('Error sending email message.', 'error'); return FALSE; } else { @@ -2988,11 +3102,11 @@ function delete_file($file_id) /* 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'] . " : + $params['standard']['subject'] = "[ERROR] Error deleting file"; + $params['standard']['body'] = "Error deleting file by " . $user->uid . " at " . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . " : file id : " . $file_id . " file path : " . $file_data->filepath; - if (!drupal_mail('textbook_companion', 'standard', $email_to, language_default(), $param, variable_get('textbook_companion_from_email', NULL), 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; } else { @@ -3009,7 +3123,7 @@ function delete_file($file_id) //Non aicte book proposal form -function book_proposal_nonaicte_form($form_state) +function book_proposal_nonaicte_form($form,&$form_state) { global $user; @@ -3071,7 +3185,7 @@ function book_proposal_nonaicte_form($form_state) '#required' => TRUE, ); - $form['how_project'] = array( + /*$form['how_project'] = array( '#type' => 'select', '#title' => t('How did you come to know about this project'), '#options' => array('Scilab Website' => 'Scilab Website', @@ -3081,7 +3195,8 @@ function book_proposal_nonaicte_form($form_state) 'Poster in my/other college' => 'Poster in my/other college', 'Others' => 'Others'), '#required' => TRUE, - ); + );*/ + $form['course'] = array( '#type' => 'textfield', '#title' => t('Course'), @@ -3092,18 +3207,7 @@ function book_proposal_nonaicte_form($form_state) $form['branch'] = array( '#type' => 'select', '#title' => t('Department/Branch'), - '#options' => array('Electrical Engineering' => 'Electrical Engineering', - 'Electronics Engineering' => 'Electronics Engineering', - 'Computer Engineering' => 'Computer Engineering', - 'Chemical Engineering' => 'Chemical Engineering', - 'Instrumentation Engineering' => 'Instrumentation Engineering', - 'Mechanical Engineering' => 'Mechanical Engineering', - 'Civil Engineering' => 'Civil Engineering', - 'Physics' => 'Physics', - 'Applied Physics' =>'Applied Physics', - ' Nuclear Technology and Biotechnology' => ' Nuclear Technology and Biotechnology', - 'Mathematics' => 'Mathematics', - 'Others' => 'Others'), + '#options' => _tbc_list_of_departments(), '#required' => TRUE, ); $form['university'] = array( @@ -3113,70 +3217,79 @@ function book_proposal_nonaicte_form($form_state) '#maxlength' => 50, '#required' => TRUE, ); - $form['city'] = array( - '#type' => 'textfield', - '#title' => t('City/ Village'), - '#size' => 80, - '#maxlength' => 150, - '#required' => TRUE, - '#attributes' =>array('placeholder' =>'Insert location of your institute/ university....'), - ); -$form['pincode'] = array( - '#type' => 'textfield', - '#title' => t('Pincode'), - '#size' => 30, - '#maxlength' => 6, - '#required' => TRUE, - '#attributes' =>array('placeholder' =>'Insert pincode of your city/ village....'), -); -$form['all_state'] = array( + $form['country'] = array( '#type' => 'select', - '#title' => t('State'), + '#title' => t('Country'), '#options' => array( - '0' => 'Please select...', - 'Andhra Pradesh' => t('Andhra Pradesh'), - 'Arunachal Pradesh' => 'Arunachal Pradesh', - 'Assam' => 'Assam', - 'Bihar' => 'Bihar', - 'Chhattisgarh' => 'Chhattisgarh', - 'Goa' => 'Goa', - 'Gujarat' => 'Gujarat', - 'Haryana' => 'Haryana', - 'Himachal Pradesh' => 'Himachal Pradesh', - 'Jammu & Kashmir' => 'Jammu & Kashmir', - 'Jharkhand' => 'Jharkhand', - 'Karnataka' => 'Karnataka', - 'Kerala' => 'Kerala', - 'Madhya Pradesh' => 'Madhya Pradesh', - 'Maharashtra' => 'Maharashtra', - 'Manipur' => 'Manipur', - 'Meghalaya' => 'Meghalaya', - 'Mizoram' => 'Mizoram', - 'Nagaland' => 'Nagaland', - 'Odisha' => 'Odisha', - 'Punjab' => 'Punjab', - 'Rajasthan' => 'Rajasthan', - 'Sikkim' => 'Sikkim', - 'Tamil Nadu' => 'Tamil Nadu', - 'Telangana' => 'Telangana', - 'Tripura' => 'Tripura', - 'Uttarakhand' => 'Uttarakhand', - 'Uttar Pradesh'=> 'Uttar Pradesh', - 'West Bengal' => 'West Bengal', - 'Andaman & Nicobar' => 'Andaman & Nicobar', - 'Chandigarh' => 'Chandigarh', - 'Dadra and Nagar Haveli' => 'Dadra and Nagar Haveli', - 'Daman & Diu' => 'Daman & Diu', - 'Delhi' => 'Delhi', - 'Lakshadweep' => 'Lakshadweep', - 'Puducherry' => 'Puducherry', - 'Others' => 'Others', + 'India' => 'India', + 'Others' => 'Others', ), '#required' => TRUE, '#tree' => TRUE, '#validated' => TRUE, - ); - + ); + $form['other_country'] = array( + '#type' => 'textfield', + '#title' => t('Other than India'), + '#size' => 100, + '#attributes' =>array('placeholder' => t('Enter your country name')), + '#states' => array( + 'visible' => array( + ':input[name="country"]' => array('value' => 'Others'), + ), + ), + ); + $form['other_state'] = array( + '#type' => 'textfield', + '#title' => t('State other than India'), + '#size' => 100, + '#attributes' =>array('placeholder' => t('Enter your state/region name')), + '#states' => array( + 'visible' => array( + ':input[name="country"]' => array('value' => 'Others'), + ), + ), + ); + $form['other_city'] = array( + '#type' => 'textfield', + '#title' => t('City other than India'), + '#size' => 100, + '#attributes' =>array('placeholder' => t('Enter your city name')), + '#states' => array( + 'visible' => array( + ':input[name="country"]' => array('value' => 'Others'), + ), + ), + ); + $form['all_state'] = array( + '#type' => 'select', + '#title' => t('State'), + '#options' => _tbc_list_of_states(), + '#validated' => TRUE, + '#states' => array( + 'visible' => array( + ':input[name="country"]' => array('value' => 'India'), + ), + ), + ); + $form['city'] = array( + '#type' => 'select', + '#title' => t('City'), + '#options' => _tbc_list_of_cities(), + '#states' => array( + 'visible' => array( + ':input[name="country"]' => array('value' => 'India'), + ), + ), + ); + $form['pincode'] = array( + '#type' => 'textfield', + '#title' => t('Pincode'), + '#size' => 30, + '#maxlength' => 6, + '#required' => False, + '#attributes' =>array('placeholder' =>'Enter pincode....'), + ); $form['faculty'] = array( '#type' => 'hidden', '#value' => 'None', @@ -3200,22 +3313,15 @@ $form['all_state'] = array( '#size' => 30, '#maxlength' => 50, ); + $form['version'] = array( - '#type' => 'select', - '#title' => t('Version'), - '#options' => array('scilab 5.4.1' => 'Scilab 5.4.1', - 'scilab 5.3.3' => 'Scilab 5.3.3', - 'olderversion' => 'Older 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'),),), - ); + '#title' => t('Scilab Version'), + '#description' => t('Input version format should be like 5.4 or 5.4.1'), + '#size' => 10, + '#required' => TRUE, + '#maxlength' => 20, + ); $form['completion_date'] = array( '#type' => 'textfield', '#title' => t('Expected Date of Completion'), @@ -3260,8 +3366,7 @@ $form['all_state'] = array( '#type' => 'textarea', '#title' => t('Reference'), '#required' => TRUE, - '#size' => 500, - '#maxlength' => 500, + '#size' => 1000, '#attributes' =>array('placeholder' =>'Links of the syllabus must be provided....'), ); $form['preference1'] = array( @@ -3321,6 +3426,26 @@ $form['all_state'] = array( '#required' => TRUE, '#default_value' => $row1->year, ); + $form['preference1']['book_category_1'] = array( + '#type' => 'select', + '#title' => t('Category'), + '#options' => _tbc_list_of_category(), + '#required' => TRUE, + ); + $form['samplefile'] = array( + '#type' => 'fieldset', + '#title' => t('<span class="form-required form-item" title="This field is required.">Sample Source Files *</span>'), + '#collapsible' => FALSE, + '#collapsed' => FALSE, + ); + $form['samplefile']['samplefile1'] = array( + '#type' => 'file', + '#title' => t('Upload sample source file'), + '#size' => 48, + '#description' => t('Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' . + t('<span style="color:red;">Allowed file extensions : ') . variable_get('textbook_companion_sample_source_file_extensions', '').'</span>', + + ); $form['termconditions'] = array( '#type' => 'checkboxes', @@ -3334,21 +3459,137 @@ $form['all_state'] = array( '#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_validate($form, &$form_state) +{ + /* mobile */ + if (!preg_match('/^[0-9\ \+]{0,15}$/', $form_state['values']['mobile'])) + form_set_error('mobile', t('Invalid mobile number')); + + /* date of completion */ + if (!preg_match('/^[0-9]{1,2}-[0-9]{1,2}-[0-9]{4}$/', $form_state['values']['completion_date'])) + form_set_error('completion_date', t('Invalid expected date of completion')); + + list($d, $m, $y) = explode('-', $form_state['values']['completion_date']); + $d = (int)$d; $m = (int)$m; $y = (int)$y; + if (!checkdate($m, $d, $y)) + form_set_error('completion_date', t('Invalid expected date of completion')); + if (mktime(0, 0, 0, $m, $d, $y) <= time()) + form_set_error('completion_date', t('Expected date of completion should be in future')); + + /* edition */ + if (!preg_match('/^[1-9][0-9]{0,1}$/', $form_state['values']['edition1'])) + form_set_error('edition1', t('Invalid edition for Book Preference 1')); + + + /* year of publication */ + if (!preg_match('/^[1-3][0-9][0-9][0-9]$/', $form_state['values']['year1'])) + form_set_error('year1', t('Invalid year of pulication for Book Preference 1')); + + /* year of publication */ + $cur_year = date('Y'); + if ((int)$form_state['values']['year1'] > $cur_year) + form_set_error('year1', t('Year of pulication should be not in the future for Book Preference 1')); + + + /* isbn */ + if (!preg_match('/^[0-9\-xX]+$/', $form_state['values']['isbn1'])) + form_set_error('isbn1', t('Invalid ISBN for Book Preference 1')); + + if (!preg_match('/^\d+(?:\.\d+)+/', $form_state['values']['version'])) + form_set_error('version', t('Please enter correct version in speacifed format')); + + + + if($form_state['values']['country']=='Others'){ + if($form_state['values']['other_country']== ''){ + form_set_error('other_country', t('Enter country name')); + // $form_state['values']['country'] = $form_state['values']['other_country']; + }else{ + $form_state['values']['country'] = $form_state['values']['other_country']; + } + if($form_state['values']['other_state']== ''){ + form_set_error('other_state', t('Enter state name')); + // $form_state['values']['country'] = $form_state['values']['other_country']; + }else{ + $form_state['values']['all_state'] = $form_state['values']['other_state']; + } + if($form_state['values']['other_city']== ''){ + form_set_error('other_city', t('Enter city name')); + // $form_state['values']['country'] = $form_state['values']['other_country']; + }else{ + $form_state['values']['city'] = $form_state['values']['other_city']; + } + }else{ + if($form_state['values']['country']== ''){ + form_set_error('country', t('Select country name')); + // $form_state['values']['country'] = $form_state['values']['other_country']; + } + if($form_state['values']['all_state']== ''){ + form_set_error('all_state', t('Select state name')); + // $form_state['values']['country'] = $form_state['values']['other_country']; + } + if($form_state['values']['city']== ''){ + form_set_error('city', t('Select city name')); + // $form_state['values']['country'] = $form_state['values']['other_country']; + } + + + } + + + if (isset($_FILES['files'])) + { + /* check if atleast one source or result file is uploaded */ + if ( ! ($_FILES['files']['name']['samplefile1'])) + form_set_error('samplefile1', t('Please upload sample code main or source file.')); + + /* check for valid filename extensions */ + foreach ($_FILES['files']['name'] as $file_form_name => $file_name) + { + if ($file_name) + { + /* checking file type */ + if (strstr($file_form_name, 'sample')) + $file_type = 'S'; + + else + $file_type = 'U'; + + $allowed_extensions_str = ''; + switch ($file_type) + { + case 'S': + $allowed_extensions_str = variable_get('textbook_companion_sample_source_file_extensions', ''); + break; + + } + $allowed_extensions = explode(',' , $allowed_extensions_str); + $allowd_file = strtolower($_FILES['files']['name'][$file_form_name]); + $temp_extension = end(explode('.', $allowd_file)); + if (!in_array($temp_extension, $allowed_extensions)) + form_set_error($file_form_name, t('Only file with ' . $allowed_extensions_str . ' extensions can be uploaded.')); + if ($_FILES['files']['size'][$file_form_name] <= 0) + form_set_error($file_form_name, t('File size cannot be zero.')); + + /* check if valid file name */ + if (!textbook_companion_check_valid_filename($_FILES['files']['name'][$file_form_name])) + form_set_error($file_form_name, t('Invalid file name specified. Only alphabets and numbers are allowed as a valid filename.')); + + + } + } + } + return; + +} function book_proposal_nonaicte_form_submit($form, &$form_state) { global $user; + $root_path = textbook_companion_samplecode_path(); $selections = variable_get("aicte_".$user->uid, ""); $tbc_to_emails = variable_get("textbook_companion_emails_all"); @@ -3379,33 +3620,15 @@ function book_proposal_nonaicte_form_submit($form, &$form_state) } } - /************************************/ - + /************************************/ - $scilab_version = $form_state['values']['version']; - - if($form_state['values']['version'] == 'olderversion'){ - $scilab_version = $form_state['values']['older']; - } - - //var_dump($form_state['values']); - - /*$query = "INSERT INTO {textbook_companion_proposal} - (uid, approver_uid, full_name, mobile, gender, how_project, course, branch, university, faculty, reviewer, reference, completion_date, creation_date, approval_date, proposal_status, scilab_version, operating_system, teacher_email, proposal_type, reason ) VALUES (".$user->uid.", 0, '".ucwords(strtolower($form_state['values']['full_name']))."', '".$form_state['values']['mobile']."', '".$form_state['values']['gender']."', '".$form_state['values']['how_project']."', '".$form_state['values']['course']."', '".$form_state['values']['branch']."', '".$form_state['values']['university']."', '".ucwords(strtolower($form_state['values']['faculty']))."', '".ucwords(strtolower($form_state['values']['reviewer']))."', '".strtolower($form_state['values']['reference'])."', '".$completion_date_timestamp."', '".time()."', 0, 0, '".$scilab_version."', '".$form_state['values']['operating_system']."', '".$form_state['values']['faculty_email']."','".$form_state['values']['proposal_type']."','".$my_reason."')";*/ - - - -/*$query = "INSERT INTO {textbook_companion_proposal} - (uid, approver_uid, full_name, mobile, gender, how_project, course, branch, university,city, pincode, state, faculty, reviewer, reference, completion_date, creation_date, message, approval_date, proposal_status, scilab_version, operating_system, teacher_email, proposal_type, reason ) VALUES (:uid, :approver_uid, :full_name, :mobile, :gender, :how_project, :course, :branch, :university, :city, :pincode, :state, - :faculty, :reviewer, :reference, :expected_completion_date, :creation_date,:message, - :approval_date, :proposal_status, :scilab_version, :operating_system, :teacher_email,: proposal_type, :reason)"; */ - + $scilab_version = 'scilab ' . $form_state['values']['version']; $query = " INSERT INTO {textbook_companion_proposal} - (uid, approver_uid, full_name, mobile, gender, how_project, course, branch, university, city, pincode, state, faculty, reviewer, reference, completion_date, creation_date, approval_date, proposal_status, message, scilab_version, operating_system, teacher_email, proposal_type, reason) VALUES (:uid, :approver_uid, :full_name, :mobile, :gender, :how_project, :course, :branch, :university, :city, :pincode, :state, + (uid, approver_uid, full_name, mobile, gender, how_project, course, branch, university, country, city, pincode, state, faculty, reviewer, reference, completion_date, creation_date, approval_date, proposal_status, message, scilab_version, operating_system, teacher_email, proposal_type, reason, samplefilepath) VALUES (:uid, :approver_uid, :full_name, :mobile, :gender, :how_project, :course, :branch, :university, :country, :city, :pincode, :state, :faculty, :reviewer, :reference, :completion_date, :creation_date, :approval_date, :proposal_status, :message, :scilab_version, - :operating_system, :teacher_email, :proposal_type, :reason) + :operating_system, :teacher_email, :proposal_type, :reason, :samplefilepath) "; // $result = db_query($query); @@ -3417,10 +3640,11 @@ $args = array( ":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'], + ":how_project"=> 'Not available', ":course"=> $form_state['values']['course'], ":branch"=> $form_state['values']['branch'], ":university"=> $form_state['values']['university'], + ":country" => $form_state['values']['country'], ":city"=> $form_state['values']['city'], ":pincode"=> $form_state['values']['pincode'], ":state"=> $form_state['values']['all_state'], @@ -3437,9 +3661,47 @@ $args = array( ":teacher_email"=>$form_state['values']['faculty_email'], ":proposal_type"=>$form_state['values']['proposal_type'], ":reason"=> $my_reason, + ":samplefilepath"=>"" ); -var_dump($args); +//var_dump($args); $result = db_query($query, $args, array('return' => Database::RETURN_INSERT_ID)); + + $dest_path = $result . '/'; + + if (!is_dir($root_path . $dest_path)){ + mkdir($root_path . $dest_path); +} + +/* uploading files */ + foreach ($_FILES['files']['name'] as $file_form_name => $file_name) + { + if ($file_name) + { + /* checking file type */ + $file_type = 'S'; + + if (file_exists($root_path . $dest_path . $_FILES['files']['name'][$file_form_name])) + { + drupal_set_message(t("Error uploading file. File !filename already exists.", array('!filename' => $_FILES['files']['name'][$file_form_name])), 'error'); + return; + } + + /* uploading file */ + if (move_uploaded_file($_FILES['files']['tmp_name'][$file_form_name], $root_path . $dest_path . $_FILES['files']['name'][$file_form_name])) + { + $query = "UPDATE {textbook_companion_proposal} SET samplefilepath = :samplefilepath WHERE id = :id"; + $args = array( + ":samplefilepath" => $dest_path . $_FILES['files']['name'][$file_form_name], + ":id" =>$result, + ); + $updateresult = db_query($query, $args); + + drupal_set_message($file_name . ' uploaded successfully.', 'status'); + } else { + drupal_set_message('Error uploading file : ' . $dest_path . $file_name, 'error'); + } + } + } if (!$result) @@ -3448,30 +3710,13 @@ var_dump($args); return; } /* proposal id */ - //$proposal_id = db_last_insert_id('textbook_companion_proposal', 'id'); - //$proposal_id = db_last_insert_id('textbook_companion_proposal', 'id'); + $proposal_id = $result; /* inserting first book preference */ if ($form_state['values']['book1']) { - /*$result = db_query("INSERT INTO {textbook_companion_preference} - (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)"; @@ -3485,7 +3730,7 @@ $args = array( ":publisher"=> ucwords(strtolower($form_state['values']['publisher1'])), ":edition"=> $form_state['values']['edition1'], ":year"=> $form_state['values']['year1'], - ":category"=> 0, + ":category"=> $form_state['values']['book_category_1'], ":approval_status"=> 0, ":nonaicte_book"=> 1, ); @@ -3497,22 +3742,27 @@ $args = array( 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)) + $email_to = $user->mail; + $from = variable_get('textbook_companion_from_email', ''); + $bcc = variable_get('textbook_companion_emails', ''); + $cc = variable_get('textbook_companion_cc_emails', ''); + + $params['nonaicte_proposal_received']['proposal_id'] = $proposal_id; + $params['nonaicte_proposal_received']['user_id'] = $user->uid; + $params['nonaicte_proposal_received']['headers']=array('From'=>$from,'MIME-Version'=> '1.0', + 'Content-Type'=> 'text/plain; charset=UTF-8; format=flowed; delsp=yes', + 'Content-Transfer-Encoding' => '8Bit', + 'X-Mailer'=> 'Drupal','Cc' => $cc, 'Bcc' => $bcc); + + if (!drupal_mail('textbook_companion', 'nonaicte_proposal_received', $email_to , language_default(), $params, $from, TRUE)) drupal_set_message('Error sending email message.', 'error'); drupal_set_message(t('We have received your book proposal. We will get back to you soon.'), 'status'); drupal_goto(''); } -// - function del_book_pdf($book_id) { $root_path = textbook_companion_path(); @@ -3522,10 +3772,67 @@ function del_book_pdf($book_id) unlink($dir_path . $pdf_filename); } +function _tbc_list_of_states(){ + $states = array(0 => '-Select-'); + $query = db_select('list_states_of_india'); + $query->fields('list_states_of_india'); + + //$query->orderBy('', ''); + $states_list = $query->execute(); + while ($states_list_data = $states_list->fetchObject()) + { + $states[$states_list_data->state] = $states_list_data->state; + } + return $states; +} +function _tbc_list_of_cities(){ + $city = array(0 => '-Select-'); + $query = db_select('list_cities_of_india'); + $query->fields('list_cities_of_india'); + $query->orderBy('city', 'ASC'); + $city_list = $query->execute(); + while ($city_list_data = $city_list->fetchObject()) + { + $city[$city_list_data->city] = $city_list_data->city; + } + return $city; +} +function _tbc_list_of_departments(){ + + $query = db_select('list_of_departments'); + $query->fields('list_of_departments'); + $query->orderBy('id', 'DESC'); + $department_list = $query->execute(); + while ($department_list_data = $department_list->fetchObject()) + { + $department[$department_list_data->department] = $department_list_data->department; + } + return $department; +} +function _tbc_list_of_category($category_id=NULL){ + if($category_id==NULL){ + $query = db_select('list_of_category'); + $query->fields('list_of_category'); + $query->orderBy('id', 'ASC'); + $category_list = $query->execute(); + }else{ + $query = db_select('list_of_category'); + $query->fields('list_of_category'); + $query->condition('category_id', $category_id); + $query->orderBy('id', 'ASC'); + $category_list = $query->execute(); + } + while ($category_list_data = $category_list->fetchObject()) + { + $category[$category_list_data->category_id] = $category_list_data->category_name; + } + return $category; +} + function textbook_companion_init(){ $path = drupal_get_path('module', 'textbook_companion'); - drupal_add_js($path . '/css/textbook_companion.css'); + drupal_add_css($path . '/css/textbook_companion.css'); drupal_add_js($path . '/js/textbook_companion.js'); drupal_add_js($path . '/js/jquery-1.7.1.js'); |