summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--abstract_bulk_approval.inc363
-rw-r--r--download.inc63
-rw-r--r--email.inc335
-rw-r--r--full_download.inc66
-rw-r--r--general_deletion.inc43
-rw-r--r--manage_proposal.inc1211
-rw-r--r--proposal.inc610
-rw-r--r--run.inc144
-rw-r--r--scilab_case_study.info7
-rw-r--r--scilab_case_study.module755
-rw-r--r--scilab_case_study_details.inc96
-rw-r--r--settings.inc98
-rw-r--r--upload_code.inc688
13 files changed, 4479 insertions, 0 deletions
diff --git a/abstract_bulk_approval.inc b/abstract_bulk_approval.inc
new file mode 100644
index 0000000..1ee7dec
--- /dev/null
+++ b/abstract_bulk_approval.inc
@@ -0,0 +1,363 @@
+<?php
+
+function scilab_case_study_abstract_bulk_approval_form($form, &$form_state)
+{
+ $options_first = _bulk_list_of_case_study_project();
+ $selected = isset($form_state['values']['case_study_project']) ? $form_state['values']['case_study_project'] : key($options_first);
+ $form = array();
+ $form['case_study_project'] = array(
+ '#type' => 'select',
+ '#title' => t('Title of the Case Study Project'),
+ '#options' => _bulk_list_of_case_study_project(),
+ '#default_value' => $selected,
+ '#ajax' => array(
+
+ 'callback' => 'ajax_bulk_case_study_abstract_details_callback'
+ ),
+ '#suffix' => '<div id="ajax_selected_case_study"></div><div id="ajax_selected_case_study_pdf"></div>'
+ );
+ $form['case_study_actions'] = array(
+ '#type' => 'select',
+ '#title' => t('Please select action for Case Study Project'),
+ '#options' => _bulk_list_case_study_actions(),
+ '#default_value' => 0,
+ '#prefix' => '<div id="ajax_selected_case_study_action" style="color:red;">',
+ '#suffix' => '</div>',
+ '#states' => array(
+ 'invisible' => array(
+ ':input[name="case_study_project"]' => array(
+ 'value' => 0
+ )
+ )
+ )
+ );
+ $form['message'] = array(
+ '#type' => 'textarea',
+ '#title' => t('Specify the reason for resubmission/ disapproval.'),
+ '#prefix' => '<div id= "message_submit">',
+ '#states' => array(
+ 'visible' => array(
+ array(
+ ':input[name="case_study_actions"]' => array(
+ 'value' => 3
+ )
+ ),
+ 'or',
+ array(
+ ':input[name="case_study_actions"]' => array(
+ 'value' => 2
+ )
+ )
+ )
+ )
+ );
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit'),
+ '#states' => array(
+ 'invisible' => array(
+ ':input[name="lab"]' => array(
+ 'value' => 0
+ )
+ )
+ )
+ );
+ return $form;
+}
+function ajax_bulk_case_study_abstract_details_callback($form, $form_state)
+{
+ $commands = array();
+ $case_study_project_default_value = $form_state['values']['case_study_project'];
+ if ($case_study_project_default_value != 0)
+ {
+ $commands[] = ajax_command_html('#ajax_selected_case_study', _case_study_details($case_study_project_default_value));
+ $form['case_study_actions']['#options'] = _bulk_list_case_study_actions();
+ $commands[] = ajax_command_replace('#ajax_selected_case_study_action', drupal_render($form['case_study_actions']));
+ } //$case_study_project_default_value != 0
+ else
+ {
+ $commands[] = ajax_command_html('#ajax_selected_case_study', '');
+ $commands[] = ajax_command_data('#ajax_selected_case_study', 'form_state_value_select', $form_state['values']['case_study_project']);
+ }
+ return array(
+ '#type' => 'ajax',
+ '#commands' => $commands
+ );
+}
+/************************************************************/
+function scilab_case_study_abstract_bulk_approval_form_submit($form, &$form_state)
+{
+ global $user;
+ $msg = '';
+ $root_path = scilab_case_study_path();
+ //var_dump($root_path);die;
+ if ($form_state['clicked_button']['#value'] == 'Submit')
+ {
+ if ($form_state['values']['case_study_project'])
+ //var_dump($form_state['values']['case_study_actions']);die;
+ // case_study_abstract_del_lab_pdf($form_state['values']['case_study_project']);
+ if (user_access('Case Study bulk manage abstract'))
+ {
+ $query = db_select('case_study_proposal');
+ $query->fields('case_study_proposal');
+ $query->condition('id', $form_state['values']['case_study_project']);
+ $user_query = $query->execute();
+ $user_info = $user_query->fetchObject();
+ //var_dump($user_info);die;
+ $user_data = user_load($user_info->uid);
+ if ($form_state['values']['case_study_actions'] == 1)
+ {
+ // approving entire project //
+ $query = db_select('case_study_submitted_abstracts');
+ $query->fields('case_study_submitted_abstracts');
+ $query->condition('proposal_id', $form_state['values']['case_study_project']);
+ $abstracts_q = $query->execute();
+ //var_dump($abstracts_q);die;
+ $experiment_list = '';
+ while ($abstract_data = $abstracts_q->fetchObject())
+ {
+ db_query("UPDATE {case_study_submitted_abstracts} SET abstract_approval_status = 1, is_submitted = 1, approver_uid = :approver_uid WHERE id = :id", array(
+ ':approver_uid' => $user->uid,
+ ':id' => $abstract_data->id
+ ));
+ db_query("UPDATE {case_study_submitted_abstracts_file} SET file_approval_status = 1, approvar_uid = :approver_uid WHERE submitted_abstract_id = :submitted_abstract_id", array(
+ ':approver_uid' => $user->uid,
+ ':submitted_abstract_id' => $abstract_data->id
+ ));
+ } //$abstract_data = $abstracts_q->fetchObject()
+ drupal_set_message(t('Approved Case Study Project. Use the checkbox below to publish this case study on the completed case studies page.'), 'status');
+ drupal_goto('case-study-project/manage-proposal/status/' . $form_state['values']['case_study_project']);
+ } //$form_state['values']['case_study_actions'] == 1
+ elseif ($form_state['values']['case_study_actions'] == 2)
+ {
+ //pending review entire project
+ $query = db_select('case_study_submitted_abstracts');
+ $query->fields('case_study_submitted_abstracts');
+ $query->condition('proposal_id', $form_state['values']['case_study_project']);
+ $abstracts_q = $query->execute();
+ $experiment_list = '';
+ while ($abstract_data = $abstracts_q->fetchObject())
+ {
+ db_query("UPDATE {case_study_submitted_abstracts} SET abstract_approval_status = 0, is_submitted = 0, approver_uid = :approver_uid WHERE id = :id", array(
+ ':approver_uid' => $user->uid,
+ ':id' => $abstract_data->id
+ ));
+ db_query("UPDATE {case_study_proposal} SET is_submitted = 0, approver_uid = :approver_uid WHERE id = :id", array(
+ ':approver_uid' => $user->uid,
+ ':id' => $abstract_data->proposal_id
+ ));
+ db_query("UPDATE {case_study_submitted_abstracts_file} SET file_approval_status = 0, approvar_uid = :approver_uid WHERE submitted_abstract_id = :submitted_abstract_id", array(
+ ':approver_uid' => $user->uid,
+ ':submitted_abstract_id' => $abstract_data->id
+ ));
+ } //$abstract_data = $abstracts_q->fetchObject()
+ drupal_set_message(t('Resubmit the project files'), 'status');
+ // email
+ $email_subject = t('[!site_name][Case Study Project] Your uploaded Case Study Project have been marked as pending', array(
+ '!site_name' => variable_get('site_name', '')
+ ));
+ $email_body = array(
+ 0 => t('
+
+Dear ' . $user_info->contributor_name . ',
+
+Kindly resubmit the project files for the project : ' . $user_info->project_title . '.
+
+Reason for resubmission: ' . $form_state['values']['message'] . '
+
+
+Best Wishes,
+
+!site_name Team,
+FOSSEE,IIT Bombay', array(
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name
+ ))
+ );
+ /** sending email when everything done **/
+ $email_to = $user_data->mail;
+ $from = variable_get('case_study_from_email', '');
+ $bcc = variable_get('case_study_emails', '');
+ $cc = variable_get('case_study_cc_emails', '');
+ $params['standard']['subject'] = $email_subject;
+ $params['standard']['body'] = $email_body;
+ $params['standard']['headers'] = array(
+ 'From' => $from,
+ 'MIME-Version' => '1.0',
+ 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
+ 'Content-Transfer-Encoding' => '8Bit',
+ 'X-Mailer' => 'Drupal',
+ 'Cc' => $cc,
+ 'Bcc' => $bcc
+ );
+ if (!drupal_mail('scilab_case_study', 'standard', $email_to, language_default(), $params, $from, TRUE))
+ {
+ drupal_set_message('Error sending email message.', 'error');
+ } //!drupal_mail('scilab_case_study', 'standard', $email_to, language_default(), $params, $from, TRUE)
+ } //$form_state['values']['case_study_actions'] == 2
+ elseif ($form_state['values']['case_study_actions'] == 3) //disapprove and delete entire Case Study Project
+ {
+ if (strlen(trim($form_state['values']['message'])) <= 30)
+ {
+ form_set_error('message', t(''));
+ $msg = drupal_set_message("Please mention the reason for disapproval. Minimum 30 character required", 'error');
+ return $msg;
+ } //strlen(trim($form_state['values']['message'])) <= 30
+ if (!user_access('Case Study bulk delete abstract'))
+ {
+ $msg = drupal_set_message(t('You do not have permission to Bulk Dis-Approved and Deleted Entire Lab.'), 'error');
+ return $msg;
+ } //!user_access('case_study bulk delete code')
+ if (scilab_case_study_abstract_delete_project($form_state['values']['case_study_project'])) //////
+ {
+ drupal_set_message(t('Dis-Approved and Deleted Entire Case Study Project.'), 'status');
+ $email_subject = t('[!site_name][Case Study Project] Your uploaded Case Study Project have been marked as dis-approved', array(
+ '!site_name' => variable_get('site_name', '')
+ ));
+ $email_body = array(
+ 0 => t('
+Dear ' . $user_info->contributor_name . ',
+
+Your uploaded Case Study Project files for the Case Study Project Title : ' . $user_info->project_title . ' have been marked as dis-approved.
+
+Reason for dis-approval: ' . $form_state['values']['message'] . '
+
+Best Wishes,
+
+!site_name Team,
+FOSSEE,IIT Bombay', array(
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name
+ ))
+ );
+ $email_to = $user_data->mail;
+ $from = variable_get('case_study_from_email', '');
+ $bcc = variable_get('case_study_emails', '');
+ $cc = variable_get('case_study_cc_emails', '');
+ $params['standard']['subject'] = $email_subject;
+ $params['standard']['body'] = $email_body;
+ $params['standard']['headers'] = array(
+ 'From' => $from,
+ 'MIME-Version' => '1.0',
+ 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
+ 'Content-Transfer-Encoding' => '8Bit',
+ 'X-Mailer' => 'Drupal',
+ 'Cc' => $cc,
+ 'Bcc' => $bcc
+ );
+ if (!drupal_mail('scilab_case_study', 'standard', $email_to, language_default(), $params, $from, TRUE))
+ {
+ drupal_set_message('Error sending email message.', 'error');
+ }
+ } //case_study_abstract_delete_project($form_state['values']['case_study_project'])
+ else
+ {
+ drupal_set_message(t('Error Dis-Approving and Deleting Entire Case Study Project.'), 'error');
+ }
+ // email
+
+ } //$form_state['values']['case_study_actions'] == 3
+
+ } //user_access('case_study project bulk manage code')
+ return $msg;
+ } //$form_state['clicked_button']['#value'] == 'Submit'
+}
+/**********************************************************/
+function _bulk_list_of_case_study_project()
+{
+ $project_titles = array(
+ '0' => 'Please select...'
+ );
+ $query = db_select('case_study_proposal');
+ $query->fields('case_study_proposal');
+ $query->condition('is_submitted', 1);
+ $query->condition('approval_status', 1);
+ $query->orderBy('project_title', 'ASC');
+ $project_titles_q = $query->execute();
+ while ($project_titles_data = $project_titles_q->fetchObject())
+ {
+ $project_titles[$project_titles_data->id] = $project_titles_data->project_title . ' (Proposed by ' . $project_titles_data->contributor_name . ')';
+ } //$project_titles_data = $project_titles_q->fetchObject()
+ return $project_titles;
+}
+function _bulk_list_case_study_actions()
+{
+ $case_study_actions = array(
+ 0 => 'Please select...'
+ );
+ $case_study_actions[1] = 'Approve Entire Case Study Project';
+ $case_study_actions[2] = 'Resubmit Project files';
+ $case_study_actions[3] = 'Dis-Approve Entire Case Study Project (This will delete Case Study Project)';
+ //$case_study_actions[4] = 'Delete Entire Case Study Project Including Proposal';
+ return $case_study_actions;
+}
+function _case_study_details($case_study_proposal_id)
+{
+ $return_html = "";
+ $query_pro = db_select('case_study_proposal');
+ $query_pro->fields('case_study_proposal');
+ $query_pro->condition('id', $case_study_proposal_id);
+ $abstracts_pro = $query_pro->execute()->fetchObject();
+ //var_dump($abstracts_pro);die;
+ $query_pdf = db_select('case_study_submitted_abstracts_file');
+ $query_pdf->fields('case_study_submitted_abstracts_file');
+ $query_pdf->condition('proposal_id', $case_study_proposal_id);
+ $query_pdf->condition('filetype', 'A');
+ $abstracts_pdf = $query_pdf->execute()->fetchObject();
+ if ($abstracts_pdf == TRUE)
+ {
+ if ($abstracts_pdf->filename != "NULL" || $abstracts_pdf->filename != "")
+ {
+ $abstract_filename = $abstracts_pdf->filename;
+ } //$abstracts_pdf->filename != "NULL" || $abstracts_pdf->filename != ""
+ else
+ {
+ $abstract_filename = "File not uploaded";
+ }
+ } //$abstracts_pdf == TRUE
+ else
+ {
+ $abstract_filename = "File not uploaded";
+ }
+ $query_process = db_select('case_study_submitted_abstracts_file');
+ $query_process->fields('case_study_submitted_abstracts_file');
+ $query_process->condition('proposal_id', $case_study_proposal_id);
+ $query_process->condition('filetype', 'S');
+ $abstracts_query_process = $query_process->execute()->fetchObject();
+ $query = db_select('case_study_submitted_abstracts');
+ $query->fields('case_study_submitted_abstracts');
+ $query->condition('proposal_id', $case_study_proposal_id);
+ $abstracts_q = $query->execute()->fetchObject();
+ if ($abstracts_q)
+ {
+ if ($abstracts_q->is_submitted == 0)
+ {
+ //drupal_set_message(t('Abstract is not submmited yet.'), 'error', $repeat = FALSE);
+ //return;
+ } //$abstracts_q->is_submitted == 0
+ } //$abstracts_q
+ //var_dump($abstracts_query_process);die;
+ if ($abstracts_query_process == TRUE)
+ {
+ if ($abstracts_query_process->filename != "NULL" || $abstracts_query_process->filename != "")
+ {
+ $abstracts_query_process_filename = $abstracts_query_process->filename;
+ } //$abstracts_query_process->filename != "NULL" || $abstracts_query_process->filename != ""
+ else
+ {
+ $abstracts_query_process_filename = "File not uploaded";
+ }
+ } //$abstracts_query_process == TRUE
+ else
+ {
+ $url = l('Upload abstract', 'case-study-project/abstract-code/upload');
+ $abstracts_query_process_filename = "File not uploaded";
+ }
+ $download_case_study = l('Download Case Study Project','case-study-project/full-download/project/'.$case_study_proposal_id);
+ $return_html .= '<strong>Proposer Name:</strong><br />' . $abstracts_pro->name_title . ' ' . $abstracts_pro->contributor_name . '<br /><br />';
+ $return_html .= '<strong>Title of the Case Study Project:</strong><br />' . $abstracts_pro->project_title . '<br /><br />';
+ $return_html .= '<strong>Uploaded an abstract (brief outline) of the project:</strong><br />' . $abstract_filename . '<br /><br />';
+ $return_html .= '<strong>Uploaded Case Directory Folder:</strong><br />' . $abstracts_query_process_filename . '<br /><br />';
+ $return_html .= $download_case_study;
+ return $return_html;
+}
diff --git a/download.inc b/download.inc
new file mode 100644
index 0000000..bb9d3d3
--- /dev/null
+++ b/download.inc
@@ -0,0 +1,63 @@
+<?php
+function download_proposal_abstract() {
+ $proposal_id = arg(3);
+ $root_path = scilab_case_study_path();
+ $query = db_select('case_study_proposal');
+ $query->fields('case_study_proposal');
+ $query->condition('id', $proposal_id);
+ $result = $query->execute();
+ $scilab_case_study_project_files = $result->fetchObject();
+ $directory_name = $scilab_case_study_project_files->directory_name . '/';
+ $str = substr($scilab_case_study_project_files->samplefilepath, strrpos($scilab_case_study_project_files->samplefilepath, '/'));
+ $abstract_file = ltrim($str, '/');
+ ob_clean();
+ header("Pragma: public");
+ header("Expires: 0");
+ header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
+ header("Cache-Control: public");
+ header("Content-Description: File Transfer");
+ header("Content-Type: application/pdf");
+ header('Content-disposition: attachment; filename="' . $abstract_file . '"');
+ header("Content-Length: " . filesize($root_path . $scilab_case_study_project_files->samplefilepath));
+ header("Content-Transfer-Encoding: binary");
+ header("Expires: 0");
+ header("Pragma: no-cache");
+ readfile($root_path . $scilab_case_study_project_files->samplefilepath);
+ ob_end_flush();
+ ob_clean();
+}
+
+function scilab_case_study_download_final_report() {
+ $proposal_id = arg(3);
+ $root_path = scilab_case_study_path();
+ $query = db_select('case_study_proposal');
+ $query->fields('case_study_proposal');
+ $query->condition('id', $proposal_id);
+ $result = $query->execute();
+ $scilab_case_study_project_files = $result->fetchObject();
+ $query = db_select('case_study_submitted_abstracts_file');
+ $query->fields('case_study_submitted_abstracts_file');
+ $query->condition('proposal_id', $proposal_id);
+ $query->condition('filetype', 'A');
+ $project_files = $query->execute();
+ $final_report_data = $project_files->fetchObject();
+ $directory_name = $scilab_case_study_project_files->directory_name . '/project_files/';
+ /*$str = substr($scilab_case_study_project_files->samplefilepath, strrpos($scilab_case_study_project_files->samplefilepath, '/'));
+ $abstract_file = ltrim($str, '/');*/
+ //var_dump($final_report_data);die;
+ ob_clean();
+ header("Pragma: public");
+ header("Expires: 0");
+ header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
+ header("Cache-Control: public");
+ header("Content-Description: File Transfer");
+ header("Content-Type: application/pdf");
+ header('Content-disposition: attachment; filename="' . $final_report_data->filename . '"');
+ header("Content-Length: " . filesize($root_path . $directory_name . $final_report_data->filename));
+ header("Content-Transfer-Encoding: binary");
+ header("Expires: 0");
+ header("Pragma: no-cache");
+ readfile($root_path . $directory_name . $final_report_data->filename);
+ ob_end_flush();
+ ob_clean();
+} \ No newline at end of file
diff --git a/email.inc b/email.inc
new file mode 100644
index 0000000..ba2a75e
--- /dev/null
+++ b/email.inc
@@ -0,0 +1,335 @@
+<?php
+/**
+ * Implementation of hook_mail().
+ */
+function scilab_case_study_mail($key, &$message, $params)
+{
+ global $user;
+ $language = $message['language'];
+ //$language = user_preferred_language($user);
+ switch ($key) {
+ case 'case_study_proposal_received':
+ /* initializing data */
+ $query = db_select('case_study_proposal');
+ $query->fields('case_study_proposal');
+ $query->condition('id', $params['case_study_proposal_received']['result1']);
+ $query->range(0, 1);
+ $proposal_data = $query->execute()->fetchObject();
+ $user = user_load($params['case_study_proposal_received']['user_id']);
+ $message['headers'] = $params['case_study_proposal_received']['headers'];
+ $message['subject'] = t('[!site_name][Case Study Project] Your Case Study Project proposal has been received', array(
+ '!site_name' => variable_get('site_name', ''),
+ ), array(
+ 'language' => $language->language,
+ ));
+ $message['body'] = array(
+ 'body' => t('
+Dear ' . $proposal_data->contributor_name . ',
+
+We have received your Case Study Project proposal with the following details:
+
+Full Name: ' . $proposal_data->name_title . ' ' . $proposal_data->contributor_name . '
+Email: ' . $user->mail . '
+University/Institute: ' . $proposal_data->university . '
+City: ' . $proposal_data->city . '
+State: ' . $proposal_data->state . '
+Country: ' . $proposal_data->country . '
+Project Title: ' . $proposal_data->project_title . '
+Date of Proposal: ' . date('d/m/Y', $proposal_data->creation_date) . '
+Expected Date of Completion: ' . date('d/m/Y', $proposal_data->expected_date_of_completion) . '
+
+Your proposal is under review. You will soon receive an email when same has been approved/disapproved.
+
+Best Wishes,
+!site_name Team,
+FOSSEE, IIT Bombay', array(
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user->name,
+ ), array(
+ 'language' => $language->language,
+ )),
+ );
+ break;
+ case 'case_study_proposal_disapproved':
+ /* initializing data */
+ $query = db_select('case_study_proposal');
+ $query->fields('case_study_proposal');
+ $query->condition('id', $params['case_study_proposal_disapproved']['proposal_id']);
+ $query->range(0, 1);
+ $proposal_data = $query->execute()->fetchObject();
+ $user_data = user_load($params['case_study_proposal_disapproved']['user_id']);
+ //$user = user_load($params['case_study_proposal']['name']);
+ $message['headers'] = $params['case_study_proposal_disapproved']['headers'];
+ $message['subject'] = t('[!site_name][Case Study Project] Your Case Study Project proposal has been disapproved', array(
+ '!site_name' => variable_get('site_name', ''),
+ ), array(
+ 'language' => $language->language,
+ ));
+ $message['body'] = array(
+ 'body' => t('
+Dear ' . $proposal_data->contributor_name . ',
+
+We regret to inform you that your Case Study proposal with following details have been disapproved:
+
+Full Name: ' . $proposal_data->name_title . ' ' . $proposal_data->contributor_name . '
+Email: ' . $user_data->mail . '
+University/Institute: ' . $proposal_data->university . '
+City: ' . $proposal_data->city . '
+State: ' . $proposal_data->state . '
+Country: ' . $proposal_data->country . '
+Project Title: ' . $proposal_data->project_title . '
+Date of Proposal: ' . date('d/m/Y', $proposal_data->creation_date) . '
+Expected Date of Completion: ' . date('d/m/Y', $proposal_data->expected_date_of_completion) . '
+
+Reason for rejection: ' . $proposal_data->dissapproval_reason . '
+
+
+You are welcome to submit a new proposal.
+
+Best Wishes,
+!site_name Team,
+FOSSEE, IIT Bombay', array(
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name,
+ ), array(
+ 'language' => $language->language,
+ )),
+ );
+ break;
+ case 'case_study_proposal_approved':
+ /* initializing data */
+ $url = 'https://scilab.in/case-study-project/abstract-code';
+ $query = db_select('case_study_proposal');
+ $query->fields('case_study_proposal');
+ $query->condition('id', $params['case_study_proposal_approved']['proposal_id']);
+ $query->range(0, 1);
+ $proposal_data = $query->execute()->fetchObject();
+ $user_data = user_load($params['case_study_proposal_approved']['user_id']);
+ $message['headers'] = $params['case_study_proposal_approved']['headers'];
+ $message['subject'] = t('[!site_name][Case Study Project] Your Case Study Project proposal has been approved', array(
+ '!site_name' => variable_get('site_name', ''),
+ ), array(
+ 'language' => $language->language,
+ ));
+ $message['body'] = array(
+ 'body' => t('
+Dear ' . $proposal_data->contributor_name . ',
+
+Your Case Study Project proposal with the following details has been approved:
+
+Full Name: ' . $proposal_data->name_title . ' ' . $proposal_data->contributor_name . '
+Email: ' . $user_data->mail . '
+University/Institute: ' . $proposal_data->university . '
+City: ' . $proposal_data->city . '
+State: ' . $proposal_data->state . '
+Country: ' . $proposal_data->country . '
+Project Title: ' . $proposal_data->project_title . '
+Date of Proposal: ' . date('d/m/Y', $proposal_data->creation_date) . '
+Expected Date of Completion: ' . date('d/m/Y', $proposal_data->expected_date_of_completion) . '
+
+
+You can upload your project files at: ' . $url . '
+
+Best Wishes,
+!site_name Team,
+FOSSEE, IIT Bombay', array(
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name,
+ ), array(
+ 'language' => $language->language,
+ )),
+ );
+ break;
+ case 'case_study_proposal_completed':
+ /* initializing data */
+ $url = 'https://scilab.in/case-study-project/completed-case-studies';
+ $query = db_select('case_study_proposal');
+ $query->fields('case_study_proposal');
+ $query->condition('id', $params['case_study_proposal_completed']['proposal_id']);
+ $query->range(0, 1);
+ $proposal_data = $query->execute()->fetchObject();
+ $user_data = user_load($params['case_study_proposal_completed']['user_id']);
+ $message['headers'] = $params['case_study_proposal_completed']['headers'];
+ $message['subject'] = t('[!site_name][Case Study Project] Your case study project has been approved and marked as completed', array(
+ '!site_name' => variable_get('site_name', ''),
+ ), array(
+ 'language' => $language->language,
+ ));
+ $message['body'] = array(
+ 'body' => t('
+Dear ' . $proposal_data->contributor_name . ',
+
+We are glad to inform that your files are approved and the Case Study Project with the following details is marked Completed. The case study is published at ' . $url . '
+
+Full Name: ' . $proposal_data->name_title . ' ' . $proposal_data->contributor_name . '
+Email: ' . $user_data->mail . '
+University/Institute: ' . $proposal_data->university . '
+City: ' . $proposal_data->city . '
+State: ' . $proposal_data->state . '
+Country: ' . $proposal_data->country . '
+Project Title: ' . $proposal_data->project_title . '
+
+Best Wishes,
+!site_name Team,
+FOSSEE, IIT Bombay', array(
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name,
+ ), array(
+ 'language' => $language->language,
+ )),
+ );
+ break;
+ case 'case_study_proposal_send_reminder_mail':
+ /* initializing data */
+ $query = db_select('case_study_proposal');
+ $query->fields('case_study_proposal');
+ $query->condition('id', $params['case_study_proposal_send_reminder_mail']['proposal_id']);
+ $query->range(0, 1);
+ $proposal_data = $query->execute()->fetchObject();
+ $user_data = user_load($params['case_study_proposal_send_reminder_mail']['user_id']);
+ $message['headers'] = $params['case_study_proposal_send_reminder_mail']['headers'];
+ $message['subject'] = t('[!site_name][Case Study Project] Completion date of your proposed Case Study is approaching', array(
+ '!site_name' => variable_get('site_name', ''),
+ ), array(
+ 'language' => $language->language,
+ ));
+ $message['body'] = array(
+ 'body' => t('
+Dear ' . $proposal_data->contributor_name . ',
+
+This is a gentle reminder regarding the proposed case study project. The submission deadline is approaching, and we kindly request you to complete your submission before the deadline.
+
+Please note that once the deadline passes, the interface will no longer accept submissions. Ensure you submit your work on time to avoid any inconvenience.
+
+Best Wishes,
+
+!site_name Team,
+FOSSEE, IIT Bombay', array(
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name,
+ ), array(
+ 'language' => $language->language,
+ )),
+ );
+ break;
+ case 'case_study_proposal_deleted':
+ /* initializing data */
+ $query = db_select('case_study_proposal');
+ $query->fields('case_study_proposal');
+ $query->condition('id', $params['case_study_proposal_deleted']['proposal_id']);
+ $query->range(0, 1);
+ $proposal_data = $query->execute()->fetchObject();
+ $user_data = user_load($params['case_study_proposal_deleted']['user_id']);
+ $message['headers'] = $params['case_study_proposal_deleted']['headers'];
+ $message['subject'] = t('[!site_name][Case Study Project] Your Case Study Project proposal has been deleted', array(
+ '!site_name' => variable_get('site_name', ''),
+ ), array(
+ 'language' => $language->language,
+ ));
+ $message['body'] = array(
+ 'body' => t('
+Dear ' . $proposal_data->contributor_name . ',
+
+We regret to inform that your Case Study Project proposal with the following details has been deleted:
+
+Full Name: ' . $proposal_data->name_title . ' ' . $proposal_data->contributor_name . '
+Email: ' . $user_data->mail . '
+University/Institute: ' . $proposal_data->university . '
+City: ' . $proposal_data->city . '
+State: ' . $proposal_data->state . '
+Country: ' . $proposal_data->country . '
+Project Title: ' . $proposal_data->project_title . '
+
+You can propose a new Case Study project.
+
+Best Wishes,
+!site_name Team,
+FOSSEE, IIT Bombay', array(
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user_data->name,
+ ), array(
+ 'language' => $language->language,
+ )),
+ );
+ break;
+ /**************************************************************/
+ case 'abstract_uploaded':
+ // $solution_q = db_query("SELECT * FROM {case_study_solution} WHERE id = %d LIMIT 1", $params['abstract_uploaded']['solution_id']);
+ $query = db_select('case_study_proposal');
+ $query->fields('case_study_proposal');
+ $query->condition('id', $params['abstract_uploaded']['proposal_id']);
+ $query->range(0, 1);
+ $proposal_data = $query->execute()->fetchObject();
+
+ $user = user_load($params['abstract_uploaded']['user_id']);
+ $message['subject'] = t('[!site_name][Case Study Project] You have uploaded Case Study project files', array(
+ '!site_name' => variable_get('site_name', ''),
+ ), array(
+ 'language' => $language->language,
+ ));
+ $message['headers'] = $params['abstract_uploaded']['headers'];
+ $message['body'] = array(
+ 'body' => t('
+Dear ' . $proposal_data->contributor_name . ',
+
+You have uploaded the following Abstract and Project files:
+
+Project Title: ' . $proposal_data->project_title . '
+
+
+The abstract and project files are under review. You will be notified when it has been approved.
+
+Best Wishes,
+!site_name Team,
+FOSSEE, IIT Bombay', array(
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user->name,
+ ), array(
+ 'language' => $language->language,
+ )),
+ );
+ break;
+/**************************************************************/
+ case 'abstract_edit_file_uploaded':
+ // $solution_q = db_query("SELECT * FROM {case_study_solution} WHERE id = %d LIMIT 1", $params['abstract_uploaded']['solution_id']);
+ $query = db_select('case_study_proposal');
+ $query->fields('case_study_proposal');
+ $query->condition('id', $params['abstract_edit_file_uploaded']['proposal_id']);
+ $query->range(0, 1);
+ $proposal_data = $query->execute()->fetchObject();
+
+ $user = user_load($params['abstract_edit_file_uploaded']['user_id']);
+ $abs_file_name = $params['abstract_edit_file_uploaded']['abs_file'];
+ $proj_file_name = $params['abstract_edit_file_uploaded']['proj_file'];
+
+ $message['subject'] = t('[!site_name][Case Study Project] You have updated project files/abstract of a case study', array(
+ '!site_name' => variable_get('site_name', ''),
+ ), array(
+ 'language' => $language->language,
+ ));
+ $message['headers'] = $params['abstract_edit_file_uploaded']['headers'];
+ $message['body'] = array(
+ 'body' => t('
+Dear ' . $proposal_data->contributor_name . ',
+
+You have updated the abstract/ project files for the following case study:
+
+Project Title: ' . $proposal_data->project_title . '
+
+Best Wishes,
+!site_name Team,
+FOSSEE, IIT Bombay', array(
+ '!site_name' => variable_get('site_name', ''),
+ '!user_name' => $user->name,
+ ), array(
+ 'language' => $language->language,
+ )),
+ );
+ break;
+ case 'standard':
+ $message['subject'] = $params['standard']['subject'];
+ $message['body'] = $params['standard']['body'];
+ $message['headers'] = $params['standard']['headers'];
+ break;
+ } //$key
+}
diff --git a/full_download.inc b/full_download.inc
new file mode 100644
index 0000000..5328e7c
--- /dev/null
+++ b/full_download.inc
@@ -0,0 +1,66 @@
+<?php
+// $Id$
+function scilab_case_study_download_full_project()
+{
+ global $user;
+ $id = arg(3);
+ $root_path = scilab_case_study_path();
+ //var_dump($root_path);die;
+ $query = db_select('case_study_proposal');
+ $query->fields('case_study_proposal');
+ $query->condition('id', $id);
+ $case_study_q = $query->execute();
+ $case_study_data = $case_study_q->fetchObject();
+ $CASE_STUDY_PATH = $case_study_data->directory_name . '/project_files/';
+ /* zip filename */
+ $zip_filename = $root_path . 'zip-' . time() . '-' . rand(0, 999999) . '.zip';
+ /* creating zip archive on the server */
+ $zip = new ZipArchive();
+ $zip->open($zip_filename, ZipArchive::CREATE);
+ $query = db_select('case_study_proposal');
+ $query->fields('case_study_proposal');
+ $query->condition('id', $id);
+ $circuit_simulation_udc_q = $query->execute();
+ $query = db_select('case_study_proposal');
+ $query->fields('case_study_proposal');
+ $query->condition('id', $id);
+ $query = db_select('case_study_submitted_abstracts_file');
+ $query->fields('case_study_submitted_abstracts_file');
+ $query->condition('proposal_id', $id);
+ $project_files = $query->execute();
+ while ($scilab_project_files = $project_files->fetchObject()) {
+ $zip->addFile($root_path . $CASE_STUDY_PATH . $scilab_project_files->filepath, $CASE_STUDY_PATH . str_replace(' ', '_', basename($scilab_project_files->filename)));
+ }
+ $zip_file_count = $zip->numFiles;
+ $zip->close();
+ if ($zip_file_count > 0) {
+ if ($user->uid) {
+ /* download zip file */
+ header('Content-Type: application/zip');
+ header('Content-disposition: attachment; filename="' . str_replace(' ', '_', $case_study_data->project_title) . '.zip"');
+ header('Content-Length: ' . filesize($zip_filename));
+ ob_end_flush();
+ ob_clean();
+ flush();
+ readfile($zip_filename);
+ unlink($zip_filename);
+ } //$user->uid
+ else {
+ header('Content-Type: application/zip');
+ header('Content-disposition: attachment; filename="' . str_replace(' ', '_', $case_study_data->project_title) . '.zip"');
+ header('Content-Length: ' . filesize($zip_filename));
+ header("Content-Transfer-Encoding: binary");
+ header('Expires: 0');
+ header('Pragma: no-cache');
+ ob_end_flush();
+ ob_clean();
+ flush();
+ readfile($zip_filename);
+ unlink($zip_filename);
+ }
+ } //$zip_file_count > 0
+ else {
+ drupal_set_message("There are no case study project in this proposal to download", 'error');
+ drupal_goto('circuit-simulation-project/full-download/project');
+ }
+} \ No newline at end of file
diff --git a/general_deletion.inc b/general_deletion.inc
new file mode 100644
index 0000000..4cf6917
--- /dev/null
+++ b/general_deletion.inc
@@ -0,0 +1,43 @@
+<?php
+/******************************************************************************/
+/****************************** DELETION FUNCTIONS ****************************/
+/******************************************************************************/
+function scilab_case_study_abstract_delete_project($proposal_id)
+{
+ $status = TRUE;
+ $root_path = scilab_case_study_path();
+ $query = db_select('case_study_proposal');
+ $query->fields('case_study_proposal');
+ $query->condition('id', $proposal_id);
+ $proposal_q = $query->execute();
+ $proposal_data = $proposal_q->fetchObject();
+ if (!$proposal_data)
+ {
+ drupal_set_message('Invalid Case Study Project.', 'error');
+ return FALSE;
+ } //!$proposal_data
+ $query = db_select('case_study_submitted_abstracts_file');
+ $query->fields('case_study_submitted_abstracts_file');
+ $query->condition('proposal_id', $proposal_id);
+ $abstract_q = $query->execute();
+ $dir_project_files = $root_path . $proposal_data->directory_name;
+ while ($abstract_data = $abstract_q->fetchObject())
+ {
+ if (is_dir($dir_project_files)){
+
+ unlink($root_path . $proposal_data->directory_name . '/project_files/' . $abstract_data->filepath);
+ }
+ else
+ {
+ drupal_set_message('Invalid case study project abstract.', 'error');
+ }
+ db_delete('case_study_submitted_abstracts_file')->condition('proposal_id', $proposal_id)->execute();
+ //!dwsim_flowsheet_delete_abstract_file($abstract_data->id)
+ }
+ $res = rmdir($root_path . $proposal_data->directory_name . '/project_files/');
+ db_delete('case_study_submitted_abstracts')->condition('proposal_id', $proposal_id)->execute();
+ unlink($root_path .'/' . $proposal_data->samplefilepath);
+ $res = rmdir($root_path . $proposal_data->directory_name);
+ db_delete('case_study_proposal')->condition('id', $proposal_data->id)->execute();
+ return $status;
+}
diff --git a/manage_proposal.inc b/manage_proposal.inc
new file mode 100644
index 0000000..687d8f0
--- /dev/null
+++ b/manage_proposal.inc
@@ -0,0 +1,1211 @@
+<?php
+// $Id$
+function scilab_case_study_proposal_pending()
+{
+ /* get pending proposals to be approved */
+ $pending_rows = array();
+ $query = db_select('case_study_proposal');
+ $query->fields('case_study_proposal');
+ $query->condition('approval_status', 0);
+ $query->orderBy('id', 'DESC');
+ $pending_q = $query->execute();
+ while ($pending_data = $pending_q->fetchObject()) {
+ $pending_rows[$pending_data->id] = array(
+ date('d-m-Y', $pending_data->creation_date),
+ l($pending_data->name_title . ' ' . $pending_data->contributor_name, 'user/' . $pending_data->uid),
+ $pending_data->project_title,
+ l('Approve', 'case-study-project/manage-proposal/approve/' . $pending_data->id) . ' | ' . l('Edit', 'case-study-project/manage-proposal/edit/' . $pending_data->id),
+ );
+ } //$pending_data = $pending_q->fetchObject()
+ /* check if there are any pending proposals */
+ if (!$pending_rows) {
+ drupal_set_message(t('There are no pending proposals.'), 'status');
+ return '';
+ } //!$pending_rows
+ $pending_header = array(
+ 'Date of Submission',
+ 'Student Name',
+ 'Title of the Case Study Project',
+ 'Action',
+ );
+ //$output = theme_table($pending_header, $pending_rows);
+ $output = theme('table', array(
+ 'header' => $pending_header,
+ 'rows' => $pending_rows,
+ ));
+ return $output;
+}
+function scilab_case_study_proposal_all()
+{
+ /* get pending proposals to be approved */
+ $proposal_rows = array();
+ $query = db_select('case_study_proposal');
+ $query->fields('case_study_proposal');
+ $query->orderBy('id', 'DESC');
+ $proposal_q = $query->execute();
+ while ($proposal_data = $proposal_q->fetchObject()) {
+ $approval_status = '';
+ switch ($proposal_data->approval_status) {
+ case 0:
+ $approval_status = 'Pending';
+ break;
+ case 1:
+ $approval_status = 'Approved | ' . l('Send Reminder Mail', 'case-study-project/manage-proposal/send-reminder-mail/' . $proposal_data->id);
+ break;
+ case 2:
+ $approval_status = 'Dis-approved';
+ break;
+ case 3:
+ $approval_status = 'Completed';
+ break;
+ case 5:
+ $approval_status = 'On Hold';
+ break;
+ default:
+ $approval_status = 'Unknown';
+ break;
+ } //$proposal_data->approval_status
+ if ($proposal_data->actual_completion_date == 0) {
+ $actual_completion_date = "Not Completed";
+ } //$proposal_data->actual_completion_date == 0
+ else {
+ $actual_completion_date = date('d-m-Y', $proposal_data->actual_completion_date);
+ }
+ if ($proposal_data->approval_date == 0) {
+ $approval_date = "Not Approved";
+ } //$proposal_data->actual_completion_date == 0
+ else {
+ $approval_date = date('d-m-Y', $proposal_data->approval_date);
+ }
+ $proposal_rows[] = array(
+ date('d-m-Y', $proposal_data->creation_date),
+ l($proposal_data->contributor_name, 'user/' . $proposal_data->uid),
+ $proposal_data->project_title,
+ $approval_date,
+ $actual_completion_date,
+ $approval_status,
+ l('Status', 'case-study-project/manage-proposal/status/' . $proposal_data->id) . ' | ' . l('Edit', 'case-study-project/manage-proposal/edit/' . $proposal_data->id),
+ );
+ } //$proposal_data = $proposal_q->fetchObject()
+ /* check if there are any pending proposals */
+ if (!$proposal_rows) {
+ drupal_set_message(t('There are no proposals.'), 'status');
+ return '';
+ } //!$proposal_rows
+ $proposal_header = array(
+ 'Date of Submission',
+ 'Student Name',
+ 'Title of the case-study project',
+ 'Date of Approval',
+ 'Date of Project Completion',
+ 'Status',
+ 'Action',
+ );
+ $output = theme('table', array(
+ 'header' => $proposal_header,
+ 'rows' => $proposal_rows,
+ ));
+ return $output;
+}
+function scilab_case_study_proposal_edit_file_all()
+{
+ /* get pending proposals to be approved */
+ $proposal_rows = array();
+ $query = db_select('case_study_proposal');
+ $query->fields('case_study_proposal');
+ $query->orderBy('id', 'DESC');
+ $query->condition('approval_status', '0', '<>');
+ $query->condition('approval_status', '1', '<>');
+ $query->condition('approval_status', '2', '<>');
+ $query->orderBy('approval_status', 'DESC');
+ $proposal_q = $query->execute();
+ while ($proposal_data = $proposal_q->fetchObject()) {
+ $approval_status = '';
+ switch ($proposal_data->approval_status) {
+ case 0:
+ $approval_status = 'Pending';
+ break;
+ case 1:
+ $approval_status = 'Approved';
+ break;
+ case 2:
+ $approval_status = 'Dis-approved';
+ break;
+ case 3:
+ $approval_status = 'Completed';
+ break;
+ case 5:
+ $approval_status = 'On Hold';
+ break;
+ default:
+ $approval_status = 'Unknown';
+ break;
+ } //$proposal_data->approval_status
+ if ($proposal_data->actual_completion_date == 0) {
+ $actual_completion_date = "Not Completed";
+ } //$proposal_data->actual_completion_date == 0
+ else {
+ $actual_completion_date = date('d-m-Y', $proposal_data->actual_completion_date);
+ }
+ if ($proposal_data->approval_date == 0) {
+ $approval_date = "Not Approved";
+ } //$proposal_data->actual_completion_date == 0
+ else {
+ $approval_date = date('d-m-Y', $proposal_data->approval_date);
+ }
+ $proposal_rows[] = array(
+ date('d-m-Y', $proposal_data->creation_date),
+ l($proposal_data->contributor_name, 'user/' . $proposal_data->uid),
+ $proposal_data->project_title,
+ $approval_date,
+ $actual_completion_date,
+ $approval_status,
+ l('Edit', 'case-study-project/abstract-code/edit-upload-files/' . $proposal_data->id),
+ );
+ } //$proposal_data = $proposal_q->fetchObject()
+ /* check if there are any pending proposals */
+ if (!$proposal_rows) {
+ drupal_set_message(t('There are no proposals.'), 'status');
+ return '';
+ } //!$proposal_rows
+ $proposal_header = array(
+ 'Date of Submission',
+ 'Student Name',
+ 'Title of the case-study project',
+ 'Date of Approval',
+ 'Date of Project Completion',
+ 'Status',
+ 'Action',
+ );
+ $output = theme('table', array(
+ 'header' => $proposal_header,
+ 'rows' => $proposal_rows,
+ ));
+ return $output;
+}
+/******************************************************************************/
+/************************** PROPOSAL APPROVAL FORM ****************************/
+/******************************************************************************/
+function scilab_case_study_proposal_approval_form($form, &$form_state)
+{
+ global $user;
+ /* get current proposal */
+ $proposal_id = (int) arg(3);
+ $query = db_select('case_study_proposal');
+ $query->fields('case_study_proposal');
+ $query->condition('id', $proposal_id);
+ $proposal_q = $query->execute();
+ if ($proposal_q) {
+ if ($proposal_data = $proposal_q->fetchObject()) {
+ /* everything ok */
+ } //$proposal_data = $proposal_q->fetchObject()
+ else {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('case-study-project/manage-proposal/all');
+ return;
+ }
+ } //$proposal_q
+ else {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('case-study-project/manage-proposal/all');
+ return;
+ }
+ if ($proposal_data->faculty_name == '') {
+ $faculty_name = 'NA';
+ } else {
+ $faculty_name = $proposal_data->faculty_name;
+ }
+ if ($proposal_data->faculty_department == '') {
+ $faculty_department = 'NA';
+ } else {
+ $faculty_department = $proposal_data->faculty_department;
+ }
+ if ($proposal_data->faculty_email == '') {
+ $faculty_email = 'NA';
+ } else {
+ $faculty_email = $proposal_data->faculty_email;
+ }
+ $form['contributor_name'] = array(
+ '#type' => 'item',
+ '#markup' => l($proposal_data->name_title . ' ' . $proposal_data->contributor_name, 'user/' . $proposal_data->uid),
+ '#title' => t('Student name'),
+ );
+ $form['student_email_id'] = array(
+ '#title' => t('Student Email'),
+ '#type' => 'item',
+ '#markup' => user_load($proposal_data->uid)->mail,
+ '#title' => t('Email'),
+ );
+ $form['contributor_contact_no'] = array(
+ '#title' => t('Contact No.'),
+ '#type' => 'item',
+ '#markup' => $proposal_data->contact_no,
+ );
+ $form['university'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->university,
+ '#title' => t('University'),
+ );
+ $form['institute'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->institute,
+ '#title' => t('Institute'),
+ );
+ $form['how_did_you_know_about_project'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->how_did_you_know_about_project,
+ '#title' => t('How did you know about the project'),
+ );
+ $form['faculty_name'] = array(
+ '#type' => 'item',
+ '#markup' => $faculty_name,
+ '#title' => t('Name of the faculty'),
+ );
+ $form['faculty_department'] = array(
+ '#type' => 'item',
+ '#markup' => $faculty_department,
+ '#title' => t('Department of the faculty'),
+ );
+ $form['faculty_email'] = array(
+ '#type' => 'item',
+ '#markup' => $faculty_email,
+ '#title' => t('Email of the faculty'),
+ );
+ $form['country'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->country,
+ '#title' => t('Country'),
+ );
+ $form['all_state'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->state,
+ '#title' => t('State'),
+ );
+ $form['city'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->city,
+ '#title' => t('City'),
+ );
+ $form['pincode'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->pincode,
+ '#title' => t('Pincode/Postal code'),
+ );
+ $form['project_title'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->project_title,
+ '#title' => t('Title of the Case Study Project'),
+ );
+ $form['operating_system'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->operating_system,
+ '#title' => t('Operating System'),
+ );
+ $form['scilab_version'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->scilab_version,
+ '#title' => t('Scilab Version used'),
+ );
+ $form['date_of_proposal'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Date of Proposal'),
+ '#default_value' => date('d/m/Y', $proposal_data->creation_date),
+ '#disabled' => true,
+ );
+ $form['expected_completion_date'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Expected Date of Completion'),
+ '#default_value' => date('d/m/Y', $proposal_data->expected_date_of_completion),
+ '#disabled' => true,
+ );
+ if (($proposal_data->samplefilepath != "") && ($proposal_data->samplefilepath != 'NULL')) {
+ $str = substr($proposal_data->samplefilepath, strrpos($proposal_data->samplefilepath, '/'));
+ $resource_file = ltrim($str, '/');
+
+ $form['abstract_file_path'] = array(
+ '#type' => 'item',
+ '#title' => t('Abstract file '),
+ '#markup' => l($resource_file, 'case-study-project/download/proposal-abstract/' . $proposal_id) . "",
+ );
+ } //$proposal_data->user_defined_compound_filepath != ""
+ else {
+ $form['abstract_file_path'] = array(
+ '#type' => 'item',
+ '#title' => t('Abstract file '),
+ '#markup' => "Not uploaded<br><br>",
+ );
+ }
+ $form['approval'] = array(
+ '#type' => 'radios',
+ '#title' => t('Select an action for the case study'),
+ '#options' => array(
+ '1' => 'Approve',
+ '2' => 'Disapprove',
+ ),
+ '#required' => true,
+ );
+ $form['message'] = array(
+ '#type' => 'textarea',
+ '#title' => t('Reason for disapproval'),
+ '#attributes' => array(
+ 'placeholder' => t('Enter reason for disapproval in minimum 30 characters '),
+ 'cols' => 50,
+ 'rows' => 4,
+ ),
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="approval"]' => array(
+ 'value' => '2',
+ ),
+ ),
+ ),
+ );
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit'),
+ );
+ $form['cancel'] = array(
+ '#type' => 'item',
+ '#markup' => l(t('Cancel'), 'case-study-project/manage-proposal/all'),
+ );
+ return $form;
+}
+function scilab_case_study_proposal_approval_form_validate($form, &$form_state)
+{
+ if ($form_state['values']['approval'] == 2) {
+ if ($form_state['values']['message'] == '') {
+ form_set_error('message', t('Reason for disapproval could not be empty'));
+ } //$form_state['values']['message'] == ''
+ } //$form_state['values']['approval'] == 2
+}
+function scilab_case_study_proposal_approval_form_submit($form, &$form_state)
+{
+ global $user;
+ /* get current proposal */
+ $proposal_id = (int) arg(3);
+ $query = db_select('case_study_proposal');
+ $query->fields('case_study_proposal');
+ $query->condition('id', $proposal_id);
+ $proposal_q = $query->execute();
+ if ($proposal_q) {
+ if ($proposal_data = $proposal_q->fetchObject()) {
+ /* everything ok */
+ } //$proposal_data = $proposal_q->fetchObject()
+ else {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('case-study-project/manage-proposal/all');
+ return;
+ }
+ } //$proposal_q
+ else {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('case-study-project/manage-proposal/all');
+ return;
+ }
+ if ($form_state['values']['approval'] == 1) {
+ $query = "UPDATE {case_study_proposal} SET approver_uid = :uid, approval_date = :date, approval_status = 1 WHERE id = :proposal_id";
+ $args = array(
+ ":uid" => $user->uid,
+ ":date" => time(),
+ ":proposal_id" => $proposal_id,
+ );
+ db_query($query, $args);
+ /* sending email */
+ $user_data = user_load($proposal_data->uid);
+ $email_to = $user_data->mail;
+ $from = variable_get('case_study_from_email', '');
+ $bcc = $user->mail . ', ' . variable_get('case_study_emails', '');
+ $cc = variable_get('case_study_cc_emails', '');
+ $params['case_study_proposal_approved']['proposal_id'] = $proposal_id;
+ $params['case_study_proposal_approved']['user_id'] = $proposal_data->uid;
+ $params['case_study_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('scilab_case_study', 'case_study_proposal_approved', $email_to, language_default(), $params, $from, true)) {
+ drupal_set_message('Error sending email message.', 'error');
+ }
+
+ drupal_set_message('Case Study with the proposal No. ' . $proposal_id . ' has been approved and the user is notified of the approval via email.', 'status');
+ drupal_goto('case-study-project/manage-proposal/all');
+ return;
+ } //$form_state['values']['approval'] == 1
+ else if ($form_state['values']['approval'] == 2) {
+ $query = "UPDATE {case_study_proposal} SET approver_uid = :uid, approval_date = :date, approval_status = 2, dissapproval_reason = :dissapproval_reason WHERE id = :proposal_id";
+ $args = array(
+ ":uid" => $user->uid,
+ ":date" => time(),
+ ":dissapproval_reason" => $form_state['values']['message'],
+ ":proposal_id" => $proposal_id,
+ );
+ $result = db_query($query, $args);
+ /* sending email */
+ $user_data = user_load($proposal_data->uid);
+ $email_to = $user_data->mail;
+ $from = variable_get('case_study_from_email', '');
+ $bcc = $user->mail . ', ' . variable_get('case_study_emails', '');
+ $cc = variable_get('case_study_cc_emails', '');
+ $params['case_study_proposal_disapproved']['proposal_id'] = $proposal_id;
+ $params['case_study_proposal_disapproved']['user_id'] = $proposal_data->uid;
+ $params['case_study_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('scilab_case_study', 'case_study_proposal_disapproved', $email_to, language_default(), $params, $from, true)) {
+ drupal_set_message('Error sending email message.', 'error');
+ }
+
+ drupal_set_message('Case Study with the proposal No. ' . $proposal_id . ' is dis-approved and the useris notified of the dis-approval via email.', 'error');
+ drupal_goto('case-study-project/manage-proposal/all');
+ return;
+ } //$form_state['values']['approval'] == 2
+}
+/******************************************************************************/
+/*************************** PROPOSAL STATUS FORM *****************************/
+/******************************************************************************/
+function scilab_case_study_proposal_status_form($form, &$form_state)
+{
+ global $user;
+ /* get current proposal */
+ $proposal_id = (int) arg(3);
+ $query = db_select('case_study_proposal');
+ $query->fields('case_study_proposal');
+ $query->condition('id', $proposal_id);
+ $proposal_q = $query->execute();
+ $query_abstract = db_select('case_study_submitted_abstracts_file');
+ $query_abstract->fields('case_study_submitted_abstracts_file');
+ $query_abstract->condition('proposal_id', $proposal_id);
+ $query_abstract->condition('filetype', 'A');
+ $query_abstract_pdf = $query_abstract->execute()->fetchObject();
+ if ($proposal_q) {
+ if ($proposal_data = $proposal_q->fetchObject()) {
+ /* everything ok */
+ } //$proposal_data = $proposal_q->fetchObject()
+ else {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('case-study-project/manage-proposal/all');
+ return;
+ }
+ } //$proposal_q
+ else {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('case-study-project/manage-proposal/all');
+ return;
+ }
+ if ($proposal_data->faculty_name == '') {
+ $faculty_name = 'NA';
+ } else {
+ $faculty_name = $proposal_data->faculty_name;
+ }
+ if ($proposal_data->faculty_department == '') {
+ $faculty_department = 'NA';
+ } else {
+ $faculty_department = $proposal_data->faculty_department;
+ }
+ if ($proposal_data->faculty_email == '') {
+ $faculty_email = 'NA';
+ } else {
+ $faculty_email = $proposal_data->faculty_email;
+ }
+ $form['contributor_name'] = array(
+ '#type' => 'item',
+ '#markup' => l($proposal_data->name_title . ' ' . $proposal_data->contributor_name, 'user/' . $proposal_data->uid),
+ '#title' => t('Student name'),
+ );
+ $form['student_email_id'] = array(
+ '#title' => t('Contributor Email'),
+ '#type' => 'item',
+ '#markup' => user_load($proposal_data->uid)->mail,
+ '#title' => t('Email'),
+ );
+ $form['contact_no'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->contact_no,
+ '#title' => t('Contact no'),
+ );
+ $form['university'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->university,
+ '#title' => t('University'),
+ );
+ $form['institute'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->institute,
+ '#title' => t('Institute'),
+ );
+ $form['how_did_you_know_about_project'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->how_did_you_know_about_project,
+ '#title' => t('How did you know about the project'),
+ );
+ $form['faculty_name'] = array(
+ '#type' => 'item',
+ '#markup' => $faculty_name,
+ '#title' => t('Name of the faculty'),
+ );
+ $form['faculty_department'] = array(
+ '#type' => 'item',
+ '#markup' => $faculty_department,
+ '#title' => t('Department of the faculty'),
+ );
+ $form['faculty_email'] = array(
+ '#type' => 'item',
+ '#markup' => $faculty_email,
+ '#title' => t('Email of the faculty'),
+ );
+ $form['country'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->country,
+ '#title' => t('Country'),
+ );
+ $form['all_state'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->state,
+ '#title' => t('State'),
+ );
+ $form['city'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->city,
+ '#title' => t('City'),
+ );
+ $form['pincode'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->pincode,
+ '#title' => t('Pincode/Postal code'),
+ );
+ $form['project_title'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->project_title,
+ '#title' => t('Title of the Case Study Project'),
+ );
+ $form['operating_system'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->operating_system,
+ '#title' => t('Operating System'),
+ );
+ $form['scilab_version'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->scilab_version,
+ '#title' => t('Version used'),
+ );
+ /************************** reference link filter *******************/
+/* $url = '~(?:(https?)://([^\s<]+)|(www\.[^\s<]+?\.[^\s<]+))(?<![\.,:])~i';
+ $reference = preg_replace($url, '<a href="$0" target="_blank" title="$0">$0</a>', $proposal_data->reference);*/
+ /******************************/
+ /*$form['reference'] = array(
+ '#type' => 'item',
+ '#markup' => $reference,
+ '#title' => t('References')
+ );*/
+ if (($proposal_data->samplefilepath != "") && ($proposal_data->samplefilepath != 'NULL')) {
+ $str = substr($proposal_data->samplefilepath, strrpos($proposal_data->samplefilepath, '/'));
+ $resource_file = ltrim($str, '/');
+
+ $form['abstract_file_path'] = array(
+ '#type' => 'item',
+ '#title' => t('Abstract file '),
+ '#markup' => l($resource_file, 'case-study-project/download/proposal-abstract/' . $proposal_id) . "",
+ );
+ } //$proposal_data->user_defined_compound_filepath != ""
+ else {
+ $form['abstract_file_path'] = array(
+ '#type' => 'item',
+ '#title' => t('Abstract file '),
+ '#markup' => "Not uploaded<br><br>",
+ );
+ }
+ $proposal_status = '';
+ switch ($proposal_data->approval_status) {
+ case 0:
+ $proposal_status = t('Pending');
+ break;
+ case 1:
+ $proposal_status = t('Approved');
+ break;
+ case 2:
+ $proposal_status = t('Dis-approved');
+ break;
+ case 3:
+ $proposal_status = t('Completed');
+ break;
+ case 5:
+ $approval_status = t('On Hold');
+ break;
+ default:
+ $proposal_status = t('Unkown');
+ break;
+ }
+ $form['proposal_status'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_status,
+ '#title' => t('Proposal Status'),
+ );
+ if ($proposal_data->approval_status == 0) {
+ $form['approve'] = array(
+ '#type' => 'item',
+ '#markup' => l('Click here', 'case-study-project/manage-proposal/approve/' . $proposal_id),
+ '#title' => t('Approve'),
+ );
+ } //$proposal_data->approval_status == 0
+ if ($proposal_data->approval_status == 1) {
+ $form['completed'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Completed'),
+ '#description' => t('Check if user has provided all the required files and pdfs.'),
+ );
+ } //$proposal_data->approval_status == 1
+ if ($proposal_data->approval_status == 2) {
+ $form['message'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->message,
+ '#title' => t('Reason for disapproval'),
+ );
+ } //$proposal_data->approval_status == 2
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit'),
+ );
+ $form['cancel'] = array(
+ '#type' => 'markup',
+ '#markup' => l(t('Cancel'), 'case-study-project/manage-proposal/all'),
+ );
+ return $form;
+}
+function scilab_case_study_proposal_status_form_submit($form, &$form_state)
+{
+ global $user;
+ /* get current proposal */
+ $proposal_id = (int) arg(3);
+ //$proposal_q = db_query("SELECT * FROM {case_study_proposal} WHERE id = %d", $proposal_id);
+ $query = db_select('case_study_proposal');
+ $query->fields('case_study_proposal');
+ $query->condition('id', $proposal_id);
+ $proposal_q = $query->execute();
+ if ($proposal_q) {
+ if ($proposal_data = $proposal_q->fetchObject()) {
+ /* everything ok */
+ } //$proposal_data = $proposal_q->fetchObject()
+ else {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('case-study-project/manage-proposal/all');
+ return;
+ }
+ } //$proposal_q
+ else {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('case-study-project/manage-proposal/all');
+ return;
+ }
+ /* set the book status to completed */
+ if ($form_state['values']['completed'] == 1) {
+ $up_query = "UPDATE case_study_proposal SET approval_status = :approval_status , actual_completion_date = :expected_completion_date WHERE id = :proposal_id";
+ $args = array(
+ ":approval_status" => '3',
+ ":proposal_id" => $proposal_id,
+ ":expected_completion_date" => time(),
+ );
+ $result = db_query($up_query, $args);
+ CreateReadmeFileCaseStudyProject($proposal_id);
+ if (!$result) {
+ drupal_set_message('Error in update status', 'error');
+ return;
+ } //!$result
+ /* sending email */
+ $user_data = user_load($proposal_data->uid);
+ $email_to = $user_data->mail;
+ $from = variable_get('case_study_from_email', '');
+ $bcc = $user->mail . ', ' . variable_get('case_study_emails', '');
+ $cc = variable_get('case_study_cc_emails', '');
+ $params['case_study_proposal_completed']['proposal_id'] = $proposal_id;
+ $params['case_study_proposal_completed']['user_id'] = $proposal_data->uid;
+ $params['case_study_proposal_completed']['headers'] = array(
+ 'From' => $from,
+ 'MIME-Version' => '1.0',
+ 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
+ 'Content-Transfer-Encoding' => '8Bit',
+ 'X-Mailer' => 'Drupal',
+ 'Cc' => $cc,
+ 'Bcc' => $bcc,
+ );
+ if (!drupal_mail('scilab_case_study', 'case_study_proposal_completed', $email_to, language_default(), $params, $from, true)) {
+ drupal_set_message('Error sending email message.', 'error');
+ }
+
+ drupal_set_message('Scilab Case Study proposal has been marked as completed. User has been notified of the completion.', 'status');
+ }
+ drupal_goto('case-study-project/manage-proposal/all');
+ return;
+
+}
+/******************************************************************************/
+/**************************** PROPOSAL EDIT FORM ******************************/
+/******************************************************************************/
+function scilab_case_study_proposal_edit_form($form, &$form_state)
+{
+ global $user;
+ /* get current proposal */
+ $proposal_id = (int) arg(3);
+ //$proposal_q = db_query("SELECT * FROM {case_study_proposal} WHERE id = %d", $proposal_id);
+ $query = db_select('case_study_proposal');
+ $query->fields('case_study_proposal');
+ $query->condition('id', $proposal_id);
+ $proposal_q = $query->execute();
+ $proposal_data = $proposal_q->fetchObject();
+ /*if ($proposal_q) {
+ if ($proposal_data = $proposal_q->fetchObject()) {
+ /* everything ok
+ } //$proposal_data = $proposal_q->fetchObject()
+ else {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('case-study-project/manage-proposal/all');
+ return;
+ }
+ } //$proposal_q
+ else {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('case-study-project/manage-proposal/all');
+ return;
+ }*/
+ $user_data = user_load($proposal_data->uid);
+ $form['name_title'] = array(
+ '#type' => 'select',
+ '#title' => t('Title'),
+ '#options' => array(
+ 'Dr' => 'Dr',
+ 'Prof' => 'Prof',
+ 'Mr' => 'Mr',
+ 'Ms' => 'Ms',
+ ),
+ '#required' => true,
+ '#default_value' => $proposal_data->name_title,
+ );
+ $form['contributor_name'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Name of the Proposer'),
+ '#size' => 30,
+ '#maxlength' => 50,
+ '#required' => true,
+ '#default_value' => $proposal_data->contributor_name,
+ );
+ $form['student_email_id'] = array(
+ '#type' => 'item',
+ '#title' => t('Email'),
+ '#markup' => $user_data->mail,
+ );
+ $form['university'] = array(
+ '#type' => 'textfield',
+ '#title' => t('University/Institute'),
+ '#size' => 200,
+ '#maxlength' => 200,
+ '#required' => true,
+ '#default_value' => $proposal_data->university,
+ );
+ $form['institute'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Institute'),
+ '#size' => 80,
+ '#maxlength' => 200,
+ '#required' => true,
+ '#default_value' => $proposal_data->institute,
+ );
+ $form['faculty_name'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Name of the Faculty'),
+ '#size' => 50,
+ '#maxlength' => 50,
+ '#validated' => true,
+ '#default_value' => $proposal_data->faculty_name,
+ );
+ $form['faculty_department'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Department of the Faculty'),
+ '#size' => 50,
+ '#maxlength' => 50,
+ '#validated' => true,
+ '#default_value' => $proposal_data->faculty_department,
+ );
+ $form['faculty_email'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Email id of the Faculty'),
+ '#size' => 255,
+ '#maxlength' => 255,
+ '#validated' => true,
+ '#default_value' => $proposal_data->faculty_email,
+ );
+ $form['country'] = array(
+ '#type' => 'select',
+ '#title' => t('Country'),
+ '#options' => array(
+ 'India' => 'India',
+ 'Others' => 'Others',
+ ),
+ '#default_value' => $proposal_data->country,
+ '#required' => true,
+ '#tree' => true,
+ '#validated' => true,
+ );
+ $form['other_country'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Other than India'),
+ '#size' => 100,
+ '#default_value' => $proposal_data->country,
+ '#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'),
+ ),
+ '#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' => _cs_list_of_states(),
+ '#default_value' => $proposal_data->state,
+ '#validated' => true,
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="country"]' => array(
+ 'value' => 'India',
+ ),
+ ),
+ ),
+ );
+ $form['city'] = array(
+ '#type' => 'select',
+ '#title' => t('City'),
+ '#options' => _cs_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,
+ '#attributes' => array(
+ 'placeholder' => 'Insert pincode of your city/ village....',
+ ),
+ );
+ $form['project_title'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Title of the Case Study Project'),
+ '#size' => 300,
+ '#maxlength' => 350,
+ '#required' => true,
+ '#default_value' => $proposal_data->project_title,
+ );
+ $form['operating_system'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Operating System'),
+ '#default_value' => $proposal_data->operating_system
+ );
+ $form['scilab_version'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Scilab Version used'),
+ '#default_value' => $proposal_data->scilab_version
+ );
+ $form['date_of_proposal'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Date of Proposal'),
+ '#default_value' => date('d/m/Y', $proposal_data->creation_date),
+ '#disabled' => true,
+ );
+ $form['delete_proposal'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Delete Proposal'),
+ );
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit'),
+ );
+ $form['cancel'] = array(
+ '#type' => 'item',
+ '#markup' => l(t('Cancel'), 'case-study-project/manage-proposal/all'),
+ );
+ return $form;
+}
+
+function scilab_case_study_proposal_edit_form_validate($form, $form_state){
+
+}
+function scilab_case_study_proposal_edit_form_submit($form, &$form_state)
+{
+ global $user;
+ /* get current proposal */
+ $proposal_id = (int) arg(3);
+ $query = db_select('case_study_proposal');
+ $query->fields('case_study_proposal');
+ $query->condition('id', $proposal_id);
+ $proposal_q = $query->execute();
+ if ($proposal_q) {
+ if ($proposal_data = $proposal_q->fetchObject()) {
+ /* everything ok */
+ } //$proposal_data = $proposal_q->fetchObject()
+ else {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('case-study-project/manage-proposal/all');
+ return;
+ }
+ } //$proposal_q
+ else {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('case-study-project/manage-proposal/all');
+ return;
+ }
+ /* delete proposal */
+ if ($form_state['values']['delete_proposal'] == 1) {
+ /* sending email */
+ $user_data = user_load($proposal_data->uid);
+ $email_to = $user_data->mail;
+ $from = variable_get('case_study_from_email', '');
+ $bcc = variable_get('case_study_emails', '');
+ $cc = variable_get('case_study_cc_emails', '');
+ $params['case_study_proposal_deleted']['proposal_id'] = $proposal_id;
+ $params['case_study_proposal_deleted']['user_id'] = $proposal_data->uid;
+ $params['case_study_proposal_deleted']['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('scilab_case_study', 'case_study_proposal_deleted', $email_to, user_preferred_language($user), $params, $from, true)) {
+ drupal_set_message('Error sending email message.', 'error');
+ }
+
+ drupal_set_message(t('Case Study proposal has been deleted.'), 'status');
+ if (rrmdir_project($proposal_id) == true) {
+ $query = db_delete('case_study_proposal');
+ $query->condition('id', $proposal_id);
+ $num_deleted = $query->execute();
+ drupal_set_message(t('Proposal Deleted'), 'status');
+ drupal_goto('case-study-project/manage-proposal/all');
+ return;
+ } //rrmdir_project($proposal_id) == TRUE
+ } //$form_state['values']['delete_proposal'] == 1
+ /* update proposal */
+ $v = $form_state['values'];
+ $project_title = $v['project_title'];
+ $proposar_name = $v['name_title'] . ' ' . $v['contributor_name'];
+ $university = $v['university'];
+ $directory_names = _cs_dir_name($project_title, $proposar_name);
+ if (CS_RenameDir($proposal_id, $directory_names)) {
+ $directory_name = $directory_names;
+ } //LM_RenameDir($proposal_id, $directory_names)
+ else {
+ return;
+ }
+ $str = substr($proposal_data->samplefilepath, strrpos($proposal_data->samplefilepath, '/'));
+ $resource_file = ltrim($str, '/');
+ $samplefilepath = $directory_name . '/' . $resource_file;
+ $query = "UPDATE case_study_proposal SET
+ name_title=:name_title,
+ contributor_name=:contributor_name,
+ university=:university,
+ institute=:institute,
+ faculty_name = :faculty_name,
+ faculty_department = :faculty_department,
+ faculty_email = :faculty_email,
+ city=:city,
+ pincode=:pincode,
+ state=:state,
+ project_title=:project_title,
+ operating_system=:operating_system,
+ scilab_version=:scilab_version,
+ directory_name=:directory_name,
+ samplefilepath = :samplefilepath
+ WHERE id=:proposal_id";
+ $args = array(
+ ':name_title' => $v['name_title'],
+ ':contributor_name' => $v['contributor_name'],
+ ':university' => $v['university'],
+ ":institute" => $v['institute'],
+ ":faculty_name" => $v['faculty_name'],
+ ":faculty_department" => $v['faculty_department'],
+ ":faculty_email" => $v['faculty_email'],
+ ':city' => $v['city'],
+ ':pincode' => $v['pincode'],
+ ':state' => $v['all_state'],
+ ':project_title' => $project_title,
+ ':operating_system' => $v['operating_system'],
+ ':scilab_version' => $v['scilab_version'],
+ ':directory_name' => $directory_name,
+ ':samplefilepath' => $samplefilepath,
+ ':proposal_id' => $proposal_id,
+ );
+ $result = db_query($query, $args);
+ drupal_set_message(t('Proposal Updated'), 'status');
+}
+
+
+/******************************************************************************/
+/*************************** Reminder mail about the proposal *****************************/
+/******************************************************************************/
+function scilab_case_study_proposal_send_reminder_mail_form($form, &$form_state)
+{
+ global $user;
+ /* get current proposal */
+ $proposal_id = (int) arg(3);
+ $query = db_select('case_study_proposal');
+ $query->fields('case_study_proposal');
+ $query->condition('id', $proposal_id);
+ $proposal_q = $query->execute();
+ if ($proposal_q) {
+ if ($proposal_data = $proposal_q->fetchObject()) {
+ /* everything ok */
+ } //$proposal_data = $proposal_q->fetchObject()
+ else {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('case-study-project/manage-proposal/all');
+ return;
+ }
+ } //$proposal_q
+ else {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('case-study-project/manage-proposal/all');
+ return;
+ }
+ $form['contributor_name'] = array(
+ '#type' => 'item',
+ '#markup' => l($proposal_data->name_title . ' ' . $proposal_data->contributor_name, 'user/' . $proposal_data->uid),
+ '#title' => t('Student name'),
+ );
+ $form['student_email_id'] = array(
+ '#title' => t('Contributor Email'),
+ '#type' => 'item',
+ '#markup' => user_load($proposal_data->uid)->mail,
+ '#title' => t('Email'),
+ );
+ $form['contact_no'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->contact_no,
+ '#title' => t('Contact no'),
+ );
+ $form['project_title'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->project_title,
+ '#title' => t('Title of the Case Study Project'),
+ );
+ $form['expected_completion_date'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Expected Date of Completion'),
+ '#default_value' => date('d/m/Y', $proposal_data->expected_date_of_completion),
+ '#disabled' => true,
+ );
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Click to send mail to the contributor'),
+ );
+ $form['cancel'] = array(
+ '#type' => 'item',
+ '#markup' => l(t('Cancel'), 'case-study-project/manage-proposal/all'),
+ );
+ return $form;
+}
+function scilab_case_study_proposal_send_reminder_mail_form_submit($form, &$form_state)
+{
+ global $user;
+ /* get current proposal */
+ $proposal_id = (int) arg(3);
+ //$proposal_q = db_query("SELECT * FROM {case_study_proposal} WHERE id = %d", $proposal_id);
+ $query = db_select('case_study_proposal');
+ $query->fields('case_study_proposal');
+ $query->condition('id', $proposal_id);
+ $proposal_q = $query->execute();
+ if ($proposal_q) {
+ if ($proposal_data = $proposal_q->fetchObject()) {
+ /* everything ok */
+ } //$proposal_data = $proposal_q->fetchObject()
+ else {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('case-study-project/manage-proposal/all');
+ return;
+ }
+ } //$proposal_q
+ else {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('case-study-project/manage-proposal/all');
+ return;
+ }
+ /* set the book status to completed */
+ /* sending email */
+ $user_data = user_load($proposal_data->uid);
+ $email_to = $user_data->mail;
+ $from = variable_get('case_study_from_email', '');
+ $bcc = $user->mail . ', ' . variable_get('case_study_emails', '');
+ $cc = variable_get('case_study_cc_emails', '');
+ $params['case_study_proposal_send_reminder_mail']['proposal_id'] = $proposal_id;
+ $params['case_study_proposal_send_reminder_mail']['user_id'] = $proposal_data->uid;
+ $params['case_study_proposal_send_reminder_mail']['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('scilab_case_study', 'case_study_proposal_send_reminder_mail', $email_to, language_default(), $params, $from, true)) {
+ drupal_set_message('Error sending email message.', 'error');
+ }
+
+ drupal_set_message('The user has been notified about the last date of submission.', 'status');
+ drupal_goto('case-study-project/manage-proposal/all');
+ return;
+
+} \ No newline at end of file
diff --git a/proposal.inc b/proposal.inc
new file mode 100644
index 0000000..a699a48
--- /dev/null
+++ b/proposal.inc
@@ -0,0 +1,610 @@
+<?php
+/*
+Approval Status :
+0 - Pending
+1 - Approved
+2 - Dis-Approved
+3 - Completed
+Solution Status :
+0 - Pending
+1 - Approved
+2 - Dis-Approved
+Solution Display :
+0 - No
+1 - Yes
+is_completed
+0 - in progress
+1 - Completed
+Tables :
+case_study_solution : approval_status
+0 - Pending
+1 - Approved
+2 - Disapproved (delete it)
+*/
+function scilab_case_study_proposal_form($form, &$form_state, $no_js_use = FALSE)
+{
+ global $user;
+ /************************ start approve book details ************************/
+ if ($user->uid == 0)
+ {
+ $msg = drupal_set_message(t('It is mandatory to ' . l('login', 'user') . ' on this website to access the case study proposal form. If you are new user please create a new account first.'), 'error');
+ drupal_goto('user');
+ return $msg;
+ } //$user->uid == 0
+ $query = db_select('case_study_proposal');
+ $query->fields('case_study_proposal');
+ $query->condition('uid', $user->uid);
+ $query->orderBy('id', 'DESC');
+ $query->range(0, 1);
+ $proposal_q = $query->execute();
+ $proposal_data = $proposal_q->fetchObject();
+ if ($proposal_data)
+ {
+ if ($proposal_data->approval_status == 0 || $proposal_data->approval_status == 1)
+ {
+ drupal_set_message(t('We have already received your proposal.'), 'status');
+ drupal_goto('');
+ return;
+ } //$proposal_data->approval_status == 0 || $proposal_data->approval_status == 1
+ } //$proposal_data
+ $form['#attributes'] = array(
+ 'enctype' => "multipart/form-data"
+ );
+
+ $form['name_title'] = array(
+ '#type' => 'select',
+ '#title' => t('Title'),
+ '#options' => array(
+ 'Dr' => 'Dr',
+ 'Prof' => 'Prof',
+ 'Mr' => 'Mr',
+ 'Ms' => 'Ms'
+ ),
+ '#required' => TRUE
+ );
+ $form['contributor_name'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Name of the contributor'),
+ '#size' => 250,
+ '#attributes' => array(
+ 'placeholder' => t('Enter your full name.....')
+ ),
+ '#maxlength' => 250,
+ '#required' => TRUE
+ );
+ $form['contributor_email_id'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Email'),
+ '#size' => 30,
+ '#value' => $user->mail,
+ '#disabled' => TRUE
+ );
+ $form['contributor_contact_no'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Contact No.'),
+ '#size' => 10,
+ '#attributes' => array(
+ 'placeholder' => t('Enter your contact number')
+ ),
+ '#maxlength' => 10,
+ '#required' => TRUE
+ );
+ $form['university'] = array(
+ '#type' => 'textfield',
+ '#title' => t('University'),
+ '#size' => 80,
+ '#maxlength' => 200,
+ '#required' => TRUE,
+ '#attributes' => array(
+ 'placeholder' => 'Insert full name of your university.... '
+ )
+ );
+ $form['institute'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Institute'),
+ '#size' => 80,
+ '#maxlength' => 200,
+ '#required' => TRUE,
+ '#attributes' => array(
+ 'placeholder' => 'Insert full name of your institute.... '
+ )
+ );
+ $form['how_did_you_know_about_project'] = array(
+ '#type' => 'select',
+ '#title' => t('How did you come to know about the Case Study Project?'),
+ '#options' => array(
+ 'Poster' => 'Poster',
+ 'Website' => 'Website',
+ 'Email' => 'Email',
+ 'Others' => 'Others'
+ ),
+ '#required' => TRUE
+ );
+ $form['others_how_did_you_know_about_project'] = array(
+ '#type' => 'textfield',
+ '#title' => t('If ‘Other’, please specify'),
+ '#maxlength' => 50,
+ '#description' => t('<span style="color:red">Maximum character limit is 50</span>'),
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="how_did_you_know_about_project"]' => array(
+ 'value' => 'Others'
+ )
+ )
+ )
+ );
+ $form['faculty_name'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Name of the Faculty Member of your Institution, if any, who helped you with this Case Study Project'),
+ '#size' => 50,
+ '#maxlength' => 50,
+ '#validated' => TRUE,
+ '#description' => t('<span style="color:red">Maximum character limit is 50</span>')
+ );
+ $form['faculty_department'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Department of the Faculty Member of your Institution, if any, who helped you with this Case Study Project'),
+ '#size' => 50,
+ '#maxlength' => 50,
+ '#validated' => TRUE,
+ '#description' => t('<span style="color:red">Maximum character limit is 50</span>')
+ );
+ $form['faculty_email'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Email id of the Faculty Member of your Institution, if any, who helped you with this Case Study Project'),
+ '#size' => 255,
+ '#maxlength' => 255,
+ '#validated' => TRUE,
+ '#description' => t('<span style="color:red">Maximum character limit is 255</span>')
+ );
+ $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' => _cs_list_of_states(),
+ '#validated' => TRUE,
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="country"]' => array(
+ 'value' => 'India'
+ )
+ )
+ )
+ );
+ $form['city'] = array(
+ '#type' => 'select',
+ '#title' => t('City'),
+ '#options' => _cs_list_of_cities(),
+ '#states' => array(
+ 'visible' => array(
+ ':input[name="country"]' => array(
+ 'value' => 'India'
+ )
+ )
+ )
+ );
+ $form['pincode'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Pincode'),
+ '#size' => 6,
+ '#maxlength' => 6
+ );
+ /***************************************************************************/
+ $form['hr'] = array(
+ '#type' => 'item',
+ '#markup' => '<hr>'
+ );
+
+ $form['project_title'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Project Title'),
+ '#size' => 250,
+ '#maxlength' => 250,
+ '#description' => t('Maximum character limit is 250'),
+ '#required' => TRUE,
+ '#validated' => TRUE,
+ );
+ $form['operating_system'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Operating System version used'),
+ '#required' => TRUE,
+ '#size' => 30,
+ '#maxlength' => 50
+ );
+ $form['scilab_version'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Scilab version used'),
+ '#maxlength' => 20,
+ //'#options' => $version_options,
+ '#attributes' => array(
+ 'placeholder' => t('Format: Scilab x.x.x')
+ ),
+ '#description' => t('<span style="color:red;">Note: Use Scilab 6.0.0 and above. </span><span>Format: Scilab x.x.x</span>'),
+ '#required' => TRUE
+ );
+ $form['abstract_file'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Submit an Abstract'),
+ '#collapsible' => FALSE,
+ '#collapsed' => FALSE
+ );
+ $form['abstract_file']['abstract_file_path'] = array(
+ '#type' => 'file',
+ '#size' => 48,
+ '#description' => t('<span style="color:red;">Upload filenames with allowed extensions only. No spaces or any special characters allowed in filename.</span>') . '<br />' . t('<span style="color:red;">Allowed file extensions: ') . variable_get('resource_upload_extensions', '') . '</span>'
+ );
+ $form['date_of_proposal'] = array(
+ '#type' => 'date_popup',
+ '#title' => t('Date of Proposal'),
+ '#default_value' => date("Y-m-d H:i:s"),
+ '#date_format' => 'd M Y',
+ '#disabled' => TRUE,
+ '#date_label_position' => '',
+ );
+ $form['expected_date_of_completion'] = array(
+ '#type' => 'date_popup',
+ '#title' => t('Expected Date of Completion'),
+ '#date_label_position' => '',
+ '#description' => '',
+ '#default_value' => '',
+ '#date_format' => 'd-M-Y',
+ //'#date_increment' => 0,
+ //'#minDate' => '+0',
+ //'#date_year_range' => '+0 : +1',
+ '#required' => TRUE,
+ '#datepicker_options' => array(
+ 'maxDate' => '+45D', // not more than current date
+ 'minDate' => '+1' // not more than given date
+ ),
+ );
+ $form['term_condition'] = array(
+ '#type' => 'checkboxes',
+ '#title' => t('Terms And Conditions'),
+ '#options' => array(
+ 'status' => t('<a href="/case-study-project/term-and-conditions" target="_blank">I agree to the Terms and Conditions</a>')
+ ),
+ '#required' => TRUE
+ );
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit')
+ );
+ return $form;
+}
+
+function scilab_case_study_proposal_form_validate($form, &$form_state)
+{
+ if ($form_state['values']['term_condition'] == '1')
+ {
+ form_set_error('term_condition', t('Please check the terms and conditions'));
+ // $form_state['values']['country'] = $form_state['values']['other_country'];
+ } //$form_state['values']['term_condition'] == '1'
+ if ($form_state['values']['country'] == 'Others')
+ {
+ if ($form_state['values']['other_country'] == '')
+ {
+ form_set_error('other_country', t('Enter country name'));
+ // $form_state['values']['country'] = $form_state['values']['other_country'];
+ } //$form_state['values']['other_country'] == ''
+ else
+ {
+ $form_state['values']['country'] = $form_state['values']['other_country'];
+ }
+ if ($form_state['values']['other_state'] == '')
+ {
+ form_set_error('other_state', t('Enter state name'));
+ // $form_state['values']['country'] = $form_state['values']['other_country'];
+ } //$form_state['values']['other_state'] == ''
+ else
+ {
+ $form_state['values']['all_state'] = $form_state['values']['other_state'];
+ }
+ if ($form_state['values']['other_city'] == '')
+ {
+ form_set_error('other_city', t('Enter city name'));
+ // $form_state['values']['country'] = $form_state['values']['other_country'];
+ } //$form_state['values']['other_city'] == ''
+ else
+ {
+ $form_state['values']['city'] = $form_state['values']['other_city'];
+ }
+ } //$form_state['values']['country'] == 'Others'
+ else
+ {
+ if ($form_state['values']['country'] == '')
+ {
+ form_set_error('country', t('Select country name'));
+ // $form_state['values']['country'] = $form_state['values']['other_country'];
+ } //$form_state['values']['country'] == ''
+ if ($form_state['values']['all_state'] == '')
+ {
+ form_set_error('all_state', t('Select state name'));
+ // $form_state['values']['country'] = $form_state['values']['other_country'];
+ } //$form_state['values']['all_state'] == ''
+ if ($form_state['values']['city'] == '')
+ {
+ form_set_error('city', t('Select city name'));
+ // $form_state['values']['country'] = $form_state['values']['other_country'];
+ } //$form_state['values']['city'] == ''
+ }
+ //Validation for project title
+
+ if(strtotime(date($form_state['values']['expected_date_of_completion'])) < time())
+ {
+ form_set_error('expected_date_of_completion', t('Completion date should not be earlier than proposal date'));
+ }
+
+ if ($form_state['values']['how_did_you_know_about_project'] == 'Others')
+ {
+ if ($form_state['values']['others_how_did_you_know_about_project'] == '')
+ {
+ form_set_error('others_how_did_you_know_about_project', t('Please enter how did you know about the project'));
+ // $form_state['values']['country'] = $form_state['values']['other_country'];
+ } //$form_state['values']['other_country'] == ''
+ else
+ {
+ $form_state['values']['how_did_you_know_about_project'] = $form_state['values']['others_how_did_you_know_about_project'];
+ }
+ }
+ /*if ($form_state['values']['faculty_name'] != '' || $form_state['values']['faculty_name'] != "NULL") {
+ if($form_state['values']['faculty_email'] == '' || $form_state['values']['faculty_email'] == "NULL")
+ {
+ form_set_error('faculty_email', t('Please enter the email id of your faculty'));
+ }
+ if($form_state['values']['faculty_department'] == '' || $form_state['values']['faculty_department'] == 'NULL'){
+ form_set_error('faculty_department', t('Please enter the Department of your faculty'));
+ }
+ }*/
+
+if (isset($_FILES['files']))
+ {
+ /* check if atleast one source or result file is uploaded */
+ if (!($_FILES['files']['name']['abstract_file_path']))
+ form_set_error('abstract_file_path', t('Please upload the abstract file'));
+ /* 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('resource_upload_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 (!scilab_case_study_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 $form_state;
+}
+function scilab_case_study_proposal_form_submit($form, &$form_state)
+{
+ global $user;
+ $root_path = scilab_case_study_path();
+ if (!$user->uid)
+ {
+ drupal_set_message('It is mandatory to login on this website to access the proposal form', 'error');
+ return;
+ }
+ if ($form_state['values']['how_did_you_know_about_project'] == 'Others')
+ {
+ $how_did_you_know_about_project = $form_state['values']['others_how_did_you_know_about_project'];
+ }
+ else {
+ $how_did_you_know_about_project = $form_state['values']['how_did_you_know_about_project'];
+ }
+ /* inserting the user proposal */
+ $v = $form_state["values"];
+ $project_title = trim($v['project_title']);
+ $proposar_name = $v['name_title'] . ' ' . $v['contributor_name'];
+ $university = $v['university'];
+ $directory_name = _cs_dir_name($project_title, $proposar_name);
+ $result = "INSERT INTO case_study_proposal
+ (
+ uid,
+ approver_uid,
+ name_title,
+ contributor_name,
+ contact_no,
+ university,
+ institute,
+ how_did_you_know_about_project,
+ faculty_name,
+ faculty_department,
+ faculty_email,
+ city,
+ pincode,
+ state,
+ country,
+ project_title,
+ operating_system,
+ scilab_version,
+ directory_name,
+ approval_status,
+ is_completed,
+ dissapproval_reason,
+ creation_date,
+ expected_date_of_completion,
+ approval_date
+ ) VALUES
+ (
+ :uid,
+ :approver_uid,
+ :name_title,
+ :contributor_name,
+ :contact_no,
+ :university,
+ :institute,
+ :how_did_you_know_about_project,
+ :faculty_name,
+ :faculty_department,
+ :faculty_email,
+ :city,
+ :pincode,
+ :state,
+ :country,
+ :project_title,
+ :operating_system,
+ :scilab_version,
+ :directory_name,
+ :approval_status,
+ :is_completed,
+ :dissapproval_reason,
+ :creation_date,
+ :expected_date_of_completion,
+ :approval_date
+ )";
+ $args = array(
+ ":uid" => $user->uid,
+ ":approver_uid" => 0,
+ ":name_title" => $v['name_title'],
+ ":contributor_name" => trim($v['contributor_name']),
+ ":contact_no" => trim($v['contributor_contact_no']),
+ ":university" => trim($v['university']),
+ ":institute" => trim($v['institute']),
+ ":how_did_you_know_about_project" => trim($how_did_you_know_about_project),
+ ":faculty_name" => $v['faculty_name'],
+ ":faculty_department" => $v['faculty_department'],
+ ":faculty_email" => $v['faculty_email'],
+ ":city" => $v['city'],
+ ":pincode" => $v['pincode'],
+ ":state" => $v['all_state'],
+ ":country" => $v['country'],
+ ":project_title" => $project_title,
+ ":operating_system" => $v['operating_system'],
+ ":scilab_version" => $v['scilab_version'],
+ ":directory_name" => $directory_name,
+ ":approval_status" => 0,
+ ":is_completed" => 0,
+ ":dissapproval_reason" => "NULL",
+ ":creation_date" => time(),
+ ":expected_date_of_completion" => strtotime(date($v['expected_date_of_completion'])),
+ ":approval_date" => 0
+ );
+ $proposal_id = db_query($result, $args, array(
+ 'return' => Database::RETURN_INSERT_ID
+ ));
+ $dest_path = $directory_name . '/';
+ $dest_path1 = $root_path . $dest_path;
+ //var_dump($dest_path1);die;
+ if (!is_dir($root_path . $dest_path))
+ mkdir($root_path . $dest_path);
+ /* uploading files */
+ foreach ($_FILES['files']['name'] as $file_form_name => $file_name)
+ {
+ if ($file_name)
+ {
+ /* checking file type */
+ //$file_type = 'S';
+ if (file_exists($root_path . $dest_path . $_FILES['files']['name'][$file_form_name]))
+ {
+ drupal_set_message(t("Error uploading file. File !filename already exists.", array('!filename' => $_FILES['files']['name'][$file_form_name])), 'error');
+ //unlink($root_path . $dest_path . $_FILES['files']['name'][$file_form_name]);
+ } //file_exists($root_path . $dest_path . $_FILES['files']['name'][$file_form_name])
+ /* uploading file */
+ if (move_uploaded_file($_FILES['files']['tmp_name'][$file_form_name], $root_path . $dest_path . $_FILES['files']['name'][$file_form_name]))
+ {
+ $query = "UPDATE case_study_proposal SET samplefilepath = :samplefilepath WHERE id = :id";
+ $args = array(
+ ":samplefilepath" => $dest_path . $_FILES['files']['name'][$file_form_name],
+ ":id" => $proposal_id
+ );
+
+ $updateresult = db_query($query, $args);
+ //var_dump($args);die;
+
+ drupal_set_message($file_name . ' uploaded successfully.', 'status');
+ } //move_uploaded_file($_FILES['files']['tmp_name'][$file_form_name], $root_path . $dest_path . $_FILES['files']['name'][$file_form_name])
+ else
+ {
+ drupal_set_message('Error uploading file : ' . $dest_path . '/' . $file_name, 'error');
+ }
+ } //$file_name
+ } //$_FILES['files']['name'] as $file_form_name => $file_name
+ if (!$proposal_id)
+ {
+ drupal_set_message(t('Error receiving your proposal. Please try again.'), 'error');
+ return;
+ } //!$proposal_id
+ /* sending email */
+ $email_to = $user->mail;
+ $form = variable_get('case_study_from_email', '');
+ $bcc = variable_get('case_study_emails', '');
+ $cc = variable_get('case_study_cc_emails', '');
+ $params['case_study_proposal_received']['result1'] = $proposal_id;
+ $params['case_study_proposal_received']['user_id'] = $user->uid;
+ $params['case_study_proposal_received']['headers'] = array(
+ 'From' => $form,
+ '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('scilab_case_study', 'case_study_proposal_received', $email_to, user_preferred_language($user), $params, $form, TRUE))
+ drupal_set_message('Error sending email message.', 'error');
+ drupal_set_message(t('We have received your case study proposal. We will get back to you soon.'), 'status');
+ drupal_goto('');
+} \ No newline at end of file
diff --git a/run.inc b/run.inc
new file mode 100644
index 0000000..a26272d
--- /dev/null
+++ b/run.inc
@@ -0,0 +1,144 @@
+<?php
+function scilab_case_study_run_form($form, &$form_state)
+{
+ $options_first = _list_of_case_study();
+ $url_case_study_id = (int) arg(2);
+ $case_study_data = _case_study_information($url_case_study_id);
+ if ($case_study_data == 'Not found') {
+ $url_case_study_id = '';
+ } //$case_study_data == 'Not found'
+ if (!$url_case_study_id) {
+ $selected = isset($form_state['values']['case_study']) ? $form_state['values']['case_study'] : key($options_first);
+ } //!$url_case_study_id
+ elseif ($url_case_study_id == '') {
+ $selected = 0;
+ } //$url_case_study_id == ''
+ else {
+ $selected = $url_case_study_id;
+ }
+ $form = array();
+ $form['case_study'] = array(
+ '#type' => 'select',
+ '#title' => t('Title of the case study'),
+ '#options' => _list_of_case_study(),
+ '#default_value' => $selected,
+ '#ajax' => array(
+ 'callback' => 'case_study_project_details_callback'
+ )
+ );
+ if (!$url_case_study_id) {
+ $form['case_study_details'] = array(
+ '#type' => 'item',
+ '#markup' => '<div id="ajax_case_study_details"></div>'
+ );
+ $form['selected_case_study'] = array(
+ '#type' => 'item',
+ '#markup' => '<div id="ajax_selected_case_study"></div>'
+ );
+ } //!$url_case_study_id
+ else {
+ $case_study_default_value = $url_case_study_id;
+ $form['case_study_details'] = array(
+ '#type' => 'item',
+ '#markup' => '<div id="ajax_case_study_details">' . _case_study_details($case_study_default_value) . '</div>'
+ );
+ $form['selected_case_study'] = array(
+ '#type' => 'item',
+ '#markup' => '<div id="ajax_selected_case_study">' . l('Download Report(PDF)', "case-study-project/download/final-report/" . $case_study_default_value) . '<br>' . l('Download Case Files and Report', 'case-study-project/full-download/project/' . $case_study_default_value) . '</div>'
+ );
+ }
+ return $form;
+}
+function case_study_project_details_callback($form, $form_state)
+{
+ $commands = array();
+ $case_study_default_value = $form_state['values']['case_study'];
+ if ($case_study_default_value != 0) {
+ $form['case_study_details']['#markup'] = _case_study_details($case_study_default_value);
+ $case_study_details = _case_study_information($case_study_default_value);
+ $provider = user_load($case_study_details->uid);
+ if ($case_study_details->uid > 0) {
+ $commands[] = ajax_command_html('#ajax_selected_case_study', l('Download Report(PDF)', "case-study-project/download/final-report/" . $case_study_default_value) . '<br>' . l('Download Case Files and Report', 'case-study-project/full-download/project/' . $case_study_default_value));
+ } //$case_study_details->uid > 0
+ else {
+ $commands[] = ajax_command_html('#ajax_selected_case_study', '');
+ $commands[] = ajax_command_html('#ajax_selected_case_study', '');
+ }
+ $commands[] = ajax_command_html('#ajax_case_study_details', _case_study_details($case_study_default_value));
+ } //$case_study_default_value != 0
+ else {
+ // $form['lab_experiment_list']['#options'] = _ajax_get_experiment_list();
+ // $commands[] = ajax_command_replace('#ajax_selected_experiment', drupal_render($form['lab_experiment_list']));
+ $commands[] = ajax_command_html('#ajax_case_study_details', '');
+ $commands[] = ajax_command_html('#ajax_selected_case_study', '');
+ $commands[] = ajax_command_html('#ajax_selected_case_study', '');
+ $commands[] = ajax_command_data('#ajax_selected_case_study', 'form_state_value_select', $form_state['values']['case_study']);
+ }
+ return array(
+ '#type' => 'ajax',
+ '#commands' => $commands
+ );
+}
+function bootstrap_table_format($headers, $rows)
+{
+ $thead = "";
+ $tbody = "";
+ foreach ($headers as $header) {
+ $thead .= "<th>{$header}</th>";
+ } //$headers as $header
+ foreach ($rows as $row) {
+ $tbody .= "<tr>";
+ foreach ($row as $data) {
+ $tbody .= "<td>{$data}</td>";
+ } //$row as $data
+ $tbody .= "</tr>";
+ } //$rows as $row
+ $table = "
+ <table class='table table-bordered table-hover' style='margin-left:-140px'>
+ <thead>{$thead}</thead>
+ <tbody>{$tbody}</tbody>
+ </table>
+ ";
+ return $table;
+}
+/*****************************************************/
+function _list_of_case_study()
+{
+ $case_study_titles = array(
+ '0' => 'Please select...'
+ );
+ //$lab_titles_q = db_query("SELECT * FROM {case_study_proposal} WHERE solution_display = 1 ORDER BY lab_title ASC");
+ $query = db_select('case_study_proposal');
+ $query->fields('case_study_proposal');
+ $query->condition('approval_status', 3);
+ $query->orderBy('project_title', 'ASC');
+ $case_study_titles_q = $query->execute();
+ while ($case_study_titles_data = $case_study_titles_q->fetchObject()) {
+ $case_study_titles[$case_study_titles_data->id] = $case_study_titles_data->project_title . ' (Proposed by ' . $case_study_titles_data->name_title . ' ' . $case_study_titles_data->contributor_name . ')';
+ } //$case_study_titles_data = $case_study_titles_q->fetchObject()
+ return $case_study_titles;
+}
+function _case_study_information($proposal_id)
+{
+ $query = db_select('case_study_proposal');
+ $query->fields('case_study_proposal');
+ $query->condition('id', $proposal_id);
+ $query->condition('approval_status', 3);
+ $case_study_q = $query->execute();
+ $case_study_data = $case_study_q->fetchObject();
+ if ($case_study_data) {
+ return $case_study_data;
+ } //$case_study_data
+ else {
+ return 'Not found';
+ }
+}
+function _case_study_details($case_study_default_value)
+{
+ $case_study_details = _case_study_information($case_study_default_value);
+ if ($case_study_default_value != 0) {
+ $form['case_study_details']['#markup'] = '<span style="color: rgb(128, 0, 0);"><strong>About the case study</strong></span></td><td style="width: 35%;"><br />' . '<ul>' . '<li><strong>Name of the Contributor:</strong> ' . $case_study_details->name_title . ' ' . $case_study_details->contributor_name . '</li>' . '<li><strong>Title of the Case Study:</strong> ' . $case_study_details->project_title . '</li>' . '<li><strong>University:</strong> ' . $case_study_details->university . '</li>' . '<li><strong>Institute:</strong> ' . $case_study_details->institute . '</li>' . '<li><strong>Operating System:</strong> ' . $case_study_details->operating_system . '</li>' . '<li><strong>Scilab Version:</strong> ' . $case_study_details->scilab_version . '</li>' . '</ul>';
+ $details = $form['case_study_details']['#markup'];
+ return $details;
+ } //$case_study_default_value != 0
+}
diff --git a/scilab_case_study.info b/scilab_case_study.info
new file mode 100644
index 0000000..98575bf
--- /dev/null
+++ b/scilab_case_study.info
@@ -0,0 +1,7 @@
+name = "Scilab Case Study"
+description = "Scilab Case Study Project, FOSSEE, IIT Bombay"
+package = FOSSEE
+version = "7.x"
+core = "7.x"
+
+;scripts[] = js/jquery-1.4.1.min.js
diff --git a/scilab_case_study.module b/scilab_case_study.module
new file mode 100644
index 0000000..808d718
--- /dev/null
+++ b/scilab_case_study.module
@@ -0,0 +1,755 @@
+<?php
+// $Id$
+/*error_reporting(E_ALL);
+ini_set('display_errors', TRUE);
+ini_set('display_startup_errors', TRUE);*/
+require_once 'general_deletion.inc';
+require_once 'email.inc';
+/**
+ * Implementation of hook_menu().
+ */
+function scilab_case_study_menu()
+{
+ $items = array();
+ /* PROPOSAL */
+ $items['case-study-project/add-project-title'] = array(
+ 'title' => 'Add new project titles',
+ 'description' => 'Add new project titles',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array(
+ 'add_project_title_form',
+ ),
+ 'access arguments' => array(
+ 'Case Study add project titles',
+ ),
+ 'type' => MENU_NORMAL_ITEM,
+ 'file' => 'add_project_titles.inc',
+ );
+ $items['case-study-project/proposal'] = array(
+ 'title' => 'Case Study Proposal Form',
+ 'description' => 'Case Study Proposal Form',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array(
+ 'scilab_case_study_proposal_form',
+ ),
+ 'access arguments' => array(
+ 'Case Study create proposal',
+ ),
+ 'type' => MENU_NORMAL_ITEM,
+ 'file' => 'proposal.inc',
+ );
+ $items['case-study-project/manage-proposal'] = array(
+ 'title' => 'Manage Case Study Proposals',
+ 'description' => 'Manage Case Study Proposals',
+ 'page callback' => 'scilab_case_study_proposal_pending',
+ 'access callback' => 'user_access',
+ 'access arguments' => array(
+ 'Case Study manage proposal',
+ ),
+ 'file' => 'manage_proposal.inc',
+ );
+ $items['case-study-project/manage-proposal/pending'] = array(
+ 'title' => 'Pending Proposals',
+ 'description' => 'Pending Case Study Proposals Queue',
+ 'page callback' => 'scilab_case_study_proposal_pending',
+ 'access callback' => 'user_access',
+ 'access arguments' => array(
+ 'Case Study manage proposal',
+ ),
+ 'type' => MENU_DEFAULT_LOCAL_TASK,
+ 'weight' => 1,
+ 'file' => 'manage_proposal.inc',
+ );
+ $items['case-study-project/manage-proposal/all'] = array(
+ 'title' => 'All Proposals',
+ 'description' => 'All Proposals',
+ 'page callback' => 'scilab_case_study_proposal_all',
+ 'access callback' => 'user_access',
+ 'access arguments' => array(
+ 'Case Study manage proposal',
+ ),
+ 'type' => MENU_LOCAL_TASK,
+ 'weight' => 4,
+ 'file' => 'manage_proposal.inc',
+ );
+ $items['case-study-project/manage-proposal/edit-upload-file'] = array(
+ 'title' => 'Edit code files',
+ 'description' => 'Edit code files',
+ 'page callback' => 'scilab_case_study_proposal_edit_file_all',
+ 'access callback' => 'user_access',
+ 'access arguments' => array(
+ 'Case Study manage proposal',
+ ),
+ 'type' => MENU_LOCAL_TASK,
+ 'weight' => 4,
+ 'file' => 'manage_proposal.inc',
+ );
+ $items['case-study-project/manage-proposal/approve'] = array(
+ 'title' => 'Approve Proposal',
+ 'description' => 'Approve Proposal',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array(
+ 'scilab_case_study_proposal_approval_form',
+ ),
+ 'access arguments' => array(
+ 'Case Study manage proposal',
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'manage_proposal.inc',
+ );
+ $items['case-study-project/manage-proposal/edit'] = array(
+ 'title' => 'Edit Proposal',
+ 'description' => 'Edit Proposal',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array(
+ 'scilab_case_study_proposal_edit_form',
+ ),
+ 'access arguments' => array(
+ 'Case Study manage proposal',
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'manage_proposal.inc',
+ );
+ $items['case-study-project/manage-proposal/send-reminder-mail'] = array(
+ 'title' => 'Send Reminder to Contriubutor about Proposal Completion Date',
+ 'description' => 'Send Reminder to Contriubutor about Proposal Completion Date',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array(
+ 'scilab_case_study_proposal_send_reminder_mail_form',
+ ),
+ 'access arguments' => array(
+ 'Case Study manage proposal',
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'manage_proposal.inc',
+ );
+ $items['case-study-project/manage-proposal/status'] = array(
+ 'title' => 'Proposal Status',
+ 'description' => 'Proposal Status',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array(
+ 'scilab_case_study_proposal_status_form',
+ ),
+ 'access arguments' => array(
+ 'Case Study approve proposal',
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'manage_proposal.inc',
+ );
+ $items['case-study-project/abstract-approval/bulk'] = array(
+ 'title' => 'Manage Case Study Submissions',
+ 'description' => 'Manage Case Study Submissions',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array(
+ 'scilab_case_study_abstract_bulk_approval_form',
+ ),
+ 'access arguments' => array(
+ 'Case Study bulk manage abstract',
+ ),
+ 'type' => MENU_LOCAL_TASK,
+ 'weight' => 2,
+ 'file' => 'abstract_bulk_approval.inc',
+ );
+ /* CODE UPLOAD */
+ $items['case-study-project/abstract-code/edit-upload-files'] = array(
+ 'title' => 'Case Study Project Directory edit uploaded files for proposal',
+ 'description' => 'Project Edit Upload',
+ 'page callback' => 'drupal_get_form',
+ 'access callback' => 'user_access',
+ 'page arguments' => array(
+ 'scilab_case_study_edit_upload_abstract_code_form',
+ ),
+ 'access arguments' => array(
+ 'Case Study upload abstract',
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'upload_code.inc',
+ 'weight' => 2,
+ );
+ $items['case-study-project/abstract-code'] = array(
+ 'title' => 'Case Study Submission',
+ 'description' => 'Abstract Submission',
+ 'page callback' => 'scilab_case_study_abstract',
+ 'access callback' => 'user_access',
+ 'access arguments' => array(
+ 'Case Study upload abstract',
+ ),
+ 'file' => 'upload_code.inc',
+ );
+ $items['case-study-project/abstract-code/upload'] = array(
+ 'title' => 'Case Study Submission',
+ 'description' => 'Project Upload',
+ 'page callback' => 'drupal_get_form',
+ 'access callback' => 'user_access',
+ 'page arguments' => array(
+ 'scilab_case_study_upload_abstract_code_form',
+ ),
+ 'access arguments' => array(
+ 'Case Study upload abstract',
+ ),
+ 'type' => MENU_LOCAL_TASK,
+ 'file' => 'upload_code.inc',
+ 'weight' => 2,
+ );
+ $items['case-study-project/abstract-code/delete'] = array(
+ 'title' => 'Delete Solution',
+ 'description' => 'Delete Solution',
+ 'page callback' => 'scilab_case_study_upload_code_delete',
+ 'access arguments' => array(
+ 'Case Study upload code',
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'upload_code_delete.inc',
+ );
+ /* CODE DOWNLOADS */
+ $items['case-study-project/full-download/project'] = array(
+ 'title' => 'Code Download',
+ 'description' => 'Code Download',
+ 'page callback' => 'scilab_case_study_download_full_project',
+ 'access arguments' => array(
+ 'Case Study download code',
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'full_download.inc',
+ );
+ /* COMPLETED Case studies */
+ $items['case-study-project/completed-case-studies'] = array(
+ 'title' => 'Completed Case studies',
+ 'page callback' => 'scilab_case_study_completed_proposals_all',
+ 'access arguments' => array(
+ 'Case Study download code',
+ ),
+ 'file' => 'scilab_case_study_details.inc',
+ );
+ /* LABS IN PROGRESS */
+ $items['case-study-project/case-study-progress'] = array(
+ 'title' => 'Case studies in Progress',
+ 'page callback' => 'scilab_case_study_progress_all',
+ 'access arguments' => array(
+ 'Case Study download code',
+ ),
+ 'file' => 'scilab_case_study_details.inc',
+ );
+ $items['case-study-project/list-of-project-titles'] = array(
+ 'title' => 'List of available Project titles',
+ 'page callback' => 'list_of_available_project_titles',
+ 'access arguments' => array(
+ 'Case Study Project titles list',
+ ),
+ 'file' => 'available_project_titles_list.inc',
+ );
+ /* DOWNLOAD FOR EVERYONE */
+ $items['case-study-project/case-study-run'] = array(
+ 'title' => 'Download Codes',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array(
+ 'scilab_case_study_run_form',
+ ),
+ 'access arguments' => array(
+ 'Case Study download code',
+ ),
+ 'type' => MENU_NORMAL_ITEM,
+ 'file' => 'run.inc',
+ );
+ $items['case-study-project/download/final-report'] = array(
+ 'title' => 'Download Final Report',
+ 'description' => 'Download Final Report',
+ 'page callback' => 'scilab_case_study_download_final_report',
+ 'access arguments' => array(
+ 'download code',
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'download.inc',
+ );
+ $items['case-study-project/download/project-title-file'] = array(
+ 'title' => 'Download Project Title file',
+ 'description' => 'Download Project Title file',
+ 'page callback' => 'download_case_study_project_title_files',
+ 'access arguments' => array(
+ 'download code',
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'available_project_titles_list.inc',
+ );
+ $items['case-study-project/download/proposal-abstract'] = array(
+ 'title' => 'Download Abstract',
+ 'description' => 'Download Abstract',
+ 'page callback' => 'download_proposal_abstract',
+ 'access arguments' => array(
+ 'download code',
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'download.inc',
+ );
+ /* ADMIN SETTINGS */
+ $items['admin/settings/case-study'] = array(
+ 'title' => 'Case Study Settings',
+ 'description' => 'Case Study Settings',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array(
+ 'scilab_case_study_settings_form',
+ ),
+ 'access arguments' => array(
+ 'administer Case Study',
+ ),
+ 'type' => MENU_NORMAL_ITEM,
+ 'file' => 'settings.inc',
+ );
+ /* AJAX REQUEST */
+ $items['case-study-project/certificates'] = array(
+ 'title' => 'List of Case Study Certificates',
+ 'description' => 'List of Case Study Certificates',
+ 'page callback' => '_list_case_study_certificates',
+ 'access arguments' => array(
+ 'list Case Study certificates',
+ ),
+ 'file' => 'pdf/list_case_study_certificate.inc',
+ );
+ $items['case-study-project/certificates/generate-pdf'] = array(
+ 'title' => 'Download Certificate',
+ 'description' => 'Download Certificate',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array(
+ 'generate_pdf',
+ ),
+ 'type' => MENU_CALLBACK,
+ 'access arguments' => array(
+ 'generate pdf',
+ ),
+ 'file' => 'pdf/cert_new.inc',
+ );
+ /*$items['case-study-project/certificates-custom'] = array(
+ 'title'=> 'List of Case Study Custom Certificates',
+ 'description'=> 'List of Case Study Custom Certificates',
+ 'page callback'=> '_list_scilab_case_study_custom_certificates',
+ 'access arguments'=> array(
+ 'list Case Study custom certificates'
+ ),
+ 'file'=> 'pdf/list_mentor_certificates.inc'
+ );
+ $items['case-study-project/certificates-custom/pdf'] = array(
+ 'title'=> 'Download Certificate',
+ 'description'=> 'Download Certificate',
+ 'page callback'=> 'drupal_get_form',
+ 'page arguments'=> array(
+ 'generate_pdf'
+ ),
+ 'type'=> MENU_CALLBACK,
+ 'access arguments'=> array(
+ 'generate pdf'
+ ),
+ 'file'=> 'pdf/mentor_cert_pdf.inc'
+ ); */
+ $items['case-study-project/certificates/verify'] = array(
+ "title" => "Certificate Verification",
+ "page callback" => "verify_certificates",
+ 'page arguments' => array(
+ 'verify_certificates',
+ ),
+ "access arguments" => array(
+ "verify certificates",
+ ),
+ 'type' => MENU_CALLBACK,
+ 'file' => 'pdf/verify_certificates.inc',
+ );
+ return $items;
+}
+/**
+ * Implementation of hook_perm().
+ */
+function scilab_case_study_permission()
+{
+ return array(
+ 'Case Study add project titles' => array(
+ 'title' => t('Case Study add project titles'),
+ 'restrict access' => true,
+ ),
+ 'Case Study create proposal' => array(
+ 'title' => t('Case Study create proposal'),
+ 'restrict access' => true,
+ ),
+ 'Case Study manage proposal' => array(
+ 'title' => t('Case Study manage proposal'),
+ 'restrict access' => true,
+ ),
+ 'Case Study edit proposal' => array(
+ 'title' => t('Case Study edit proposal'),
+ 'restrict access' => true,
+ ),
+ 'Case Study approve proposal' => array(
+ 'title' => t('Case Study approve proposal'),
+ 'restrict access' => true,
+ ),
+ 'Case Study propose solution' => array(
+ 'title' => t('Case Study propose solution'),
+ 'restrict access' => true,
+ ),
+ 'Case Study Project titles list' => array(
+ 'title' => t('Case Study Project titles list'),
+ 'restrict access' => true,
+ ),
+ 'Case Study approve abstract' => array(
+ 'title' => t('Case Study approve code'),
+ 'restrict access' => true,
+ ),
+ 'Case Study bulk manage abstract' => array(
+ 'title' => t('Case Study bulk manage abstract'),
+ 'restrict access' => true,
+ ),
+ 'Case Study bulk delete abstract' => array(
+ 'title' => t('Case Study bulk delete code'),
+ 'restrict access' => true,
+ ),
+ 'Case Study upload abstract' => array(
+ 'title' => t('Case Study upload code'),
+ 'restrict access' => true,
+ ),
+ 'Case Study download code' => array(
+ 'title' => t('Case Study download code'),
+ 'restrict access' => true,
+ ),
+ 'administer Case Study' => array(
+ 'title' => t('administer Case Study'),
+ 'restrict access' => true,
+ ),
+ 'Case Study generate abstract' => array(
+ 'title' => t('Case Study generate abstract'),
+ 'restrict access' => true,
+ ),
+ "list Case Study certificates" => array(
+ "title" => t("list the certificates"),
+ "description" => t("list the certificates"),
+ 'restrict access' => true,
+ ),
+ "list Case Study custom certificates" => array(
+ "title" => t("list the mentor certificates"),
+ "description" => t("list the mentor certificates"),
+ 'restrict access' => true,
+ ),
+ "verify certificates" => array(
+ "title" => t("verify the certificates"),
+ "description" => t("verify the certificates"),
+ 'restrict access' => true,
+ ),
+
+ );
+}
+/*************************** VALIDATION FUNCTIONS *****************************/
+function scilab_case_study_check_valid_filename($file_name)
+{
+ if (!preg_match('/^[0-9a-zA-Z\.\_]+$/', $file_name)) {
+ return false;
+ } else if (substr_count($file_name, ".") > 1) {
+ return false;
+ } else {
+ return true;
+ }
+
+}
+function scilab_case_study_check_name($name = '')
+{
+ if (!preg_match('/^[0-9a-zA-Z\ ]+$/', $name)) {
+ return false;
+ } else {
+ return true;
+ }
+
+}
+function scilab_case_study_check_code_number($number = '')
+{
+ if (!preg_match('/^[0-9]+$/', $number)) {
+ return false;
+ } else {
+ return true;
+ }
+
+}
+function scilab_case_study_path()
+{
+ return $_SERVER['DOCUMENT_ROOT'] . base_path() . 'case_study_uploads/';
+}
+/************************* USER VERIFICATION FUNCTIONS ************************/
+function scilab_case_study_get_proposal()
+{
+ global $user;
+ $query = db_select('case_study_proposal');
+ $query->fields('case_study_proposal');
+ $query->condition('uid', $user->uid);
+ $query->orderBy('id', 'DESC');
+ $query->range(0, 1);
+ $proposal_q = $query->execute();
+ $proposal_data = $proposal_q->fetchObject();
+ if (!$proposal_data) {
+ drupal_set_message("You do not have any approved Case Study proposal. Please propose a Case Study", 'error');
+ drupal_goto('');
+ } //!$proposal_data
+ switch ($proposal_data->approval_status) {
+ case 0:
+ drupal_set_message(t('Proposal is awaiting approval.'), 'status');
+ return false;
+ case 1:
+ return $proposal_data;
+ case 2:
+ drupal_set_message(t('Proposal has been dis-approved.'), 'error');
+ return false;
+ case 3:
+ drupal_set_message(t('Proposal has been marked as completed.'), 'status');
+ return false;
+ default:
+ drupal_set_message(t('Invalid proposal state. Please contact site administrator for further information.'), 'error');
+ return false;
+ } //$proposal_data->approval_status
+ return false;
+}
+/*************************************************************************/
+/***** Function To convert only first charater of string in uppercase ****/
+/*************************************************************************/
+/*function ucname($string)
+{
+$string = ucwords(strtolower($string));
+foreach (array(
+'-',
+'\''
+) as $delimiter)
+{
+if (strpos($string, $delimiter) !== false)
+{
+$string = implode($delimiter, array_map('ucfirst', explode($delimiter, $string)));
+} //strpos($string, $delimiter) !== false
+} //array( '-', '\'') as $delimiter
+return $string;
+}*/
+function _cs_sentence_case($string)
+{
+ $string = ucwords(strtolower($string));
+ foreach (array(
+ '-',
+ '\'',
+ ) as $delimiter) {
+ if (strpos($string, $delimiter) !== false) {
+ $string = implode($delimiter, array_map('ucfirst', explode($delimiter, $string)));
+ } //strpos($string, $delimiter) !== false
+ } //array( '-', '\'') as $delimiter
+ return $string;
+}
+function _cs_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;
+ } //$states_list_data = $states_list->fetchObject()
+ return $states;
+}
+function _cs_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;
+ } //$city_list_data = $city_list->fetchObject()
+ return $city;
+}
+function _cs_list_of_pincodes()
+{
+ $pincode = array(
+ 0 => '-Select-',
+ );
+ $query = db_select('list_of_all_india_pincode');
+ $query->fields('list_of_all_india_pincode');
+ $query->orderBy('pincode', 'ASC');
+ $pincode_list = $query->execute();
+ while ($pincode_list_data = $pincode_list->fetchObject()) {
+ $pincode[$pincode_list_data->pincode] = $pincode_list_data->pincode;
+ } //$pincode_list_data = $pincode_list->fetchObject()
+ return $pincode;
+}
+function _cs_list_of_departments()
+{
+ $department = array();
+ $query = db_select('list_of_departments');
+ $query->fields('list_of_departments');
+ $query->orderBy('id', 'DESC');
+ $department_list = $query->execute();
+ while ($department_list_data = $department_list->fetchObject()) {
+ $department[$department_list_data->department] = $department_list_data->department;
+ } //$department_list_data = $department_list->fetchObject()
+ return $department;
+}
+
+function _cs_list_of_case_studies()
+{
+ $existing_case_studies = array();
+ $result = db_query("SELECT * from list_of_project_titles WHERE {project_title_name} NOT IN( SELECT project_title from case_study_proposal WHERE approval_status = 0 OR approval_status = 1 OR approval_status = 3)");
+ while ($case_study_list_data = $result->fetchObject()) {
+ $existing_case_studies[$case_study_list_data->project_title_name] = $case_study_list_data->project_title_name;
+ }
+ return $existing_case_studies;
+}
+
+function _cs_list_of_versions(){
+ $versions = array();
+ $query = db_select('case_study_software_version');
+ $query->fields('case_study_software_version');
+ $version_list = $query->execute();
+ while($version_data = $version_list->fetchObject()){
+ $versions[$version_data->id] = $version_data->case_study_version;
+ }
+ return $versions;
+}
+
+function _cs_list_of_simulation_types(){
+ $simulation_types = array();
+ $query = db_select('case_study_simulation_type');
+ $query->fields('case_study_simulation_type');
+ $simulation_type_list = $query->execute();
+ while ($simulation_type_data = $simulation_type_list->fetchObject()) {
+ $simulation_types[$simulation_type_data->id] = $simulation_type_data->simulation_type;
+ }
+ return $simulation_types;
+}
+
+function _cs_list_of_solvers($simulation_id){
+ $simulation_id = $simulation_id;
+ $solvers = array(
+ 0 => '-Select-',
+ );
+ $query = db_select('case_study_solvers');
+ $query->fields('case_study_solvers');
+ $query->condition('simulation_type_id',$simulation_id);
+ $solvers_list = $query->execute();
+ while($solvers_data = $solvers_list->fetchObject()){
+ $solvers[$solvers_data->solver_name] = $solvers_data->solver_name;
+ }
+ return $solvers;
+}
+
+function _cs_dir_name($project, $proposar_name)
+{
+ $project_title = $project;
+ $proposar_name = $proposar_name;
+ $dir_name = $project_title . ' By ' . $proposar_name;
+ $directory_name = str_replace("__", "_", str_replace(" ", "_", str_replace("/", "_", trim($dir_name))));
+ return $directory_name;
+}
+function scilab_case_study_document_path()
+{
+ return $_SERVER['DOCUMENT_ROOT'] . base_path() . 'case_study_uploads/';
+}
+function CS_RenameDir($proposal_id, $dir_name)
+{
+ $proposal_id = $proposal_id;
+ $dir_name = $dir_name;
+ $query = db_query("SELECT directory_name,id FROM case_study_proposal WHERE id = :proposal_id", array(
+ ':proposal_id' => $proposal_id,
+ ));
+ $result = $query->fetchObject();
+// var_dump($dir_name . $result->directory_name);
+ if ($result != null) {
+ $files = scandir(scilab_case_study_path());
+ $files_id_dir = scilab_case_study_path() . $result->id;
+ //var_dump($files);die;
+ $file_dir = scilab_case_study_path() . $result->directory_name;
+ if (is_dir($file_dir)) {
+ $new_directory_name = rename(scilab_case_study_path() . $result->directory_name, scilab_case_study_path() . $dir_name);
+ return $new_directory_name;
+ } //is_dir($file_dir)
+ else if (is_dir($files_id_dir)) {
+ $new_directory_name = rename(scilab_case_study_path() . $result->id, scilab_case_study_path() . $dir_name);
+ return $new_directory_name;
+ } //is_dir($files_id_dir)
+ else {
+ drupal_set_message('Directory not available for rename.');
+ return;
+ }
+ } //$result != NULL
+ else {
+ drupal_set_message('Project directory name not present in databse');
+ return;
+ }
+ return;
+}
+function CreateReadmeFileCaseStudyProject($proposal_id)
+{
+ $result = db_query("
+ SELECT * from case_study_proposal WHERE id = :proposal_id", array(
+ ":proposal_id" => $proposal_id,
+ ));
+ $proposal_data = $result->fetchObject();
+ $root_path = scilab_case_study_path();
+ $readme_file = fopen($root_path . $proposal_data->directory_name . "/README.txt", "w") or die("Unable to open file!");
+ $txt = "";
+ $txt .= "About the Case Study";
+ $txt .= "\n" . "\n";
+ $txt .= "Title Of The Case Study Project: " . $proposal_data->project_title . "\n";
+ $txt .= "Proposar Name: " . $proposal_data->name_title . " " . $proposal_data->contributor_name . "\n";
+ $txt .= "University: " . $proposal_data->university . "\n";
+ $txt .= "\n" . "\n";
+ $txt .= " Case Study Project By FOSSEE, IIT Bombay" . "\n";
+ fwrite($readme_file, $txt);
+ fclose($readme_file);
+ return $txt;
+}
+function rrmdir_project($prop_id)
+{
+ $proposal_id = $prop_id;
+ $result = db_query("SELECT * from case_study_proposal WHERE id = :proposal_id", array(
+ ":proposal_id" => $proposal_id,
+ ));
+ $proposal_data = $result->fetchObject();
+ $root_path = scilab_case_study_document_path();
+ $dir = $root_path . $proposal_data->directory_name;
+ if ($proposal_data->id == $prop_id) {
+ if (is_dir($dir)) {
+ $objects = scandir($dir);
+ foreach ($objects as $object) {
+ if ($object != "." && $object != "..") {
+ if (filetype($dir . "/" . $object) == "dir") {
+ rrmdir($dir . "/" . $object);
+ } //filetype($dir . "/" . $object) == "dir"
+ else {
+ unlink($dir . "/" . $object);
+ }
+ } //$object != "." && $object != ".."
+ } //$objects as $object
+ reset($objects);
+ rmdir($dir);
+ $msg = drupal_set_message("Directory deleted successfully");
+ return $msg;
+ } //is_dir($dir)
+ $msg = drupal_set_message("Directory not present");
+ return $msg;
+ } //$proposal_data->id == $prop_id
+ else {
+ $msg = drupal_set_message("Data not found");
+ return $msg;
+ }
+}
+function rrmdir($dir)
+{
+ if (is_dir($dir)) {
+ $objects = scandir($dir);
+ foreach ($objects as $object) {
+ if ($object != "." && $object != "..") {
+ if (filetype($dir . "/" . $object) == "dir") {
+ rrmdir($dir . "/" . $object);
+ } else {
+ unlink($dir . "/" . $object);
+ }
+
+ } //$object != "." && $object != ".."
+ } //$objects as $object
+ reset($objects);
+ rmdir($dir);
+ } //is_dir($dir)
+}
diff --git a/scilab_case_study_details.inc b/scilab_case_study_details.inc
new file mode 100644
index 0000000..08526f6
--- /dev/null
+++ b/scilab_case_study_details.inc
@@ -0,0 +1,96 @@
+<?php
+// case study display completed proposals
+function scilab_case_study_completed_proposals_all()
+{
+ $output = "";
+ $query = db_select('case_study_proposal');
+ $query->fields('case_study_proposal');
+ $query->condition('approval_status', 3);
+ $query->orderBy('actual_completion_date', 'DESC');
+ //$query->condition('is_completed', 1);
+ $result = $query->execute();
+
+ //var_dump($case_study_abstract);die;
+ if ($result->rowCount() == 0)
+ {
+ $output .= "There are no completed case studies currently. Click <a href='proposal'>here</a> to propose a case study.";
+
+ } //$result->rowCount() == 0
+ else
+ {
+ $output .= "Work has been completed for the following case studies. We welcome your contributions." . "<hr>";
+ $preference_rows = array();
+ $i = $result->rowCount();
+ //var_dump($i);die;
+ while ($row = $result->fetchObject())
+ {
+ $proposal_id = $row->id;
+ $project_title = l($row->project_title, "case-study-project/case-study-run/" . $row->id);
+ $year = date("Y", $row->actual_completion_date);
+ $preference_rows[] = array(
+ $i,
+ $project_title,
+ $row->contributor_name,
+ $row->university,
+ $year
+ );
+ $i--;
+ } //$row = $result->fetchObject()
+ $preference_header = array(
+ 'No',
+ 'Case Study Project',
+ 'Contributor Name',
+ 'University/ Institute',
+ 'Year of Completion'
+ );
+ $output .= theme('table', array(
+ 'header' => $preference_header,
+ 'rows' => $preference_rows
+ ));
+ }
+ return $output;
+}
+// case study display in progress proposals
+function scilab_case_study_progress_all()
+{
+ $page_content = "";
+ $query = db_select('case_study_proposal');
+ $query->fields('case_study_proposal');
+ $query->condition('approval_status', 1);
+ $query->condition('is_completed', 0);
+ $result = $query->execute();
+ if ($result->rowCount() == 0)
+ {
+ $page_content .= "There are no case studies in progress currently. Click <a href='proposal'>here</a> to propose a case study.";
+ } //$result->rowCount() == 0
+ else
+ {
+ $page_content .= "Work is in progress for the following case studies under case study Project<hr>";
+ $preference_rows = array();
+ $i = $result->rowCount();
+ while ($row = $result->fetchObject())
+ {
+ $approval_date = date("Y", $row->approval_date);
+ $preference_rows[] = array(
+ $i,
+ $row->project_title,
+ $row->contributor_name,
+ $row->university,
+ $approval_date
+ );
+ $i--;
+ } //$row = $result->fetchObject()
+ $preference_header = array(
+ 'No',
+ 'Case Study Project',
+ 'Contributor Name',
+ 'Institute/ University',
+ 'Year'
+ );
+ $page_content .= theme('table', array(
+ 'header' => $preference_header,
+ 'rows' => $preference_rows
+ ));
+ }
+ return $page_content;
+}
diff --git a/settings.inc b/settings.inc
new file mode 100644
index 0000000..3e86915
--- /dev/null
+++ b/settings.inc
@@ -0,0 +1,98 @@
+<?php
+// $Id$
+function scilab_case_study_settings_form($form, $form_state)
+{
+ $form['emails'] = array(
+ '#type' => 'textfield',
+ '#title' => t('(Bcc) Notification emails'),
+ '#description' => t('Specify emails id for Bcc option of mail system with comma separated'),
+ '#size' => 50,
+ '#maxlength' => 255,
+ '#required' => TRUE,
+ '#default_value' => variable_get('case_study_emails', '')
+ );
+ $form['cc_emails'] = array(
+ '#type' => 'textfield',
+ '#title' => t('(Cc) Notification emails'),
+ '#description' => t('Specify emails id for Cc option of mail system with comma separated'),
+ '#size' => 50,
+ '#maxlength' => 255,
+ '#required' => TRUE,
+ '#default_value' => variable_get('case_study_cc_emails', '')
+ );
+ $form['from_email'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Outgoing from email address'),
+ '#description' => t('Email address to be display in the from field of all outgoing messages'),
+ '#size' => 50,
+ '#maxlength' => 255,
+ '#required' => TRUE,
+ '#default_value' => variable_get('case_study_from_email', '')
+ );
+ $form['extensions']['resource_upload'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Allowed file extensions for uploading resource files'),
+ '#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('resource_upload_extensions', '')
+ );
+ $form['extensions']['abstract_upload'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Allowed file extensions for abstract'),
+ '#description' => t('A comma separated list WITHOUT SPACE of pdf file extensions that are permitted to be uploaded on the server'),
+ '#size' => 50,
+ '#maxlength' => 255,
+ '#required' => TRUE,
+ '#default_value' => variable_get('case_study_abstract_upload_extensions', '')
+ );
+ $form['extensions']['case_study_upload'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Allowed extensions for project files'),
+ '#description' => t('A comma separated list WITHOUT SPACE of pdf file extensions that are permitted to be uploaded on the server'),
+ '#size' => 50,
+ '#maxlength' => 255,
+ '#required' => TRUE,
+ '#default_value' => variable_get('case_study_project_files_extensions', '')
+ );
+ $form['extensions']['case_study_final_report'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Allowed extensions for Final report in Case directory submission'),
+ '#description' => t('A comma separated list WITHOUT SPACE of pdf file extensions that are permitted to be uploaded on the server'),
+ '#size' => 50,
+ '#maxlength' => 255,
+ '#required' => TRUE,
+ '#default_value' => variable_get('case_study_final_report_extensions', '')
+ );
+ $form['extensions']['list_of_available_projects_file'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Allowed file extensions for file uploaded for available projects list'),
+ '#description' => t('A comma separated list WITHOUT SPACE of file extensions that are permitted to be uploaded on the server'),
+ '#size' => 50,
+ '#maxlength' => 255,
+ '#required' => TRUE,
+ '#default_value' => variable_get('list_of_available_projects_file', '')
+ );
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit')
+ );
+ return $form;
+}
+function scilab_case_study_settings_form_validate($form, &$form_state)
+{
+ return;
+}
+function scilab_case_study_settings_form_submit($form, &$form_state)
+{
+ variable_set('case_study_emails', $form_state['values']['emails']);
+ variable_set('case_study_cc_emails', $form_state['values']['cc_emails']);
+ variable_set('case_study_from_email', $form_state['values']['from_email']);
+ variable_set('resource_upload_extensions', $form_state['values']['resource_upload']);
+ variable_set('case_study_abstract_upload_extensions', $form_state['values']['abstract_upload']);
+ variable_set('case_study_project_files_extensions', $form_state['values']['case_study_upload']);
+ variable_set('case_study_final_report_extensions', $form_state['values']['case_study_final_report']);
+ variable_set('list_of_available_projects_file', $form_state['values']['list_of_available_projects_file']);
+ drupal_set_message(t('Settings updated'), 'status');
+}
diff --git a/upload_code.inc b/upload_code.inc
new file mode 100644
index 0000000..5025acb
--- /dev/null
+++ b/upload_code.inc
@@ -0,0 +1,688 @@
+<?php
+// $Id$
+function scilab_case_study_abstract()
+{
+ global $user;
+ $return_html = "";
+ $proposal_data = scilab_case_study_get_proposal();
+ if (!$proposal_data) {
+ drupal_goto('');
+ return;
+ } //!$proposal_data
+ //$return_html .= l('Upload abstract', 'case-study-project/abstract-code/upload') . '<br />';
+ /* get experiment list */
+ $query = db_select('case_study_submitted_abstracts');
+ $query->fields('case_study_submitted_abstracts');
+ $query->condition('proposal_id', $proposal_data->id);
+ $abstracts_q = $query->execute()->fetchObject();
+ $query_pro = db_select('case_study_proposal');
+ $query_pro->fields('case_study_proposal');
+ $query_pro->condition('id', $proposal_data->id);
+ $abstracts_pro = $query_pro->execute()->fetchObject();
+ $query_pdf = db_select('case_study_submitted_abstracts_file');
+ $query_pdf->fields('case_study_submitted_abstracts_file');
+ $query_pdf->condition('proposal_id', $proposal_data->id);
+ $query_pdf->condition('filetype', 'A');
+ $abstracts_pdf = $query_pdf->execute()->fetchObject();
+ if ($abstracts_pdf == true) {
+ if ($abstracts_pdf->filename != "NULL" || $abstracts_pdf->filename != "") {
+ $abstract_filename = $abstracts_pdf->filename;
+ //$abstract_filename = l($abstracts_pdf->filename, 'case-study-project/download/project-file/' . $proposal_data->id);
+ } //$abstracts_pdf->filename != "NULL" || $abstracts_pdf->filename != ""
+ else {
+ $abstract_filename = "File not uploaded";
+ }
+ } //$abstracts_pdf == TRUE
+ else {
+ $abstract_filename = "File not uploaded";
+ }
+ $query_process = db_select('case_study_submitted_abstracts_file');
+ $query_process->fields('case_study_submitted_abstracts_file');
+ $query_process->condition('proposal_id', $proposal_data->id);
+ $query_process->condition('filetype', 'S');
+ $abstracts_query_process = $query_process->execute()->fetchObject();
+ if ($abstracts_query_process == true) {
+ if ($abstracts_query_process->filename != "NULL" || $abstracts_query_process->filename != "") {
+ $abstracts_query_process_filename = $abstracts_query_process->filename;
+ //$abstracts_query_process_filename = l($abstracts_query_process->filename, 'case-study-project/download/project-file/' . $proposal_data->id);
+ } //$abstracts_query_process->filename != "NULL" || $abstracts_query_process->filename != ""
+ else {
+ $abstracts_query_process_filename = "File not uploaded";
+ }
+ if ($abstracts_q->is_submitted == '') {
+ $url = l('Upload Case Directory', 'case-study-project/abstract-code/upload');
+ } //$abstracts_q->is_submitted == ''
+ else if ($abstracts_q->is_submitted == 1) {
+ $url = "";
+ } //$abstracts_q->is_submitted == 1
+ else if ($abstracts_q->is_submitted == 0) {
+ $url = l('Edit', 'case-study-project/abstract-code/upload');
+ } //$abstracts_q->is_submitted == 0
+ } //$abstracts_query_process == TRUE
+ else {
+ $url = l('Upload Case Directory', 'case-study-project/abstract-code/upload');
+ $abstracts_query_process_filename = "File not uploaded";
+ }
+ $return_html .= '<strong>Contributor Name:</strong><br />' . $proposal_data->name_title . ' ' . $proposal_data->contributor_name . '<br /><br />';
+ $return_html .= '<strong>Title of the Case Study Project:</strong><br />' . $proposal_data->project_title . '<br /><br />';
+ $return_html .= '<strong>Uploaded abstract of the project:</strong><br />' . $abstract_filename . '<br /><br />';
+ $return_html .= '<strong>Uploaded Case Directory:</strong><br />' . $abstracts_query_process_filename . '<br /><br />';
+ $return_html .= $url . '<br />';
+ return $return_html;
+}
+function scilab_case_study_upload_abstract_code_form($form, &$form_state)
+{
+ global $user;
+ $form['#attributes'] = array(
+ 'enctype' => "multipart/form-data",
+ );
+ /* get current proposal */
+ //$proposal_id = (int) arg(3);
+ $uid = $user->uid;
+ $query = db_select('case_study_proposal');
+ $query->fields('case_study_proposal');
+ $query->condition('uid', $uid);
+ $query->condition('approval_status', '1');
+ $proposal_q = $query->execute();
+ if ($proposal_q) {
+ if ($proposal_data = $proposal_q->fetchObject()) {
+ /* everything ok */
+ } //$proposal_data = $proposal_q->fetchObject()
+ else {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('case-study-project/abstract-code');
+ return;
+ }
+ } //$proposal_q
+ else {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('case-study-project/abstract-code');
+ return;
+ }
+ $query = db_select('case_study_submitted_abstracts');
+ $query->fields('case_study_submitted_abstracts');
+ $query->condition('proposal_id', $proposal_data->id);
+ $abstracts_q = $query->execute()->fetchObject();
+ if ($abstracts_q) {
+ if ($abstracts_q->is_submitted == 1) {
+ drupal_set_message(t('You have already submited your Case Directory, hence you can not upload any more, for any query please write to us.'), 'error', $repeat = false);
+ drupal_goto('case-study-project/abstract-code');
+ //return;
+ } //$abstracts_q->is_submitted == 1
+ } //$abstracts_q->is_submitted == 1
+ $form['project_title'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->project_title,
+ '#title' => t('Title of the Case Study Project'),
+ );
+ $form['contributor_name'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->contributor_name,
+ '#title' => t('Contributor Name'),
+ );
+ $existing_uploaded_S_file = default_value_for_uploaded_files("S", $proposal_data->id);
+ if (!$existing_uploaded_S_file) {
+ $existing_uploaded_S_file = new stdClass();
+ $existing_uploaded_S_file->filename = "No file uploaded";
+ } //!$existing_uploaded_S_file
+ $form['upload_case_study_developed_process'] = array(
+ '#type' => 'file',
+ '#title' => t('Upload the Case Directory'),
+ //'#required' => TRUE,
+ '#description' => t('<span style="color:red;">Current File:</span> ' . $existing_uploaded_S_file->filename . '<br />Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' . t('<span style="color:red;">Allowed file extensions: ') . variable_get('case_study_project_files_extensions', '') . '</span>',
+ );
+ $existing_uploaded_A_file = default_value_for_uploaded_files("A", $proposal_data->id);
+ if (!$existing_uploaded_A_file) {
+ $existing_uploaded_A_file = new stdClass();
+ $existing_uploaded_A_file->filename = "No file uploaded";
+ } //!$existing_uploaded_A_file
+ $form['upload_case_study_final_report'] = array(
+ '#type' => 'file',
+ '#title' => t('Upload the Final Report'),
+ //'#required' => TRUE,
+ '#description' => t('<span style="color:red;">Current File:</span> ' . $existing_uploaded_A_file->filename . '<br />Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' . t('<span style="color:red;">Allowed file extensions: ') . variable_get('case_study_final_report_extensions', '') . '</span>',
+ );
+ $form['prop_id'] = array(
+ '#type' => 'hidden',
+ '#value' => $proposal_data->id,
+ );
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit'),
+ '#submit' => array(
+ 'scilab_case_study_upload_abstract_code_form_submit',
+ ),
+ );
+ $form['cancel'] = array(
+ '#type' => 'item',
+ '#markup' => l(t('Cancel'), 'case-study-project/abstract-code'),
+ );
+ return $form;
+}
+
+///////////////////////////////////////////////////////////////
+function scilab_case_study_upload_abstract_code_form_validate($form, &$form_state)
+{
+ //var_dump($form);die;
+ if (isset($_FILES['files'])) {
+ /* check if atleast one source or result file is uploaded */
+ $existing_uploaded_A_file = default_value_for_uploaded_files("A", $form_state['values']['prop_id']);
+ $existing_uploaded_S_file = default_value_for_uploaded_files("S", $form_state['values']['prop_id']);
+ if(!$existing_uploaded_A_file){
+ if (!($_FILES['files']['name']['upload_case_study_final_report'])) {
+ form_set_error('upload_case_study_final_report', t('Please upload the final report'));
+ }
+ }
+ if(!$existing_uploaded_S_file){
+ if (!($_FILES['files']['name']['upload_case_study_developed_process'])) {
+ form_set_error('upload_case_study_developed_process', t('Please upload the case files'));
+ }
+ }
+
+ /* check for valid filename extensions */
+ foreach ($_FILES['files']['name'] as $file_form_name => $file_name) {
+ if ($file_name) {
+ /* checking file type */
+ if (strstr($file_form_name, 'upload_case_study_developed_process'))
+ $file_type = 'S';
+ else if (strstr($file_form_name, 'upload_case_study_final_report'))
+ $file_type = 'A';
+ $allowed_extensions_str = '';
+ switch ($file_type)
+ {
+ case 'S':
+ $allowed_extensions_str = variable_get('case_study_project_files_extensions', '');
+ break;
+ case 'A':
+ $allowed_extensions_str = variable_get('case_study_final_report_extensions', '');
+ break;
+ } //$file_type
+ $allowed_extensions = explode(',', $allowed_extensions_str);
+ $tmp_ext = explode('.', strtolower($_FILES['files']['name'][$file_form_name]));
+ $temp_extension = end($tmp_ext);
+ if (!in_array($temp_extension, $allowed_extensions))
+ form_set_error($file_form_name, t('Only file with ' . $allowed_extensions_str . ' extensions can be uploaded.'));
+ if ($_FILES['files']['size'][$file_form_name] <= 0)
+ form_set_error($file_form_name, t('File size cannot be zero.'));
+ /* check if valid file name */
+ if (!scilab_case_study_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 $form_state;
+}
+function scilab_case_study_upload_abstract_code_form_submit($form, &$form_state)
+{
+ global $user;
+ $v = $form_state['values'];
+ $root_path = scilab_case_study_path();
+ $proposal_data = scilab_case_study_get_proposal();
+ $proposal_id = $proposal_data->id;
+ if (!$proposal_data) {
+ drupal_goto('');
+ return;
+ } //!$proposal_data
+ $proposal_id = $proposal_data->id;
+ $proposal_directory = $proposal_data->directory_name;
+ /* create proposal folder if not present */
+ //$dest_path = $proposal_directory . '/';
+ $dest_path = $proposal_directory . '/project_files/';
+ if (!is_dir($root_path . $dest_path))
+ mkdir($root_path . $dest_path);
+ $proposal_id = $proposal_data->id;
+ $query_s = "SELECT * FROM case_study_submitted_abstracts WHERE proposal_id = :proposal_id";
+ $args_s = array(
+ ":proposal_id" => $proposal_id,
+ );
+ $query_s_result = db_query($query_s, $args_s)->fetchObject();
+ if (!$query_s_result) {
+ /* creating solution database entry */
+ $query = "INSERT INTO case_study_submitted_abstracts(
+ proposal_id,
+ approver_uid,
+ abstract_approval_status,
+ abstract_upload_date,
+ abstract_approval_date,
+ is_submitted) VALUES (:proposal_id, :approver_uid, :abstract_approval_status,:abstract_upload_date, :abstract_approval_date, :is_submitted)";
+ $args = array(
+ ":proposal_id" => $proposal_id,
+ ":approver_uid" => 0,
+ ":abstract_approval_status" => 0,
+ ":abstract_upload_date" => time(),
+ ":abstract_approval_date" => 0,
+ ":is_submitted" => 1,
+ );
+ $submitted_abstract_id = db_query($query, $args, array(
+ 'return' => Database::RETURN_INSERT_ID,
+ ));
+ $query1 = "UPDATE case_study_proposal SET is_submitted = :is_submitted WHERE id = :id";
+ $args1 = array(
+ ":is_submitted" => 1,
+ ":id" => $proposal_id,
+ );
+ db_query($query1, $args1);
+ drupal_set_message('Abstract uploaded successfully.', 'status');
+ } //!$query_s_result
+ else {
+ $query = "UPDATE case_study_submitted_abstracts SET abstract_upload_date =:abstract_upload_date,
+ is_submitted= :is_submitted WHERE proposal_id = :proposal_id";
+ $args = array(
+ ":abstract_upload_date" => time(),
+ ":is_submitted" => 1,
+ ":proposal_id" => $proposal_id,
+ );
+ $submitted_abstract_id = db_query($query, $args, array(
+ 'return' => Database::RETURN_INSERT_ID,
+ ));
+ $query1 = "UPDATE case_study_proposal SET is_submitted = :is_submitted WHERE id = :id";
+ $args1 = array(
+ ":is_submitted" => 1,
+ ":id" => $proposal_id,
+ );
+ db_query($query1, $args1);
+ drupal_set_message('Abstract updated successfully.', 'status');
+ }
+ foreach ($_FILES['files']['name'] as $file_form_name => $file_name) {
+ if ($file_name) {
+ /* checking file type */
+ if (strstr($file_form_name, 'upload_case_study_developed_process'))
+ {
+ $file_type = 'S';
+ } //strstr($file_form_name, 'upload_case_study_developed_process')
+ else if (strstr($file_form_name, 'upload_case_study_final_report'))
+ {
+ $file_type = 'A';
+ } //strstr($file_form_name, 'upload_an_abstract')
+ switch ($file_type)
+ {
+ case 'S':
+ 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 overwritten the exisitng file ", array(
+ '!filename' => $_FILES['files']['name'][$file_form_name]
+ )), 'status');
+ } //file_exists($root_path . $dest_path . $_FILES['files']['name'][$file_form_name])
+ /* uploading file */
+ else if (move_uploaded_file($_FILES['files']['tmp_name'][$file_form_name], $root_path . $dest_path . $_FILES['files']['name'][$file_form_name]))
+ {
+ /* for uploaded files making an entry in the database */
+ $query_ab_f = "SELECT * FROM case_study_submitted_abstracts_file WHERE proposal_id = :proposal_id AND filetype =
+ :filetype";
+ $args_ab_f = array(
+ ":proposal_id" => $proposal_id,
+ ":filetype" => $file_type
+ );
+ $query_ab_f_result = db_query($query_ab_f, $args_ab_f)->fetchObject();
+ if (!$query_ab_f_result)
+ {
+ $query = "INSERT INTO case_study_submitted_abstracts_file (submitted_abstract_id, proposal_id, uid, approvar_uid, filename, filepath, filemime, filesize, filetype, timestamp)
+ VALUES (:submitted_abstract_id, :proposal_id, :uid, :approvar_uid, :filename, :filepath, :filemime, :filesize, :filetype, :timestamp)";
+ $args = array(
+ ":submitted_abstract_id" => $submitted_abstract_id,
+ ":proposal_id" => $proposal_id,
+ ":uid" => $user->uid,
+ ":approvar_uid" => 0,
+ ":filename" => $_FILES['files']['name'][$file_form_name],
+ ":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" => $file_type,
+ ":timestamp" => time()
+ );
+ db_query($query, $args);
+ drupal_set_message($file_name . ' uploaded successfully.', 'status');
+ } //!$query_ab_f_result
+ else
+ {
+ unlink($root_path . $dest_path . $query_ab_f_result->filename);
+ $query = "UPDATE {case_study_submitted_abstracts_file} SET filename = :filename, filepath=:filepath, filemime=:filemime, filesize=:filesize, timestamp=:timestamp WHERE proposal_id = :proposal_id AND filetype = :filetype";
+ $args = array(
+ ":filename" => $_FILES['files']['name'][$file_form_name],
+ ":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" => $proposal_id,
+ ":filetype" => $file_type
+ );
+ db_query($query, $args);
+ drupal_set_message($file_name . ' file updated successfully.', 'status');
+ }
+ } //move_uploaded_file($_FILES['files']['tmp_name'][$file_form_name], $root_path . $dest_path . $_FILES['files']['name'][$file_form_name])
+ else
+ {
+ drupal_set_message('Error uploading file : ' . $dest_path . $file_name, 'error');
+ }
+ break;
+ case 'A':
+ 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 overwritten the exisitng file ", array(
+ '!filename' => $_FILES['files']['name'][$file_form_name]
+ )), 'status');
+ } //file_exists($root_path . $dest_path . $_FILES['files']['name'][$file_form_name])
+ /* uploading file */
+ else if (move_uploaded_file($_FILES['files']['tmp_name'][$file_form_name], $root_path . $dest_path . $_FILES['files']['name'][$file_form_name]))
+ {
+ /* for uploaded files making an entry in the database */
+ $query_ab_f = "SELECT * FROM case_study_submitted_abstracts_file WHERE proposal_id = :proposal_id AND filetype =
+ :filetype";
+ $args_ab_f = array(
+ ":proposal_id" => $proposal_id,
+ ":filetype" => $file_type
+ );
+ $query_ab_f_result = db_query($query_ab_f, $args_ab_f)->fetchObject();
+ if (!$query_ab_f_result)
+ {
+ $query = "INSERT INTO {case_study_submitted_abstracts_file} (submitted_abstract_id, proposal_id, uid, approvar_uid, filename, filepath, filemime, filesize, filetype, timestamp)
+ VALUES (:submitted_abstract_id, :proposal_id, :uid, :approvar_uid, :filename, :filepath, :filemime, :filesize, :filetype, :timestamp)";
+ $args = array(
+ ":submitted_abstract_id" => $submitted_abstract_id,
+ ":proposal_id" => $proposal_id,
+ ":uid" => $user->uid,
+ ":approvar_uid" => 0,
+ ":filename" => $_FILES['files']['name'][$file_form_name],
+ ":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" => $file_type,
+ ":timestamp" => time()
+ );
+ db_query($query, $args);
+ drupal_set_message($file_name . ' uploaded successfully.', 'status');
+ } //!$query_ab_f_result
+ else
+ {
+ unlink($root_path . $dest_path . $query_ab_f_result->filename);
+ $query = "UPDATE {case_study_submitted_abstracts_file} SET filename = :filename, filepath=:filepath, filemime=:filemime, filesize=:filesize, timestamp=:timestamp WHERE proposal_id = :proposal_id AND filetype = :filetype";
+ $args = array(
+ ":filename" => $_FILES['files']['name'][$file_form_name],
+ ":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" => $proposal_id,
+ ":filetype" => $file_type
+ );
+ db_query($query, $args);
+ drupal_set_message($file_name . ' file updated successfully.', 'status');
+ }
+ } //move_uploaded_file($_FILES['files']['tmp_name'][$file_form_name], $root_path . $dest_path . $_FILES['files']['name'][$file_form_name])
+ else
+ {
+ drupal_set_message('Error uploading file : ' . $dest_path . $file_name, 'error');
+ }
+ break;
+ } //$file_type
+ } //$file_name
+ } //$_FILES['files']['name'] as $file_form_name => $file_name
+ /* sending email */
+ $email_to = $user->mail;
+ $from = variable_get('case_study_from_email', '');
+ $bcc = variable_get('case_study_emails', '');
+ $cc = variable_get('case_study_cc_emails', '');
+ $params['abstract_uploaded']['proposal_id'] = $proposal_id;
+ $params['abstract_uploaded']['submitted_abstract_id'] = $submitted_abstract_id;
+ $params['abstract_uploaded']['user_id'] = $user->uid;
+ $params['abstract_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('scilab_case_study', 'abstract_uploaded', $email_to, language_default(), $params, $from, true)) {
+ drupal_set_message('Error sending email message.', 'error');
+ }
+
+ drupal_goto('case-study-project/abstract-code');
+}
+function default_value_for_uploaded_files($filetype, $proposal_id)
+{
+ $query = db_select('case_study_submitted_abstracts_file');
+ $query->fields('case_study_submitted_abstracts_file');
+ $query->condition('proposal_id', $proposal_id);
+ $selected_files_array = "";
+ if ($filetype == "S") {
+ $query->condition('filetype', $filetype);
+ $filetype_q = $query->execute()->fetchObject();
+ return $filetype_q;
+ } elseif ($filetype == "A") {
+ $query->condition('filetype', $filetype);
+ $filetype_q = $query->execute()->fetchObject();
+ return $filetype_q;
+ }
+ return;
+}
+function scilab_case_study_edit_upload_abstract_code_form($form, &$form_state)
+{
+ global $user;
+ $form['#attributes'] = array(
+ 'enctype' => "multipart/form-data",
+ );
+ /* get current proposal */
+ $proposal_id = (int) arg(3);
+ $uid = $user->uid;
+ $query = db_select('case_study_proposal');
+ $query->fields('case_study_proposal');
+ $query->condition('id', $proposal_id);
+ $proposal_q = $query->execute();
+ if ($proposal_q) {
+ if ($proposal_data = $proposal_q->fetchObject()) {
+ /* everything ok */
+ } //$proposal_data = $proposal_q->fetchObject()
+ else {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('case-study-project/manage-proposal/edit-upload-file');
+ return;
+ }
+ } //$proposal_q
+ else {
+ drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error');
+ drupal_goto('case-study-project/manage-proposal/edit-upload-file');
+ return;
+ }
+ $query = db_select('case_study_submitted_abstracts');
+ $query->fields('case_study_submitted_abstracts');
+ $query->condition('proposal_id', $proposal_data->id);
+ $abstracts_q = $query->execute()->fetchObject();
+ $form['project_title'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->project_title,
+ '#title' => t('Title of the Case Study Project'),
+ );
+ $form['contributor_name'] = array(
+ '#type' => 'item',
+ '#markup' => $proposal_data->contributor_name,
+ '#title' => t('Contributor Name'),
+ );
+ $existing_uploaded_A_file = default_value_for_uploaded_files("A", $proposal_data->id);
+ if (!$existing_uploaded_A_file) {
+ $existing_uploaded_A_file = new stdClass();
+ $existing_uploaded_A_file->filename = "No file uploaded";
+ } //!$existing_uploaded_A_file
+ $form['upload_case_study_abstract'] = array(
+ '#type' => 'file',
+ '#title' => t('Upload the Case study abstract'),
+ //'#required' => TRUE,
+ '#description' => t('<span style="color:red;">Current File :</span> ' . $existing_uploaded_A_file->filename . '<br />Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' . t('<span style="color:red;">Allowed file extensions : ') . variable_get('resource_upload_extensions', '') . '</span>',
+ );
+ $existing_uploaded_S_file = default_value_for_uploaded_files("S", $proposal_data->id);
+ if (!$existing_uploaded_S_file) {
+ $existing_uploaded_S_file = new stdClass();
+ $existing_uploaded_S_file->filename = "No file uploaded";
+ } //!$existing_uploaded_S_file
+ $form['upload_case_study_developed_process'] = array(
+ '#type' => 'file',
+ '#title' => t('Upload the Case Directory'),
+ //'#required' => TRUE,
+ '#description' => t('<span style="color:red;">Current File :</span> ' . $existing_uploaded_S_file->filename . '<br />Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '<br />' . t('<span style="color:red;">Allowed file extensions : ') . variable_get('case_study_project_files_extensions', '') . '</span>',
+ );
+ $form['prop_id'] = array(
+ '#type' => 'hidden',
+ '#value' => $proposal_data->id,
+ );
+ $form['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Submit'),
+ '#submit' => array(
+ 'scilab_case_study_edit_upload_abstract_code_form_submit',
+ ),
+ );
+ $form['cancel'] = array(
+ '#type' => 'item',
+ '#markup' => l(t('Cancel'), 'case-study-project/manage-proposal/edit-upload-file'),
+ );
+ return $form;
+}
+///////////////////////////////////////////////////////////////
+function scilab_case_study_edit_upload_abstract_code_form_validate($form, &$form_state)
+{
+
+ if (!($_FILES['files']['name']['upload_case_study_abstract'] || $_FILES['files']['name']['upload_case_study_developed_process'])) {
+ drupal_set_message('No files uploaded', 'error');
+ return;
+ }
+ if (isset($_FILES['files'])) {
+ /* check for valid filename extensions */
+ foreach ($_FILES['files']['name'] as $file_form_name => $file_name) {
+ if ($file_name) {
+ /* checking file type */
+ if (strstr($file_form_name, 'upload_case_study_abstract')) {
+ $file_type = 'A';
+ } else if (strstr($file_form_name, 'upload_case_study_developed_process')) {
+ $file_type = 'S';
+ } else {
+ $file_type = 'U';
+ }
+
+ $allowed_extensions_str = '';
+ switch ($file_type) {
+ case 'A':
+ $allowed_extensions_str = variable_get('resource_upload_extensions', '');
+ break;
+ case 'S':
+ $allowed_extensions_str = variable_get('case_study_project_files_extensions', '');
+ break;
+ } //$file_type
+ /* checking file type */
+ $allowed_extensions = explode(',', $allowed_extensions_str);
+ $fnames = explode('.', strtolower($_FILES['files']['name'][$file_form_name]));
+ $temp_extension = end($fnames);
+ if (!in_array($temp_extension, $allowed_extensions)) {
+ form_set_error($file_form_name, t('Only file with ' . $allowed_extensions_str . ' extensions can be uploaded.'));
+ }
+
+ if ($_FILES['files']['size'][$file_form_name] <= 0) {
+ form_set_error($file_form_name, t('File size cannot be zero.'));
+ }
+
+ /* check if valid file name */
+ if (!scilab_case_study_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
+ } else {
+ drupal_set_message('No files uploaded', 'error');
+ return $form_state;
+ }
+
+}
+function scilab_case_study_edit_upload_abstract_code_form_submit($form, &$form_state)
+{
+ global $user;
+ $v = $form_state['values'];
+ $root_path = scilab_case_study_path();
+ $query = db_select('case_study_proposal');
+ $query->fields('case_study_proposal');
+ $query->condition('id', $v['prop_id']);
+ $proposal_q = $query->execute();
+ $proposal_data = $proposal_q->fetchObject();
+ $proposal_id = $proposal_data->id;
+ if (!$proposal_data) {
+ drupal_goto('');
+ return;
+ } //!$proposal_data
+ $proposal_id = $proposal_data->id;
+ $proposal_directory = $proposal_data->directory_name;
+ /* create proposal folder if not present */
+ //$dest_path = $proposal_directory . '/';
+ $dest_path_project_files = $proposal_directory . '/';
+ $proposal_id = $proposal_data->id;
+ foreach ($_FILES['files']['name'] as $file_form_name => $file_name) {
+
+ if ($file_name) {
+ /* uploading file */
+ /* checking file type */
+ if (strstr($file_form_name, 'upload_case_study_abstract')) {
+ $file_type = 'A';
+ $abs_file_name = $_FILES['files']['name'][$file_form_name];
+ } else {
+ $abs_file_name = "Not updated";
+ }
+ if (strstr($file_form_name, 'upload_case_study_developed_process')) {
+ $file_type = 'S';
+ $proj_file_name = $_FILES['files']['name'][$file_form_name];
+ } else {
+ $proj_file_name = "Not updated";
+ }
+ if (move_uploaded_file($_FILES['files']['tmp_name'][$file_form_name], $root_path . $dest_path_project_files . $_FILES['files']['name'][$file_form_name])) {
+ $query_ab_f = "SELECT * FROM case_study_submitted_abstracts_file WHERE proposal_id = :proposal_id AND filetype =
+ :filetype";
+ $args_ab_f = array(
+ ":proposal_id" => $proposal_id,
+ ":filetype" => $file_type,
+ );
+ $query_ab_f_result = db_query($query_ab_f, $args_ab_f)->fetchObject();
+ unlink($root_path . $dest_path_project_files . $query_ab_f_result->filename);
+ $query = "UPDATE {case_study_submitted_abstracts_file} SET filename = :filename, filepath=:filepath, filemime=:filemime, filesize=:filesize, timestamp=:timestamp WHERE proposal_id = :proposal_id AND filetype = :filetype";
+ $args = array(
+ ":filename" => $_FILES['files']['name'][$file_form_name],
+ ":filepath" => $dest_path_project_files . $_FILES['files']['name'][$file_form_name],
+ ":filemime" => mime_content_type($root_path . $dest_path_project_files . $_FILES['files']['name'][$file_form_name]),
+ ":filesize" => $_FILES['files']['size'][$file_form_name],
+ ":timestamp" => time(),
+ ":proposal_id" => $proposal_id,
+ ":filetype" => $file_type,
+ );
+ db_query($query, $args, array('return' => Database::RETURN_INSERT_ID,
+ ));
+
+ drupal_set_message($file_name . ' file updated successfully.', 'status');
+
+ } else {
+ drupal_set_message($file_name . ' file not updated successfully.', 'error');
+ }
+ }
+ } //$_FILES['files']['name'] as $file_form_name => $file_name
+ /* sending email */
+ $email_to = $user->mail;
+ $from = variable_get('case_study_from_email', '');
+ $bcc = variable_get('case_study_emails', '');
+ $cc = variable_get('case_study_cc_emails', '');
+ $params['abstract_edit_file_uploaded']['proposal_id'] = $proposal_id;
+ $params['abstract_edit_file_uploaded']['user_id'] = $user->uid;
+ $params['abstract_edit_file_uploaded']['abs_file'] = $abs_file_name;
+ $params['abstract_edit_file_uploaded']['proj_file'] = $proj_file_name;
+ $params['abstract_edit_file_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('case_study', 'abstract_edit_file_uploaded', $email_to, language_default(), $params, $from, true)) {
+ drupal_set_message('Error sending email message.', 'error');
+ }
+ drupal_goto('case-study-project/abstract-code/edit-upload-files');
+}