From 363ece64917433aa2c619ce29860352e39309636 Mon Sep 17 00:00:00 2001 From: Sashi20 Date: Wed, 24 Jan 2024 18:14:23 +0530 Subject: Add proposal form and case directory submission forms --- abstract_bulk_approval.inc | 403 ++++++++++++++ download.inc | 62 +++ email.inc | 306 +++++++++++ full_download.inc | 66 +++ general_deletion.inc | 43 ++ manage_proposal.inc | 1197 +++++++++++++++++++++++++++++++++++++++++ proposal.inc | 608 +++++++++++++++++++++ run.inc | 144 +++++ scilab_case_study.info | 7 + scilab_case_study.module | 749 ++++++++++++++++++++++++++ scilab_case_study_details.inc | 96 ++++ settings.inc | 98 ++++ upload_code.inc | 682 +++++++++++++++++++++++ 13 files changed, 4461 insertions(+) create mode 100644 abstract_bulk_approval.inc create mode 100644 download.inc create mode 100644 email.inc create mode 100644 full_download.inc create mode 100644 general_deletion.inc create mode 100644 manage_proposal.inc create mode 100644 proposal.inc create mode 100644 run.inc create mode 100644 scilab_case_study.info create mode 100644 scilab_case_study.module create mode 100644 scilab_case_study_details.inc create mode 100644 settings.inc create mode 100644 upload_code.inc diff --git a/abstract_bulk_approval.inc b/abstract_bulk_approval.inc new file mode 100644 index 0000000..4952994 --- /dev/null +++ b/abstract_bulk_approval.inc @@ -0,0 +1,403 @@ + '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' => '
' + ); + $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' => '
', + '#suffix' => '
', + '#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' => '
', + '#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.'), 'status'); + // email + $email_subject = t('[!site_name][case study Project] Your uploaded case study project have been approved', array( + '!site_name' => variable_get('site_name', '') + )); + $email_body = array( + 0 => t(' + +Dear !user_name, + +Your uploaded abstract for the case study project has been approved: + +Title of case study project : ' . $user_info->project_title . ' + +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)) + { + $msg = 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'] == 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_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_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 .= 'Proposer Name:
' . $abstracts_pro->name_title . ' ' . $abstracts_pro->contributor_name . '

'; + $return_html .= 'Title of the case study Project:
' . $abstracts_pro->project_title . '

'; + $return_html .= 'Uploaded an abstract (brief outline) of the project:
' . $abstract_filename . '

'; + $return_html .= 'Uploaded Case Directory Folder:
' . $abstracts_query_process_filename . '

'; + $return_html .= $download_case_study; + return $return_html; +} diff --git a/download.inc b/download.inc new file mode 100644 index 0000000..4a4ec2d --- /dev/null +++ b/download.inc @@ -0,0 +1,62 @@ +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', $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, '/');*/ + 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..2908e0d --- /dev/null +++ b/email.inc @@ -0,0 +1,306 @@ +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 !user_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 !user_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 = 'http://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 !user_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 */ + $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 proposal has been completed', array( + '!site_name' => variable_get('site_name', ''), + ), array( + 'language' => $language->language, + )); + $message['body'] = array( + 'body' => t(' +Dear !user_name, + +Your Case Study and abstract on the following process have been completed successfully. + +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_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 !user_name, + +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 !user_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 !user_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 @@ +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 @@ +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..1a9491c --- /dev/null +++ b/manage_proposal.inc @@ -0,0 +1,1197 @@ +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'; + 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'); + return; + } + } //$proposal_q + else { + drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error'); + drupal_goto('case-study-project/manage-proposal'); + 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

", + ); + } + $form['approval'] = array( + '#type' => 'radios', + '#title' => t('CFD Case Study proposal'), + '#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'), + ); + 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'); + return; + } + } //$proposal_q + else { + drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error'); + drupal_goto('case-study-project/manage-proposal'); + 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'); + 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'); + 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'); + return; + } + } //$proposal_q + else { + drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error'); + drupal_goto('case-study-project/manage-proposal'); + 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<]+))(?$0', $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

", + ); + } + $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'); + return; + } + } //$proposal_q + else { + drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error'); + drupal_goto('case-study-project/manage-proposal'); + 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('Congratulations! CFD Case Study proposal has been marked as completed. User has been notified of the completion.', 'status'); + } + drupal_goto('case-study-project/manage-proposal'); + 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'); + return; + } + } //$proposal_q + else { + drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error'); + drupal_goto('case-study-project/manage-proposal'); + 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['how_did_you_know_about_project'] = array( + '#type' => 'textfield', + '#title' => t('How did you come to know about the Case Study Project?'), + '#default_value' => $proposal_data->how_did_you_know_about_project, + '#required' => true, + ); + $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' => _df_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' => _df_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, + ); + $version_options = _cs_list_of_versions(); + $form['version'] = array( + '#type' => 'select', + '#title' => t('Version used'), + '#options' => $version_options, + '#default_value' => $proposal_data->version_id + ); + $simulation_type_options = _cs_list_of_simulation_types(); + $form['simulation_type'] = array( + '#type' => 'select', + '#title' => t('Simulation Type used'), + '#options' => $simulation_type_options, + '#default_value' => $proposal_data->simulation_type_id, + '#ajax' => array( + 'callback' => 'ajax_solver_used_callback', + ), + ); + $simulation_id = isset($form_state['values']['simulation_type']) ? $form_state['values']['simulation_type'] : $proposal_data->simulation_type_id; + + $form['solver_used'] = array( + '#type' => 'select', + '#title' => t('Select the Solver to be used'), + '#options' => _cs_list_of_solvers($simulation_id), + '#prefix' => '
', + '#suffix' => '
', + '#states' => array( + 'invisible' => array( + ':input[name="simulation_type"]' => array( + 'value' => 19 + ) + ) + ), + //'#required' => TRUE + '#default_value' => $proposal_data->solver_used, + ); + + $form['solver_used_text'] = array( + '#type' => 'textfield', + '#title' => t('Enter the Solver to be used'), + '#size' => 100, + '#description' => t('Maximum character limit is 50'), + //'#required' => TRUE, + '#prefix' => '
', + '#suffix' => '
', + '#states' => array( + 'visible' => array( + ':input[name="simulation_type"]' => array( + 'value' => 19 + ) + ) + ), + '#default_value' => $proposal_data->solver_used + ); + /* $form['solver_used'] = array( + '#type' => 'textfield', + '#title' => t('Solver to be used'), + '#size' => 50, + '#maxlength' => 50, + '#required' => true, + '#default_value' => $proposal_data->solver_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['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'), + ); + return $form; +} + +function ajax_solver_used_callback($form, $form_state){ + $simulation_id = isset($form_state['values']['simulation_type']) ? $form_state['values']['simulation_type'] : key($simulation_type_options); + if($simulation_id < 19){ + $form['solver_used']['#options'] = _cs_list_of_solvers($simulation_id); + $form['solver_used']['#required'] = TRUE; + $form['solver_used']['#validated'] = TRUE; + $commands[] = ajax_command_replace('#ajax-solver-replace', drupal_render($form['solver_used'])); + $commands[] = ajax_command_html('#ajax-solver-text-replace', ''); + } + else{ + $commands[] = ajax_command_html('#ajax-solver-replace', ''); + $form['solver_used_text']['#required'] = TRUE; + $form['solver_used_text']['#validated'] = TRUE; + $commands[] = ajax_command_replace('#ajax-solver-text-replace', drupal_render($form['solver_used_text'])); + } + return array( + '#type' => 'ajax', + '#commands' => $commands + ); +} +function scilab_case_study_proposal_edit_form_validate($form, $form_state){ + if ($form_state['values']['simulation_type'] < 19) { + if($form_state['values']['solver_used'] == '0'){ + form_set_error('solver_used', t('Please select an option')); + } + } + else if ($form_state['values']['simulation_type'] == 19) { + if ($form_state['values']['solver_used_text'] != '') + { + if (strlen($form_state['values']['solver_used_text']) > 100) + { + form_set_error('solver_used_text', t('Maximum charater limit is 100 charaters only, please check the length of the solver used')); + } //strlen($form_state['values']['project_title']) > 250 + else if (strlen($form_state['values']['solver_used_text']) < 7) + { + form_set_error('solver_used_text', t('Minimum charater limit is 7 charaters, please check the length of the solver used')); + } //strlen($form_state['values']['project_title']) < 10 + } + else + { + form_set_error('solver_used_text', t('Solver used cannot be empty')); + } + } +} +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'); + return; + } + } //$proposal_q + else { + drupal_set_message(t('Invalid proposal selected. Please try again.'), 'error'); + drupal_goto('case-study-project/manage-proposal'); + 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'); + 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 = _df_dir_name($project_title, $proposar_name); + if (DF_RenameDir($proposal_id, $directory_names)) { + $directory_name = $directory_names; + } //LM_RenameDir($proposal_id, $directory_names) + else { + return; + } + $simulation_id = $v['simulation_type']; + if($simulation_id < 19){ + $solver = $v['solver_used']; + } + else{ + $solver = $v['solver_used_text']; + } + $query = "UPDATE case_study_proposal SET + name_title=:name_title, + contributor_name=:contributor_name, + university=:university, + institute=:institute, + how_did_you_know_about_project = :how_did_you_know_about_project, + faculty_name = :faculty_name, + faculty_department = :faculty_department, + faculty_email = :faculty_email, + city=:city, + pincode=:pincode, + state=:state, + project_title=:project_title, + version_id=:version_id, + simulation_type_id=:simulation_type_id, + solver_used=:solver_used, + directory_name=:directory_name + WHERE id=:proposal_id"; + $args = array( + ':name_title' => $v['name_title'], + ':contributor_name' => $v['contributor_name'], + ':university' => $v['university'], + ":institute" => $v['institute'], + ":how_did_you_know_about_project" => $v['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'], + ':project_title' => $project_title, + ':version_id' => $v['version'], + ':simulation_type_id' => $simulation_id, + ":solver_used" => $solver, + ':directory_name' => $directory_name, + ':proposal_id' => $proposal_id, + ); + $result = db_query($query, $args); + drupal_set_message(t('Proposal Updated'), 'status'); +} diff --git a/proposal.inc b/proposal.inc new file mode 100644 index 0000000..0f180d4 --- /dev/null +++ b/proposal.inc @@ -0,0 +1,608 @@ +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' => 250 + ); + $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('Maximum character limit is 50'), + '#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('Maximum character limit is 50') + ); + $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('Maximum character limit is 50') + ); + $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('Maximum character limit is 255') + ); + $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 + ); + /***************************************************************************/ + $form['hr'] = array( + '#type' => 'item', + '#markup' => '
' + ); + + $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('Note: Use Scilab 6.0.0 and above. Format: Scilab x.x.x'), + '#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('Upload filenames with allowed extensions only. No spaces or any special characters allowed in filename.') . '
' . t('Allowed file extensions: ') . variable_get('resource_upload_extensions', '') . '' + ); + $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('I agree to the Terms and Conditions') + ), + '#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..62d6065 --- /dev/null +++ b/run.inc @@ -0,0 +1,144 @@ + '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' => '
' + ); + $form['selected_case_study'] = array( + '#type' => 'item', + '#markup' => '
' + ); + } //!$url_case_study_id + else { + $case_study_default_value = $url_case_study_id; + $form['case_study_details'] = array( + '#type' => 'item', + '#markup' => '
' . _case_study_details($case_study_default_value) . '
' + ); + $form['selected_case_study'] = array( + '#type' => 'item', + '#markup' => '
' . l('Download Abstract', "case-study-project/download/final-report/" . $case_study_default_value) . '
' . l('Download Case Study', 'case-study-project/full-download/project/' . $case_study_default_value) . '
' + ); + } + 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 Abstract', "case-study-project/download/final-report/" . $case_study_default_value) . '
' . l('Download case study', '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 .= "{$header}"; + } //$headers as $header + foreach ($rows as $row) { + $tbody .= ""; + foreach ($row as $data) { + $tbody .= "{$data}"; + } //$row as $data + $tbody .= ""; + } //$rows as $row + $table = " + + {$thead} + {$tbody} +
+ "; + 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'] = 'About the case study
' . ''; + $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..5713635 --- /dev/null +++ b/scilab_case_study.module @@ -0,0 +1,749 @@ + '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/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' => 'CS Manage Code', + 'description' => 'Bulk Mangage', + '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 Project Directory 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 Project Directory 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() . 'scilab_uploads/case_study_uploads/'; +} +function scilab_case_study_file_path($value = '') +{ + return $_SERVER['DOCUMENT_ROOT'] . base_path() . 'scilab_uploads/'; +} +function scilab_case_study_project_titles_resource_file_path() +{ + return $_SERVER['DOCUMENT_ROOT'] . base_path() . 'scilab_uploads/case_project_titles_resource_files/'; +} +/************************* 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() . 'scilab_uploads/case_study_uploads/'; +} +function DF_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(); + 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 @@ +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 here to propose a case study."; + + } //$result->rowCount() == 0 + else + { + $output .= "Work has been completed for the following case studies. We welcome your contributions." . "
"; + $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 here to propose a case study."; + } //$result->rowCount() == 0 + else + { + $page_content .= "Work is in progress for the following case studies under case study Project
"; + $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 @@ + '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..49c2786 --- /dev/null +++ b/upload_code.inc @@ -0,0 +1,682 @@ +'; + /* 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 .= 'Contributor Name:
' . $proposal_data->name_title . ' ' . $proposal_data->contributor_name . '

'; + $return_html .= 'Title of the Case Study Project:
' . $proposal_data->project_title . '

'; + $return_html .= 'Uploaded abstract of the project:
' . $abstract_filename . '

'; + $return_html .= 'Uploaded Case Directory:
' . $abstracts_query_process_filename . '

'; + $return_html .= $url . '
'; + 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('Current File: ' . $existing_uploaded_S_file->filename . '
Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '
' . t('Allowed file extensions: ') . variable_get('case_study_project_files_extensions', '') . '', + ); + $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('Current File: ' . $existing_uploaded_A_file->filename . '
Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '
' . t('Allowed file extensions: ') . variable_get('case_study_final_report_extensions', '') . '', + ); + $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 */ + if (!($_FILES['files']['name']['upload_case_study_developed_process'])) { + form_set_error('upload_case_study_developed_process', t('Please upload the case files')); + } + if (!($_FILES['files']['name']['upload_case_study_final_report'])) { + form_set_error('upload_case_study_final_report', t('Please upload the final report')); + } + + /* 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])) + { + //unlink($root_path . $dest_path . $_FILES['files']['name'][$file_form_name]); + drupal_set_message(t("File !filename already exists hence overwirtten the exisitng file ", array( + '!filename' => $_FILES['files']['name'][$file_form_name] + )), 'error'); + } //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" => $file_path . $_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])) + { + //unlink($root_path . $dest_path . $_FILES['files']['name'][$file_form_name]); + drupal_set_message(t("File !filename already exists hence overwirtten the exisitng file ", array( + '!filename' => $_FILES['files']['name'][$file_form_name] + )), 'error'); + } //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" => $file_path . $_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('Current File : ' . $existing_uploaded_A_file->filename . '
Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '
' . t('Allowed file extensions : ') . variable_get('resource_upload_extensions', '') . '', + ); + $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('Current File : ' . $existing_uploaded_S_file->filename . '
Separate filenames with underscore. No spaces or any special characters allowed in filename.') . '
' . t('Allowed file extensions : ') . variable_get('case_study_project_files_extensions', '') . '', + ); + $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" => $file_path . $_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'); +} -- cgit