summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSashi202020-05-14 11:38:35 +0530
committerGitHub2020-05-14 11:38:35 +0530
commit04988c4f54bc95f7eb601d21f5e21f448b27028a (patch)
tree812fdaef4cbca0e27f6769ad22ece500ec7ad682
parentdf2bce6785d0229eb3c03f8edc91d86008123bb2 (diff)
parent50cfdcba360dcb17f88c42ce3a51d09a9670ce65 (diff)
downloadr_textbook_companion-04988c4f54bc95f7eb601d21f5e21f448b27028a.tar.gz
r_textbook_companion-04988c4f54bc95f7eb601d21f5e21f448b27028a.tar.bz2
r_textbook_companion-04988c4f54bc95f7eb601d21f5e21f448b27028a.zip
Merge pull request #35 from Sashi20/drupal_7.x
Add new field to upload file with codable examples to code submission interface
-rwxr-xr-xcode_approval.inc214
-rwxr-xr-xdownload.inc26
-rwxr-xr-xgeneral.inc202
-rwxr-xr-xsettings.inc10
-rwxr-xr-xtextbook_companion.module131
5 files changed, 566 insertions, 17 deletions
diff --git a/code_approval.inc b/code_approval.inc
index cdb5b32..b4e1862 100755
--- a/code_approval.inc
+++ b/code_approval.inc
@@ -30,11 +30,19 @@ function code_approval()
$query = db_select('textbook_companion_preference');
$query->fields('textbook_companion_preference');
$query->condition('id', $row->c_preference_id);
+ $query->condition('approved_codable_example_files', 1);
+ $query->condition('submitted_codable_examples_file', 1);
$result = $query->execute();
$preference_data = $result->fetchObject();
/* get proposal data */
/*$proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d", $preference_data->proposal_id);
$proposal_data = db_fetch_object($proposal_q);*/
+ if(!$preference_data){
+ //drupal_set_message('No data found.', 'status');
+ //drupal_goto('textbook-companion/code-approval');
+ //return;
+ }
+ else{
$query = db_select('textbook_companion_proposal');
$query->fields('textbook_companion_proposal');
$query->condition('id', $preference_data->proposal_id);
@@ -49,6 +57,7 @@ function code_approval()
l('Edit', 'textbook-companion/code-approval/approve/' . $row->c_id)
);
}
+}
/* check if there are any pending proposals */
if (!$rows) {
drupal_set_message(t('There are no pending proposals'), 'status');
@@ -95,7 +104,7 @@ function code_approval_form($form, &$form_state)
$proposal_data = $result->fetchObject();
} else {
drupal_set_message(t('Invalid chapter selected.'), 'error');
- drupal_goto('textbook-companion/code-approval');
+ //drupal_goto('textbook-companion/code-approval');
return;
}
$form['#tree'] = TRUE;
@@ -1596,3 +1605,206 @@ function edit_code_submission_form_submit($form, $form_state)
}
}
}
+
+function codable_example_approval()
+{
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('approved_codable_example_files', 0);
+ $query->condition('submited_all_examples_code', 1);
+ $query->condition('submitted_codable_examples_file', 1);
+ $result = $query->execute();
+ $preference_data = $result->fetchObject();
+ if(!$preference_data){
+ drupal_set_message('No data found.', 'status');
+ drupal_goto('textbook-companion/code-approval');
+ }
+ /* get proposal data */
+ /*$proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d", $preference_data->proposal_id);
+ $proposal_data = db_fetch_object($proposal_q);*/
+ $query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal');
+ $query->condition('id', $preference_data->proposal_id);
+ $result = $query->execute();
+ $proposal_data = $result->fetchObject();
+ /* setting table row information */
+ $rows[] = array(
+ $preference_data->book,
+ $proposal_data->full_name,
+ l('Edit', 'textbook-companion/code-approval/approve-codable-examples/' . $preference_data->id)
+ );
+
+ /* check if there are any pending proposals */
+ if (!$rows) {
+ drupal_set_message(t('There are no pending proposals'), 'status');
+ return '';
+ }
+ $header = array(
+ 'Title of the Book',
+ 'Contributor Name',
+ 'Actions'
+ );
+ $output = theme('table', array(
+ 'header' => $header,
+ 'rows' => $rows
+ ));
+ return $output;
+}
+
+function codable_examples_approval_form($form, &$form_state)
+{
+ /* get a list of unapproved chapters */
+ $pref_id = arg(3);
+
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('id', $pref_id);
+ $result = $query->execute();
+ $preference_data = $result->fetchObject();
+ //var_dump($preference_data);die;
+ /* get proposal data */
+ /*$proposal_q = db_query("SELECT * FROM {textbook_companion_proposal} WHERE id = %d", $preference_data->proposal_id);
+ $proposal_data = db_fetch_object($proposal_q);*/
+ $query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal');
+ $query->condition('id', $preference_data->proposal_id);
+ $result = $query->execute();
+ $proposal_data = $result->fetchObject();
+
+ $form['#tree'] = TRUE;
+ $form['contributor'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->full_name,
+ '#title' => t('Contributor Name')
+ );
+ $form['book_details']['book'] = array(
+ '#type' => 'item',
+ '#markup' => $preference_data->book,
+ '#title' => t('Title of the Book')
+ );
+
+ /* get example data */
+ /*$example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE chapter_id = %d AND approval_status = 0", $chapter_id);*/
+ $query = db_select('textbook_companion_codable_example_files');
+ $query->fields('textbook_companion_codable_example_files');
+ $query->condition('proposal_id', $preference_data->proposal_id);
+ //$query->condition('approval_status', 0);
+ $example_q = $query->execute();
+ $example_data = $example_q->fetchObject();
+ /*$form['example_details'][$example_data->id] = array(
+ '#type' => 'fieldset',
+ '#collapsible' => FALSE,
+ '#collapsed' => TRUE
+ );*/
+ $form['download_file'] = array(
+ '#type' => 'item',
+ '#title' => t('Click to download the file with list of codable examples'),
+ '#markup' => l('Download Example', 'textbook-companion/download/codable-example/' . $example_data->proposal_id)
+ );
+ $form['status_of_codable_example'] = array(
+ '#type' => 'radios',
+ '#options' => array(
+ 'Approved',
+ 'Dis-approved'
+ )
+ );
+ $form['message'] = array(
+ '#type' => 'textarea',
+ '#size' => 255,
+ '#maxlength' => 255,
+ '#title' => t('Reason for dis-approval')
+ );
+ $form['proposal_id'] = array(
+ '#type' => 'hidden',
+ '#value' => $example_data->proposal_id
+ );
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit')
+ );
+ $form['back_to_list'] = array(
+ '#type' => 'item',
+ '#markup' => l('Back to Code Approval List', 'textbook-companion/code-approval/codable-examples')
+ );
+ return $form;
+}
+
+function codable_examples_approval_form_submit($form, &$form_state){
+ global $user;
+ $proposal_id = $form_state['values']['proposal_id'];
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('proposal_id', $proposal_id);
+ $result = $query->execute();
+ $preference_data = $result->fetchObject();
+ $query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal');
+ $query->condition('id', $preference_data->proposal_id);
+ $result = $query->execute();
+ $proposal_data = $result->fetchObject();
+ $user_data = user_load($proposal_data->uid);
+ $ex_data = $form_state['values'];
+ if ($ex_data['status_of_codable_example'] == "0") {
+ /*db_query("UPDATE {textbook_companion_example} SET approval_status = 1, approver_uid = %d, approval_date = %d WHERE id = %d", $user->uid, time(), $ex_data['example_id']);*/
+ $query = db_update('textbook_companion_preference');
+ $query->fields(array(
+ 'approved_codable_example_files' => 1,
+ ));
+ $query->condition('proposal_id', $ex_data['proposal_id']);
+ $num_updated = $query->execute();
+ /* sending email */
+ $email_to = $user_data->mail;
+ $from = variable_get('textbook_companion_from_email', '');
+ $bcc = variable_get('textbook_companion_emails', '');
+ $cc = variable_get('textbook_companion_cc_emails', '');
+ $param['codable_example_approved']['proposal_id'] = $ex_data['proposal_id'];
+ $param['codable_example_approved']['user_id'] = $user_data->uid;
+ $param['codable_example_approved']['headers'] = array(
+ 'From' => $from,
+ 'MIME-Version' => '1.0',
+ 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
+ 'Content-Transfer-Encoding' => '8Bit',
+ 'X-Mailer' => 'Drupal',
+ 'Cc' => $cc,
+ 'Bcc' => $bcc
+ );
+ if (!drupal_mail('textbook_companion', 'codable_example_approved', $email_to, language_default(), $param, $from, TRUE))
+ drupal_set_message('Error sending email message.', 'error');
+ drupal_set_message('File approved.', 'status');
+ drupal_goto('textbook-companion/code-approval/codable-examples');
+ } else if ($ex_data['status_of_codable_example'] == "1") {
+
+ /* sending email */
+ $query = db_update('textbook_companion_preference');
+ $query->fields(array(
+ 'submitted_codable_examples_file' => 0,
+ 'submited_all_examples_code' => 0,
+ 'approved_codable_example_files' => 0,
+ ));
+ $query->condition('proposal_id', $ex_data['proposal_id']);
+ $num_updated = $query->execute();
+ $email_to = $user_data->mail;
+ $from = variable_get('textbook_companion_from_email', '');
+ $bcc = variable_get('textbook_companion_emails', '');
+ $cc = variable_get('textbook_companion_cc_emails', '');
+ $param['codable_example_disapproved']['proposal_id'] = $ex_data['proposal_id'];
+ $param['codable_example_disapproved']['user_id'] = $user_data->uid;
+ $param['codable_example_disapproved']['message'] = $ex_data['message'];
+ $param['codable_example_disapproved']['headers'] = array(
+ 'From' => $from,
+ 'MIME-Version' => '1.0',
+ 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
+ 'Content-Transfer-Encoding' => '8Bit',
+ 'X-Mailer' => 'Drupal',
+ 'Cc' => $cc,
+ 'Bcc' => $bcc
+ );
+ if (!drupal_mail('textbook_companion', 'codable_example_disapproved', $email_to, language_default(), $param, $from, TRUE))
+ drupal_set_message('Error sending email message.', 'error');
+ drupal_set_message('File disapproved and user has been notified of the changes.', 'status');
+ drupal_goto('textbook-companion/code-approval/codable-examples');
+ }
+ else {
+ drupal_set_message('Error in updating the status. Please contact administrator.', 'error');
+ }
+}
diff --git a/download.inc b/download.inc
index 3ba603e..ba7ee35 100755
--- a/download.inc
+++ b/download.inc
@@ -22,6 +22,32 @@ function textbook_companion_download_example_file()
ob_clean();
readfile($root_path . $example_file_data->directory_name . '/' . $example_file_data->filepath);
}
+
+function textbook_companion_download_codable_example_file()
+ {
+ $proposal_id = arg(3);
+ $root_path = textbook_companion_path();
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('proposal_id', $proposal_id);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $proposal_data = $result->fetchObject();
+ $query = db_select('textbook_companion_codable_example_files');
+ $query->fields('textbook_companion_codable_example_files');
+ $query->condition('proposal_id', $proposal_id);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $example_file_data = $result->fetchObject();
+ $filename = $example_file_data->filename;
+ ob_clean();
+ header('Content-Type: ' . $example_file_data->filemime);
+ header('Content-disposition: attachment; filename="' . $filename . '"');
+ header('Content-Length: ' . filesize($root_path . $proposal_data->directory_name . '/' . $example_file_data->filepath));
+
+ readfile($root_path . $proposal_data->directory_name . '/' . $example_file_data->filepath);
+ }
+
function textbook_companion_download_sample_code()
{
$proposal_id = arg(3);
diff --git a/general.inc b/general.inc
index 01d8bb2..9c8f4ec 100755
--- a/general.inc
+++ b/general.inc
@@ -295,13 +295,38 @@ function list_examples()
return $return_html;
}
function all_example_submitted_check_form($form,&$form_state,$preference_id){
- $form = array();
+ //$form = array();
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('id', $preference_id);
+ $query->condition('approval_status', 1);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $preference_data = $result->fetchObject();
+ $form['#attributes'] = array(
+ 'enctype' => "multipart/form-data"
+ );
$form['all_example_submitted'] = array(
'#type' => 'checkbox',
'#title' => t('I have submitted codes for all the examples'),
'#description' => 'Once you have submited this option you are not able to upload more examples.',
'#required' => TRUE,
+ );
+ //var_dump($preference_data->approved_codable_example_files);die;
+ if($preference_data->approved_codable_example_files == 0){
+ $form['upload_codable_examples'] = array(
+ '#type' => 'file',
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="all_example_submitted"]' => array(
+ 'checked' => True
+ )
+ )
+ ),
+ '#title' => t('Upload a document file containing a list of codable examples as shown in the template <a href="https://static.fossee.in/r/manuals/Template.docx" target="_blank">here</a><span style="color:red">*</span>'),
+ '#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_codable_examples_extensions', '') . '</span>',
);
+ }
$form['hidden_preference_id'] = array(
'#type' => 'hidden',
'#value' => $preference_id
@@ -316,13 +341,182 @@ function all_example_submitted_check_form_validate($form,&$form_state){
if ($form_state['values']['all_example_submitted'] != 1) {
form_set_error('all_example_submitted', t('Please check the field if you are intrested to submit the all uploaded examples for review!'));
}
+if (isset($_FILES['files']))
+ {
+ /* check if atleast one source or result file is uploaded */
+ if (!($_FILES['files']['name']['upload_codable_examples']))
+ form_set_error('upload_codable_examples', t('Please upload the file containing a list of codable examples.'));
+ /* check for valid filename extensions */
+ foreach ($_FILES['files']['name'] as $file_form_name => $file_name)
+ {
+ if ($file_name)
+ {
+ /* checking file type */
+ $allowed_extensions_str = variable_get('textbook_companion_codable_examples_extensions', '');
+ $allowed_extensions = explode(',', $allowed_extensions_str);
+ $fnames = explode('.', strtolower($_FILES['files']['name'][$file_form_name]));
+ $temp_extension = end($fnames);
+ if (!in_array($temp_extension, $allowed_extensions))
+ form_set_error($file_form_name, t('Only file with ' . $allowed_extensions_str . ' extensions can be uploaded.'));
+ if ($_FILES['files']['size'][$file_form_name] <= 0)
+ form_set_error($file_form_name, t('File size cannot be zero.'));
+ /* check if valid file name */
+ if (!textbook_companion_check_valid_filename($_FILES['files']['name'][$file_form_name]))
+ form_set_error($file_form_name, t('Invalid file name specified. Only alphabets and numbers are allowed as a valid filename.'));
+ } //$file_name
+ } //$_FILES['files']['name'] as $file_form_name => $file_name
+ }
return;
}
function all_example_submitted_check_form_submit($form,&$form_state){
global $user;
-if ($form_state['values']['all_example_submitted'] == 1) {
-db_query('UPDATE textbook_companion_preference SET submited_all_examples_code = 1 WHERE id = :preference_id',array(':preference_id' => $form_state['values']['hidden_preference_id']));
+/*if ($form_state['values']['all_example_submitted'] == 1) {
+db_query('UPDATE textbook_companion_preference SET submited_all_examples_code = 1 WHERE id = :preference_id',array(':preference_id' => $form_state['values']['hidden_preference_id']));*/
+$query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal');
+ $query->condition('uid', $user->uid);
+ $query->orderBy('id', 'DESC');
+ $query->range(0, 1);
+ $result = $query->execute();
+ $proposal_data = $result->fetchObject();
+ if (!$proposal_data)
+ {
+ drupal_set_message("Please submit a " . l('proposal', 'textbook-companion/proposal') . ".", 'error');
+ drupal_goto('');
+ }
+ if ($proposal_data->proposal_status != 1 && $proposal_data->proposal_status != 4)
+ {
+ switch ($proposal_data->proposal_status)
+ {
+ case 0:
+ drupal_set_message(t('We have already received your proposal. We will get back to you soon.'), 'status');
+ drupal_goto('');
+ return;
+ break;
+ case 2:
+ drupal_set_message(t('Your proposal has been dis-approved. Please create another proposal ' . l('here', 'textbook-companion/proposal') . '.'), 'error');
+ drupal_goto('');
+ return;
+ break;
+ case 3:
+ drupal_set_message(t('Congratulations! You have completed your last book proposal. You have to create another proposal ' . l('here', 'textbook-companion/proposal') . '.'), 'status');
+ drupal_goto('');
+ return;
+ break;
+ case 5:
+ drupal_set_message(t('You have submmited your all codes'), 'status');
+ drupal_goto('');
+ return;
+ break;
+ default:
+ drupal_set_message(t('Invalid proposal state. Please contact site administrator for further information.'), 'error');
+ drupal_goto('');
+ return;
+ break;
+ }
+ }
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('proposal_id', $proposal_data->id);
+ $query->condition('approval_status', 1);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $preference_data = $result->fetchObject();
+ if (!$preference_data)
+ {
+ drupal_set_message(t('Invalid Book Preference status. Please contact site administrator for further information.'), 'error');
+ drupal_goto('');
+ return;
+ }
+ if($preference_data->approved_codable_example_files == 0){
+$root_path = textbook_companion_path();
+$proposal_directory = $preference_data->directory_name;
+ $dest_path = $proposal_directory . '/';
+ if (!is_dir($root_path . $dest_path)){
+ if(!mkdir($root_path . $dest_path))
+ {
+ drupal_set_message(t('You cannot upload your code. Error in creating directory'), 'error');
+ }
+ }
+ /* creating directories */
+ $dest_path .= 'codable_example_file';
+ if (!is_dir($root_path . $dest_path))
+ mkdir($root_path . $dest_path);
+ //var_dump($root_path . $dest_path);die;
+ $filepath = 'codable_example_file/';
+ foreach ($_FILES['files']['name'] as $file_form_name => $file_name)
+ {
+ if (file_exists($root_path . $dest_path . '/' . $_FILES['files']['name'][$file_form_name]))
+ {
+ move_uploaded_file($_FILES['files']['tmp_name'][$file_form_name], $root_path . $dest_path . '/' . $_FILES['files']['name'][$file_form_name]);
+ drupal_set_message(t("File !filename already exists hence overwirtten the exisitng file ", array(
+ '!filename' => $_FILES['files']['name'][$file_form_name]
+ )), 'status');
+ $query = "UPDATE {textbook_companion_codable_example_files} SET filename = :filename, filepath=:filepath, filemime=:filemime, filesize=:filesize, timestamp=:timestamp WHERE proposal_id = :proposal_id";
+ $args = array(
+ ":filename" => $_FILES['files']['name'][$file_form_name],
+ ":filepath" => $filepath . $_FILES['files']['name'][$file_form_name],
+ ":filemime" => mime_content_type($root_path . $dest_path . '/' . $_FILES['files']['name'][$file_form_name]),
+ ":filesize" => $_FILES['files']['size'][$file_form_name],
+ ":timestamp" => time(),
+ ":proposal_id" => $preference_data->proposal_id
+ );
+ db_query($query, $args);
+ db_query('UPDATE textbook_companion_preference SET submited_all_examples_code = 1, submitted_codable_examples_file = 1 WHERE id = :preference_id',array(':preference_id' => $preference_data->id));
+ return;
+ }
+ /* uploading file */
+ else if (move_uploaded_file($_FILES['files']['tmp_name'][$file_form_name], $root_path . $dest_path . '/' . $_FILES['files']['name'][$file_form_name]))
+ {
+ $query_codable_examples_file = "SELECT * FROM textbook_companion_codable_example_files WHERE proposal_id = :proposal_id";
+ $args_query_codable_examples_file = array(
+ ":proposal_id" => $preference_data->proposal_id
+ );
+ $query_codable_examples_file_result = db_query($query_codable_examples_file, $args_query_codable_examples_file)->fetchObject();
+ if(!$query_codable_examples_file_result){
+ $query = "INSERT INTO {textbook_companion_codable_example_files} (proposal_id, filename, filepath,filemime, filesize, filetype, timestamp) VALUES (:proposal_id, :filename ,:filepath,:filemime, :filesize, :filetype, :timestamp)";
+ $args = array(
+ ":proposal_id" => $preference_data->proposal_id,
+ ":filename" => $_FILES['files']['name'][$file_form_name],
+ ":filepath" => $filepath . $_FILES['files']['name'][$file_form_name],
+ ":filemime" => mime_content_type($root_path . $dest_path . '/' . $_FILES['files']['name'][$file_form_name]),
+ ":filesize" => $_FILES['files']['size'][$file_form_name],
+ ":filetype" => 'C',
+ ":timestamp" => time()
+ );
+ $result = db_query($query, $args, array(
+ 'return' => Database::RETURN_INSERT_ID
+ ));
+ drupal_set_message('File uploaded successfully.', 'status');
+ }
+ else
+ {
+ unlink($root_path . $dest_path . '/' . $query_codable_examples_file_result->filename);
+ $query = "UPDATE {textbook_companion_codable_example_files} SET filename = :filename, filepath=:filepath, filemime=:filemime, filesize=:filesize, timestamp=:timestamp WHERE proposal_id = :proposal_id";
+ $args = array(
+ ":filename" => $_FILES['files']['name'][$file_form_name],
+ ":filepath" => $filepath . $_FILES['files']['name'][$file_form_name],
+ ":filemime" => mime_content_type($root_path . $dest_path . '/' . $_FILES['files']['name'][$file_form_name]),
+ ":filesize" => $_FILES['files']['size'][$file_form_name],
+ ":timestamp" => time(),
+ ":proposal_id" => $preference_data->proposal_id
+ );
+ db_query($query, $args);
+ drupal_set_message($file_name . ' file updated successfully.', 'status');
+ }
+ db_query('UPDATE textbook_companion_preference SET submited_all_examples_code = 1, submitted_codable_examples_file = 1 WHERE id = :preference_id',array(':preference_id' => $preference_data->id));
+ }
+ else
+ {
+ drupal_set_message('Error uploading file : ' . $dest_path . '/' . $file_name, 'error');
+ }
+ }
+ }
+ else{
+ db_query('UPDATE textbook_companion_preference SET submited_all_examples_code = 1 WHERE id = :preference_id',array(':preference_id' => $preference_data->id));
+ }
+ //drupal_set_message('File uploaded successfully.', 'status');
/* sending email */
$query = ("SELECT proposal_id FROM textbook_companion_preference WHERE id= :preference_id");
$args = array(":preference_id" => $form_state['values']['hidden_preference_id']);
@@ -347,4 +541,4 @@ db_query('UPDATE textbook_companion_preference SET submited_all_examples_code =
if (!drupal_mail('textbook_companion', 'all_code_submitted', $email_to, language_default(), $param, $from, TRUE))
drupal_set_message('Error sending email message.', 'error');
}
-}
+
diff --git a/settings.inc b/settings.inc
index 8ce3adb..f59c745 100755
--- a/settings.inc
+++ b/settings.inc
@@ -47,6 +47,15 @@ function textbook_companion_settings_form($form, &$form_state)
'#required' => TRUE,
'#default_value' => variable_get('textbook_companion_dataset_extensions', '')
);
+ $form['extensions']['codable_examples'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Allowed file extensions to upload codable examples'),
+ '#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_codable_examples_extensions', '')
+ );
$form['extensions']['sample_source'] = array(
'#type' => 'textfield',
'#title' => t('Allowed sample source file extensions'),
@@ -86,6 +95,7 @@ function textbook_companion_settings_form_submit($form, &$form_state)
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_dataset_extensions', $form_state['values']['dataset']);
+ variable_set('textbook_companion_codable_examples_extensions', $form_state['values']['codable_examples']);
variable_set('textbook_companion_sample_source_extensions', $form_state['values']['sample_source']);
variable_set('textbook_companion_book_preferences', $form_state['values']['book_preference_options']);
drupal_set_message(t('Settings updated'), 'status');
diff --git a/textbook_companion.module b/textbook_companion.module
index ed4be9d..3fb1f79 100755
--- a/textbook_companion.module
+++ b/textbook_companion.module
@@ -182,6 +182,31 @@ function textbook_companion_menu()
'weight' => 1,
'file' => 'code_approval.inc'
);
+ $items['textbook-companion/code-approval/codable-examples'] = array(
+ 'title' => 'Manage Codable Examples',
+ 'description' => 'Manage Codable Examples',
+ 'page callback' => 'codable_example_approval',
+ 'access arguments' => array(
+ 'approve code'
+ ),
+ 'type' => MENU_LOCAL_TASK,
+ 'weight' => 2,
+ 'file' => 'code_approval.inc'
+ );
+ $items['textbook-companion/code-approval/approve-codable-examples'] = array(
+ 'title' => 'Approve codable examples',
+ 'description' => 'Approve codable examples',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array(
+ 'codable_examples_approval_form'
+ ),
+ 'access arguments' => array(
+ 'approve code'
+ ),
+ //'weight' => 3,
+ 'type' => MENU_NORMAL_ITEM,
+ 'file' => 'code_approval.inc'
+ );
$items['textbook-companion/code-approval/bulk'] = array(
'title' => 'Bulk Manage',
'description' => 'Bulk Mangage',
@@ -193,7 +218,7 @@ function textbook_companion_menu()
'bulk manage code'
),
'type' => MENU_LOCAL_TASK,
- 'weight' => 2,
+ 'weight' => 3,
'file' => 'code_approval.inc'
);
/* $items['textbook-companion/code-approval/edit-code-submission'] = array(
@@ -282,17 +307,6 @@ function textbook_companion_menu()
'file' => 'general.inc',
'weight' => 1
);
- /*$items['textbook-companion/code/upload-codable-examples'] = array(
- 'title' => 'Upload Codable Examples',
- 'description' => 'Upload Codable Examples',
- 'page callback' => 'upload_codable_examples',
- 'access arguments' => array(
- 'upload code'
- ),
- 'type' => MENU_LOCAL_TASK,
- 'file' => 'code.inc',
- 'weight' => 2
- );*/
$items['textbook-companion/code/upload'] = array(
'title' => 'Code Submission',
'description' => 'Code Submission',
@@ -536,6 +550,16 @@ function textbook_companion_menu()
'type' => MENU_CALLBACK,
'file' => 'download.inc'
);
+ $items['textbook-companion/download/codable-example'] = array(
+ 'title' => 'Code Download',
+ 'description' => 'Code Download',
+ 'page callback' => 'textbook_companion_download_codable_example_file',
+ 'access arguments' => array(
+ 'download code'
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'download.inc'
+ );
$items['textbook-companion/download/chapter'] = array(
'title' => 'Code Download',
'description' => 'Code Download',
@@ -2452,6 +2476,89 @@ FOSSEE, IIT Bombay', array(
))
);
break;
+ case 'codable_example_approved':
+
+ /*$example_q = db_query("SELECT * FROM {textbook_companion_example} WHERE id = %d LIMIT 1", $params['codable_example_approved']['example_id']);
+ $example_data = db_fetch_object($example_q);*/
+ $query = db_select('textbook_companion_codable_example_files');
+ $query->fields('textbook_companion_codable_example_files');
+ $query->condition('proposal_id', $params['codable_example_approved']['proposal_id']);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $codable_example_data = $result->fetchObject();
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('proposal_id', $codable_example_data->proposal_id);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $preference_data = $result->fetchObject();
+ $query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal');
+ $query->condition('id', $preference_data->proposal_id);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $proposal_data = $result->fetchObject();
+ $user_data = user_load($params['codable_example_approved']['user_id']);
+ $message['headers'] = $params['codable_example_approved']['headers'];
+ $message['subject'] = t('[!site_name][Textbook Companion] Your codable solved examples document has been approved', array(
+ '!site_name' => variable_get('site_name', '')
+ ));
+ $message['body'] = array(
+ 'body' => t('
+Dear ' . $proposal_data->full_name . ',
+
+Congratulations! Your codable examples document has been approved. As you have now coded all of the codable solved examples of your proposed textbook, we shall begin with reviewing your TBC codes.
+
+Best Wishes,
+
+!site_name Team,
+FOSSEE, IIT Bombay', array(
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name
+ ))
+ );
+ break;
+ case 'codable_example_disapproved':
+ $user_data = user_load($params['codable_example_disapproved']['user_id']);
+ $query = db_select('textbook_companion_codable_example_files');
+ $query->fields('textbook_companion_codable_example_files');
+ $query->condition('proposal_id', $params['codable_example_disapproved']['proposal_id']);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $codable_example_data = $result->fetchObject();
+ $query = db_select('textbook_companion_preference');
+ $query->fields('textbook_companion_preference');
+ $query->condition('proposal_id', $codable_example_data->proposal_id);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $preference_data = $result->fetchObject();
+ $query = db_select('textbook_companion_proposal');
+ $query->fields('textbook_companion_proposal');
+ $query->condition('id', $preference_data->proposal_id);
+ $query->range(0, 1);
+ $result = $query->execute();
+ $proposal_data = $result->fetchObject();
+ $message['headers'] = $params['codable_example_disapproved']['headers'];
+ $message['subject'] = t('[!site_name][Textbook Companion] Your codable solved examples document has been disapproved', array(
+ '!site_name' => variable_get('site_name', '')
+ ));
+ $message['body'] = array(
+ 'body' => t('
+Dear ' . $proposal_data->full_name . ',
+
+Unfortunately, it seems like you have not coded all of the codable solved examples from your proposed textbook. Kindly address the below-mentioned comments and reupload the document after making necessary changes.
+
+Reason for dis-approval: ' . $params['codable_example_disapproved']['message'] . '
+
+Best Wishes,
+
+!site_name Team,
+FOSSEE, IIT Bombay', array(
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name
+ ))
+ );
+ break;
case 'example_deleted_user':
$user_data = user_load($params['example_deleted_user']['user_id']);